Also split out .PropertyDeclaration and .PropertySignature from .Property.

This commit is contained in:
Cyrus Najmabadi
2014-12-08 16:37:35 -08:00
parent c1b19d761d
commit cc83925f32
9 changed files with 77 additions and 43 deletions
+2 -1
View File
@@ -397,7 +397,8 @@ module ts {
bindDeclaration(<Declaration>node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes, /*isBlockScopeContainer*/ false);
}
break;
case SyntaxKind.Property:
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShorthandPropertyAssignment:
bindDeclaration(<Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
+25 -14
View File
@@ -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(<Declaration>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) &&
!!(<PropertyDeclaration>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(<TypeParameterDeclaration>node);
case SyntaxKind.Parameter:
return checkParameter(<ParameterDeclaration>node);
case SyntaxKind.Property:
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
return checkPropertyDeclaration(<PropertyDeclaration>node);
case SyntaxKind.FunctionType:
case SyntaxKind.ConstructorType:
@@ -8689,7 +8698,8 @@ module ts {
checkFunctionExpressionBodies((<WithStatement>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 === (<TypeParameterDeclaration>parent).constraint;
case SyntaxKind.Property:
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
case SyntaxKind.Parameter:
case SyntaxKind.VariableDeclaration:
return node === (<VariableDeclaration>parent).type;
+8 -6
View File
@@ -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(<AccessorDeclaration>node);
case SyntaxKind.VariableStatement:
return emitVariableStatement(<VariableStatement>node);
case SyntaxKind.Property:
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
return emitPropertyDeclaration(<PropertyDeclaration>node);
case SyntaxKind.InterfaceDeclaration:
return emitInterfaceDeclaration(<InterfaceDeclaration>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 && (<PropertyDeclaration>member).initializer) {
if (member.kind === SyntaxKind.PropertyDeclaration && (member.flags & NodeFlags.Static) === staticFlag && (<PropertyDeclaration>member).initializer) {
writeLine();
emitLeadingComments(member);
emitStart(member);
+19 -10
View File
@@ -272,7 +272,8 @@ module ts {
child((<ParameterDeclaration>node).questionToken) ||
child((<ParameterDeclaration>node).type) ||
child((<ParameterDeclaration>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 (<VariableDeclaration>parent).initializer === node;
@@ -703,7 +707,8 @@ module ts {
return (<MethodDeclaration>node).questionToken !== undefined;
case SyntaxKind.ShorthandPropertyAssignment:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.Property:
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
return (<PropertyDeclaration>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 = <PropertyDeclaration>createNode(SyntaxKind.Property, fullStart);
var property = <PropertyDeclaration>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 = <PropertyDeclaration>createNode(SyntaxKind.Property, fullStart);
var property = <PropertyDeclaration>createNode(SyntaxKind.PropertyDeclaration, fullStart);
setModifiers(property, modifiers);
property.name = name;
property.questionToken = questionToken;
@@ -4566,7 +4572,9 @@ module ts {
case SyntaxKind.Parameter: return checkParameter(<ParameterDeclaration>node);
case SyntaxKind.PostfixUnaryExpression: return checkPostfixUnaryExpression(<PostfixUnaryExpression>node);
case SyntaxKind.PrefixUnaryExpression: return checkPrefixUnaryExpression(<PrefixUnaryExpression>node);
case SyntaxKind.Property: return checkProperty(<PropertyDeclaration>node);
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
return checkProperty(<PropertyDeclaration>node);
case SyntaxKind.ReturnStatement: return checkReturnStatement(<ReturnStatement>node);
case SyntaxKind.SetAccessor: return checkSetAccessor(<MethodDeclaration>node);
case SyntaxKind.SourceFile: return checkSourceFile(<SourceFile>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:
+2 -1
View File
@@ -147,7 +147,8 @@ module ts {
TypeParameter,
Parameter,
// TypeMember
Property,
PropertySignature,
PropertyDeclaration,
MethodSignature,
MethodDeclaration,
Constructor,
+2 -1
View File
@@ -86,7 +86,8 @@ module ts.BreakpointResolver {
return spanInVariableDeclaration((<VariableStatement>node).declarations[0]);
case SyntaxKind.VariableDeclaration:
case SyntaxKind.Property:
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
return spanInVariableDeclaration(<VariableDeclaration>node);
case SyntaxKind.Parameter:
+2 -1
View File
@@ -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:
+2 -1
View File
@@ -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((<PropertyDeclaration>node).name), ts.ScriptElementKind.memberVariableElement);
case SyntaxKind.FunctionDeclaration:
+15 -8
View File
@@ -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(<Declaration>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: