Merge pull request #5898 from Microsoft/fix3475_let

Disallow let in let/const declaration regardless of target
This commit is contained in:
Yui
2015-12-03 22:27:33 -08:00
49 changed files with 736 additions and 65 deletions
+18 -4
View File
@@ -15965,13 +15965,27 @@ namespace ts {
if (forInOrOfStatement.initializer.kind === SyntaxKind.VariableDeclarationList) {
const variableList = <VariableDeclarationList>forInOrOfStatement.initializer;
if (!checkGrammarVariableDeclarationList(variableList)) {
if (variableList.declarations.length > 1) {
const declarations = variableList.declarations;
// declarations.length can be zero if there is an error in variable declaration in for-of or for-in
// See http://www.ecma-international.org/ecma-262/6.0/#sec-for-in-and-for-of-statements for details
// For example:
// var let = 10;
// for (let of [1,2,3]) {} // this is invalid ES6 syntax
// for (let in [1,2,3]) {} // this is invalid ES6 syntax
// We will then want to skip on grammar checking on variableList declaration
if (!declarations.length) {
return false;
}
if (declarations.length > 1) {
const diagnostic = forInOrOfStatement.kind === SyntaxKind.ForInStatement
? Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement
: Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement;
return grammarErrorOnFirstToken(variableList.declarations[1], diagnostic);
}
const firstDeclaration = variableList.declarations[0];
const firstDeclaration = declarations[0];
if (firstDeclaration.initializer) {
const diagnostic = forInOrOfStatement.kind === SyntaxKind.ForInStatement
? Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer
@@ -16170,7 +16184,7 @@ namespace ts {
}
}
const checkLetConstNames = languageVersion >= ScriptTarget.ES6 && (isLet(node) || isConst(node));
const checkLetConstNames = (isLet(node) || isConst(node));
// 1. LexicalDeclaration : LetOrConst BindingList ;
// It is a Syntax Error if the BoundNames of BindingList contains "let".
@@ -16184,7 +16198,7 @@ namespace ts {
function checkGrammarNameInLetOrConstDeclarations(name: Identifier | BindingPattern): boolean {
if (name.kind === SyntaxKind.Identifier) {
if ((<Identifier>name).text === "let") {
if ((<Identifier>name).originalKeywordKind === SyntaxKind.LetKeyword) {
return grammarErrorOnNode(name, Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations);
}
}
@@ -0,0 +1,22 @@
tests/cases/compiler/invalidLetInForOfAndForIn_ES5.ts(5,13): error TS1005: '=' expected.
tests/cases/compiler/invalidLetInForOfAndForIn_ES5.ts(5,20): error TS1005: ',' expected.
tests/cases/compiler/invalidLetInForOfAndForIn_ES5.ts(7,1): error TS1005: ';' expected.
==== tests/cases/compiler/invalidLetInForOfAndForIn_ES5.ts (3 errors) ====
// This should be an error
// More details: http://www.ecma-international.org/ecma-262/6.0/#sec-iteration-statements
var let = 10;
for (let of [1,2,3]) {}
~
!!! error TS1005: '=' expected.
~
!!! error TS1005: ',' expected.
for (let in [1,2,3]) {}
~~~
!!! error TS1005: ';' expected.
@@ -0,0 +1,18 @@
//// [invalidLetInForOfAndForIn_ES5.ts]
// This should be an error
// More details: http://www.ecma-international.org/ecma-262/6.0/#sec-iteration-statements
var let = 10;
for (let of [1,2,3]) {}
for (let in [1,2,3]) {}
//// [invalidLetInForOfAndForIn_ES5.js]
// This should be an error
// More details: http://www.ecma-international.org/ecma-262/6.0/#sec-iteration-statements
var let = 10;
for (let of = [1, 2, 3], { }; ; )
for ( in [1, 2, 3]) { }
@@ -0,0 +1,22 @@
tests/cases/compiler/invalidLetInForOfAndForIn_ES6.ts(5,13): error TS1005: '=' expected.
tests/cases/compiler/invalidLetInForOfAndForIn_ES6.ts(5,20): error TS1005: ',' expected.
tests/cases/compiler/invalidLetInForOfAndForIn_ES6.ts(7,1): error TS1005: ';' expected.
==== tests/cases/compiler/invalidLetInForOfAndForIn_ES6.ts (3 errors) ====
// This should be an error
// More details: http://www.ecma-international.org/ecma-262/6.0/#sec-iteration-statements
var let = 10;
for (let of [1,2,3]) {}
~
!!! error TS1005: '=' expected.
~
!!! error TS1005: ',' expected.
for (let in [1,2,3]) {}
~~~
!!! error TS1005: ';' expected.
@@ -0,0 +1,18 @@
//// [invalidLetInForOfAndForIn_ES6.ts]
// This should be an error
// More details: http://www.ecma-international.org/ecma-262/6.0/#sec-iteration-statements
var let = 10;
for (let of [1,2,3]) {}
for (let in [1,2,3]) {}
//// [invalidLetInForOfAndForIn_ES6.js]
// This should be an error
// More details: http://www.ecma-international.org/ecma-262/6.0/#sec-iteration-statements
var let = 10;
for (let of = [1, 2, 3], { }; ; )
for ( in [1, 2, 3]) { }
@@ -0,0 +1,6 @@
//// [letAsIdentifier2.ts]
function let() {}
//// [letAsIdentifier2.js]
function let() { }
@@ -0,0 +1,5 @@
=== tests/cases/compiler/letAsIdentifier2.ts ===
function let() {}
>let : Symbol(let, Decl(letAsIdentifier2.ts, 0, 0))
@@ -0,0 +1,5 @@
=== tests/cases/compiler/letAsIdentifier2.ts ===
function let() {}
>let : () => void
@@ -0,0 +1,16 @@
tests/cases/compiler/letInConstDeclarations_ES5.ts(3,15): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInConstDeclarations_ES5.ts(6,19): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
==== tests/cases/compiler/letInConstDeclarations_ES5.ts (2 errors) ====
// All use of let in const declaration should be an error
const x = 50, let = 5;
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
{
const x = 10, let = 20;
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
}
@@ -0,0 +1,15 @@
//// [letInConstDeclarations_ES5.ts]
// All use of let in const declaration should be an error
const x = 50, let = 5;
{
const x = 10, let = 20;
}
//// [letInConstDeclarations_ES5.js]
// All use of let in const declaration should be an error
var x = 50, let = 5;
{
var x_1 = 10, let_1 = 20;
}
@@ -0,0 +1,16 @@
tests/cases/compiler/letInConstDeclarations_ES6.ts(3,15): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInConstDeclarations_ES6.ts(6,19): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
==== tests/cases/compiler/letInConstDeclarations_ES6.ts (2 errors) ====
// All use of let in const declaration should be an error
const x = 50, let = 5;
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
{
const x = 10, let = 20;
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
}
@@ -0,0 +1,15 @@
//// [letInConstDeclarations_ES6.ts]
// All use of let in const declaration should be an error
const x = 50, let = 5;
{
const x = 10, let = 20;
}
//// [letInConstDeclarations_ES6.js]
// All use of let in const declaration should be an error
const x = 50, let = 5;
{
const x = 10, let = 20;
}
@@ -0,0 +1,48 @@
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES5.ts(3,10): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES5.ts(5,12): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES5.ts(7,10): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES5.ts(9,12): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES5.ts(12,11): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES5.ts(14,13): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES5.ts(16,11): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES5.ts(18,13): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
==== tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES5.ts (8 errors) ====
// Should be an error
for (let let of [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
for (const let of [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
for (let let in [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
for (const let in [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
{
for (let let of [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
for (const let of [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
for (let let in [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
for (const let in [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
}
@@ -0,0 +1,43 @@
//// [letInLetConstDeclOfForOfAndForIn_ES5.ts]
// Should be an error
for (let let of [1,2,3]) {}
for (const let of [1,2,3]) {}
for (let let in [1,2,3]) {}
for (const let in [1,2,3]) {}
{
for (let let of [1,2,3]) {}
for (const let of [1,2,3]) {}
for (let let in [1,2,3]) {}
for (const let in [1,2,3]) {}
}
//// [letInLetConstDeclOfForOfAndForIn_ES5.js]
// Should be an error
for (var _i = 0, _a = [1, 2, 3]; _i < _a.length; _i++) {
var let = _a[_i];
}
for (var _b = 0, _c = [1, 2, 3]; _b < _c.length; _b++) {
var let = _c[_b];
}
for (var let in [1, 2, 3]) { }
for (var let in [1, 2, 3]) { }
{
for (var _d = 0, _e = [1, 2, 3]; _d < _e.length; _d++) {
var let = _e[_d];
}
for (var _f = 0, _g = [1, 2, 3]; _f < _g.length; _f++) {
var let = _g[_f];
}
for (var let in [1, 2, 3]) { }
for (var let in [1, 2, 3]) { }
}
@@ -0,0 +1,48 @@
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES6.ts(3,10): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES6.ts(5,12): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES6.ts(7,10): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES6.ts(9,12): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES6.ts(12,11): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES6.ts(14,13): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES6.ts(16,11): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES6.ts(18,13): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
==== tests/cases/compiler/letInLetConstDeclOfForOfAndForIn_ES6.ts (8 errors) ====
// Should be an error
for (let let of [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
for (const let of [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
for (let let in [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
for (const let in [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
{
for (let let of [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
for (const let of [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
for (let let in [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
for (const let in [1,2,3]) {}
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
}
@@ -0,0 +1,35 @@
//// [letInLetConstDeclOfForOfAndForIn_ES6.ts]
// Should be an error
for (let let of [1,2,3]) {}
for (const let of [1,2,3]) {}
for (let let in [1,2,3]) {}
for (const let in [1,2,3]) {}
{
for (let let of [1,2,3]) {}
for (const let of [1,2,3]) {}
for (let let in [1,2,3]) {}
for (const let in [1,2,3]) {}
}
//// [letInLetConstDeclOfForOfAndForIn_ES6.js]
// Should be an error
for (let let of [1, 2, 3]) { }
for (const let of [1, 2, 3]) { }
for (let let in [1, 2, 3]) { }
for (const let in [1, 2, 3]) { }
{
for (let let of [1, 2, 3]) { }
for (const let of [1, 2, 3]) { }
for (let let in [1, 2, 3]) { }
for (const let in [1, 2, 3]) { }
}
@@ -0,0 +1,16 @@
tests/cases/compiler/letInLetDeclarations_ES5.ts(3,13): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetDeclarations_ES5.ts(6,17): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
==== tests/cases/compiler/letInLetDeclarations_ES5.ts (2 errors) ====
// All use of let in const declaration should be an error
let x = 50, let = 5;
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
{
let x = 10, let = 20;
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
}
@@ -0,0 +1,15 @@
//// [letInLetDeclarations_ES5.ts]
// All use of let in const declaration should be an error
let x = 50, let = 5;
{
let x = 10, let = 20;
}
//// [letInLetDeclarations_ES5.js]
// All use of let in const declaration should be an error
var x = 50, let = 5;
{
var x_1 = 10, let_1 = 20;
}
@@ -0,0 +1,16 @@
tests/cases/compiler/letInLetDeclarations_ES6.ts(3,13): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetDeclarations_ES6.ts(6,17): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
==== tests/cases/compiler/letInLetDeclarations_ES6.ts (2 errors) ====
// All use of let in const declaration should be an error
let x = 50, let = 5;
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
{
let x = 10, let = 20;
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
}
@@ -0,0 +1,15 @@
//// [letInLetDeclarations_ES6.ts]
// All use of let in const declaration should be an error
let x = 50, let = 5;
{
let x = 10, let = 20;
}
//// [letInLetDeclarations_ES6.js]
// All use of let in const declaration should be an error
let x = 50, let = 5;
{
let x = 10, let = 20;
}
@@ -1,23 +0,0 @@
tests/cases/compiler/letInLetOrConstDeclarations.ts(2,9): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetOrConstDeclarations.ts(3,14): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/letInLetOrConstDeclarations.ts(6,11): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
==== tests/cases/compiler/letInLetOrConstDeclarations.ts (3 errors) ====
{
let let = 1; // should error
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
for (let let in []) { } // should error
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
}
{
const let = 1; // should error
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
}
{
function let() { // should be ok
}
}
@@ -1,25 +0,0 @@
//// [letInLetOrConstDeclarations.ts]
{
let let = 1; // should error
for (let let in []) { } // should error
}
{
const let = 1; // should error
}
{
function let() { // should be ok
}
}
//// [letInLetOrConstDeclarations.js]
{
let let = 1; // should error
for (let let in []) { } // should error
}
{
const let = 1; // should error
}
{
function let() {
}
}
@@ -0,0 +1,16 @@
//// [letInVarDeclOfForIn_ES5.ts]
// should not be an error
for (var let in [1,2,3]) {}
{
for (var let in [1,2,3]) {}
}
//// [letInVarDeclOfForIn_ES5.js]
// should not be an error
for (var let in [1, 2, 3]) { }
{
for (var let in [1, 2, 3]) { }
}
@@ -0,0 +1,11 @@
=== tests/cases/compiler/letInVarDeclOfForIn_ES5.ts ===
// should not be an error
for (var let in [1,2,3]) {}
>let : Symbol(let, Decl(letInVarDeclOfForIn_ES5.ts, 2, 8), Decl(letInVarDeclOfForIn_ES5.ts, 5, 9))
{
for (var let in [1,2,3]) {}
>let : Symbol(let, Decl(letInVarDeclOfForIn_ES5.ts, 2, 8), Decl(letInVarDeclOfForIn_ES5.ts, 5, 9))
}
@@ -0,0 +1,19 @@
=== tests/cases/compiler/letInVarDeclOfForIn_ES5.ts ===
// should not be an error
for (var let in [1,2,3]) {}
>let : any
>[1,2,3] : number[]
>1 : number
>2 : number
>3 : number
{
for (var let in [1,2,3]) {}
>let : any
>[1,2,3] : number[]
>1 : number
>2 : number
>3 : number
}
@@ -0,0 +1,16 @@
//// [letInVarDeclOfForIn_ES6.ts]
// should not be an error
for (var let in [1,2,3]) {}
{
for (var let in [1,2,3]) {}
}
//// [letInVarDeclOfForIn_ES6.js]
// should not be an error
for (var let in [1, 2, 3]) { }
{
for (var let in [1, 2, 3]) { }
}
@@ -0,0 +1,11 @@
=== tests/cases/compiler/letInVarDeclOfForIn_ES6.ts ===
// should not be an error
for (var let in [1,2,3]) {}
>let : Symbol(let, Decl(letInVarDeclOfForIn_ES6.ts, 2, 8), Decl(letInVarDeclOfForIn_ES6.ts, 5, 9))
{
for (var let in [1,2,3]) {}
>let : Symbol(let, Decl(letInVarDeclOfForIn_ES6.ts, 2, 8), Decl(letInVarDeclOfForIn_ES6.ts, 5, 9))
}
@@ -0,0 +1,19 @@
=== tests/cases/compiler/letInVarDeclOfForIn_ES6.ts ===
// should not be an error
for (var let in [1,2,3]) {}
>let : any
>[1,2,3] : number[]
>1 : number
>2 : number
>3 : number
{
for (var let in [1,2,3]) {}
>let : any
>[1,2,3] : number[]
>1 : number
>2 : number
>3 : number
}
@@ -0,0 +1,20 @@
//// [letInVarDeclOfForOf_ES5.ts]
// should not be an error
for (var let of [1,2,3]) {}
{
for (var let of [1,2,3]) {}
}
//// [letInVarDeclOfForOf_ES5.js]
// should not be an error
for (var _i = 0, _a = [1, 2, 3]; _i < _a.length; _i++) {
var let = _a[_i];
}
{
for (var _b = 0, _c = [1, 2, 3]; _b < _c.length; _b++) {
var let = _c[_b];
}
}
@@ -0,0 +1,11 @@
=== tests/cases/compiler/letInVarDeclOfForOf_ES5.ts ===
// should not be an error
for (var let of [1,2,3]) {}
>let : Symbol(let, Decl(letInVarDeclOfForOf_ES5.ts, 2, 8), Decl(letInVarDeclOfForOf_ES5.ts, 5, 9))
{
for (var let of [1,2,3]) {}
>let : Symbol(let, Decl(letInVarDeclOfForOf_ES5.ts, 2, 8), Decl(letInVarDeclOfForOf_ES5.ts, 5, 9))
}
@@ -0,0 +1,19 @@
=== tests/cases/compiler/letInVarDeclOfForOf_ES5.ts ===
// should not be an error
for (var let of [1,2,3]) {}
>let : number
>[1,2,3] : number[]
>1 : number
>2 : number
>3 : number
{
for (var let of [1,2,3]) {}
>let : number
>[1,2,3] : number[]
>1 : number
>2 : number
>3 : number
}
@@ -0,0 +1,16 @@
//// [letInVarDeclOfForOf_ES6.ts]
// should not be an error
for (var let of [1,2,3]) {}
{
for (var let of [1,2,3]) {}
}
//// [letInVarDeclOfForOf_ES6.js]
// should not be an error
for (var let of [1, 2, 3]) { }
{
for (var let of [1, 2, 3]) { }
}
@@ -0,0 +1,11 @@
=== tests/cases/compiler/letInVarDeclOfForOf_ES6.ts ===
// should not be an error
for (var let of [1,2,3]) {}
>let : Symbol(let, Decl(letInVarDeclOfForOf_ES6.ts, 2, 8), Decl(letInVarDeclOfForOf_ES6.ts, 5, 9))
{
for (var let of [1,2,3]) {}
>let : Symbol(let, Decl(letInVarDeclOfForOf_ES6.ts, 2, 8), Decl(letInVarDeclOfForOf_ES6.ts, 5, 9))
}
@@ -0,0 +1,19 @@
=== tests/cases/compiler/letInVarDeclOfForOf_ES6.ts ===
// should not be an error
for (var let of [1,2,3]) {}
>let : number
>[1,2,3] : number[]
>1 : number
>2 : number
>3 : number
{
for (var let of [1,2,3]) {}
>let : number
>[1,2,3] : number[]
>1 : number
>2 : number
>3 : number
}
@@ -1,6 +1,8 @@
tests/cases/compiler/strictModeReservedWord.ts(1,5): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/strictModeReservedWord.ts(5,9): error TS1212: Identifier expected. 'public' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(6,9): error TS1212: Identifier expected. 'static' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(7,9): error TS1212: Identifier expected. 'let' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(7,9): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
tests/cases/compiler/strictModeReservedWord.ts(8,9): error TS1212: Identifier expected. 'package' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(8,9): error TS2300: Duplicate identifier 'package'.
tests/cases/compiler/strictModeReservedWord.ts(9,14): error TS1212: Identifier expected. 'package' is a reserved word in strict mode
@@ -41,8 +43,10 @@ tests/cases/compiler/strictModeReservedWord.ts(24,5): error TS1212: Identifier e
tests/cases/compiler/strictModeReservedWord.ts(24,5): error TS2349: Cannot invoke an expression whose type lacks a call signature.
==== tests/cases/compiler/strictModeReservedWord.ts (41 errors) ====
==== tests/cases/compiler/strictModeReservedWord.ts (43 errors) ====
let let = 10;
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
function foo() {
"use strict"
@@ -55,6 +59,8 @@ tests/cases/compiler/strictModeReservedWord.ts(24,5): error TS2349: Cannot invok
let let = "blah";
~~~
!!! error TS1212: Identifier expected. 'let' is a reserved word in strict mode
~~~
!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
var package = "hello"
~~~~~~~
!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode
@@ -0,0 +1,10 @@
// @target: es6
// This should be an error
// More details: http://www.ecma-international.org/ecma-262/6.0/#sec-iteration-statements
var let = 10;
for (let of [1,2,3]) {}
for (let in [1,2,3]) {}
@@ -0,0 +1,10 @@
// @target: es6
// This should be an error
// More details: http://www.ecma-international.org/ecma-262/6.0/#sec-iteration-statements
var let = 10;
for (let of [1,2,3]) {}
for (let in [1,2,3]) {}
+3
View File
@@ -0,0 +1,3 @@
// @target: es6
function let() {}
@@ -0,0 +1,8 @@
// @target: es5
// All use of let in const declaration should be an error
const x = 50, let = 5;
{
const x = 10, let = 20;
}
@@ -0,0 +1,8 @@
// @target: es6
// All use of let in const declaration should be an error
const x = 50, let = 5;
{
const x = 10, let = 20;
}
@@ -0,0 +1,21 @@
// @target: es5
// Should be an error
for (let let of [1,2,3]) {}
for (const let of [1,2,3]) {}
for (let let in [1,2,3]) {}
for (const let in [1,2,3]) {}
{
for (let let of [1,2,3]) {}
for (const let of [1,2,3]) {}
for (let let in [1,2,3]) {}
for (const let in [1,2,3]) {}
}
@@ -0,0 +1,21 @@
// @target: es6
// Should be an error
for (let let of [1,2,3]) {}
for (const let of [1,2,3]) {}
for (let let in [1,2,3]) {}
for (const let in [1,2,3]) {}
{
for (let let of [1,2,3]) {}
for (const let of [1,2,3]) {}
for (let let in [1,2,3]) {}
for (const let in [1,2,3]) {}
}
@@ -0,0 +1,8 @@
// @target: es5
// All use of let in const declaration should be an error
let x = 50, let = 5;
{
let x = 10, let = 20;
}
@@ -0,0 +1,8 @@
// @target: es6
// All use of let in const declaration should be an error
let x = 50, let = 5;
{
let x = 10, let = 20;
}
@@ -1,12 +0,0 @@
// @target: es6
{
let let = 1; // should error
for (let let in []) { } // should error
}
{
const let = 1; // should error
}
{
function let() { // should be ok
}
}
@@ -0,0 +1,8 @@
// @target: es5
// should not be an error
for (var let in [1,2,3]) {}
{
for (var let in [1,2,3]) {}
}
@@ -0,0 +1,8 @@
// @target: es6
// should not be an error
for (var let in [1,2,3]) {}
{
for (var let in [1,2,3]) {}
}
@@ -0,0 +1,8 @@
// @target: es5
// should not be an error
for (var let of [1,2,3]) {}
{
for (var let of [1,2,3]) {}
}
@@ -0,0 +1,8 @@
// @target: es6
// should not be an error
for (var let of [1,2,3]) {}
{
for (var let of [1,2,3]) {}
}