diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index cf681ef11..7b225dccf 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -1,5 +1,92 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`SFC compile `) + assertCode(code) + expect(code).toMatch(`string: { type: String, required: true }`) + expect(code).toMatch(`number: { type: Number, required: true }`) + expect(code).toMatch(`boolean: { type: Boolean, required: true }`) + expect(code).toMatch(`object: { type: Object, required: true }`) + expect(code).toMatch(`objectLiteral: { type: Object, required: true }`) + expect(code).toMatch(`fn: { type: Function, required: true }`) + expect(code).toMatch(`functionRef: { type: Function, required: true }`) + expect(code).toMatch(`objectRef: { type: Object, required: true }`) + expect(code).toMatch(`array: { type: Array, required: true }`) + expect(code).toMatch(`arrayRef: { type: Array, required: true }`) + expect(code).toMatch(`tuple: { type: Array, required: true }`) + expect(code).toMatch(`set: { type: Set, required: true }`) + expect(code).toMatch(`literal: { type: String, required: true }`) + expect(code).toMatch(`optional: { type: null, required: false }`) + expect(code).toMatch(`recordRef: { type: Object, required: true }`) + expect(code).toMatch(`interface: { type: Object, required: true }`) + expect(code).toMatch(`alias: { type: Array, required: true }`) + expect(code).toMatch(`union: { type: [String, Number], required: true }`) + expect(code).toMatch( + `literalUnion: { type: [String, String], required: true }` + ) + expect(code).toMatch( + `literalUnionMixed: { type: [String, Number, Boolean], required: true }` + ) + expect(code).toMatch(`intersection: { type: Object, required: true }`) + }) + + test('extract emits', () => { + const { code } = compile(` + + `) + assertCode(code) + expect(code).toMatch(`declare function __emit__(e: 'foo' | 'bar'): void`) + expect(code).toMatch( + `declare function __emit__(e: 'baz', id: number): void` + ) + expect(code).toMatch( + `emits: ["foo", "bar", "baz"] as unknown as undefined` + ) + }) }) describe('errors', () => { diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index f358ddb99..42ee651c2 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -420,7 +420,7 @@ export function compileScriptSetup( } } - // check default export to make sure it doesn't reference setup scope + // 4. check default export to make sure it doesn't reference setup scope // variables if (needDefaultExportRefCheck) { checkDefaultExport( @@ -433,7 +433,7 @@ export function compileScriptSetup( ) } - // remove non-script content + // 5. remove non-script content if (script) { if (startOffset < scriptStartOffset!) { //