feat(runtime-core): config.performance tracing support

This commit is contained in:
Evan You
2020-04-01 21:36:50 -04:00
parent a022b63605
commit e93e426bfa
5 changed files with 126 additions and 24 deletions

View File

@@ -1,5 +1,10 @@
import { VNode } from './vnode'
import { Data, ComponentInternalInstance, Component } from './component'
import {
Data,
ComponentInternalInstance,
Component,
formatComponentName
} from './component'
import { isString, isFunction } from '@vue/shared'
import { toRaw, isRef, pauseTracking, resetTracking } from '@vue/reactivity'
import { callWithErrorHandling, ErrorCodes } from './errorHandling'
@@ -43,7 +48,10 @@ export function warn(msg: string, ...args: any[]) {
msg + args.join(''),
instance && instance.proxy,
trace
.map(({ vnode }) => `at <${formatComponentName(vnode)}>`)
.map(
({ vnode }) =>
`at <${formatComponentName(vnode.type as Component)}>`
)
.join('\n'),
trace
]
@@ -111,24 +119,6 @@ function formatTraceEntry({ vnode, recurseCount }: TraceEntry): any[] {
: [open + close, rootLabel]
}
const classifyRE = /(?:^|[-_])(\w)/g
const classify = (str: string): string =>
str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '')
function formatComponentName(vnode: ComponentVNode, file?: string): string {
const Component = vnode.type as Component
let name = isFunction(Component)
? Component.displayName || Component.name
: Component.name
if (!name && file) {
const match = file.match(/([^/\\]+)\.vue$/)
if (match) {
name = match[1]
}
}
return name ? classify(name) : 'Anonymous'
}
function formatProps(props: Data): any[] {
const res: any[] = []
const keys = Object.keys(props)