diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap index f85b2db9b9f..5b11ae5c1a5 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap @@ -80,10 +80,11 @@ exports[`sfc props transform default values w/ type declaration, prod mode 1`] = export default /*#__PURE__*/_defineComponent({ props: { - foo: { type: Number, default: 1 }, - bar: { type: Object, default: () => {} }, - baz: { type: null }, - bool: { type: Boolean } + foo: { default: 1 }, + bar: { default: () => {} }, + baz: null, + boola: { type: Boolean }, + boolb: { type: [Boolean, Number] } }, setup(__props: any) { diff --git a/packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts b/packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts index e8fc9039f55..5d406608288 100644 --- a/packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts @@ -83,7 +83,7 @@ describe('sfc props transform', () => { const { content } = compile( ` `, { isProd: true } @@ -91,10 +91,11 @@ describe('sfc props transform', () => { // literals can be used as-is, non-literals are always returned from a // function expect(content).toMatch(`props: { - foo: { type: Number, default: 1 }, - bar: { type: Object, default: () => {} }, - baz: { type: null }, - bool: { type: Boolean } + foo: { default: 1 }, + bar: { default: () => {} }, + baz: null, + boola: { type: Boolean }, + boolb: { type: [Boolean, Number] } }`) assertCode(content) }) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 9a4ac1979f7..dcaf3848caa 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -685,21 +685,23 @@ export function compileScript( } } + const { type, required } = props[key] if (!isProd) { - const { type, required } = props[key] return `${key}: { type: ${toRuntimeTypeString( type )}, required: ${required}${ defaultString ? `, ${defaultString}` : `` } }` - } else { - const { type } = props[key] - // production: checks are useless + } else if (type.indexOf('Boolean') > -1) { + // production: if boolean exists, should keep the type. return `${key}: { type: ${toRuntimeTypeString( type )}${ defaultString ? `, ${defaultString}` : `` } }` + } else { + // production: checks are useless + return `${key}: ${defaultString ? `{ ${defaultString} }` : 'null'}` } }) .join(',\n ')}\n }`