Fix extends keyword bug (superclass name was interpreted as an HTML expression)
authorNick Downing <nick@ndcode.org>
Sun, 9 Jan 2022 01:36:19 +0000 (12:36 +1100)
committerNick Downing <nick@ndcode.org>
Sun, 9 Jan 2022 01:36:48 +0000 (12:36 +1100)
src/expression.js

index 78bc2df..b70cf7d 100644 (file)
@@ -259,7 +259,7 @@ pp.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forInit)
     // only could be private fields in 'in', such as #x in obj
     if (this.type !== tt._in) this.unexpected()
   } else {
-    expr = this.parseExprSubscripts(refDestructuringErrors, forInit)
+    expr = this.parseExprSubscripts(refDestructuringErrors, forInit, true) // Nick allowHTML = true
     if (this.checkExpressionErrors(refDestructuringErrors)) return expr
     while (this.type.postfix && !this.canInsertSemicolon()) {
       let node = this.startNodeAt(startPos, startLoc)
@@ -291,12 +291,12 @@ function isPrivateFieldAccess(node) {
 
 // Parse call, dot, and `[]`-subscript expressions.
 
-pp.parseExprSubscripts = function(refDestructuringErrors, forInit) {
+pp.parseExprSubscripts = function(refDestructuringErrors, forInit, allowHTML) { // Nick allowHTML
   let startPos = this.start, startLoc = this.startLoc
   let expr = this.parseExprAtom(refDestructuringErrors, forInit)
   if (expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")")
     return expr
-  let result = this.parseSubscripts(expr, startPos, startLoc, false, forInit)
+  let result = this.parseSubscripts(expr, startPos, startLoc, false, forInit, allowHTML) // Nick allowHTML
   if (refDestructuringErrors && result.type === "MemberExpression") {
     if (refDestructuringErrors.parenthesizedAssign >= result.start) refDestructuringErrors.parenthesizedAssign = -1
     if (refDestructuringErrors.parenthesizedBind >= result.start) refDestructuringErrors.parenthesizedBind = -1
@@ -305,14 +305,14 @@ pp.parseExprSubscripts = function(refDestructuringErrors, forInit) {
   return result
 }
 
-pp.parseSubscripts = function(base, startPos, startLoc, noCalls, forInit) {
+pp.parseSubscripts = function(base, startPos, startLoc, noCalls, forInit, allowHTML) { // Nick allowHTML
   let maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
       this.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 &&
       this.potentialArrowAt === base.start
   let optionalChained = false
 
   while (true) {
-    let element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit)
+    let element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit, allowHTML) // Nick allowHTML
 
     if (element.optional) optionalChained = true
     if (element === base || element.type === "ArrowFunctionExpression") {
@@ -328,7 +328,7 @@ pp.parseSubscripts = function(base, startPos, startLoc, noCalls, forInit) {
   }
 }
 
-pp.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit) {
+pp.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit, allowHTML) { // Nick allowHTML
   let optionalSupported = this.options.ecmaVersion >= 11
   let optional = optionalSupported && this.eat(tt.questionDot)
   if (noCalls && optional) this.raise(this.lastTokStart, "Optional chaining cannot appear in the callee of new expressions")
@@ -393,7 +393,7 @@ pp.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow,
     node.tag = base
     node.quasi = this.parseTemplate({isTagged: true})
     base = this.finishNode(node, "TaggedTemplateExpression")
-  } else if (this.type === tt.braceL) { // Nick
+  } else if (allowHTML && this.type === tt.braceL) { // Nick
     let node = this.startNodeAt(startPos, startLoc)
     node.tag = base
     if (
@@ -716,7 +716,7 @@ pp.parseNew = function() {
     return this.finishNode(node, "MetaProperty")
   }
   let startPos = this.start, startLoc = this.startLoc, isImport = this.type === tt._import
-  node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true, false)
+  node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true, false, false) // Nick allowHTML = false
   if (isImport && node.callee.type === "ImportExpression") {
     this.raise(startPos, "Cannot use new with import()")
   }