Repository navigation
Expand file tree
/
Copy pathlog.js
More file actions
67 lines (62 loc) · 1.77 KB
/
Copy pathlog.js
File metadata and controls
67 lines (62 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { isFunction, type } from './base'
import { getStackByFiberInDevAndProd } from './componentError'
const isDev = process.env.NODE_ENV !== 'production'
export function warn (msg, location, e) {
const condition = mpxGlobal.__mpx?.config.ignoreWarning
if (isDev && !e) {
e = new Error('Mpx runtime warn')
}
let ignore = false
if (typeof condition === 'boolean') {
ignore = condition
} else if (typeof condition === 'string') {
ignore = msg.indexOf(condition) !== -1
} else if (typeof condition === 'function') {
ignore = condition(msg, location, e)
} else if (condition instanceof RegExp) {
ignore = condition.test(msg)
}
if (!ignore) {
const warnHandler = mpxGlobal.__mpx?.config.warnHandler
if (isFunction(warnHandler)) {
warnHandler(msg, location, e)
} else {
log('warn', msg, location, e)
}
}
}
export function error (msg, location, e) {
const workInProgress = global.workInProgress
let stack = ''
if (workInProgress) {
stack = getStackByFiberInDevAndProd(workInProgress)
}
const errorHandler = mpxGlobal.__mpx?.config.errorHandler
if (!e) {
e = new Error(stack ? `${msg}\n Error Component Stack:${stack}` : msg)
} else {
if (stack) {
if (type(e) === 'Error') {
e.message += `\n Error Component Stack:${stack}`
}
if (type(e) === 'String') {
e += `\n Error Component Stack:${stack}`
}
}
}
if (isFunction(errorHandler)) {
errorHandler(msg, location, e)
} else {
log('error', msg, location, e)
}
}
function log (type, msg, location, e) {
if (isDev) {
let header = `[Mpx runtime ${type}]: `
if (location) {
header = `[Mpx runtime ${type} at ${location}]: `
}
console[type](header + msg)
if (e) console[type](e)
}
}