diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index 2ff89f5f..4164124a 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -746,10 +746,111 @@ return { a, b, c, d, x } }" `; +exports[`SFC compile @@ -64,7 +62,6 @@ const bar = 1 test('defineEmit() (deprecated)', () => { const { content, bindings } = compile(` `) @@ -84,7 +81,6 @@ const myEmit = defineEmit(['foo', 'bar']) test('defineEmits()', () => { const { content, bindings } = compile(` `) @@ -104,7 +100,6 @@ const myEmit = defineEmits(['foo', 'bar']) test('defineExpose()', () => { const { content } = compile(` `) @@ -170,7 +165,7 @@ defineExpose({ foo: 123 }) test('should allow defineProps/Emit at the start of imports', () => { assertCode( compile(` @@ -494,7 +488,6 @@ defineExpose({ foo: 123 }) test('defineProps/Emit w/ runtime options', () => { const { content } = compile(` @@ -509,7 +502,6 @@ const emit = defineEmits(['a', 'b']) test('defineProps w/ type', () => { const { content, bindings } = compile(` `) @@ -713,7 +704,6 @@ const emit = defineEmits(['a', 'b']) expect(() => compile(` `) @@ -724,7 +714,6 @@ const emit = defineEmits(['a', 'b']) const type = `{(e: 'foo' | 'bar'): void; (e: 'baz', id: number): void;}` const { content } = compile(` `) @@ -734,6 +723,78 @@ const emit = defineEmits(['a', 'b']) `emits: ["foo", "bar", "baz"] as unknown as undefined` ) }) + + test('defineEmits w/ type (interface)', () => { + const { content } = compile(` + + `) + assertCode(content) + expect(content).toMatch(`emit: ({ (e: 'foo' | 'bar'): void }),`) + expect(content).toMatch(`emits: ["foo", "bar"] as unknown as undefined`) + }) + + test('defineEmits w/ type (exported interface)', () => { + const { content } = compile(` + + `) + assertCode(content) + expect(content).toMatch(`emit: ({ (e: 'foo' | 'bar'): void }),`) + expect(content).toMatch(`emits: ["foo", "bar"] as unknown as undefined`) + }) + + test('defineEmits w/ type (type alias)', () => { + const { content } = compile(` + + `) + assertCode(content) + expect(content).toMatch(`emit: ({ (e: 'foo' | 'bar'): void }),`) + expect(content).toMatch(`emits: ["foo", "bar"] as unknown as undefined`) + }) + + test('defineEmits w/ type (exported type alias)', () => { + const { content } = compile(` + + `) + assertCode(content) + expect(content).toMatch(`emit: ({ (e: 'foo' | 'bar'): void }),`) + expect(content).toMatch(`emits: ["foo", "bar"] as unknown as undefined`) + }) + + test('defineEmits w/ type (referenced function type)', () => { + const { content } = compile(` + + `) + assertCode(content) + expect(content).toMatch(`emit: ((e: 'foo' | 'bar') => void),`) + expect(content).toMatch(`emits: ["foo", "bar"] as unknown as undefined`) + }) + + test('defineEmits w/ type (referenced exported function type)', () => { + const { content } = compile(` + + `) + assertCode(content) + expect(content).toMatch(`emit: ((e: 'foo' | 'bar') => void),`) + expect(content).toMatch(`emits: ["foo", "bar"] as unknown as undefined`) + }) }) describe('async/await detection', () => { @@ -1052,7 +1113,6 @@ const emit = defineEmits(['a', 'b']) expect(() => { compile(``) }).toThrow(`cannot accept both type and non-type arguments`) @@ -1061,7 +1121,6 @@ const emit = defineEmits(['a', 'b']) test('defineProps/Emit() referencing local var', () => { expect(() => compile(``) @@ -1083,7 +1141,6 @@ const emit = defineEmits(['a', 'b']) test('defineProps/Emit() referencing ref declarations', () => { expect(() => compile(`