瀏覽代碼

fix(compile-sfc): generate setup prop type format error (#4506)

fix #4505
webfansplz 4 年之前
父節點
當前提交
e6fe751b20
共有 2 個文件被更改,包括 4 次插入3 次删除
  1. 2 2
      packages/compiler-sfc/__tests__/compileScript.spec.ts
  2. 2 1
      packages/compiler-sfc/src/compileScript.ts

+ 2 - 2
packages/compiler-sfc/__tests__/compileScript.spec.ts

@@ -799,8 +799,8 @@ const emit = defineEmits(['a', 'b'])
       <script setup lang="ts">
       const props = withDefaults(defineProps<{
         foo?: string
-        bar?: number
-        baz: boolean
+        bar?: number;
+        baz: boolean;
         qux?(): number
       }>(), {
         foo: 'hi',

+ 2 - 1
packages/compiler-sfc/src/compileScript.ts

@@ -623,7 +623,8 @@ export function compileScript(
               ) +
               ', '
           } else {
-            res += scriptSetupSource.slice(m.start!, m.end!) + `, `
+            res +=
+              scriptSetupSource.slice(m.start!, m.typeAnnotation.end!) + `, `
           }
         }
       }