MCPcopy
hub / github.com/vuejs/core / processDefineProps

Function processDefineProps

packages/compiler-sfc/src/script/defineProps.ts:47–93  ·  view source on GitHub ↗
(
  ctx: ScriptCompileContext,
  node: Node,
  declId?: LVal,
  isWithDefaults = false,
)

Source from the content-addressed store, hash-verified

45>
46
47export 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
95function processWithDefaults(
96 ctx: ScriptCompileContext,

Callers 2

compileScriptFunction · 0.90
processWithDefaultsFunction · 0.85

Calls 5

isCallOfFunction · 0.90
processPropsDestructureFunction · 0.90
processWithDefaultsFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected