GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — RFC 0004: Add `ImportExpression` AST type by JLHwung · Pull Request #4 · babel/rfcs

Conversation

@JLHwung

@JLHwung JLHwung commented May 1, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

View Rendered Text

This RFC proposes to parse import() as a new AST node type ImportExpression instead of CallExpression.

Pinging a few people who may be interested in this:

@axetroy - vscode-npm-import-package-version
@devongovett - parcel
@flytam - babel-plugin-resolve-config-json
@kevinbarabash - eslint-plugin-khan
@ljharb - babel-plugin-dynamic-import-node, eslint-plugin-import
@suchipi - transform-imports
@swannodette - closurescript

Please share this RFC to anyone who can contribute to the discussion.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

suchipi, chicoxyzzy, axetroy, xiaohesong, coderaiser, kliukovkin, AjayPoshak, and mischnic reacted with thumbs up emoji
All reactions
  • 👍 8 reactions
@JLHwung
create import-expression-ast-node type
8a0fbed
@ljharb

ljharb commented May 1, 2020

Copy link
Copy Markdown
Member

Note this will also likely impact eslint-plugin-import, which I also maintain.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

existentialism
existentialism reviewed May 1, 2020
View reviewed changes
Comment thread rfcs/0000-import-expression-ast-node.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

@nicolo-ribaudo nicolo-ribaudo added repo: babel/babel status: proposed labels May 1, 2020
@JLHwung @existentialism
Update rfcs/0000-import-expression-ast-node.md
d3e31ef
Co-authored-by: Brian Ng <[email protected]>
@JLHwung

JLHwung commented May 1, 2020

Copy link
Copy Markdown
Collaborator Author

@ljharb I think any ESLint plugins that relies on CallExpression[callee=Import] will have to adapt to the new ImportExpression regardless of whether this RFC is accepted, because it has been included in ESTree and eslint should follow this path, too. In this way the RFC also aligns babel parser behaviour to ESTree.

nicolo-ribaudo, existentialism, ljharb, xiaohesong, and coderaiser reacted with thumbs up emoji ljharb and AjayPoshak reacted with hooray emoji
All reactions
  • 👍 5 reactions
  • 🎉 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JLHwung
update RFC PR link
c8c22d2
existentialism
existentialism reviewed May 1, 2020
View reviewed changes
Comment thread rfcs/0000-import-expression-ast-node.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JLHwung @existentialism
Update rfcs/0000-import-expression-ast-node.md
fc73053
Co-authored-by: Brian Ng <[email protected]>
nicolo-ribaudo
nicolo-ribaudo reviewed May 1, 2020
View reviewed changes
Comment thread rfcs/0000-import-expression-ast-node.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

existentialism
existentialism reviewed May 1, 2020
View reviewed changes
Comment thread rfcs/0000-import-expression-ast-node.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

existentialism
existentialism reviewed May 1, 2020
View reviewed changes
Comment thread rfcs/0000-import-expression-ast-node.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

existentialism
existentialism reviewed May 1, 2020
View reviewed changes
Comment thread rfcs/0000-import-expression-ast-node.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

nicolo-ribaudo
nicolo-ribaudo reviewed May 1, 2020
View reviewed changes

@nicolo-ribaudo nicolo-ribaudo left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this proposal. Note that I don't think that aligning with ESTree should be a goal for us, but this AST shape is definitely better than our current one since it "automatically" disallows invalid states.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ljharb and AjayPoshak reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
existentialism
existentialism reviewed May 1, 2020
View reviewed changes
Comment thread rfcs/0000-import-expression-ast-node.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

existentialism
existentialism reviewed May 1, 2020
View reviewed changes
Comment thread rfcs/0000-import-expression-ast-node.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

existentialism
existentialism reviewed May 1, 2020
View reviewed changes
Comment thread rfcs/0000-import-expression-ast-node.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

existentialism
existentialism reviewed May 1, 2020
View reviewed changes
Comment thread rfcs/0000-import-expression-ast-node.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

