Skip to content

Commit 58681ed

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
[source-map] Support 'undefined' root OriginalScopes
With the proposed extension API in https://crrev.com/c/5774044, we may have OriginalScope trees for only some of the original source files in a source map. This CL prepares the 'SourceMapScopesInfo' class for that and adds the necessary 'undefined' checks where needed. [email protected] Bug: 389857436 Change-Id: I8435618ef450cbe81eca5973b02a7779a2d6dc69 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6185434 Commit-Queue: Simon Zünd <[email protected]> Auto-Submit: Simon Zünd <[email protected]> Reviewed-by: Kim-Anh Tran <[email protected]>
1 parent d006340 commit 58681ed

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

front_end/core/sdk/SourceMapScopesInfo.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {GeneratedRange, OriginalPosition, OriginalScope, Position,} from '.
1111

1212
export class SourceMapScopesInfo {
1313
readonly #sourceMap: SourceMap;
14-
readonly #originalScopes: OriginalScope[];
14+
readonly #originalScopes: (OriginalScope|undefined)[];
1515
readonly #generatedRanges: GeneratedRange[];
1616

1717
#cachedVariablesAndBindingsPresent: boolean|null = null;
@@ -130,8 +130,12 @@ export class SourceMapScopesInfo {
130130
// We check whether any original scope has a non-empty list of variables, and
131131
// generated ranges with a non-empty binding list.
132132

133-
function walkTree(nodes: OriginalScope[]|GeneratedRange[]): boolean {
133+
function walkTree(nodes: (OriginalScope|undefined)[]|GeneratedRange[]): boolean {
134134
for (const node of nodes) {
135+
if (!node) {
136+
continue;
137+
}
138+
135139
if ('variables' in node && node.variables.length > 0) {
136140
return true;
137141
}
@@ -274,8 +278,12 @@ export class SourceMapScopesInfo {
274278
* to inner.
275279
*/
276280
#findOriginalScopeChain({sourceIndex, line, column}: OriginalPosition): OriginalScope[] {
277-
const result: OriginalScope[] = [];
281+
const scope = this.#originalScopes[sourceIndex];
282+
if (!scope) {
283+
return [];
284+
}
278285

286+
const result: OriginalScope[] = [];
279287
(function walkScopes(scopes: OriginalScope[]) {
280288
for (const scope of scopes) {
281289
if (!contains(scope, line, column)) {
@@ -284,7 +292,7 @@ export class SourceMapScopesInfo {
284292
result.push(scope);
285293
walkScopes(scope.children);
286294
}
287-
})([this.#originalScopes[sourceIndex]]);
295+
})([scope]);
288296

289297
return result;
290298
}

0 commit comments

Comments
 (0)