feat(compiler-sfc): analyze import usage in template via AST #9729
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.
Use proper AST analysis to perform import usage check.
close #8897
close nuxt/nuxt#22416
This PR also adds two new parser options (both are already transform options, they just now also apply to the parser):
prefixIdentifiers
expressionPlugins
When enabled,
SimpleExpression
andCompoundExpression
nodes now also has anast
property attached, which is the Babel AST parsed from the original JS expression. During the transform phase,transformExpression
will reuse the ASTs if they are already present on expression nodes.SFCParseOptions
from@vue/compiler-sfc
now also gets a newparseExpressions: boolean
option. Since this is required for the new import usage check to work, it is enabled by default. The only case where you'd want to disable it is when you are using theparse
method from@vue/compiler-sfc
for non-compilation purposes (e.g. just to get the blocks of the SFC) and want to avoid the Babel parse overhead.