Skip to content

Commit cea8b25

Browse files
committed
wip: fix useCssVars helper call + tests
1 parent b79a06c commit cea8b25

File tree

4 files changed

+128
-88
lines changed

4 files changed

+128
-88
lines changed

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

+75-49
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
exports[`SFC compile <script setup> CSS vars injection <script> w/ default export 1`] = `
44
"const __default__ = { setup() {} }
5-
import { useCssVars as __useCssVars__ } from 'vue'
5+
import { useCssVars as _useCssVars } from 'vue'
66
const __injectCSSVars__ = () => {
7-
__useCssVars__(_ctx => ({ color: _ctx.color }))
7+
_useCssVars(_ctx => ({ color: _ctx.color }))
88
}
99
const __setup__ = __default__.setup
1010
__default__.setup = __setup__
@@ -18,9 +18,9 @@ exports[`SFC compile <script setup> CSS vars injection <script> w/ default expor
1818
// export default {}
1919
const __default__ = {}
2020
21-
import { useCssVars as __useCssVars__ } from 'vue'
21+
import { useCssVars as _useCssVars } from 'vue'
2222
const __injectCSSVars__ = () => {
23-
__useCssVars__(_ctx => ({ color: _ctx.color }))
23+
_useCssVars(_ctx => ({ color: _ctx.color }))
2424
}
2525
const __setup__ = __default__.setup
2626
__default__.setup = __setup__
@@ -32,9 +32,9 @@ export default __default__"
3232
exports[`SFC compile <script setup> CSS vars injection <script> w/ no default export 1`] = `
3333
"const a = 1
3434
const __default__ = {}
35-
import { useCssVars as __useCssVars__ } from 'vue'
35+
import { useCssVars as _useCssVars } from 'vue'
3636
const __injectCSSVars__ = () => {
37-
__useCssVars__(_ctx => ({ color: _ctx.color }))
37+
_useCssVars(_ctx => ({ color: _ctx.color }))
3838
}
3939
const __setup__ = __default__.setup
4040
__default__.setup = __setup__
@@ -44,12 +44,13 @@ export default __default__"
4444
`;
4545
4646
exports[`SFC compile <script setup> CSS vars injection w/ <script setup> 1`] = `
47-
"import { useCssVars } from 'vue'
47+
"import { useCssVars as _useCssVars } from 'vue'
4848
4949
export default {
50+
expose: [],
5051
setup() {
5152
const color = 'red'
52-
__useCssVars__(_ctx => ({ color }))
53+
_useCssVars(_ctx => ({ color }))
5354
return { color }
5455
}
5556
@@ -58,6 +59,7 @@ return { color }
5859
5960
exports[`SFC compile <script setup> defineOptions() 1`] = `
6061
"export default {
62+
expose: [],
6163
props: {
6264
foo: String
6365
},
@@ -78,6 +80,7 @@ exports[`SFC compile <script setup> errors should allow defineOptions() referenc
7880
"import { bar } from './bar'
7981
8082
export default {
83+
expose: [],
8184
props: {
8285
foo: {
8386
default: () => bar
@@ -95,6 +98,7 @@ return { bar }
9598
9699
exports[`SFC compile <script setup> errors should allow defineOptions() referencing scope var 1`] = `
97100
"export default {
101+
expose: [],
98102
props: {
99103
foo: {
100104
default: bar => bar + 1
@@ -112,12 +116,14 @@ return { bar }
112116
`;
113117
114118
exports[`SFC compile <script setup> imports dedupe between user & helper 1`] = `
115-
"import { ref } from 'vue'
119+
"import { ref as _ref } from 'vue'
120+
import { ref } from 'vue'
116121
117122
export default {
123+
expose: [],
118124
setup() {
119125
120-
const foo = ref(1)
126+
const foo = _ref(1)
121127
122128
return { foo, ref }
123129
}
@@ -129,6 +135,7 @@ exports[`SFC compile <script setup> imports import dedupe between <script> and <
129135
"import { x } from './x'
130136
131137
export default {
138+
expose: [],
132139
setup() {
133140
134141
x()
@@ -144,6 +151,7 @@ exports[`SFC compile <script setup> imports should extract comment for import or
144151
import b from 'b'
145152
146153
export default {
154+
expose: [],
147155
setup() {
148156
149157
@@ -156,6 +164,7 @@ return { a, b }
156164
exports[`SFC compile <script setup> imports should hoist and expose imports 1`] = `
157165
"import { ref } from 'vue'
158166
export default {
167+
expose: [],
159168
setup() {
160169
161170
return { ref }
@@ -172,6 +181,7 @@ import { ref } from 'vue'
172181
import other from './util'
173182
174183
export default {
184+
expose: [],
175185
setup() {
176186
177187
const count = ref(0)
@@ -197,6 +207,7 @@ const _hoisted_1 = /*#__PURE__*/_createVNode(\\"div\\", null, \\"static\\", -1 /
197207
import { ref } from 'vue'
198208
199209
export default {
210+
expose: [],
200211
setup() {
201212
202213
const count = ref(0)
@@ -213,12 +224,13 @@ return (_ctx, _cache, $props, $setup, $data, $options) => {
213224
`;
214225
215226
exports[`SFC compile <script setup> ref: syntax sugar accessing ref binding 1`] = `
216-
"import { ref } from 'vue'
227+
"import { ref as _ref } from 'vue'
217228
218229
export default {
230+
expose: [],
219231
setup() {
220232
221-
const a = ref(1)
233+
const a = _ref(1)
222234
console.log(a.value)
223235
function get() {
224236
return a.value + 1
@@ -231,15 +243,16 @@ return { a, get }
231243
`;
232244
233245
exports[`SFC compile <script setup> ref: syntax sugar array destructure 1`] = `
234-
"import { ref } from 'vue'
246+
"import { ref as _ref } from 'vue'
235247
236248
export default {
249+
expose: [],
237250
setup() {
238251
239-
const n = ref(1), [__a, __b = 1, ...__c] = useFoo()
240-
const a = ref(__a);
241-
const b = ref(__b);
242-
const c = ref(__c);
252+
const n = _ref(1), [__a, __b = 1, ...__c] = useFoo()
253+
const a = _ref(__a);
254+
const b = _ref(__b);
255+
const c = _ref(__c);
243256
console.log(n.value, a.value, b.value, c.value)
244257
245258
return { n, a, b, c }
@@ -249,14 +262,15 @@ return { n, a, b, c }
249262
`;
250263
251264
exports[`SFC compile <script setup> ref: syntax sugar convert ref declarations 1`] = `
252-
"import { ref } from 'vue'
265+
"import { ref as _ref } from 'vue'
253266
254267
export default {
268+
expose: [],
255269
setup() {
256270
257-
const foo = ref()
258-
const a = ref(1)
259-
const b = ref({
271+
const foo = _ref()
272+
const a = _ref(1)
273+
const b = _ref({
260274
count: 0
261275
})
262276
let c = () => {}
@@ -269,12 +283,13 @@ return { foo, a, b, c, d }
269283
`;
270284
271285
exports[`SFC compile <script setup> ref: syntax sugar multi ref declarations 1`] = `
272-
"import { ref } from 'vue'
286+
"import { ref as _ref } from 'vue'
273287
274288
export default {
289+
expose: [],
275290
setup() {
276291
277-
const a = ref(1), b = ref(2), c = ref({
292+
const a = _ref(1), b = _ref(2), c = _ref({
278293
count: 0
279294
})
280295
@@ -285,13 +300,14 @@ return { a, b, c }
285300
`;
286301
287302
exports[`SFC compile <script setup> ref: syntax sugar mutating ref binding 1`] = `
288-
"import { ref } from 'vue'
303+
"import { ref as _ref } from 'vue'
289304
290305
export default {
306+
expose: [],
291307
setup() {
292308
293-
const a = ref(1)
294-
const b = ref({ count: 0 })
309+
const a = _ref(1)
310+
const b = _ref({ count: 0 })
295311
function inc() {
296312
a.value++
297313
a.value = a.value + 1
@@ -306,16 +322,17 @@ return { a, b, inc }
306322
`;
307323
308324
exports[`SFC compile <script setup> ref: syntax sugar nested destructure 1`] = `
309-
"import { ref } from 'vue'
325+
"import { ref as _ref } from 'vue'
310326
311327
export default {
328+
expose: [],
312329
setup() {
313330
314331
const [{ a: { b: __b }}] = useFoo()
315-
const b = ref(__b);
332+
const b = _ref(__b);
316333
const { c: [__d, __e] } = useBar()
317-
const d = ref(__d);
318-
const e = ref(__e);
334+
const d = _ref(__d);
335+
const e = _ref(__e);
319336
console.log(b.value, d.value, e.value)
320337
321338
return { b, d, e }
@@ -325,17 +342,18 @@ return { b, d, e }
325342
`;
326343
327344
exports[`SFC compile <script setup> ref: syntax sugar object destructure 1`] = `
328-
"import { ref } from 'vue'
345+
"import { ref as _ref } from 'vue'
329346
330347
export default {
348+
expose: [],
331349
setup() {
332350
333-
const n = ref(1), { a: __a, b: __c, d: __d = 1, e: __f = 2, ...__g } = useFoo()
334-
const a = ref(__a);
335-
const c = ref(__c);
336-
const d = ref(__d);
337-
const f = ref(__f);
338-
const g = ref(__g);
351+
const n = _ref(1), { a: __a, b: __c, d: __d = 1, e: __f = 2, ...__g } = useFoo()
352+
const a = _ref(__a);
353+
const c = _ref(__c);
354+
const d = _ref(__d);
355+
const f = _ref(__f);
356+
const g = _ref(__g);
339357
console.log(n.value, a.value, c.value, d.value, f.value, g.value)
340358
341359
return { n, a, c, d, f, g }
@@ -346,6 +364,7 @@ return { n, a, c, d, f, g }
346364
347365
exports[`SFC compile <script setup> ref: syntax sugar should not convert non ref labels 1`] = `
348366
"export default {
367+
expose: [],
349368
setup() {
350369
351370
foo: a = 1, b = 2, c = {
@@ -359,12 +378,13 @@ return { }
359378
`;
360379
361380
exports[`SFC compile <script setup> ref: syntax sugar using ref binding in property shorthand 1`] = `
362-
"import { ref } from 'vue'
381+
"import { ref as _ref } from 'vue'
363382
364383
export default {
384+
expose: [],
365385
setup() {
366386
367-
const a = ref(1)
387+
const a = _ref(1)
368388
const b = { a: a.value }
369389
function test() {
370390
const { a } = b
@@ -380,6 +400,7 @@ exports[`SFC compile <script setup> should expose top level declarations 1`] = `
380400
"import { x } from './x'
381401
382402
export default {
403+
expose: [],
383404
setup() {
384405
385406
let a = 1
@@ -394,10 +415,11 @@ return { a, b, c, d, x }
394415
`;
395416
396417
exports[`SFC compile <script setup> with TypeScript defineOptions w/ runtime options 1`] = `
397-
"import { defineComponent } from 'vue'
418+
"import { defineComponent as _defineComponent } from 'vue'
398419
399420
400-
export default defineComponent({
421+
export default _defineComponent({
422+
expose: [],
401423
props: { foo: String },
402424
emits: ['a', 'b'],
403425
setup(__props, { props, emit }) {
@@ -411,10 +433,11 @@ return { props, emit }
411433
`;
412434
413435
exports[`SFC compile <script setup> with TypeScript defineOptions w/ type / extract emits (union) 1`] = `
414-
"import { Slots, defineComponent } from 'vue'
436+
"import { Slots as _Slots, defineComponent as _defineComponent } from 'vue'
415437
416438
417-
export default defineComponent({
439+
export default _defineComponent({
440+
expose: [],
418441
emits: [\\"foo\\", \\"bar\\", \\"baz\\"] as unknown as undefined,
419442
setup(__props, { emit }: {
420443
props: {},
@@ -432,10 +455,11 @@ return { emit }
432455
`;
433456
434457
exports[`SFC compile <script setup> with TypeScript defineOptions w/ type / extract emits 1`] = `
435-
"import { Slots, defineComponent } from 'vue'
458+
"import { Slots as _Slots, defineComponent as _defineComponent } from 'vue'
436459
437460
438-
export default defineComponent({
461+
export default _defineComponent({
462+
expose: [],
439463
emits: [\\"foo\\", \\"bar\\"] as unknown as undefined,
440464
setup(__props, { emit }: {
441465
props: {},
@@ -453,14 +477,15 @@ return { emit }
453477
`;
454478
455479
exports[`SFC compile <script setup> with TypeScript defineOptions w/ type / extract props 1`] = `
456-
"import { defineComponent } from 'vue'
480+
"import { defineComponent as _defineComponent } from 'vue'
457481
458482
interface Test {}
459483
460484
type Alias = number[]
461485
462486
463-
export default defineComponent({
487+
export default _defineComponent({
488+
expose: [],
464489
props: {
465490
string: { type: String, required: true },
466491
number: { type: Number, required: true },
@@ -495,11 +520,12 @@ return { }
495520
`;
496521
497522
exports[`SFC compile <script setup> with TypeScript hoist type declarations 1`] = `
498-
"import { defineComponent } from 'vue'
523+
"import { defineComponent as _defineComponent } from 'vue'
499524
export interface Foo {}
500525
type Bar = {}
501526
502-
export default defineComponent({
527+
export default _defineComponent({
528+
expose: [],
503529
setup() {
504530
505531

0 commit comments

Comments
 (0)