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: fix escape character for import.meta.env #11055

Closed
wants to merge 1 commit into from

Conversation

Ricinix
Copy link

@Ricinix Ricinix commented Nov 24, 2022

Description

I find a bug when using import.meta.env:
*.vue?raw will be transformed into export default "xxxx", if I use import.meta.env.xxx in a vue component, it will be replaced with "xxx" directly.
For example, The source code is export default "... import.meta.env.xxx === 'dev' ... ", but the final code will be export default "... "xxx" === 'dev' ... ". The "xxx" should be \"xxx\", or the rollup AST parser will go wrong.
I don't know if this is the best solution for this bug, just a suggestion. Maybe the import.meta.env replacement run before *.vue?raw transform will be better?

Forgive me for bad English hhhh.

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 Commit 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.

Comment on lines +49 to +50
const envVal = env[key]
importMetaKeys[`import.meta.env.${key}`] = typeof envVal === 'string' ? `\`${envVal}\`` : JSON.stringify(envVal)
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 the right fix. If the import.meta.env.xxx is in a string, it should be skip entirely, which is being fixed in #9791

@bluwy
Copy link
Member

bluwy commented Dec 2, 2022

Closing as this isn't the right fix.

@bluwy bluwy closed this Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants