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

Function processDefineOptions

packages/compiler-sfc/src/script/defineOptions.ts:12–87  ·  view source on GitHub ↗
(
  ctx: ScriptCompileContext,
  node: Node,
)

Source from the content-addressed store, hash-verified

10export const DEFINE_OPTIONS = 'defineOptions'
11
12export function processDefineOptions(
13 ctx: ScriptCompileContext,
14 node: Node,
15): boolean {
16 if (!isCallOf(node, DEFINE_OPTIONS)) {
17 return false
18 }
19 if (ctx.hasDefineOptionsCall) {
20 ctx.error(`duplicate ${DEFINE_OPTIONS}() call`, node)
21 }
22 if (node.typeParameters) {
23 ctx.error(`${DEFINE_OPTIONS}() cannot accept type arguments`, node)
24 }
25 if (!node.arguments[0]) return true
26
27 ctx.hasDefineOptionsCall = true
28 ctx.optionsRuntimeDecl = unwrapTSNode(node.arguments[0])
29
30 let propsOption = undefined
31 let emitsOption = undefined
32 let exposeOption = undefined
33 let slotsOption = undefined
34 if (ctx.optionsRuntimeDecl.type === 'ObjectExpression') {
35 for (const prop of ctx.optionsRuntimeDecl.properties) {
36 if (
37 (prop.type === 'ObjectProperty' || prop.type === 'ObjectMethod') &&
38 prop.key.type === 'Identifier'
39 ) {
40 switch (prop.key.name) {
41 case 'props':
42 propsOption = prop
43 break
44
45 case 'emits':
46 emitsOption = prop
47 break
48
49 case 'expose':
50 exposeOption = prop
51 break
52
53 case 'slots':
54 slotsOption = prop
55 break
56 }
57 }
58 }
59 }
60
61 if (propsOption) {
62 ctx.error(
63 `${DEFINE_OPTIONS}() cannot be used to declare props. Use ${DEFINE_PROPS}() instead.`,
64 propsOption,
65 )
66 }
67 if (emitsOption) {
68 ctx.error(
69 `${DEFINE_OPTIONS}() cannot be used to declare emits. Use ${DEFINE_EMITS}() instead.`,

Callers 1

compileScriptFunction · 0.90

Calls 3

isCallOfFunction · 0.90
unwrapTSNodeFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected