|
|
|
@@ -6923,7 +6923,6 @@ var Diagnostics = {
|
|
|
|
|
Disallow_inconsistently_cased_references_to_the_same_file: diag(6078, 3 /* Message */, "Disallow_inconsistently_cased_references_to_the_same_file_6078", "Disallow inconsistently-cased references to the same file."),
|
|
|
|
|
Specify_library_files_to_be_included_in_the_compilation: diag(6079, 3 /* Message */, "Specify_library_files_to_be_included_in_the_compilation_6079", "Specify library files to be included in the compilation."),
|
|
|
|
|
Specify_JSX_code_generation: diag(6080, 3 /* Message */, "Specify_JSX_code_generation_6080", "Specify JSX code generation."),
|
|
|
|
|
File_0_has_an_unsupported_extension_so_skipping_it: diag(6081, 3 /* Message */, "File_0_has_an_unsupported_extension_so_skipping_it_6081", "File '{0}' has an unsupported extension, so skipping it."),
|
|
|
|
|
Only_amd_and_system_modules_are_supported_alongside_0: diag(6082, 1 /* Error */, "Only_amd_and_system_modules_are_supported_alongside_0_6082", "Only 'amd' and 'system' modules are supported alongside --{0}."),
|
|
|
|
|
Base_directory_to_resolve_non_absolute_module_names: diag(6083, 3 /* Message */, "Base_directory_to_resolve_non_absolute_module_names_6083", "Base directory to resolve non-absolute module names."),
|
|
|
|
|
Deprecated_Use_jsxFactory_instead_Specify_the_object_invoked_for_createElement_when_targeting_react_JSX_emit: diag(6084, 3 /* Message */, "Deprecated_Use_jsxFactory_instead_Specify_the_object_invoked_for_createElement_when_targeting_react__6084", "[Deprecated] Use '--jsxFactory' instead. Specify the object invoked for createElement when targeting 'react' JSX emit"),
|
|
|
|
@@ -17042,7 +17041,8 @@ function usesExtensionsOnImports({ imports }, hasExtension2 = or(hasJSFileExtens
|
|
|
|
|
}
|
|
|
|
|
function getModuleSpecifierEndingPreference(preference, resolutionMode, compilerOptions, sourceFile) {
|
|
|
|
|
const moduleResolution = getEmitModuleResolutionKind(compilerOptions);
|
|
|
|
|
if (preference === "js" || resolutionMode === 99 /* ESNext */ && 3 /* Node16 */ <= moduleResolution && moduleResolution <= 99 /* NodeNext */) {
|
|
|
|
|
const moduleResolutionIsNodeNext = 3 /* Node16 */ <= moduleResolution && moduleResolution <= 99 /* NodeNext */;
|
|
|
|
|
if (preference === "js" || resolutionMode === 99 /* ESNext */ && moduleResolutionIsNodeNext) {
|
|
|
|
|
if (!shouldAllowImportingTsExtension(compilerOptions)) {
|
|
|
|
|
return 2 /* JsExtension */;
|
|
|
|
|
}
|
|
|
|
@@ -17060,16 +17060,19 @@ function getModuleSpecifierEndingPreference(preference, resolutionMode, compiler
|
|
|
|
|
return inferPreference();
|
|
|
|
|
function inferPreference() {
|
|
|
|
|
let usesJsExtensions = false;
|
|
|
|
|
const specifiers = sourceFile.imports.length ? sourceFile.imports.map((i) => i.text) : isSourceFileJS(sourceFile) ? getRequiresAtTopOfFile(sourceFile).map((r) => r.arguments[0].text) : emptyArray;
|
|
|
|
|
const specifiers = sourceFile.imports.length ? sourceFile.imports : isSourceFileJS(sourceFile) ? getRequiresAtTopOfFile(sourceFile).map((r) => r.arguments[0]) : emptyArray;
|
|
|
|
|
for (const specifier of specifiers) {
|
|
|
|
|
if (pathIsRelative(specifier)) {
|
|
|
|
|
if (fileExtensionIsOneOf(specifier, extensionsNotSupportingExtensionlessResolution)) {
|
|
|
|
|
if (pathIsRelative(specifier.text)) {
|
|
|
|
|
if (moduleResolutionIsNodeNext && resolutionMode === 1 /* CommonJS */ && getModeForUsageLocation(sourceFile, specifier, compilerOptions) === 99 /* ESNext */) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (hasTSFileExtension(specifier)) {
|
|
|
|
|
if (fileExtensionIsOneOf(specifier.text, extensionsNotSupportingExtensionlessResolution)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (hasTSFileExtension(specifier.text)) {
|
|
|
|
|
return 3 /* TsExtension */;
|
|
|
|
|
}
|
|
|
|
|
if (hasJSFileExtension(specifier)) {
|
|
|
|
|
if (hasJSFileExtension(specifier.text)) {
|
|
|
|
|
usesJsExtensions = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -32493,7 +32496,7 @@ var Parser;
|
|
|
|
|
if (!jsDocDiagnostics) {
|
|
|
|
|
jsDocDiagnostics = [];
|
|
|
|
|
}
|
|
|
|
|
jsDocDiagnostics.push(...parseDiagnostics);
|
|
|
|
|
addRange(jsDocDiagnostics, parseDiagnostics, saveParseDiagnosticsLength);
|
|
|
|
|
}
|
|
|
|
|
currentToken = saveToken;
|
|
|
|
|
parseDiagnostics.length = saveParseDiagnosticsLength;
|
|
|
|
@@ -38721,15 +38724,9 @@ function loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFail
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const loader = (extensions2, candidate2, onlyRecordFailures2, state2) => {
|
|
|
|
|
const fromFile = tryFile(candidate2, onlyRecordFailures2, state2);
|
|
|
|
|
const fromFile = loadFileNameFromPackageJsonField(extensions2, candidate2, onlyRecordFailures2, state2);
|
|
|
|
|
if (fromFile) {
|
|
|
|
|
const resolved = resolvedIfExtensionMatches(extensions2, fromFile);
|
|
|
|
|
if (resolved) {
|
|
|
|
|
return noPackageId(resolved);
|
|
|
|
|
}
|
|
|
|
|
if (state2.traceEnabled) {
|
|
|
|
|
trace(state2.host, Diagnostics.File_0_has_an_unsupported_extension_so_skipping_it, fromFile);
|
|
|
|
|
}
|
|
|
|
|
return noPackageId(fromFile);
|
|
|
|
|
}
|
|
|
|
|
const expandedExtensions = extensions2 === 4 /* Declaration */ ? 1 /* TypeScript */ | 4 /* Declaration */ : extensions2;
|
|
|
|
|
const features = state2.features;
|
|
|
|
@@ -38785,10 +38782,6 @@ function loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFail
|
|
|
|
|
return loadModuleFromFile(extensions, indexPath, onlyRecordFailuresForIndex, state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function resolvedIfExtensionMatches(extensions, path, resolvedUsingTsExtension) {
|
|
|
|
|
const ext = tryGetExtensionFromPath2(path);
|
|
|
|
|
return ext !== void 0 && extensionIsOk(extensions, ext) ? { path, ext, resolvedUsingTsExtension } : void 0;
|
|
|
|
|
}
|
|
|
|
|
function extensionIsOk(extensions, extension) {
|
|
|
|
|
return extensions & 2 /* JavaScript */ && (extension === ".js" /* Js */ || extension === ".jsx" /* Jsx */ || extension === ".mjs" /* Mjs */ || extension === ".cjs" /* Cjs */) || extensions & 1 /* TypeScript */ && (extension === ".ts" /* Ts */ || extension === ".tsx" /* Tsx */ || extension === ".mts" /* Mts */ || extension === ".cts" /* Cts */) || extensions & 4 /* Declaration */ && (extension === ".d.ts" /* Dts */ || extension === ".d.mts" /* Dmts */ || extension === ".d.cts" /* Dcts */) || extensions & 8 /* Json */ && extension === ".json" /* Json */ || false;
|
|
|
|
|
}
|
|
|
|
@@ -42636,11 +42629,12 @@ function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignatu
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// src/compiler/moduleSpecifiers.ts
|
|
|
|
|
function getPreferences({ importModuleSpecifierPreference, importModuleSpecifierEnding }, compilerOptions, importingSourceFile, oldImportSpecifier) {
|
|
|
|
|
const preferredEnding = getPreferredEnding();
|
|
|
|
|
function getModuleSpecifierPreferences({ importModuleSpecifierPreference, importModuleSpecifierEnding }, compilerOptions, importingSourceFile, oldImportSpecifier) {
|
|
|
|
|
const filePreferredEnding = getPreferredEnding();
|
|
|
|
|
return {
|
|
|
|
|
relativePreference: oldImportSpecifier !== void 0 ? isExternalModuleNameRelative(oldImportSpecifier) ? 0 /* Relative */ : 1 /* NonRelative */ : importModuleSpecifierPreference === "relative" ? 0 /* Relative */ : importModuleSpecifierPreference === "non-relative" ? 1 /* NonRelative */ : importModuleSpecifierPreference === "project-relative" ? 3 /* ExternalNonRelative */ : 2 /* Shortest */,
|
|
|
|
|
getAllowedEndingsInPreferredOrder: (syntaxImpliedNodeFormat) => {
|
|
|
|
|
const preferredEnding = syntaxImpliedNodeFormat !== importingSourceFile.impliedNodeFormat ? getPreferredEnding(syntaxImpliedNodeFormat) : filePreferredEnding;
|
|
|
|
|
if ((syntaxImpliedNodeFormat ?? importingSourceFile.impliedNodeFormat) === 99 /* ESNext */) {
|
|
|
|
|
if (shouldAllowImportingTsExtension(compilerOptions, importingSourceFile.fileName)) {
|
|
|
|
|
return [3 /* TsExtension */, 2 /* JsExtension */];
|
|
|
|
@@ -42665,7 +42659,7 @@ function getPreferences({ importModuleSpecifierPreference, importModuleSpecifier
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
function getPreferredEnding() {
|
|
|
|
|
function getPreferredEnding(resolutionMode) {
|
|
|
|
|
if (oldImportSpecifier !== void 0) {
|
|
|
|
|
if (hasJSFileExtension(oldImportSpecifier))
|
|
|
|
|
return 2 /* JsExtension */;
|
|
|
|
@@ -42674,14 +42668,14 @@ function getPreferences({ importModuleSpecifierPreference, importModuleSpecifier
|
|
|
|
|
}
|
|
|
|
|
return getModuleSpecifierEndingPreference(
|
|
|
|
|
importModuleSpecifierEnding,
|
|
|
|
|
importingSourceFile.impliedNodeFormat,
|
|
|
|
|
resolutionMode ?? importingSourceFile.impliedNodeFormat,
|
|
|
|
|
compilerOptions,
|
|
|
|
|
importingSourceFile
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function getModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName2, host, options = {}) {
|
|
|
|
|
return getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName2, host, getPreferences({}, compilerOptions, importingSourceFile), {}, options);
|
|
|
|
|
return getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName2, host, getModuleSpecifierPreferences({}, compilerOptions, importingSourceFile), {}, options);
|
|
|
|
|
}
|
|
|
|
|
function getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName2, host, preferences, userPreferences, options = {}) {
|
|
|
|
|
const info = getInfo(importingSourceFileName, host);
|
|
|
|
@@ -42753,7 +42747,7 @@ function getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions
|
|
|
|
|
}
|
|
|
|
|
function computeModuleSpecifiers(modulePaths, compilerOptions, importingSourceFile, host, userPreferences, options = {}, forAutoImport) {
|
|
|
|
|
const info = getInfo(importingSourceFile.fileName, host);
|
|
|
|
|
const preferences = getPreferences(userPreferences, compilerOptions, importingSourceFile);
|
|
|
|
|
const preferences = getModuleSpecifierPreferences(userPreferences, compilerOptions, importingSourceFile);
|
|
|
|
|
const existingSpecifier = forEach(modulePaths, (modulePath) => forEach(
|
|
|
|
|
host.getFileIncludeReasons().get(toPath(modulePath.path, host.getCurrentDirectory(), info.getCanonicalFileName)),
|
|
|
|
|
(reason) => {
|
|
|
|
@@ -43263,7 +43257,7 @@ function tryGetModuleNameAsNodeModule({ path, isRedirect }, { getCanonicalFileNa
|
|
|
|
|
if (!parts) {
|
|
|
|
|
return void 0;
|
|
|
|
|
}
|
|
|
|
|
const preferences = getPreferences(userPreferences, options, importingSourceFile);
|
|
|
|
|
const preferences = getModuleSpecifierPreferences(userPreferences, options, importingSourceFile);
|
|
|
|
|
const allowedEndings = preferences.getAllowedEndingsInPreferredOrder();
|
|
|
|
|
let moduleSpecifier = path;
|
|
|
|
|
let isPackageRootPath = false;
|
|
|
|
@@ -45915,6 +45909,11 @@ function createTypeChecker(host) {
|
|
|
|
|
diagnosticMessage = error(errorLocation, Diagnostics.Class_0_used_before_its_declaration, declarationName);
|
|
|
|
|
} else if (result.flags & 256 /* RegularEnum */) {
|
|
|
|
|
diagnosticMessage = error(errorLocation, Diagnostics.Enum_0_used_before_its_declaration, declarationName);
|
|
|
|
|
} else {
|
|
|
|
|
Debug.assert(!!(result.flags & 128 /* ConstEnum */));
|
|
|
|
|
if (getIsolatedModules(compilerOptions)) {
|
|
|
|
|
diagnosticMessage = error(errorLocation, Diagnostics.Enum_0_used_before_its_declaration, declarationName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (diagnosticMessage) {
|
|
|
|
|
addRelatedInfo(diagnosticMessage, createDiagnosticForNode(declaration, Diagnostics._0_is_declared_here, declarationName));
|
|
|
|
@@ -54467,6 +54466,8 @@ function createTypeChecker(host) {
|
|
|
|
|
result.compositeSignatures = concatenate(left.compositeKind !== 2097152 /* Intersection */ && left.compositeSignatures || [left], [right]);
|
|
|
|
|
if (paramMapper) {
|
|
|
|
|
result.mapper = left.compositeKind !== 2097152 /* Intersection */ && left.mapper && left.compositeSignatures ? combineTypeMappers(left.mapper, paramMapper) : paramMapper;
|
|
|
|
|
} else if (left.compositeKind !== 2097152 /* Intersection */ && left.mapper && left.compositeSignatures) {
|
|
|
|
|
result.mapper = left.mapper;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@@ -55064,7 +55065,7 @@ function createTypeChecker(host) {
|
|
|
|
|
return simplified !== type ? simplified : getConstraintOfType(type);
|
|
|
|
|
}
|
|
|
|
|
function getConstraintFromIndexedAccess(type) {
|
|
|
|
|
if (isMappedTypeGenericIndexedAccess(type) || isGenericMappedType(type.objectType)) {
|
|
|
|
|
if (isMappedTypeGenericIndexedAccess(type)) {
|
|
|
|
|
return substituteIndexedMappedType(type.objectType, type.indexType);
|
|
|
|
|
}
|
|
|
|
|
const indexConstraint = getSimplifiedTypeOrConstraint(type.indexType);
|
|
|
|
@@ -55314,11 +55315,15 @@ function createTypeChecker(host) {
|
|
|
|
|
return type.resolvedApparentType || (type.resolvedApparentType = getResolvedApparentTypeOfMappedType(type));
|
|
|
|
|
}
|
|
|
|
|
function getResolvedApparentTypeOfMappedType(type) {
|
|
|
|
|
const typeVariable = getHomomorphicTypeVariable(type);
|
|
|
|
|
if (typeVariable && !type.declaration.nameType) {
|
|
|
|
|
const constraint = getConstraintOfTypeParameter(typeVariable);
|
|
|
|
|
if (constraint && everyType(constraint, isArrayOrTupleType)) {
|
|
|
|
|
return instantiateType(type, prependTypeMapping(typeVariable, constraint, type.mapper));
|
|
|
|
|
const target = type.target ?? type;
|
|
|
|
|
const typeVariable = getHomomorphicTypeVariable(target);
|
|
|
|
|
if (typeVariable && !target.declaration.nameType) {
|
|
|
|
|
const constraint = getConstraintTypeFromMappedType(type);
|
|
|
|
|
if (constraint.flags & 4194304 /* Index */) {
|
|
|
|
|
const baseConstraint = getBaseConstraintOfType(constraint.type);
|
|
|
|
|
if (baseConstraint && everyType(baseConstraint, isArrayOrTupleType)) {
|
|
|
|
|
return instantiateType(target, prependTypeMapping(typeVariable, baseConstraint, type.mapper));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return type;
|
|
|
|
@@ -55577,10 +55582,14 @@ function createTypeChecker(host) {
|
|
|
|
|
return errorInfo;
|
|
|
|
|
}
|
|
|
|
|
function getPropertyOfType(type, name, skipObjectFunctionPropertyAugment, includeTypeOnlyMembers) {
|
|
|
|
|
var _a, _b;
|
|
|
|
|
type = getReducedApparentType(type);
|
|
|
|
|
if (type.flags & 524288 /* Object */) {
|
|
|
|
|
const resolved = resolveStructuredTypeMembers(type);
|
|
|
|
|
const symbol = resolved.members.get(name);
|
|
|
|
|
if (symbol && !includeTypeOnlyMembers && ((_a = type.symbol) == null ? void 0 : _a.flags) & 512 /* ValueModule */ && ((_b = getSymbolLinks(type.symbol).typeOnlyExportStarMap) == null ? void 0 : _b.has(name))) {
|
|
|
|
|
return void 0;
|
|
|
|
|
}
|
|
|
|
|
if (symbol && symbolIsValue(symbol, includeTypeOnlyMembers)) {
|
|
|
|
|
return symbol;
|
|
|
|
|
}
|
|
|
|
@@ -57353,7 +57362,7 @@ function createTypeChecker(host) {
|
|
|
|
|
return target.objectFlags & 8 /* Tuple */ ? createNormalizedTupleType(target, typeArguments) : createTypeReference(target, typeArguments);
|
|
|
|
|
}
|
|
|
|
|
function createNormalizedTupleType(target, elementTypes) {
|
|
|
|
|
var _a, _b, _c;
|
|
|
|
|
var _a, _b, _c, _d;
|
|
|
|
|
if (!(target.combinedFlags & 14 /* NonRequired */)) {
|
|
|
|
|
return createTypeReference(target, elementTypes);
|
|
|
|
|
}
|
|
|
|
@@ -57373,8 +57382,10 @@ function createTypeChecker(host) {
|
|
|
|
|
const type = elementTypes[i];
|
|
|
|
|
const flags = target.elementFlags[i];
|
|
|
|
|
if (flags & 8 /* Variadic */) {
|
|
|
|
|
if (type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericMappedType(type)) {
|
|
|
|
|
addElement(type, 8 /* Variadic */, (_a = target.labeledElementDeclarations) == null ? void 0 : _a[i]);
|
|
|
|
|
if (type.flags & 1 /* Any */) {
|
|
|
|
|
addElement(type, 4 /* Rest */, (_a = target.labeledElementDeclarations) == null ? void 0 : _a[i]);
|
|
|
|
|
} else if (type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericMappedType(type)) {
|
|
|
|
|
addElement(type, 8 /* Variadic */, (_b = target.labeledElementDeclarations) == null ? void 0 : _b[i]);
|
|
|
|
|
} else if (isTupleType(type)) {
|
|
|
|
|
const elements = getElementTypes(type);
|
|
|
|
|
if (elements.length + expandedTypes.length >= 1e4) {
|
|
|
|
@@ -57389,10 +57400,10 @@ function createTypeChecker(host) {
|
|
|
|
|
return addElement(t, type.target.elementFlags[n], (_a2 = type.target.labeledElementDeclarations) == null ? void 0 : _a2[n]);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
addElement(isArrayLikeType(type) && getIndexTypeOfType(type, numberType) || errorType, 4 /* Rest */, (_b = target.labeledElementDeclarations) == null ? void 0 : _b[i]);
|
|
|
|
|
addElement(isArrayLikeType(type) && getIndexTypeOfType(type, numberType) || errorType, 4 /* Rest */, (_c = target.labeledElementDeclarations) == null ? void 0 : _c[i]);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
addElement(type, flags, (_c = target.labeledElementDeclarations) == null ? void 0 : _c[i]);
|
|
|
|
|
addElement(type, flags, (_d = target.labeledElementDeclarations) == null ? void 0 : _d[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (let i = 0; i < lastRequiredIndex; i++) {
|
|
|
|
@@ -58756,10 +58767,6 @@ function createTypeChecker(host) {
|
|
|
|
|
}
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
function maybeCloneTypeParameter(p) {
|
|
|
|
|
const constraint = getConstraintOfTypeParameter(p);
|
|
|
|
|
return constraint && (isGenericObjectType(constraint) || isGenericIndexType(constraint)) ? cloneTypeParameter(p) : p;
|
|
|
|
|
}
|
|
|
|
|
function isSimpleTupleType(node) {
|
|
|
|
|
return isTupleTypeNode(node) && length(node.elements) > 0 && !some(node.elements, (e) => isOptionalTypeNode(e) || isRestTypeNode(e) || isNamedTupleMember(e) && !!(e.questionToken || e.dotDotDotToken));
|
|
|
|
|
}
|
|
|
|
@@ -58789,27 +58796,19 @@ function createTypeChecker(host) {
|
|
|
|
|
const checkTypeDeferred = isDeferredType(checkType, checkTuples);
|
|
|
|
|
let combinedMapper;
|
|
|
|
|
if (root.inferTypeParameters) {
|
|
|
|
|
const freshParams = sameMap(root.inferTypeParameters, maybeCloneTypeParameter);
|
|
|
|
|
const freshMapper = freshParams !== root.inferTypeParameters ? createTypeMapper(root.inferTypeParameters, freshParams) : void 0;
|
|
|
|
|
const context = createInferenceContext(
|
|
|
|
|
freshParams,
|
|
|
|
|
root.inferTypeParameters,
|
|
|
|
|
/*signature*/
|
|
|
|
|
void 0,
|
|
|
|
|
0 /* None */
|
|
|
|
|
);
|
|
|
|
|
if (freshMapper) {
|
|
|
|
|
const freshCombinedMapper = combineTypeMappers(mapper, freshMapper);
|
|
|
|
|
for (let i = 0; i < freshParams.length; i++) {
|
|
|
|
|
if (freshParams[i] !== root.inferTypeParameters[i]) {
|
|
|
|
|
freshParams[i].mapper = freshCombinedMapper;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (mapper) {
|
|
|
|
|
context.nonFixingMapper = combineTypeMappers(context.nonFixingMapper, mapper);
|
|
|
|
|
}
|
|
|
|
|
if (!checkTypeDeferred) {
|
|
|
|
|
inferTypes(context.inferences, checkType, instantiateType(extendsType, freshMapper), 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
|
|
|
|
|
inferTypes(context.inferences, checkType, extendsType, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
|
|
|
|
|
}
|
|
|
|
|
const innerMapper = combineTypeMappers(freshMapper, context.mapper);
|
|
|
|
|
combinedMapper = mapper ? combineTypeMappers(innerMapper, mapper) : innerMapper;
|
|
|
|
|
combinedMapper = mapper ? combineTypeMappers(context.mapper, mapper) : context.mapper;
|
|
|
|
|
}
|
|
|
|
|
const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
|
|
|
|
|
if (!checkTypeDeferred && !isDeferredType(inferredExtendsType, checkTuples)) {
|
|
|
|
@@ -59786,8 +59785,8 @@ function createTypeChecker(host) {
|
|
|
|
|
if (!result) {
|
|
|
|
|
const newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
|
|
|
|
|
const checkType = root.checkType;
|
|
|
|
|
const distributionType = root.isDistributive ? getMappedType(checkType, newMapper) : void 0;
|
|
|
|
|
result = distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */) ? mapTypeWithAlias(getReducedType(distributionType), (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint), aliasSymbol, aliasTypeArguments) : getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments);
|
|
|
|
|
const distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
|
|
|
|
|
result = distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */) ? mapTypeWithAlias(distributionType, (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint), aliasSymbol, aliasTypeArguments) : getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments);
|
|
|
|
|
root.instantiations.set(id, result);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
@@ -60661,8 +60660,8 @@ function createTypeChecker(host) {
|
|
|
|
|
const paramCount = sourceRestType || targetRestType ? Math.min(sourceCount, targetCount) : Math.max(sourceCount, targetCount);
|
|
|
|
|
const restIndex = sourceRestType || targetRestType ? paramCount - 1 : -1;
|
|
|
|
|
for (let i = 0; i < paramCount; i++) {
|
|
|
|
|
const sourceType = i === restIndex ? getRestTypeAtPosition(source, i) : tryGetTypeAtPosition(source, i);
|
|
|
|
|
const targetType = i === restIndex ? getRestTypeAtPosition(target, i) : tryGetTypeAtPosition(target, i);
|
|
|
|
|
const sourceType = i === restIndex ? getRestOrAnyTypeAtPosition(source, i) : tryGetTypeAtPosition(source, i);
|
|
|
|
|
const targetType = i === restIndex ? getRestOrAnyTypeAtPosition(target, i) : tryGetTypeAtPosition(target, i);
|
|
|
|
|
if (sourceType && targetType) {
|
|
|
|
|
const sourceSig = checkMode & 3 /* Callback */ || isInstantiatedGenericParameter(source, i) ? void 0 : getSingleCallSignature(getNonNullableType(sourceType));
|
|
|
|
|
const targetSig = checkMode & 3 /* Callback */ || isInstantiatedGenericParameter(target, i) ? void 0 : getSingleCallSignature(getNonNullableType(targetType));
|
|
|
|
@@ -65645,7 +65644,7 @@ function createTypeChecker(host) {
|
|
|
|
|
function hasMatchingArgument(expression, reference) {
|
|
|
|
|
if (expression.arguments) {
|
|
|
|
|
for (const argument of expression.arguments) {
|
|
|
|
|
if (isOrContainsMatchingReference(reference, argument) || optionalChainContainsReference(argument, reference)) {
|
|
|
|
|
if (isOrContainsMatchingReference(reference, argument) || optionalChainContainsReference(argument, reference) || getCandidateDiscriminantPropertyAccess(argument, reference)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -65655,6 +65654,36 @@ function createTypeChecker(host) {
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
function getCandidateDiscriminantPropertyAccess(expr, reference) {
|
|
|
|
|
if (isBindingPattern(reference) || isFunctionExpressionOrArrowFunction(reference) || isObjectLiteralMethod(reference)) {
|
|
|
|
|
if (isIdentifier(expr)) {
|
|
|
|
|
const symbol = getResolvedSymbol(expr);
|
|
|
|
|
const declaration = symbol.valueDeclaration;
|
|
|
|
|
if (declaration && (isBindingElement(declaration) || isParameter(declaration)) && reference === declaration.parent && !declaration.initializer && !declaration.dotDotDotToken) {
|
|
|
|
|
return declaration;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (isAccessExpression(expr)) {
|
|
|
|
|
if (isMatchingReference(reference, expr.expression)) {
|
|
|
|
|
return expr;
|
|
|
|
|
}
|
|
|
|
|
} else if (isIdentifier(expr)) {
|
|
|
|
|
const symbol = getResolvedSymbol(expr);
|
|
|
|
|
if (isConstantVariable(symbol)) {
|
|
|
|
|
const declaration = symbol.valueDeclaration;
|
|
|
|
|
if (isVariableDeclaration(declaration) && !declaration.type && declaration.initializer && isAccessExpression(declaration.initializer) && isMatchingReference(reference, declaration.initializer.expression)) {
|
|
|
|
|
return declaration.initializer;
|
|
|
|
|
}
|
|
|
|
|
if (isBindingElement(declaration) && !declaration.initializer) {
|
|
|
|
|
const parent = declaration.parent.parent;
|
|
|
|
|
if (isVariableDeclaration(parent) && !parent.type && parent.initializer && (isIdentifier(parent.initializer) || isAccessExpression(parent.initializer)) && isMatchingReference(reference, parent.initializer)) {
|
|
|
|
|
return declaration;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return void 0;
|
|
|
|
|
}
|
|
|
|
|
function getFlowNodeId(flow) {
|
|
|
|
|
if (!flow.id || flow.id < 0) {
|
|
|
|
|
flow.id = nextFlowId;
|
|
|
|
@@ -66754,39 +66783,9 @@ function createTypeChecker(host) {
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
function getCandidateDiscriminantPropertyAccess(expr) {
|
|
|
|
|
if (isBindingPattern(reference) || isFunctionExpressionOrArrowFunction(reference) || isObjectLiteralMethod(reference)) {
|
|
|
|
|
if (isIdentifier(expr)) {
|
|
|
|
|
const symbol = getResolvedSymbol(expr);
|
|
|
|
|
const declaration = symbol.valueDeclaration;
|
|
|
|
|
if (declaration && (isBindingElement(declaration) || isParameter(declaration)) && reference === declaration.parent && !declaration.initializer && !declaration.dotDotDotToken) {
|
|
|
|
|
return declaration;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (isAccessExpression(expr)) {
|
|
|
|
|
if (isMatchingReference(reference, expr.expression)) {
|
|
|
|
|
return expr;
|
|
|
|
|
}
|
|
|
|
|
} else if (isIdentifier(expr)) {
|
|
|
|
|
const symbol = getResolvedSymbol(expr);
|
|
|
|
|
if (isConstantVariable(symbol)) {
|
|
|
|
|
const declaration = symbol.valueDeclaration;
|
|
|
|
|
if (isVariableDeclaration(declaration) && !declaration.type && declaration.initializer && isAccessExpression(declaration.initializer) && isMatchingReference(reference, declaration.initializer.expression)) {
|
|
|
|
|
return declaration.initializer;
|
|
|
|
|
}
|
|
|
|
|
if (isBindingElement(declaration) && !declaration.initializer) {
|
|
|
|
|
const parent = declaration.parent.parent;
|
|
|
|
|
if (isVariableDeclaration(parent) && !parent.type && parent.initializer && (isIdentifier(parent.initializer) || isAccessExpression(parent.initializer)) && isMatchingReference(reference, parent.initializer)) {
|
|
|
|
|
return declaration;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return void 0;
|
|
|
|
|
}
|
|
|
|
|
function getDiscriminantPropertyAccess(expr, computedType) {
|
|
|
|
|
if (declaredType.flags & 1048576 /* Union */ || computedType.flags & 1048576 /* Union */) {
|
|
|
|
|
const access = getCandidateDiscriminantPropertyAccess(expr);
|
|
|
|
|
const access = getCandidateDiscriminantPropertyAccess(expr, reference);
|
|
|
|
|
if (access) {
|
|
|
|
|
const name = getAccessedPropertyName(access);
|
|
|
|
|
if (name) {
|
|
|
|
@@ -73665,6 +73664,11 @@ function createTypeChecker(host) {
|
|
|
|
|
}
|
|
|
|
|
return createTupleType(types, flags, readonly, names);
|
|
|
|
|
}
|
|
|
|
|
function getRestOrAnyTypeAtPosition(source, pos) {
|
|
|
|
|
const restType = getRestTypeAtPosition(source, pos);
|
|
|
|
|
const elementType = restType && getElementTypeOfArrayType(restType);
|
|
|
|
|
return elementType && isTypeAny(elementType) ? anyType : restType;
|
|
|
|
|
}
|
|
|
|
|
function getParameterCount(signature) {
|
|
|
|
|
const length2 = signature.parameters.length;
|
|
|
|
|
if (signatureHasRestParameter(signature)) {
|
|
|
|
@@ -73721,7 +73725,7 @@ function createTypeChecker(host) {
|
|
|
|
|
if (signatureHasRestParameter(signature)) {
|
|
|
|
|
const restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]);
|
|
|
|
|
if (!isTupleType(restType)) {
|
|
|
|
|
return restType;
|
|
|
|
|
return isTypeAny(restType) ? anyArrayType : restType;
|
|
|
|
|
}
|
|
|
|
|
if (restType.target.hasRestElement) {
|
|
|
|
|
return sliceTupleType(restType, restType.target.fixedLength);
|
|
|
|
@@ -77025,20 +77029,17 @@ function createTypeChecker(host) {
|
|
|
|
|
const objectType = type.objectType;
|
|
|
|
|
const indexType = type.indexType;
|
|
|
|
|
const objectIndexType = isGenericMappedType(objectType) && getMappedTypeNameTypeKind(objectType) === 2 /* Remapping */ ? getIndexTypeForMappedType(objectType, 0 /* None */) : getIndexType(objectType, 0 /* None */);
|
|
|
|
|
if (isTypeAssignableTo(indexType, objectIndexType)) {
|
|
|
|
|
const hasNumberIndexInfo = !!getIndexInfoOfType(objectType, numberType);
|
|
|
|
|
if (everyType(indexType, (t) => isTypeAssignableTo(t, objectIndexType) || hasNumberIndexInfo && isApplicableIndexType(t, numberType))) {
|
|
|
|
|
if (accessNode.kind === 212 /* ElementAccessExpression */ && isAssignmentTarget(accessNode) && getObjectFlags(objectType) & 32 /* Mapped */ && getMappedTypeModifiers(objectType) & 1 /* IncludeReadonly */) {
|
|
|
|
|
error(accessNode, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(objectType));
|
|
|
|
|
}
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
const apparentObjectType = getApparentType(objectType);
|
|
|
|
|
if (getIndexInfoOfType(apparentObjectType, numberType) && isTypeAssignableToKind(indexType, 296 /* NumberLike */)) {
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
if (isGenericObjectType(objectType)) {
|
|
|
|
|
const propertyName = getPropertyNameFromIndex(indexType, accessNode);
|
|
|
|
|
if (propertyName) {
|
|
|
|
|
const propertySymbol = forEachType(apparentObjectType, (t) => getPropertyOfType(t, propertyName));
|
|
|
|
|
const propertySymbol = forEachType(getApparentType(objectType), (t) => getPropertyOfType(t, propertyName));
|
|
|
|
|
if (propertySymbol && getDeclarationModifierFlagsFromSymbol(propertySymbol) & 6 /* NonPublicAccessibilityModifier */) {
|
|
|
|
|
error(accessNode, Diagnostics.Private_or_protected_member_0_cannot_be_accessed_on_a_type_parameter, unescapeLeadingUnderscores(propertyName));
|
|
|
|
|
return errorType;
|
|
|
|
@@ -83098,7 +83099,7 @@ function createTypeChecker(host) {
|
|
|
|
|
true,
|
|
|
|
|
location
|
|
|
|
|
);
|
|
|
|
|
const resolvedSymbol = valueSymbol && valueSymbol.flags & 2097152 /* Alias */ ? resolveAlias(valueSymbol) : valueSymbol;
|
|
|
|
|
const resolvedValueSymbol = valueSymbol && valueSymbol.flags & 2097152 /* Alias */ ? resolveAlias(valueSymbol) : valueSymbol;
|
|
|
|
|
isTypeOnly || (isTypeOnly = !!(valueSymbol && getTypeOnlyAliasDeclaration(valueSymbol, 111551 /* Value */)));
|
|
|
|
|
const typeSymbol = resolveEntityName(
|
|
|
|
|
typeName,
|
|
|
|
@@ -83106,26 +83107,30 @@ function createTypeChecker(host) {
|
|
|
|
|
/*ignoreErrors*/
|
|
|
|
|
true,
|
|
|
|
|
/*dontResolveAlias*/
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
location
|
|
|
|
|
);
|
|
|
|
|
if (resolvedSymbol && resolvedSymbol === typeSymbol) {
|
|
|
|
|
const resolvedTypeSymbol = typeSymbol && typeSymbol.flags & 2097152 /* Alias */ ? resolveAlias(typeSymbol) : typeSymbol;
|
|
|
|
|
if (!valueSymbol) {
|
|
|
|
|
isTypeOnly || (isTypeOnly = !!(typeSymbol && getTypeOnlyAliasDeclaration(typeSymbol, 788968 /* Type */)));
|
|
|
|
|
}
|
|
|
|
|
if (resolvedValueSymbol && resolvedValueSymbol === resolvedTypeSymbol) {
|
|
|
|
|
const globalPromiseSymbol = getGlobalPromiseConstructorSymbol(
|
|
|
|
|
/*reportErrors*/
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
if (globalPromiseSymbol && resolvedSymbol === globalPromiseSymbol) {
|
|
|
|
|
if (globalPromiseSymbol && resolvedValueSymbol === globalPromiseSymbol) {
|
|
|
|
|
return 9 /* Promise */;
|
|
|
|
|
}
|
|
|
|
|
const constructorType = getTypeOfSymbol(resolvedSymbol);
|
|
|
|
|
const constructorType = getTypeOfSymbol(resolvedValueSymbol);
|
|
|
|
|
if (constructorType && isConstructorType(constructorType)) {
|
|
|
|
|
return isTypeOnly ? 10 /* TypeWithCallSignature */ : 1 /* TypeWithConstructSignatureAndValue */;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!typeSymbol) {
|
|
|
|
|
if (!resolvedTypeSymbol) {
|
|
|
|
|
return isTypeOnly ? 11 /* ObjectType */ : 0 /* Unknown */;
|
|
|
|
|
}
|
|
|
|
|
const type = getDeclaredTypeOfSymbol(typeSymbol);
|
|
|
|
|
const type = getDeclaredTypeOfSymbol(resolvedTypeSymbol);
|
|
|
|
|
if (isErrorType(type)) {
|
|
|
|
|
return isTypeOnly ? 11 /* ObjectType */ : 0 /* Unknown */;
|
|
|
|
|
} else if (type.flags & 3 /* AnyOrUnknown */) {
|
|
|
|
@@ -88595,9 +88600,50 @@ function transformTypeScript(context) {
|
|
|
|
|
return visitorWorker(node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function visitElidableStatement(node) {
|
|
|
|
|
function isElisionBlocked(node) {
|
|
|
|
|
const parsed = getParseTreeNode(node);
|
|
|
|
|
if (parsed !== node) {
|
|
|
|
|
if (parsed === node || isExportAssignment(node)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!parsed || parsed.kind !== node.kind) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
switch (node.kind) {
|
|
|
|
|
case 272 /* ImportDeclaration */:
|
|
|
|
|
Debug.assertNode(parsed, isImportDeclaration);
|
|
|
|
|
if (node.importClause !== parsed.importClause) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (node.attributes !== parsed.attributes) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 271 /* ImportEqualsDeclaration */:
|
|
|
|
|
Debug.assertNode(parsed, isImportEqualsDeclaration);
|
|
|
|
|
if (node.name !== parsed.name) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (node.isTypeOnly !== parsed.isTypeOnly) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (node.moduleReference !== parsed.moduleReference && (isEntityName(node.moduleReference) || isEntityName(parsed.moduleReference))) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 278 /* ExportDeclaration */:
|
|
|
|
|
Debug.assertNode(parsed, isExportDeclaration);
|
|
|
|
|
if (node.exportClause !== parsed.exportClause) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (node.attributes !== parsed.attributes) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
function visitElidableStatement(node) {
|
|
|
|
|
if (isElisionBlocked(node)) {
|
|
|
|
|
if (node.transformFlags & 1 /* ContainsTypeScript */) {
|
|
|
|
|
return visitEachChild(node, visitor, context);
|
|
|
|
|
}
|
|
|
|
@@ -115236,7 +115282,7 @@ function createPrinter(printerOptions = {}, handlers = {}) {
|
|
|
|
|
return getLiteralTextOfNode(textSourceNode, neverAsciiEscape, jsxAttributeEscape);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const flags = (neverAsciiEscape ? 1 /* NeverAsciiEscape */ : 0) | (jsxAttributeEscape ? 2 /* JsxAttributeEscape */ : 0) | (printerOptions.terminateUnterminatedLiterals ? 4 /* TerminateUnterminatedLiterals */ : 0) | (printerOptions.target && printerOptions.target === 99 /* ESNext */ ? 8 /* AllowNumericSeparator */ : 0);
|
|
|
|
|
const flags = (neverAsciiEscape ? 1 /* NeverAsciiEscape */ : 0) | (jsxAttributeEscape ? 2 /* JsxAttributeEscape */ : 0) | (printerOptions.terminateUnterminatedLiterals ? 4 /* TerminateUnterminatedLiterals */ : 0) | (printerOptions.target && printerOptions.target >= 8 /* ES2021 */ ? 8 /* AllowNumericSeparator */ : 0);
|
|
|
|
|
return getLiteralText(node, currentSourceFile, flags);
|
|
|
|
|
}
|
|
|
|
|
function pushNameGenerationScope(node) {
|
|
|
|
|