JS: fix import statement/call parsing at module level
Taco de Wolff
3 years ago
180 | 180 |
case ErrorToken:
|
181 | 181 |
return
|
182 | 182 |
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 |
}
|
185 | 195 |
case ExportToken:
|
186 | 196 |
exportStmt := p.parseExportStmt()
|
187 | 197 |
module.List = append(module.List, &exportStmt)
|
|
584 | 594 |
}
|
585 | 595 |
|
586 | 596 |
func (p *Parser) parseImportStmt() (importStmt ImportStmt) {
|
587 | |
// assume we're at import
|
588 | |
p.next()
|
|
597 |
// assume we're passed import
|
589 | 598 |
if p.tt == StringToken {
|
590 | 599 |
importStmt.Module = p.data
|
591 | 600 |
p.next()
|
265 | 265 |
{"x = new new.target", "Stmt(x=(new (new.target)))"},
|
266 | 266 |
{"x = new import.meta", "Stmt(x=(new (import.meta)))"},
|
267 | 267 |
{"x = import(a)", "Stmt(x=(import(a)))"},
|
|
268 |
{"import('module')", "Stmt(import('module'))"},
|
268 | 269 |
{"x = +a", "Stmt(x=(+a))"},
|
269 | 270 |
{"x = ++a", "Stmt(x=(++a))"},
|
270 | 271 |
{"x = -a", "Stmt(x=(-a))"},
|