( ctx: ScriptCompileContext, node: Node, declId?: LVal, isWithDefaults = false, )
| 45 | > |
| 46 | |
| 47 | export function processDefineProps( |
| 48 | ctx: ScriptCompileContext, |
| 49 | node: Node, |
| 50 | declId?: LVal, |
| 51 | isWithDefaults = false, |
| 52 | ): boolean { |
| 53 | if (!isCallOf(node, DEFINE_PROPS)) { |
| 54 | return processWithDefaults(ctx, node, declId) |
| 55 | } |
| 56 | |
| 57 | if (ctx.hasDefinePropsCall) { |
| 58 | ctx.error(`duplicate ${DEFINE_PROPS}() call`, node) |
| 59 | } |
| 60 | ctx.hasDefinePropsCall = true |
| 61 | ctx.propsRuntimeDecl = node.arguments[0] |
| 62 | |
| 63 | // register bindings |
| 64 | if (ctx.propsRuntimeDecl) { |
| 65 | for (const key of getObjectOrArrayExpressionKeys(ctx.propsRuntimeDecl)) { |
| 66 | if (!(key in ctx.bindingMetadata)) { |
| 67 | ctx.bindingMetadata[key] = BindingTypes.PROPS |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // call has type parameters - infer runtime types from it |
| 73 | if (node.typeParameters) { |
| 74 | if (ctx.propsRuntimeDecl) { |
| 75 | ctx.error( |
| 76 | `${DEFINE_PROPS}() cannot accept both type and non-type arguments ` + |
| 77 | `at the same time. Use one or the other.`, |
| 78 | node, |
| 79 | ) |
| 80 | } |
| 81 | ctx.propsTypeDecl = node.typeParameters.params[0] |
| 82 | } |
| 83 | |
| 84 | // handle props destructure |
| 85 | if (!isWithDefaults && declId && declId.type === 'ObjectPattern') { |
| 86 | processPropsDestructure(ctx, declId) |
| 87 | } |
| 88 | |
| 89 | ctx.propsCall = node |
| 90 | ctx.propsDecl = declId |
| 91 | |
| 92 | return true |
| 93 | } |
| 94 | |
| 95 | function processWithDefaults( |
| 96 | ctx: ScriptCompileContext, |
no test coverage detected