import { compileSFCScript as compile, assertCode, mockId } from './utils'
describe('SFC compile <script setup>', () => {
+ test('should compile JS syntax', () => {
+ const { content } = compile(`
+ <script setup lang='js'>
+ const a = 1
+ const b = 2
+ </script>
+ `)
+ expect(content).toMatch(`return { a, b }`)
+ assertCode(content)
+ })
+
test('should expose top level declarations', () => {
const { content, bindings } = compile(`
<script setup>
const cssVars = sfc.cssVars
const scriptLang = script && script.lang
const scriptSetupLang = scriptSetup && scriptSetup.lang
+ const isJS =
+ scriptLang === 'js' ||
+ scriptLang === 'jsx' ||
+ scriptSetupLang === 'js' ||
+ scriptSetupLang === 'jsx'
const isTS =
scriptLang === 'ts' ||
scriptLang === 'tsx' ||
if (!script) {
throw new Error(`[@vue/compiler-sfc] SFC contains no <script> tags.`)
}
- if (scriptLang && !isTS && scriptLang !== 'jsx') {
+ if (scriptLang && !isJS && !isTS) {
// do not process non js/ts script blocks
return script
}
)
}
- if (scriptSetupLang && !isTS && scriptSetupLang !== 'jsx') {
+ if (scriptSetupLang && !isJS && !isTS) {
// do not process non js/ts script blocks
return scriptSetup
}