Skip to content

Commit

Permalink
Fix tokenization of properties named 'class' or 'function'
Browse files Browse the repository at this point in the history
FIX: Fix an issue where tokenizing (without parsing) an object literal with a property
named `class` or `function` could, in some circumstance, put the tokenizer into an
invalid state.

Closes #1242
  • Loading branch information
marijnh committed Aug 28, 2023
1 parent c5b8cae commit 6cae5ec
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion acorn/src/tokencontext.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pp.updateContext = function(prevType) {
this.exprAllowed = type.beforeExpr
}

// Used to handle egde cases when token context could not be inferred correctly during tokenization phase
// Used to handle edge cases when token context could not be inferred correctly during tokenization phase

pp.overrideContext = function(tokenCtx) {
if (this.curContext() !== tokenCtx) {
Expand Down Expand Up @@ -132,6 +132,13 @@ tt._function.updateContext = tt._class.updateContext = function(prevType) {
this.exprAllowed = false
}

tt.colon.updateContext = function() {
if (this.curContext().token === "function") {
this.context.pop()
this.exprAllowed = true
}
}

tt.backQuote.updateContext = function() {
if (this.curContext() === types.q_tmpl)
this.context.pop()
Expand Down

0 comments on commit 6cae5ec

Please sign in to comment.