Skip to content

Commit

Permalink
Fix tokenizing of slash after propery with keyword name
Browse files Browse the repository at this point in the history
FIX: Fix an issue where a slash after a call to a propery named the same
as some keywords would be tokenized as a regular expression.

Closes #1232
  • Loading branch information
marijnh committed Aug 9, 2023
1 parent e7c9171 commit 38b7af4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions acorn-loose/src/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ lp.parsePropertyAccessor = function() {
lp.parseIdent = function() {
let name = this.tok.type === tt.name ? this.tok.value : this.tok.type.keyword
if (!name) return this.dummyIdent()
if (this.tok.type.keyword) this.toks.type = tt.name
let node = this.startNode()
this.next()
node.name = name
Expand Down
1 change: 1 addition & 0 deletions acorn/src/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,7 @@ pp.parseIdentNode = function() {
(this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
this.context.pop()
}
this.type = tt.name
} else {
this.unexpected()
}
Expand Down
37 changes: 37 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29929,3 +29929,40 @@ test(`typeof async function f(){}

testFail(`typeof async function f(){}
/foo/`, "Unexpected token (2:5)", { ecmaVersion: 8, locations: true })

test("foo.if() / 2", {
type: "Program",
body: [
{
type: "ExpressionStatement",
expression: {
type: "BinaryExpression",
left: {
type: "CallExpression",
callee: {
type: "MemberExpression",
object: {
type: "Identifier",
name: "foo"
},
property: {
type: "Identifier",
name: "if"
},
computed: false
},
arguments: []
},
operator: "/",
right: {
type: "Literal",
value: 2,
raw: "2"
}
}
}
],
sourceType: "script"
}, {
ecmaVersion: 5
})

0 comments on commit 38b7af4

Please sign in to comment.