Skip to content

Commit

Permalink
fix(compiler-sfc): fix defineProps() call on imported identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 25, 2021
1 parent be2b1d3 commit 691d354
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ return { }
}"
`;
exports[`SFC compile <script setup> defineProps w/ external definition 1`] = `
"import { propsModel } from './props'
export default {
props: propsModel,
setup(__props, { expose }) {
expose()
const props = __props
return { props, propsModel }
}
}"
`;
exports[`SFC compile <script setup> defineProps() 1`] = `
"export default {
props: {
Expand Down
13 changes: 13 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ const bar = 1
},`)
})

test('defineProps w/ external definition', () => {
const { content } = compile(`
<script setup>
import { defineProps } from 'vue'
import { propsModel } from './props'
const props = defineProps(propsModel)
</script>
`)
assertCode(content)
expect(content).toMatch(`export default {
props: propsModel,`)
})

test('defineEmit() (deprecated)', () => {
const { content, bindings } = compile(`
<script setup>
Expand Down
10 changes: 9 additions & 1 deletion packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,15 @@ export function walkIdentifiers(
})
}

function isRefIdentifier(id: Identifier, parent: Node, parentStack: Node[]) {
function isRefIdentifier(
id: Identifier,
parent: Node | null,
parentStack: Node[]
) {
if (!parent) {
return true
}

// declaration id
if (
(parent.type === 'VariableDeclarator' ||
Expand Down

0 comments on commit 691d354

Please sign in to comment.