From 1fe9bfdd0ee0ecf9dff23a40c0066645719e46b9 Mon Sep 17 00:00:00 2001 From: Jay Clark <84106309+jayeclark@users.noreply.github.com> Date: Mon, 6 Dec 2021 16:46:08 -0400 Subject: [PATCH] Fix strict/es5+ octal literal 2x error #46810 (#46823) * Fix strict/es5+ octal literal 2x error #46810 Signed-off-by: Jay Clark * Accept baseline test changes Signed-off-by: Jay Clark * Add test case Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> --- src/compiler/binder.ts | 2 +- ...leCompilationBindStrictModeErrors.errors.txt | 5 +---- .../reference/plainJSBinderErrors.errors.txt | 5 +---- .../strictModeOctalLiterals.errors.txt | 17 +++++++++++++++++ .../reference/strictModeOctalLiterals.js | 13 +++++++++++++ .../reference/strictModeOctalLiterals.symbols | 10 ++++++++++ .../reference/strictModeOctalLiterals.types | 14 ++++++++++++++ .../literals/strictModeOctalLiterals.ts | 5 +++++ 8 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 tests/baselines/reference/strictModeOctalLiterals.errors.txt create mode 100644 tests/baselines/reference/strictModeOctalLiterals.js create mode 100644 tests/baselines/reference/strictModeOctalLiterals.symbols create mode 100644 tests/baselines/reference/strictModeOctalLiterals.types create mode 100644 tests/cases/conformance/expressions/literals/strictModeOctalLiterals.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 5ed5bf12c43..eefc41fdaf8 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2335,7 +2335,7 @@ namespace ts { } function checkStrictModeNumericLiteral(node: NumericLiteral) { - if (inStrictMode && node.numericLiteralFlags & TokenFlags.Octal) { + if (languageVersion < ScriptTarget.ES5 && inStrictMode && node.numericLiteralFlags & TokenFlags.Octal) { file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode)); } } diff --git a/tests/baselines/reference/jsFileCompilationBindStrictModeErrors.errors.txt b/tests/baselines/reference/jsFileCompilationBindStrictModeErrors.errors.txt index 64fc50e8307..6d1f32442a5 100644 --- a/tests/baselines/reference/jsFileCompilationBindStrictModeErrors.errors.txt +++ b/tests/baselines/reference/jsFileCompilationBindStrictModeErrors.errors.txt @@ -10,7 +10,6 @@ tests/cases/compiler/b.js(3,7): error TS1210: Code contained in a class is evalu 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. 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. tests/cases/compiler/c.js(2,5): error TS1215: Invalid use of 'eval'. Modules are automatically in strict mode. -tests/cases/compiler/d.js(2,9): error TS1121: Octal literals are not allowed in strict mode. tests/cases/compiler/d.js(2,11): error TS1005: ',' expected. @@ -72,10 +71,8 @@ tests/cases/compiler/d.js(2,11): error TS1005: ',' expected. !!! error TS1215: Invalid use of 'eval'. Modules are automatically in strict mode. }; -==== tests/cases/compiler/d.js (2 errors) ==== +==== tests/cases/compiler/d.js (1 errors) ==== "use strict"; var x = 009; // error - ~~ -!!! error TS1121: Octal literals are not allowed in strict mode. ~ !!! error TS1005: ',' expected. \ No newline at end of file diff --git a/tests/baselines/reference/plainJSBinderErrors.errors.txt b/tests/baselines/reference/plainJSBinderErrors.errors.txt index 72aaa17b1e8..6171c0e80e9 100644 --- a/tests/baselines/reference/plainJSBinderErrors.errors.txt +++ b/tests/baselines/reference/plainJSBinderErrors.errors.txt @@ -10,14 +10,13 @@ tests/cases/conformance/salsa/plainJSBinderErrors.js(18,16): error TS1102: 'dele tests/cases/conformance/salsa/plainJSBinderErrors.js(19,16): error TS1102: 'delete' cannot be called on an identifier in strict mode. 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. 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. -tests/cases/conformance/salsa/plainJSBinderErrors.js(26,27): error TS1121: Octal literals are not allowed in strict mode. tests/cases/conformance/salsa/plainJSBinderErrors.js(27,9): error TS1101: 'with' statements are not allowed in strict mode. tests/cases/conformance/salsa/plainJSBinderErrors.js(33,13): error TS1344: 'A label is not allowed here. tests/cases/conformance/salsa/plainJSBinderErrors.js(39,7): error TS1215: Invalid use of 'eval'. Modules are automatically in strict mode. tests/cases/conformance/salsa/plainJSBinderErrors.js(40,7): error TS1215: Invalid use of 'arguments'. Modules are automatically in strict mode. -==== tests/cases/conformance/salsa/plainJSBinderErrors.js (17 errors) ==== +==== tests/cases/conformance/salsa/plainJSBinderErrors.js (16 errors) ==== export default 12 ~~~~~~~~~~~~~~~~~ !!! error TS2528: A module cannot have multiple default exports. @@ -70,8 +69,6 @@ tests/cases/conformance/salsa/plainJSBinderErrors.js(40,7): error TS1215: Invali } withOctal() { const redundant = 010 - ~~~ -!!! error TS1121: Octal literals are not allowed in strict mode. with (redundant) { ~~~~ !!! error TS1101: 'with' statements are not allowed in strict mode. diff --git a/tests/baselines/reference/strictModeOctalLiterals.errors.txt b/tests/baselines/reference/strictModeOctalLiterals.errors.txt new file mode 100644 index 00000000000..3d52e5323f2 --- /dev/null +++ b/tests/baselines/reference/strictModeOctalLiterals.errors.txt @@ -0,0 +1,17 @@ +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'. +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'. +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'. + + +==== tests/cases/conformance/expressions/literals/strictModeOctalLiterals.ts (3 errors) ==== + export enum E { + A = 12 + 01 + ~~ +!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'. + } + const orbitol: 01 = 01 + ~~ +!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'. + ~~ +!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'. + \ No newline at end of file diff --git a/tests/baselines/reference/strictModeOctalLiterals.js b/tests/baselines/reference/strictModeOctalLiterals.js new file mode 100644 index 00000000000..df3f9acfe54 --- /dev/null +++ b/tests/baselines/reference/strictModeOctalLiterals.js @@ -0,0 +1,13 @@ +//// [strictModeOctalLiterals.ts] +export enum E { + A = 12 + 01 +} +const orbitol: 01 = 01 + + +//// [strictModeOctalLiterals.js] +export var E; +(function (E) { + E[E["A"] = 13] = "A"; +})(E || (E = {})); +const orbitol = 01; diff --git a/tests/baselines/reference/strictModeOctalLiterals.symbols b/tests/baselines/reference/strictModeOctalLiterals.symbols new file mode 100644 index 00000000000..286a1eda1cc --- /dev/null +++ b/tests/baselines/reference/strictModeOctalLiterals.symbols @@ -0,0 +1,10 @@ +=== tests/cases/conformance/expressions/literals/strictModeOctalLiterals.ts === +export enum E { +>E : Symbol(E, Decl(strictModeOctalLiterals.ts, 0, 0)) + + A = 12 + 01 +>A : Symbol(E.A, Decl(strictModeOctalLiterals.ts, 0, 15)) +} +const orbitol: 01 = 01 +>orbitol : Symbol(orbitol, Decl(strictModeOctalLiterals.ts, 3, 5)) + diff --git a/tests/baselines/reference/strictModeOctalLiterals.types b/tests/baselines/reference/strictModeOctalLiterals.types new file mode 100644 index 00000000000..ffbb20d8f4e --- /dev/null +++ b/tests/baselines/reference/strictModeOctalLiterals.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/expressions/literals/strictModeOctalLiterals.ts === +export enum E { +>E : E + + A = 12 + 01 +>A : E +>12 + 01 : number +>12 : 12 +>01 : 1 +} +const orbitol: 01 = 01 +>orbitol : 1 +>01 : 1 + diff --git a/tests/cases/conformance/expressions/literals/strictModeOctalLiterals.ts b/tests/cases/conformance/expressions/literals/strictModeOctalLiterals.ts new file mode 100644 index 00000000000..69b9267f999 --- /dev/null +++ b/tests/cases/conformance/expressions/literals/strictModeOctalLiterals.ts @@ -0,0 +1,5 @@ +// @target: es2018 +export enum E { + A = 12 + 01 +} +const orbitol: 01 = 01