-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
156 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2654,7 +2654,16 @@ module ts { | |
error(Diagnostics.Variable_declaration_list_cannot_be_empty); | ||
} | ||
if (languageVersion < ScriptTarget.ES6) { | ||
grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.let_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); | ||
grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); | ||
} | ||
} | ||
else if (parseOptional(SyntaxKind.ConstKeyword)) { | ||
var declarations = parseVariableDeclarationList(NodeFlags.Const, true); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mhegazy
Author
Contributor
|
||
if (!declarations.length) { | ||
error(Diagnostics.Variable_declaration_list_cannot_be_empty); | ||
} | ||
if (languageVersion < ScriptTarget.ES6) { | ||
grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); | ||
} | ||
} | ||
else { | ||
|
@@ -3145,10 +3154,10 @@ module ts { | |
} | ||
if (languageVersion < ScriptTarget.ES6) { | ||
if (node.flags & NodeFlags.Let) { | ||
grammarErrorOnNode(node, Diagnostics.let_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); | ||
grammarErrorOnNode(node, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); | ||
} | ||
else if (node.flags & NodeFlags.Const) { | ||
grammarErrorOnNode(node, Diagnostics.const_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); | ||
grammarErrorOnNode(node, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); | ||
} | ||
} | ||
else if (!allowLetDeclarations){ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
tests/cases/compiler/constDeclarations-es5.ts(2,1): error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. | ||
tests/cases/compiler/constDeclarations-es5.ts(3,1): error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. | ||
tests/cases/compiler/constDeclarations-es5.ts(4,1): error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. | ||
tests/cases/compiler/constDeclarations-es5.ts(2,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. | ||
tests/cases/compiler/constDeclarations-es5.ts(3,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. | ||
tests/cases/compiler/constDeclarations-es5.ts(4,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. | ||
|
||
|
||
==== tests/cases/compiler/constDeclarations-es5.ts (3 errors) ==== | ||
|
||
const z7 = false; | ||
~~~~~~~~~~~~~~~~~ | ||
!!! error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. | ||
!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. | ||
const z8: number = 23; | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. | ||
!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. | ||
const z9 = 0, z10 :string = "", z11 = null; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. | ||
!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//// [constDeclarations-scopes2.ts] | ||
|
||
// global | ||
const c = "string"; | ||
|
||
var n: number; | ||
var b: boolean; | ||
|
||
// for scope | ||
for (const c = 0; c < 10; n = c ) { | ||
// for block | ||
const c = false; | ||
b = c; | ||
} | ||
|
||
|
||
|
||
//// [constDeclarations-scopes2.js] | ||
// global | ||
const c = "string"; | ||
var n; | ||
var b; | ||
for (var c = 0; c < 10; n = c) { | ||
// for block | ||
const c = false; | ||
b = c; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
=== tests/cases/compiler/constDeclarations-scopes2.ts === | ||
|
||
// global | ||
const c = "string"; | ||
>c : string | ||
|
||
var n: number; | ||
>n : number | ||
|
||
var b: boolean; | ||
>b : boolean | ||
|
||
// for scope | ||
for (const c = 0; c < 10; n = c ) { | ||
>c : number | ||
>c < 10 : boolean | ||
>c : number | ||
>n = c : number | ||
>n : number | ||
>c : number | ||
|
||
// for block | ||
const c = false; | ||
>c : boolean | ||
|
||
b = c; | ||
>b = c : boolean | ||
>b : boolean | ||
>c : boolean | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// @target: ES6 | ||
|
||
// global | ||
const c = "string"; | ||
|
||
var n: number; | ||
var b: boolean; | ||
|
||
// for scope | ||
for (const c = 0; c < 10; n = c ) { | ||
// for block | ||
const c = false; | ||
b = c; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
So ES6 permits a const declaration in a for statement, but it is still an error to re-assign the const, right? Not sure why you'd ever want to do that, but if that's what ES6 says then so be it.