Merge pull request #2323 from Microsoft/letConstInDestructuringInNotStrictMode

correctly parse destructuring in let outside of strict mode
This commit is contained in:
Vladimir Matveev 2015-03-13 13:34:06 -07:00
commit 82a940df06
4 changed files with 32 additions and 2 deletions

View File

@ -2975,6 +2975,12 @@ module ts {
return !scanner.hasPrecedingLineBreak() && isIdentifier()
}
function nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine() {
nextToken();
return !scanner.hasPrecedingLineBreak() &&
(isIdentifier() || token === SyntaxKind.OpenBraceToken || token === SyntaxKind.OpenBracketToken);
}
function parseYieldExpression(): YieldExpression {
var node = <YieldExpression>createNode(SyntaxKind.YieldExpression);
@ -4873,9 +4879,9 @@ module ts {
}
function isLetDeclaration() {
// It is let declaration if in strict mode or next token is identifier on same line.
// It is let declaration if in strict mode or next token is identifier\open bracket\open curly on same line.
// otherwise it needs to be treated like identifier
return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOnSameLine);
return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine);
}
function isDeclarationStart(): boolean {

View File

@ -0,0 +1,11 @@
//// [letInNonStrictMode.ts]
let [x] = [1];
let {a: y} = {a: 1};
//// [letInNonStrictMode.js]
var x = ([
1
])[0];
var y = ({
a: 1
}).a;

View File

@ -0,0 +1,11 @@
=== tests/cases/compiler/letInNonStrictMode.ts ===
let [x] = [1];
>x : number
>[1] : [number]
let {a: y} = {a: 1};
>a : unknown
>y : number
>{a: 1} : { a: number; }
>a : number

View File

@ -0,0 +1,2 @@
let [x] = [1];
let {a: y} = {a: 1};