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

feat(imports): support import attributes - fixes #14674 #17485

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

redfox-mx
Copy link

@redfox-mx redfox-mx commented Jun 15, 2024

Description

Fixes #14674, #12140

Adds support for import attributes by parsing them in the import analysis plugin.

Additional context

How this works:

  • es-module-lexer provides information about where the attributes are. We already use this to clip them off.
  • We grab the string (import attributes into source code) and convert to object literal { foo: 'bar' }
  • Pass this through to resolveId where plugins can do what they want.

Build phase

  • At build time we remove strip import attributes step since rollup remove it for us, it allows to pass attributes to resolveId hook

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, especially the Pull Request Guidelines.
  • 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 ).
  • Update the corresponding documentation if needed.
  • Ideally, include relevant tests that fail without this PR but pass with it.

PS: this pr solve some errors of #15654

Copy link

stackblitz bot commented Jun 15, 2024

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

@redfox-mx
Copy link
Author

Hi! lint job fails since import attribute syntax is not supported by eslint

@sheremet-va sheremet-va added the p2-to-be-discussed Enhancement under consideration (priority) label Jun 19, 2024
@fregante
Copy link

Hi! lint job fails since import attribute syntax is not supported by eslint

That's weird, the ESLint config is already using the TypeScript parser, which does support import attributes.

https://github.com/redfox-mx/vite/blob/1f2d0f60cf008fb0dbba7bbf34c1b1d96cbfd7db/eslint.config.js#L36

See: https://x.com/bradzacher/status/1772901399518408775

I just used it myself, without any config: https://github.com/refined-github/shorten-repo-url/pull/48/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-to-be-discussed Enhancement under consideration (priority)
Projects
Status: P2 - 3
Development

Successfully merging this pull request may close these issues.

Vite plugins drop import attributes/assertions property only from src not node_modules
3 participants