Skip to content

Commit

Permalink
Fix inappropriate regexp tokenizing after anon class/function in for …
Browse files Browse the repository at this point in the history
…spec

Closes acornjs#982
  • Loading branch information
marijnh committed Sep 29, 2020
1 parent e232621 commit 9e308bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion acorn/src/tokencontext.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ tt.incDec.updateContext = function() {
}

tt._function.updateContext = tt._class.updateContext = function(prevType) {
if (prevType.beforeExpr && prevType !== tt.semi && prevType !== tt._else &&
if (prevType.beforeExpr && prevType !== tt._else &&
!(prevType === tt.semi && this.curContext() !== types.p_stat) &&
!(prevType === tt._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) &&
!((prevType === tt.colon || prevType === tt.braceL) && this.curContext() === types.b_stat))
this.context.push(types.f_expr)
Expand Down
6 changes: 6 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29478,3 +29478,9 @@ test("'use strict'\n!=10; 05", {}, {ecmaVersion: 6})
testFail("\"use strict\"\nfoo\n05", "Invalid number (3:0)", {ecmaVersion: 6})
testFail("\"use strict\"\n;(foo)\n05", "Invalid number (3:0)", {ecmaVersion: 6})
testFail("'use strict'\n!blah; 05", "Invalid number (2:7)", {ecmaVersion: 6})

// Make sure a slash after an anonymous function/class in a for spec is treated as division
test("for (; function () {} / 1;);", {}, {ecmaVersion: 6})
test("for (; class {} / 1;);", {}, {ecmaVersion: 6})
test("for (;; function () {} / 1);", {}, {ecmaVersion: 6})
test("for (;; class {} / 1);", {}, {ecmaVersion: 6})

0 comments on commit 9e308bb

Please sign in to comment.