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(scan): improve script regular matching (fixes #2942) #2961

Merged
merged 4 commits into from Apr 27, 2021
Merged

fix(scan): improve script regular matching (fixes #2942) #2961

merged 4 commits into from Apr 27, 2021

Conversation

anncwb
Copy link
Contributor

@anncwb anncwb commented Apr 12, 2021

fixes #2942

Description

Will match to the <script-xxx/> component or comment in

e.g

<template>
    <script-develop-pane/>
</template>

const scriptRE = /(<script\b[^>]*>)(.*?)<\/script>/gims

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.

@Shinigami92 Shinigami92 added the p3-minor-bug An edge case that only affects very specific usage (priority) label Apr 12, 2021
@anncwb
Copy link
Contributor Author

anncwb commented Apr 12, 2021

Modified the regularity and added some examples

@Shinigami92 Shinigami92 self-requested a review April 13, 2021 06:05
@ygj6
Copy link
Member

ygj6 commented Apr 14, 2021

Nice work!
But there is a special scenario, when the template contains comments, the comment content is still compiled.

<template>
    <!--  <script >var test = null</script> -->
</template>

@anncwb
Copy link
Contributor Author

anncwb commented Apr 14, 2021

For comments, additional processing is required. Let me first look for a good way

@anncwb
Copy link
Contributor Author

anncwb commented Apr 15, 2021

After investigation, the scan script only scans .(vue|html|svelte), so the current approach is feasible. Adding // <script></script> in <script> will cause the vue compiler to fail, so there is no need to consider other comment types

@antfu antfu merged commit 1e785d1 into vitejs:main Apr 27, 2021
TobiasMelen pushed a commit to TobiasMelen/vite that referenced this pull request May 3, 2021
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.

Error at first time dev by error: Unexpected "<" when template has <script- component name or <script comment
4 participants