Skip to content

Commit c2af0ca

Browse files
committed
skip Debug in core/scanner
1 parent c30f78c commit c2af0ca

File tree

2 files changed

+87
-193
lines changed

2 files changed

+87
-193
lines changed

src/compiler/core.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Comparer, Comparison, EqualityComparer, MapLike, Push, SortedArray, SortedReadonlyArray } from "./corePublic";
2-
import { Debug } from "./debug";
2+
// import { Debug } from "./debug";
33
import { __String, CharacterCodes, Queue, TextSpan, UnderscoreEscapedMap } from "./types";
44

55
/** @internal */
@@ -122,7 +122,7 @@ export function reduceLeftIterator<T, U>(iterator: Iterator<T> | undefined, f: (
122122
/** @internal */
123123
export function zipWith<T, U, V>(arrayA: readonly T[], arrayB: readonly U[], callback: (a: T, b: U, index: number) => V): V[] {
124124
const result: V[] = [];
125-
Debug.assertEqual(arrayA.length, arrayB.length);
125+
// Debug.assertEqual(arrayA.length, arrayB.length);
126126
for (let i = 0; i < arrayA.length; i++) {
127127
result.push(callback(arrayA[i], arrayB[i], i));
128128
}
@@ -131,7 +131,7 @@ export function zipWith<T, U, V>(arrayA: readonly T[], arrayB: readonly U[], cal
131131

132132
/** @internal */
133133
export function zipToIterator<T, U>(arrayA: readonly T[], arrayB: readonly U[]): Iterator<[T, U]> {
134-
Debug.assertEqual(arrayA.length, arrayB.length);
134+
// Debug.assertEqual(arrayA.length, arrayB.length);
135135
let i = 0;
136136
return {
137137
next() {
@@ -146,7 +146,7 @@ export function zipToIterator<T, U>(arrayA: readonly T[], arrayB: readonly U[]):
146146

147147
/** @internal */
148148
export function zipToMap<K, V>(keys: readonly K[], values: readonly V[]): Map<K, V> {
149-
Debug.assert(keys.length === values.length);
149+
// Debug.assert(keys.length === values.length);
150150
const map = new Map<K, V>();
151151
for (let i = 0; i < keys.length; ++i) {
152152
map.set(keys[i], values[i]);
@@ -266,7 +266,8 @@ export function findMap<T, U>(array: readonly T[], callback: (element: T, index:
266266
return result;
267267
}
268268
}
269-
return Debug.fail();
269+
// return Debug.fail();
270+
throw new Error();
270271
}
271272

272273
/** @internal */
@@ -884,7 +885,8 @@ function deduplicateSorted<T>(array: SortedReadonlyArray<T>, comparer: EqualityC
884885

885886
case Comparison.LessThan:
886887
// If `array` is sorted, `next` should **never** be less than `last`.
887-
return Debug.fail("Array is unsorted.");
888+
// return Debug.fail("Array is unsorted.");
889+
throw new Error("Array is unsorted.");
888890
}
889891

890892
deduplicated.push(last = next);
@@ -1005,14 +1007,14 @@ export function relativeComplement<T>(arrayA: T[] | undefined, arrayB: T[] | und
10051007
loopB: for (let offsetA = 0, offsetB = 0; offsetB < arrayB.length; offsetB++) {
10061008
if (offsetB > 0) {
10071009
// Ensure `arrayB` is properly sorted.
1008-
Debug.assertGreaterThanOrEqual(comparer(arrayB[offsetB], arrayB[offsetB - 1]), Comparison.EqualTo);
1010+
// Debug.assertGreaterThanOrEqual(comparer(arrayB[offsetB], arrayB[offsetB - 1]), Comparison.EqualTo);
10091011
}
10101012

10111013
loopA: for (const startA = offsetA; offsetA < arrayA.length; offsetA++) {
10121014
if (offsetA > startA) {
10131015
// Ensure `arrayA` is properly sorted. We only need to perform this check if
10141016
// `offsetA` has changed since we entered the loop.
1015-
Debug.assertGreaterThanOrEqual(comparer(arrayA[offsetA], arrayA[offsetA - 1]), Comparison.EqualTo);
1017+
// Debug.assertGreaterThanOrEqual(comparer(arrayA[offsetA], arrayA[offsetA - 1]), Comparison.EqualTo);
10161018
}
10171019

10181020
switch (comparer(arrayB[offsetB], arrayA[offsetA])) {
@@ -1259,7 +1261,7 @@ export function firstOrUndefined<T>(array: readonly T[] | undefined): T | undefi
12591261

12601262
/** @internal */
12611263
export function first<T>(array: readonly T[]): T {
1262-
Debug.assert(array.length !== 0);
1264+
// Debug.assert(array.length !== 0);
12631265
return array[0];
12641266
}
12651267

@@ -1274,7 +1276,7 @@ export function lastOrUndefined<T>(array: readonly T[] | undefined): T | undefin
12741276

12751277
/** @internal */
12761278
export function last<T>(array: readonly T[]): T {
1277-
Debug.assert(array.length !== 0);
1279+
// Debug.assert(array.length !== 0);
12781280
return array[array.length - 1];
12791281
}
12801282

@@ -1295,7 +1297,12 @@ export function singleOrUndefined<T>(array: readonly T[] | undefined): T | undef
12951297
* @internal
12961298
*/
12971299
export function single<T>(array: readonly T[]): T {
1298-
return Debug.checkDefined(singleOrUndefined(array));
1300+
// return Debug.checkDefined(singleOrUndefined(array));
1301+
const result = singleOrUndefined(array);
1302+
if (result === undefined) {
1303+
throw new Error();
1304+
}
1305+
return result;
12991306
}
13001307

13011308
/**
@@ -1991,8 +1998,8 @@ export function tryCast<T>(value: T, test: (value: T) => boolean): T | undefined
19911998
/** @internal */
19921999
export function cast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut {
19932000
if (value !== undefined && test(value)) return value;
1994-
1995-
return Debug.fail(`Invalid cast. The supplied value ${value} did not pass the test '${Debug.getFunctionName(test)}'.`);
2001+
throw new Error(`Invalid cast. The supplied value ${value} did not pass the test`);
2002+
// return Debug.fail(`Invalid cast. The supplied value ${value} did not pass the test '${Debug.getFunctionName(test)}'.`);
19962003
}
19972004

19982005
/**
@@ -2478,7 +2485,7 @@ export function getSpellingSuggestion<T>(name: string, candidates: T[], getName:
24782485
continue;
24792486
}
24802487

2481-
Debug.assert(distance < bestDistance); // Else `levenshteinWithMax` should return undefined
2488+
// Debug.assert(distance < bestDistance); // Else `levenshteinWithMax` should return undefined
24822489
bestDistance = distance;
24832490
bestCandidate = candidate;
24842491
}
@@ -2692,7 +2699,7 @@ export function patternText({ prefix, suffix }: Pattern): string {
26922699
* @internal
26932700
*/
26942701
export function matchedText(pattern: Pattern, candidate: string): string {
2695-
Debug.assert(isPatternMatch(pattern, candidate));
2702+
// Debug.assert(isPatternMatch(pattern, candidate));
26962703
return candidate.substring(pattern.prefix.length, candidate.length - pattern.suffix.length);
26972704
}
26982705

0 commit comments

Comments
 (0)