JLHwung and others added 4 commits May 1, 2020 16:59
@JLHwung @existentialism
Apply suggestions from code review
a48758d
Co-authored-by: Brian Ng <[email protected]>
@JLHwung
fix: update compat example
3fef8fd
@JLHwung
nits
fd8cb51
@JLHwung
fix: code example arguments error
b155ed9
@JLHwung JLHwung mentioned this pull request May 5, 2020
May 7th Meeting babel/notes#114
Closed
8 tasks
@existentialism existentialism mentioned this pull request May 6, 2020
Bump flow-parser from 0.122.0 to 0.124.0 prettier/prettier#8230
Merged
existentialism
existentialism approved these changes May 7, 2020
View reviewed changes
@JLHwung
update background about dynamic import implementation
206d2bc
nicolo-ribaudo
nicolo-ribaudo approved these changes May 8, 2020
View reviewed changes

@nicolo-ribaudo nicolo-ribaudo left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb Currently, the @babel/plugin-proposal-dynamic-import when targeting CommonJS is just a proxy to babel-plugin-dynamic-import.

Since this AST change makes it harder to have a plugin working with Babel 6-7 and with Babel 8, I was thinking that it would be easier to only support Babel 6-7 in babel-plugin-dynamic-import and write the new logic for Babel 8 in our monorepo.

Does that sound good to you?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ljharb

ljharb commented May 8, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@nicolo-ribaudo that doesn't make sense to me; how does it make it harder? It seems like I just have to add an extra visitor.

If babel wants to inline the dependency, that's one thing, but otherwise it seems pretty trivial to support 6, 7, and 8?

More to the point, if it's not easy to support both babel 7 and 8 in the same transform, then imo the change is poorly designed and shouldn't happen at all.

