Skip to content

Commit 78023ec

Browse files
webfansplzyyx990803
authored andcommitted
refactor(compile-sfc): extract the checkStaticDefaults method
1 parent 5f1c675 commit 78023ec

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

packages/compiler-sfc/src/compileScript.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -513,22 +513,27 @@ export function compileScript(
513513
)
514514
}
515515

516-
function genRuntimeProps(props: Record<string, PropTypeData>) {
517-
const keys = Object.keys(props)
518-
if (!keys.length) {
519-
return ``
520-
}
521-
522-
// check defaults. If the default object is an object literal with only
523-
// static properties, we can directly generate more optimzied default
524-
// decalrations. Otherwise we will have to fallback to runtime merging.
525-
const hasStaticDefaults =
516+
/**
517+
* check defaults. If the default object is an object literal with only
518+
* static properties, we can directly generate more optimzied default
519+
* decalrations. Otherwise we will have to fallback to runtime merging.
520+
*/
521+
function checkStaticDefaults() {
522+
return (
526523
propsRuntimeDefaults &&
527524
propsRuntimeDefaults.type === 'ObjectExpression' &&
528525
propsRuntimeDefaults.properties.every(
529526
node => node.type === 'ObjectProperty' && !node.computed
530527
)
528+
)
529+
}
531530

531+
function genRuntimeProps(props: Record<string, PropTypeData>) {
532+
const keys = Object.keys(props)
533+
if (!keys.length) {
534+
return ``
535+
}
536+
const hasStaticDefaults = checkStaticDefaults()
532537
let propsDecls = `{
533538
${keys
534539
.map(key => {
@@ -580,12 +585,7 @@ export function compileScript(
580585
if (!keys.length) {
581586
return ``
582587
}
583-
const hasStaticDefaults =
584-
propsRuntimeDefaults &&
585-
propsRuntimeDefaults.type === 'ObjectExpression' &&
586-
propsRuntimeDefaults.properties.every(
587-
node => node.type === 'ObjectProperty' && !node.computed
588-
)
588+
const hasStaticDefaults = checkStaticDefaults()
589589
keys.map(key => {
590590
if (hasStaticDefaults) {
591591
const prop = (propsRuntimeDefaults as ObjectExpression).properties.find(

0 commit comments

Comments
 (0)