diff --git a/js/parse.go b/js/parse.go index ce236f6..71c21ae 100644 --- a/js/parse.go +++ b/js/parse.go @@ -181,8 +181,18 @@ func (p *Parser) parseModule() (module BlockStmt) { case ErrorToken: return case ImportToken: - importStmt := p.parseImportStmt() - module.List = append(module.List, &importStmt) + p.next() + if p.tt == OpenParenToken { + // could be an import call expression + left := &LiteralExpr{ImportToken, []byte("import")} + p.exprLevel++ + suffix := p.parseExpressionSuffix(left, OpExpr, OpCall) + p.exprLevel-- + module.List = append(module.List, &ExprStmt{suffix}) + } else { + importStmt := p.parseImportStmt() + module.List = append(module.List, &importStmt) + } case ExportToken: exportStmt := p.parseExportStmt() module.List = append(module.List, &exportStmt) @@ -585,8 +595,7 @@ func (p *Parser) parseBlockStmt(in string) (blockStmt BlockStmt) { } func (p *Parser) parseImportStmt() (importStmt ImportStmt) { - // assume we're at import - p.next() + // assume we're passed import if p.tt == StringToken { importStmt.Module = p.data p.next() diff --git a/js/parse_test.go b/js/parse_test.go index 6b88f25..e45a0e6 100644 --- a/js/parse_test.go +++ b/js/parse_test.go @@ -266,6 +266,7 @@ func TestParse(t *testing.T) { {"x = new new.target", "Stmt(x=(new (new.target)))"}, {"x = new import.meta", "Stmt(x=(new (import.meta)))"}, {"x = import(a)", "Stmt(x=(import(a)))"}, + {"import('module')", "Stmt(import('module'))"}, {"x = +a", "Stmt(x=(+a))"}, {"x = ++a", "Stmt(x=(++a))"}, {"x = -a", "Stmt(x=(-a))"},