Skip to content

Revisit Dynamic Imports #197

Description

@mysticatea

Hello.

Currently, AST for dynamic imports is using CallExpression: https://github.com/estree/estree/blob/2c161ae714c1b23198be3be08c930e55a621c187/experimental/import-expression.md
But I think an independent node type is better:

interface ImportExpression <: Expression {
    type: "ImportExpression";
    source: Expression;
}

For some reasons:

  • source property is consistent with ImportDeclaration to express importing source.
    On the other hand, it's hard to read that arguments[0] express the importing source.
  • Searching CallExpressions which have Import node in that callee is not convenient to analyze dependencies.
  • The arguments property doesn't fit Dynamic Imports syntax.
    • The syntax cannot have multiple arguments. (i.e. import() and import(a, b) are syntax error)
    • The syntax cannot have trailing commas. (i.e. import(source,) is syntax error)
  • [EDIT] Import node is not consistent with import.meta meta property. Existing MetaProperty node represents import.meta without Import node. The Import node will confuse us in the future.

Thoughts?

Thank you.


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions