Allow const and let declarations to be exported in modules. Also ensure that const module elements are not used as references.

This commit is contained in:
Mohamed Hegazy
2014-10-17 15:15:22 -07:00
parent 4ef68b9fb0
commit a5a6c6f242
24 changed files with 843 additions and 87 deletions

View File

@@ -5550,12 +5550,27 @@ module ts {
}
}
function isConstVariableReference(n: Node) {
if (n.kind === SyntaxKind.Identifier) {
var symbol = findSymbol(n);
return symbol && (symbol.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Const) !== 0;
function isConstVariableReference(n: Node): boolean {
switch (n.kind) {
case SyntaxKind.Identifier:
case SyntaxKind.PropertyAccess:
var symbol = findSymbol(n);
return symbol && (symbol.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Const) !== 0;
case SyntaxKind.IndexedAccess:
var index = (<IndexedAccess>n).index;
var symbol = findSymbol((<IndexedAccess>n).object);
if (symbol && index.kind === SyntaxKind.StringLiteral) {
var name = (<LiteralExpression>index).text;
var apparentType = getApparentType(getTypeOfSymbol(symbol));
var prop = getPropertyOfApparentType(apparentType, name);
return prop && (prop.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(prop) & NodeFlags.Const) !== 0;
}
return false;
case SyntaxKind.ParenExpression:
return isConstVariableReference((<ParenExpression>n).expression);
default:
return false;
}
return false;
}
if (!isReferenceOrErrorExpression(n)) {

View File

@@ -119,9 +119,8 @@ module ts {
let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: DiagnosticCategory.Error, key: "'let' declarations are only available when targeting ECMAScript 6 and higher." },
const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: DiagnosticCategory.Error, key: "'const' declarations are only available when targeting ECMAScript 6 and higher." },
const_must_be_intialized: { code: 1155, category: DiagnosticCategory.Error, key: "const must be intialized." },
const_must_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "const must be declared inside a block." },
let_must_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "let must be declared inside a block." },
Only_var_declarations_can_be_exported: { code: 1158, category: DiagnosticCategory.Error, key: "Only var declarations can be exported." },
const_declarations_must_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "'const' declarations must be declared inside a block." },
let_declarations_must_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations must be declared inside a block." },
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

View File

