|
6 | 6 | * The decoded scopes information found in a source map.
|
7 | 7 | */
|
8 | 8 | export interface ScopeInfo {
|
| 9 | + /** |
| 10 | + * The length of {@linkcode scopes} must match the length of "sources" in the source map JSON. Each entry describes the scope tree of the corresponding source file. |
| 11 | + */ |
9 | 12 | scopes: (OriginalScope | null)[];
|
| 13 | + |
| 14 | + /** |
| 15 | + * The range tree of the generated bundle. Multiple top-level ranges are allowed but must not overlap source position wise. |
| 16 | + */ |
10 | 17 | ranges: GeneratedRange[];
|
11 | 18 | }
|
12 | 19 |
|
13 | 20 | /**
|
14 | 21 | * A scope in the authored source.
|
15 | 22 | */
|
16 | 23 | export interface OriginalScope {
|
| 24 | + /** The beginning of this scope (inclusive). */ |
17 | 25 | start: Position;
|
| 26 | + |
| 27 | + /** The end of this scope (exclusive) */ |
18 | 28 | end: Position;
|
19 | 29 |
|
20 | 30 | /**
|
@@ -42,15 +52,28 @@ export interface OriginalScope {
|
42 | 52 | */
|
43 | 53 | variables: string[];
|
44 | 54 |
|
| 55 | + /** |
| 56 | + * The child scopes. When manually building scopes, {@linkcode children} must be sorted, not |
| 57 | + * overlap each other and be contained within [start, end). |
| 58 | + */ |
45 | 59 | children: OriginalScope[];
|
| 60 | + |
| 61 | + /** The parent scope or `undefined` for top-level scopes. */ |
46 | 62 | parent?: OriginalScope;
|
47 | 63 | }
|
48 | 64 |
|
49 | 65 | /**
|
50 |
| - * A range (can be a scope) in the generated JavaScript. |
| 66 | + * A range (can be a scope) in the generated JavaScript/WASM. |
| 67 | + * |
| 68 | + * The name "range" was chosen deliberately as a GeneratedRange does not necessarily |
| 69 | + * correspond to a lexical JavaScript scope. E.g. inlining, or concatenating multiple |
| 70 | + * bundles can result in generated ranges that are not lexical scopes. |
51 | 71 | */
|
52 | 72 | export interface GeneratedRange {
|
| 73 | + /** The beginning of this range (inclusive) */ |
53 | 74 | start: Position;
|
| 75 | + |
| 76 | + /** The end of this range (exclusive) */ |
54 | 77 | end: Position;
|
55 | 78 |
|
56 | 79 | /**
|
@@ -83,7 +106,13 @@ export interface GeneratedRange {
|
83 | 106 | */
|
84 | 107 | values: Binding[];
|
85 | 108 |
|
| 109 | + /** |
| 110 | + * The child ranges. When manually building ranges, {@linkcode children} must be sorted, |
| 111 | + * not overlap each other and be contained within [start, end). |
| 112 | + */ |
86 | 113 | children: GeneratedRange[];
|
| 114 | + |
| 115 | + /** The parent range or `undefined` for top-level ranges. */ |
87 | 116 | parent?: GeneratedRange;
|
88 | 117 | }
|
89 | 118 |
|
@@ -111,15 +140,28 @@ export interface SubRangeBinding {
|
111 | 140 | to: Position;
|
112 | 141 | }
|
113 | 142 |
|
| 143 | +/** |
| 144 | + * A position with 0-based line and column numbers. |
| 145 | + * |
| 146 | + * A {@linkcode Position} object by itself does not imply a position in original source |
| 147 | + * or generated code. It is used in both and normally it is clear from context. |
| 148 | + */ |
114 | 149 | export interface Position {
|
115 | 150 | line: number;
|
116 | 151 | column: number;
|
117 | 152 | }
|
118 | 153 |
|
| 154 | +/** |
| 155 | + * A position with 0-based line and column numbers in a specific original source file. |
| 156 | + */ |
119 | 157 | export interface OriginalPosition extends Position {
|
| 158 | + /** The 0-based index into "sources" in the source map. Or into {@linkcode ScopeInfo.scopes}. */ |
120 | 159 | sourceIndex: number;
|
121 | 160 | }
|
122 | 161 |
|
| 162 | +/** |
| 163 | + * A standard source map json object as per https://tc39.es/ecma426. |
| 164 | + */ |
123 | 165 | export interface SourceMapJson {
|
124 | 166 | version: 3;
|
125 | 167 | sources: (string | null)[];
|
|
0 commit comments