[sdk] Decode 'isScope' flag for generated ranges

The flag was added a while ago to the "Scopes" proposal with the
PR https://github.com/tc39/source-map/pull/69.

We need in DevTools to figure out inlined function scopes.

R=kimanh@chromium.org

Bug: 40277685
Change-Id: I5d25fa2d235256f965bef9d54944876018e44b90
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5639705
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: Kim-Anh Tran <kimanh@chromium.org>
This commit is contained in:
Simon Zünd
2024-06-19 09:18:29 +00:00
committed by Devtools-frontend LUCI CQ
parent 812a51b91e
commit a3eace8a2e
3 changed files with 27 additions and 0 deletions
@@ -386,4 +386,20 @@ describe('decodeGeneratedRanges', () => {
{from: {line: 0, column: 60}, to: {line: 0, column: 100}, value: 'y'},
]);
});
it('decodes the "isScope" flag', () => {
const range = new GeneratedRangeBuilder()
.start(0, 0)
.start(5, 0, {isScope: true})
.end(10, 0)
.start(20, 4, {isScope: false})
.end(30, 0)
.end(40, 0)
.build();
const generatedRange = decodeGeneratedRanges(range, [], []);
assert.lengthOf(generatedRange.children, 2);
assert.isTrue(generatedRange.children[0].isScope);
assert.isFalse(generatedRange.children[1].isScope);
});
});
+7
View File
@@ -34,6 +34,11 @@ export interface GeneratedRange {
end: Position;
originalScope?: OriginalScope;
/**
* Whether this generated range is an actual JavaScript scope in the generated code.
*/
isScope: boolean;
/**
* If this `GeneratedRange` is the result of inlining `originalScope`, then `callsite`
* refers to where `originalScope` was called in the original ("authored") code.
@@ -188,6 +193,7 @@ export function decodeGeneratedRanges(
const range: GeneratedRange = {
start: {line: item.line, column: item.column},
end: {line: item.line, column: item.column},
isScope: Boolean(item.flags & EncodedGeneratedRangeFlag.IsScope),
values: [],
children: [],
};
@@ -289,6 +295,7 @@ interface EncodedGeneratedRangeEnd {
export const enum EncodedGeneratedRangeFlag {
HasDefinition = 0x1,
HasCallsite = 0x2,
IsScope = 0x4,
}
function isRangeStart(item: EncodedGeneratedRangeStart|EncodedGeneratedRangeEnd): item is EncodedGeneratedRangeStart {
+4
View File
@@ -200,6 +200,7 @@ export class GeneratedRangeBuilder {
};
start(line: number, column: number, options?: {
isScope?: boolean,
definition?: {sourceIdx: number, scopeIdx: number},
callsite?: {sourceIdx: number, line: number, column: number},
bindings?: (number|{line: number, column: number, nameIdx: number}[])[],
@@ -220,6 +221,9 @@ export class GeneratedRangeBuilder {
if (options?.callsite) {
flags |= SDK.SourceMapScopes.EncodedGeneratedRangeFlag.HasCallsite;
}
if (options?.isScope) {
flags |= SDK.SourceMapScopes.EncodedGeneratedRangeFlag.IsScope;
}
this.#encodedRange += encodeVlq(flags);
if (options?.definition) {