diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index 949c9946d9f..a8d9a33087f 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -739,6 +739,21 @@ return { get FooBaz() { return FooBaz }, get Last() { return Last } } })" `; +exports[`SFC compile + + `) + expect(content).toMatch('return { get Foo() { return Foo } }') + assertCode(content) + }) }) describe('inlineTemplate mode', () => { diff --git a/packages/compiler-sfc/src/script/importUsageCheck.ts b/packages/compiler-sfc/src/script/importUsageCheck.ts index 7019dcf2312..b5cec68ddd4 100644 --- a/packages/compiler-sfc/src/script/importUsageCheck.ts +++ b/packages/compiler-sfc/src/script/importUsageCheck.ts @@ -20,7 +20,7 @@ export function isImportUsed(local: string, sfc: SFCDescriptor): boolean { return new RegExp( // #4274 escape $ since it's a special char in regex // (and is the only regex special char that is valid in identifiers) - `[^\\w$_]${local.replace(/\$/g, '\\$')}[^\\w$_]` + `[^\\w$.]${local.replace(/\$/g, '\\$')}[^\\w$]` ).test(resolveTemplateUsageCheckString(sfc)) } @@ -63,7 +63,11 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor) { )}` } } - if (prop.type === NodeTypes.ATTRIBUTE && prop.name === 'ref' && prop.value?.content) { + if ( + prop.type === NodeTypes.ATTRIBUTE && + prop.name === 'ref' && + prop.value?.content + ) { code += `,${prop.value.content}` } }