forked from react/create-react-app
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproxyConsole.js
More file actions
42 lines (36 loc) · 1.03 KB
/
Copy pathproxyConsole.js
File metadata and controls
42 lines (36 loc) · 1.03 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
/* @flow */
type ReactFrame = {
fileName: string | null,
lineNumber: number | null,
functionName: string | null,
};
const ReactFrameStack: Array<ReactFrame[]> = [];
export type { ReactFrame };
const registerReactStack = () => {
// $FlowFixMe
console.stack = frames => ReactFrameStack.push(frames);
// $FlowFixMe
console.stackEnd = frames => ReactFrameStack.pop();
};
const unregisterReactStack = () => {
// $FlowFixMe
console.stack = undefined;
// $FlowFixMe
console.stackEnd = undefined;
};
type ConsoleProxyCallback = (
message: string,
frames: ReactFrame[] | void
) => void;
const permanentRegister = function proxyConsole(
type: string,
callback: ConsoleProxyCallback
) {
const orig = console[type];
console[type] = function __stack_frame_overlay_proxy_console__() {
const message = [].slice.call(arguments).join(' ');
callback(message, ReactFrameStack[ReactFrameStack.length - 1]);
return orig.apply(this, arguments);
};
};
export { permanentRegister, registerReactStack, unregisterReactStack };