File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -1277,6 +1277,21 @@ return () => {}
1277
1277
}"
1278
1278
`;
1279
1279
1280
+ exports[`SFC compile <script setup> > should compile JS syntax 1`] = `
1281
+ "const a = 1
1282
+ const b = 2
1283
+
1284
+ export default {
1285
+ setup(__props, { expose }) {
1286
+ expose();
1287
+
1288
+
1289
+ return { a, b }
1290
+ }
1291
+
1292
+ }"
1293
+ `;
1294
+
1280
1295
exports[`SFC compile <script setup> > should expose top level declarations 1`] = `
1281
1296
"import { x } from './x'
1282
1297
Original file line number Diff line number Diff line change @@ -2,6 +2,17 @@ import { BindingTypes } from '@vue/compiler-core'
2
2
import { compileSFCScript as compile , assertCode , mockId } from './utils'
3
3
4
4
describe ( 'SFC compile <script setup>' , ( ) => {
5
+ test ( 'should compile JS syntax' , ( ) => {
6
+ const { content } = compile ( `
7
+ <script setup lang='js'>
8
+ const a = 1
9
+ const b = 2
10
+ </script>
11
+ ` )
12
+ expect ( content ) . toMatch ( `return { a, b }` )
13
+ assertCode ( content )
14
+ } )
15
+
5
16
test ( 'should expose top level declarations' , ( ) => {
6
17
const { content, bindings } = compile ( `
7
18
<script setup>
Original file line number Diff line number Diff line change @@ -167,6 +167,11 @@ export function compileScript(
167
167
const cssVars = sfc . cssVars
168
168
const scriptLang = script && script . lang
169
169
const scriptSetupLang = scriptSetup && scriptSetup . lang
170
+ const isJS =
171
+ scriptLang === 'js' ||
172
+ scriptLang === 'jsx' ||
173
+ scriptSetupLang === 'js' ||
174
+ scriptSetupLang === 'jsx'
170
175
const isTS =
171
176
scriptLang === 'ts' ||
172
177
scriptLang === 'tsx' ||
@@ -196,7 +201,7 @@ export function compileScript(
196
201
if ( ! script ) {
197
202
throw new Error ( `[@vue/compiler-sfc] SFC contains no <script> tags.` )
198
203
}
199
- if ( scriptLang && ! isTS && scriptLang !== 'jsx' ) {
204
+ if ( scriptLang && ! isJS && ! isTS ) {
200
205
// do not process non js/ts script blocks
201
206
return script
202
207
}
@@ -264,7 +269,7 @@ export function compileScript(
264
269
)
265
270
}
266
271
267
- if ( scriptSetupLang && ! isTS && scriptSetupLang !== 'jsx' ) {
272
+ if ( scriptSetupLang && ! isJS && ! isTS ) {
268
273
// do not process non js/ts script blocks
269
274
return scriptSetup
270
275
}
You can’t perform that action at this time.
0 commit comments