Skip to content

Commit 4e52c9b

Browse files
committed
Set callSite position via options
1 parent b0c8338 commit 4e52c9b

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

src/builder/builder.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,18 @@ describe("ScopeInfoBuilder", () => {
209209

210210
assertEquals(info.ranges[0]?.values, ["a", null, "b"]);
211211
});
212+
213+
it("can set the callSite position via option", () => {
214+
const info = builder.startRange(0, 0, {
215+
callSite: { line: 10, column: 20, sourceIndex: 0 },
216+
}).endRange(0, 10).build();
217+
218+
assertEquals(info.ranges[0].callSite, {
219+
line: 10,
220+
column: 20,
221+
sourceIndex: 0,
222+
});
223+
});
212224
});
213225

214226
describe("setRangeDefinitionScope", () => {

src/builder/builder.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import type {
66
Binding,
77
GeneratedRange,
8+
OriginalPosition,
89
OriginalScope,
910
ScopeInfo,
1011
} from "../scopes.d.ts";
@@ -135,6 +136,7 @@ export class ScopeInfoBuilder {
135136
isStackFrame?: boolean;
136137
isHidden?: boolean;
137138
values?: Binding[];
139+
callSite?: OriginalPosition;
138140
},
139141
): this {
140142
const range: GeneratedRange = {
@@ -156,6 +158,10 @@ export class ScopeInfoBuilder {
156158
range.originalScope = this.#keyToScope.get(options.scopeKey);
157159
}
158160

161+
if (options?.callSite) {
162+
range.callSite = options.callSite;
163+
}
164+
159165
this.#rangeStack.push(range);
160166

161167
return this;

src/builder/safe_builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import type { Binding, OriginalScope, ScopeInfo } from "../scopes.d.ts";
5+
import type { Binding, OriginalPosition, OriginalScope, ScopeInfo } from "../scopes.d.ts";
66
import { comparePositions } from "../util.ts";
77
import { ScopeInfoBuilder, type ScopeKey } from "./builder.ts";
88

@@ -115,6 +115,7 @@ export class SafeScopeInfoBuilder extends ScopeInfoBuilder {
115115
isStackFrame?: boolean;
116116
isHidden?: boolean;
117117
values?: Binding[];
118+
callSite?: OriginalPosition;
118119
},
119120
): this {
120121
this.#verifyEmptyScopeStack("starRange");

src/scopes.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ export interface GeneratedRange {
7070
isHidden: boolean;
7171

7272
/**
73-
* If this `GeneratedRange` is the result of inlining `originalScope`, then `callsite`
73+
* If this `GeneratedRange` is the result of inlining `originalScope`, then `callSite`
7474
* refers to where `originalScope` was called in the original ("authored") code.
7575
*
7676
* If this field is present than `originalScope` is present as well and `isStackFrame` is `false`.
7777
*/
78-
callsite?: OriginalPosition;
78+
callSite?: OriginalPosition;
7979

8080
/**
8181
* Expressions that compute the values of the variables of this OriginalScope. The length

0 commit comments

Comments
 (0)