Skip to content

Commit

Permalink
Fix contextual let heuristic to account for escapes and astral charac…
Browse files Browse the repository at this point in the history
…ters

FIX: Fix a bug where let bindings containing escaped or astral characters were sometimes
not properly parsed.

Closes #1036
  • Loading branch information
marijnh committed May 18, 2021
1 parent 43c989c commit f85a712
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions acorn/src/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ pp.isLet = function(context) {
// Statement) is allowed here. If context is not empty then only a Statement
// is allowed. However, `let [` is an explicit negative lookahead for
// ExpressionStatement, so special-case it first.
if (nextCh === 91) return true // '['
if (nextCh === 91 || nextCh === 92 || nextCh > 0xd7ff && nextCh < 0xdc00) return true // '[', '/', astral
if (context) return false

if (nextCh === 123) return true // '{'
if (isIdentifierStart(nextCh, true)) {
let pos = next + 1
while (isIdentifierChar(this.input.charCodeAt(pos), true)) ++pos
while (isIdentifierChar(nextCh = this.input.charCodeAt(pos), true)) ++pos
if (nextCh === 92 || nextCh > 0xd7ff && nextCh < 0xdc00) return true
let ident = this.input.slice(next, pos)
if (!keywordRelationalOperator.test(ident)) return true
}
Expand Down
6 changes: 6 additions & 0 deletions test/tests-harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -16618,3 +16618,9 @@ test("[[...[], 0].x] = []", {
],
sourceType: "script"
}, {ecmaVersion: 6})

// #1036
test("let \u0061;", {}, {ecmaVersion: 6})
test("let in\u0061;", {}, {ecmaVersion: 6})
test("let in𝐬𝐭𝐚𝐧𝐜𝐞𝐨𝐟;", {}, {ecmaVersion: 6})
test("let 𝐢𝐧;", {}, {ecmaVersion: 6})

0 comments on commit f85a712

Please sign in to comment.