GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||
GeezerVison is showing github.com — RFC 0004: Add `ImportExpression` AST type by JLHwung · Pull Request #4 · babel/rfcs Conversation
|
|
Note this will also likely impact |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Brian Ng <[email protected]>
|
@ljharb I think any ESLint plugins that relies on |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Brian Ng <[email protected]>
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| ``` | ||
|
|
||
| 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. |
There was a problem 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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
|
@JLHwung is there anything left before merging this PR? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@ACSAIS
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Didn't know it, thanks for your answer @JLHwung ! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Progress? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Though estree uses I wounder what the ast will look like for {
"type": "ImportExpression",
"phase": "source"
}?
{
"type": "CallExpression",
"callee": {
"type": "MetaProperty"
}
} |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@fisker Good question. Currently the { "type": "CallExpression", "callee": { "type": "ImportSource" } } but popular matchers like |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
That's reasonable. 👍 Introduce What do you think |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@fisker The Babel AST of import phase will follow the ESTree proposal here. It will be built on top of the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@JLHwung Can we enable the new mode by default for Babel 8, and then merge this RFC? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This is enabled by default in Babel 8 🎉 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
ImportExpression AST type
|
Woo! :D |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.