forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack-frame.js
More file actions
110 lines (96 loc) · 2.92 KB
/
stack-frame.js
File metadata and controls
110 lines (96 loc) · 2.92 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
//@flow
/** A container holding a script line. */
class ScriptLine {
/** The line number of this line of source. */
lineNumber: number;
/** The content (or value) of this line of source. */
content: string;
/** Whether or not this line should be highlighted. Particularly useful for error reporting with context. */
highlight: boolean;
constructor(lineNumber: number, content: string, highlight: boolean = false) {
this.lineNumber = lineNumber;
this.content = content;
this.highlight = highlight;
}
}
/**
* A representation of a stack frame.
*/
class StackFrame {
functionName: string | null;
fileName: string | null;
lineNumber: number | null;
columnNumber: number | null;
_originalFunctionName: string | null;
_originalFileName: string | null;
_originalLineNumber: number | null;
_originalColumnNumber: number | null;
_scriptCode: ScriptLine[] | null;
_originalScriptCode: ScriptLine[] | null;
constructor(
functionName: string | null = null,
fileName: string | null = null,
lineNumber: number | null = null,
columnNumber: number | null = null,
scriptCode: ScriptLine[] | null = null,
sourceFunctionName: string | null = null,
sourceFileName: string | null = null,
sourceLineNumber: number | null = null,
sourceColumnNumber: number | null = null,
sourceScriptCode: ScriptLine[] | null = null
) {
this.functionName = functionName;
this.fileName = fileName;
this.lineNumber = lineNumber;
this.columnNumber = columnNumber;
this._originalFunctionName = sourceFunctionName;
this._originalFileName = sourceFileName;
this._originalLineNumber = sourceLineNumber;
this._originalColumnNumber = sourceColumnNumber;
this._scriptCode = scriptCode;
this._originalScriptCode = sourceScriptCode;
}
/**
* Returns the name of this function.
*/
getFunctionName(): string | null {
return this.functionName;
}
/**
* Returns the source of the frame.
* This contains the file name, line number, and column number when available.
*/
getSource(): string {
let str = '';
if (this.fileName != null) {
str += this.fileName + ':';
}
if (this.lineNumber != null) {
str += this.lineNumber + ':';
}
if (this.columnNumber != null) {
str += this.columnNumber + ':';
}
return str.slice(0, -1);
}
/**
* Returns a pretty version of this stack frame.
*/
toString(): string {
const f = this.getFunctionName();
if (f == null) {
return this.getSource();
}
return `${f} (${this.getSource()})`;
}
}
export { StackFrame, ScriptLine };
export default StackFrame;