"import { x } from './x'
export const n = 1
- const __default__ = {
+ const __default__ = {
some:'option'
}
"import { x } from './x'
export const n = 1
- const __default__ = {
+ const __default__ = {
some:'option'
}
expose()
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: {
const props = __props
+
const bar = 1
return { props, bar }
expose()
const props = __props
+
return { props, emit }
expose()
const props = __props
+
const a = 1;
return { props, a, emit }
}),
_createElementVNode(\\"div\\", {
onClick: _cache[5] || (_cache[5] = () => {
- let a = '' + _unref(lett)
+ let a = '' + _unref(lett)
_isRef(v) ? v.value = a : v = a
})
}),
let z2 = z
})
let lz = _ctx.z
- })
+ })
_isRef(v) ? v.value = _ctx.a : v = _ctx.a
})
})
+
return { props, emit }
}
bar?: number
baz: boolean
}
+
return { props, defaults }
expose()
const props = __props as { foo: string, bar?: number, baz: boolean, qux(): number }
+
return { props }
setup(__props) {
const rest = _createPropsRestProxy(__props, [\\"foo\\",\\"bar\\"])
+
return () => {}
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>
const { content } = compile(`
<script>
export const n = 1
- export default
- {
+ export default
+ {
some:'option'
}
</script>
const { content } = compile(`
<script>
export const n = 1
- export default{
+ export default{
some:'option'
}
</script>
<div @click="v += 1"/>
<div @click="v -= 1"/>
<div @click="() => {
- let a = '' + lett
+ let a = '' + lett
v = a
}"/>
<div @click="() => {
let z2 = z
})
let lz = z
- })
+ })
v = a
}"/>
</template>
// 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 =