]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): fix defineProps() call on imported identifier
authorEvan You <yyx990803@gmail.com>
Fri, 25 Jun 2021 18:05:59 +0000 (14:05 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 25 Jun 2021 18:05:59 +0000 (14:05 -0400)
packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap
packages/compiler-sfc/__tests__/compileScript.spec.ts
packages/compiler-sfc/src/compileScript.ts

index d65806a49af0b46ef0bec53690c1309eb573e43c..5e80e9790869ec074bfe54a6c8ccb9931bf22357 100644 (file)
@@ -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: {
index 085e2956f71d99efa528d3f9375104234f05269e..e0c2c5584b563f6f737b99601aeebc7f15af30dc 100644 (file)
@@ -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>
index 08f4863444d7781c4ccf1cf0c9036f41fcd23d6c..0eacf1f6ceb35c6da179eafabdd415a3d4c6c8ae 100644 (file)
@@ -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' ||