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

Destructuring #1346

Merged
merged 38 commits into from
Dec 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
86f290f
Initial parser support for destructuring patterns
ahejlsberg Nov 5, 2014
a01b440
Rework tracking and error reporting related to widening of types
ahejlsberg Nov 6, 2014
2d3752e
Merge branch 'master' into destructuring
ahejlsberg Nov 6, 2014
3d3212b
Adding binding patterns to declaration names
ahejlsberg Nov 7, 2014
af00c71
End-to-end support for destructuring in variable declarations
ahejlsberg Nov 10, 2014
3cda261
Rudimentary support in language service
ahejlsberg Nov 11, 2014
bd65f16
Parser errors for destructuring declarations
ahejlsberg Nov 11, 2014
a6401bb
Adding destructuring variable declaration error messages
ahejlsberg Nov 12, 2014
7840f0d
Moving error reporting to getWidenedTypeForVariableDeclaration
ahejlsberg Nov 12, 2014
850f3cb
Destructuring parameter declarations
ahejlsberg Nov 19, 2014
2ed5f41
Destructuring of tuple type cannot specify extra variables
ahejlsberg Nov 20, 2014
58c3c2f
Merge branch 'master' into destructuring
ahejlsberg Nov 20, 2014
d39749f
Adding SyntaxKind.FunctionType/ConstructorType to isAnyFunction
ahejlsberg Nov 20, 2014
607140b
Support for destructuring assignments
ahejlsberg Nov 21, 2014
38a2640
Propagate node kind in variable/parameter destructuring declarations
ahejlsberg Nov 22, 2014
6b96386
Allow string or numeric literal as property name of object binding
ahejlsberg Nov 22, 2014
8ed1f24
Fine tuning array and tuple type checks in destructuring
ahejlsberg Nov 23, 2014
d8ecd8c
Fixed bug in union type identity comparison
ahejlsberg Nov 24, 2014
98eaca5
Accepting new baselines
ahejlsberg Nov 28, 2014
cf3e3ac
Rewriting and emit for destructuring declarations
ahejlsberg Nov 28, 2014
28a73bc
Emit of rest parameter for loop uses unique temporary variable name
ahejlsberg Nov 29, 2014
ec7ce72
Removing unused diagnostics related to '_i' variable name
ahejlsberg Nov 29, 2014
501a370
Accepting new baselines
ahejlsberg Nov 29, 2014
3ff2a62
Allow assignment expressions as destructuring assignment target
ahejlsberg Nov 30, 2014
9e63911
Emit for destructuring assignments
ahejlsberg Dec 2, 2014
ab35da9
Baseline changes from updating rest parameter emit to use new tempora…
ahejlsberg Dec 2, 2014
7994e90
Emit for destructuring parameter declarations
ahejlsberg Dec 2, 2014
0731a28
Support exported destructuring variable declarations
ahejlsberg Dec 2, 2014
dc39de1
Removing fourslash test that no longer applies
ahejlsberg Dec 2, 2014
ecfcb9d
Fixing fourslash test
ahejlsberg Dec 3, 2014
65d1510
Adding rudimentary tests
ahejlsberg Dec 3, 2014
816abb1
Merge branch 'master' into destructuring
ahejlsberg Dec 4, 2014
b49e277
Addressing CR feedback
ahejlsberg Dec 5, 2014
4118ffc
Accepting new baselines
ahejlsberg Dec 5, 2014
05c9966
Addressing CR feedback:
ahejlsberg Dec 6, 2014
b3dffff
Addressing a bit more CR feedback
ahejlsberg Dec 6, 2014
459dee0
Merge branch 'master' into destructuring
ahejlsberg Dec 8, 2014
7bc35b3
Merge branch 'master' into destructuring
ahejlsberg Dec 9, 2014
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
41 changes: 24 additions & 17 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,9 @@ module ts {
// symbol as its sole member. To the rest of the system, this symbol will be indistinguishable
// from an actual type literal symbol you would have gotten had you used the long form.

var symbolKind = node.kind === SyntaxKind.FunctionType ? SymbolFlags.CallSignature : SymbolFlags.ConstructSignature;
var symbol = createSymbol(symbolKind, getDeclarationName(node));
addDeclarationToSymbol(symbol, node, symbolKind);
bindChildren(node, symbolKind, /*isBlockScopeContainer:*/ false);
var symbol = createSymbol(SymbolFlags.Signature, getDeclarationName(node));
addDeclarationToSymbol(symbol, node, SymbolFlags.Signature);
bindChildren(node, SymbolFlags.Signature, /*isBlockScopeContainer:*/ false);

var typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
Expand Down Expand Up @@ -376,21 +375,33 @@ module ts {
}
declareSymbol(blockScopeContainer.locals, undefined, node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes);
}

