Skip to content

Commit a490eb2

Browse files
committed
Merge pull request #217 from Microsoft/strict_mode
Strict mode support
2 parents 64ab02e + 4c70d73 commit a490eb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+344
-352
lines changed

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ module ts {
9999
A_constructor_implementation_cannot_be_declared_in_an_ambient_context: { code: 1111, category: DiagnosticCategory.Error, key: "A constructor implementation cannot be declared in an ambient context." },
100100
A_class_member_cannot_be_declared_optional: { code: 1112, category: DiagnosticCategory.Error, key: "A class member cannot be declared optional." },
101101
A_default_clause_cannot_appear_more_than_once_in_a_switch_statement: { code: 1113, category: DiagnosticCategory.Error, key: "A 'default' clause cannot appear more than once in a 'switch' statement." },
102+
An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode: { code: 1114, category: DiagnosticCategory.Error, key: "An object literal cannot have multiple properties with the same name in strict mode." },
103+
An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name: { code: 1115, category: DiagnosticCategory.Error, key: "An object literal cannot have multiple get/set accessors with the same name." },
104+
An_object_literal_cannot_have_property_and_accessor_with_the_same_name: { code: 1116, category: DiagnosticCategory.Error, key: "An object literal cannot have property and accessor with the same name." },
102105
Duplicate_identifier_0: { code: 2000, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
103106
new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 2068, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead." },
104107
Multiple_constructor_implementations_are_not_allowed: { code: 2070, category: DiagnosticCategory.Error, key: "Multiple constructor implementations are not allowed." },

src/compiler/diagnosticMessages.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,18 @@
388388
"category": "Error",
389389
"code": 1113
390390
},
391-
391+
"An object literal cannot have multiple properties with the same name in strict mode.": {
392+
"category": "Error",
393+
"code": 1114
394+
},
395+
"An object literal cannot have multiple get/set accessors with the same name.": {
396+
"category": "Error",
397+
"code": 1115
398+
},
399+
"An object literal cannot have property and accessor with the same name.": {
400+
"category": "Error",
401+
"code": 1116
402+
},
392403
"Duplicate identifier '{0}'.": {
393404
"category": "Error",
394405
"code": 2000

src/compiler/emitter.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,8 +1669,7 @@ module ts {
16691669

16701670
function emitDirectivePrologues(statements: Statement[], startWithNewLine: boolean): number {
16711671
for (var i = 0; i < statements.length; ++i) {
1672-
if (statements[i].kind === SyntaxKind.ExpressionStatement &&
1673-
(<ExpressionStatement>statements[i]).expression.kind === SyntaxKind.StringLiteral) {
1672+
if (isPrologueDirective(statements[i])) {
16741673
if (startWithNewLine || i > 0) {
16751674
writeLine();
16761675
}

src/compiler/parser.ts

Lines changed: 186 additions & 20 deletions
Large diffs are not rendered by default.

src/compiler/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ module ts {
215215
FirstReservedWord = BreakKeyword,
216216
LastReservedWord = WithKeyword,
217217
FirstKeyword = BreakKeyword,
218-
LastKeyword = StringKeyword
218+
LastKeyword = StringKeyword,
219+
FirstFutureReservedWord = ImplementsKeyword,
220+
LastFutureReservedWord = YieldKeyword
219221
}
220222

221223
export enum NodeFlags {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
==== tests/cases/compiler/constructorStaticParamNameErrors.ts (1 errors) ====
2+
'use strict'
3+
// static as constructor parameter name should give error if 'use strict'
4+
class test {
5+
constructor (static) { }
6+
~~~~~~
7+
!!! Identifier expected.
8+
}

tests/baselines/reference/constructorStaticParamNameErrors.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/baselines/reference/duplicateObjectLiteralProperty.errors.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
==== tests/cases/compiler/duplicateObjectLiteralProperty.ts (8 errors) ====
1+
==== tests/cases/compiler/duplicateObjectLiteralProperty.ts (9 errors) ====
22
var x = {
33
a: 1,
44
b: true, // OK
@@ -30,6 +30,8 @@
3030
~
3131
!!! Accessors are only available when targeting ECMAScript 5 and higher.
3232
~
33+
!!! An object literal cannot have multiple get/set accessors with the same name.
34+
~
3335
!!! Duplicate identifier 'a'.
3436
};
3537

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
==== tests/cases/compiler/duplicatePropertiesInStrictMode.ts (2 errors) ====
2+
"use strict";
3+
var x = {
4+
x: 1,
5+
x: 2
6+
~
7+
!!! An object literal cannot have multiple properties with the same name in strict mode.
8+
~
9+
!!! Duplicate identifier 'x'.
10+
}

tests/baselines/reference/objectLiteralErrors.errors.txt

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (41 errors) ====
1+
==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (59 errors) ====
22

33
// Multiple properties with the same name
44
var e1 = { a: 0, a: 0 };
@@ -59,57 +59,93 @@
5959
// Accessor and property with the same name
6060
var f1 = { a: 0, get a() { return 0; } };
6161
~
62+
!!! An object literal cannot have property and accessor with the same name.
63+
~
6264
!!! Duplicate identifier 'a'.
6365
var f2 = { a: '', get a() { return ''; } };
6466
~
67+
!!! An object literal cannot have property and accessor with the same name.
68+
~
6569
!!! Duplicate identifier 'a'.
6670
var f3 = { a: 0, get a() { return ''; } };
6771
~
72+
!!! An object literal cannot have property and accessor with the same name.
73+
~
6874
!!! Duplicate identifier 'a'.
6975
var f4 = { a: true, get a() { return false; } };
7076
~
77+
!!! An object literal cannot have property and accessor with the same name.
78+
~
7179
!!! Duplicate identifier 'a'.
7280
var f5 = { a: {}, get a() { return {}; } };
7381
~
82+
!!! An object literal cannot have property and accessor with the same name.
83+
~
7484
!!! Duplicate identifier 'a'.
7585
var f6 = { a: 0, get 'a'() { return 0; } };
7686
~~~
87+
!!! An object literal cannot have property and accessor with the same name.
88+
~~~
7789
!!! Duplicate identifier ''a''.
7890
var f7 = { 'a': 0, get a() { return 0; } };
7991
~
92+
!!! An object literal cannot have property and accessor with the same name.
93+
~
8094
!!! Duplicate identifier 'a'.
8195
var f8 = { 'a': 0, get "a"() { return 0; } };
8296
~~~
97+
!!! An object literal cannot have property and accessor with the same name.
98+
~~~
8399
!!! Duplicate identifier '"a"'.
84100
var f9 = { 'a': 0, get 'a'() { return 0; } };
85101
~~~
102+
!!! An object literal cannot have property and accessor with the same name.
103+
~~~
86104
!!! Duplicate identifier ''a''.
87105
var f10 = { "a": 0, get 'a'() { return 0; } };
88106
~~~
107+
!!! An object literal cannot have property and accessor with the same name.
108+
~~~
89109
!!! Duplicate identifier ''a''.
90110
var f11 = { 1.0: 0, get '1'() { return 0; } };
91111
~~~
112+
!!! An object literal cannot have property and accessor with the same name.
113+
~~~
92114
!!! Duplicate identifier ''1''.
93115
var f12 = { 0: 0, get 0() { return 0; } };
94116
~
117+
!!! An object literal cannot have property and accessor with the same name.
118+
~
95119
!!! Duplicate identifier '0'.
96120
var f13 = { 0: 0, get 0() { return 0; } };
97121
~
122+
!!! An object literal cannot have property and accessor with the same name.
123+
~
98124
!!! Duplicate identifier '0'.
99125
var f14 = { 0: 0, get 0x0() { return 0; } };
100126
~~~
127+
!!! An object literal cannot have property and accessor with the same name.
128+
~~~
101129
!!! Duplicate identifier '0x0'.
102130
var f14 = { 0: 0, get 000() { return 0; } };
103131
~~~
132+
!!! An object literal cannot have property and accessor with the same name.
133+
~~~
104134
!!! Duplicate identifier '000'.
105135
var f15 = { "100": 0, get 1e2() { return 0; } };
106136
~~~
137+
!!! An object literal cannot have property and accessor with the same name.
138+
~~~
107139
!!! Duplicate identifier '1e2'.
108140
var f16 = { 0x20: 0, get 3.2e1() { return 0; } };
109141
~~~~~
142+
!!! An object literal cannot have property and accessor with the same name.
143+
~~~~~
110144
!!! Duplicate identifier '3.2e1'.
111145
var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } };
112146
~
147+
!!! An object literal cannot have property and accessor with the same name.
148+
~
113149
!!! Duplicate identifier 'a'.
114150

115151
// Get and set accessor with mismatched type annotations

tests/baselines/reference/objectLiteralErrors.js

Lines changed: 0 additions & 135 deletions
This file was deleted.

tests/baselines/reference/parser10.1.1-8gs.errors.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
==== tests/cases/conformance/parser/ecmascript5/parser10.1.1-8gs.ts (1 errors) ====
1+
==== tests/cases/conformance/parser/ecmascript5/parser10.1.1-8gs.ts (4 errors) ====
22
/// Copyright (c) 2012 Ecma International. All rights reserved.
33
/// Ecma International makes this code available under the terms and conditions set
44
/// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
@@ -18,4 +18,10 @@
1818
~~~~~~~~~~~~~
1919
!!! Cannot find name 'NotEarlyError'.
2020
var public = 1;
21+
~~~~~~
22+
!!! Variable declaration expected.
23+
~
24+
!!! Variable declaration expected.
25+
~
26+
!!! Variable declaration expected.
2127

tests/baselines/reference/parser10.1.1-8gs.js

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331_1.ts (1 errors) ====
2+
"use strict";
3+
4+
class test {
5+
constructor (static) { }
6+
~~~~~~
7+
!!! Identifier expected.
8+
}
9+

0 commit comments

Comments
 (0)