Skip to content

Commit

Permalink
Force-retokenize regexps when a slash is found in expression position
Browse files Browse the repository at this point in the history
Issue #751
Issue #589
  • Loading branch information
marijnh committed Nov 5, 2018
1 parent 3df4763 commit f0cbb35
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions acorn/src/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ pp.parseSubscripts = function(base, startPos, startLoc, noCalls) {
// or `{}`.

pp.parseExprAtom = function(refDestructuringErrors) {
// If a division operator appears in an expression position, the
// tokenizer got confused, and we force it to read a regexp instead.
if (this.type === tt.slash) this.readRegexp()

let node, canBeArrow = this.potentialArrowAt === this.start
switch (this.type) {
case tt._super:
Expand Down
1 change: 1 addition & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -26840,6 +26840,7 @@ test("x = {foo: function x() {} / divide}", {});
test("foo; function f() {} /regexp/", {});
test("{function f() {} /regexp/}", {});
test("function fn() {return\nfunction foo() {}\n/42/}", {});
test("var x\n/foo/", {});

test("{}/=/", {
type: "Program",
Expand Down

0 comments on commit f0cbb35

Please sign in to comment.