From 83d95351a9f809311d624fc3398e7f6829b72447 Mon Sep 17 00:00:00 2001 From: lsdsjy Date: Thu, 7 Dec 2023 14:14:27 +0800 Subject: [PATCH] fix(compiler-sfc): check template `ref` usage, (#12985) close #12984 --- packages/compiler-sfc/src/compileScript.ts | 2 ++ .../test/__snapshots__/compileScript.spec.ts.snap | 14 ++++++++++++++ packages/compiler-sfc/test/compileScript.spec.ts | 13 +++++++++++++ 3 files changed, 29 insertions(+) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 2c0f9f246..275945a2b 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -1818,6 +1818,8 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor, isTS: boolean) { if (value) { code += `,${processExp(value, isTS, baseName)}` } + } else if (name === 'ref') { + code += `,${value}` } } }, diff --git a/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap index 601abd2ee..4b81610a4 100644 --- a/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap @@ -364,6 +364,20 @@ return { vMyDir } })" `; +exports[`SFC compile + + `) + expect(content).toMatch(`return { aref }`) + assertCode(content) + }) + test('vue interpolations', () => { const { content } = compile(`