-
Notifications
You must be signed in to change notification settings - Fork 47.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This uses a reverse linked list in DEV-only to keep track of where we're currently executing.
- Loading branch information
1 parent
86715ef
commit ccc880a
Showing
2 changed files
with
166 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import { | ||
describeBuiltInComponentFrame, | ||
describeFunctionComponentFrame, | ||
describeClassComponentFrame, | ||
} from 'shared/ReactComponentStackFrame'; | ||
|
||
// DEV-only reverse linked list representing the current component stack | ||
type BuiltInComponentStackNode = { | ||
tag: 0, | ||
parent: null | ComponentStackNode, | ||
type: string, | ||
}; | ||
type FunctionComponentStackNode = { | ||
tag: 1, | ||
parent: null | ComponentStackNode, | ||
type: Function, | ||
}; | ||
type ClassComponentStackNode = { | ||
tag: 2, | ||
parent: null | ComponentStackNode, | ||
type: Function, | ||
}; | ||
export type ComponentStackNode = | ||
| BuiltInComponentStackNode | ||
| FunctionComponentStackNode | ||
| ClassComponentStackNode; | ||
|
||
export function getStackByComponentStackNode( | ||
componentStack: ComponentStackNode, | ||
): string { | ||
try { | ||
let info = ''; | ||
let node = componentStack; | ||
do { | ||
switch (node.tag) { | ||
case 0: | ||
info += describeBuiltInComponentFrame(node.type, null, null); | ||
break; | ||
case 1: | ||
info += describeFunctionComponentFrame(node.type, null, null); | ||
break; | ||
case 2: | ||
info += describeClassComponentFrame(node.type, null, null); | ||
break; | ||
} | ||
node = node.parent; | ||
} while (node); | ||
return info; | ||
} catch (x) { | ||
return '\nError generating stack: ' + x.message + '\n' + x.stack; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters