Skip to content

Commit 16ca64e

Browse files
authored
fix: lines break (unplugin#156)
1 parent 7b18e7f commit 16ca64e

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

src/core/transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { transformScriptSetup } from './transformScriptSetup'
66
import { transformSfcRefSugar } from './transformSfcRefSugar'
77
import { resolveOptions } from './options'
88

9-
const scriptSetupRE = /<script\s(.*\s)?setup(\s.*)?>/
9+
export const scriptSetupRE = /<script\s+(.*\s+)?setup(\s+.*)?\s*>/
1010

1111
export function shouldTransform(code: string, id: string, options?: ScriptSetupTransformOptions): boolean {
1212
// avoid transforming twice

test/transform_filter.test.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { } from 'node:test'
2+
import { describe, expect, it } from 'vitest'
3+
import { scriptSetupRE } from '../src/core'
4+
5+
describe('transform filter', () => {
6+
describe('look for what needs to be converted by regular ', () => {
7+
const cases: string[] = [
8+
`<script lang="tsx"
9+
setup>
10+
import HelloWorld from './HelloWorld.vue'
11+
</setup>`,
12+
'<script lang="ts" setup>',
13+
`<script
14+
lang="ts"
15+
setup>
16+
import HelloWorld from './HelloWorld.vue'
17+
</script>`,
18+
`<script
19+
setup>
20+
import HelloWorld from './HelloWorld.vue'
21+
</script>`,
22+
`<script setup>
23+
import HelloWorld from './HelloWorld.vue'
24+
</script>`,
25+
`<script setup lang="tsx" >
26+
import HelloWorld from './HelloWorld.vue'
27+
</script>
28+
`,
29+
`<script setup
30+
lang="ts">
31+
import HelloWorld from './HelloWorld.vue'
32+
</script>
33+
`,
34+
`<script
35+
setup
36+
lang="ts">
37+
import HelloWorld from './HelloWorld.vue'
38+
</script>
39+
`,
40+
`<script setup
41+
lang="ts">
42+
import HelloWorld from './HelloWorld.vue'
43+
</script>`,
44+
]
45+
46+
for (const input of cases) {
47+
it(input, () => {
48+
expect(scriptSetupRE.test(input)).toEqual(true)
49+
})
50+
}
51+
})
52+
53+
describe('filter what is not needed by regular ', () => {
54+
const cases: string[] = [
55+
`<scriptlang="ts"
56+
setup>
57+
import HelloWorld from './HelloWorld.vue'
58+
</script>
59+
`,
60+
`<script lang="ts">
61+
import HelloWorld from './HelloWorld.vue'
62+
</script>`,
63+
`<script>
64+
import HelloWorld from './HelloWorld.vue'
65+
</script>
66+
`,
67+
]
68+
69+
for (const input of cases) {
70+
it(input, () => {
71+
expect(scriptSetupRE.test(input)).toEqual(false)
72+
})
73+
}
74+
})
75+
})

0 commit comments

Comments
 (0)