From 4eaa105816acfbc9f1ab37d6664cbaf2a2916964 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Sat, 28 Dec 2024 18:55:53 +0800 Subject: [PATCH] chore(uts): sync typescript --- .../lib/typescript/lib/typescript.factory.js | 66 ++++++------------- .../lib/typescript/lib/typescript.js | 66 ++++++------------- 2 files changed, 38 insertions(+), 94 deletions(-) diff --git a/packages/uni-uts-v1/lib/typescript/lib/typescript.factory.js b/packages/uni-uts-v1/lib/typescript/lib/typescript.factory.js index 1a5c0061bef..a48287b4161 100644 --- a/packages/uni-uts-v1/lib/typescript/lib/typescript.factory.js +++ b/packages/uni-uts-v1/lib/typescript/lib/typescript.factory.js @@ -40695,13 +40695,13 @@ ${lanes.join("\n")} } function tryFileLookup(fileName, onlyRecordFailures, state) { var _a, _b, _c; - if (state && !state.isConfigLookup && ((_a = __utsHacker__) == null ? void 0 : _a.tryFileLookup)) { - const result = (_b = __utsHacker__) == null ? void 0 : _b.tryFileLookup(fileName); - if (result) { - return result; - } - } if (!onlyRecordFailures) { + if (state && !state.isConfigLookup && ((_a = __utsHacker__) == null ? void 0 : _a.tryFileLookup)) { + const result = (_b = __utsHacker__) == null ? void 0 : _b.tryFileLookup(fileName); + if (result) { + return result; + } + } if (state.host.fileExists(fileName)) { if (state.traceEnabled) { trace(state.host, Diagnostics.File_0_exists_use_it_as_a_name_resolution_result, fileName); @@ -45713,7 +45713,6 @@ ${lanes.join("\n")} return moduleState === 1 /* Instantiated */ || preserveConstEnums && moduleState === 2 /* ConstEnumOnly */; } function createTypeChecker(host) { - const flowTypeReferences = []; var deferredDiagnosticsCallbacks = []; var addLazyDiagnostic = (arg) => { deferredDiagnosticsCallbacks.push(arg); @@ -46173,7 +46172,10 @@ ${lanes.join("\n")} getGlobalType, // fix by uts 暴露此方法,用于将指定symbol标记为非typeOnly // @ts-ignore - markSymbolAsNotTypeOnly + markSymbolAsNotTypeOnly, + // fix by uts 暴露此方法,用于获取错误类型 + // @ts-ignore + getErrorType: () => errorType }; function runWithoutResolvedSignatureCaching(node, fn) { const cachedSignatures = []; @@ -67888,43 +67890,13 @@ ${lanes.join("\n")} } flowInvocationCount++; const sharedFlowStart = sharedFlowCount; - flowTypeReferences.push(reference); const evolvedType = getTypeFromFlowType(getTypeAtFlowNode(flowNode)); - flowTypeReferences.pop(); sharedFlowCount = sharedFlowStart; const resultType = getObjectFlags(evolvedType) & 256 /* EvolvingArray */ && isEvolvingArrayOperationTarget(reference) ? autoArrayType : finalizeEvolvingArrayType(evolvedType); if (resultType === unreachableNeverType || reference.parent && reference.parent.kind === 235 /* NonNullExpression */ && !(resultType.flags & 131072 /* Never */) && getTypeWithFacts(resultType, 2097152 /* NEUndefinedOrNull */).flags & 131072 /* Never */) { return declaredType; } - if (reference.__is_narrow_type) { - delete reference.__is_narrow_type; - if (resultType !== nonNullUnknownType && resultType !== neverType && resultType !== anyType && resultType !== declaredType && reference.parent && !isAsExpression(reference.parent)) { - let isSameType2 = function() { - if ( - // 如果是匹配到了可为空的类型,即:declaredType = A | null,resultType = A - declaredType.flags & 1048576 /* Union */ && declaredType.types.length === 2 && declaredType.types.find( - (t) => t === nullType - ) && declaredType.types.find( - (t) => t === resultType - ) - ) { - return true; - } - return false; - }; - var isSameType = isSameType2; - if (!isSameType2()) { - reference.__evolvedType = resultType; - } - } - } return resultType === nonNullUnknownType ? unknownType : resultType; - function wrapperNarrowType(type) { - if (flowTypeReferences.length) { - flowTypeReferences[flowTypeReferences.length - 1].__is_narrow_type = true; - } - return type; - } function getOrSetCacheKey() { if (isKeySet) { return key; @@ -68591,11 +68563,11 @@ ${lanes.join("\n")} } const propertyAccess = getDiscriminantPropertyAccess(target, type); if (propertyAccess) { - return wrapperNarrowType(narrowTypeByDiscriminant(type, propertyAccess, (t) => narrowTypeByLiteralExpression(t, literal, assumeTrue))); + return narrowTypeByDiscriminant(type, propertyAccess, (t) => narrowTypeByLiteralExpression(t, literal, assumeTrue)); } - return wrapperNarrowType(type); + return type; } - return wrapperNarrowType(narrowTypeByLiteralExpression(type, literal, assumeTrue)); + return narrowTypeByLiteralExpression(type, literal, assumeTrue); } function narrowTypeByLiteralExpression(type, literal, assumeTrue) { return assumeTrue ? narrowTypeByTypeName(type, literal.text) : getAdjustedTypeWithFacts(type, typeofNEFacts.get(literal.text) || 32768 /* TypeofNEHostObject */); @@ -68726,25 +68698,25 @@ ${lanes.join("\n")} const left = getReferenceCandidate(expr.left); if (!isMatchingReference(reference, left)) { if (assumeTrue && strictNullChecks && optionalChainContainsReference(left, reference)) { - return wrapperNarrowType(getAdjustedTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */)); + return getAdjustedTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */); } - return wrapperNarrowType(type); + return type; } const rightType = getTypeOfExpression(expr.right); if (!isTypeDerivedFrom(rightType, globalFunctionType)) { - return wrapperNarrowType(type); + return type; } const instanceType = mapType(rightType, getInstanceType); if (isTypeAny(type) && (instanceType === globalObjectType || instanceType === globalFunctionType) || !assumeTrue && !(instanceType.flags & 524288 /* Object */ && !isEmptyAnonymousObjectType(instanceType))) { - return wrapperNarrowType(type); + return type; } - return wrapperNarrowType(getNarrowedType( + return getNarrowedType( type, instanceType, assumeTrue, /*checkDerived*/ true - )); + ); } function getInstanceType(constructorType) { const prototypePropertyType = getTypeOfPropertyOfType(constructorType, "prototype"); diff --git a/packages/uni-uts-v1/lib/typescript/lib/typescript.js b/packages/uni-uts-v1/lib/typescript/lib/typescript.js index d8f1062e9ff..4464c067066 100644 --- a/packages/uni-uts-v1/lib/typescript/lib/typescript.js +++ b/packages/uni-uts-v1/lib/typescript/lib/typescript.js @@ -40692,13 +40692,13 @@ ${lanes.join("\n")} } function tryFileLookup(fileName, onlyRecordFailures, state) { var _a, _b, _c; - if (state && !state.isConfigLookup && ((_a = globalThis.__utsHacker__) == null ? void 0 : _a.tryFileLookup)) { - const result = (_b = globalThis.__utsHacker__) == null ? void 0 : _b.tryFileLookup(fileName); - if (result) { - return result; - } - } if (!onlyRecordFailures) { + if (state && !state.isConfigLookup && ((_a = globalThis.__utsHacker__) == null ? void 0 : _a.tryFileLookup)) { + const result = (_b = globalThis.__utsHacker__) == null ? void 0 : _b.tryFileLookup(fileName); + if (result) { + return result; + } + } if (state.host.fileExists(fileName)) { if (state.traceEnabled) { trace(state.host, Diagnostics.File_0_exists_use_it_as_a_name_resolution_result, fileName); @@ -45710,7 +45710,6 @@ ${lanes.join("\n")} return moduleState === 1 /* Instantiated */ || preserveConstEnums && moduleState === 2 /* ConstEnumOnly */; } function createTypeChecker(host) { - const flowTypeReferences = []; var deferredDiagnosticsCallbacks = []; var addLazyDiagnostic = (arg) => { deferredDiagnosticsCallbacks.push(arg); @@ -46170,7 +46169,10 @@ ${lanes.join("\n")} getGlobalType, // fix by uts 暴露此方法,用于将指定symbol标记为非typeOnly // @ts-ignore - markSymbolAsNotTypeOnly + markSymbolAsNotTypeOnly, + // fix by uts 暴露此方法,用于获取错误类型 + // @ts-ignore + getErrorType: () => errorType }; function runWithoutResolvedSignatureCaching(node, fn) { const cachedSignatures = []; @@ -67885,43 +67887,13 @@ ${lanes.join("\n")} } flowInvocationCount++; const sharedFlowStart = sharedFlowCount; - flowTypeReferences.push(reference); const evolvedType = getTypeFromFlowType(getTypeAtFlowNode(flowNode)); - flowTypeReferences.pop(); sharedFlowCount = sharedFlowStart; const resultType = getObjectFlags(evolvedType) & 256 /* EvolvingArray */ && isEvolvingArrayOperationTarget(reference) ? autoArrayType : finalizeEvolvingArrayType(evolvedType); if (resultType === unreachableNeverType || reference.parent && reference.parent.kind === 235 /* NonNullExpression */ && !(resultType.flags & 131072 /* Never */) && getTypeWithFacts(resultType, 2097152 /* NEUndefinedOrNull */).flags & 131072 /* Never */) { return declaredType; } - if (reference.__is_narrow_type) { - delete reference.__is_narrow_type; - if (resultType !== nonNullUnknownType && resultType !== neverType && resultType !== anyType && resultType !== declaredType && reference.parent && !isAsExpression(reference.parent)) { - let isSameType2 = function() { - if ( - // 如果是匹配到了可为空的类型,即:declaredType = A | null,resultType = A - declaredType.flags & 1048576 /* Union */ && declaredType.types.length === 2 && declaredType.types.find( - (t) => t === nullType - ) && declaredType.types.find( - (t) => t === resultType - ) - ) { - return true; - } - return false; - }; - var isSameType = isSameType2; - if (!isSameType2()) { - reference.__evolvedType = resultType; - } - } - } return resultType === nonNullUnknownType ? unknownType : resultType; - function wrapperNarrowType(type) { - if (flowTypeReferences.length) { - flowTypeReferences[flowTypeReferences.length - 1].__is_narrow_type = true; - } - return type; - } function getOrSetCacheKey() { if (isKeySet) { return key; @@ -68588,11 +68560,11 @@ ${lanes.join("\n")} } const propertyAccess = getDiscriminantPropertyAccess(target, type); if (propertyAccess) { - return wrapperNarrowType(narrowTypeByDiscriminant(type, propertyAccess, (t) => narrowTypeByLiteralExpression(t, literal, assumeTrue))); + return narrowTypeByDiscriminant(type, propertyAccess, (t) => narrowTypeByLiteralExpression(t, literal, assumeTrue)); } - return wrapperNarrowType(type); + return type; } - return wrapperNarrowType(narrowTypeByLiteralExpression(type, literal, assumeTrue)); + return narrowTypeByLiteralExpression(type, literal, assumeTrue); } function narrowTypeByLiteralExpression(type, literal, assumeTrue) { return assumeTrue ? narrowTypeByTypeName(type, literal.text) : getAdjustedTypeWithFacts(type, typeofNEFacts.get(literal.text) || 32768 /* TypeofNEHostObject */); @@ -68723,25 +68695,25 @@ ${lanes.join("\n")} const left = getReferenceCandidate(expr.left); if (!isMatchingReference(reference, left)) { if (assumeTrue && strictNullChecks && optionalChainContainsReference(left, reference)) { - return wrapperNarrowType(getAdjustedTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */)); + return getAdjustedTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */); } - return wrapperNarrowType(type); + return type; } const rightType = getTypeOfExpression(expr.right); if (!isTypeDerivedFrom(rightType, globalFunctionType)) { - return wrapperNarrowType(type); + return type; } const instanceType = mapType(rightType, getInstanceType); if (isTypeAny(type) && (instanceType === globalObjectType || instanceType === globalFunctionType) || !assumeTrue && !(instanceType.flags & 524288 /* Object */ && !isEmptyAnonymousObjectType(instanceType))) { - return wrapperNarrowType(type); + return type; } - return wrapperNarrowType(getNarrowedType( + return getNarrowedType( type, instanceType, assumeTrue, /*checkDerived*/ true - )); + ); } function getInstanceType(constructorType) { const prototypePropertyType = getTypeOfPropertyOfType(constructorType, "prototype");