You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/builder/safe_builder.ts
+50Lines changed: 50 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@ import type {
6
6
Binding,
7
7
OriginalPosition,
8
8
OriginalScope,
9
+
Position,
9
10
ScopeInfo,
10
11
}from"../scopes.d.ts";
11
12
import{comparePositions}from"../util.ts";
@@ -268,6 +269,7 @@ export class SafeScopeInfoBuilder extends ScopeInfoBuilder {
268
269
);
269
270
}
270
271
272
+
this.#verifyRangeValues(range,{ line, column });
271
273
super.endRange(line,column);
272
274
returnthis;
273
275
}
@@ -306,4 +308,52 @@ export class SafeScopeInfoBuilder extends ScopeInfoBuilder {
306
308
thrownewError(`Can't ${op} while no GeneratedRange is on the stack.`);
307
309
}
308
310
}
311
+
312
+
#verifyRangeValues(
313
+
range: {start: Position;values: Binding[]},
314
+
end: Position,
315
+
): void{
316
+
for(constvalueofrange.values){
317
+
if(!Array.isArray(value)){
318
+
continue;
319
+
}
320
+
321
+
constsubRanges=value;
322
+
if(subRanges.length===0){
323
+
continue;
324
+
}
325
+
326
+
constfirst=subRanges.at(0)!;
327
+
if(comparePositions(first.from,range.start)!==0){
328
+
thrownewError(
329
+
`Sub-range bindings must start at the generated range's start. Expected ${range.start.line}:${range.start.column}, but got ${first.from.line}:${first.from.column}`,
330
+
);
331
+
}
332
+
333
+
constlast=subRanges.at(-1)!;
334
+
if(comparePositions(last.to,end)!==0){
335
+
thrownewError(
336
+
`Sub-range bindings must end at the generated range's end. Expected ${end.line}:${end.column}, but got ${last.to.line}:${last.to.column}`,
337
+
);
338
+
}
339
+
340
+
for(leti=0;i<subRanges.length;++i){
341
+
constcurrent=subRanges[i];
342
+
if(comparePositions(current.from,current.to)>=0){
343
+
thrownewError(
344
+
`Sub-range binding 'from' (${current.from.line}:${current.from.column}) must precede 'to' (${current.to.line}:${current.to.column})`,
345
+
);
346
+
}
347
+
348
+
if(i>0){
349
+
constprev=subRanges[i-1];
350
+
if(comparePositions(prev.to,current.from)!==0){
351
+
thrownewError(
352
+
`Sub-range bindings must be sorted and not overlap. Found gap between ${prev.to.line}:${prev.to.column} and ${current.from.line}:${current.from.column}`,
0 commit comments