Skip to content

Commit 1b49b5a

Browse files
committed
fix(compiler-sfc): updated code
1 parent 9ebb189 commit 1b49b5a

File tree

1 file changed

+207
-0
lines changed

1 file changed

+207
-0
lines changed

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

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,101 @@
11
// Vitest Snapshot v1
22

3+
exports[`sfc props transform > $$() escape 1`] = `
4+
"import { toRef as _toRef } from 'vue'
5+
6+
export default {
7+
props: ['foo'],
8+
setup(__props) {
9+
const __props_bar = _toRef(__props, 'bar');
10+
const __props_foo = _toRef(__props, 'foo');
11+
12+
13+
console.log((__props_foo))
14+
console.log((__props_bar))
15+
;({ foo: __props_foo, baz: __props_bar })
16+
17+
return () => {}
18+
}
19+
20+
}"
21+
`;
22+
23+
exports[`sfc props transform > aliasing 1`] = `
24+
"import { toDisplayString as _toDisplayString } from \\"vue\\"
25+
26+
27+
export default {
28+
props: ['foo'],
29+
setup(__props) {
30+
31+
32+
let x = foo
33+
let y = __props.foo
34+
35+
return (_ctx, _cache) => {
36+
return _toDisplayString(__props.foo + __props.foo)
37+
}
38+
}
39+
40+
}"
41+
`;
42+
43+
exports[`sfc props transform > basic usage 1`] = `
44+
"import { toDisplayString as _toDisplayString } from \\"vue\\"
45+
46+
47+
export default {
48+
props: ['foo'],
49+
setup(__props) {
50+
51+
52+
console.log(__props.foo)
53+
54+
return (_ctx, _cache) => {
55+
return _toDisplayString(__props.foo)
56+
}
57+
}
58+
59+
}"
60+
`;
61+
62+
exports[`sfc props transform > computed static key 1`] = `
63+
"import { toDisplayString as _toDisplayString } from \\"vue\\"
64+
65+
66+
export default {
67+
props: ['foo'],
68+
setup(__props) {
69+
70+
71+
console.log(__props.foo)
72+
73+
return (_ctx, _cache) => {
74+
return _toDisplayString(__props.foo)
75+
}
76+
}
77+
78+
}"
79+
`;
80+
81+
exports[`sfc props transform > default values w/ runtime declaration 1`] = `
82+
"import { mergeDefaults as _mergeDefaults } from 'vue'
83+
84+
export default {
85+
props: _mergeDefaults(['foo', 'bar'], {
86+
foo: 1,
87+
bar: () => ({})
88+
}),
89+
setup(__props) {
90+
91+
92+
93+
return () => {}
94+
}
95+
96+
}"
97+
`;
98+
399
exports[`sfc props transform > default values w/ type declaration & key is string 1`] = `
4100
"import { defineComponent as _defineComponent } from 'vue'
5101
@@ -19,3 +115,114 @@ return () => {}
19115
20116
})"
21117
`;
118+
119+
exports[`sfc props transform > default values w/ type declaration 1`] = `
120+
"import { defineComponent as _defineComponent } from 'vue'
121+
122+
export default /*#__PURE__*/_defineComponent({
123+
props: {
124+
foo: { type: Number, required: false, default: 1 },
125+
bar: { type: Object, required: false, default: () => ({}) }
126+
},
127+
setup(__props: any) {
128+
129+
130+
131+
return () => {}
132+
}
133+
134+
})"
135+
`;
136+
137+
exports[`sfc props transform > default values w/ type declaration, prod mode 1`] = `
138+
"import { defineComponent as _defineComponent } from 'vue'
139+
140+
export default /*#__PURE__*/_defineComponent({
141+
props: {
142+
foo: { default: 1 },
143+
bar: { default: () => ({}) },
144+
baz: null,
145+
boola: { type: Boolean },
146+
boolb: { type: [Boolean, Number] },
147+
func: { type: Function, default: () => (() => {}) }
148+
},
149+
setup(__props: any) {
150+
151+
152+
153+
return () => {}
154+
}
155+
156+
})"
157+
`;
158+
159+
exports[`sfc props transform > multiple variable declarations 1`] = `
160+
"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
161+
162+
163+
export default {
164+
props: ['foo'],
165+
setup(__props) {
166+
167+
const bar = 'fish', hello = 'world'
168+
169+
return (_ctx, _cache) => {
170+
return (_openBlock(), _createElementBlock(\\"div\\", null, _toDisplayString(__props.foo) + \\" \\" + _toDisplayString(hello) + \\" \\" + _toDisplayString(bar), 1 /* TEXT */))
171+
}
172+
}
173+
174+
}"
175+
`;
176+
177+
exports[`sfc props transform > nested scope 1`] = `
178+
"export default {
179+
props: ['foo', 'bar'],
180+
setup(__props) {
181+
182+
183+
function test(foo) {
184+
console.log(foo)
185+
console.log(__props.bar)
186+
}
187+
188+
return () => {}
189+
}
190+
191+
}"
192+
`;
193+
194+
exports[`sfc props transform > non-identifier prop names 1`] = `
195+
"import { toDisplayString as _toDisplayString } from \\"vue\\"
196+
197+
198+
export default {
199+
props: { 'foo.bar': Function },
200+
setup(__props) {
201+
202+
203+
let x = __props[\\"foo.bar\\"]
204+
205+
return (_ctx, _cache) => {
206+
return _toDisplayString(__props[\\"foo.bar\\"])
207+
}
208+
}
209+
210+
}"
211+
`;
212+
213+
exports[`sfc props transform > rest spread 1`] = `
214+
"import { createPropsRestProxy as _createPropsRestProxy } from 'vue'
215+
216+
export default {
217+
props: ['foo', 'bar', 'baz'],
218+
setup(__props) {
219+
220+
const rest = _createPropsRestProxy(__props, [\\"foo\\",\\"bar\\"]);
221+
222+
223+
224+
return () => {}
225+
}
226+
227+
}"
228+
`;

0 commit comments

Comments
 (0)