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(compiler-sfc): add new line after defineProps #4765

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -392,6 +392,7 @@ export default {
expose()

const props = __props



return { props, propsModel }
Expand All @@ -410,6 +411,7 @@ exports[`SFC compile <script setup> defineProps() 1`] = `

const props = __props


const bar = 1

return { props, bar }
Expand All @@ -426,6 +428,7 @@ exports[`SFC compile <script setup> defineProps/defineEmits in multi-variable de
expose()

const props = __props



return { props, emit }
Expand All @@ -442,6 +445,7 @@ exports[`SFC compile <script setup> defineProps/defineEmits in multi-variable de
expose()

const props = __props

const a = 1;

return { props, a, emit }
Expand Down Expand Up @@ -589,6 +593,24 @@ return { bar }
}"
`;

exports[`SFC compile <script setup> import without new line at top of setup script + defineProps 1`] = `
"const props = __props
import { ref } from 'vue'

export default {
props: {
foo: String
},
setup(__props, { expose }) {
expose()


return { props, ref }
}

}"
`;

exports[`SFC compile <script setup> imports dedupe between user & helper 1`] = `
"import { ref as _ref } from 'vue'
import { ref } from 'vue'
Expand Down Expand Up @@ -1286,6 +1308,7 @@ const props = __props




return { props, emit }
}

Expand Down Expand Up @@ -1341,6 +1364,7 @@ const props = __props as {
bar?: number
baz: boolean
}



return { props, defaults }
Expand All @@ -1363,6 +1387,7 @@ export default /*#__PURE__*/_defineComponent({
expose()

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



return { props }
Expand Down
12 changes: 12 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Expand Up @@ -84,6 +84,18 @@ const bar = 1
},`)
})

test('import without new line at top of setup script + defineProps ', () => {
const { content } = compile(`
<script setup>import { ref } from 'vue'
const props = defineProps({
foo: String
})
</script>
`)
// should generate working code
assertCode(content)
})

test('defineProps w/ external definition', () => {
const { content } = compile(`
<script setup>
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/compileScript.ts
Expand Up @@ -1214,7 +1214,7 @@ export function compileScript(
startOffset,
`\nconst ${propsIdentifier} = __props${
propsTypeDecl ? ` as ${genSetupPropsType(propsTypeDecl)}` : ``
}`
}\n`
)
}
if (propsDestructureRestId) {
Expand Down