Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computed properties (but not known symbols) #1752

Merged
merged 28 commits into from
Jan 26, 2015
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
15187e5
Enable computed properties
JsonFreeman Jan 6, 2015
d192fea
Switch checkObjectLiteral to iterate over element declarations
JsonFreeman Jan 6, 2015
ef06879
Create symbols for computed properties
JsonFreeman Jan 9, 2015
7192767
Add type checking for computed properties in object literals
JsonFreeman Jan 10, 2015
4ac2b4b
Add tests for object literals with computed properties
JsonFreeman Jan 12, 2015
4c0122d
Move computed property checks so that they will be checked in classes…
JsonFreeman Jan 13, 2015
de3eb36
Update baselines
JsonFreeman Jan 13, 2015
96b5f1f
Add tests for classes, methods, accessors with computed properties
JsonFreeman Jan 14, 2015
4c5db71
Remove some unnecessary TODOs
JsonFreeman Jan 14, 2015
1b35a1b
Contextual typing for computed properties
JsonFreeman Jan 14, 2015
1973b42
Indexers in object literals include computed property types
JsonFreeman Jan 15, 2015
f943f6c
Adjust error numbers
JsonFreeman Jan 16, 2015
4cc2722
Disallow this in computed properties in classes
JsonFreeman Jan 17, 2015
e317767
Consolidate getSuperContainer
JsonFreeman Jan 17, 2015
b5349a5
Disallow super and fix this capturing for computed properties
JsonFreeman Jan 20, 2015
89f36bb
Disallow computed properties referencing type parameters from contain…
JsonFreeman Jan 20, 2015
85219ee
Check computed properties against indexers in classes
JsonFreeman Jan 21, 2015
26da378
Move subroutine function to the bottom of checkIndexConstraints
JsonFreeman Jan 21, 2015
eb7798f
Skip computed properties on declaration emit
JsonFreeman Jan 21, 2015
de5aa6c
Fix source map scope name for computed properties
JsonFreeman Jan 21, 2015
b022ccd
Merge branch 'master' into computedProperties
JsonFreeman Jan 21, 2015
768d818
Fix error message wording
JsonFreeman Jan 21, 2015
eeb4dc4
Merge branch 'master' into computedProperties
JsonFreeman Jan 21, 2015
f7a8ba2
Use isTypeOfKind in computed property checks
JsonFreeman Jan 22, 2015
12fc418
Make isNumericComputedName call checkComputedPropertyName
JsonFreeman Jan 22, 2015
4a7aa7e
Address CR feedback
JsonFreeman Jan 23, 2015
9c9434b
Merge branch 'master' into computedProperties
JsonFreeman Jan 23, 2015
bd29ca8
Merge branch 'master' into computedProperties
JsonFreeman Jan 24, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ module ts {
}

function declareSymbol(symbols: SymbolTable, parent: Symbol, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags): Symbol {
// Nodes with computed property names will not get symbols, because the type checker
// does not make properties for them.
if (hasComputedNameButNotSymbol(node)) {
return undefined;
}
Debug.assert(!hasComputedNameButNotSymbol(node));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So ensure that either it does not have a computed name OR if it does, it has a symbol? I'm confused.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OR that it has no name!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to invent a term for this, and put a doc comment above the function that defines the term? I could call it a dynamic name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should discuss this; @yuit and I think that the "But" is a problem - it's just "And" but it indicates something that is contradictory in intuition.

hasDynamicName is not bad for starters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will change that. You're right, "but" is bad.


var name = getDeclarationName(node);
if (name !== undefined) {
Expand Down Expand Up @@ -395,14 +391,14 @@ module ts {
break;
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
bindDeclaration(<Declaration>node, SymbolFlags.Property | ((<PropertyDeclaration>node).questionToken ? SymbolFlags.Optional : 0), SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.Property | ((<PropertyDeclaration>node).questionToken ? SymbolFlags.Optional : 0), SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShorthandPropertyAssignment:
bindDeclaration(<Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.EnumMember:
bindDeclaration(<Declaration>node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes, /*isBlockScopeContainer*/ false);
bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.CallSignature:
case SyntaxKind.ConstructSignature:
Expand All @@ -415,7 +411,7 @@ module ts {
// as other properties in the object literal. So we use SymbolFlags.PropertyExcludes
// so that it will conflict with any other object literal members with the same
// name.
bindDeclaration(<Declaration>node, SymbolFlags.Method | ((<MethodDeclaration>node).questionToken ? SymbolFlags.Optional : 0),
bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.Method | ((<MethodDeclaration>node).questionToken ? SymbolFlags.Optional : 0),
isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true);
break;
case SyntaxKind.FunctionDeclaration:
Expand All @@ -425,10 +421,10 @@ module ts {
bindDeclaration(<Declaration>node, SymbolFlags.Constructor, /*symbolExcludes:*/ 0, /*isBlockScopeContainer:*/ true);
break;
case SyntaxKind.GetAccessor:
bindDeclaration(<Declaration>node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes, /*isBlockScopeContainer*/ true);
bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes, /*isBlockScopeContainer*/ true);
break;
case SyntaxKind.SetAccessor:
bindDeclaration(<Declaration>node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes, /*isBlockScopeContainer*/ true);
bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes, /*isBlockScopeContainer*/ true);
break;

case SyntaxKind.FunctionType:
Expand Down Expand Up @@ -510,5 +506,14 @@ module ts {
declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
}
}

function bindPropertyOrMethodOrAccessor(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags, isBlockScopeContainer: boolean) {
if (hasComputedNameButNotSymbol(node)) {
bindAnonymousDeclaration(node, symbolKind, "__computed", isBlockScopeContainer);
}
else {
bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer);
}
}
}
}
Loading