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( `