Skip to content

Commit

Permalink
chore(uts): sync compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Jan 9, 2025
1 parent 654d9a5 commit 7174ca4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 13 deletions.
37 changes: 31 additions & 6 deletions packages/uni-uts-v1/lib/typescript/lib/typescript.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -46175,8 +46175,33 @@ ${lanes.join("\n")}
markSymbolAsNotTypeOnly,
// fix by uts 暴露此方法,用于获取错误类型
// @ts-ignore
getErrorType: () => errorType
getErrorType: () => errorType,
// fix by uts 暴露此方法,用于收窄 in 操作符
narrowTypeByInKeyword
};
function isTypePresencePossible(type, propName, assumeTrue) {
const prop = getPropertyOfType(type, propName);
return prop ? !!(prop.flags & 16777216 /* Optional */ || getCheckFlags(prop) & 48 /* Partial */) || assumeTrue : !!getApplicableIndexInfoForName(type, propName) || !assumeTrue;
}
function narrowTypeByInKeyword(type, nameType, assumeTrue) {
const name = getPropertyNameFromType(nameType);
const isKnownProperty2 = someType(type, (t) => isTypePresencePossible(
t,
name,
/*assumeTrue*/
true
));
if (isKnownProperty2) {
return filterType(type, (t) => isTypePresencePossible(t, name, assumeTrue));
}
if (assumeTrue) {
const recordSymbol = getGlobalRecordSymbol();
if (recordSymbol) {
return getIntersectionType([type, getTypeAliasInstantiation(recordSymbol, [nameType, unknownType])]);
}
}
return type;
}
function runWithoutResolvedSignatureCaching(node, fn) {
const cachedSignatures = [];
while (node) {
Expand Down Expand Up @@ -68352,20 +68377,20 @@ ${lanes.join("\n")}
}
return type;
}
function isTypePresencePossible(type, propName, assumeTrue) {
function isTypePresencePossible2(type, propName, assumeTrue) {
const prop = getPropertyOfType(type, propName);
return prop ? !!(prop.flags & 16777216 /* Optional */ || getCheckFlags(prop) & 48 /* Partial */) || assumeTrue : !!getApplicableIndexInfoForName(type, propName) || !assumeTrue;
}
function narrowTypeByInKeyword(type, nameType, assumeTrue) {
function narrowTypeByInKeyword2(type, nameType, assumeTrue) {
const name = getPropertyNameFromType(nameType);
const isKnownProperty2 = someType(type, (t) => isTypePresencePossible(
const isKnownProperty2 = someType(type, (t) => isTypePresencePossible2(
t,
name,
/*assumeTrue*/
true
));
if (isKnownProperty2) {
return filterType(type, (t) => isTypePresencePossible(t, name, assumeTrue));
return filterType(type, (t) => isTypePresencePossible2(t, name, assumeTrue));
}
if (assumeTrue) {
const recordSymbol = getGlobalRecordSymbol();
Expand Down Expand Up @@ -68439,7 +68464,7 @@ ${lanes.join("\n")}
if (isMatchingReference(reference, target)) {
const leftType = getTypeOfExpression(expr.left);
if (isTypeUsableAsPropertyName(leftType)) {
return narrowTypeByInKeyword(type, leftType, assumeTrue);
return narrowTypeByInKeyword2(type, leftType, assumeTrue);
}
}
break;
Expand Down
37 changes: 31 additions & 6 deletions packages/uni-uts-v1/lib/typescript/lib/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -46172,8 +46172,33 @@ ${lanes.join("\n")}
markSymbolAsNotTypeOnly,
// fix by uts 暴露此方法,用于获取错误类型
// @ts-ignore
getErrorType: () => errorType
getErrorType: () => errorType,
// fix by uts 暴露此方法,用于收窄 in 操作符
narrowTypeByInKeyword
};
function isTypePresencePossible(type, propName, assumeTrue) {
const prop = getPropertyOfType(type, propName);
return prop ? !!(prop.flags & 16777216 /* Optional */ || getCheckFlags(prop) & 48 /* Partial */) || assumeTrue : !!getApplicableIndexInfoForName(type, propName) || !assumeTrue;
}
function narrowTypeByInKeyword(type, nameType, assumeTrue) {
const name = getPropertyNameFromType(nameType);
const isKnownProperty2 = someType(type, (t) => isTypePresencePossible(
t,
name,
/*assumeTrue*/
true
));
if (isKnownProperty2) {
return filterType(type, (t) => isTypePresencePossible(t, name, assumeTrue));
}
if (assumeTrue) {
const recordSymbol = getGlobalRecordSymbol();
if (recordSymbol) {
return getIntersectionType([type, getTypeAliasInstantiation(recordSymbol, [nameType, unknownType])]);
}
}
return type;
}
function runWithoutResolvedSignatureCaching(node, fn) {
const cachedSignatures = [];
while (node) {
Expand Down Expand Up @@ -68349,20 +68374,20 @@ ${lanes.join("\n")}
}
return type;
}
function isTypePresencePossible(type, propName, assumeTrue) {
function isTypePresencePossible2(type, propName, assumeTrue) {
const prop = getPropertyOfType(type, propName);
return prop ? !!(prop.flags & 16777216 /* Optional */ || getCheckFlags(prop) & 48 /* Partial */) || assumeTrue : !!getApplicableIndexInfoForName(type, propName) || !assumeTrue;
}
function narrowTypeByInKeyword(type, nameType, assumeTrue) {
function narrowTypeByInKeyword2(type, nameType, assumeTrue) {
const name = getPropertyNameFromType(nameType);
const isKnownProperty2 = someType(type, (t) => isTypePresencePossible(
const isKnownProperty2 = someType(type, (t) => isTypePresencePossible2(
t,
name,
/*assumeTrue*/
true
));
if (isKnownProperty2) {
return filterType(type, (t) => isTypePresencePossible(t, name, assumeTrue));
return filterType(type, (t) => isTypePresencePossible2(t, name, assumeTrue));
}
if (assumeTrue) {
const recordSymbol = getGlobalRecordSymbol();
Expand Down Expand Up @@ -68436,7 +68461,7 @@ ${lanes.join("\n")}
if (isMatchingReference(reference, target)) {
const leftType = getTypeOfExpression(expr.left);
if (isTypeUsableAsPropertyName(leftType)) {
return narrowTypeByInKeyword(type, leftType, assumeTrue);
return narrowTypeByInKeyword2(type, leftType, assumeTrue);
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion packages/uni-uts-v1/lib/uni-x/dist/compiler.js

Large diffs are not rendered by default.

0 comments on commit 7174ca4

Please sign in to comment.