Jelajahi Sumber

fix(compiler-sfc): fix import usage check for kebab-case same name shorthand binding

fix #11745
close #11754
Evan You 1 tahun lalu
induk
melakukan
0f7c0e5dc0

+ 15 - 0
packages/compiler-sfc/__tests__/compileScript/importUsageCheck.spec.ts

@@ -250,3 +250,18 @@ test('check when has explicit parse options', () => {
   )
   expect(content).toMatch('return { get x() { return x } }')
 })
+
+// #11745
+test('shorthand binding w/ kebab-case', () => {
+  const { content } = compile(
+    `
+    <script setup lang="ts">
+      import { fooBar } from "./foo.ts"
+    </script>
+    <template>
+      <div :foo-bar></div>
+    </template>
+    `,
+  )
+  expect(content).toMatch('return { get fooBar() { return fooBar }')
+})

+ 1 - 1
packages/compiler-sfc/src/script/importUsageCheck.ts

@@ -62,7 +62,7 @@ function resolveTemplateUsedIdentifiers(sfc: SFCDescriptor): Set<string> {
               extractIdentifiers(ids, prop.exp)
             } else if (prop.name === 'bind' && !prop.exp) {
               // v-bind shorthand name as identifier
-              ids.add((prop.arg as SimpleExpressionNode).content)
+              ids.add(camelize((prop.arg as SimpleExpressionNode).content))
             }
           }
           if (