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
AST of import declaration without attributes #314
Comments
One point against doing this is that the import specifiers follow the same pattern - the array is always defined, regardless of the presence of the braces. So keeping it like this is standardised with that, at least, for better or worse. Another point against this is that there are already implementations of the current spec. Things can change though and (AFAIK) acorn/eslint don't have support yet. |
Yes, Prettier actually determines whether to print
Since import attributes is still stage 3 syntax, I think we can still be able to change the estree spec. |
@JLHwung What do you think? |
I agree with @bradzacher, like he said the import specifiers follows the always-array pattern even if the empty braces This rule is not limited to empty braces. For example ESTree does not differentiate |
Agree with @bradzacher and @JLHwung here. ESTree is an abstract syntax tree, which necessarily means that not every token is represented, but rather, the meaning of the syntax is represented. I think the meaning is properly conveyed with the empty array. |
The following AST is defined for import attributes:
This means
import foo from "mod";
andimport foo from "mod" with {};
have the same AST.This isn't good for implementing code formatters. For example, Prettier's implementation reads the original text of the input to print attributes( https://github.com/prettier/prettier/blob/f5e339351e792cea0e8a6b111b336d5efa6441ea/src/language-js/print/module.js#L251-L272 ).
So I propose representing
attributes
as an empty array inimport foo from "mod" with {};
and asnull
inimport foo from "mod";
.What do you think?
The text was updated successfully, but these errors were encountered: