From bb59751dd4e45afcaafd607f22505a724b1ef841 Mon Sep 17 00:00:00 2001 From: webfansplz <308241863@qq.com> Date: Mon, 23 Oct 2023 15:08:17 +0800 Subject: [PATCH] fix(compiler-sfc): Optimize the value of emitIdentifier (#12851) --- packages/compiler-sfc/src/compileScript.ts | 5 ++++- .../__snapshots__/compileScript.spec.ts.snap | 16 ++++++++++++++++ packages/compiler-sfc/test/compileScript.spec.ts | 13 +++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index db04dbef3..d6e066d80 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -414,7 +414,10 @@ export function compileScript( } if (declId) { - emitIdentifier = scriptSetup!.content.slice(declId.start!, declId.end!) + emitIdentifier = + declId.type === 'Identifier' + ? declId.name + : scriptSetup!.content.slice(declId.start!, declId.end!) } return true diff --git a/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap index bb52a66b9..bcecdb4ef 100644 --- a/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap @@ -558,6 +558,22 @@ export default /*#__PURE__*/_defineComponent({ +return { emit } +} + +})" +`; + +exports[`SFC compile + `) + assertCode(content) + expect(content).toMatch(`setup(__props, { emit }) {`) + expect(content).toMatch(`emits: ['foo']`) + }) + test('runtime Enum', () => { const { content, bindings } = compile( `