Skip to content

Commit 239f899

Browse files
committed
Implement bulder setRangeCallSite
1 parent 4e52c9b commit 239f899

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

src/builder/builder.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,26 @@ describe("ScopeInfoBuilder", () => {
288288
});
289289
});
290290

291+
describe("setRangeCallSite", () => {
292+
it("sets the callSite", () => {
293+
const info = builder.startRange(0, 0).setRangeCallSite({
294+
line: 10,
295+
column: 20,
296+
sourceIndex: 0,
297+
}).endRange(0, 10).build();
298+
299+
assertEquals(info.ranges[0].callSite, {
300+
line: 10,
301+
column: 20,
302+
sourceIndex: 0,
303+
});
304+
});
305+
306+
it("does nothing when no range is on the stack", () => {
307+
builder.setRangeCallSite({ line: 10, column: 20, sourceIndex: 0 });
308+
});
309+
});
310+
291311
describe("endRange", () => {
292312
it("does nothing when no range is open", () => {
293313
builder.endRange(0, 20);

src/builder/builder.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ export class ScopeInfoBuilder {
200200
return this;
201201
}
202202

203+
setRangeCallSite(callSite: OriginalPosition): this {
204+
const range = this.#rangeStack.at(-1);
205+
if (range) range.callSite = callSite;
206+
207+
return this;
208+
}
209+
203210
endRange(line: number, column: number): this {
204211
const range = this.#rangeStack.pop();
205212
if (!range) return this;

src/builder/safe_builder.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,30 @@ describe("SafeScopeInfoBuilder", () => {
298298
});
299299
});
300300

301+
describe("setRangeCallSite", () => {
302+
it("throws when no range is on open", () => {
303+
assertThrows(() =>
304+
builder.setRangeCallSite({
305+
line: 10,
306+
column: 20,
307+
sourceIndex: 0,
308+
})
309+
);
310+
});
311+
312+
it("throws while building a scope", () => {
313+
builder.startScope(0, 0);
314+
315+
assertThrows(() =>
316+
builder.setRangeCallSite({
317+
line: 10,
318+
column: 20,
319+
sourceIndex: 0,
320+
})
321+
);
322+
});
323+
});
324+
301325
describe("endRange", () => {
302326
it("throws when the range stack is empty", () => {
303327
assertThrows(() => builder.endRange(5, 0));

src/builder/safe_builder.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
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, OriginalPosition, OriginalScope, ScopeInfo } from "../scopes.d.ts";
5+
import type {
6+
Binding,
7+
OriginalPosition,
8+
OriginalScope,
9+
ScopeInfo,
10+
} from "../scopes.d.ts";
611
import { comparePositions } from "../util.ts";
712
import { ScopeInfoBuilder, type ScopeKey } from "./builder.ts";
813

@@ -241,6 +246,14 @@ export class SafeScopeInfoBuilder extends ScopeInfoBuilder {
241246
return this;
242247
}
243248

249+
override setRangeCallSite(callSite: OriginalPosition): this {
250+
this.#verifyEmptyScopeStack("setRangeCallSite");
251+
this.#verifyRangePresent("setRangeCallSite");
252+
253+
super.setRangeCallSite(callSite);
254+
return this;
255+
}
256+
244257
override endRange(line: number, column: number): this {
245258
this.#verifyEmptyScopeStack("endRange");
246259

0 commit comments

Comments
 (0)