diff --git a/Makefile b/Makefile index b798591f75..d7413495d1 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ FLOW_COMMIT = a1f9a4c709dcebb27a5084acf47755fbae699c25 -TEST262_COMMIT = d9740c172652d36194ceae3ed3d0484e9968ebc3 +TEST262_COMMIT = 36d2d2d348d83e9d6554af59a672fbcd9413914b TYPESCRIPT_COMMIT = da8633212023517630de5f3620a23736b63234b1 FORCE_PUBLISH = -f @babel/runtime -f @babel/runtime-corejs2 -f @babel/runtime-corejs3 -f @babel/standalone diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index 986d242ee9..5827e5154a 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -810,6 +810,9 @@ export default class StatementParser extends ExpressionParser { afterBlockParse?: (hasStrictModeDirective: boolean) => void, ): N.BlockStatement { const node = this.startNode(); + if (allowDirectives) { + this.state.strictErrors.clear(); + } this.expect(tt.braceL); if (createNewLexicalScope) { this.scope.enter(SCOPE_OTHER); @@ -863,44 +866,35 @@ export default class StatementParser extends ExpressionParser { end: TokenType, afterBlockParse?: (hasStrictModeDirective: boolean) => void, ): void { - const octalPositions = []; const oldStrict = this.state.strict; let hasStrictModeDirective = false; let parsedNonDirective = false; while (!this.match(end)) { - // Track octal literals that occur before a "use strict" directive. - if (!parsedNonDirective && this.state.octalPositions.length) { - octalPositions.push(...this.state.octalPositions); - } - const stmt = this.parseStatement(null, topLevel); - if (directives && !parsedNonDirective && this.isValidDirective(stmt)) { - const directive = this.stmtToDirective(stmt); - directives.push(directive); + if (directives && !parsedNonDirective) { + if (this.isValidDirective(stmt)) { + const directive = this.stmtToDirective(stmt); + directives.push(directive); - if (!hasStrictModeDirective && directive.value.value === "use strict") { - hasStrictModeDirective = true; - this.setStrict(true); + if ( + !hasStrictModeDirective && + directive.value.value === "use strict" + ) { + hasStrictModeDirective = true; + this.setStrict(true); + } + + continue; } - - continue; + parsedNonDirective = true; + // clear strict errors since the strict mode will not change within the block + this.state.strictErrors.clear(); } - - parsedNonDirective = true; body.push(stmt); } - // Throw an error for any octal literals found before a - // "use strict" directive. Strict mode will be set at parse - // time for any literals that occur after the directive. - if (this.state.strict && octalPositions.length) { - for (const pos of octalPositions) { - this.raise(pos, Errors.StrictOctalLiteral); - } - } - if (afterBlockParse) { afterBlockParse.call(this, hasStrictModeDirective); } diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index 971226007c..7c119c7d11 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -210,14 +210,17 @@ export default class Tokenizer extends ParserErrors { setStrict(strict: boolean): void { this.state.strict = strict; - if (!this.match(tt.num) && !this.match(tt.string)) return; - this.state.pos = this.state.start; - while (this.state.pos < this.state.lineStart) { - this.state.lineStart = - this.input.lastIndexOf("\n", this.state.lineStart - 2) + 1; - --this.state.curLine; + if (strict) { + // Throw an error for any string decimal escape found before/immediately + // after a "use strict" directive. Strict mode will be set at parse + // time for any literals that occur after the next node of the strict + // directive. + this.state.strictErrors.forEach((message, pos) => + /* eslint-disable @babel/development-internal/dry-error-messages */ + this.raise(pos, message), + ); + this.state.strictErrors.clear(); } - this.nextToken(); } curContext(): TokContext { @@ -230,8 +233,6 @@ export default class Tokenizer extends ParserErrors { nextToken(): void { const curContext = this.curContext(); if (!curContext?.preserveSpace) this.skipSpace(); - - this.state.octalPositions = []; this.state.start = this.state.pos; this.state.startLoc = this.state.curPosition(); if (this.state.pos >= this.length) { @@ -1121,9 +1122,8 @@ export default class Tokenizer extends ParserErrors { if (hasLeadingZero) { const integer = this.input.slice(start, this.state.pos); - if (this.state.strict) { - this.raise(start, Errors.StrictOctalLiteral); - } else { + this.recordStrictModeErrors(start, Errors.StrictOctalLiteral); + if (!this.state.strict) { // disallow numeric separators in non octal decimals and legacy octal likes const underscorePos = integer.indexOf("_"); if (underscorePos > 0) { @@ -1321,8 +1321,15 @@ export default class Tokenizer extends ParserErrors { } } - // Used to read escaped characters + recordStrictModeErrors(pos: number, message: string) { + if (this.state.strict && !this.state.strictErrors.has(pos)) { + this.raise(pos, message); + } else { + this.state.strictErrors.set(pos, message); + } + } + // Used to read escaped characters readEscapedChar(inTemplate: boolean): string | null { const throwOnInvalid = !inTemplate; const ch = this.input.charCodeAt(++this.state.pos); @@ -1364,8 +1371,11 @@ export default class Tokenizer extends ParserErrors { case charCodes.digit9: if (inTemplate) { return null; - } else if (this.state.strict) { - this.raise(this.state.pos - 1, Errors.StrictNumericEscape); + } else { + this.recordStrictModeErrors( + this.state.pos - 1, + Errors.StrictNumericEscape, + ); } // fall through default: @@ -1393,13 +1403,8 @@ export default class Tokenizer extends ParserErrors { ) { if (inTemplate) { return null; - } else if (this.state.strict) { - this.raise(codePos, Errors.StrictNumericEscape); } else { - // This property is used to throw an error for - // an octal literal in a directive that occurs prior - // to a "use strict" directive. - this.state.octalPositions.push(codePos); + this.recordStrictModeErrors(codePos, Errors.StrictNumericEscape); } } diff --git a/packages/babel-parser/src/tokenizer/state.js b/packages/babel-parser/src/tokenizer/state.js index b2a5bb4eae..ef61fde4ea 100644 --- a/packages/babel-parser/src/tokenizer/state.js +++ b/packages/babel-parser/src/tokenizer/state.js @@ -137,10 +137,15 @@ export default class State { // escape sequences must not be interpreted as keywords. containsEsc: boolean = false; - // This property is used to throw an error for - // an octal literal in a directive that occurs prior - // to a "use strict" directive. - octalPositions: number[] = []; + // This property is used to track the following errors + // - StrictNumericEscape + // - StrictOctalLiteral + // + // in a literal that occurs prior to/immediately after a "use strict" directive. + + // todo(JLHwung): set strictErrors to null and avoid recording string errors + // after a non-directive is parsed + strictErrors: Map = new Map(); // Names of exports store. `default` is stored as a name for both // `export default foo;` and `export { foo as default };`. diff --git a/packages/babel-parser/test/fixtures/core/escape-string/invalid-octal-strict-directive-function/input.js b/packages/babel-parser/test/fixtures/core/escape-string/invalid-decimal-escape-strict-directive-function/input.js similarity index 68% rename from packages/babel-parser/test/fixtures/core/escape-string/invalid-octal-strict-directive-function/input.js rename to packages/babel-parser/test/fixtures/core/escape-string/invalid-decimal-escape-strict-directive-function/input.js index ff2a818984..0c035a82a0 100644 --- a/packages/babel-parser/test/fixtures/core/escape-string/invalid-octal-strict-directive-function/input.js +++ b/packages/babel-parser/test/fixtures/core/escape-string/invalid-decimal-escape-strict-directive-function/input.js @@ -20,13 +20,3 @@ function d() { "\5"; } -function c() { - "use strict"; - 05; -} - -function d() { - "use strict"; - 04; - 05; -} diff --git a/packages/babel-parser/test/fixtures/core/escape-string/invalid-octal-strict-directive-function/output.json b/packages/babel-parser/test/fixtures/core/escape-string/invalid-decimal-escape-strict-directive-function/output.json similarity index 60% rename from packages/babel-parser/test/fixtures/core/escape-string/invalid-octal-strict-directive-function/output.json rename to packages/babel-parser/test/fixtures/core/escape-string/invalid-decimal-escape-strict-directive-function/output.json index 78d725b77c..4450ba694b 100644 --- a/packages/babel-parser/test/fixtures/core/escape-string/invalid-octal-strict-directive-function/output.json +++ b/packages/babel-parser/test/fixtures/core/escape-string/invalid-decimal-escape-strict-directive-function/output.json @@ -1,20 +1,17 @@ { "type": "File", - "start":0,"end":268,"loc":{"start":{"line":1,"column":0},"end":{"line":32,"column":1}}, + "start":0,"end":182,"loc":{"start":{"line":1,"column":0},"end":{"line":21,"column":1}}, "errors": [ - "SyntaxError: Legacy octal literals are not allowed in strict mode (2:4)", - "SyntaxError: Legacy octal literals are not allowed in strict mode (7:4)", - "SyntaxError: Legacy octal literals are not allowed in strict mode (8:4)", + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (2:4)", + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (7:4)", + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (8:4)", "SyntaxError: The only valid numeric escape in strict mode is '\\0' (14:4)", "SyntaxError: The only valid numeric escape in strict mode is '\\0' (19:4)", - "SyntaxError: The only valid numeric escape in strict mode is '\\0' (20:4)", - "SyntaxError: Legacy octal literals are not allowed in strict mode (25:2)", - "SyntaxError: Legacy octal literals are not allowed in strict mode (30:2)", - "SyntaxError: Legacy octal literals are not allowed in strict mode (31:2)" + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (20:4)" ], "program": { "type": "Program", - "start":0,"end":268,"loc":{"start":{"line":1,"column":0},"end":{"line":32,"column":1}}, + "start":0,"end":182,"loc":{"start":{"line":1,"column":0},"end":{"line":21,"column":1}}, "sourceType": "script", "interpreter": null, "body": [ @@ -40,11 +37,11 @@ "value": { "type": "DirectiveLiteral", "start":17,"end":21,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":6}}, - "value": "\\5", "extra": { "raw": "\"\\5\"", "rawValue": "\\5" - } + }, + "value": "\\5" } }, { @@ -53,11 +50,11 @@ "value": { "type": "DirectiveLiteral", "start":25,"end":37,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":14}}, - "value": "use strict", "extra": { "raw": "\"use strict\"", "rawValue": "use strict" - } + }, + "value": "use strict" } } ] @@ -85,11 +82,11 @@ "value": { "type": "DirectiveLiteral", "start":59,"end":63,"loc":{"start":{"line":7,"column":2},"end":{"line":7,"column":6}}, - "value": "\\4", "extra": { "raw": "\"\\4\"", "rawValue": "\\4" - } + }, + "value": "\\4" } }, { @@ -98,11 +95,11 @@ "value": { "type": "DirectiveLiteral", "start":67,"end":71,"loc":{"start":{"line":8,"column":2},"end":{"line":8,"column":6}}, - "value": "\\5", "extra": { "raw": "\"\\5\"", "rawValue": "\\5" - } + }, + "value": "\\5" } }, { @@ -111,11 +108,11 @@ "value": { "type": "DirectiveLiteral", "start":75,"end":87,"loc":{"start":{"line":9,"column":2},"end":{"line":9,"column":14}}, - "value": "use strict", "extra": { "raw": "\"use strict\"", "rawValue": "use strict" - } + }, + "value": "use strict" } } ] @@ -143,11 +140,11 @@ "value": { "type": "DirectiveLiteral", "start":109,"end":121,"loc":{"start":{"line":13,"column":2},"end":{"line":13,"column":14}}, - "value": "use strict", "extra": { "raw": "\"use strict\"", "rawValue": "use strict" - } + }, + "value": "use strict" } }, { @@ -156,11 +153,11 @@ "value": { "type": "DirectiveLiteral", "start":125,"end":129,"loc":{"start":{"line":14,"column":2},"end":{"line":14,"column":6}}, - "value": "\\5", "extra": { "raw": "\"\\5\"", "rawValue": "\\5" - } + }, + "value": "\\5" } } ] @@ -188,11 +185,11 @@ "value": { "type": "DirectiveLiteral", "start":151,"end":163,"loc":{"start":{"line":18,"column":2},"end":{"line":18,"column":14}}, - "value": "use strict", "extra": { "raw": "\"use strict\"", "rawValue": "use strict" - } + }, + "value": "use strict" } }, { @@ -201,11 +198,11 @@ "value": { "type": "DirectiveLiteral", "start":167,"end":171,"loc":{"start":{"line":19,"column":2},"end":{"line":19,"column":6}}, - "value": "\\4", "extra": { "raw": "\"\\4\"", "rawValue": "\\4" - } + }, + "value": "\\4" } }, { @@ -214,116 +211,11 @@ "value": { "type": "DirectiveLiteral", "start":175,"end":179,"loc":{"start":{"line":20,"column":2},"end":{"line":20,"column":6}}, - "value": "\\5", "extra": { "raw": "\"\\5\"", "rawValue": "\\5" - } - } - } - ] - } - }, - { - "type": "FunctionDeclaration", - "start":184,"end":222,"loc":{"start":{"line":23,"column":0},"end":{"line":26,"column":1}}, - "id": { - "type": "Identifier", - "start":193,"end":194,"loc":{"start":{"line":23,"column":9},"end":{"line":23,"column":10},"identifierName":"c"}, - "name": "c" - }, - "generator": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start":197,"end":222,"loc":{"start":{"line":23,"column":13},"end":{"line":26,"column":1}}, - "body": [ - { - "type": "ExpressionStatement", - "start":217,"end":220,"loc":{"start":{"line":25,"column":2},"end":{"line":25,"column":5}}, - "expression": { - "type": "NumericLiteral", - "start":217,"end":219,"loc":{"start":{"line":25,"column":2},"end":{"line":25,"column":4}}, - "extra": { - "rawValue": 5, - "raw": "05" }, - "value": 5 - } - } - ], - "directives": [ - { - "type": "Directive", - "start":201,"end":214,"loc":{"start":{"line":24,"column":2},"end":{"line":24,"column":15}}, - "value": { - "type": "DirectiveLiteral", - "start":201,"end":213,"loc":{"start":{"line":24,"column":2},"end":{"line":24,"column":14}}, - "value": "use strict", - "extra": { - "raw": "\"use strict\"", - "rawValue": "use strict" - } - } - } - ] - } - }, - { - "type": "FunctionDeclaration", - "start":224,"end":268,"loc":{"start":{"line":28,"column":0},"end":{"line":32,"column":1}}, - "id": { - "type": "Identifier", - "start":233,"end":234,"loc":{"start":{"line":28,"column":9},"end":{"line":28,"column":10},"identifierName":"d"}, - "name": "d" - }, - "generator": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start":237,"end":268,"loc":{"start":{"line":28,"column":13},"end":{"line":32,"column":1}}, - "body": [ - { - "type": "ExpressionStatement", - "start":257,"end":260,"loc":{"start":{"line":30,"column":2},"end":{"line":30,"column":5}}, - "expression": { - "type": "NumericLiteral", - "start":257,"end":259,"loc":{"start":{"line":30,"column":2},"end":{"line":30,"column":4}}, - "extra": { - "rawValue": 4, - "raw": "04" - }, - "value": 4 - } - }, - { - "type": "ExpressionStatement", - "start":263,"end":266,"loc":{"start":{"line":31,"column":2},"end":{"line":31,"column":5}}, - "expression": { - "type": "NumericLiteral", - "start":263,"end":265,"loc":{"start":{"line":31,"column":2},"end":{"line":31,"column":4}}, - "extra": { - "rawValue": 5, - "raw": "05" - }, - "value": 5 - } - } - ], - "directives": [ - { - "type": "Directive", - "start":241,"end":254,"loc":{"start":{"line":29,"column":2},"end":{"line":29,"column":15}}, - "value": { - "type": "DirectiveLiteral", - "start":241,"end":253,"loc":{"start":{"line":29,"column":2},"end":{"line":29,"column":14}}, - "value": "use strict", - "extra": { - "raw": "\"use strict\"", - "rawValue": "use strict" - } + "value": "\\5" } } ] diff --git a/packages/babel-parser/test/fixtures/core/escape-string/invalid-octal-strict-directive/input.js b/packages/babel-parser/test/fixtures/core/escape-string/invalid-decimal-escape-strict-directive/input.js similarity index 90% rename from packages/babel-parser/test/fixtures/core/escape-string/invalid-octal-strict-directive/input.js rename to packages/babel-parser/test/fixtures/core/escape-string/invalid-decimal-escape-strict-directive/input.js index ee60917379..0451ac64c2 100644 --- a/packages/babel-parser/test/fixtures/core/escape-string/invalid-octal-strict-directive/input.js +++ b/packages/babel-parser/test/fixtures/core/escape-string/invalid-decimal-escape-strict-directive/input.js @@ -8,7 +8,4 @@ "\4"; "\5"; -04; -05; - "\04 foo \05 bar \06"; diff --git a/packages/babel-parser/test/fixtures/core/escape-string/invalid-octal-strict-directive/output.json b/packages/babel-parser/test/fixtures/core/escape-string/invalid-decimal-escape-strict-directive/output.json similarity index 55% rename from packages/babel-parser/test/fixtures/core/escape-string/invalid-octal-strict-directive/output.json rename to packages/babel-parser/test/fixtures/core/escape-string/invalid-decimal-escape-strict-directive/output.json index e57ef5ed03..27f42a3a21 100644 --- a/packages/babel-parser/test/fixtures/core/escape-string/invalid-octal-strict-directive/output.json +++ b/packages/babel-parser/test/fixtures/core/escape-string/invalid-decimal-escape-strict-directive/output.json @@ -1,66 +1,24 @@ { "type": "File", - "start":0,"end":96,"loc":{"start":{"line":1,"column":0},"end":{"line":14,"column":22}}, + "start":0,"end":87,"loc":{"start":{"line":1,"column":0},"end":{"line":11,"column":22}}, "errors": [ + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (1:2)", + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (1:10)", + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (1:18)", + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (3:2)", + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (4:2)", "SyntaxError: The only valid numeric escape in strict mode is '\\0' (8:2)", "SyntaxError: The only valid numeric escape in strict mode is '\\0' (9:2)", - "SyntaxError: Legacy octal literals are not allowed in strict mode (11:0)", - "SyntaxError: Legacy octal literals are not allowed in strict mode (12:0)", - "SyntaxError: The only valid numeric escape in strict mode is '\\0' (14:2)", - "SyntaxError: The only valid numeric escape in strict mode is '\\0' (14:10)", - "SyntaxError: The only valid numeric escape in strict mode is '\\0' (14:18)", - "SyntaxError: Legacy octal literals are not allowed in strict mode (1:2)", - "SyntaxError: Legacy octal literals are not allowed in strict mode (1:10)", - "SyntaxError: Legacy octal literals are not allowed in strict mode (1:18)", - "SyntaxError: Legacy octal literals are not allowed in strict mode (3:2)", - "SyntaxError: Legacy octal literals are not allowed in strict mode (4:2)" + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (11:2)", + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (11:10)", + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (11:18)" ], "program": { "type": "Program", - "start":0,"end":96,"loc":{"start":{"line":1,"column":0},"end":{"line":14,"column":22}}, + "start":0,"end":87,"loc":{"start":{"line":1,"column":0},"end":{"line":11,"column":22}}, "sourceType": "script", "interpreter": null, - "body": [ - { - "type": "ExpressionStatement", - "start":65,"end":68,"loc":{"start":{"line":11,"column":0},"end":{"line":11,"column":3}}, - "expression": { - "type": "NumericLiteral", - "start":65,"end":67,"loc":{"start":{"line":11,"column":0},"end":{"line":11,"column":2}}, - "extra": { - "rawValue": 4, - "raw": "04" - }, - "value": 4 - } - }, - { - "type": "ExpressionStatement", - "start":69,"end":72,"loc":{"start":{"line":12,"column":0},"end":{"line":12,"column":3}}, - "expression": { - "type": "NumericLiteral", - "start":69,"end":71,"loc":{"start":{"line":12,"column":0},"end":{"line":12,"column":2}}, - "extra": { - "rawValue": 5, - "raw": "05" - }, - "value": 5 - } - }, - { - "type": "ExpressionStatement", - "start":74,"end":96,"loc":{"start":{"line":14,"column":0},"end":{"line":14,"column":22}}, - "expression": { - "type": "StringLiteral", - "start":74,"end":95,"loc":{"start":{"line":14,"column":0},"end":{"line":14,"column":21}}, - "extra": { - "rawValue": "\u0004 foo \u0005 bar \u0006", - "raw": "\"\\04 foo \\05 bar \\06\"" - }, - "value": "\u0004 foo \u0005 bar \u0006" - } - } - ], + "body": [], "directives": [ { "type": "Directive", @@ -68,11 +26,11 @@ "value": { "type": "DirectiveLiteral", "start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":21}}, - "value": "\\01 foo \\02 bar \\03", "extra": { "raw": "\"\\01 foo \\02 bar \\03\"", "rawValue": "\\01 foo \\02 bar \\03" - } + }, + "value": "\\01 foo \\02 bar \\03" } }, { @@ -81,11 +39,11 @@ "value": { "type": "DirectiveLiteral", "start":24,"end":28,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":4}}, - "value": "\\4", "extra": { "raw": "\"\\4\"", "rawValue": "\\4" - } + }, + "value": "\\4" } }, { @@ -94,11 +52,11 @@ "value": { "type": "DirectiveLiteral", "start":30,"end":34,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":4}}, - "value": "\\5", "extra": { "raw": "\"\\5\"", "rawValue": "\\5" - } + }, + "value": "\\5" } }, { @@ -107,11 +65,11 @@ "value": { "type": "DirectiveLiteral", "start":37,"end":49,"loc":{"start":{"line":6,"column":0},"end":{"line":6,"column":12}}, - "value": "use strict", "extra": { "raw": "\"use strict\"", "rawValue": "use strict" - } + }, + "value": "use strict" } }, { @@ -120,11 +78,11 @@ "value": { "type": "DirectiveLiteral", "start":52,"end":56,"loc":{"start":{"line":8,"column":0},"end":{"line":8,"column":4}}, - "value": "\\4", "extra": { "raw": "\"\\4\"", "rawValue": "\\4" - } + }, + "value": "\\4" } }, { @@ -133,11 +91,24 @@ "value": { "type": "DirectiveLiteral", "start":58,"end":62,"loc":{"start":{"line":9,"column":0},"end":{"line":9,"column":4}}, - "value": "\\5", "extra": { "raw": "\"\\5\"", "rawValue": "\\5" - } + }, + "value": "\\5" + } + }, + { + "type": "Directive", + "start":65,"end":87,"loc":{"start":{"line":11,"column":0},"end":{"line":11,"column":22}}, + "value": { + "type": "DirectiveLiteral", + "start":65,"end":86,"loc":{"start":{"line":11,"column":0},"end":{"line":11,"column":21}}, + "extra": { + "raw": "\"\\04 foo \\05 bar \\06\"", + "rawValue": "\\04 foo \\05 bar \\06" + }, + "value": "\\04 foo \\05 bar \\06" } } ] diff --git a/packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine-before-use-strict/input.js b/packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine-before-use-strict/input.js new file mode 100644 index 0000000000..71e0ab9148 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine-before-use-strict/input.js @@ -0,0 +1,5 @@ +() => { + "\8";"\9"; + "use strict"; + "\8";"\9"; +} diff --git a/packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine-before-use-strict/output.json b/packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine-before-use-strict/output.json new file mode 100644 index 0000000000..2390fa033b --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine-before-use-strict/output.json @@ -0,0 +1,103 @@ +{ + "type": "File", + "start":0,"end":51,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, + "errors": [ + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (2:4)", + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (2:9)", + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (4:4)", + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (4:9)" + ], + "program": { + "type": "Program", + "start":0,"end":51,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":51,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, + "expression": { + "type": "ArrowFunctionExpression", + "start":0,"end":51,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":6,"end":51,"loc":{"start":{"line":1,"column":6},"end":{"line":5,"column":1}}, + "body": [], + "directives": [ + { + "type": "Directive", + "start":10,"end":15,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":7}}, + "value": { + "type": "DirectiveLiteral", + "start":10,"end":14,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":6}}, + "extra": { + "raw": "\"\\8\"", + "rawValue": "\\8" + }, + "value": "\\8" + } + }, + { + "type": "Directive", + "start":15,"end":20,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":12}}, + "value": { + "type": "DirectiveLiteral", + "start":15,"end":19,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":11}}, + "extra": { + "raw": "\"\\9\"", + "rawValue": "\\9" + }, + "value": "\\9" + } + }, + { + "type": "Directive", + "start":23,"end":36,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":15}}, + "value": { + "type": "DirectiveLiteral", + "start":23,"end":35,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":14}}, + "extra": { + "raw": "\"use strict\"", + "rawValue": "use strict" + }, + "value": "use strict" + } + }, + { + "type": "Directive", + "start":39,"end":44,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":7}}, + "value": { + "type": "DirectiveLiteral", + "start":39,"end":43,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":6}}, + "extra": { + "raw": "\"\\8\"", + "rawValue": "\\8" + }, + "value": "\\8" + } + }, + { + "type": "Directive", + "start":44,"end":49,"loc":{"start":{"line":4,"column":7},"end":{"line":4,"column":12}}, + "value": { + "type": "DirectiveLiteral", + "start":44,"end":48,"loc":{"start":{"line":4,"column":7},"end":{"line":4,"column":11}}, + "extra": { + "raw": "\"\\9\"", + "rawValue": "\\9" + }, + "value": "\\9" + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine/input.js b/packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine/input.js index 191e53efd4..7a2c516686 100644 --- a/packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine/input.js +++ b/packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine/input.js @@ -1,5 +1,5 @@ -"\8","\9"; +"\8";"\9"; () => { "use strict"; - "\8", "\9"; + "\8";"\9"; } diff --git a/packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine/output.json b/packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine/output.json index 0c5b417df2..fad92eec30 100644 --- a/packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine/output.json +++ b/packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine/output.json @@ -1,87 +1,30 @@ { "type": "File", - "start":0,"end":50,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, + "start":0,"end":49,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, "errors": [ "SyntaxError: The only valid numeric escape in strict mode is '\\0' (4:4)", - "SyntaxError: The only valid numeric escape in strict mode is '\\0' (4:10)" + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (4:9)" ], "program": { "type": "Program", - "start":0,"end":50,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, + "start":0,"end":49,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, "sourceType": "script", "interpreter": null, "body": [ { "type": "ExpressionStatement", - "start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, - "expression": { - "type": "SequenceExpression", - "start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9}}, - "expressions": [ - { - "type": "StringLiteral", - "start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}}, - "extra": { - "rawValue": "8", - "raw": "\"\\8\"" - }, - "value": "8" - }, - { - "type": "StringLiteral", - "start":5,"end":9,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":9}}, - "extra": { - "rawValue": "9", - "raw": "\"\\9\"" - }, - "value": "9" - } - ] - } - }, - { - "type": "ExpressionStatement", - "start":11,"end":50,"loc":{"start":{"line":2,"column":0},"end":{"line":5,"column":1}}, + "start":11,"end":49,"loc":{"start":{"line":2,"column":0},"end":{"line":5,"column":1}}, "expression": { "type": "ArrowFunctionExpression", - "start":11,"end":50,"loc":{"start":{"line":2,"column":0},"end":{"line":5,"column":1}}, + "start":11,"end":49,"loc":{"start":{"line":2,"column":0},"end":{"line":5,"column":1}}, "id": null, "generator": false, "async": false, "params": [], "body": { "type": "BlockStatement", - "start":17,"end":50,"loc":{"start":{"line":2,"column":6},"end":{"line":5,"column":1}}, - "body": [ - { - "type": "ExpressionStatement", - "start":37,"end":48,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":13}}, - "expression": { - "type": "SequenceExpression", - "start":37,"end":47,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":12}}, - "expressions": [ - { - "type": "StringLiteral", - "start":37,"end":41,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":6}}, - "extra": { - "rawValue": "8", - "raw": "\"\\8\"" - }, - "value": "8" - }, - { - "type": "StringLiteral", - "start":43,"end":47,"loc":{"start":{"line":4,"column":8},"end":{"line":4,"column":12}}, - "extra": { - "rawValue": "9", - "raw": "\"\\9\"" - }, - "value": "9" - } - ] - } - } - ], + "start":17,"end":49,"loc":{"start":{"line":2,"column":6},"end":{"line":5,"column":1}}, + "body": [], "directives": [ { "type": "Directive", @@ -89,11 +32,37 @@ "value": { "type": "DirectiveLiteral", "start":21,"end":33,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":14}}, - "value": "use strict", "extra": { "raw": "\"use strict\"", "rawValue": "use strict" - } + }, + "value": "use strict" + } + }, + { + "type": "Directive", + "start":37,"end":42,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":7}}, + "value": { + "type": "DirectiveLiteral", + "start":37,"end":41,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":6}}, + "extra": { + "raw": "\"\\8\"", + "rawValue": "\\8" + }, + "value": "\\8" + } + }, + { + "type": "Directive", + "start":42,"end":47,"loc":{"start":{"line":4,"column":7},"end":{"line":4,"column":12}}, + "value": { + "type": "DirectiveLiteral", + "start":42,"end":46,"loc":{"start":{"line":4,"column":7},"end":{"line":4,"column":11}}, + "extra": { + "raw": "\"\\9\"", + "rawValue": "\\9" + }, + "value": "\\9" } } ] @@ -101,6 +70,33 @@ } } ], - "directives": [] + "directives": [ + { + "type": "Directive", + "start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}, + "value": { + "type": "DirectiveLiteral", + "start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}}, + "extra": { + "raw": "\"\\8\"", + "rawValue": "\\8" + }, + "value": "\\8" + } + }, + { + "type": "Directive", + "start":5,"end":10,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":10}}, + "value": { + "type": "DirectiveLiteral", + "start":5,"end":9,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":9}}, + "extra": { + "raw": "\"\\9\"", + "rawValue": "\\9" + }, + "value": "\\9" + } + } + ] } } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/escape-string/numeric-escape/input.js b/packages/babel-parser/test/fixtures/core/escape-string/numeric-escape/input.js deleted file mode 100644 index b86f21808d..0000000000 --- a/packages/babel-parser/test/fixtures/core/escape-string/numeric-escape/input.js +++ /dev/null @@ -1 +0,0 @@ -function hello() { 'use strict'; "\1"; } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/escape-string/numeric-escape/output.json b/packages/babel-parser/test/fixtures/core/escape-string/numeric-escape/output.json deleted file mode 100644 index e9e573c73f..0000000000 --- a/packages/babel-parser/test/fixtures/core/escape-string/numeric-escape/output.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "type": "File", - "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}}, - "errors": [ - "SyntaxError: The only valid numeric escape in strict mode is '\\0' (1:35)" - ], - "program": { - "type": "Program", - "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}}, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "FunctionDeclaration", - "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}}, - "id": { - "type": "Identifier", - "start":9,"end":14,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":14},"identifierName":"hello"}, - "name": "hello" - }, - "generator": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start":17,"end":40,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":40}}, - "body": [], - "directives": [ - { - "type": "Directive", - "start":19,"end":32,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":32}}, - "value": { - "type": "DirectiveLiteral", - "start":19,"end":31,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":31}}, - "value": "use strict", - "extra": { - "raw": "'use strict'", - "rawValue": "use strict" - } - } - }, - { - "type": "Directive", - "start":33,"end":38,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":38}}, - "value": { - "type": "DirectiveLiteral", - "start":33,"end":37,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":37}}, - "value": "\\1", - "extra": { - "raw": "\"\\1\"", - "rawValue": "\\1" - } - } - } - ] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict-function/input.js b/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict-function/input.js new file mode 100644 index 0000000000..fca3d2695c --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict-function/input.js @@ -0,0 +1,10 @@ +function c() { + "use strict"; + 05; +} + +function d() { + "use strict"; + 04; + 05; +} diff --git a/packages/babel-parser/test/fixtures/core/escape-string/invalid-octal-strict-directive-function/options.json b/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict-function/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/core/escape-string/invalid-octal-strict-directive-function/options.json rename to packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict-function/options.json diff --git a/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict-function/output.json b/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict-function/output.json new file mode 100644 index 0000000000..86f191f936 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict-function/output.json @@ -0,0 +1,123 @@ +{ + "type": "File", + "start":0,"end":84,"loc":{"start":{"line":1,"column":0},"end":{"line":10,"column":1}}, + "errors": [ + "SyntaxError: Legacy octal literals are not allowed in strict mode (3:2)", + "SyntaxError: Legacy octal literals are not allowed in strict mode (8:2)", + "SyntaxError: Legacy octal literals are not allowed in strict mode (9:2)" + ], + "program": { + "type": "Program", + "start":0,"end":84,"loc":{"start":{"line":1,"column":0},"end":{"line":10,"column":1}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, + "id": { + "type": "Identifier", + "start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10},"identifierName":"c"}, + "name": "c" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":13,"end":38,"loc":{"start":{"line":1,"column":13},"end":{"line":4,"column":1}}, + "body": [ + { + "type": "ExpressionStatement", + "start":33,"end":36,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":5}}, + "expression": { + "type": "NumericLiteral", + "start":33,"end":35,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":4}}, + "extra": { + "rawValue": 5, + "raw": "05" + }, + "value": 5 + } + } + ], + "directives": [ + { + "type": "Directive", + "start":17,"end":30,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":15}}, + "value": { + "type": "DirectiveLiteral", + "start":17,"end":29,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":14}}, + "extra": { + "raw": "\"use strict\"", + "rawValue": "use strict" + }, + "value": "use strict" + } + } + ] + } + }, + { + "type": "FunctionDeclaration", + "start":40,"end":84,"loc":{"start":{"line":6,"column":0},"end":{"line":10,"column":1}}, + "id": { + "type": "Identifier", + "start":49,"end":50,"loc":{"start":{"line":6,"column":9},"end":{"line":6,"column":10},"identifierName":"d"}, + "name": "d" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":53,"end":84,"loc":{"start":{"line":6,"column":13},"end":{"line":10,"column":1}}, + "body": [ + { + "type": "ExpressionStatement", + "start":73,"end":76,"loc":{"start":{"line":8,"column":2},"end":{"line":8,"column":5}}, + "expression": { + "type": "NumericLiteral", + "start":73,"end":75,"loc":{"start":{"line":8,"column":2},"end":{"line":8,"column":4}}, + "extra": { + "rawValue": 4, + "raw": "04" + }, + "value": 4 + } + }, + { + "type": "ExpressionStatement", + "start":79,"end":82,"loc":{"start":{"line":9,"column":2},"end":{"line":9,"column":5}}, + "expression": { + "type": "NumericLiteral", + "start":79,"end":81,"loc":{"start":{"line":9,"column":2},"end":{"line":9,"column":4}}, + "extra": { + "rawValue": 5, + "raw": "05" + }, + "value": 5 + } + } + ], + "directives": [ + { + "type": "Directive", + "start":57,"end":70,"loc":{"start":{"line":7,"column":2},"end":{"line":7,"column":15}}, + "value": { + "type": "DirectiveLiteral", + "start":57,"end":69,"loc":{"start":{"line":7,"column":2},"end":{"line":7,"column":14}}, + "extra": { + "raw": "\"use strict\"", + "rawValue": "use strict" + }, + "value": "use strict" + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict/input.js b/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict/input.js new file mode 100644 index 0000000000..147abeb937 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict/input.js @@ -0,0 +1 @@ +"use strict"; 04; 05; diff --git a/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict/options.json b/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict/options.json new file mode 100644 index 0000000000..b412ffe671 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "script" +} diff --git a/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict/output.json b/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict/output.json new file mode 100644 index 0000000000..e184e7d7f8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/legacy-octal/legacy-octal-after-use-strict/output.json @@ -0,0 +1,57 @@ +{ + "type": "File", + "start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":21}}, + "errors": [ + "SyntaxError: Legacy octal literals are not allowed in strict mode (1:14)", + "SyntaxError: Legacy octal literals are not allowed in strict mode (1:18)" + ], + "program": { + "type": "Program", + "start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":21}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":14,"end":17,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":17}}, + "expression": { + "type": "NumericLiteral", + "start":14,"end":16,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":16}}, + "extra": { + "rawValue": 4, + "raw": "04" + }, + "value": 4 + } + }, + { + "type": "ExpressionStatement", + "start":18,"end":21,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":21}}, + "expression": { + "type": "NumericLiteral", + "start":18,"end":20,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":20}}, + "extra": { + "rawValue": 5, + "raw": "05" + }, + "value": 5 + } + } + ], + "directives": [ + { + "type": "Directive", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "value": { + "type": "DirectiveLiteral", + "start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}}, + "extra": { + "raw": "\"use strict\"", + "rawValue": "use strict" + }, + "value": "use strict" + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0216/output.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0216/output.json index 7d00761d55..fa26c140fe 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0216/output.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0216/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, "errors": [ - "SyntaxError: Legacy octal literals are not allowed in strict mode (1:2)" + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (1:2)" ], "program": { "type": "Program", @@ -17,11 +17,11 @@ "value": { "type": "DirectiveLiteral", "start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}}, - "value": "\\1", "extra": { "raw": "\"\\1\"", "rawValue": "\\1" - } + }, + "value": "\\1" } }, { @@ -30,11 +30,11 @@ "value": { "type": "DirectiveLiteral", "start":6,"end":18,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":18}}, - "value": "use strict", "extra": { "raw": "'use strict'", "rawValue": "use strict" - } + }, + "value": "use strict" } } ] diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0217/output.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0217/output.json index e9e573c73f..66906dba7f 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0217/output.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0217/output.json @@ -32,11 +32,11 @@ "value": { "type": "DirectiveLiteral", "start":19,"end":31,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":31}}, - "value": "use strict", "extra": { "raw": "'use strict'", "rawValue": "use strict" - } + }, + "value": "use strict" } }, { @@ -45,11 +45,11 @@ "value": { "type": "DirectiveLiteral", "start":33,"end":37,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":37}}, - "value": "\\1", "extra": { "raw": "\"\\1\"", "rawValue": "\\1" - } + }, + "value": "\\1" } } ] diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0221/output.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0221/output.json index 13226ad500..d0760f1b38 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0221/output.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0221/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":55,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":55}}, "errors": [ - "SyntaxError: Legacy octal literals are not allowed in strict mode (1:36)" + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (1:36)" ], "program": { "type": "Program", @@ -32,11 +32,11 @@ "value": { "type": "DirectiveLiteral", "start":19,"end":38,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":38}}, - "value": "octal directive\\1", "extra": { "raw": "\"octal directive\\1\"", "rawValue": "octal directive\\1" - } + }, + "value": "octal directive\\1" } }, { @@ -45,11 +45,11 @@ "value": { "type": "DirectiveLiteral", "start":40,"end":52,"loc":{"start":{"line":1,"column":40},"end":{"line":1,"column":52}}, - "value": "use strict", "extra": { "raw": "\"use strict\"", "rawValue": "use strict" - } + }, + "value": "use strict" } } ] diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0222/output.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0222/output.json index 43d10e2912..2ed529ae45 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0222/output.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0222/output.json @@ -2,8 +2,8 @@ "type": "File", "start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":76}}, "errors": [ - "SyntaxError: Legacy octal literals are not allowed in strict mode (1:36)", - "SyntaxError: Legacy octal literals are not allowed in strict mode (1:57)" + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (1:36)", + "SyntaxError: The only valid numeric escape in strict mode is '\\0' (1:57)" ], "program": { "type": "Program", @@ -33,11 +33,11 @@ "value": { "type": "DirectiveLiteral", "start":19,"end":38,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":38}}, - "value": "octal directive\\1", "extra": { "raw": "\"octal directive\\1\"", "rawValue": "octal directive\\1" - } + }, + "value": "octal directive\\1" } }, { @@ -46,11 +46,11 @@ "value": { "type": "DirectiveLiteral", "start":40,"end":59,"loc":{"start":{"line":1,"column":40},"end":{"line":1,"column":59}}, - "value": "octal directive\\2", "extra": { "raw": "\"octal directive\\2\"", "rawValue": "octal directive\\2" - } + }, + "value": "octal directive\\2" } }, { @@ -59,11 +59,11 @@ "value": { "type": "DirectiveLiteral", "start":61,"end":73,"loc":{"start":{"line":1,"column":61},"end":{"line":1,"column":73}}, - "value": "use strict", "extra": { "raw": "\"use strict\"", "rawValue": "use strict" - } + }, + "value": "use strict" } } ]