@@ -467,18 +467,14 @@
"category": "Error",
"code": 1155
},
"const must be declared inside a block.": {
"'const' declarations must be declared inside a block.": {
"category": "Error",
"code": 1156
},
"let must be declared inside a block.": {
"'let' declarations must be declared inside a block.": {
"category": "Error",
"code": 1157
},
"Only var declarations can be exported.": {
"category": "Error",
"code": 1158
},
"Duplicate identifier '{0}'.": {
"category": "Error",

View File

@@ -3180,15 +3180,12 @@ module ts {
}
else if (!allowLetAndConstDeclarations) {
if (node.flags & NodeFlags.Let) {
grammarErrorOnNode(node, Diagnostics.let_must_be_declared_inside_a_block);
grammarErrorOnNode(node, Diagnostics.let_declarations_must_be_declared_inside_a_block);
}
else if (node.flags & NodeFlags.Const) {
grammarErrorOnNode(node, Diagnostics.const_must_be_declared_inside_a_block);
grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_declared_inside_a_block);
}
}
else if (node.flags & NodeFlags.Export && node.flags & NodeFlags.BlockScoped) {
grammarErrorOnNode(node, Diagnostics.Only_var_declarations_can_be_exported);
}
return node;
}

View File

@@ -14,9 +14,10 @@ tests/cases/compiler/constDeclarations-access2.ts(18,1): error TS2449: The opera
tests/cases/compiler/constDeclarations-access2.ts(19,1): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations-access2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations-access2.ts(21,3): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations-access2.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant.
==== tests/cases/compiler/constDeclarations-access2.ts (16 errors) ====
==== tests/cases/compiler/constDeclarations-access2.ts (17 errors) ====
const x = 0
@@ -71,6 +72,10 @@ tests/cases/compiler/constDeclarations-access2.ts(21,3): error TS2449: The opera
~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
++((x));
~~~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
// OK
var a = x + 1;

View File

@@ -21,6 +21,8 @@ x--;
++x;
--x;
++((x));
// OK
var a = x + 1;
@@ -57,6 +59,7 @@ x++;
x--;
++x;
--x;
++((x));
// OK
var a = x + 1;
function f(v) {

View File

@@ -0,0 +1,102 @@
tests/cases/compiler/constDeclarations-access3.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations-access3.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
==== tests/cases/compiler/constDeclarations-access3.ts (18 errors) ====
module M {
export const x = 0;
}
// Errors
M.x = 1;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x += 2;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x -= 3;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x *= 4;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x /= 5;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x %= 6;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x <<= 7;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x >>= 8;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x >>>= 9;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x &= 10;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x |= 11;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x ^= 12;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x++;
~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
M.x--;
~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
++M.x;
~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
--M.x;
~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
++((M.x));
~~~~~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
M["x"] = 0;
~~~~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
// OK
var a = M.x + 1;
function f(v: number) { }
f(M.x);
if (M.x) { }
M.x;
(M.x);
-M.x;
+M.x;
M.x.toString();

View File

@@ -0,0 +1,83 @@
//// [constDeclarations-access3.ts]
module M {
export const x = 0;
}
// Errors
M.x = 1;
M.x += 2;
M.x -= 3;
M.x *= 4;
M.x /= 5;
M.x %= 6;
M.x <<= 7;
M.x >>= 8;
M.x >>>= 9;
M.x &= 10;
M.x |= 11;
M.x ^= 12;
M.x++;
M.x--;
++M.x;
--M.x;
++((M.x));
M["x"] = 0;
// OK
var a = M.x + 1;
function f(v: number) { }
f(M.x);
if (M.x) { }
M.x;
(M.x);
-M.x;
+M.x;
M.x.toString();
//// [constDeclarations-access3.js]
var M;
(function (M) {
M.x = 0;
})(M || (M = {}));
// Errors
M.x = 1;
M.x += 2;
M.x -= 3;
M.x *= 4;
M.x /= 5;
M.x %= 6;
M.x <<= 7;
M.x >>= 8;
M.x >>>= 9;
M.x &= 10;
M.x |= 11;
M.x ^= 12;
M.x++;
M.x--;
++M.x;
--M.x;
++((M.x));
M["x"] = 0;
// OK
var a = M.x + 1;
function f(v) {
}
f(M.x);
if (M.x) {
}
M.x;
(M.x);
-M.x;
+M.x;
M.x.toString();

View File

@@ -0,0 +1,102 @@
tests/cases/compiler/constDeclarations-access4.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations-access4.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
==== tests/cases/compiler/constDeclarations-access4.ts (18 errors) ====
declare module M {
const x: number;
}
// Errors
M.x = 1;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x += 2;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x -= 3;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x *= 4;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x /= 5;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x %= 6;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x <<= 7;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x >>= 8;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x >>>= 9;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x &= 10;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x |= 11;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x ^= 12;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
M.x++;
~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
M.x--;
~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
++M.x;
~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
--M.x;
~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
++((M.x));
~~~~~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
M["x"] = 0;
~~~~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
// OK
var a = M.x + 1;
function f(v: number) { }
f(M.x);
if (M.x) { }
M.x;
(M.x);
-M.x;
+M.x;
M.x.toString();

View File

@@ -0,0 +1,79 @@
//// [constDeclarations-access4.ts]
declare module M {
const x: number;
}
// Errors
M.x = 1;
M.x += 2;
M.x -= 3;
M.x *= 4;
M.x /= 5;
M.x %= 6;
M.x <<= 7;
M.x >>= 8;
M.x >>>= 9;
M.x &= 10;
M.x |= 11;
M.x ^= 12;
M.x++;
M.x--;
++M.x;
--M.x;
++((M.x));
M["x"] = 0;
// OK
var a = M.x + 1;
function f(v: number) { }
f(M.x);
if (M.x) { }
M.x;
(M.x);
-M.x;
+M.x;
M.x.toString();
//// [constDeclarations-access4.js]
// Errors
M.x = 1;
M.x += 2;
M.x -= 3;
M.x *= 4;
M.x /= 5;
M.x %= 6;
M.x <<= 7;
M.x >>= 8;
M.x >>>= 9;
M.x &= 10;
M.x |= 11;
M.x ^= 12;
M.x++;
M.x--;
++M.x;
--M.x;
++((M.x));
M["x"] = 0;
// OK
var a = M.x + 1;
function f(v) {
}
f(M.x);
if (M.x) {
}
M.x;
(M.x);
-M.x;
+M.x;
M.x.toString();

View File

@@ -0,0 +1,103 @@
tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(17,1): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(19,3): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The operand of an increment or decrement operator cannot be a constant.
tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
==== tests/cases/compiler/constDeclarations_access_2.ts (18 errors) ====
///<reference path='constDeclarations_access_1.ts'/>
import m = require('constDeclarations_access_1');
// Errors
m.x = 1;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
m.x += 2;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
m.x -= 3;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
m.x *= 4;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
m.x /= 5;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
m.x %= 6;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
m.x <<= 7;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
m.x >>= 8;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
m.x >>>= 9;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
m.x &= 10;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
m.x |= 11;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
m.x ^= 12;
~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
m
m.x++;
~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
m.x--;
~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
++m.x;
~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
--m.x;
~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
++((m.x));
~~~~~~~
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant.
m["x"] = 0;
~~~~~~
!!! error TS2450: Left-hand side of assignment expression cannot be a constant.
// OK
var a = m.x + 1;
function f(v: number) { }
f(m.x);
if (m.x) { }
m.x;
(m.x);
-m.x;
+m.x;
m.x.toString();
==== tests/cases/compiler/constDeclarations_access_1.ts (0 errors) ====
export const x = 0;

View File

@@ -0,0 +1,89 @@
//// [tests/cases/compiler/constDeclarations-access5.ts] ////
//// [constDeclarations_access_1.ts]
export const x = 0;
//// [constDeclarations_access_2.ts]
///<reference path='constDeclarations_access_1.ts'/>
import m = require('constDeclarations_access_1');
// Errors
m.x = 1;
m.x += 2;
m.x -= 3;
m.x *= 4;
m.x /= 5;
m.x %= 6;
m.x <<= 7;
m.x >>= 8;
m.x >>>= 9;
m.x &= 10;
m.x |= 11;
m.x ^= 12;
m
m.x++;
m.x--;
++m.x;
--m.x;
++((m.x));
m["x"] = 0;
// OK
var a = m.x + 1;
function f(v: number) { }
f(m.x);
if (m.x) { }
m.x;
(m.x);
-m.x;
+m.x;
m.x.toString();
//// [constDeclarations_access_1.js]
define(["require", "exports"], function (require, exports) {
exports.x = 0;
});
//// [constDeclarations_access_2.js]
define(["require", "exports", 'constDeclarations_access_1'], function (require, exports, m) {
// Errors
m.x = 1;
m.x += 2;
m.x -= 3;
m.x *= 4;
m.x /= 5;
m.x %= 6;
m.x <<= 7;
m.x >>= 8;
m.x >>>= 9;
m.x &= 10;
m.x |= 11;
m.x ^= 12;
m;
m.x++;
m.x--;
++m.x;
--m.x;
++((m.x));
m["x"] = 0;
// OK
var a = m.x + 1;
function f(v) {
}
f(m.x);
if (m.x) {
}
m.x;
(m.x);
-m.x;
+m.x;
m.x.toString();
});

View File

@@ -1,12 +1,12 @@
tests/cases/compiler/constDeclarations-invalidContexts.ts(4,5): error TS1156: const must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(6,5): error TS1156: const must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(9,5): error TS1156: const must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(12,5): error TS1156: const must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(17,5): error TS1156: const must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(20,5): error TS1156: const must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(23,5): error TS1156: const must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(26,12): error TS1156: const must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(29,29): error TS1156: const must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(4,5): error TS1156: 'const' declarations must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(6,5): error TS1156: 'const' declarations must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(9,5): error TS1156: 'const' declarations must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(12,5): error TS1156: 'const' declarations must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(17,5): error TS1156: 'const' declarations must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(20,5): error TS1156: 'const' declarations must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(23,5): error TS1156: 'const' declarations must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(26,12): error TS1156: 'const' declarations must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(29,29): error TS1156: 'const' declarations must be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(16,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
@@ -16,21 +16,21 @@ tests/cases/compiler/constDeclarations-invalidContexts.ts(16,7): error TS2410: A
if (true)
const c1 = 0;
~~~~~~~~~~~~~
!!! error TS1156: const must be declared inside a block.
!!! error TS1156: 'const' declarations must be declared inside a block.
else
const c2 = 0;
~~~~~~~~~~~~~
!!! error TS1156: const must be declared inside a block.
!!! error TS1156: 'const' declarations must be declared inside a block.
while (true)
const c3 = 0;
~~~~~~~~~~~~~
!!! error TS1156: const must be declared inside a block.
!!! error TS1156: 'const' declarations must be declared inside a block.
do
const c4 = 0;
~~~~~~~~~~~~~
!!! error TS1156: const must be declared inside a block.
!!! error TS1156: 'const' declarations must be declared inside a block.
while (true);
var obj;
@@ -39,27 +39,27 @@ tests/cases/compiler/constDeclarations-invalidContexts.ts(16,7): error TS2410: A
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
const c5 = 0;
~~~~~~~~~~~~~
!!! error TS1156: const must be declared inside a block.
!!! error TS1156: 'const' declarations must be declared inside a block.
for (var i = 0; i < 10; i++)
const c6 = 0;
~~~~~~~~~~~~~
!!! error TS1156: const must be declared inside a block.
!!! error TS1156: 'const' declarations must be declared inside a block.
for (var i2 in {})
const c7 = 0;
~~~~~~~~~~~~~
!!! error TS1156: const must be declared inside a block.
!!! error TS1156: 'const' declarations must be declared inside a block.
if (true)
label: const c8 = 0;
~~~~~~~~~~~~~
!!! error TS1156: const must be declared inside a block.
!!! error TS1156: 'const' declarations must be declared inside a block.
while (false)
label2: label3: label4: const c9 = 0;
~~~~~~~~~~~~~
!!! error TS1156: const must be declared inside a block.
!!! error TS1156: 'const' declarations must be declared inside a block.

View File

@@ -1,20 +0,0 @@
tests/cases/compiler/constDeclarations2.ts(4,5): error TS1158: Only var declarations can be exported.
tests/cases/compiler/constDeclarations2.ts(5,5): error TS1158: Only var declarations can be exported.
tests/cases/compiler/constDeclarations2.ts(6,5): error TS1158: Only var declarations can be exported.
==== tests/cases/compiler/constDeclarations2.ts (3 errors) ====
// No error
module M {
export const c1 = false;
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1158: Only var declarations can be exported.
export const c2: number = 23;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1158: Only var declarations can be exported.
export const c3 = 0, c4 :string = "", c5 = null;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1158: Only var declarations can be exported.
}

View File

@@ -0,0 +1,26 @@
//// [constDeclarations2.ts]
// No error
module M {
export const c1 = false;
export const c2: number = 23;
export const c3 = 0, c4 :string = "", c5 = null;
}
//// [constDeclarations2.js]
// No error
var M;
(function (M) {
M.c1 = false;
M.c2 = 23;
M.c3 = 0, M.c4 = "", M.c5 = null;
})(M || (M = {}));
//// [constDeclarations2.d.ts]
declare module M {
const c1: boolean;
const c2: number;
const c3: number, c4: string, c5: any;
}

View File

@@ -0,0 +1,18 @@
=== tests/cases/compiler/constDeclarations2.ts ===
// No error
module M {
>M : typeof M
export const c1 = false;
>c1 : boolean
export const c2: number = 23;
>c2 : number
export const c3 = 0, c4 :string = "", c5 = null;
>c3 : number
>c4 : string
>c5 : any
}

View File

@@ -1,12 +1,12 @@
tests/cases/compiler/letDeclarations-invalidContexts.ts(4,5): error TS1157: let must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(6,5): error TS1157: let must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(9,5): error TS1157: let must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(12,5): error TS1157: let must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(17,5): error TS1157: let must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(20,5): error TS1157: let must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(23,5): error TS1157: let must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(26,12): error TS1157: let must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(29,29): error TS1157: let must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(4,5): error TS1157: 'let' declarations must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(6,5): error TS1157: 'let' declarations must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(9,5): error TS1157: 'let' declarations must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(12,5): error TS1157: 'let' declarations must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(17,5): error TS1157: 'let' declarations must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(20,5): error TS1157: 'let' declarations must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(23,5): error TS1157: 'let' declarations must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(26,12): error TS1157: 'let' declarations must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(29,29): error TS1157: 'let' declarations must be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(16,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
@@ -16,21 +16,21 @@ tests/cases/compiler/letDeclarations-invalidContexts.ts(16,7): error TS2410: All
if (true)
let l1 = 0;
~~~~~~~~~~~
!!! error TS1157: let must be declared inside a block.
!!! error TS1157: 'let' declarations must be declared inside a block.
else
let l2 = 0;
~~~~~~~~~~~
!!! error TS1157: let must be declared inside a block.
!!! error TS1157: 'let' declarations must be declared inside a block.
while (true)
let l3 = 0;
~~~~~~~~~~~
!!! error TS1157: let must be declared inside a block.
!!! error TS1157: 'let' declarations must be declared inside a block.
do
let l4 = 0;
~~~~~~~~~~~
!!! error TS1157: let must be declared inside a block.
!!! error TS1157: 'let' declarations must be declared inside a block.
while (true);
var obj;
@@ -39,27 +39,27 @@ tests/cases/compiler/letDeclarations-invalidContexts.ts(16,7): error TS2410: All
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
let l5 = 0;
~~~~~~~~~~~
!!! error TS1157: let must be declared inside a block.
!!! error TS1157: 'let' declarations must be declared inside a block.
for (var i = 0; i < 10; i++)
let l6 = 0;
~~~~~~~~~~~
!!! error TS1157: let must be declared inside a block.
!!! error TS1157: 'let' declarations must be declared inside a block.
for (var i2 in {})
let l7 = 0;
~~~~~~~~~~~
!!! error TS1157: let must be declared inside a block.
!!! error TS1157: 'let' declarations must be declared inside a block.
if (true)
label: let l8 = 0;
~~~~~~~~~~~
!!! error TS1157: let must be declared inside a block.
!!! error TS1157: 'let' declarations must be declared inside a block.
while (false)
label2: label3: label4: let l9 = 0;
~~~~~~~~~~~
!!! error TS1157: let must be declared inside a block.
!!! error TS1157: 'let' declarations must be declared inside a block.

View File

@@ -1,11 +0,0 @@
tests/cases/compiler/letDeclarations2.ts(4,5): error TS1158: Only var declarations can be exported.
==== tests/cases/compiler/letDeclarations2.ts (1 errors) ====
module M {
let l1 = "s";
export let l2 = 0;
~~~~~~~~~~~~~~~~~~
!!! error TS1158: Only var declarations can be exported.
}

View File

@@ -0,0 +1,19 @@
//// [letDeclarations2.ts]
module M {
let l1 = "s";
export let l2 = 0;
}
//// [letDeclarations2.js]
var M;
(function (M) {
let l1 = "s";
M.l2 = 0;
})(M || (M = {}));
//// [letDeclarations2.d.ts]
declare module M {
let l2: number;
}

View File

@@ -0,0 +1,11 @@
=== tests/cases/compiler/letDeclarations2.ts ===
module M {
>M : typeof M
let l1 = "s";
>l1 : string
export let l2 = 0;
>l2 : number
}

View File

@@ -21,6 +21,8 @@ x--;
++x;
--x;
++((x));
// OK
var a = x + 1;

View File

@@ -0,0 +1,45 @@
// @target: ES6
module M {
export const x = 0;
}
// Errors
M.x = 1;
M.x += 2;
M.x -= 3;
M.x *= 4;
M.x /= 5;
M.x %= 6;
M.x <<= 7;
M.x >>= 8;
M.x >>>= 9;
M.x &= 10;
M.x |= 11;
M.x ^= 12;
M.x++;
M.x--;
++M.x;
--M.x;
++((M.x));
M["x"] = 0;
// OK
var a = M.x + 1;
function f(v: number) { }
f(M.x);
if (M.x) { }
M.x;
(M.x);
-M.x;
+M.x;
M.x.toString();

View File

@@ -0,0 +1,45 @@
// @target: ES6
declare module M {
const x: number;
}
// Errors
M.x = 1;
M.x += 2;
M.x -= 3;
M.x *= 4;
M.x /= 5;
M.x %= 6;
M.x <<= 7;
M.x >>= 8;
M.x >>>= 9;
M.x &= 10;
M.x |= 11;
M.x ^= 12;
M.x++;
M.x--;
++M.x;
--M.x;
++((M.x));
M["x"] = 0;
// OK
var a = M.x + 1;
function f(v: number) { }
f(M.x);
if (M.x) { }
M.x;
(M.x);
-M.x;
+M.x;
M.x.toString();

View File

@@ -0,0 +1,48 @@
// @target: ES6
// @module: amd
// @Filename: constDeclarations_access_1.ts
export const x = 0;
// @Filename: constDeclarations_access_2.ts
///<reference path='constDeclarations_access_1.ts'/>
import m = require('constDeclarations_access_1');
// Errors
m.x = 1;
m.x += 2;
m.x -= 3;
m.x *= 4;
m.x /= 5;
m.x %= 6;
m.x <<= 7;
m.x >>= 8;
m.x >>>= 9;
m.x &= 10;
m.x |= 11;
m.x ^= 12;
m
m.x++;
m.x--;
++m.x;
--m.x;
++((m.x));
m["x"] = 0;
// OK
var a = m.x + 1;
function f(v: number) { }
f(m.x);
if (m.x) { }
m.x;
(m.x);
-m.x;
+m.x;
m.x.toString();