From: Evan You Date: Mon, 2 Sep 2024 09:29:40 +0000 (+0800) Subject: fix(compiler-sfc): fix import usage check for kebab-case same name shorthand binding X-Git-Tag: v3.5.0~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0f7c0e5dc0eedada7a5194db87fd0a7dbd1d3354;p=thirdparty%2Fvuejs%2Fcore.git fix(compiler-sfc): fix import usage check for kebab-case same name shorthand binding fix #11745 close #11754 --- diff --git a/packages/compiler-sfc/__tests__/compileScript/importUsageCheck.spec.ts b/packages/compiler-sfc/__tests__/compileScript/importUsageCheck.spec.ts index fe52b12d4e..210fa09688 100644 --- a/packages/compiler-sfc/__tests__/compileScript/importUsageCheck.spec.ts +++ b/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( + ` + + + `, + ) + expect(content).toMatch('return { get fooBar() { return fooBar }') +}) diff --git a/packages/compiler-sfc/src/script/importUsageCheck.ts b/packages/compiler-sfc/src/script/importUsageCheck.ts index 6b9fbc634c..22ef37cf37 100644 --- a/packages/compiler-sfc/src/script/importUsageCheck.ts +++ b/packages/compiler-sfc/src/script/importUsageCheck.ts @@ -62,7 +62,7 @@ function resolveTemplateUsedIdentifiers(sfc: SFCDescriptor): Set { 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 (