( ctx: ScriptCompileContext, node: Node, declId?: LVal, )
| 93 | } |
| 94 | |
| 95 | function processWithDefaults( |
| 96 | ctx: ScriptCompileContext, |
| 97 | node: Node, |
| 98 | declId?: LVal, |
| 99 | ): boolean { |
| 100 | if (!isCallOf(node, WITH_DEFAULTS)) { |
| 101 | return false |
| 102 | } |
| 103 | if ( |
| 104 | !processDefineProps( |
| 105 | ctx, |
| 106 | node.arguments[0], |
| 107 | declId, |
| 108 | true /* isWithDefaults */, |
| 109 | ) |
| 110 | ) { |
| 111 | ctx.error( |
| 112 | `${WITH_DEFAULTS}' first argument must be a ${DEFINE_PROPS} call.`, |
| 113 | node.arguments[0] || node, |
| 114 | ) |
| 115 | } |
| 116 | |
| 117 | if (ctx.propsRuntimeDecl) { |
| 118 | ctx.error( |
| 119 | `${WITH_DEFAULTS} can only be used with type-based ` + |
| 120 | `${DEFINE_PROPS} declaration.`, |
| 121 | node, |
| 122 | ) |
| 123 | } |
| 124 | if (declId && declId.type === 'ObjectPattern') { |
| 125 | ctx.warn( |
| 126 | `${WITH_DEFAULTS}() is unnecessary when using destructure with ${DEFINE_PROPS}().\n` + |
| 127 | `Reactive destructure will be disabled when using withDefaults().\n` + |
| 128 | `Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(...). `, |
| 129 | node.callee, |
| 130 | ) |
| 131 | } |
| 132 | ctx.propsRuntimeDefaults = node.arguments[1] |
| 133 | if (!ctx.propsRuntimeDefaults) { |
| 134 | ctx.error(`The 2nd argument of ${WITH_DEFAULTS} is required.`, node) |
| 135 | } |
| 136 | ctx.propsCall = node |
| 137 | |
| 138 | return true |
| 139 | } |
| 140 | |
| 141 | export function genRuntimeProps(ctx: ScriptCompileContext): string | undefined { |
| 142 | let propsDecls: undefined | string |
no test coverage detected