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: handle unclosed string literal for multiline vue component props #7

Merged
merged 2 commits into from Mar 29, 2024

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Mar 29, 2024

Description

It looks like js-token cannot perfectly handle extreme Vue input and some people are experiencing issues on Vitest since is-token version is introduced in Vitest 1.3.0.

The example I added here changes the source length in current version and it makes Vitest's import.meta.env => __vite_ssr_import_meta__.env replacement to miss the spot of the original code.

  <SomeOtherComponent
    :some-prop="
      testValue
        ? 'A long value to break handling of env variables'
        : 'it needs to break into a new line'
    "
  >
  <SomeOtherComponent
    :some-prop=""  <--- doubled double quote
      testValue
        ? '                                               '
        : '                                 '
    ""
  >

js-token detects the original double quote as "unclosed string literal" https://github.com/lydell/js-tokens?tab=readme-ov-file#stringliteral like below. In this case, I think we can just keep the output and it looks working now.

  { type: 'StringLiteral', value: '"', closed: false },

I checked with the previous regex version in the first commit 641b7a1 and it's working similar, so probably regex version has been saving vue input magically.

@hi-ogawa hi-ogawa changed the title fix: keep unclosed string literal to handle exotic vue input fix: handle unclosed string literal for multiline vue component props Mar 29, 2024
@antfu antfu merged commit a39ba58 into antfu:main Mar 29, 2024
8 checks passed
@hi-ogawa hi-ogawa deleted the fix-regex-fallback branch March 30, 2024 00:23
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.

Multiline Vue component props breaks import.meta.env
2 participants