Skip to content

Commit 530c876

Browse files
committed
More optimizing
1 parent 1c69acb commit 530c876

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

src/compiler/checker.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17929,13 +17929,13 @@ namespace ts {
1792917929
let overflow = false;
1793017930
let overrideNextErrorInfo = 0; // How many `reportRelationError` calls should be skipped in the elaboration pyramid
1793117931
let lastSkippedInfo: [Type, Type] | undefined;
17932-
let incompatibleStack: [DiagnosticMessage, (string | number)?, (string | number)?, (string | number)?, (string | number)?][] = [];
17932+
let incompatibleStack: [DiagnosticMessage, (string | number)?, (string | number)?, (string | number)?, (string | number)?][] | undefined;
1793317933
let inPropertyCheck = false;
1793417934

1793517935
Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
1793617936

1793717937
const result = isRelatedTo(source, target, RecursionFlags.Both, /*reportErrors*/ !!errorNode, headMessage);
17938-
if (incompatibleStack.length) {
17938+
if (incompatibleStack) {
1793917939
reportIncompatibleStack();
1794017940
}
1794117941
if (overflow) {
@@ -17997,21 +17997,21 @@ namespace ts {
1799717997
return {
1799817998
errorInfo,
1799917999
lastSkippedInfo,
18000-
incompatibleStack: incompatibleStack.slice(),
18000+
incompatibleStack: incompatibleStack ? incompatibleStack.slice() : undefined,
1800118001
overrideNextErrorInfo,
18002-
relatedInfo: !relatedInfo ? undefined : relatedInfo.slice() as ([DiagnosticRelatedInformation, ...DiagnosticRelatedInformation[]] | undefined)
18002+
relatedInfo: relatedInfo ? relatedInfo.slice() as [DiagnosticRelatedInformation, ...DiagnosticRelatedInformation[]] : undefined,
1800318003
};
1800418004
}
1800518005

1800618006
function reportIncompatibleError(message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number) {
1800718007
overrideNextErrorInfo++; // Suppress the next relation error
1800818008
lastSkippedInfo = undefined; // Reset skipped info cache
18009-
incompatibleStack.push([message, arg0, arg1, arg2, arg3]);
18009+
(incompatibleStack || (incompatibleStack = [])).push([message, arg0, arg1, arg2, arg3]);
1801018010
}
1801118011

1801218012
function reportIncompatibleStack() {
18013-
const stack = incompatibleStack;
18014-
incompatibleStack = [];
18013+
const stack = incompatibleStack || [];
18014+
incompatibleStack = undefined;
1801518015
const info = lastSkippedInfo;
1801618016
lastSkippedInfo = undefined;
1801718017
if (stack.length === 1) {
@@ -18025,7 +18025,7 @@ namespace ts {
1802518025
// The first error will be the innermost, while the last will be the outermost - so by popping off the end,
1802618026
// we can build from left to right
1802718027
let path = "";
18028-
const secondaryRootErrors: typeof incompatibleStack = [];
18028+
const secondaryRootErrors: [DiagnosticMessage, (string | number)?, (string | number)?, (string | number)?, (string | number)?][] = [];
1802918029
while (stack.length) {
1803018030
const [msg, ...args] = stack.pop()!;
1803118031
switch (msg.code) {
@@ -18119,7 +18119,7 @@ namespace ts {
1811918119

1812018120
function reportError(message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): void {
1812118121
Debug.assert(!!errorNode);
18122-
if (incompatibleStack.length) reportIncompatibleStack();
18122+
if (incompatibleStack) reportIncompatibleStack();
1812318123
if (message.elidedInCompatabilityPyramid) return;
1812418124
errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2, arg3);
1812518125
}
@@ -18135,7 +18135,7 @@ namespace ts {
1813518135
}
1813618136

1813718137
function reportRelationError(message: DiagnosticMessage | undefined, source: Type, target: Type) {
18138-
if (incompatibleStack.length) reportIncompatibleStack();
18138+
if (incompatibleStack) reportIncompatibleStack();
1813918139
const [sourceType, targetType] = getTypeNamesForErrorDisplay(source, target);
1814018140
let generalizedSource = source;
1814118141
let generalizedSourceType = sourceType;
@@ -18308,41 +18308,41 @@ namespace ts {
1830818308
if (relation === comparableRelation && !(target.flags & TypeFlags.Never) && isSimpleTypeRelatedTo(target, source, relation) ||
1830918309
isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True;
1831018310

18311-
const isPerformingExcessPropertyChecks = !(intersectionState & IntersectionState.Target) && (isObjectLiteralType(source) && getObjectFlags(source) & ObjectFlags.FreshLiteral);
18312-
if (isPerformingExcessPropertyChecks) {
18313-
if (hasExcessProperties(source as FreshObjectLiteralType, target, reportErrors)) {
18314-
if (reportErrors) {
18315-
reportRelationError(headMessage, source, originalTarget.aliasSymbol ? originalTarget : target);
18311+
if (source.flags & TypeFlags.StructuredOrInstantiable || target.flags & TypeFlags.StructuredOrInstantiable) {
18312+
const isPerformingExcessPropertyChecks = !(intersectionState & IntersectionState.Target) && (isObjectLiteralType(source) && getObjectFlags(source) & ObjectFlags.FreshLiteral);
18313+
if (isPerformingExcessPropertyChecks) {
18314+
if (hasExcessProperties(source as FreshObjectLiteralType, target, reportErrors)) {
18315+
if (reportErrors) {
18316+
reportRelationError(headMessage, source, originalTarget.aliasSymbol ? originalTarget : target);
18317+
}
18318+
return Ternary.False;
1831618319
}
18317-
return Ternary.False;
1831818320
}
18319-
}
1832018321

18321-
const isPerformingCommonPropertyChecks = relation !== comparableRelation && !(intersectionState & IntersectionState.Target) &&
18322-
source.flags & (TypeFlags.Primitive | TypeFlags.Object | TypeFlags.Intersection) && source !== globalObjectType &&
18323-
target.flags & (TypeFlags.Object | TypeFlags.Intersection) && isWeakType(target) &&
18324-
(getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source));
18325-
const isComparingJsxAttributes = !!(getObjectFlags(source) & ObjectFlags.JsxAttributes);
18326-
if (isPerformingCommonPropertyChecks && !hasCommonProperties(source, target, isComparingJsxAttributes)) {
18327-
if (reportErrors) {
18328-
const sourceString = typeToString(originalSource.aliasSymbol ? originalSource : source);
18329-
const targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
18330-
const calls = getSignaturesOfType(source, SignatureKind.Call);
18331-
const constructs = getSignaturesOfType(source, SignatureKind.Construct);
18332-
if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, RecursionFlags.Source, /*reportErrors*/ false) ||
18333-
constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, RecursionFlags.Source, /*reportErrors*/ false)) {
18334-
reportError(Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
18335-
}
18336-
else {
18337-
reportError(Diagnostics.Type_0_has_no_properties_in_common_with_type_1, sourceString, targetString);
18322+
const isPerformingCommonPropertyChecks = relation !== comparableRelation && !(intersectionState & IntersectionState.Target) &&
18323+
source.flags & (TypeFlags.Primitive | TypeFlags.Object | TypeFlags.Intersection) && source !== globalObjectType &&
18324+
target.flags & (TypeFlags.Object | TypeFlags.Intersection) && isWeakType(target) &&
18325+
(getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source));
18326+
const isComparingJsxAttributes = !!(getObjectFlags(source) & ObjectFlags.JsxAttributes);
18327+
if (isPerformingCommonPropertyChecks && !hasCommonProperties(source, target, isComparingJsxAttributes)) {
18328+
if (reportErrors) {
18329+
const sourceString = typeToString(originalSource.aliasSymbol ? originalSource : source);
18330+
const targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
18331+
const calls = getSignaturesOfType(source, SignatureKind.Call);
18332+
const constructs = getSignaturesOfType(source, SignatureKind.Construct);
18333+
if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, RecursionFlags.Source, /*reportErrors*/ false) ||
18334+
constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, RecursionFlags.Source, /*reportErrors*/ false)) {
18335+
reportError(Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
18336+
}
18337+
else {
18338+
reportError(Diagnostics.Type_0_has_no_properties_in_common_with_type_1, sourceString, targetString);
18339+
}
1833818340
}
18341+
return Ternary.False;
1833918342
}
18340-
return Ternary.False;
18341-
}
1834218343

18343-
traceUnionsOrIntersectionsTooLarge(source, target);
18344+
traceUnionsOrIntersectionsTooLarge(source, target);
1834418345

18345-
if (source.flags & TypeFlags.StructuredOrInstantiable || target.flags & TypeFlags.StructuredOrInstantiable) {
1834618346
const skipCaching = source.flags & TypeFlags.Union && (source as UnionType).types.length < 4 && !(target.flags & TypeFlags.Union) ||
1834718347
target.flags & TypeFlags.Union && (target as UnionType).types.length < 4 && !(source.flags & TypeFlags.StructuredOrInstantiable);
1834818348
let result = skipCaching ?

0 commit comments

Comments
 (0)