Skip to content

Commit f85a712

Browse files
committed
Fix contextual let heuristic to account for escapes and astral characters
FIX: Fix a bug where let bindings containing escaped or astral characters were sometimes not properly parsed. Closes #1036
1 parent 43c989c commit f85a712

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

acorn/src/statement.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ pp.isLet = function(context) {
4242
// Statement) is allowed here. If context is not empty then only a Statement
4343
// is allowed. However, `let [` is an explicit negative lookahead for
4444
// ExpressionStatement, so special-case it first.
45-
if (nextCh === 91) return true // '['
45+
if (nextCh === 91 || nextCh === 92 || nextCh > 0xd7ff && nextCh < 0xdc00) return true // '[', '/', astral
4646
if (context) return false
4747

4848
if (nextCh === 123) return true // '{'
4949
if (isIdentifierStart(nextCh, true)) {
5050
let pos = next + 1
51-
while (isIdentifierChar(this.input.charCodeAt(pos), true)) ++pos
51+
while (isIdentifierChar(nextCh = this.input.charCodeAt(pos), true)) ++pos
52+
if (nextCh === 92 || nextCh > 0xd7ff && nextCh < 0xdc00) return true
5253
let ident = this.input.slice(next, pos)
5354
if (!keywordRelationalOperator.test(ident)) return true
5455
}

test/tests-harmony.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16618,3 +16618,9 @@ test("[[...[], 0].x] = []", {
1661816618
],
1661916619
sourceType: "script"
1662016620
}, {ecmaVersion: 6})
16621+
16622+
// #1036
16623+
test("let \u0061;", {}, {ecmaVersion: 6})
16624+
test("let in\u0061;", {}, {ecmaVersion: 6})
16625+
test("let in𝐬𝐭𝐚𝐧𝐜𝐞𝐨𝐟;", {}, {ecmaVersion: 6})
16626+
test("let 𝐢𝐧;", {}, {ecmaVersion: 6})

0 commit comments

Comments
 (0)