Skip to content

Commit

Permalink
fix: lines break (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaw52 committed Aug 1, 2023
1 parent 7b18e7f commit 16ca64e
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { transformScriptSetup } from './transformScriptSetup'
import { transformSfcRefSugar } from './transformSfcRefSugar'
import { resolveOptions } from './options'

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

export function shouldTransform(code: string, id: string, options?: ScriptSetupTransformOptions): boolean {
// avoid transforming twice
Expand Down
75 changes: 75 additions & 0 deletions test/transform_filter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { } from 'node:test'
import { describe, expect, it } from 'vitest'
import { scriptSetupRE } from '../src/core'

describe('transform filter', () => {
describe('look for what needs to be converted by regular ', () => {
const cases: string[] = [
`<script lang="tsx"
setup>
import HelloWorld from './HelloWorld.vue'
</setup>`,
'<script lang="ts" setup>',
`<script
lang="ts"
setup>
import HelloWorld from './HelloWorld.vue'
</script>`,
`<script
setup>
import HelloWorld from './HelloWorld.vue'
</script>`,
`<script setup>
import HelloWorld from './HelloWorld.vue'
</script>`,
`<script setup lang="tsx" >
import HelloWorld from './HelloWorld.vue'
</script>
`,
`<script setup
lang="ts">
import HelloWorld from './HelloWorld.vue'
</script>
`,
`<script
setup
lang="ts">
import HelloWorld from './HelloWorld.vue'
</script>
`,
`<script setup
lang="ts">
import HelloWorld from './HelloWorld.vue'
</script>`,
]

for (const input of cases) {
it(input, () => {
expect(scriptSetupRE.test(input)).toEqual(true)
})
}
})

describe('filter what is not needed by regular ', () => {
const cases: string[] = [
`<scriptlang="ts"
setup>
import HelloWorld from './HelloWorld.vue'
</script>
`,
`<script lang="ts">
import HelloWorld from './HelloWorld.vue'
</script>`,
`<script>
import HelloWorld from './HelloWorld.vue'
</script>
`,
]

for (const input of cases) {
it(input, () => {
expect(scriptSetupRE.test(input)).toEqual(false)
})
}
})
})

0 comments on commit 16ca64e

Please sign in to comment.