Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ES2018 import() #202

Merged
merged 1 commit into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Esprima/Ast/Import.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ namespace Esprima.Ast
{
public sealed class Import : Expression
{
public readonly Expression Source;

public Import() : base(Nodes.Import)
{
}

public Import(Expression source) : base(Nodes.Import)
{
Source = source;
}

public override NodeCollection ChildNodes => NodeCollection.Empty;

protected internal override void Accept(AstVisitor visitor)
Expand Down
20 changes: 18 additions & 2 deletions src/Esprima/JavascriptParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1510,8 +1510,24 @@ private bool MatchImportCall()
private Import ParseImportCall()
{
var node = CreateNode();
ExpectKeyword("import");
return Finalize(node, new Import());
ExpectKeyword("import");
Expect("(");

var source = this.parseAssignmentExpression();
if (!this.Match(")") && this._config.Tolerant)
{
this.TolerateUnexpectedToken(this.NextToken());
}
else
{
this.Expect(")");
if (this.Match(";"))
{
this.NextToken();
}
}

return Finalize(node, new Import(source));
}

private bool MatchImportMeta()
Expand Down
3 changes: 2 additions & 1 deletion src/Esprima/Utils/AstVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ protected internal virtual void VisitExportSpecifier(ExportSpecifier exportSpeci
}

protected internal virtual void VisitImport(Import import)
{
{
Visit(import.Source);
}

protected internal virtual void VisitImportDeclaration(ImportDeclaration importDeclaration)
Expand Down
Loading