Skip to content

Commit 1fe9bfd

Browse files
jayeclarksandersn
andauthored
Fix strict/es5+ octal literal 2x error microsoft#46810 (microsoft#46823)
* Fix strict/es5+ octal literal 2x error microsoft#46810 Signed-off-by: Jay Clark <[email protected]> * Accept baseline test changes Signed-off-by: Jay Clark <[email protected]> * Add test case Co-authored-by: Nathan Shively-Sanders <[email protected]>
1 parent 2a7eb58 commit 1fe9bfd

File tree

8 files changed

+62
-9
lines changed

8 files changed

+62
-9
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2335,7 +2335,7 @@ namespace ts {
23352335
}
23362336

23372337
function checkStrictModeNumericLiteral(node: NumericLiteral) {
2338-
if (inStrictMode && node.numericLiteralFlags & TokenFlags.Octal) {
2338+
if (languageVersion < ScriptTarget.ES5 && inStrictMode && node.numericLiteralFlags & TokenFlags.Octal) {
23392339
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode));
23402340
}
23412341
}

tests/baselines/reference/jsFileCompilationBindStrictModeErrors.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ tests/cases/compiler/b.js(3,7): error TS1210: Code contained in a class is evalu
1010
tests/cases/compiler/b.js(6,13): error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode.
1111
tests/cases/compiler/c.js(1,12): error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
1212
tests/cases/compiler/c.js(2,5): error TS1215: Invalid use of 'eval'. Modules are automatically in strict mode.
13-
tests/cases/compiler/d.js(2,9): error TS1121: Octal literals are not allowed in strict mode.
1413
tests/cases/compiler/d.js(2,11): error TS1005: ',' expected.
1514

1615

@@ -72,10 +71,8 @@ tests/cases/compiler/d.js(2,11): error TS1005: ',' expected.
7271
!!! error TS1215: Invalid use of 'eval'. Modules are automatically in strict mode.
7372
};
7473

75-
==== tests/cases/compiler/d.js (2 errors) ====
74+
==== tests/cases/compiler/d.js (1 errors) ====
7675
"use strict";
7776
var x = 009; // error
78-
~~
79-
!!! error TS1121: Octal literals are not allowed in strict mode.
8077
~
8178
!!! error TS1005: ',' expected.

tests/baselines/reference/plainJSBinderErrors.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ tests/cases/conformance/salsa/plainJSBinderErrors.js(18,16): error TS1102: 'dele
1010
tests/cases/conformance/salsa/plainJSBinderErrors.js(19,16): error TS1102: 'delete' cannot be called on an identifier in strict mode.
1111
tests/cases/conformance/salsa/plainJSBinderErrors.js(22,15): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'eval'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
1212
tests/cases/conformance/salsa/plainJSBinderErrors.js(23,15): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
13-
tests/cases/conformance/salsa/plainJSBinderErrors.js(26,27): error TS1121: Octal literals are not allowed in strict mode.
1413
tests/cases/conformance/salsa/plainJSBinderErrors.js(27,9): error TS1101: 'with' statements are not allowed in strict mode.
1514
tests/cases/conformance/salsa/plainJSBinderErrors.js(33,13): error TS1344: 'A label is not allowed here.
1615
tests/cases/conformance/salsa/plainJSBinderErrors.js(39,7): error TS1215: Invalid use of 'eval'. Modules are automatically in strict mode.
1716
tests/cases/conformance/salsa/plainJSBinderErrors.js(40,7): error TS1215: Invalid use of 'arguments'. Modules are automatically in strict mode.
1817

1918

20-
==== tests/cases/conformance/salsa/plainJSBinderErrors.js (17 errors) ====
19+
==== tests/cases/conformance/salsa/plainJSBinderErrors.js (16 errors) ====
2120
export default 12
2221
~~~~~~~~~~~~~~~~~
2322
!!! error TS2528: A module cannot have multiple default exports.
@@ -70,8 +69,6 @@ tests/cases/conformance/salsa/plainJSBinderErrors.js(40,7): error TS1215: Invali
7069
}
7170
withOctal() {
7271
const redundant = 010
73-
~~~
74-
!!! error TS1121: Octal literals are not allowed in strict mode.
7572
with (redundant) {
7673
~~~~
7774
!!! error TS1101: 'with' statements are not allowed in strict mode.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
tests/cases/conformance/expressions/literals/strictModeOctalLiterals.ts(2,14): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'.
2+
tests/cases/conformance/expressions/literals/strictModeOctalLiterals.ts(4,16): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'.
3+
tests/cases/conformance/expressions/literals/strictModeOctalLiterals.ts(4,21): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'.
4+
5+
6+
==== tests/cases/conformance/expressions/literals/strictModeOctalLiterals.ts (3 errors) ====
7+
export enum E {
8+
A = 12 + 01
9+
~~
10+
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'.
11+
}
12+
const orbitol: 01 = 01
13+
~~
14+
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'.
15+
~~
16+
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'.
17+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [strictModeOctalLiterals.ts]
2+
export enum E {
3+
A = 12 + 01
4+
}
5+
const orbitol: 01 = 01
6+
7+
8+
//// [strictModeOctalLiterals.js]
9+
export var E;
10+
(function (E) {
11+
E[E["A"] = 13] = "A";
12+
})(E || (E = {}));
13+
const orbitol = 01;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/conformance/expressions/literals/strictModeOctalLiterals.ts ===
2+
export enum E {
3+
>E : Symbol(E, Decl(strictModeOctalLiterals.ts, 0, 0))
4+
5+
A = 12 + 01
6+
>A : Symbol(E.A, Decl(strictModeOctalLiterals.ts, 0, 15))
7+
}
8+
const orbitol: 01 = 01
9+
>orbitol : Symbol(orbitol, Decl(strictModeOctalLiterals.ts, 3, 5))
10+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/conformance/expressions/literals/strictModeOctalLiterals.ts ===
2+
export enum E {
3+
>E : E
4+
5+
A = 12 + 01
6+
>A : E
7+
>12 + 01 : number
8+
>12 : 12
9+
>01 : 1
10+
}
11+
const orbitol: 01 = 01
12+
>orbitol : 1
13+
>01 : 1
14+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @target: es2018
2+
export enum E {
3+
A = 12 + 01
4+
}
5+
const orbitol: 01 = 01

0 commit comments

Comments
 (0)