From 89eda30c874f8c7f042acb4dd5b15ec74ecf3980 Mon Sep 17 00:00:00 2001 From: lsdsjy Date: Thu, 16 Mar 2023 19:42:57 +0800 Subject: [PATCH 1/3] fix(sfc): check template `ref` usage --- packages/compiler-sfc/src/compileScript.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index db04dbef333..3fd18018ef3 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -1801,7 +1801,7 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor, isTS: boolean) { } for (let i = 0; i < attrs.length; i++) { const { name, value } = attrs[i] - if (dirRE.test(name)) { + if (dirRE.test(name) || name === 'ref') { const baseName = onRE.test(name) ? 'on' : slotRE.test(name) From 70f6e7d56d521fd6451e793bd0e8ca322d717ab3 Mon Sep 17 00:00:00 2001 From: lsdsjy Date: Thu, 16 Mar 2023 19:53:21 +0800 Subject: [PATCH 2/3] chore: add test case --- .../test/__snapshots__/compileScript.spec.ts.snap | 14 ++++++++++++++ packages/compiler-sfc/test/compileScript.spec.ts | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap index bb52a66b907..82b305c4255 100644 --- a/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap @@ -348,6 +348,20 @@ return { vMyDir } })" `; +exports[`SFC compile + + `) + expect(content).toMatch(`return { aref }`) + assertCode(content) + }) + test('vue interpolations', () => { const { content } = compile(`