typescript
Version:
TypeScript is a language for application scale JavaScript development
1,738 lines (1,731 loc) • 6.17 MB
JavaScript
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
"use strict";
// src/compiler/corePublic.ts
var versionMajorMinor = "5.8";
var version = "5.8.2";
// src/compiler/core.ts
var emptyArray = [];
var emptyMap = /* @__PURE__ */ new Map();
function length(array) {
return array !== void 0 ? array.length : 0;
}
function forEach(array, callback) {
if (array !== void 0) {
for (let i = 0; i < array.length; i++) {
const result = callback(array[i], i);
if (result) {
return result;
}
}
}
return void 0;
}
function firstDefined(array, callback) {
if (array === void 0) {
return void 0;
}
for (let i = 0; i < array.length; i++) {
const result = callback(array[i], i);
if (result !== void 0) {
return result;
}
}
return void 0;
}
function firstDefinedIterator(iter, callback) {
for (const value of iter) {
const result = callback(value);
if (result !== void 0) {
return result;
}
}
return void 0;
}
function reduceLeftIterator(iterator, f, initial) {
let result = initial;
if (iterator) {
let pos = 0;
for (const value of iterator) {
result = f(result, value, pos);
pos++;
}
}
return result;
}
function zipWith(arrayA, arrayB, callback) {
const result = [];
Debug.assertEqual(arrayA.length, arrayB.length);
for (let i = 0; i < arrayA.length; i++) {
result.push(callback(arrayA[i], arrayB[i], i));
}
return result;
}
function every(array, callback) {
if (array !== void 0) {
for (let i = 0; i < array.length; i++) {
if (!callback(array[i], i)) {
return false;
}
}
}
return true;
}
function find(array, predicate, startIndex) {
if (array === void 0) return void 0;
for (let i = startIndex ?? 0; i < array.length; i++) {
const value = array[i];
if (predicate(value, i)) {
return value;
}
}
return void 0;
}
function findLast(array, predicate, startIndex) {
if (array === void 0) return void 0;
for (let i = startIndex ?? array.length - 1; i >= 0; i--) {
const value = array[i];
if (predicate(value, i)) {
return value;
}
}
return void 0;
}
function findIndex(array, predicate, startIndex) {
if (array === void 0) return -1;
for (let i = startIndex ?? 0; i < array.length; i++) {
if (predicate(array[i], i)) {
return i;
}
}
return -1;
}
function findLastIndex(array, predicate, startIndex) {
if (array === void 0) return -1;
for (let i = startIndex ?? array.length - 1; i >= 0; i--) {
if (predicate(array[i], i)) {
return i;
}
}
return -1;
}
function contains(array, value, equalityComparer = equateValues) {
if (array !== void 0) {
for (let i = 0; i < array.length; i++) {
if (equalityComparer(array[i], value)) {
return true;
}
}
}
return false;
}
function indexOfAnyCharCode(text, charCodes, start) {
for (let i = start ?? 0; i < text.length; i++) {
if (contains(charCodes, text.charCodeAt(i))) {
return i;
}
}
return -1;
}
function countWhere(array, predicate) {
let count = 0;
if (array !== void 0) {
for (let i = 0; i < array.length; i++) {
const v = array[i];
if (predicate(v, i)) {
count++;
}
}
}
return count;
}
function filter(array, f) {
if (array !== void 0) {
const len = array.length;
let i = 0;
while (i < len && f(array[i])) i++;
if (i < len) {
const result = array.slice(0, i);
i++;
while (i < len) {
const item = array[i];
if (f(item)) {
result.push(item);
}
i++;
}
return result;
}
}
return array;
}
function filterMutate(array, f) {
let outIndex = 0;
for (let i = 0; i < array.length; i++) {
if (f(array[i], i, array)) {
array[outIndex] = array[i];
outIndex++;
}
}
array.length = outIndex;
}
function clear(array) {
array.length = 0;
}
function map(array, f) {
let result;
if (array !== void 0) {
result = [];
for (let i = 0; i < array.length; i++) {
result.push(f(array[i], i));
}
}
return result;
}
function* mapIterator(iter, mapFn) {
for (const x of iter) {
yield mapFn(x);
}
}
function sameMap(array, f) {
if (array !== void 0) {
for (let i = 0; i < array.length; i++) {
const item = array[i];
const mapped = f(item, i);
if (item !== mapped) {
const result = array.slice(0, i);
result.push(mapped);
for (i++; i < array.length; i++) {
result.push(f(array[i], i));
}
return result;
}
}
}
return array;
}
function flatten(array) {
const result = [];
for (let i = 0; i < array.length; i++) {
const v = array[i];
if (v) {
if (isArray(v)) {
addRange(result, v);
} else {
result.push(v);
}
}
}
return result;
}
function flatMap(array, mapfn) {
let result;
if (array !== void 0) {
for (let i = 0; i < array.length; i++) {
const v = mapfn(array[i], i);
if (v) {
if (isArray(v)) {
result = addRange(result, v);
} else {
result = append(result, v);
}
}
}
}
return result ?? emptyArray;
}
function flatMapToMutable(array, mapfn) {
const result = [];
if (array !== void 0) {
for (let i = 0; i < array.length; i++) {
const v = mapfn(array[i], i);
if (v) {
if (isArray(v)) {
addRange(result, v);
} else {
result.push(v);
}
}
}
}
return result;
}
function sameFlatMap(array, mapfn) {
let result;
if (array !== void 0) {
for (let i = 0; i < array.length; i++) {
const item = array[i];
const mapped = mapfn(item, i);
if (result || item !== mapped || isArray(mapped)) {
if (!result) {
result = array.slice(0, i);
}
if (isArray(mapped)) {
addRange(result, mapped);
} else {
result.push(mapped);
}
}
}
}
return result ?? array;
}
function mapDefined(array, mapFn) {
const result = [];
if (array !== void 0) {
for (let i = 0; i < array.length; i++) {
const mapped = mapFn(array[i], i);
if (mapped !== void 0) {
result.push(mapped);
}
}
}
return result;
}
function* mapDefinedIterator(iter, mapFn) {
for (const x of iter) {
const value = mapFn(x);
if (value !== void 0) {
yield value;
}
}
}
function getOrUpdate(map2, key, callback) {
if (map2.has(key)) {
return map2.get(key);
}
const value = callback();
map2.set(key, value);
return value;
}
function tryAddToSet(set, value) {
if (!set.has(value)) {
set.add(value);
return true;
}
return false;
}
function spanMap(array, keyfn, mapfn) {
let result;
if (array !== void 0) {
result = [];
const len = array.length;
let previousKey;
let key;
let start = 0;
let pos = 0;
while (start < len) {
while (pos < len) {
const value = array[pos];
key = keyfn(value, pos);
if (pos === 0) {
previousKey = key;
} else if (key !== previousKey) {
break;
}
pos++;
}
if (start < pos) {
const v = mapfn(array.slice(start, pos), previousKey, start, pos);
if (v) {
result.push(v);
}
start = pos;
}
previousKey = key;
pos++;
}
}
return result;
}
function some(array, predicate) {
if (array !== void 0) {
if (predicate !== void 0) {
for (let i = 0; i < array.length; i++) {
if (predicate(array[i])) {
return true;
}
}
} else {
return array.length > 0;
}
}
return false;
}
function getRangesWhere(arr, pred, cb) {
let start;
for (let i = 0; i < arr.length; i++) {
if (pred(arr[i])) {
start = start === void 0 ? i : start;
} else {
if (start !== void 0) {
cb(start, i);
start = void 0;
}
}
}
if (start !== void 0) cb(start, arr.length);
}
function concatenate(array1, array2) {
if (array2 === void 0 || array2.length === 0) return array1;
if (array1 === void 0 || array1.length === 0) return array2;
return [...array1, ...array2];
}
function selectIndex(_, i) {
return i;
}
function indicesOf(array) {
return array.map(selectIndex);
}
function deduplicateRelational(array, equalityComparer, comparer) {
const indices = indicesOf(array);
stableSortIndices(array, indices, comparer);
let last2 = array[indices[0]];
const deduplicated = [indices[0]];
for (let i = 1; i < indices.length; i++) {
const index = indices[i];
const item = array[index];
if (!equalityComparer(last2, item)) {
deduplicated.push(index);
last2 = item;
}
}
deduplicated.sort();
return deduplicated.map((i) => array[i]);
}
function deduplicateEquality(array, equalityComparer) {
const result = [];
for (let i = 0; i < array.length; i++) {
pushIfUnique(result, array[i], equalityComparer);
}
return result;
}
function deduplicate(array, equalityComparer, comparer) {
return array.length === 0 ? [] : array.length === 1 ? array.slice() : comparer ? deduplicateRelational(array, equalityComparer, comparer) : deduplicateEquality(array, equalityComparer);
}
function deduplicateSorted(array, comparer) {
if (array.length === 0) return emptyArray;
let last2 = array[0];
const deduplicated = [last2];
for (let i = 1; i < array.length; i++) {
const next = array[i];
switch (comparer(next, last2)) {
// equality comparison
case true:
// relational comparison
// falls through
case 0 /* EqualTo */:
continue;
case -1 /* LessThan */:
return Debug.fail("Array is unsorted.");
}
deduplicated.push(last2 = next);
}
return deduplicated;
}
function insertSorted(array, insert, compare, equalityComparer, allowDuplicates) {
if (array.length === 0) {
array.push(insert);
return true;
}
const insertIndex = binarySearch(array, insert, identity, compare);
if (insertIndex < 0) {
if (equalityComparer && !allowDuplicates) {
const idx = ~insertIndex;
if (idx > 0 && equalityComparer(insert, array[idx - 1])) {
return false;
}
if (idx < array.length && equalityComparer(insert, array[idx])) {
array.splice(idx, 1, insert);
return true;
}
}
array.splice(~insertIndex, 0, insert);
return true;
}
if (allowDuplicates) {
array.splice(insertIndex, 0, insert);
return true;
}
return false;
}
function sortAndDeduplicate(array, comparer, equalityComparer) {
return deduplicateSorted(toSorted(array, comparer), equalityComparer ?? comparer ?? compareStringsCaseSensitive);
}
function arrayIsEqualTo(array1, array2, equalityComparer = equateValues) {
if (array1 === void 0 || array2 === void 0) {
return array1 === array2;
}
if (array1.length !== array2.length) {
return false;
}
for (let i = 0; i < array1.length; i++) {
if (!equalityComparer(array1[i], array2[i], i)) {
return false;
}
}
return true;
}
function compact(array) {
let result;
if (array !== void 0) {
for (let i = 0; i < array.length; i++) {
const v = array[i];
if (result ?? !v) {
result ?? (result = array.slice(0, i));
if (v) {
result.push(v);
}
}
}
}
return result ?? array;
}
function relativeComplement(arrayA, arrayB, comparer) {
if (!arrayB || !arrayA || arrayB.length === 0 || arrayA.length === 0) return arrayB;
const result = [];
loopB:
for (let offsetA = 0, offsetB = 0; offsetB < arrayB.length; offsetB++) {
if (offsetB > 0) {
Debug.assertGreaterThanOrEqual(comparer(arrayB[offsetB], arrayB[offsetB - 1]), 0 /* EqualTo */);
}
loopA:
for (const startA = offsetA; offsetA < arrayA.length; offsetA++) {
if (offsetA > startA) {
Debug.assertGreaterThanOrEqual(comparer(arrayA[offsetA], arrayA[offsetA - 1]), 0 /* EqualTo */);
}
switch (comparer(arrayB[offsetB], arrayA[offsetA])) {
case -1 /* LessThan */:
result.push(arrayB[offsetB]);
continue loopB;
case 0 /* EqualTo */:
continue loopB;
case 1 /* GreaterThan */:
continue loopA;
}
}
}
return result;
}
function append(to, value) {
if (value === void 0) return to;
if (to === void 0) return [value];
to.push(value);
return to;
}
function toOffset(array, offset) {
return offset < 0 ? array.length + offset : offset;
}
function addRange(to, from, start, end) {
if (from === void 0 || from.length === 0) return to;
if (to === void 0) return from.slice(start, end);
start = start === void 0 ? 0 : toOffset(from, start);
end = end === void 0 ? from.length : toOffset(from, end);
for (let i = start; i < end && i < from.length; i++) {
if (from[i] !== void 0) {
to.push(from[i]);
}
}
return to;
}
function pushIfUnique(array, toAdd, equalityComparer) {
if (contains(array, toAdd, equalityComparer)) {
return false;
} else {
array.push(toAdd);
return true;
}
}
function appendIfUnique(array, toAdd, equalityComparer) {
if (array !== void 0) {
pushIfUnique(array, toAdd, equalityComparer);
return array;
} else {
return [toAdd];
}
}
function stableSortIndices(array, indices, comparer) {
indices.sort((x, y) => comparer(array[x], array[y]) || compareValues(x, y));
}
function toSorted(array, comparer) {
return array.length === 0 ? emptyArray : array.slice().sort(comparer);
}
function rangeEquals(array1, array2, pos, end) {
while (pos < end) {
if (array1[pos] !== array2[pos]) {
return false;
}
pos++;
}
return true;
}
var elementAt = !!Array.prototype.at ? (array, offset) => array == null ? void 0 : array.at(offset) : (array, offset) => {
if (array !== void 0) {
offset = toOffset(array, offset);
if (offset < array.length) {
return array[offset];
}
}
return void 0;
};
function firstOrUndefined(array) {
return array === void 0 || array.length === 0 ? void 0 : array[0];
}
function firstOrUndefinedIterator(iter) {
if (iter !== void 0) {
for (const value of iter) {
return value;
}
}
return void 0;
}
function first(array) {
Debug.assert(array.length !== 0);
return array[0];
}
function firstIterator(iter) {
for (const value of iter) {
return value;
}
Debug.fail("iterator is empty");
}
function lastOrUndefined(array) {
return array === void 0 || array.length === 0 ? void 0 : array[array.length - 1];
}
function last(array) {
Debug.assert(array.length !== 0);
return array[array.length - 1];
}
function singleOrUndefined(array) {
return array !== void 0 && array.length === 1 ? array[0] : void 0;
}
function singleOrMany(array) {
return array !== void 0 && array.length === 1 ? array[0] : array;
}
function replaceElement(array, index, value) {
const result = array.slice(0);
result[index] = value;
return result;
}
function binarySearch(array, value, keySelector, keyComparer, offset) {
return binarySearchKey(array, keySelector(value), keySelector, keyComparer, offset);
}
function binarySearchKey(array, key, keySelector, keyComparer, offset) {
if (!some(array)) {
return -1;
}
let low = offset ?? 0;
let high = array.length - 1;
while (low <= high) {
const middle = low + (high - low >> 1);
const midKey = keySelector(array[middle], middle);
switch (keyComparer(midKey, key)) {
case -1 /* LessThan */:
low = middle + 1;
break;
case 0 /* EqualTo */:
return middle;
case 1 /* GreaterThan */:
high = middle - 1;
break;
}
}
return ~low;
}
function reduceLeft(array, f, initial, start, count) {
if (array && array.length > 0) {
const size = array.length;
if (size > 0) {
let pos = start === void 0 || start < 0 ? 0 : start;
const end = count === void 0 || pos + count > size - 1 ? size - 1 : pos + count;
let result;
if (arguments.length <= 2) {
result = array[pos];
pos++;
} else {
result = initial;
}
while (pos <= end) {
result = f(result, array[pos], pos);
pos++;
}
return result;
}
}
return initial;
}
var hasOwnProperty = Object.prototype.hasOwnProperty;
function hasProperty(map2, key) {
return hasOwnProperty.call(map2, key);
}
function getOwnKeys(map2) {
const keys = [];
for (const key in map2) {
if (hasOwnProperty.call(map2, key)) {
keys.push(key);
}
}
return keys;
}
function getOwnValues(collection) {
const values = [];
for (const key in collection) {
if (hasOwnProperty.call(collection, key)) {
values.push(collection[key]);
}
}
return values;
}
function arrayOf(count, f) {
const result = new Array(count);
for (let i = 0; i < count; i++) {
result[i] = f(i);
}
return result;
}
function arrayFrom(iterator, map2) {
const result = [];
for (const value of iterator) {
result.push(map2 ? map2(value) : value);
}
return result;
}
function assign(t, ...args) {
for (const arg of args) {
if (arg === void 0) continue;
for (const p in arg) {
if (hasProperty(arg, p)) {
t[p] = arg[p];
}
}
}
return t;
}
function equalOwnProperties(left, right, equalityComparer = equateValues) {
if (left === right) return true;
if (!left || !right) return false;
for (const key in left) {
if (hasOwnProperty.call(left, key)) {
if (!hasOwnProperty.call(right, key)) return false;
if (!equalityComparer(left[key], right[key])) return false;
}
}
for (const key in right) {
if (hasOwnProperty.call(right, key)) {
if (!hasOwnProperty.call(left, key)) return false;
}
}
return true;
}
function arrayToMap(array, makeKey, makeValue = identity) {
const result = /* @__PURE__ */ new Map();
for (let i = 0; i < array.length; i++) {
const value = array[i];
const key = makeKey(value);
if (key !== void 0) result.set(key, makeValue(value));
}
return result;
}
function arrayToMultiMap(values, makeKey, makeValue = identity) {
const result = createMultiMap();
for (let i = 0; i < values.length; i++) {
const value = values[i];
result.add(makeKey(value), makeValue(value));
}
return result;
}
function group(values, getGroupId, resultSelector = identity) {
return arrayFrom(arrayToMultiMap(values, getGroupId).values(), resultSelector);
}
function groupBy(values, keySelector) {
const result = {};
if (values !== void 0) {
for (let i = 0; i < values.length; i++) {
const value = values[i];
const key = `${keySelector(value)}`;
const array = result[key] ?? (result[key] = []);
array.push(value);
}
}
return result;
}
function extend(first2, second) {
const result = {};
for (const id in second) {
if (hasOwnProperty.call(second, id)) {
result[id] = second[id];
}
}
for (const id in first2) {
if (hasOwnProperty.call(first2, id)) {
result[id] = first2[id];
}
}
return result;
}
function copyProperties(first2, second) {
for (const id in second) {
if (hasOwnProperty.call(second, id)) {
first2[id] = second[id];
}
}
}
function maybeBind(obj, fn) {
return fn == null ? void 0 : fn.bind(obj);
}
function createMultiMap() {
const map2 = /* @__PURE__ */ new Map();
map2.add = multiMapAdd;
map2.remove = multiMapRemove;
return map2;
}
function multiMapAdd(key, value) {
let values = this.get(key);
if (values !== void 0) {
values.push(value);
} else {
this.set(key, values = [value]);
}
return values;
}
function multiMapRemove(key, value) {
const values = this.get(key);
if (values !== void 0) {
unorderedRemoveItem(values, value);
if (!values.length) {
this.delete(key);
}
}
}
function createQueue(items) {
const elements = (items == null ? void 0 : items.slice()) ?? [];
let headIndex = 0;
function isEmpty() {
return headIndex === elements.length;
}
function enqueue(...items2) {
elements.push(...items2);
}
function dequeue() {
if (isEmpty()) {
throw new Error("Queue is empty");
}
const result = elements[headIndex];
elements[headIndex] = void 0;
headIndex++;
if (headIndex > 100 && headIndex > elements.length >> 1) {
const newLength = elements.length - headIndex;
elements.copyWithin(
/*target*/
0,
/*start*/
headIndex
);
elements.length = newLength;
headIndex = 0;
}
return result;
}
return {
enqueue,
dequeue,
isEmpty
};
}
function isArray(value) {
return Array.isArray(value);
}
function toArray(value) {
return isArray(value) ? value : [value];
}
function isString(text) {
return typeof text === "string";
}
function isNumber(x) {
return typeof x === "number";
}
function tryCast(value, test) {
return value !== void 0 && test(value) ? value : void 0;
}
function cast(value, test) {
if (value !== void 0 && test(value)) return value;
return Debug.fail(`Invalid cast. The supplied value ${value} did not pass the test '${Debug.getFunctionName(test)}'.`);
}
function noop(_) {
}
function returnFalse() {
return false;
}
function returnTrue() {
return true;
}
function returnUndefined() {
return void 0;
}
function identity(x) {
return x;
}
function toLowerCase(x) {
return x.toLowerCase();
}
var fileNameLowerCaseRegExp = /[^\u0130\u0131\u00DFa-z0-9\\/:\-_. ]+/g;
function toFileNameLowerCase(x) {
return fileNameLowerCaseRegExp.test(x) ? x.replace(fileNameLowerCaseRegExp, toLowerCase) : x;
}
function notImplemented() {
throw new Error("Not implemented");
}
function memoize(callback) {
let value;
return () => {
if (callback) {
value = callback();
callback = void 0;
}
return value;
};
}
function memoizeOne(callback) {
const map2 = /* @__PURE__ */ new Map();
return (arg) => {
const key = `${typeof arg}:${arg}`;
let value = map2.get(key);
if (value === void 0 && !map2.has(key)) {
value = callback(arg);
map2.set(key, value);
}
return value;
};
}
function equateValues(a, b) {
return a === b;
}
function equateStringsCaseInsensitive(a, b) {
return a === b || a !== void 0 && b !== void 0 && a.toUpperCase() === b.toUpperCase();
}
function equateStringsCaseSensitive(a, b) {
return equateValues(a, b);
}
function compareComparableValues(a, b) {
return a === b ? 0 /* EqualTo */ : a === void 0 ? -1 /* LessThan */ : b === void 0 ? 1 /* GreaterThan */ : a < b ? -1 /* LessThan */ : 1 /* GreaterThan */;
}
function compareValues(a, b) {
return compareComparableValues(a, b);
}
function maxBy(arr, init, mapper) {
for (let i = 0; i < arr.length; i++) {
init = Math.max(init, mapper(arr[i]));
}
return init;
}
function min(items, compare) {
return reduceLeft(items, (x, y) => compare(x, y) === -1 /* LessThan */ ? x : y);
}
function compareStringsCaseInsensitive(a, b) {
if (a === b) return 0 /* EqualTo */;
if (a === void 0) return -1 /* LessThan */;
if (b === void 0) return 1 /* GreaterThan */;
a = a.toUpperCase();
b = b.toUpperCase();
return a < b ? -1 /* LessThan */ : a > b ? 1 /* GreaterThan */ : 0 /* EqualTo */;
}
function compareStringsCaseSensitive(a, b) {
return compareComparableValues(a, b);
}
function getStringComparer(ignoreCase) {
return ignoreCase ? compareStringsCaseInsensitive : compareStringsCaseSensitive;
}
var uiComparerCaseSensitive;
var uiLocale;
function setUILocale(value) {
if (uiLocale !== value) {
uiLocale = value;
uiComparerCaseSensitive = void 0;
}
}
function compareBooleans(a, b) {
return compareValues(a ? 1 : 0, b ? 1 : 0);
}
function getSpellingSuggestion(name, candidates, getName) {
const maximumLengthDifference = Math.max(2, Math.floor(name.length * 0.34));
let bestDistance = Math.floor(name.length * 0.4) + 1;
let bestCandidate;
for (const candidate of candidates) {
const candidateName = getName(candidate);
if (candidateName !== void 0 && Math.abs(candidateName.length - name.length) <= maximumLengthDifference) {
if (candidateName === name) {
continue;
}
if (candidateName.length < 3 && candidateName.toLowerCase() !== name.toLowerCase()) {
continue;
}
const distance = levenshteinWithMax(name, candidateName, bestDistance - 0.1);
if (distance === void 0) {
continue;
}
Debug.assert(distance < bestDistance);
bestDistance = distance;
bestCandidate = candidate;
}
}
return bestCandidate;
}
function levenshteinWithMax(s1, s2, max) {
let previous = new Array(s2.length + 1);
let current = new Array(s2.length + 1);
const big = max + 0.01;
for (let i = 0; i <= s2.length; i++) {
previous[i] = i;
}
for (let i = 1; i <= s1.length; i++) {
const c1 = s1.charCodeAt(i - 1);
const minJ = Math.ceil(i > max ? i - max : 1);
const maxJ = Math.floor(s2.length > max + i ? max + i : s2.length);
current[0] = i;
let colMin = i;
for (let j = 1; j < minJ; j++) {
current[j] = big;
}
for (let j = minJ; j <= maxJ; j++) {
const substitutionDistance = s1[i - 1].toLowerCase() === s2[j - 1].toLowerCase() ? previous[j - 1] + 0.1 : previous[j - 1] + 2;
const dist = c1 === s2.charCodeAt(j - 1) ? previous[j - 1] : Math.min(
/*delete*/
previous[j] + 1,
/*insert*/
current[j - 1] + 1,
/*substitute*/
substitutionDistance
);
current[j] = dist;
colMin = Math.min(colMin, dist);
}
for (let j = maxJ + 1; j <= s2.length; j++) {
current[j] = big;
}
if (colMin > max) {
return void 0;
}
const temp = previous;
previous = current;
current = temp;
}
const res = previous[s2.length];
return res > max ? void 0 : res;
}
function endsWith(str, suffix, ignoreCase) {
const expectedPos = str.length - suffix.length;
return expectedPos >= 0 && (ignoreCase ? equateStringsCaseInsensitive(str.slice(expectedPos), suffix) : str.indexOf(suffix, expectedPos) === expectedPos);
}
function removeSuffix(str, suffix) {
return endsWith(str, suffix) ? str.slice(0, str.length - suffix.length) : str;
}
function orderedRemoveItem(array, item) {
for (let i = 0; i < array.length; i++) {
if (array[i] === item) {
orderedRemoveItemAt(array, i);
return true;
}
}
return false;
}
function orderedRemoveItemAt(array, index) {
for (let i = index; i < array.length - 1; i++) {
array[i] = array[i + 1];
}
array.pop();
}
function unorderedRemoveItemAt(array, index) {
array[index] = array[array.length - 1];
array.pop();
}
function unorderedRemoveItem(array, item) {
return unorderedRemoveFirstItemWhere(array, (element) => element === item);
}
function unorderedRemoveFirstItemWhere(array, predicate) {
for (let i = 0; i < array.length; i++) {
if (predicate(array[i])) {
unorderedRemoveItemAt(array, i);
return true;
}
}
return false;
}
function createGetCanonicalFileName(useCaseSensitiveFileNames2) {
return useCaseSensitiveFileNames2 ? identity : toFileNameLowerCase;
}
function patternText({ prefix, suffix }) {
return `${prefix}*${suffix}`;
}
function matchedText(pattern, candidate) {
Debug.assert(isPatternMatch(pattern, candidate));
return candidate.substring(pattern.prefix.length, candidate.length - pattern.suffix.length);
}
function findBestPatternMatch(values, getPattern, candidate) {
let matchedValue;
let longestMatchPrefixLength = -1;
for (let i = 0; i < values.length; i++) {
const v = values[i];
const pattern = getPattern(v);
if (pattern.prefix.length > longestMatchPrefixLength && isPatternMatch(pattern, candidate)) {
longestMatchPrefixLength = pattern.prefix.length;
matchedValue = v;
}
}
return matchedValue;
}
function startsWith(str, prefix, ignoreCase) {
return ignoreCase ? equateStringsCaseInsensitive(str.slice(0, prefix.length), prefix) : str.lastIndexOf(prefix, 0) === 0;
}
function removePrefix(str, prefix) {
return startsWith(str, prefix) ? str.substr(prefix.length) : str;
}
function isPatternMatch({ prefix, suffix }, candidate) {
return candidate.length >= prefix.length + suffix.length && startsWith(candidate, prefix) && endsWith(candidate, suffix);
}
function and(f, g) {
return (arg) => f(arg) && g(arg);
}
function or(...fs) {
return (...args) => {
let lastResult;
for (const f of fs) {
lastResult = f(...args);
if (lastResult) {
return lastResult;
}
}
return lastResult;
};
}
function not(fn) {
return (...args) => !fn(...args);
}
function assertType(_) {
}
function singleElementArray(t) {
return t === void 0 ? void 0 : [t];
}
function enumerateInsertsAndDeletes(newItems, oldItems, comparer, inserted, deleted, unchanged) {
unchanged ?? (unchanged = noop);
let newIndex = 0;
let oldIndex = 0;
const newLen = newItems.length;
const oldLen = oldItems.length;
let hasChanges = false;
while (newIndex < newLen && oldIndex < oldLen) {
const newItem = newItems[newIndex];
const oldItem = oldItems[oldIndex];
const compareResult = comparer(newItem, oldItem);
if (compareResult === -1 /* LessThan */) {
inserted(newItem);
newIndex++;
hasChanges = true;
} else if (compareResult === 1 /* GreaterThan */) {
deleted(oldItem);
oldIndex++;
hasChanges = true;
} else {
unchanged(oldItem, newItem);
newIndex++;
oldIndex++;
}
}
while (newIndex < newLen) {
inserted(newItems[newIndex++]);
hasChanges = true;
}
while (oldIndex < oldLen) {
deleted(oldItems[oldIndex++]);
hasChanges = true;
}
return hasChanges;
}
function cartesianProduct(arrays) {
const result = [];
cartesianProductWorker(
arrays,
result,
/*outer*/
void 0,
0
);
return result;
}
function cartesianProductWorker(arrays, result, outer, index) {
for (const element of arrays[index]) {
let inner;
if (outer) {
inner = outer.slice();
inner.push(element);
} else {
inner = [element];
}
if (index === arrays.length - 1) {
result.push(inner);
} else {
cartesianProductWorker(arrays, result, inner, index + 1);
}
}
}
function takeWhile(array, predicate) {
if (array !== void 0) {
const len = array.length;
let index = 0;
while (index < len && predicate(array[index])) {
index++;
}
return array.slice(0, index);
}
}
function skipWhile(array, predicate) {
if (array !== void 0) {
const len = array.length;
let index = 0;
while (index < len && predicate(array[index])) {
index++;
}
return array.slice(index);
}
}
function isNodeLikeSystem() {
return typeof process !== "undefined" && !!process.nextTick && !process.browser && typeof require !== "undefined";
}
// src/compiler/debug.ts
var Debug;
((Debug2) => {
let currentAssertionLevel = 0 /* None */;
Debug2.currentLogLevel = 2 /* Warning */;
Debug2.isDebugging = false;
function shouldLog(level) {
return Debug2.currentLogLevel <= level;
}
Debug2.shouldLog = shouldLog;
function logMessage(level, s) {
if (Debug2.loggingHost && shouldLog(level)) {
Debug2.loggingHost.log(level, s);
}
}
function log(s) {
logMessage(3 /* Info */, s);
}
Debug2.log = log;
((_log) => {
function error(s) {
logMessage(1 /* Error */, s);
}
_log.error = error;
function warn(s) {
logMessage(2 /* Warning */, s);
}
_log.warn = warn;
function log2(s) {
logMessage(3 /* Info */, s);
}
_log.log = log2;
function trace2(s) {
logMessage(4 /* Verbose */, s);
}
_log.trace = trace2;
})(log = Debug2.log || (Debug2.log = {}));
const assertionCache = {};
function getAssertionLevel() {
return currentAssertionLevel;
}
Debug2.getAssertionLevel = getAssertionLevel;
function setAssertionLevel(level) {
const prevAssertionLevel = currentAssertionLevel;
currentAssertionLevel = level;
if (level > prevAssertionLevel) {
for (const key of getOwnKeys(assertionCache)) {
const cachedFunc = assertionCache[key];
if (cachedFunc !== void 0 && Debug2[key] !== cachedFunc.assertion && level >= cachedFunc.level) {
Debug2[key] = cachedFunc;
assertionCache[key] = void 0;
}
}
}
}
Debug2.setAssertionLevel = setAssertionLevel;
function shouldAssert(level) {
return currentAssertionLevel >= level;
}
Debug2.shouldAssert = shouldAssert;
function shouldAssertFunction(level, name) {
if (!shouldAssert(level)) {
assertionCache[name] = { level, assertion: Debug2[name] };
Debug2[name] = noop;
return false;
}
return true;
}
function fail(message, stackCrawlMark) {
debugger;
const e = new Error(message ? `Debug Failure. ${message}` : "Debug Failure.");
if (Error.captureStackTrace) {
Error.captureStackTrace(e, stackCrawlMark || fail);
}
throw e;
}
Debug2.fail = fail;
function failBadSyntaxKind(node, message, stackCrawlMark) {
return fail(
`${message || "Unexpected node."}\r
Node ${formatSyntaxKind(node.kind)} was unexpected.`,
stackCrawlMark || failBadSyntaxKind
);
}
Debug2.failBadSyntaxKind = failBadSyntaxKind;
function assert(expression, message, verboseDebugInfo, stackCrawlMark) {
if (!expression) {
message = message ? `False expression: ${message}` : "False expression.";
if (verboseDebugInfo) {
message += "\r\nVerbose Debug Information: " + (typeof verboseDebugInfo === "string" ? verboseDebugInfo : verboseDebugInfo());
}
fail(message, stackCrawlMark || assert);
}
}
Debug2.assert = assert;
function assertEqual(a, b, msg, msg2, stackCrawlMark) {
if (a !== b) {
const message = msg ? msg2 ? `${msg} ${msg2}` : msg : "";
fail(`Expected ${a} === ${b}. ${message}`, stackCrawlMark || assertEqual);
}
}
Debug2.assertEqual = assertEqual;
function assertLessThan(a, b, msg, stackCrawlMark) {
if (a >= b) {
fail(`Expected ${a} < ${b}. ${msg || ""}`, stackCrawlMark || assertLessThan);
}
}
Debug2.assertLessThan = assertLessThan;
function assertLessThanOrEqual(a, b, stackCrawlMark) {
if (a > b) {
fail(`Expected ${a} <= ${b}`, stackCrawlMark || assertLessThanOrEqual);
}
}
Debug2.assertLessThanOrEqual = assertLessThanOrEqual;
function assertGreaterThanOrEqual(a, b, stackCrawlMark) {
if (a < b) {
fail(`Expected ${a} >= ${b}`, stackCrawlMark || assertGreaterThanOrEqual);
}
}
Debug2.assertGreaterThanOrEqual = assertGreaterThanOrEqual;
function assertIsDefined(value, message, stackCrawlMark) {
if (value === void 0 || value === null) {
fail(message, stackCrawlMark || assertIsDefined);
}
}
Debug2.assertIsDefined = assertIsDefined;
function checkDefined(value, message, stackCrawlMark) {
assertIsDefined(value, message, stackCrawlMark || checkDefined);
return value;
}
Debug2.checkDefined = checkDefined;
function assertEachIsDefined(value, message, stackCrawlMark) {
for (const v of value) {
assertIsDefined(v, message, stackCrawlMark || assertEachIsDefined);
}
}
Debug2.assertEachIsDefined = assertEachIsDefined;
function checkEachDefined(value, message, stackCrawlMark) {
assertEachIsDefined(value, message, stackCrawlMark || checkEachDefined);
return value;
}
Debug2.checkEachDefined = checkEachDefined;
function assertNever(member, message = "Illegal value:", stackCrawlMark) {
const detail = typeof member === "object" && hasProperty(member, "kind") && hasProperty(member, "pos") ? "SyntaxKind: " + formatSyntaxKind(member.kind) : JSON.stringify(member);
return fail(`${message} ${detail}`, stackCrawlMark || assertNever);
}
Debug2.assertNever = assertNever;
function assertEachNode(nodes, test, message, stackCrawlMark) {
if (shouldAssertFunction(1 /* Normal */, "assertEachNode")) {
assert(
test === void 0 || every(nodes, test),
message || "Unexpected node.",
() => `Node array did not pass test '${getFunctionName(test)}'.`,
stackCrawlMark || assertEachNode
);
}
}
Debug2.assertEachNode = assertEachNode;
function assertNode(node, test, message, stackCrawlMark) {
if (shouldAssertFunction(1 /* Normal */, "assertNode")) {
assert(
node !== void 0 && (test === void 0 || test(node)),
message || "Unexpected node.",
() => `Node ${formatSyntaxKind(node == null ? void 0 : node.kind)} did not pass test '${getFunctionName(test)}'.`,
stackCrawlMark || assertNode
);
}
}
Debug2.assertNode = assertNode;
function assertNotNode(node, test, message, stackCrawlMark) {
if (shouldAssertFunction(1 /* Normal */, "assertNotNode")) {
assert(
node === void 0 || test === void 0 || !test(node),
message || "Unexpected node.",
() => `Node ${formatSyntaxKind(node.kind)} should not have passed test '${getFunctionName(test)}'.`,
stackCrawlMark || assertNotNode
);
}
}
Debug2.assertNotNode = assertNotNode;
function assertOptionalNode(node, test, message, stackCrawlMark) {
if (shouldAssertFunction(1 /* Normal */, "assertOptionalNode")) {
assert(
test === void 0 || node === void 0 || test(node),
message || "Unexpected node.",
() => `Node ${formatSyntaxKind(node == null ? void 0 : node.kind)} did not pass test '${getFunctionName(test)}'.`,
stackCrawlMark || assertOptionalNode
);
}
}
Debug2.assertOptionalNode = assertOptionalNode;
function assertOptionalToken(node, kind, message, stackCrawlMark) {
if (shouldAssertFunction(1 /* Normal */, "assertOptionalToken")) {
assert(
kind === void 0 || node === void 0 || node.kind === kind,
message || "Unexpected node.",
() => `Node ${formatSyntaxKind(node == null ? void 0 : node.kind)} was not a '${formatSyntaxKind(kind)}' token.`,
stackCrawlMark || assertOptionalToken
);
}
}
Debug2.assertOptionalToken = assertOptionalToken;
function assertMissingNode(node, message, stackCrawlMark) {
if (shouldAssertFunction(1 /* Normal */, "assertMissingNode")) {
assert(
node === void 0,
message || "Unexpected node.",
() => `Node ${formatSyntaxKind(node.kind)} was unexpected'.`,
stackCrawlMark || assertMissingNode
);
}
}
Debug2.assertMissingNode = assertMissingNode;
function type(_value) {
}
Debug2.type = type;
function getFunctionName(func) {
if (typeof func !== "function") {
return "";
} else if (hasProperty(func, "name")) {
return func.name;
} else {
const text = Function.prototype.toString.call(func);
const match = /^function\s+([\w$]+)\s*\(/.exec(text);
return match ? match[1] : "";
}
}
Debug2.getFunctionName = getFunctionName;
function formatSymbol(symbol) {
return `{ name: ${unescapeLeadingUnderscores(symbol.escapedName)}; flags: ${formatSymbolFlags(symbol.flags)}; declarations: ${map(symbol.declarations, (node) => formatSyntaxKind(node.kind))} }`;
}
Debug2.formatSymbol = formatSymbol;
function formatEnum(value = 0, enumObject, isFlags) {
const members = getEnumMembers(enumObject);
if (value === 0) {
return members.length > 0 && members[0][0] === 0 ? members[0][1] : "0";
}
if (isFlags) {
const result = [];
let remainingFlags = value;
for (const [enumValue, enumName] of members) {
if (enumValue > value) {
break;
}
if (enumValue !== 0 && enumValue & value) {
result.push(enumName);
remainingFlags &= ~enumValue;
}
}
if (remainingFlags === 0) {
return result.join("|");
}
} else {
for (const [enumValue, enumName] of members) {
if (enumValue === value) {
return enumName;
}
}
}
return value.toString();
}
Debug2.formatEnum = formatEnum;
const enumMemberCache = /* @__PURE__ */ new Map();
function getEnumMembers(enumObject) {
const existing = enumMemberCache.get(enumObject);
if (existing) {
return existing;
}
const result = [];
for (const name in enumObject) {
const value = enumObject[name];
if (typeof value === "number") {
result.push([value, name]);
}
}
const sorted = toSorted(result, (x, y) => compareValues(x[0], y[0]));
enumMemberCache.set(enumObject, sorted);
return sorted;
}
function formatSyntaxKind(kind) {
return formatEnum(
kind,
SyntaxKind,
/*isFlags*/
false
);
}
Debug2.formatSyntaxKind = formatSyntaxKind;
function formatSnippetKind(kind) {
return formatEnum(
kind,
SnippetKind,
/*isFlags*/
false
);
}
Debug2.formatSnippetKind = formatSnippetKind;
function formatScriptKind(kind) {
return formatEnum(
kind,
ScriptKind,
/*isFlags*/
false
);
}
Debug2.formatScriptKind = formatScriptKind;
function formatNodeFlags(flags) {
return formatEnum(
flags,
NodeFlags,
/*isFlags*/
true
);
}
Debug2.formatNodeFlags = formatNodeFlags;
function formatNodeCheckFlags(flags) {
return formatEnum(
flags,
NodeCheckFlags,
/*isFlags*/
true
);
}
Debug2.formatNodeCheckFlags = formatNodeCheckFlags;
function formatModifierFlags(flags) {
return formatEnum(
flags,
ModifierFlags,
/*isFlags*/
true
);
}
Debug2.formatModifierFlags = formatModifierFlags;
function formatTransformFlags(flags) {
return formatEnum(
flags,
TransformFlags,
/*isFlags*/
true
);
}
Debug2.formatTransformFlags = formatTransformFlags;
function formatEmitFlags(flags) {
return formatEnum(
flags,
EmitFlags,
/*isFlags*/
true
);
}
Debug2.formatEmitFlags = formatEmitFlags;
function formatSymbolFlags(flags) {
return formatEnum(
flags,
SymbolFlags,
/*isFlags*/
true
);
}
Debug2.formatSymbolFlags = formatSymbolFlags;
function formatTypeFlags(flags) {
return formatEnum(
flags,
TypeFlags,
/*isFlags*/
true
);
}
Debug2.formatTypeFlags = formatTypeFlags;
function formatSignatureFlags(flags) {
return formatEnum(
flags,
SignatureFlags,
/*isFlags*/
true
);
}
Debug2.formatSignatureFlags = formatSignatureFlags;
function formatObjectFlags(flags) {
return formatEnum(
flags,
ObjectFlags,
/*isFlags*/
true
);
}
Debug2.formatObjectFlags = formatObjectFlags;
function formatFlowFlags(flags) {
return formatEnum(
flags,
FlowFlags,
/*isFlags*/
true
);
}
Debug2.formatFlowFlags = formatFlowFlags;
function formatRelationComparisonResult(result) {
return formatEnum(
result,
RelationComparisonResult,
/*isFlags*/
true
);
}
Debug2.formatRelationComparisonResult = formatRelationComparisonResult;
function formatCheckMode(mode) {
return formatEnum(
mode,
CheckMode,
/*isFlags*/
true
);
}
Debug2.formatCheckMode = formatCheckMode;
function formatSignatureCheckMode(mode) {
return formatEnum(
mode,
SignatureCheckMode,
/*isFlags*/
true
);
}
Debug2.formatSignatureCheckMode = formatSignatureCheckMode;
function formatTypeFacts(facts) {
return formatEnum(
facts,
TypeFacts,
/*isFlags*/
true
);
}
Debug2.formatTypeFacts = formatTypeFacts;
let isDebugInfoEnabled = false;
let flowNodeProto;
function attachFlowNodeDebugInfoWorker(flowNode) {
if (!("__debugFlowFlags" in flowNode)) {
Object.defineProperties(flowNode, {
// for use with vscode-js-debug's new customDescriptionGenerator in launch.json
__tsDebuggerDisplay: {
value() {
const flowHeader = this.flags & 2 /* Start */ ? "FlowStart" : this.flags & 4 /* BranchLabel */ ? "FlowBranchLabel" : this.flags & 8 /* LoopLabel */ ? "FlowLoopLabel" : this.flags & 16 /* Assignment */ ? "FlowAssignment" : this.flags & 32 /* TrueCondition */ ? "FlowTrueCondition" : this.flags & 64 /* FalseCondition */ ? "FlowFalseCondition" : this.flags & 128 /* SwitchClause */ ? "FlowSwitchClause" : this.flags & 256 /* ArrayMutation */ ? "FlowArrayMutation" : this.flags & 512 /* Call */ ? "FlowCall" : this.flags & 1024 /* ReduceLabel */ ? "FlowReduceLabel" : this.flags & 1 /* Unreachable */ ? "FlowUnreachable" : "UnknownFlow";
const remainingFlags = this.flags & ~(2048 /* Referenced */ - 1);
return `${flowHeader}${remainingFlags ? ` (${formatFlowFlags(remainingFlags)})` : ""}`;
}
},
__debugFlowFlags: {
get() {
return formatEnum(
this.flags,
FlowFlags,
/*isFlags*/
true
);
}
},
__debugToString: {
value() {
return formatControlFlowGraph(this);
}
}
});
}
}
function attachFlowNodeDebugInfo(flowNode) {
if (isDebugInfoEnabled) {
if (typeof Object.setPrototypeOf === "function") {
if (!flowNodeProto) {
flowNodeProto = Object.create(Object.prototype);
attachFlowNodeDebugInfoWorker(flowNodeProto);
}
Object.setPrototypeOf(flowNode, flowNodeProto);
} else {
attachFlowNodeDebugInfoWorker(flowNode);
}
}
return flowNode;
}
Debug2.attachFlowNodeDebugInfo = attachFlowNodeDebugInfo;
let nodeArrayProto;
function attachNodeArrayDebugInfoWorker(array) {
if (!("__tsDebuggerDisplay" in array)) {
Object.defineProperties(array, {
__tsDebuggerDisplay: {
value(defaultValue) {
defaultValue = String(defaultValue).replace(/(?:,[\s\w]+:[^,]+)+\]$/, "]");
return `NodeArray ${defaultValue}`;
}
}
});
}
}
function attachNodeArrayDebugInfo(array) {
if (isDebugInfoEnabled) {
if (typeof Object.setPrototypeOf === "function") {
if (!nodeArrayProto) {
nodeArrayProto = Object.create(Array.prototype);
attachNodeArrayDebugInfoWorker(nodeArrayProto);
}
Object.setPrototypeOf(array, nodeArrayProto);
} else {
attachNodeArrayDebugInfoWorker(array);
}
}
}
Debug2.attachNodeArrayDebugInfo = attachNodeArrayDebugInfo;
function enableDebugInfo() {
if (isDebugInfoEnabled) return;
const weakTypeTextMap = /* @__PURE__ */ new WeakMap();
const weakNodeTextMap = /* @__PURE__ */ new WeakMap();
Object.defineProperties(objectAllocator.getSymbolConstructor().prototype, {
// for use with vscode-js-debug's new customDescriptionGenerator in launch.json
__tsDebuggerDisplay: {
value() {
const symbolHeader = this.flags & 33554432 /* Transient */ ? "TransientSymbol" : "Symbol";
const remainingSymbolFlags = this.flags & ~33554432 /* Transient */;
return `${symbolHeader} '${symbolName(this)}'${remainingSymbolFlags ? ` (${formatSymbolFlags(remainingSymbolFlags)})` : ""}`;
}
},
__debugFlags: {
get() {
return formatSymbolFlags(this.flags);
}
}
});
Object.defineProperties(objectAllocator.getTypeConstructor().prototype, {
// for use with vscode-js-debug's new customDescriptionGenerator in launch.json
__tsDebuggerDisplay: {
value() {
const typeHeader = this.flags & 67359327 /* Intrinsic */ ? `IntrinsicType ${this.intrinsicName}${this.debugIntrinsicName ? ` (${this.debugIntrinsicName})` : ""}` : this.flags & 98304 /* Nullable */ ? "NullableType" : this.flags & 384 /* StringOrNumberLiteral */ ? `LiteralType ${JSON.stringify(this.value)}` : this.flags & 2048 /* BigIntLiteral */ ? `LiteralType ${this.value.negative ? "-" : ""}${this.value.base10Value}n` : this.flags & 8192 /* UniqueESSymbol */ ? "UniqueESSymbolType" : this.flags & 32 /* Enum */ ? "EnumType" : this.flags & 1048576 /* Union */ ? "UnionType" : this.flags & 2097152 /* Intersection */ ? "IntersectionType" : this.flags & 4194304 /* Index */ ? "IndexType" : this.flags & 8388608 /* IndexedAccess */ ? "IndexedAccessType" : this.flags & 16777216 /* Conditional */ ? "ConditionalType" : this.flags & 33554432 /* Substitution */ ? "SubstitutionType" : this.flags & 262144 /* TypeParameter */ ? "TypeParameter" : this.flags & 524288 /* Object */ ? this.objectFlags & 3 /* ClassOrInterface */ ? "InterfaceType" : this.objectFlags & 4 /* Reference */ ? "TypeReference" : this.objectFlags & 8 /* Tuple */ ? "TupleType" : this.objectFlag