devtools-tracing 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/generate.ts +32 -26
- package/index.ts +2 -1
- package/lib/extension-api/ExtensionAPI.d.ts +357 -0
- package/lib/front_end/models/bindings/CSSWorkspaceBinding.ts +318 -0
- package/lib/front_end/models/bindings/CompilerScriptMapping.ts +536 -0
- package/lib/front_end/models/bindings/ContentProviderBasedProject.ts +187 -0
- package/lib/front_end/models/bindings/DebuggerLanguagePlugins.ts +1197 -0
- package/lib/front_end/models/bindings/DebuggerWorkspaceBinding.ts +733 -0
- package/lib/front_end/models/bindings/DefaultScriptMapping.ts +141 -0
- package/lib/front_end/models/bindings/FileUtils.ts +228 -0
- package/lib/front_end/models/bindings/LiveLocation.ts +81 -0
- package/lib/front_end/models/bindings/NetworkProject.ts +157 -0
- package/lib/front_end/models/bindings/PresentationConsoleMessageHelper.ts +312 -0
- package/lib/front_end/models/bindings/ResourceMapping.ts +539 -0
- package/lib/front_end/models/bindings/ResourceScriptMapping.ts +491 -0
- package/lib/front_end/models/bindings/ResourceUtils.ts +103 -0
- package/lib/front_end/models/bindings/SASSSourceMapping.ts +222 -0
- package/lib/front_end/models/bindings/StylesSourceMapping.ts +316 -0
- package/lib/front_end/models/bindings/TempFile.ts +67 -0
- package/lib/front_end/models/bindings/bindings.ts +39 -0
- package/lib/front_end/models/source_map_scopes/NamesResolver.ts +765 -0
- package/lib/front_end/models/source_map_scopes/ScopeChainModel.ts +84 -0
- package/lib/front_end/models/source_map_scopes/source_map_scopes.ts +11 -0
- package/lib/front_end/models/stack_trace/StackTrace.ts +53 -0
- package/lib/front_end/models/stack_trace/StackTraceImpl.ts +85 -0
- package/lib/front_end/models/stack_trace/StackTraceModel.ts +128 -0
- package/lib/front_end/models/stack_trace/Trie.ts +163 -0
- package/lib/front_end/models/stack_trace/stack_trace.ts +9 -0
- package/lib/front_end/models/stack_trace/stack_trace_impl.ts +13 -0
- package/lib/front_end/models/trace_source_maps_resolver/SourceMapsResolver.ts +240 -0
- package/lib/front_end/models/trace_source_maps_resolver/trace_source_maps_resolver.ts +5 -0
- package/lib/front_end/models/workspace/FileManager.ts +97 -0
- package/lib/front_end/models/workspace/IgnoreListManager.ts +628 -0
- package/lib/front_end/models/workspace/SearchConfig.ts +149 -0
- package/lib/front_end/models/workspace/UISourceCode.ts +698 -0
- package/lib/front_end/models/workspace/WorkspaceImpl.ts +339 -0
- package/lib/front_end/models/workspace/workspace.ts +17 -0
- package/lib/front_end/panels/timeline/TimelineUIUtils.ts +1029 -0
- package/lib/front_end/panels/timeline/extensions/ExtensionUI.ts +49 -0
- package/lib/front_end/panels/timeline/extensions/extensions.ts +9 -0
- package/lib/front_end/third_party/codemirror.next/LICENSE +21 -0
- package/lib/front_end/third_party/codemirror.next/README.chromium +30 -0
- package/lib/front_end/third_party/codemirror.next/bundle-tsconfig.json +24 -0
- package/lib/front_end/third_party/codemirror.next/bundle.ts +135 -0
- package/lib/front_end/third_party/codemirror.next/chunk/angular.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/angular.js.map +1 -0
- package/lib/front_end/third_party/codemirror.next/chunk/codemirror.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/codemirror.js.map +1 -0
- package/lib/front_end/third_party/codemirror.next/chunk/cpp.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/cpp.js.map +1 -0
- package/lib/front_end/third_party/codemirror.next/chunk/css.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/html.js +4 -0
- package/lib/front_end/third_party/codemirror.next/chunk/java.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/java.js.map +1 -0
- package/lib/front_end/third_party/codemirror.next/chunk/javascript.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/legacy.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/legacy.js.map +1 -0
- package/lib/front_end/third_party/codemirror.next/chunk/less.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/less.js.map +1 -0
- package/lib/front_end/third_party/codemirror.next/chunk/markdown.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/markdown.js.map +1 -0
- package/lib/front_end/third_party/codemirror.next/chunk/php.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/php.js.map +1 -0
- package/lib/front_end/third_party/codemirror.next/chunk/python.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/python.js.map +1 -0
- package/lib/front_end/third_party/codemirror.next/chunk/sass.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/sass.js.map +1 -0
- package/lib/front_end/third_party/codemirror.next/chunk/svelte.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/svelte.js.map +1 -0
- package/lib/front_end/third_party/codemirror.next/chunk/vue.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/vue.js.map +1 -0
- package/lib/front_end/third_party/codemirror.next/chunk/wast.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/wast.js.map +1 -0
- package/lib/front_end/third_party/codemirror.next/chunk/xml.js +2 -0
- package/lib/front_end/third_party/codemirror.next/chunk/xml.js.map +1 -0
- package/lib/front_end/third_party/codemirror.next/codemirror.next.d.ts +8057 -0
- package/lib/front_end/third_party/codemirror.next/codemirror.next.js +2 -0
- package/lib/front_end/third_party/codemirror.next/codemirror.next.js.map +1 -0
- package/lib/front_end/third_party/codemirror.next/package.json +43 -0
- package/lib/front_end/third_party/codemirror.next/rebuild.sh +6 -0
- package/lib/front_end/third_party/codemirror.next/rollup.config.mjs +49 -0
- package/lib/front_end/third_party/source-map-scopes-codec/LICENSE +26 -0
- package/lib/front_end/third_party/source-map-scopes-codec/README.chromium +31 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/CONTRIBUTING.md +33 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/LICENSE +26 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/README.md +64 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/builder/builder.d.ts +62 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/builder/builder.d.ts.map +1 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/builder/safe_builder.d.ts +37 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/builder/safe_builder.d.ts.map +1 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/decode/decode.d.ts +29 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/decode/decode.d.ts.map +1 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/encode/encode.d.ts +8 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/encode/encode.d.ts.map +1 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/mod.d.ts +6 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/mod.d.ts.map +1 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/deno.json +21 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/package.json +14 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/builder.js +196 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/builder.js.map +1 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/builder.ts +262 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/safe_builder.js +235 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/safe_builder.js.map +1 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/safe_builder.ts +359 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/codec.js +39 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/codec.js.map +1 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/codec.ts +53 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/decode/decode.js +438 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/decode/decode.js.map +1 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/decode/decode.ts +539 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encode.js +23 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encode.js.map +1 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encode.ts +35 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encoder.js +257 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encoder.js.map +1 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encoder.ts +348 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/mod.js +8 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/mod.js.map +1 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/mod.ts +20 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/scopes-tsconfig.json +8 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/scopes.d.ts +184 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/util.js +9 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/util.js.map +1 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/util.ts +12 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/vlq.js +82 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/vlq.js.map +1 -0
- package/lib/front_end/third_party/source-map-scopes-codec/package/src/vlq.ts +99 -0
- package/lib/front_end/third_party/source-map-scopes-codec/source-map-scopes-codec.ts +5 -0
- package/lib/front_end/ui/legacy/theme_support/ThemeSupport.ts +222 -0
- package/lib/front_end/ui/legacy/theme_support/theme_support.ts +5 -0
- package/package.json +11 -5
- package/patches/chrome-devtools-frontend+1.0.1533544.patch +1549 -20
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
// Copyright 2025 The Chromium Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
GeneratedRangeFlags,
|
|
7
|
+
type GeneratedRangeStartItem,
|
|
8
|
+
OriginalScopeFlags,
|
|
9
|
+
type OriginalScopeStartItem,
|
|
10
|
+
Tag,
|
|
11
|
+
} from "../codec.js";
|
|
12
|
+
import type {
|
|
13
|
+
GeneratedRange,
|
|
14
|
+
IndexSourceMapJson,
|
|
15
|
+
OriginalScope,
|
|
16
|
+
Position,
|
|
17
|
+
ScopeInfo,
|
|
18
|
+
SourceMap,
|
|
19
|
+
SourceMapJson,
|
|
20
|
+
SubRangeBinding,
|
|
21
|
+
} from "../scopes.d.ts";
|
|
22
|
+
import { TokenIterator } from "../vlq.js";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The mode decides how well-formed the encoded scopes have to be, to be accepted by the decoder.
|
|
26
|
+
*
|
|
27
|
+
* LAX is the default and is much more lenient. It's still best effort though and the decoder doesn't
|
|
28
|
+
* implement any error recovery: e.g. superfluous "start" items can lead to whole trees being omitted.
|
|
29
|
+
*
|
|
30
|
+
* STRICT mode will throw in the following situations:
|
|
31
|
+
*
|
|
32
|
+
* - Encountering ORIGINAL_SCOPE_END, or GENERATED_RANGE_END items that don't have matching *_START items.
|
|
33
|
+
* - Encountering ORIGINAL_SCOPE_VARIABLES items outside a surrounding scope START/END.
|
|
34
|
+
* - Encountering GENERATED_RANGE_BINDINGS items outside a surrounding range START/END.
|
|
35
|
+
* - Miss-matches between the number of variables in a scope vs the number of value expressions in the ranges.
|
|
36
|
+
* - Out-of-bound indices into the "names" array.
|
|
37
|
+
*/
|
|
38
|
+
export const enum DecodeMode {
|
|
39
|
+
STRICT = 1,
|
|
40
|
+
LAX = 2,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface DecodeOptions {
|
|
44
|
+
mode: DecodeMode;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Offsets `start` and `end` of all generated ranges by the specified amount.
|
|
48
|
+
* Intended to be used when decoding sections of index source maps one-by-one.
|
|
49
|
+
*
|
|
50
|
+
* Has no effect when passing a {@link IndexSourceMapJson} directly to {@link decode}.
|
|
51
|
+
*/
|
|
52
|
+
generatedOffset: Position;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const DEFAULT_DECODE_OPTIONS: DecodeOptions = {
|
|
56
|
+
mode: DecodeMode.LAX,
|
|
57
|
+
generatedOffset: { line: 0, column: 0 },
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export function decode(
|
|
61
|
+
sourceMap: SourceMap,
|
|
62
|
+
options: Partial<DecodeOptions> = DEFAULT_DECODE_OPTIONS,
|
|
63
|
+
): ScopeInfo {
|
|
64
|
+
const opts = { ...DEFAULT_DECODE_OPTIONS, ...options };
|
|
65
|
+
if ("sections" in sourceMap) {
|
|
66
|
+
return decodeIndexMap(sourceMap, {
|
|
67
|
+
...opts,
|
|
68
|
+
generatedOffset: { line: 0, column: 0 },
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return decodeMap(sourceMap, opts);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function decodeMap(
|
|
75
|
+
sourceMap: SourceMapJson,
|
|
76
|
+
options: DecodeOptions,
|
|
77
|
+
): ScopeInfo {
|
|
78
|
+
if (!sourceMap.scopes || !sourceMap.names) return { scopes: [], ranges: [] };
|
|
79
|
+
|
|
80
|
+
return new Decoder(sourceMap.scopes, sourceMap.names, options).decode();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function decodeIndexMap(
|
|
84
|
+
sourceMap: IndexSourceMapJson,
|
|
85
|
+
options: DecodeOptions,
|
|
86
|
+
): ScopeInfo {
|
|
87
|
+
const scopeInfo: ScopeInfo = { scopes: [], ranges: [] };
|
|
88
|
+
|
|
89
|
+
for (const section of sourceMap.sections) {
|
|
90
|
+
const { scopes, ranges } = decode(section.map, {
|
|
91
|
+
...options,
|
|
92
|
+
generatedOffset: section.offset,
|
|
93
|
+
});
|
|
94
|
+
for (const scope of scopes) scopeInfo.scopes.push(scope);
|
|
95
|
+
for (const range of ranges) scopeInfo.ranges.push(range);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return scopeInfo;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const DEFAULT_SCOPE_STATE = {
|
|
102
|
+
line: 0,
|
|
103
|
+
column: 0,
|
|
104
|
+
name: 0,
|
|
105
|
+
kind: 0,
|
|
106
|
+
variable: 0,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const DEFAULT_RANGE_STATE = {
|
|
110
|
+
line: 0,
|
|
111
|
+
column: 0,
|
|
112
|
+
defScopeIdx: 0,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
class Decoder {
|
|
116
|
+
readonly #encodedScopes: string;
|
|
117
|
+
readonly #names: string[];
|
|
118
|
+
readonly #mode: DecodeMode;
|
|
119
|
+
|
|
120
|
+
#scopes: (OriginalScope | null)[] = [];
|
|
121
|
+
#ranges: GeneratedRange[] = [];
|
|
122
|
+
|
|
123
|
+
readonly #scopeState = { ...DEFAULT_SCOPE_STATE };
|
|
124
|
+
readonly #rangeState = { ...DEFAULT_RANGE_STATE };
|
|
125
|
+
|
|
126
|
+
readonly #scopeStack: OriginalScope[] = [];
|
|
127
|
+
readonly #rangeStack: GeneratedRange[] = [];
|
|
128
|
+
|
|
129
|
+
#flatOriginalScopes: OriginalScope[] = [];
|
|
130
|
+
#subRangeBindingsForRange = new Map<number, [number, number, number][]>();
|
|
131
|
+
|
|
132
|
+
constructor(scopes: string, names: string[], options: DecodeOptions) {
|
|
133
|
+
this.#encodedScopes = scopes;
|
|
134
|
+
this.#names = names;
|
|
135
|
+
this.#mode = options.mode;
|
|
136
|
+
this.#rangeState.line = options.generatedOffset.line;
|
|
137
|
+
this.#rangeState.column = options.generatedOffset.column;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
decode(): ScopeInfo {
|
|
141
|
+
const iter = new TokenIterator(this.#encodedScopes);
|
|
142
|
+
|
|
143
|
+
while (iter.hasNext()) {
|
|
144
|
+
if (iter.peek() === ",") {
|
|
145
|
+
iter.nextChar(); // Consume ",".
|
|
146
|
+
this.#scopes.push(null); // Add an EmptyItem;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const tag = iter.nextUnsignedVLQ();
|
|
151
|
+
switch (tag) {
|
|
152
|
+
case Tag.ORIGINAL_SCOPE_START: {
|
|
153
|
+
const item: OriginalScopeStartItem = {
|
|
154
|
+
flags: iter.nextUnsignedVLQ(),
|
|
155
|
+
line: iter.nextUnsignedVLQ(),
|
|
156
|
+
column: iter.nextUnsignedVLQ(),
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
if (item.flags & OriginalScopeFlags.HAS_NAME) {
|
|
160
|
+
item.nameIdx = iter.nextSignedVLQ();
|
|
161
|
+
}
|
|
162
|
+
if (item.flags & OriginalScopeFlags.HAS_KIND) {
|
|
163
|
+
item.kindIdx = iter.nextSignedVLQ();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
this.#handleOriginalScopeStartItem(item);
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
case Tag.ORIGINAL_SCOPE_VARIABLES: {
|
|
170
|
+
const variableIdxs: number[] = [];
|
|
171
|
+
|
|
172
|
+
while (iter.hasNext() && iter.peek() !== ",") {
|
|
173
|
+
variableIdxs.push(iter.nextSignedVLQ());
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
this.#handleOriginalScopeVariablesItem(variableIdxs);
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
case Tag.ORIGINAL_SCOPE_END: {
|
|
180
|
+
this.#handleOriginalScopeEndItem(
|
|
181
|
+
iter.nextUnsignedVLQ(),
|
|
182
|
+
iter.nextUnsignedVLQ(),
|
|
183
|
+
);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
case Tag.GENERATED_RANGE_START: {
|
|
187
|
+
const flags = iter.nextUnsignedVLQ();
|
|
188
|
+
const line = flags & GeneratedRangeFlags.HAS_LINE
|
|
189
|
+
? iter.nextUnsignedVLQ()
|
|
190
|
+
: undefined;
|
|
191
|
+
const column = iter.nextUnsignedVLQ();
|
|
192
|
+
|
|
193
|
+
const definitionIdx = flags & GeneratedRangeFlags.HAS_DEFINITION
|
|
194
|
+
? iter.nextSignedVLQ()
|
|
195
|
+
: undefined;
|
|
196
|
+
|
|
197
|
+
this.#handleGeneratedRangeStartItem({
|
|
198
|
+
flags,
|
|
199
|
+
line,
|
|
200
|
+
column,
|
|
201
|
+
definitionIdx,
|
|
202
|
+
});
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case Tag.GENERATED_RANGE_END: {
|
|
206
|
+
const lineOrColumn = iter.nextUnsignedVLQ();
|
|
207
|
+
const maybeColumn = iter.hasNext() && iter.peek() !== ","
|
|
208
|
+
? iter.nextUnsignedVLQ()
|
|
209
|
+
: undefined;
|
|
210
|
+
|
|
211
|
+
if (maybeColumn !== undefined) {
|
|
212
|
+
this.#handleGeneratedRangeEndItem(lineOrColumn, maybeColumn);
|
|
213
|
+
} else {
|
|
214
|
+
this.#handleGeneratedRangeEndItem(0, lineOrColumn);
|
|
215
|
+
}
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
case Tag.GENERATED_RANGE_BINDINGS: {
|
|
219
|
+
const valueIdxs: number[] = [];
|
|
220
|
+
|
|
221
|
+
while (iter.hasNext() && iter.peek() !== ",") {
|
|
222
|
+
valueIdxs.push(iter.nextUnsignedVLQ());
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
this.#handleGeneratedRangeBindingsItem(valueIdxs);
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
case Tag.GENERATED_RANGE_SUBRANGE_BINDING: {
|
|
229
|
+
const variableIndex = iter.nextUnsignedVLQ();
|
|
230
|
+
const bindings: [number, number, number][] = [];
|
|
231
|
+
|
|
232
|
+
while (iter.hasNext() && iter.peek() !== ",") {
|
|
233
|
+
bindings.push([
|
|
234
|
+
iter.nextUnsignedVLQ(),
|
|
235
|
+
iter.nextUnsignedVLQ(),
|
|
236
|
+
iter.nextUnsignedVLQ(),
|
|
237
|
+
]);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
this.#recordGeneratedSubRangeBindingItem(variableIndex, bindings);
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
case Tag.GENERATED_RANGE_CALL_SITE: {
|
|
244
|
+
this.#handleGeneratedRangeCallSite(
|
|
245
|
+
iter.nextUnsignedVLQ(),
|
|
246
|
+
iter.nextUnsignedVLQ(),
|
|
247
|
+
iter.nextUnsignedVLQ(),
|
|
248
|
+
);
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Consume any trailing VLQ and the the ","
|
|
254
|
+
while (iter.hasNext() && iter.peek() !== ",") iter.nextUnsignedVLQ();
|
|
255
|
+
if (iter.hasNext()) iter.nextChar();
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (iter.currentChar() === ",") {
|
|
259
|
+
// Handle trailing EmptyItem.
|
|
260
|
+
this.#scopes.push(null);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (this.#scopeStack.length > 0) {
|
|
264
|
+
this.#throwInStrictMode(
|
|
265
|
+
"Encountered ORIGINAL_SCOPE_START without matching END!",
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
if (this.#rangeStack.length > 0) {
|
|
269
|
+
this.#throwInStrictMode(
|
|
270
|
+
"Encountered GENERATED_RANGE_START without matching END!",
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const info = { scopes: this.#scopes, ranges: this.#ranges };
|
|
275
|
+
|
|
276
|
+
this.#scopes = [];
|
|
277
|
+
this.#ranges = [];
|
|
278
|
+
this.#flatOriginalScopes = [];
|
|
279
|
+
|
|
280
|
+
return info;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
#throwInStrictMode(message: string) {
|
|
284
|
+
if (this.#mode === DecodeMode.STRICT) throw new Error(message);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
#handleOriginalScopeStartItem(item: OriginalScopeStartItem) {
|
|
288
|
+
this.#scopeState.line += item.line;
|
|
289
|
+
if (item.line === 0) {
|
|
290
|
+
this.#scopeState.column += item.column;
|
|
291
|
+
} else {
|
|
292
|
+
this.#scopeState.column = item.column;
|
|
293
|
+
}
|
|
294
|
+
const scope: OriginalScope = {
|
|
295
|
+
start: { line: this.#scopeState.line, column: this.#scopeState.column },
|
|
296
|
+
end: { line: this.#scopeState.line, column: this.#scopeState.column },
|
|
297
|
+
isStackFrame: false,
|
|
298
|
+
variables: [],
|
|
299
|
+
children: [],
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
if (item.nameIdx !== undefined) {
|
|
303
|
+
this.#scopeState.name += item.nameIdx;
|
|
304
|
+
scope.name = this.#resolveName(this.#scopeState.name);
|
|
305
|
+
}
|
|
306
|
+
if (item.kindIdx !== undefined) {
|
|
307
|
+
this.#scopeState.kind += item.kindIdx;
|
|
308
|
+
scope.kind = this.#resolveName(this.#scopeState.kind);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
scope.isStackFrame = Boolean(
|
|
312
|
+
item.flags & OriginalScopeFlags.IS_STACK_FRAME,
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
this.#scopeStack.push(scope);
|
|
316
|
+
this.#flatOriginalScopes.push(scope);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
#handleOriginalScopeVariablesItem(variableIdxs: number[]) {
|
|
320
|
+
const scope = this.#scopeStack.at(-1);
|
|
321
|
+
if (!scope) {
|
|
322
|
+
this.#throwInStrictMode(
|
|
323
|
+
"Encountered ORIGINAL_SCOPE_VARIABLES without surrounding ORIGINAL_SCOPE_START",
|
|
324
|
+
);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
for (const variableIdx of variableIdxs) {
|
|
329
|
+
this.#scopeState.variable += variableIdx;
|
|
330
|
+
scope.variables.push(this.#resolveName(this.#scopeState.variable));
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
#handleOriginalScopeEndItem(line: number, column: number) {
|
|
335
|
+
this.#scopeState.line += line;
|
|
336
|
+
if (line === 0) {
|
|
337
|
+
this.#scopeState.column += column;
|
|
338
|
+
} else {
|
|
339
|
+
this.#scopeState.column = column;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const scope = this.#scopeStack.pop();
|
|
343
|
+
if (!scope) {
|
|
344
|
+
this.#throwInStrictMode(
|
|
345
|
+
"Encountered ORIGINAL_SCOPE_END without matching ORIGINAL_SCOPE_START!",
|
|
346
|
+
);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
scope.end = {
|
|
351
|
+
line: this.#scopeState.line,
|
|
352
|
+
column: this.#scopeState.column,
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
if (this.#scopeStack.length > 0) {
|
|
356
|
+
const parent = this.#scopeStack.at(-1)!;
|
|
357
|
+
scope.parent = parent;
|
|
358
|
+
parent.children.push(scope);
|
|
359
|
+
} else {
|
|
360
|
+
this.#scopes.push(scope);
|
|
361
|
+
this.#scopeState.line = 0;
|
|
362
|
+
this.#scopeState.column = 0;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
#handleGeneratedRangeStartItem(item: GeneratedRangeStartItem) {
|
|
367
|
+
if (item.line !== undefined) {
|
|
368
|
+
this.#rangeState.line += item.line;
|
|
369
|
+
this.#rangeState.column = item.column;
|
|
370
|
+
} else {
|
|
371
|
+
this.#rangeState.column += item.column;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const range: GeneratedRange = {
|
|
375
|
+
start: {
|
|
376
|
+
line: this.#rangeState.line,
|
|
377
|
+
column: this.#rangeState.column,
|
|
378
|
+
},
|
|
379
|
+
end: {
|
|
380
|
+
line: this.#rangeState.line,
|
|
381
|
+
column: this.#rangeState.column,
|
|
382
|
+
},
|
|
383
|
+
isStackFrame: Boolean(
|
|
384
|
+
item.flags & GeneratedRangeFlags.IS_STACK_FRAME,
|
|
385
|
+
),
|
|
386
|
+
isHidden: Boolean(item.flags & GeneratedRangeFlags.IS_HIDDEN),
|
|
387
|
+
values: [],
|
|
388
|
+
children: [],
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
if (item.definitionIdx !== undefined) {
|
|
392
|
+
this.#rangeState.defScopeIdx += item.definitionIdx;
|
|
393
|
+
if (
|
|
394
|
+
this.#rangeState.defScopeIdx < 0 ||
|
|
395
|
+
this.#rangeState.defScopeIdx >= this.#flatOriginalScopes.length
|
|
396
|
+
) {
|
|
397
|
+
this.#throwInStrictMode("Invalid definition scope index");
|
|
398
|
+
} else {
|
|
399
|
+
range.originalScope =
|
|
400
|
+
this.#flatOriginalScopes[this.#rangeState.defScopeIdx];
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
this.#rangeStack.push(range);
|
|
405
|
+
this.#subRangeBindingsForRange.clear();
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
#handleGeneratedRangeBindingsItem(valueIdxs: number[]) {
|
|
409
|
+
const range = this.#rangeStack.at(-1);
|
|
410
|
+
if (!range) {
|
|
411
|
+
this.#throwInStrictMode(
|
|
412
|
+
"Encountered GENERATED_RANGE_BINDINGS without surrounding GENERATED_RANGE_START",
|
|
413
|
+
);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
for (const valueIdx of valueIdxs) {
|
|
418
|
+
if (valueIdx === 0) {
|
|
419
|
+
range.values.push(null);
|
|
420
|
+
} else {
|
|
421
|
+
range.values.push(this.#resolveName(valueIdx - 1));
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
#recordGeneratedSubRangeBindingItem(
|
|
427
|
+
variableIndex: number,
|
|
428
|
+
bindings: [number, number, number][],
|
|
429
|
+
) {
|
|
430
|
+
if (this.#subRangeBindingsForRange.has(variableIndex)) {
|
|
431
|
+
this.#throwInStrictMode(
|
|
432
|
+
"Encountered multiple GENERATED_RANGE_SUBRANGE_BINDING items for the same variable",
|
|
433
|
+
);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
this.#subRangeBindingsForRange.set(variableIndex, bindings);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
#handleGeneratedRangeCallSite(
|
|
440
|
+
sourceIndex: number,
|
|
441
|
+
line: number,
|
|
442
|
+
column: number,
|
|
443
|
+
) {
|
|
444
|
+
const range = this.#rangeStack.at(-1);
|
|
445
|
+
if (!range) {
|
|
446
|
+
this.#throwInStrictMode(
|
|
447
|
+
"Encountered GENERATED_RANGE_CALL_SITE without surrounding GENERATED_RANGE_START",
|
|
448
|
+
);
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
range.callSite = {
|
|
453
|
+
sourceIndex,
|
|
454
|
+
line,
|
|
455
|
+
column,
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
#handleGeneratedRangeEndItem(line: number, column: number) {
|
|
460
|
+
if (line !== 0) {
|
|
461
|
+
this.#rangeState.line += line;
|
|
462
|
+
this.#rangeState.column = column;
|
|
463
|
+
} else {
|
|
464
|
+
this.#rangeState.column += column;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const range = this.#rangeStack.pop();
|
|
468
|
+
if (!range) {
|
|
469
|
+
this.#throwInStrictMode(
|
|
470
|
+
"Encountered GENERATED_RANGE_END without matching GENERATED_RANGE_START!",
|
|
471
|
+
);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
range.end = {
|
|
476
|
+
line: this.#rangeState.line,
|
|
477
|
+
column: this.#rangeState.column,
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
this.#handleGeneratedRangeSubRangeBindings(range);
|
|
481
|
+
|
|
482
|
+
if (this.#rangeStack.length > 0) {
|
|
483
|
+
const parent = this.#rangeStack.at(-1)!;
|
|
484
|
+
range.parent = parent;
|
|
485
|
+
parent.children.push(range);
|
|
486
|
+
} else {
|
|
487
|
+
this.#ranges.push(range);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
#handleGeneratedRangeSubRangeBindings(range: GeneratedRange) {
|
|
492
|
+
for (const [variableIndex, bindings] of this.#subRangeBindingsForRange) {
|
|
493
|
+
const value = range.values[variableIndex];
|
|
494
|
+
const subRanges: SubRangeBinding[] = [];
|
|
495
|
+
range.values[variableIndex] = subRanges;
|
|
496
|
+
|
|
497
|
+
let lastLine = range.start.line;
|
|
498
|
+
let lastColumn = range.start.column;
|
|
499
|
+
|
|
500
|
+
subRanges.push({
|
|
501
|
+
from: { line: lastLine, column: lastColumn },
|
|
502
|
+
to: { line: 0, column: 0 },
|
|
503
|
+
value: value as string | undefined,
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
for (const [binding, line, column] of bindings) {
|
|
507
|
+
lastLine += line;
|
|
508
|
+
if (line === 0) {
|
|
509
|
+
lastColumn += column;
|
|
510
|
+
} else {
|
|
511
|
+
lastColumn = column;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
subRanges.push({
|
|
515
|
+
from: { line: lastLine, column: lastColumn },
|
|
516
|
+
to: { line: 0, column: 0 }, // This will be fixed in the post-processing step.
|
|
517
|
+
value: binding === 0 ? undefined : this.#resolveName(binding - 1),
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
for (const value of range.values) {
|
|
523
|
+
if (Array.isArray(value)) {
|
|
524
|
+
const subRanges = value;
|
|
525
|
+
for (let i = 0; i < subRanges.length - 1; ++i) {
|
|
526
|
+
subRanges[i].to = subRanges[i + 1].from;
|
|
527
|
+
}
|
|
528
|
+
subRanges[subRanges.length - 1].to = range.end;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
#resolveName(index: number): string {
|
|
534
|
+
if (index < 0 || index >= this.#names.length) {
|
|
535
|
+
this.#throwInStrictMode("Illegal index into the 'names' array");
|
|
536
|
+
}
|
|
537
|
+
return this.#names[index] ?? "";
|
|
538
|
+
}
|
|
539
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2025 The Chromium Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
import { Encoder } from "./encoder.js";
|
|
5
|
+
/**
|
|
6
|
+
* Encodes the `ScopeInfo` into a source map JSON object.
|
|
7
|
+
*
|
|
8
|
+
* If `inputSourceMap` is provided, `encode` will augment the "names" array and
|
|
9
|
+
* overwrite the "scopes" field, before returning the provided `inputSourceMap` again.
|
|
10
|
+
*/ export function encode(scopesInfo, inputSourceMap) {
|
|
11
|
+
inputSourceMap ||= {
|
|
12
|
+
version: 3,
|
|
13
|
+
mappings: "",
|
|
14
|
+
sources: new Array(scopesInfo.scopes.length).fill(null)
|
|
15
|
+
};
|
|
16
|
+
inputSourceMap.names ||= [];
|
|
17
|
+
if (inputSourceMap.sources.length !== scopesInfo.scopes.length) {
|
|
18
|
+
throw new Error(`SourceMapJson.sources.length must match ScopesInfo.scopes! ${inputSourceMap.sources.length} vs ${scopesInfo.scopes.length}`);
|
|
19
|
+
}
|
|
20
|
+
inputSourceMap.scopes = new Encoder(scopesInfo, inputSourceMap.names).encode();
|
|
21
|
+
return inputSourceMap;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=encode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.js","sources":["./encode.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAG7B,SAAS,OAAO,uBAAuB;AAEvC;;;;;CAKC,GACD,OAAO,SAAS,OACd,UAAqB,EACrB,cAA8B;EAE9B,mBAAmB;IACjB,SAAS;IACT,UAAU;IACV,SAAS,IAAI,MAAM,WAAW,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC;EACpD;EACA,eAAe,KAAK,KAAK,EAAE;EAE3B,IAAI,eAAe,OAAO,CAAC,MAAM,KAAK,WAAW,MAAM,CAAC,MAAM,EAAE;IAC9D,MAAM,IAAI,MACR,CAAC,2DAA2D,EAAE,eAAe,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,MAAM,CAAC,MAAM,EAAE;EAEhI;EAEA,eAAe,MAAM,GAAG,IAAI,QAAQ,YAAY,eAAe,KAAK,EACjE,MAAM;EAET,OAAO;AACT"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright 2025 The Chromium Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
import type { ScopeInfo, SourceMapJson } from "../scopes.d.ts";
|
|
6
|
+
import { Encoder } from "./encoder.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Encodes the `ScopeInfo` into a source map JSON object.
|
|
10
|
+
*
|
|
11
|
+
* If `inputSourceMap` is provided, `encode` will augment the "names" array and
|
|
12
|
+
* overwrite the "scopes" field, before returning the provided `inputSourceMap` again.
|
|
13
|
+
*/
|
|
14
|
+
export function encode(
|
|
15
|
+
scopesInfo: ScopeInfo,
|
|
16
|
+
inputSourceMap?: SourceMapJson,
|
|
17
|
+
): SourceMapJson {
|
|
18
|
+
inputSourceMap ||= {
|
|
19
|
+
version: 3,
|
|
20
|
+
mappings: "",
|
|
21
|
+
sources: new Array(scopesInfo.scopes.length).fill(null),
|
|
22
|
+
};
|
|
23
|
+
inputSourceMap.names ||= [];
|
|
24
|
+
|
|
25
|
+
if (inputSourceMap.sources.length !== scopesInfo.scopes.length) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`SourceMapJson.sources.length must match ScopesInfo.scopes! ${inputSourceMap.sources.length} vs ${scopesInfo.scopes.length}`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
inputSourceMap.scopes = new Encoder(scopesInfo, inputSourceMap.names)
|
|
32
|
+
.encode();
|
|
33
|
+
|
|
34
|
+
return inputSourceMap;
|
|
35
|
+
}
|