bindChildren(node, SymbolFlags.BlockScopedVariable, /*isBlockScopeContainer*/ false);
}

function getDestructuringParameterName(node: Declaration) {
return "__" + indexOf((<SignatureDeclaration>node.parent).parameters, node);
}

function bind(node: Node) {
node.parent = parent;
switch (node.kind) {
case SyntaxKind.TypeParameter:
bindDeclaration(<Declaration>node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.Parameter:
bindDeclaration(<Declaration>node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false);
if (isBindingPattern((<Declaration>node).name)) {
bindAnonymousDeclaration(<Declaration>node, SymbolFlags.FunctionScopedVariable, getDestructuringParameterName(<Declaration>node), /*isBlockScopeContainer*/ false);
}
else {
bindDeclaration(<Declaration>node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false);
}
break;
case SyntaxKind.VariableDeclaration:
if (node.flags & NodeFlags.BlockScoped) {
case SyntaxKind.BindingElement:
if (isBindingPattern((<Declaration>node).name)) {
bindChildren(node, 0, /*isBlockScopeContainer*/ false);
}
else if (node.flags & NodeFlags.BlockScoped) {
bindBlockScopedVariableDeclaration(<Declaration>node);
}
else {
Expand All @@ -399,6 +410,8 @@ module ts {
break;
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
bindDeclaration(<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);
Expand All @@ -407,23 +420,19 @@ module ts {
bindDeclaration(<Declaration>node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.CallSignature:
bindDeclaration(<Declaration>node, SymbolFlags.CallSignature, 0, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.ConstructSignature:
bindDeclaration(<Declaration>node, SymbolFlags.ConstructSignature, 0, /*isBlockScopeContainer*/ true);
case SyntaxKind.IndexSignature:
bindDeclaration(<Declaration>node, SymbolFlags.Signature, 0, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
// If this is an ObjectLiteralExpression method, then it sits in the same space
// 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,
bindDeclaration(<Declaration>node, SymbolFlags.Method | ((<MethodDeclaration>node).questionToken ? SymbolFlags.Optional : 0),
isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true);
break;
case SyntaxKind.IndexSignature:
bindDeclaration(<Declaration>node, SymbolFlags.IndexSignature, 0, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.FunctionDeclaration:
bindDeclaration(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes, /*isBlockScopeContainer*/ true);
break;
Expand Down Expand Up @@ -483,17 +492,15 @@ module ts {
bindAnonymousDeclaration(<SourceFile>node, SymbolFlags.ValueModule, '"' + removeFileExtension((<SourceFile>node).filename) + '"', /*isBlockScopeContainer*/ true);
break;
}

case SyntaxKind.Block:
case SyntaxKind.TryBlock:
case SyntaxKind.CatchClause:
case SyntaxKind.FinallyBlock:
case SyntaxKind.ForStatement:
case SyntaxKind.ForInStatement:
case SyntaxKind.SwitchStatement:
bindChildren(node, 0 , true);
bindChildren(node, 0, /*isBlockScopeContainer*/ true);
break;

default:
var saveParent = parent;
parent = node;
Expand Down
Loading