parent
9e3d7731c7
commit
d4c04e9799
@ -394,12 +394,30 @@ export default {
|
||||
const props = __props
|
||||
|
||||
|
||||
|
||||
return { props, propsModel }
|
||||
}
|
||||
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`SFC compile <script setup> defineProps w/ leading code 1`] = `
|
||||
"import { x } from './x'
|
||||
|
||||
export default {
|
||||
props: {},
|
||||
setup(__props, { expose }) {
|
||||
expose()
|
||||
|
||||
const props = __props
|
||||
|
||||
|
||||
return { props, x }
|
||||
}
|
||||
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`SFC compile <script setup> defineProps() 1`] = `
|
||||
"export default {
|
||||
props: {
|
||||
@ -410,6 +428,7 @@ exports[`SFC compile <script setup> defineProps() 1`] = `
|
||||
|
||||
const props = __props
|
||||
|
||||
|
||||
const bar = 1
|
||||
|
||||
return { props, bar }
|
||||
@ -428,6 +447,7 @@ exports[`SFC compile <script setup> defineProps/defineEmits in multi-variable de
|
||||
const props = __props
|
||||
|
||||
|
||||
|
||||
return { props, emit }
|
||||
}
|
||||
|
||||
@ -442,6 +462,7 @@ exports[`SFC compile <script setup> defineProps/defineEmits in multi-variable de
|
||||
expose()
|
||||
|
||||
const props = __props
|
||||
|
||||
const a = 1;
|
||||
|
||||
return { props, a, emit }
|
||||
@ -1286,6 +1307,7 @@ const props = __props
|
||||
|
||||
|
||||
|
||||
|
||||
return { props, emit }
|
||||
}
|
||||
|
||||
@ -1362,6 +1384,7 @@ const props = __props as {
|
||||
}
|
||||
|
||||
|
||||
|
||||
return { props, defaults }
|
||||
}
|
||||
|
||||
@ -1384,6 +1407,7 @@ export default /*#__PURE__*/_defineComponent({
|
||||
const props = __props as { foo: string, bar?: number, baz: boolean, qux(): number }
|
||||
|
||||
|
||||
|
||||
return { props }
|
||||
}
|
||||
|
||||
|
@ -121,6 +121,7 @@ export default {
|
||||
const rest = _createPropsRestProxy(__props, [\\"foo\\",\\"bar\\"])
|
||||
|
||||
|
||||
|
||||
return () => {}
|
||||
}
|
||||
|
||||
|
@ -96,6 +96,18 @@ const bar = 1
|
||||
props: propsModel,`)
|
||||
})
|
||||
|
||||
// #4764
|
||||
test('defineProps w/ leading code', () => {
|
||||
const { content } = compile(`
|
||||
<script setup>import { x } from './x'
|
||||
const props = defineProps({})
|
||||
</script>
|
||||
`)
|
||||
// props declaration should be inside setup, not moved along with the import
|
||||
expect(content).not.toMatch(`const props = __props\nimport`)
|
||||
assertCode(content)
|
||||
})
|
||||
|
||||
test('defineEmits()', () => {
|
||||
const { content, bindings } = compile(`
|
||||
<script setup>
|
||||
|
@ -1205,25 +1205,25 @@ export function compileScript(
|
||||
// we use a default __props so that template expressions referencing props
|
||||
// can use it directly
|
||||
if (propsIdentifier) {
|
||||
s.prependRight(
|
||||
s.prependLeft(
|
||||
startOffset,
|
||||
`\nconst ${propsIdentifier} = __props${
|
||||
propsTypeDecl ? ` as ${genSetupPropsType(propsTypeDecl)}` : ``
|
||||
}`
|
||||
}\n`
|
||||
)
|
||||
}
|
||||
if (propsDestructureRestId) {
|
||||
s.prependRight(
|
||||
s.prependLeft(
|
||||
startOffset,
|
||||
`\nconst ${propsDestructureRestId} = ${helper(
|
||||
`createPropsRestProxy`
|
||||
)}(__props, ${JSON.stringify(Object.keys(propsDestructuredBindings))})`
|
||||
)}(__props, ${JSON.stringify(Object.keys(propsDestructuredBindings))})\n`
|
||||
)
|
||||
}
|
||||
// inject temp variables for async context preservation
|
||||
if (hasAwait) {
|
||||
const any = isTS ? `: any` : ``
|
||||
s.prependRight(startOffset, `\nlet __temp${any}, __restore${any}\n`)
|
||||
s.prependLeft(startOffset, `\nlet __temp${any}, __restore${any}\n`)
|
||||
}
|
||||
|
||||
const destructureElements =
|
||||
|
Loading…
Reference in New Issue
Block a user