JLHwung reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jridgewell
jridgewell reviewed May 8, 2020
View reviewed changes
Comment thread rfcs/0000-import-expression-ast-node.md
}
```

When `@babel/parser` [supported](https://github.com/babel/babylon/pull/163) dynamic import, it was called `import-function` and shared similar syntax structure with `super` call that is parsed as `CallExpression[callee=Super]`. However, it encourages an incorrect mental model, as developers may think of `import()` as a function call. Besides, it was later syntactically limited to one argument, different from other call expressions. Last, it is also problematic when we extend the current AST shape to support stage-1 [module attributes](https://github.com/tc39/proposal-module-attributes) (`import(moduleName, attributes)`) since the arguments (`moduleName` and `attributes` respectively) share the same semantics in the AST.

@jridgewell jridgewell May 8, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bit of discussion in tc39/proposal-import-attributes#52. Honestly, I'd rather we treat it as a regular function call, exactly the same as super().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ljharb ljharb May 8, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I very much doubt that import() will ever get consensus to be treated as a normal function call; there was a lot of discussion about that during its advancement. It’s syntax, and will likely always be special in a number of ways.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JLHwung JLHwung May 9, 2020

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the ImportExpression is also created to be consistent with ImportDeclaration.

interface ImportDeclaration <: ModuleDeclaration {
  type: "ImportDeclaration";
  source: Literal;
}

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

Although on the CST level an import expression shares similar syntax features with a function call, but on the AST level I think we should abstract them to common import interface.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ljharb and coderaiser reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@fisker fisker mentioned this pull request May 15, 2020
Refactor import() print prettier/prettier#8319
Closed
@kliukovkin

kliukovkin commented Aug 3, 2020

Copy link
Copy Markdown

@JLHwung is there anything left before merging this PR?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JLHwung

JLHwung commented Aug 3, 2020

Copy link
Copy Markdown
Collaborator Author

@ACSAIS

An RFC is considered as accepted if it receives at least 4 approving reviews, and no rejection from core team members. If the RFC is proposed by a core team member, this number is lowered to 3.

https://github.com/babel/rfcs#reviewing-rfcs

kliukovkin reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kliukovkin

kliukovkin commented Aug 3, 2020

Copy link
Copy Markdown

Didn't know it, thanks for your answer @JLHwung !

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

suchipi
suchipi approved these changes Aug 4, 2020
View reviewed changes
@fisker

fisker commented Aug 28, 2022

Copy link
Copy Markdown

Progress?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nicolo-ribaudo nicolo-ribaudo mentioned this pull request Oct 7, 2022
Inline dynamic import transform babel/babel#15026
Merged
@nicolo-ribaudo

nicolo-ribaudo commented Jun 1, 2023

Copy link
Copy Markdown
Member

This AST change would also make it easier to support https://github.com/tc39/proposal-import-reflection/. I wonder if we can start implementing it in Babel 7 as opt-in with a parser option.

JLHwung reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JLHwung JLHwung mentioned this pull request Jun 2, 2023
Add createImportExpressions parser option babel/babel#15682
Merged
1 task done
@fisker

fisker commented Jun 4, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Though estree uses ImportExpression, and I hope babel aligh with them.

I wounder what the ast will look like for import.source("<specifier>").

{
  "type": "ImportExpression", 
  "phase": "source"
}

?

CallExpression seems easier to extend

{
  "type": "CallExpression", 
  "callee": {
    "type": "MetaProperty"
  }
}
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JLHwung

JLHwung commented Jun 4, 2023

Copy link
Copy Markdown
Collaborator Author

@fisker Good question. Currently the MetaProperty represents member-expression-like productions: function.sent and import.meta and they are expressions. However import.source() is different as import.source does not exist. If it were a MetaProperty, it will be inconsistent with other meta properties. If we extend Babel's current CallExpression approach for import.source(), we could use

{
  "type": "CallExpression", 
  "callee": {
    "type": "ImportSource"
  }
}

but popular matchers like CallExpression[callee.type = Import] now have to cover a new AST type. In this case, since either way we will need new AST type for import.source(), I think the ImportExpression approach is more compelling than before.

fisker reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fisker

fisker commented Jun 4, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

That's reasonable. 👍

Introduce ImportSource for import.source() seems not a good idea to me, we'll need a new one for import.asset()...

What do you think {ImportExpression,Import}[phase="source" | "asset"]?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JLHwung

JLHwung commented Jun 7, 2023

Copy link
Copy Markdown
Collaborator Author

What do you think {ImportExpression,Import}[phase="source" | "asset"]?

@fisker The Babel AST of import phase will follow the ESTree proposal here. It will be built on top of the ImportExpression AST. Eventually we will phase out the current CallExpression(Import) model.

fisker and coderaiser reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nicolo-ribaudo

nicolo-ribaudo commented Oct 13, 2023

Copy link
Copy Markdown
Member

@JLHwung Can we enable the new mode by default for Babel 8, and then merge this RFC?

JLHwung reacted with thumbs up emoji coderaiser reacted with rocket emoji
All reactions
  • 👍 1 reaction
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JLHwung JLHwung mentioned this pull request Nov 21, 2023
Breaking: parserOpts.createImportExpressions defaults to true babel/babel#16114
Merged
@nicolo-ribaudo

nicolo-ribaudo commented May 2, 2024

Copy link
Copy Markdown
Member

This is enabled by default in Babel 8 🎉

ljharb, suchipi, and coderaiser reacted with hooray emoji
All reactions
  • 🎉 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nicolo-ribaudo
Rename
2d711f3
nicolo-ribaudo
nicolo-ribaudo reviewed May 2, 2024
View reviewed changes
Comment thread rfcs/0004-import-expression-ast-node.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread rfcs/0004-import-expression-ast-node.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

@nicolo-ribaudo
Update flag name
54c18a0
@nicolo-ribaudo nicolo-ribaudo changed the title Add ImportExpression AST type RFC 0004: Add ImportExpression AST type May 2, 2024
@nicolo-ribaudo
nicolo-ribaudo merged commit f4ea1ed into babel:main May 2, 2024
@suchipi

suchipi commented May 3, 2024

Copy link
Copy Markdown
Member

Woo! :D

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@nicolo-ribaudo nicolo-ribaudo nicolo-ribaudo approved these changes
+4 more reviewers
@ljharb ljharb ljharb left review comments
@jridgewell jridgewell jridgewell left review comments
@existentialism existentialism existentialism approved these changes
@suchipi suchipi suchipi approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

repo: babel/babel status: proposed

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@JLHwung @ljharb @kliukovkin @fisker @nicolo-ribaudo @suchipi @existentialism @jridgewell
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.