diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index 818ea02e303..23a3741afb2 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -1457,6 +1457,22 @@ export default /*#__PURE__*/_defineComponent({ +return { emit } +} + +})" +`; + +exports[`SFC compile + `) + expect(content).toMatch(`emits: ["foo:bar"]`) + assertCode(content) + }) + describe('defineSlots()', () => { test('basic usage', () => { const { content } = compile(` diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 8d22d7e1348..31114c52d8c 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -2316,11 +2316,15 @@ function extractRuntimeEmits( hasCallSignature = true } if (t.type === 'TSPropertySignature') { - if (t.key.type !== 'Identifier' || t.computed) { + if (t.key.type === 'Identifier' && !t.computed) { + emits.add(t.key.name) + hasProperty = true + } else if (t.key.type === 'StringLiteral' && !t.computed) { + emits.add(t.key.value) + hasProperty = true + } else { error(`defineEmits() type cannot use computed keys.`, t.key) } - emits.add(t.key.name) - hasProperty = true } } if (hasCallSignature && hasProperty) {