UNPKG

typescript

Version:

TypeScript is a language for application scale JavaScript development

1,507 lines (1,499 loc) • 1.74 MB
/*! ***************************************************************************** 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"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/typingsInstaller/nodeTypingsInstaller.ts var nodeTypingsInstaller_exports = {}; __export(nodeTypingsInstaller_exports, { NodeTypingsInstaller: () => NodeTypingsInstaller }); module.exports = __toCommonJS(nodeTypingsInstaller_exports); var fs = __toESM(require("fs")); var path = __toESM(require("path")); // src/compiler/corePublic.ts var versionMajorMinor = "5.2"; var version = "5.2.2"; // src/compiler/core.ts var emptyArray = []; var emptyMap = /* @__PURE__ */ new Map(); function length(array) { return array ? array.length : 0; } function forEach(array, callback) { if (array) { for (let i = 0; i < array.length; i++) { const result = callback(array[i], i); if (result) { return result; } } } return void 0; } 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) { 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 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 contains(array, value, equalityComparer = equateValues) { if (array) { for (const v of array) { if (equalityComparer(v, 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 filter(array, f) { if (array) { 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 map(array, f) { let result; if (array) { 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) { 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 (const v of array) { if (v) { if (isArray(v)) { addRange(result, v); } else { result.push(v); } } } return result; } function flatMap(array, mapfn) { let result; if (array) { 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 sameFlatMap(array, mapfn) { let result; if (array) { 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) { 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 some(array, predicate) { if (array) { if (predicate) { for (const v of array) { if (predicate(v)) { return true; } } } else { return array.length > 0; } } return false; } function concatenate(array1, array2) { if (!some(array2)) return array1; if (!some(array1)) 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 (const item of array) { pushIfUnique(result, item, 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 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) { 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 sort(array, comparer) { return array.length === 0 ? array : array.slice().sort(comparer); } function stableSort(array, comparer) { const indices = indicesOf(array); stableSortIndices(array, indices, comparer); return indices.map((i) => array[i]); } var elementAt = !!Array.prototype.at ? (array, offset) => array == null ? void 0 : array.at(offset) : (array, offset) => { if (array) { 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 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 && array.length === 1 ? array[0] : void 0; } 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 getProperty(map2, key) { return hasOwnProperty.call(map2, key) ? map2[key] : void 0; } function getOwnKeys(map2) { const keys = []; for (const key in map2) { if (hasOwnProperty.call(map2, key)) { keys.push(key); } } return keys; } function arrayFrom(iterator, map2) { const result = []; for (const value of iterator) { result.push(map2 ? map2(value) : value); } return result; } function arrayToMap(array, makeKey, makeValue = identity) { const result = /* @__PURE__ */ new Map(); for (const value of array) { const key = makeKey(value); if (key !== void 0) result.set(key, makeValue(value)); } return result; } 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) { values.push(value); } else { this.set(key, values = [value]); } return values; } function multiMapRemove(key, value) { const values = this.get(key); if (values) { unorderedRemoveItem(values, value); if (!values.length) { this.delete(key); } } } function isArray(value) { return Array.isArray(value); } function toArray(value) { return isArray(value) ? value : [value]; } function isString(text) { return typeof text === "string"; } 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 returnTrue() { return true; } 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 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 createUIStringComparer = (() => { let defaultComparer; let enUSComparer; const stringComparerFactory = getStringComparerFactory(); return createStringComparer; function compareWithCallback(a, b, comparer) { if (a === b) return 0 /* EqualTo */; if (a === void 0) return -1 /* LessThan */; if (b === void 0) return 1 /* GreaterThan */; const value = comparer(a, b); return value < 0 ? -1 /* LessThan */ : value > 0 ? 1 /* GreaterThan */ : 0 /* EqualTo */; } function createIntlCollatorStringComparer(locale) { const comparer = new Intl.Collator(locale, { usage: "sort", sensitivity: "variant" }).compare; return (a, b) => compareWithCallback(a, b, comparer); } function createLocaleCompareStringComparer(locale) { if (locale !== void 0) return createFallbackStringComparer(); return (a, b) => compareWithCallback(a, b, compareStrings); function compareStrings(a, b) { return a.localeCompare(b); } } function createFallbackStringComparer() { return (a, b) => compareWithCallback(a, b, compareDictionaryOrder); function compareDictionaryOrder(a, b) { return compareStrings(a.toUpperCase(), b.toUpperCase()) || compareStrings(a, b); } function compareStrings(a, b) { return a < b ? -1 /* LessThan */ : a > b ? 1 /* GreaterThan */ : 0 /* EqualTo */; } } function getStringComparerFactory() { if (typeof Intl === "object" && typeof Intl.Collator === "function") { return createIntlCollatorStringComparer; } if (typeof String.prototype.localeCompare === "function" && typeof String.prototype.toLocaleUpperCase === "function" && "a".localeCompare("B") < 0) { return createLocaleCompareStringComparer; } return createFallbackStringComparer; } function createStringComparer(locale) { if (locale === void 0) { return defaultComparer || (defaultComparer = stringComparerFactory(locale)); } else if (locale === "en-US") { return enUSComparer || (enUSComparer = stringComparerFactory(locale)); } else { return stringComparerFactory(locale); } } })(); 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) { const expectedPos = str.length - suffix.length; return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos; } function stringContains(str, substring) { return str.indexOf(substring) !== -1; } function removeMinAndVersionNumbers(fileName) { let end = fileName.length; for (let pos = end - 1; pos > 0; pos--) { let ch = fileName.charCodeAt(pos); if (ch >= 48 /* _0 */ && ch <= 57 /* _9 */) { do { --pos; ch = fileName.charCodeAt(pos); } while (pos > 0 && ch >= 48 /* _0 */ && ch <= 57 /* _9 */); } else if (pos > 4 && (ch === 110 /* n */ || ch === 78 /* N */)) { --pos; ch = fileName.charCodeAt(pos); if (ch !== 105 /* i */ && ch !== 73 /* I */) { break; } --pos; ch = fileName.charCodeAt(pos); if (ch !== 109 /* m */ && ch !== 77 /* M */) { break; } --pos; ch = fileName.charCodeAt(pos); } else { break; } if (ch !== 45 /* minus */ && ch !== 46 /* dot */) { break; } end = pos; } return end === fileName.length ? fileName : fileName.slice(0, end); } 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 (const v of values) { const pattern = getPattern(v); if (isPatternMatch(pattern, candidate) && pattern.prefix.length > longestMatchPrefixLength) { longestMatchPrefixLength = pattern.prefix.length; matchedValue = v; } } return matchedValue; } function startsWith(str, prefix) { return str.lastIndexOf(prefix, 0) === 0; } 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 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 padLeft(s, length2, padString = " ") { return length2 <= s.length ? s : padString.repeat(length2 - s.length) + s; } var trimString = !!String.prototype.trim ? (s) => s.trim() : (s) => trimStringEnd(trimStringStart(s)); var trimStringEnd = !!String.prototype.trimEnd ? (s) => s.trimEnd() : trimEndImpl; var trimStringStart = !!String.prototype.trimStart ? (s) => s.trimStart() : (s) => s.replace(/^\s+/g, ""); function trimEndImpl(s) { let end = s.length - 1; while (end >= 0) { if (!isWhiteSpaceLike(s.charCodeAt(end))) break; end--; } return s.slice(0, end + 1); } function isNodeLikeSystem() { return typeof process !== "undefined" && !!process.nextTick && !process.browser && typeof module === "object"; } // 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 log2(s) { logMessage(3 /* Info */, s); } Debug2.log = log2; ((_log) => { function error(s) { logMessage(1 /* Error */, s); } _log.error = error; function warn(s) { logMessage(2 /* Warning */, s); } _log.warn = warn; function log3(s) { logMessage(3 /* Info */, s); } _log.log = log3; function trace2(s) { logMessage(4 /* Verbose */, s); } _log.trace = trace2; })(log2 = 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 = stableSort(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 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); } } } Debug2.attachFlowNodeDebugInfo = attachFlowNodeDebugInfo; let nodeArrayProto; function attachNodeArrayDebugInfoWorker(array) { if (!("__tsDebuggerDisplay" in array)) { Object.defineProperties(array, { __tsDebuggerDisplay: { value(defaultValue) { defaultValue = String(defaultValue).replace(/(?:,[\s\w\d_]+:[^,]+)+\]$/, "]"); 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 & 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 & 67359327 /* Intrinsic */ ? `IntrinsicType ${this.intrinsicName}` : 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.objectFlags & 16 /* Anonymous */ ? "AnonymousType" : this.objectFlags & 32 /* Mapped */ ? "MappedType" : this.objectFlags & 1024 /* ReverseMapped */ ? "ReverseMappedType" : this.objectFlags & 256 /* EvolvingArray */ ? "EvolvingArrayType" : "ObjectType" : "Type"; const remainingObjectFlags = this.flags & 524288 /* Object */ ? this.objectFlags & ~1343 /* ObjectTypeKindMask */ : 0; return `${typeHeader}${this.symbol ? ` '${symbolName(this.symbol)}'` : ""}${remainingObjectFlags ? ` (${formatObjectFlags(remainingObjectFlags)})` : ""}`; } }, __debugFlags: { get() { return formatTypeFlags(this.flags); } }, __debugObjectFlags: { get() { return this.flags & 524288 /* Object */ ? formatObjectFlags(this.objectFlags) : ""; } }, __debugTypeToString: { value() { let text = weakTypeTextMap.get(this); if (text === void 0) { text = this.checker.typeToString(this); weakTypeTextMap.set(this, text); } return text; } } }); Object.defineProperties(objectAllocator.getSignatureConstructor().prototype, { __debugFlags: { get() { return formatSignatureFlags(this.flags); } }, __debugSignatureToString: { value() { var _a; return (_a = this.checker) == null ? void 0 : _a.signatureToString(this); } } }); const nodeConstructors = [ objectAllocator.getNodeConstructor(), objectAllocator.getIdentifierConstructor(), objectAllocator.getTokenConstructor(), objectAllocator.getSourceFileConstructor() ]; for (const ctor of nodeConstructors) { if (!hasProperty(ctor.prototype, "__debugKind")) { Object.defineProperties(ctor.prototype, { // for use with vscode-js-debug's new customDescriptionGenerator in launch.json __tsDebuggerDisplay: { value() { const nodeHeader = isGeneratedIdentifier(this) ? "GeneratedIdentifier" : isIdentifier(this) ? `Identifier '${idText(this)}'` : isPrivateIdentifier(this) ? `PrivateIdentifier '${idText(this)}'` : isStringLiteral(this) ? `StringLiteral ${JSON.stringify(this.text.length < 10 ? this.text : this.text.slice(10) + "...")}` : isNumericLiteral(this) ? `NumericLiteral ${this.text}` : isBigIntLiteral(this) ? `BigIntLiteral ${this.text}n` : isTypeParameterDeclaration(this) ? "TypeParameterDeclaration" : isParameter(this) ? "ParameterDeclaration" : isConstructorDeclaration(this) ? "ConstructorDeclaration" : isGetAccessorDeclaration(this) ? "GetAccessorDeclaration" : isSetAccessorDeclaration(this) ? "SetAccessorDeclaration" : isCallSignatureDeclaration(this) ? "CallSignatureDeclaration" : isConstructSignatureDeclaration(this) ? "ConstructSignatureDeclaration" : isIndexSignatureDeclaration(this) ? "IndexSignatureDeclaration" : isTypePredicateNode(this) ? "TypePredicateNode" : isTypeReferenceNode(this) ? "TypeReferenceNode" : isFunctionTypeNode(this) ? "FunctionTypeNode" : isConstructorTypeNode(this) ? "ConstructorTypeNode" : isTypeQueryNode(this) ? "TypeQueryNode" : isTypeLiteralNode(this) ? "TypeLiteralNode" : isArrayTypeNode(this) ? "ArrayTypeNode" : isTupleTypeNode(this) ? "TupleTypeNode" : isOptionalTypeNode(this) ? "OptionalTypeNode" : isRestTypeNode(this) ? "RestTypeNode" : isUnionTypeNode(this) ? "UnionTypeNode" : isIntersectionTypeNode(this) ? "IntersectionTypeNode" : isConditionalTypeNode(this) ? "ConditionalTypeNode" : isInferTypeNode(this) ? "InferTypeNode" : isParenthesizedTypeNode(this) ? "ParenthesizedTypeNode" : isThisTypeNode(this) ? "ThisTypeNode" : isTypeOperatorNode(this) ? "TypeOperatorNode" : isIndexedAccessTypeNode(this) ? "IndexedAccessTypeNode" : isMappedTypeNode(this) ? "MappedTypeNode" : isLiteralTypeNode(this) ? "LiteralTypeNode" : isNamedTupleMember(this) ? "NamedTupleMember" : isImportTypeNode(this) ? "ImportTypeNode" : formatSyntaxKind(this.kind); return `${nodeHeader}${this.flags ? ` (${formatNodeFlags(this.flags)})` : ""}`; } }, __debugKind: { get() { return formatSyntaxKind(this.kind); } }, __debugNodeFlags: { get() { return formatNodeFlags(this.flags); } }, __debugModifierFlags: { get() { return formatModifierFlags(getEffectiveModifierFlagsNoCache(this)); } }, __debugTransformFlags: { get() { return formatTransformFlags(this.transformFlags); } }, __debugIsParseTreeNode: { get() { return isParseTreeNode(this); } }, __debugEmitFlags: { get() { return formatEmitFlags(getEmitFlags(this)); } }, __debugGetText: { value(includeTrivia) { if (nodeIsSynthesized(this)) return ""; let text = weakNodeTextMap.get(this); if (text === void 0) { const parseNode = getParseTreeNode(this); const sourceFile = parseNode && getSourceFileOfNode(parseNode); text = sourceFile ? getSourceTextOfNodeFromSourceFile(sourceFile, parseNode, includeTrivia) : ""; weakNodeTextMap.set(this, text); } return text; } } }); } } isDebugInfoEnabled = true; } Debug2.enableDebugInfo = enableDebugInfo; function formatVariance(varianceFlags) { const variance = varianceFlags & 7 /* VarianceMask */; let result = variance === 0 /* Invariant */ ? "in out" : variance === 3 /* Bivariant */ ? "[bivariant]" : variance === 2 /* Contravariant */ ? "in" : variance === 1 /* Covariant */ ? "out" : variance === 4 /* Independent */ ? "[independent]" : ""; if (varianceFlags & 8 /* Unmeasurable */) { result += " (unmeasurable)"; } else if (varianceFlags & 16 /* Unreliable */) { result += " (unreliable)"; } return result; } Debug2.formatVariance = formatVariance; class DebugTypeMapper { __debugToString() { var _a; type(this); switch (this.kind) { case 3 /* Function */: return ((_a = this.debugInfo) == null ? void 0 : _a.call(this)) || "(function mapper)"; case 0 /* Simple */: return `${this.source.__debugTypeToString()} -> ${this.target.__debugTypeToString()}`; case 1 /* Array */: return zipWith( this.sources, this.targets || map(this.sources, () => "any"), (s, t) => `${s.__debugTypeToString()} -> ${typeof t === "string" ? t : t.__debugTypeToString()}` ).join(", "); case 2 /* Deferred */: return zipWith( this.sources, this.targets, (s, t) => `${s.__debugTypeToString()} -> ${t().__debugTypeToString()}` ).join(", "); case 5 /* Merged */: case 4 /* Composite */: return `m1: ${this.mapper1.__debugToString().split("\n").join("\n ")} m2: ${this.mapper2.__debugToString().split("\n").join("\n ")}`; default: return assertNever(this); } } } Debug2.DebugTypeMapper = DebugTypeMapper; function attachDebugPrototypeIfDebug(mapper) { if (Debug2.isDebugging) { return Object.setPrototypeOf(mapper, DebugTypeMapper.prototype); } return mapper; } Debug2.attachDebugPrototypeIfDebug = attachDebugPrototypeIfDebug; function printControlFlowGraph(flowNode) { return console.log(formatControlFlowGraph(flowNode)); } Debug2.printControlFlowGraph = printControlFlowGraph; function formatControlFlowGraph(flowNode) { let nextDebugFlowId = -1; function getDebugFlowNodeId(f) { if (!f.id) { f.id = nextDebugFlowId; nextDebugFlowId--; } return f.id; } let BoxChara