Skip to content

fix: use non-greedy matching to extract the script setup tag - #78

Open
fengyuanchen wants to merge 1 commit into
unplugin:mainfrom
fengyuanchen:main
Open

fengyuanchen wants to merge 1 commit into
unplugin:mainfrom
fengyuanchen:main

Conversation

@fengyuanchen

Copy link
Copy Markdown

Description

Correctly extracting multiple script setup tags, e.g.:

Source:

# Hello World

This is an example for multiple script setup tags.

<script setup>
import Foo from './Foo.vue'
</script>

<Foo />

<script setup>
import Bar from './Bar.vue'
</script>

<Bar />

Before fix:

Extract an incorrect script.

// console.log(extractScriptSetup(html).scripts);
[
  {
    code: `
import Foo from './Foo.vue'
</script>

<Foo />

<script setup>
import Bar from './Bar.vue'
`,
    attr: '',
  }
]

⚠️ Causes an error:

Element is missing end tag.

After fixed:

Precisely extract the content of two scripts.

// console.log(extractScriptSetup(html).scripts);
[
  {
    code: `import Foo from './Foo.vue'`,
    attr: '',
  },
  {
    code: `import Bar from './Bar.vue'`,
    attr: '',
  }
]

Linked Issues

Additional context

@bolt-new-by-stackblitz

Copy link
Copy Markdown

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

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.

1 participant