Codebase list golang-github-tdewolff-parse / 8c2ea15
JS: fix import statement/call parsing at module level Taco de Wolff 3 years ago
2 changed file(s) with 14 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
180180 case ErrorToken:
181181 return
182182 case ImportToken:
183 importStmt := p.parseImportStmt()
184 module.List = append(module.List, &importStmt)
183 p.next()
184 if p.tt == OpenParenToken {
185 // could be an import call expression
186 left := &LiteralExpr{ImportToken, []byte("import")}
187 p.exprLevel++
188 suffix := p.parseExpressionSuffix(left, OpExpr, OpCall)
189 p.exprLevel--
190 module.List = append(module.List, &ExprStmt{suffix})
191 } else {
192 importStmt := p.parseImportStmt()
193 module.List = append(module.List, &importStmt)
194 }
185195 case ExportToken:
186196 exportStmt := p.parseExportStmt()
187197 module.List = append(module.List, &exportStmt)
584594 }
585595
586596 func (p *Parser) parseImportStmt() (importStmt ImportStmt) {
587 // assume we're at import
588 p.next()
597 // assume we're passed import
589598 if p.tt == StringToken {
590599 importStmt.Module = p.data
591600 p.next()
265265 {"x = new new.target", "Stmt(x=(new (new.target)))"},
266266 {"x = new import.meta", "Stmt(x=(new (import.meta)))"},
267267 {"x = import(a)", "Stmt(x=(import(a)))"},
268 {"import('module')", "Stmt(import('module'))"},
268269 {"x = +a", "Stmt(x=(+a))"},
269270 {"x = ++a", "Stmt(x=(++a))"},
270271 {"x = -a", "Stmt(x=(-a))"},