From 847b3599bcca2c91506934ed608612d1bbabf913 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sun, 27 Oct 2024 11:32:19 +0900 Subject: [PATCH] change loose parser --- acorn-loose/src/statement.js | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/acorn-loose/src/statement.js b/acorn-loose/src/statement.js index 0d4e25d9..1befa702 100644 --- a/acorn-loose/src/statement.js +++ b/acorn-loose/src/statement.js @@ -565,9 +565,19 @@ lp.parseWithClause = function() { this.eat(tt.braceL) if (this.curLineStart > continuedLine) continuedLine = this.curLineStart while (!this.closes(tt.braceR, indent + (this.curLineStart <= continuedLine ? 1 : 0), line)) { - const attr = this.parseImportAttribute() - if (!attr) break - nodes.push(attr) + const attr = this.startNode() + attr.key = this.tok.type === tt.string ? this.parseExprAtom() : this.parseIdent() + if (this.eat(tt.colon)) { + if (this.tok.type === tt.string) + attr.value = this.parseExprAtom() + else attr.value = this.dummyString() + } else { + if (isDummy(attr.key)) break + if (this.tok.type === tt.string) + attr.value = this.parseExprAtom() + else break + } + nodes.push(this.finishNode(attr, "ImportAttribute")) this.eat(tt.comma) } this.eat(tt.braceR) @@ -575,21 +585,6 @@ lp.parseWithClause = function() { return nodes } -lp.parseImportAttribute = function() { - const node = this.startNode() - node.key = this.tok.type === tt.string ? this.parseExprAtom() : this.parseIdent() - this.eat(tt.colon) - if (this.tok.type === tt.string) { - node.value = this.parseExprAtom() - } else { - if (isDummy(node.key)) { - return null - } - node.value = this.dummyString() - } - return this.finishNode(node, "ImportAttribute") -} - lp.parseExportSpecifierList = function() { let elts = [] let indent = this.curIndent, line = this.curLineStart, continuedLine = this.nextLineStart