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

Function warn

packages/runtime-core/src/warning.ts:35–79  ·  view source on GitHub ↗
(msg: string, ...args: any[])

Source from the content-addressed store, hash-verified

33let isWarning = false
34
35export function warn(msg: string, ...args: any[]): void {
36 if (isWarning) return
37 isWarning = true
38
39 // avoid props formatting or warn handler tracking deps that might be mutated
40 // during patch, leading to infinite recursion.
41 pauseTracking()
42
43 const instance = stack.length ? stack[stack.length - 1].component : null
44 const appWarnHandler = instance && instance.appContext.config.warnHandler
45 const trace = getComponentTrace()
46
47 if (appWarnHandler) {
48 callWithErrorHandling(
49 appWarnHandler,
50 instance,
51 ErrorCodes.APP_WARN_HANDLER,
52 [
53 // eslint-disable-next-line no-restricted-syntax
54 msg + args.map(a => a.toString?.() ?? JSON.stringify(a)).join(''),
55 instance && instance.proxy,
56 trace
57 .map(
58 ({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`,
59 )
60 .join('\n'),
61 trace,
62 ],
63 )
64 } else {
65 const warnArgs = [`[Vue warn]: ${msg}`, ...args]
66 if (
67 trace.length &&
68 // avoid spamming console during tests
69 !__TEST__
70 ) {
71 /* v8 ignore next 2 */
72 warnArgs.push(`\n`, ...formatTrace(trace))
73 }
74 console.warn(...warnArgs)
75 }
76
77 resetTracking()
78 isWarning = false
79}
80
81export function getComponentTrace(): ComponentTraceStack {
82 let currentVNode: VNode | null = stack[stack.length - 1]

Callers 15

runtime.tsFile · 0.90
ssrRenderListFunction · 0.90
setFunction · 0.90
getFunction · 0.90
normalizeContainerFunction · 0.90
constructorMethod · 0.90
resolveMethod · 0.90
_mountMethod · 0.90
useHostFunction · 0.90
nodeOps.tsFile · 0.90
setSelectedFunction · 0.90
sanitizeEventValueFunction · 0.90

Calls 10

pauseTrackingFunction · 0.90
callWithErrorHandlingFunction · 0.90
formatComponentNameFunction · 0.90
resetTrackingFunction · 0.90
getComponentTraceFunction · 0.85
formatTraceFunction · 0.85
mapMethod · 0.80
toStringMethod · 0.80
warnMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected