Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(defineProps): defineProps starts with parenthesis #6430

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -12,6 +12,27 @@ return { a }
}"
`;

exports[`SFC analyze <script> bindings auto name inference defineProps starts with parenthesis 1`] = `
"export default {
props: {
foo: String
},
setup(__props, { expose }) {
expose();

const props = __props;


(() => {
console.log(props)
})();

return { props }
}

}"
`;

exports[`SFC analyze <script> bindings auto name inference do not overwrite manual name (call) 1`] = `
"import { defineComponent } from 'vue'
const __default__ = defineComponent({
Expand Down Expand Up @@ -640,7 +661,7 @@ export default {
setup(__props, { expose }) {
expose();

const props = __props
const props = __props;



Expand All @@ -658,7 +679,7 @@ export default {
setup(__props, { expose }) {
expose();

const props = __props
const props = __props;


return { props, x }
Expand All @@ -675,7 +696,7 @@ exports[`SFC compile <script setup> defineProps() 1`] = `
setup(__props, { expose }) {
expose();

const props = __props
const props = __props;


const bar = 1
Expand All @@ -693,7 +714,7 @@ exports[`SFC compile <script setup> defineProps/defineEmits in multi-variable de
setup(__props, { expose, emit }) {
expose();

const props = __props
const props = __props;



Expand All @@ -710,7 +731,7 @@ exports[`SFC compile <script setup> defineProps/defineEmits in multi-variable de
setup(__props, { expose, emit }) {
expose();

const props = __props
const props = __props;

const a = 1;

Expand Down Expand Up @@ -1567,7 +1588,7 @@ export default /*#__PURE__*/_defineComponent({
setup(__props, { expose, emit }) {
expose();

const props = __props
const props = __props;



Expand Down Expand Up @@ -1661,7 +1682,7 @@ const props = __props as {
foo?: string
bar?: number
baz: boolean
}
};



Expand All @@ -1684,7 +1705,7 @@ export default /*#__PURE__*/_defineComponent({
setup(__props: any, { expose }) {
expose();

const props = __props as { foo: string, bar?: number, baz: boolean, qux(): number }
const props = __props as { foo: string, bar?: number, baz: boolean, qux(): number };



Expand Down
15 changes: 15 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Expand Up @@ -1705,5 +1705,20 @@ describe('SFC analyze <script> bindings', () => {
expect(content).toMatch(`name: 'Baz'`)
assertCode(content)
})

test('defineProps starts with parenthesis', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the position of the test is not correct.

Maybe it should be moved to line 98

const { content } = compile(`
<script setup>
const props = defineProps({
foo: String
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this line should without ;

(() => {
console.log(props)
})();
</script>
`)

assertCode(content)
})
})
})
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/compileScript.ts
Expand Up @@ -1339,7 +1339,7 @@ export function compileScript(
startOffset,
`\nconst ${propsIdentifier} = __props${
propsTypeDecl ? ` as ${genSetupPropsType(propsTypeDecl)}` : ``
}\n`
};\n`
)
}
if (propsDestructureRestId) {
Expand Down