Skip to content

Commit 4821f84

Browse files
committed
fix(compiler-sfc): updated unit test
1 parent 717a992 commit 4821f84

File tree

3 files changed

+145
-3
lines changed

3 files changed

+145
-3
lines changed

packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,49 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`SFC analyze <script> bindings > auto name inference > basic 1`] = `
4+
"const a = 1
5+
export default {
6+
__name: 'FooBar',
7+
setup(__props, { expose: __expose }) {
8+
__expose();
9+
10+
return { a }
11+
}
12+
13+
}"
14+
`;
15+
16+
exports[`SFC analyze <script> bindings > auto name inference > do not overwrite manual name (call) 1`] = `
17+
"import { defineComponent } from 'vue'
18+
const __default__ = defineComponent({
19+
name: 'Baz'
20+
})
21+
22+
export default /*#__PURE__*/Object.assign(__default__, {
23+
setup(__props, { expose: __expose }) {
24+
__expose();
25+
const a = 1
26+
return { a, defineComponent }
27+
}
28+
29+
})"
30+
`;
31+
32+
exports[`SFC analyze <script> bindings > auto name inference > do not overwrite manual name (object) 1`] = `
33+
"const __default__ = {
34+
name: 'Baz'
35+
}
36+
37+
export default /*#__PURE__*/Object.assign(__default__, {
38+
setup(__props, { expose: __expose }) {
39+
__expose();
40+
const a = 1
41+
return { a }
42+
}
43+
44+
})"
45+
`;
46+
347
exports[`SFC compile <script setup> > <script> and <script setup> co-usage > export call expression as default 1`] = `
448
"function fn() {
549
return \\"hello, world\\";
@@ -1281,3 +1325,102 @@ return { D, C, B, Foo }
12811325
12821326
})"
12831327
`;
1328+
1329+
exports[`SFC genDefaultAs > <script setup> only 1`] = `
1330+
"const a = 1
1331+
1332+
const _sfc_ = {
1333+
setup(__props, { expose: __expose }) {
1334+
__expose();
1335+
1336+
1337+
return { a }
1338+
}
1339+
1340+
}"
1341+
`;
1342+
1343+
exports[`SFC genDefaultAs > <script setup> only w/ ts 1`] = `
1344+
"import { defineComponent as _defineComponent } from 'vue'
1345+
const a = 1
1346+
1347+
const _sfc_ = /*#__PURE__*/_defineComponent({
1348+
setup(__props, { expose: __expose }) {
1349+
__expose();
1350+
1351+
1352+
return { a }
1353+
}
1354+
1355+
})"
1356+
`;
1357+
1358+
exports[`SFC genDefaultAs > <script> + <script setup> 1`] = `
1359+
"const __default__ = {}
1360+
1361+
const _sfc_ = /*#__PURE__*/Object.assign(__default__, {
1362+
setup(__props, { expose: __expose }) {
1363+
__expose();
1364+
1365+
const a = 1
1366+
1367+
return { a }
1368+
}
1369+
1370+
})"
1371+
`;
1372+
1373+
exports[`SFC genDefaultAs > <script> + <script setup> 2`] = `
1374+
"const __default__ = {}
1375+
1376+
const _sfc_ = /*#__PURE__*/Object.assign(__default__, {
1377+
setup(__props, { expose: __expose }) {
1378+
__expose();
1379+
1380+
const a = 1
1381+
1382+
return { a }
1383+
}
1384+
1385+
})"
1386+
`;
1387+
1388+
exports[`SFC genDefaultAs > <script> + <script setup> w/ ts 1`] = `
1389+
"import { defineComponent as _defineComponent } from 'vue'
1390+
1391+
const __default__ = {}
1392+
1393+
const _sfc_ = /*#__PURE__*/_defineComponent({
1394+
...__default__,
1395+
setup(__props, { expose: __expose }) {
1396+
__expose();
1397+
1398+
const a = 1
1399+
1400+
return { a }
1401+
}
1402+
1403+
})"
1404+
`;
1405+
1406+
exports[`SFC genDefaultAs > normal <script> only 1`] = `
1407+
"
1408+
const _sfc_ = {}
1409+
"
1410+
`;
1411+
1412+
exports[`SFC genDefaultAs > normal <script> w/ cssVars 1`] = `
1413+
"
1414+
const _sfc_ = {}
1415+
1416+
import { useCssVars as _useCssVars } from 'vue'
1417+
const __injectCSSVars__ = () => {
1418+
_useCssVars(_ctx => ({
1419+
\\"xxxxxxxx-x\\": (_ctx.x)
1420+
}))}
1421+
const __setup__ = _sfc_.setup
1422+
_sfc_.setup = __setup__
1423+
? (props, ctx) => { __injectCSSVars__();return __setup__(props, ctx) }
1424+
: __injectCSSVars__
1425+
"
1426+
`;

packages/compiler-sfc/__tests__/compileScript.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ describe('SFC compile <script setup>', () => {
529529
// check snapshot and make sure helper imports and
530530
// hoists are placed correctly.
531531
assertCode(content)
532-
532+
expect(content).toMatch(`expose()`)
533533
})
534534

535535
test('with defineExpose()', () => {

packages/compiler-sfc/src/compileScript.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,7 @@ export function compileScript(
975975

976976
// <script setup> components are closed by default. If the user did not
977977
// explicitly call `defineExpose`, call expose() with no args.
978-
const exposeCall =
979-
ctx.hasDefineExposeCall ? `` : ` __expose();\n`
978+
const exposeCall = ctx.hasDefineExposeCall ? `` : ` __expose();\n`
980979
// wrap setup code with function.
981980
if (ctx.isTS) {
982981
// for TS, make sure the exported type is still valid type with

0 commit comments

Comments
 (0)