From cc83925f323551ab841d5b70aff66746a4e9c596 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 8 Dec 2014 16:37:35 -0800 Subject: [PATCH] Also split out .PropertyDeclaration and .PropertySignature from .Property. --- src/compiler/binder.ts | 3 ++- src/compiler/checker.ts | 39 ++++++++++++++++++++------------ src/compiler/emitter.ts | 14 +++++++----- src/compiler/parser.ts | 29 ++++++++++++++++-------- src/compiler/types.ts | 3 ++- src/services/breakpoints.ts | 3 ++- src/services/formatting/rules.ts | 3 ++- src/services/navigationBar.ts | 3 ++- src/services/services.ts | 23 ++++++++++++------- 9 files changed, 77 insertions(+), 43 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index d98f7dc844b..281985b0ba0 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -397,7 +397,8 @@ module ts { bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes, /*isBlockScopeContainer*/ false); } break; - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: bindDeclaration(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2ef8d7efe79..4690d0ad75d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -361,7 +361,8 @@ module ts { break loop; } break; - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: // TypeScript 1.0 spec (April 2014): 8.4.1 // Initializer expressions for instance member variables are evaluated in the scope // of the class constructor body but are not permitted to reference parameters or @@ -1622,7 +1623,8 @@ module ts { // Exported members/ambient module elements (exception import declaration) are visible if parent is visible return isDeclarationVisible(parent); - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.MethodDeclaration: @@ -1740,7 +1742,8 @@ module ts { return; } switch (declaration.kind) { - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: var diagnostic = Diagnostics.Member_0_implicitly_has_an_1_type; break; case SyntaxKind.Parameter: @@ -4631,7 +4634,7 @@ module ts { function captureLexicalThis(node: Node, container: Node): void { var classNode = container.parent && container.parent.kind === SyntaxKind.ClassDeclaration ? container.parent : undefined; getNodeLinks(node).flags |= NodeCheckFlags.LexicalThis; - if (container.kind === SyntaxKind.Property || container.kind === SyntaxKind.Constructor) { + if (container.kind === SyntaxKind.PropertyDeclaration || container.kind === SyntaxKind.Constructor) { getNodeLinks(classNode).flags |= NodeCheckFlags.CaptureThis; } else { @@ -4666,7 +4669,8 @@ module ts { // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks } break; - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: if (container.flags & NodeFlags.Static) { error(node, Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer); // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks @@ -4694,7 +4698,8 @@ module ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: @@ -4765,7 +4770,8 @@ module ts { container.kind === SyntaxKind.MethodSignature || container.kind === SyntaxKind.GetAccessor || container.kind === SyntaxKind.SetAccessor || - container.kind === SyntaxKind.Property || + container.kind === SyntaxKind.PropertyDeclaration || + container.kind === SyntaxKind.PropertySignature || container.kind === SyntaxKind.Constructor; } } @@ -5010,7 +5016,8 @@ module ts { switch (parent.kind) { case SyntaxKind.VariableDeclaration: case SyntaxKind.Parameter: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return getContextualTypeForInitializerExpression(node); case SyntaxKind.ArrowFunction: case SyntaxKind.ReturnStatement: @@ -5229,7 +5236,7 @@ module ts { // If a symbol is a synthesized symbol with no value declaration, we assume it is a property. Example of this are the synthesized // '.prototype' property as well as synthesized tuple index properties. function getDeclarationKindFromSymbol(s: Symbol) { - return s.valueDeclaration ? s.valueDeclaration.kind : SyntaxKind.Property; + return s.valueDeclaration ? s.valueDeclaration.kind : SyntaxKind.PropertyDeclaration; } function getDeclarationFlagsFromSymbol(s: Symbol) { @@ -6952,7 +6959,7 @@ module ts { } function isInstancePropertyWithInitializer(n: Node): boolean { - return n.kind === SyntaxKind.Property && + return n.kind === SyntaxKind.PropertyDeclaration && !(n.flags & NodeFlags.Static) && !!(n).initializer; } @@ -7569,7 +7576,8 @@ module ts { return false; } - if (node.kind === SyntaxKind.Property || + if (node.kind === SyntaxKind.PropertyDeclaration || + node.kind === SyntaxKind.PropertySignature || node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || node.kind === SyntaxKind.GetAccessor || @@ -8573,7 +8581,8 @@ module ts { return checkTypeParameter(node); case SyntaxKind.Parameter: return checkParameter(node); - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return checkPropertyDeclaration(node); case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: @@ -8689,7 +8698,8 @@ module ts { checkFunctionExpressionBodies((node).expression); break; case SyntaxKind.Parameter: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.PropertyAssignment: @@ -8946,7 +8956,8 @@ module ts { switch (parent.kind) { case SyntaxKind.TypeParameter: return node === (parent).constraint; - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: return node === (parent).type; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index ce4ac8ae46f..f84f19b256c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -950,10 +950,10 @@ module ts { if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) { writeTextOfNode(currentSourceFile, node.name); // If optional property emit ? - if (node.kind === SyntaxKind.Property && hasQuestionToken(node)) { + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) { write("?"); } - if (node.kind === SyntaxKind.Property && node.parent.kind === SyntaxKind.TypeLiteral) { + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } else if (!(node.flags & NodeFlags.Private)) { @@ -971,7 +971,7 @@ module ts { Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } // This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit - else if (node.kind === SyntaxKind.Property) { + else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) { // TODO(jfreeman): Deal with computed properties in error reporting. if (node.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? @@ -1363,7 +1363,8 @@ module ts { return emitAccessorDeclaration(node); case SyntaxKind.VariableStatement: return emitVariableStatement(node); - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return emitPropertyDeclaration(node); case SyntaxKind.InterfaceDeclaration: return emitInterfaceDeclaration(node); @@ -2132,7 +2133,8 @@ module ts { switch (parent.kind) { case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: @@ -2985,7 +2987,7 @@ module ts { function emitMemberAssignments(node: ClassDeclaration, staticFlag: NodeFlags) { forEach(node.members, member => { - if (member.kind === SyntaxKind.Property && (member.flags & NodeFlags.Static) === staticFlag && (member).initializer) { + if (member.kind === SyntaxKind.PropertyDeclaration && (member.flags & NodeFlags.Static) === staticFlag && (member).initializer) { writeLine(); emitLeadingComments(member); emitStart(member); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e40c074a56a..e9941421768 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -272,7 +272,8 @@ module ts { child((node).questionToken) || child((node).type) || child((node).initializer); - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: return children(node.modifiers) || @@ -554,7 +555,8 @@ module ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ModuleDeclaration: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: @@ -574,7 +576,8 @@ module ts { return undefined; } switch (node.kind) { - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: @@ -641,7 +644,8 @@ module ts { switch (parent.kind) { case SyntaxKind.VariableDeclaration: case SyntaxKind.Parameter: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.EnumMember: case SyntaxKind.PropertyAssignment: return (parent).initializer === node; @@ -703,7 +707,8 @@ module ts { return (node).questionToken !== undefined; case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.PropertyAssignment: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return (node).questionToken !== undefined; } } @@ -740,7 +745,8 @@ module ts { case SyntaxKind.TypeParameter: case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: @@ -2158,7 +2164,7 @@ module ts { return finishNode(method); } else { - var property = createNode(SyntaxKind.Property, fullStart); + var property = createNode(SyntaxKind.PropertySignature, fullStart); property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); @@ -3857,7 +3863,7 @@ module ts { return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, /*requireBlock:*/ false); } else { - var property = createNode(SyntaxKind.Property, fullStart); + var property = createNode(SyntaxKind.PropertyDeclaration, fullStart); setModifiers(property, modifiers); property.name = name; property.questionToken = questionToken; @@ -4566,7 +4572,9 @@ module ts { case SyntaxKind.Parameter: return checkParameter(node); case SyntaxKind.PostfixUnaryExpression: return checkPostfixUnaryExpression(node); case SyntaxKind.PrefixUnaryExpression: return checkPrefixUnaryExpression(node); - case SyntaxKind.Property: return checkProperty(node); + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + return checkProperty(node); case SyntaxKind.ReturnStatement: return checkReturnStatement(node); case SyntaxKind.SetAccessor: return checkSetAccessor(node); case SyntaxKind.SourceFile: return checkSourceFile(node); @@ -5228,7 +5236,8 @@ module ts { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.Constructor: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.IndexSignature: diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 328ed3c6c06..44108c347ae 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -147,7 +147,8 @@ module ts { TypeParameter, Parameter, // TypeMember - Property, + PropertySignature, + PropertyDeclaration, MethodSignature, MethodDeclaration, Constructor, diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 68974cc3b69..3a2cc2ad7e7 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -86,7 +86,8 @@ module ts.BreakpointResolver { return spanInVariableDeclaration((node).declarations[0]); case SyntaxKind.VariableDeclaration: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return spanInVariableDeclaration(node); case SyntaxKind.Parameter: diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index d9cf61ae4a1..9b6f0cecb9d 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -458,7 +458,8 @@ module ts.formatting { // equal in p = 0; case SyntaxKind.Parameter: case SyntaxKind.EnumMember: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return context.currentTokenSpan.kind === SyntaxKind.EqualsToken || context.nextTokenSpan.kind === SyntaxKind.EqualsToken; // "in" keyword in for (var x in []) { } case SyntaxKind.ForInStatement: diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 56fca4ffdfe..0840ccbf7de 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -227,7 +227,8 @@ module ts.NavigationBar { case SyntaxKind.ConstructSignature: return createItem(node, "new()", ts.ScriptElementKind.constructSignatureElement); - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.memberVariableElement); case SyntaxKind.FunctionDeclaration: diff --git a/src/services/services.ts b/src/services/services.ts index 5eae06e759e..54c17f01019 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -824,7 +824,8 @@ module ts { // fall through case SyntaxKind.VariableDeclaration: case SyntaxKind.EnumMember: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: namedDeclarations.push(node); break; } @@ -1988,7 +1989,8 @@ module ts { function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: Node): boolean { if (node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) { switch (node.parent.kind) { - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.EnumMember: case SyntaxKind.MethodDeclaration: @@ -2605,7 +2607,7 @@ module ts { containingNodeKind === SyntaxKind.InterfaceDeclaration; // interface a { | case SyntaxKind.SemicolonToken: - return containingNodeKind === SyntaxKind.Property && + return containingNodeKind === SyntaxKind.PropertySignature && previousToken.parent.parent.kind === SyntaxKind.InterfaceDeclaration; // interface a { f; | case SyntaxKind.PublicKeyword: @@ -2854,7 +2856,9 @@ module ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: return ScriptElementKind.memberFunctionElement; - case SyntaxKind.Property: return ScriptElementKind.memberVariableElement; + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + return ScriptElementKind.memberVariableElement; case SyntaxKind.IndexSignature: return ScriptElementKind.indexSignatureElement; case SyntaxKind.ConstructSignature: return ScriptElementKind.constructSignatureElement; case SyntaxKind.CallSignature: return ScriptElementKind.callSignatureElement; @@ -4277,7 +4281,8 @@ module ts { var staticFlag = NodeFlags.Static; switch (searchSpaceNode.kind) { - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: @@ -4328,8 +4333,9 @@ module ts { if (isObjectLiteralMethod(searchSpaceNode)) { break; } - // fall through - case SyntaxKind.Property: + // fall through + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -4740,7 +4746,8 @@ module ts { switch (node.kind) { case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: