Skip to content

Commit fb9d9e1

Browse files
committed
fix(compiler-sfc): updated code
1 parent 31b3866 commit fb9d9e1

File tree

3 files changed

+4
-212
lines changed

3 files changed

+4
-212
lines changed
Lines changed: 1 addition & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,11 @@
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-
993
exports[`sfc props transform > default values w/ type declaration & key is string 1`] = `
1004
"import { defineComponent as _defineComponent } from 'vue'
1015
1026
export default /*#__PURE__*/_defineComponent({
1037
props: {
104-
\\"foo\\": { type: Number, required: true, default: 1 }
8+
foo: { type: Number, required: true, default: 1 }
1059
},
10610
setup(__props: any) {
10711
@@ -112,114 +16,3 @@ return () => {}
11216
11317
})"
11418
`;
115-
116-
exports[`sfc props transform > default values w/ type declaration 1`] = `
117-
"import { defineComponent as _defineComponent } from 'vue'
118-
119-
export default /*#__PURE__*/_defineComponent({
120-
props: {
121-
foo: { type: Number, required: false, default: 1 },
122-
bar: { type: Object, required: false, default: () => ({}) }
123-
},
124-
setup(__props: any) {
125-
126-
127-
128-
return () => {}
129-
}
130-
131-
})"
132-
`;
133-
134-
exports[`sfc props transform > default values w/ type declaration, prod mode 1`] = `
135-
"import { defineComponent as _defineComponent } from 'vue'
136-
137-
export default /*#__PURE__*/_defineComponent({
138-
props: {
139-
foo: { default: 1 },
140-
bar: { default: () => ({}) },
141-
baz: null,
142-
boola: { type: Boolean },
143-
boolb: { type: [Boolean, Number] },
144-
func: { type: Function, default: () => (() => {}) }
145-
},
146-
setup(__props: any) {
147-
148-
149-
150-
return () => {}
151-
}
152-
153-
})"
154-
`;
155-
156-
exports[`sfc props transform > multiple variable declarations 1`] = `
157-
"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
158-
159-
160-
export default {
161-
props: ['foo'],
162-
setup(__props) {
163-
164-
const bar = 'fish', hello = 'world'
165-
166-
return (_ctx, _cache) => {
167-
return (_openBlock(), _createElementBlock(\\"div\\", null, _toDisplayString(__props.foo) + \\" \\" + _toDisplayString(hello) + \\" \\" + _toDisplayString(bar), 1 /* TEXT */))
168-
}
169-
}
170-
171-
}"
172-
`;
173-
174-
exports[`sfc props transform > nested scope 1`] = `
175-
"export default {
176-
props: ['foo', 'bar'],
177-
setup(__props) {
178-
179-
180-
function test(foo) {
181-
console.log(foo)
182-
console.log(__props.bar)
183-
}
184-
185-
return () => {}
186-
}
187-
188-
}"
189-
`;
190-
191-
exports[`sfc props transform > non-identifier prop names 1`] = `
192-
"import { toDisplayString as _toDisplayString } from \\"vue\\"
193-
194-
195-
export default {
196-
props: { 'foo.bar': Function },
197-
setup(__props) {
198-
199-
200-
let x = __props[\\"foo.bar\\"]
201-
202-
return (_ctx, _cache) => {
203-
return _toDisplayString(__props[\\"foo.bar\\"])
204-
}
205-
}
206-
207-
}"
208-
`;
209-
210-
exports[`sfc props transform > rest spread 1`] = `
211-
"import { createPropsRestProxy as _createPropsRestProxy } from 'vue'
212-
213-
export default {
214-
props: ['foo', 'bar', 'baz'],
215-
setup(__props) {
216-
217-
const rest = _createPropsRestProxy(__props, [\\"foo\\",\\"bar\\"]);
218-
219-
220-
221-
return () => {}
222-
}
223-
224-
}"
225-
`;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('sfc props transform', () => {
107107
`)
108108
expect(content).toMatch(`
109109
props: {
110-
"foo": { type: Number, required: true, default: 1 }
110+
foo: { type: Number, required: true, default: 1 }
111111
},`)
112112
assertCode(content)
113113
})

packages/compiler-sfc/src/compileScript.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,7 @@ export function compileScript(
871871
}
872872

873873
function genDestructuredDefaultValue(key: string): string | undefined {
874-
const rawKey = key.startsWith('"') && key.endsWith('"') ? key.split('"')[1] : key
875-
const destructured = propsDestructuredBindings[rawKey]
874+
const destructured = propsDestructuredBindings[key]
876875
if (destructured && destructured.default) {
877876
const value = scriptSetup!.content.slice(
878877
destructured.default.start!,
@@ -1895,7 +1894,7 @@ function extractRuntimeProps(
18951894
) {
18961895
let type, keyName;
18971896
if(m.key.type === 'StringLiteral'){
1898-
keyName = `"${m.key.value}"`
1897+
keyName = m.key.value
18991898
} else {
19001899
keyName = m.key.name
19011900
}

0 commit comments

Comments
 (0)