From 186d10ae985bdf6518bc35fea163cb0e4a4e7b1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Mon, 14 Nov 2022 09:15:17 +0800 Subject: [PATCH] refactor(compiler-sfc): drop Function prop type when no static default value (#7125) --- .../__snapshots__/compileScript.spec.ts.snap | 23 ++++++++++++++ .../__tests__/compileScript.spec.ts | 30 +++++++++++++++++++ packages/compiler-sfc/src/compileScript.ts | 11 +++++-- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index b167dea7026..ae42d6f87b9 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -1784,6 +1784,29 @@ const props = __props as { foo: string, bar?: number, baz: boolean, qux(): numbe +return { props } +} + +})" +`; + +exports[`SFC compile + `, + { isProd: true } + ) + assertCode(content) + expect(content).toMatch(`const props = __props`) + + // foo has no default value, the Function can be dropped + expect(content).toMatch(`foo: null`) + expect(content).toMatch(`bar: { type: Boolean }`) + expect(content).toMatch( + `baz: { type: [Boolean, Function], default: true }` + ) + expect(content).toMatch(`qux: { default: 'hi' }`) + }) + test('withDefaults (dynamic)', () => { const { content } = compile(`