Skip to content

Commit

Permalink
chore(uts): sync typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Dec 28, 2024
1 parent cdff3b4 commit 4eaa105
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 94 deletions.
66 changes: 19 additions & 47 deletions packages/uni-uts-v1/lib/typescript/lib/typescript.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */);
Expand Down Expand Up @@ -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");
Expand Down
66 changes: 19 additions & 47 deletions packages/uni-uts-v1/lib/typescript/lib/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */);
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 4eaa105

Please sign in to comment.