mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 00:56:38 -05:00
[WIP] Improve optional chaining checker performance (#33794)
* Improve optional chaining checker performance * Improve optional chaining checker performance * Add flags to Signature * Inline getOptionalExpression * split checks for optional chains * Cache optional call signatures
This commit is contained in:
@@ -233,14 +233,14 @@ namespace ts.codefix {
|
||||
let someSigHasRestParameter = false;
|
||||
for (const sig of signatures) {
|
||||
minArgumentCount = Math.min(sig.minArgumentCount, minArgumentCount);
|
||||
if (sig.hasRestParameter) {
|
||||
if (signatureHasRestParameter(sig)) {
|
||||
someSigHasRestParameter = true;
|
||||
}
|
||||
if (sig.parameters.length >= maxArgsSignature.parameters.length && (!sig.hasRestParameter || maxArgsSignature.hasRestParameter)) {
|
||||
if (sig.parameters.length >= maxArgsSignature.parameters.length && (!signatureHasRestParameter(sig) || signatureHasRestParameter(maxArgsSignature))) {
|
||||
maxArgsSignature = sig;
|
||||
}
|
||||
}
|
||||
const maxNonRestArgs = maxArgsSignature.parameters.length - (maxArgsSignature.hasRestParameter ? 1 : 0);
|
||||
const maxNonRestArgs = maxArgsSignature.parameters.length - (signatureHasRestParameter(maxArgsSignature) ? 1 : 0);
|
||||
const maxArgsParameterSymbolNames = maxArgsSignature.parameters.map(symbol => symbol.name);
|
||||
|
||||
const parameters = createDummyParameters(maxNonRestArgs, maxArgsParameterSymbolNames, /* types */ undefined, minArgumentCount, /*inJs*/ false);
|
||||
|
||||
@@ -1112,7 +1112,7 @@ namespace ts.codefix {
|
||||
}
|
||||
const returnType = combineFromUsage(combineUsages(calls.map(call => call.return_)));
|
||||
// TODO: GH#18217
|
||||
return checker.createSignature(/*declaration*/ undefined!, /*typeParameters*/ undefined, /*thisParameter*/ undefined, parameters, returnType, /*typePredicate*/ undefined, length, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
|
||||
return checker.createSignature(/*declaration*/ undefined!, /*typeParameters*/ undefined, /*thisParameter*/ undefined, parameters, returnType, /*typePredicate*/ undefined, length, SignatureFlags.None);
|
||||
}
|
||||
|
||||
function addCandidateType(usage: Usage, type: Type | undefined) {
|
||||
|
||||
@@ -464,6 +464,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
class SignatureObject implements Signature {
|
||||
flags: SignatureFlags;
|
||||
checker: TypeChecker;
|
||||
declaration!: SignatureDeclaration;
|
||||
typeParameters?: TypeParameter[];
|
||||
@@ -473,8 +474,6 @@ namespace ts {
|
||||
resolvedTypePredicate: TypePredicate | undefined;
|
||||
minTypeArgumentCount!: number;
|
||||
minArgumentCount!: number;
|
||||
hasRestParameter!: boolean;
|
||||
hasLiteralTypes!: boolean;
|
||||
|
||||
// Undefined is used to indicate the value has not been computed. If, after computing, the
|
||||
// symbol has no doc comment, then the empty array will be returned.
|
||||
@@ -484,9 +483,11 @@ namespace ts {
|
||||
// symbol has no doc comment, then the empty array will be returned.
|
||||
jsDocTags?: JSDocTagInfo[];
|
||||
|
||||
constructor(checker: TypeChecker) {
|
||||
constructor(checker: TypeChecker, flags: SignatureFlags) {
|
||||
this.checker = checker;
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
getDeclaration(): SignatureDeclaration {
|
||||
return this.declaration;
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace ts.Completions.StringCompletions {
|
||||
const candidates: Signature[] = [];
|
||||
checker.getResolvedSignature(argumentInfo.invocation, candidates, argumentInfo.argumentCount);
|
||||
const types = flatMap(candidates, candidate => {
|
||||
if (!candidate.hasRestParameter && argumentInfo.argumentCount > candidate.parameters.length) return;
|
||||
if (!signatureHasRestParameter(candidate) && argumentInfo.argumentCount > candidate.parameters.length) return;
|
||||
const type = checker.getParameterType(candidate, argumentInfo.argumentIndex);
|
||||
isNewIdentifier = isNewIdentifier || !!(type.flags & TypeFlags.String);
|
||||
return getStringLiteralTypes(type, uniques);
|
||||
|
||||
Reference in New Issue
Block a user