Skip to content
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

fix(analysis): warnings for dynamic imports that use static template literals #14458

Merged
merged 6 commits into from
Sep 28, 2023

Conversation

Dunqing
Copy link
Contributor

@Dunqing Dunqing commented Sep 24, 2023

Description

When I finished this PR, I noticed that there was another one #14103 being processed. But I think we shouldn't hide warnings.

Fixes: #14101
Closes: #14103

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@stackblitz
Copy link

stackblitz bot commented Sep 24, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

bluwy
bluwy previously approved these changes Sep 25, 2023
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

I like this change!

Comment on lines 472 to 475
} else if (templateLiteralRE.test(rawUrl)) {
// Only static template literal will into this branch.
// It has variables will processed in importMetaGlob.ts
specifier = rawUrl.replace(templateLiteralRE, '$1')
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is correct.
Dynamic import with /* @vite-ignore */ or dynamic imports that cannot be handled with the dynamic-import plugin (e.g. import(`${startsWithVariable}/foo`)) will be still there.
https://stackblitz.com/edit/vitejs-vite-fnln8a?file=main.js&terminal=dev
image

So templateLiteralRE.test(rawUrl) will match `foo${va}`
https://stackblitz.com/edit/node-ptwy2i?file=index.js

This comment was marked as outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I realize that. A dynamic import that doesn't conform to the rules will still get in here. So do I just need to exclude paths containing variables here?

Copy link
Member

Choose a reason for hiding this comment

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

So do I just need to exclude paths containing variables here?

I think so 👍

sapphi-red
sapphi-red previously approved these changes Sep 26, 2023
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

import(`foo\${bar}.js`) will still cause a warning but I guess that's fine.

@bluwy bluwy enabled auto-merge (squash) September 28, 2023 07:19
@bluwy bluwy added the p3-minor-bug An edge case that only affects very specific usage (priority) label Sep 28, 2023
@bluwy bluwy merged commit ec7ee22 into vitejs:main Sep 28, 2023
9 checks passed
bluwy pushed a commit that referenced this pull request Oct 3, 2023
@bluwy bluwy mentioned this pull request Oct 3, 2023
bluwy pushed a commit that referenced this pull request Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Import Analysis - warns on imports that use a template literal but have no variables
3 participants