Skip to content

Commit

Permalink
Fix misleading error message for octal escapes in template strings
Browse files Browse the repository at this point in the history
This updates the error message for something like `\033` to include something about template strings, rather than claiming that the error is due to strict mode.
  • Loading branch information
not-an-aardvark authored and marijnh committed Mar 3, 2018
1 parent a0cc9fe commit 42f6379
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/tokenize.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,12 @@ pp.readEscapedChar = function(inTemplate) {
this.pos += octalStr.length - 1
ch = this.input.charCodeAt(this.pos)
if ((octalStr !== "0" || ch == 56 || ch == 57) && (this.strict || inTemplate)) {
this.invalidStringToken(this.pos - 1 - octalStr.length, "Octal literal in strict mode")
this.invalidStringToken(
this.pos - 1 - octalStr.length,
inTemplate
? "Octal literal in template string"
: "Octal literal in strict mode"
)
}
return String.fromCharCode(octal)
}
Expand Down
6 changes: 4 additions & 2 deletions test/tests-harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -13281,7 +13281,7 @@ testFail("[...a, b] = c", "Comma is not permitted after the rest element (1:5)",

testFail("({ t(eval) { \"use strict\"; } });", "Binding eval in strict mode (1:5)", {ecmaVersion: 6});

testFail("\"use strict\"; `${test}\\02`;", "Octal literal in strict mode (1:22)", {ecmaVersion: 6});
testFail("\"use strict\"; `${test}\\02`;", "Octal literal in template string (1:22)", {ecmaVersion: 6});

testFail("if (1) import \"acorn\";", "'import' and 'export' may only appear at the top level (1:7)", {ecmaVersion: 6});

Expand Down Expand Up @@ -14591,7 +14591,9 @@ test("export default function foo() {} false", {

// https://github.com/acornjs/acorn/issues/274

testFail("`\\07`", "Octal literal in strict mode (1:1)", {ecmaVersion: 6});
testFail("`\\07`", "Octal literal in template string (1:1)", {ecmaVersion: 6});

testFail("(function(){ 'use strict'; '\\07'; })", "Octal literal in strict mode (1:28)", {ecmaVersion: 6});

// https://github.com/acornjs/acorn/issues/277

Expand Down

0 comments on commit 42f6379

Please sign in to comment.