mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 10:41:56 -05:00
CR feedback.
This commit is contained in:
@@ -397,7 +397,7 @@ module ts {
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.LonghandPropertyAssignment:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
|
||||
@@ -1697,7 +1697,7 @@ module ts {
|
||||
if (declaration.initializer) {
|
||||
var type = checkAndMarkExpression(declaration.initializer);
|
||||
// Widening of property assignments is handled by checkObjectLiteral, exclude them here
|
||||
if (declaration.kind !== SyntaxKind.LonghandPropertyAssignment) {
|
||||
if (declaration.kind !== SyntaxKind.PropertyAssignment) {
|
||||
var unwidenedType = type;
|
||||
type = getWidenedType(type);
|
||||
if (type !== unwidenedType) {
|
||||
@@ -3244,7 +3244,7 @@ module ts {
|
||||
|
||||
// Returns true if the given expression contains (at any level of nesting) a function or arrow expression
|
||||
// that is subject to contextual typing.
|
||||
function isContextSensitiveCore(node: Expression | MethodDeclaration | PropertyAssignment): boolean {
|
||||
function isContextSensitiveCore(node: Expression | MethodDeclaration | ObjectLiteralElement): boolean {
|
||||
Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node));
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.FunctionExpression:
|
||||
@@ -3260,8 +3260,8 @@ module ts {
|
||||
case SyntaxKind.BinaryExpression:
|
||||
return (<BinaryExpression>node).operator === SyntaxKind.BarBarToken &&
|
||||
(isContextSensitiveCore((<BinaryExpression>node).left) || isContextSensitiveCore((<BinaryExpression>node).right));
|
||||
case SyntaxKind.LonghandPropertyAssignment:
|
||||
return isContextSensitiveCore((<LonghandPropertyAssignment>node).initializer);
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
return isContextSensitiveCore((<PropertyAssignment>node).initializer);
|
||||
case SyntaxKind.Method:
|
||||
return isContextSensitiveFunctionLikeDeclaration(<MethodDeclaration>node);
|
||||
}
|
||||
@@ -4913,14 +4913,14 @@ module ts {
|
||||
return node.contextualType;
|
||||
}
|
||||
|
||||
return getContextualTypeForPropertyAssignment(node);
|
||||
return getContextualTypeForObjectLiteralElement(node);
|
||||
}
|
||||
|
||||
function getContextualTypeForPropertyAssignment(propertyAssignment: PropertyAssignment) {
|
||||
var objectLiteral = <ObjectLiteralExpression>propertyAssignment.parent;
|
||||
function getContextualTypeForObjectLiteralElement(element: ObjectLiteralElement) {
|
||||
var objectLiteral = <ObjectLiteralExpression>element.parent;
|
||||
var type = getContextualType(objectLiteral);
|
||||
// TODO(jfreeman): Handle this case for computed names and symbols
|
||||
var name = (<Identifier>propertyAssignment.name).text;
|
||||
var name = (<Identifier>element.name).text;
|
||||
if (type && name) {
|
||||
return getTypeOfPropertyOfContextualType(type, name) ||
|
||||
isNumericName(name) && getIndexTypeOfContextualType(type, IndexKind.Number) ||
|
||||
@@ -4974,8 +4974,8 @@ module ts {
|
||||
return getTypeFromTypeNode((<TypeAssertion>parent).type);
|
||||
case SyntaxKind.BinaryExpression:
|
||||
return getContextualTypeForBinaryOperand(node);
|
||||
case SyntaxKind.LonghandPropertyAssignment:
|
||||
return getContextualTypeForPropertyAssignment(<PropertyAssignment>parent);
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
return getContextualTypeForObjectLiteralElement(<ObjectLiteralElement>parent);
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
return getContextualTypeForElementExpression(node);
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
@@ -5111,10 +5111,10 @@ module ts {
|
||||
if (hasProperty(members, id)) {
|
||||
var member = members[id];
|
||||
if (member.flags & SymbolFlags.Property || isObjectLiteralMethod(member.declarations[0])) {
|
||||
var memberDecl = <PropertyAssignment>member.declarations[0];
|
||||
var memberDecl = <ObjectLiteralElement>member.declarations[0];
|
||||
var type: Type;
|
||||
if (memberDecl.kind === SyntaxKind.LonghandPropertyAssignment) {
|
||||
type = checkExpression((<LonghandPropertyAssignment>memberDecl).initializer, contextualMapper);
|
||||
if (memberDecl.kind === SyntaxKind.PropertyAssignment) {
|
||||
type = checkExpression((<PropertyAssignment>memberDecl).initializer, contextualMapper);
|
||||
}
|
||||
else if (memberDecl.kind === SyntaxKind.Method) {
|
||||
type = checkObjectLiteralMethod(<MethodDeclaration>memberDecl, contextualMapper);
|
||||
@@ -8633,7 +8633,7 @@ module ts {
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
case SyntaxKind.LonghandPropertyAssignment:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
case SyntaxKind.ElementAccessExpression:
|
||||
case SyntaxKind.CallExpression:
|
||||
|
||||
@@ -2122,7 +2122,7 @@ module ts {
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.LonghandPropertyAssignment:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
case SyntaxKind.EnumMember:
|
||||
case SyntaxKind.Method:
|
||||
@@ -3549,7 +3549,7 @@ module ts {
|
||||
return emitArrayLiteral(<ArrayLiteralExpression>node);
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
return emitObjectLiteral(<ObjectLiteralExpression>node);
|
||||
case SyntaxKind.LonghandPropertyAssignment:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
return emitPropertyAssignment(<PropertyDeclaration>node);
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
return emitComputedPropertyName(<ComputedPropertyName>node);
|
||||
@@ -3590,7 +3590,6 @@ module ts {
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
return emitBlock(<Block>node);
|
||||
case SyntaxKind.VariableStatement:
|
||||
|
||||
@@ -223,7 +223,7 @@ module ts {
|
||||
child((<ParameterDeclaration>node).type) ||
|
||||
child((<ParameterDeclaration>node).initializer);
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.LonghandPropertyAssignment:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
return children(node.modifiers) ||
|
||||
child((<PropertyDeclaration>node).name) ||
|
||||
@@ -589,7 +589,7 @@ module ts {
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.EnumMember:
|
||||
case SyntaxKind.LonghandPropertyAssignment:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
return (<VariableDeclaration>parent).initializer === node;
|
||||
case SyntaxKind.ExpressionStatement:
|
||||
case SyntaxKind.IfStatement:
|
||||
@@ -647,7 +647,7 @@ module ts {
|
||||
case SyntaxKind.Method:
|
||||
return (<MethodDeclaration>node).questionToken !== undefined;
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
case SyntaxKind.LonghandPropertyAssignment:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.Property:
|
||||
return (<PropertyDeclaration>node).questionToken !== undefined;
|
||||
}
|
||||
@@ -686,7 +686,7 @@ module ts {
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.LonghandPropertyAssignment:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
case SyntaxKind.EnumMember:
|
||||
case SyntaxKind.Method:
|
||||
@@ -3166,7 +3166,7 @@ module ts {
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parsePropertyAssignment(): PropertyAssignment {
|
||||
function parseObjectLiteralElement(): ObjectLiteralElement {
|
||||
var fullStart = scanner.getStartPos();
|
||||
var initialToken = token;
|
||||
|
||||
@@ -3194,12 +3194,12 @@ module ts {
|
||||
return finishNode(shorthandDeclaration);
|
||||
}
|
||||
else {
|
||||
var longhandDeclaration = <LonghandPropertyAssignment>createNode(SyntaxKind.LonghandPropertyAssignment, fullStart);
|
||||
longhandDeclaration.name = propertyName;
|
||||
longhandDeclaration.questionToken = questionToken;
|
||||
var propertyAssignment = <PropertyAssignment>createNode(SyntaxKind.PropertyAssignment, fullStart);
|
||||
propertyAssignment.name = propertyName;
|
||||
propertyAssignment.questionToken = questionToken;
|
||||
parseExpected(SyntaxKind.ColonToken);
|
||||
longhandDeclaration.initializer = allowInAnd(parseAssignmentExpressionOrHigher);
|
||||
return finishNode(longhandDeclaration);
|
||||
propertyAssignment.initializer = allowInAnd(parseAssignmentExpressionOrHigher);
|
||||
return finishNode(propertyAssignment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3210,7 +3210,7 @@ module ts {
|
||||
node.flags |= NodeFlags.MultiLine;
|
||||
}
|
||||
|
||||
node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parsePropertyAssignment);
|
||||
node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralElement);
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
return finishNode(node);
|
||||
}
|
||||
@@ -4413,7 +4413,7 @@ module ts {
|
||||
case SyntaxKind.IndexSignature: return checkIndexSignature(<SignatureDeclaration>node);
|
||||
case SyntaxKind.InterfaceDeclaration: return checkInterfaceDeclaration(<InterfaceDeclaration>node);
|
||||
case SyntaxKind.LabeledStatement: return checkLabeledStatement(<LabeledStatement>node);
|
||||
case SyntaxKind.LonghandPropertyAssignment: return checkLonghandPropertyAssignment(<LonghandPropertyAssignment>node);
|
||||
case SyntaxKind.PropertyAssignment: return checkPropertyAssignment(<PropertyAssignment>node);
|
||||
case SyntaxKind.Method: return checkMethod(<MethodDeclaration>node);
|
||||
case SyntaxKind.ModuleDeclaration: return checkModuleDeclaration(<ModuleDeclaration>node);
|
||||
case SyntaxKind.ObjectLiteralExpression: return checkObjectLiteralExpression(<ObjectLiteralExpression>node);
|
||||
@@ -5039,7 +5039,7 @@ module ts {
|
||||
// d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true
|
||||
// and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields
|
||||
var currentKind: number;
|
||||
if (prop.kind === SyntaxKind.LonghandPropertyAssignment ||
|
||||
if (prop.kind === SyntaxKind.PropertyAssignment ||
|
||||
prop.kind === SyntaxKind.ShorthandPropertyAssignment ||
|
||||
prop.kind === SyntaxKind.Method) {
|
||||
currentKind = Property;
|
||||
@@ -5342,7 +5342,7 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkLonghandPropertyAssignment(node: LonghandPropertyAssignment) {
|
||||
function checkPropertyAssignment(node: PropertyAssignment) {
|
||||
return checkForInvalidQuestionMark(node, node.questionToken, Diagnostics.An_object_member_cannot_be_declared_optional);
|
||||
}
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ module ts {
|
||||
CatchClause,
|
||||
|
||||
// Property assignments
|
||||
LonghandPropertyAssignment,
|
||||
PropertyAssignment,
|
||||
ShorthandPropertyAssignment,
|
||||
|
||||
// Enum
|
||||
@@ -383,17 +383,17 @@ module ts {
|
||||
export type VariableOrParameterDeclaration = VariableDeclaration | ParameterDeclaration;
|
||||
export type VariableOrParameterOrPropertyDeclaration = VariableOrParameterDeclaration | PropertyDeclaration;
|
||||
|
||||
export interface PropertyAssignment extends Declaration {
|
||||
_propertyAssignmentBrand: any;
|
||||
export interface ObjectLiteralElement extends Declaration {
|
||||
_objectLiteralBrandBrand: any;
|
||||
}
|
||||
|
||||
export interface ShorthandPropertyAssignment extends PropertyAssignment {
|
||||
export interface ShorthandPropertyAssignment extends ObjectLiteralElement {
|
||||
name: Identifier;
|
||||
questionToken?: Node;
|
||||
}
|
||||
|
||||
export interface LonghandPropertyAssignment extends PropertyAssignment {
|
||||
_longhandPropertyAssignmentBrand: any;
|
||||
export interface PropertyAssignment extends ObjectLiteralElement {
|
||||
_propertyAssignmentBrand: any;
|
||||
name: DeclarationName;
|
||||
questionToken?: Node;
|
||||
initializer: Expression;
|
||||
@@ -420,7 +420,16 @@ module ts {
|
||||
body?: Block;
|
||||
}
|
||||
|
||||
export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, PropertyAssignment {
|
||||
// Note that a MethodDeclaration is considered both a ClassElement and an ObjectLiteralElement.
|
||||
// Both the grammars for ClassDeclaration and ObjectLiteralExpression allow for MethodDeclarations
|
||||
// as child elements, and so a MethodDeclaration satisfies both interfaces. This avoids the
|
||||
// alternative where we would need separate kinds/types for ClassMethodDeclaration and
|
||||
// ObjectLiteralMethodDeclaration, which would look identical.
|
||||
//
|
||||
// Because of this, it may be necessary to determine what sort of MethodDeclaration you have
|
||||
// at later stages of the compiler pipeline. In that case, you can either check the parent kind
|
||||
// of the method, or use helpers like isObjectLiteralMethodDeclaration
|
||||
export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement {
|
||||
contextualType?: Type; // Used to temporarily assign a contextual type during overload resolution
|
||||
|
||||
body?: Block;
|
||||
@@ -430,7 +439,9 @@ module ts {
|
||||
body?: Block;
|
||||
}
|
||||
|
||||
export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, PropertyAssignment {
|
||||
// See the comment on MethodDeclaration for the intuition behind AccessorDeclaration being a
|
||||
// ClassElement and an ObjectLiteralElement.
|
||||
export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement {
|
||||
_accessorDeclarationBrand: any;
|
||||
body: Block;
|
||||
}
|
||||
@@ -587,7 +598,7 @@ module ts {
|
||||
|
||||
// An ObjectLiteralExpression is the declaration node for an anonymous symbol.
|
||||
export interface ObjectLiteralExpression extends PrimaryExpression, Declaration {
|
||||
properties: NodeArray<PropertyAssignment>;
|
||||
properties: NodeArray<ObjectLiteralElement>;
|
||||
}
|
||||
|
||||
export interface PropertyAccessExpression extends MemberExpression {
|
||||
|
||||
@@ -102,10 +102,10 @@ module ts.BreakpointResolver {
|
||||
return spanInFunctionDeclaration(<FunctionLikeDeclaration>node);
|
||||
|
||||
case SyntaxKind.Block:
|
||||
return isFunctionBlock(node)
|
||||
? spanInFunctionBlock(<Block>node)
|
||||
: spanInBlock(<Block>node);
|
||||
|
||||
if (isFunctionBlock(node)) {
|
||||
return spanInFunctionBlock(<Block>node);
|
||||
}
|
||||
// Fall through
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
@@ -240,7 +240,7 @@ module ts.BreakpointResolver {
|
||||
|
||||
default:
|
||||
// If this is name of property assignment, set breakpoint in the initializer
|
||||
if (node.parent.kind === SyntaxKind.LonghandPropertyAssignment && (<PropertyDeclaration>node.parent).name === node) {
|
||||
if (node.parent.kind === SyntaxKind.PropertyAssignment && (<PropertyDeclaration>node.parent).name === node) {
|
||||
return spanInNode((<PropertyDeclaration>node.parent).initializer);
|
||||
}
|
||||
|
||||
@@ -483,7 +483,7 @@ module ts.BreakpointResolver {
|
||||
|
||||
function spanInColonToken(node: Node): TextSpan {
|
||||
// Is this : specifying return annotation of the function declaration
|
||||
if (isAnyFunction(node.parent) || node.parent.kind === SyntaxKind.LonghandPropertyAssignment) {
|
||||
if (isAnyFunction(node.parent) || node.parent.kind === SyntaxKind.PropertyAssignment) {
|
||||
return spanInPreviousNode(node);
|
||||
}
|
||||
|
||||
|
||||
@@ -1973,14 +1973,14 @@ module ts {
|
||||
/** Returns true if node is a name of an object literal property, e.g. "a" in x = { "a": 1 } */
|
||||
function isNameOfPropertyAssignment(node: Node): boolean {
|
||||
return (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) &&
|
||||
(node.parent.kind === SyntaxKind.LonghandPropertyAssignment || node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) && (<PropertyDeclaration>node.parent).name === node;
|
||||
(node.parent.kind === SyntaxKind.PropertyAssignment || node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) && (<PropertyDeclaration>node.parent).name === node;
|
||||
}
|
||||
|
||||
function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: Node): boolean {
|
||||
if (node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) {
|
||||
switch (node.parent.kind) {
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.LonghandPropertyAssignment:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.EnumMember:
|
||||
case SyntaxKind.Method:
|
||||
case SyntaxKind.GetAccessor:
|
||||
@@ -2647,7 +2647,7 @@ module ts {
|
||||
|
||||
var existingMemberNames: Map<boolean> = {};
|
||||
forEach(existingMembers, m => {
|
||||
if (m.kind !== SyntaxKind.LonghandPropertyAssignment && m.kind !== SyntaxKind.ShorthandPropertyAssignment) {
|
||||
if (m.kind !== SyntaxKind.PropertyAssignment && m.kind !== SyntaxKind.ShorthandPropertyAssignment) {
|
||||
// Ignore omitted expressions for missing members in the object literal
|
||||
return;
|
||||
}
|
||||
@@ -4717,7 +4717,7 @@ module ts {
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.LonghandPropertyAssignment:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
case SyntaxKind.EnumMember:
|
||||
case SyntaxKind.Method:
|
||||
|
||||
Reference in New Issue
Block a user