Skip to content

Commit aaf0f78

Browse files
Merge pull request #3778 from Microsoft/noPushApply
Don't call push.apply, it can stack overflow with large arrays.
2 parents 1344b14 + e0e9bcf commit aaf0f78

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

Diff for: src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3305,7 +3305,7 @@ namespace ts {
33053305
let declarations: Declaration[] = [];
33063306
for (let prop of props) {
33073307
if (prop.declarations) {
3308-
declarations.push.apply(declarations, prop.declarations);
3308+
addRange(declarations, prop.declarations);
33093309
}
33103310
propTypes.push(getTypeOfSymbol(prop));
33113311
}

Diff for: src/services/navigationBar.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ namespace ts.NavigationBar {
228228

229229
function merge(target: ts.NavigationBarItem, source: ts.NavigationBarItem) {
230230
// First, add any spans in the source to the target.
231-
target.spans.push.apply(target.spans, source.spans);
231+
addRange(target.spans, source.spans);
232232

233233
if (source.childItems) {
234234
if (!target.childItems) {
@@ -465,7 +465,7 @@ namespace ts.NavigationBar {
465465
// are not properties will be filtered out later by createChildItem.
466466
let nodes: Node[] = removeDynamicallyNamedProperties(node);
467467
if (constructor) {
468-
nodes.push.apply(nodes, filter(constructor.parameters, p => !isBindingPattern(p.name)));
468+
addRange(nodes, filter(constructor.parameters, p => !isBindingPattern(p.name)));
469469
}
470470

471471
childItems = getItemsWorker(sortNodes(nodes), createChildItem);

Diff for: src/services/services.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ namespace ts {
345345
ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), jsDocCommentTextRange => {
346346
let cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration);
347347
if (cleanedParamJsDocComment) {
348-
jsDocCommentParts.push.apply(jsDocCommentParts, cleanedParamJsDocComment);
348+
addRange(jsDocCommentParts, cleanedParamJsDocComment);
349349
}
350350
});
351351
}
@@ -365,7 +365,7 @@ namespace ts {
365365
declaration.kind === SyntaxKind.VariableDeclaration ? declaration.parent.parent : declaration, sourceFileOfDeclaration), jsDocCommentTextRange => {
366366
let cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration);
367367
if (cleanedJsDocComment) {
368-
jsDocCommentParts.push.apply(jsDocCommentParts, cleanedJsDocComment);
368+
addRange(jsDocCommentParts, cleanedJsDocComment);
369369
}
370370
});
371371
}
@@ -3854,7 +3854,7 @@ namespace ts {
38543854
displayParts.push(spacePart());
38553855
}
38563856
if (!(type.flags & TypeFlags.Anonymous)) {
3857-
displayParts.push.apply(displayParts, symbolToDisplayParts(typeChecker, type.symbol, enclosingDeclaration, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments));
3857+
addRange(displayParts, symbolToDisplayParts(typeChecker, type.symbol, enclosingDeclaration, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments));
38583858
}
38593859
addSignatureDisplayParts(signature, allSignatures, TypeFormatFlags.WriteArrowStyleSignature);
38603860
break;
@@ -3915,7 +3915,7 @@ namespace ts {
39153915
displayParts.push(spacePart());
39163916
displayParts.push(operatorPart(SyntaxKind.EqualsToken));
39173917
displayParts.push(spacePart());
3918-
displayParts.push.apply(displayParts, typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration));
3918+
addRange(displayParts, typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration));
39193919
}
39203920
if (symbolFlags & SymbolFlags.Enum) {
39213921
addNewLineIfDisplayPartsExist();
@@ -3961,7 +3961,7 @@ namespace ts {
39613961
else if (signatureDeclaration.kind !== SyntaxKind.CallSignature && signatureDeclaration.name) {
39623962
addFullSymbolName(signatureDeclaration.symbol);
39633963
}
3964-
displayParts.push.apply(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature));
3964+
addRange(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature));
39653965
}
39663966
}
39673967
if (symbolFlags & SymbolFlags.EnumMember) {
@@ -4022,10 +4022,10 @@ namespace ts {
40224022
let typeParameterParts = mapToDisplayParts(writer => {
40234023
typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(<TypeParameter>type, writer, enclosingDeclaration);
40244024
});
4025-
displayParts.push.apply(displayParts, typeParameterParts);
4025+
addRange(displayParts, typeParameterParts);
40264026
}
40274027
else {
4028-
displayParts.push.apply(displayParts, typeToDisplayParts(typeChecker, type, enclosingDeclaration));
4028+
addRange(displayParts, typeToDisplayParts(typeChecker, type, enclosingDeclaration));
40294029
}
40304030
}
40314031
else if (symbolFlags & SymbolFlags.Function ||
@@ -4059,7 +4059,7 @@ namespace ts {
40594059
function addFullSymbolName(symbol: Symbol, enclosingDeclaration?: Node) {
40604060
let fullSymbolDisplayParts = symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration || sourceFile, /*meaning*/ undefined,
40614061
SymbolFormatFlags.WriteTypeParametersOrArguments | SymbolFormatFlags.UseOnlyExternalAliasing);
4062-
displayParts.push.apply(displayParts, fullSymbolDisplayParts);
4062+
addRange(displayParts, fullSymbolDisplayParts);
40634063
}
40644064

40654065
function addPrefixForAnyFunctionOrVar(symbol: Symbol, symbolKind: string) {
@@ -4089,7 +4089,7 @@ namespace ts {
40894089
}
40904090

40914091
function addSignatureDisplayParts(signature: Signature, allSignatures: Signature[], flags?: TypeFormatFlags) {
4092-
displayParts.push.apply(displayParts, signatureToDisplayParts(typeChecker, signature, enclosingDeclaration, flags | TypeFormatFlags.WriteTypeArgumentsOfSignature));
4092+
addRange(displayParts, signatureToDisplayParts(typeChecker, signature, enclosingDeclaration, flags | TypeFormatFlags.WriteTypeArgumentsOfSignature));
40934093
if (allSignatures.length > 1) {
40944094
displayParts.push(spacePart());
40954095
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
@@ -4106,7 +4106,7 @@ namespace ts {
41064106
let typeParameterParts = mapToDisplayParts(writer => {
41074107
typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration);
41084108
});
4109-
displayParts.push.apply(displayParts, typeParameterParts);
4109+
addRange(displayParts, typeParameterParts);
41104110
}
41114111
}
41124112

@@ -5620,7 +5620,7 @@ namespace ts {
56205620
// type to the search set
56215621
if (isNameOfPropertyAssignment(location)) {
56225622
forEach(getPropertySymbolsFromContextualType(location), contextualSymbol => {
5623-
result.push.apply(result, typeChecker.getRootSymbols(contextualSymbol));
5623+
addRange(result, typeChecker.getRootSymbols(contextualSymbol));
56245624
});
56255625

56265626
/* Because in short-hand property assignment, location has two meaning : property name and as value of the property

Diff for: src/services/signatureHelp.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ namespace ts.SignatureHelp {
550550
let suffixDisplayParts: SymbolDisplayPart[] = [];
551551

552552
if (callTargetDisplayParts) {
553-
prefixDisplayParts.push.apply(prefixDisplayParts, callTargetDisplayParts);
553+
addRange(prefixDisplayParts, callTargetDisplayParts);
554554
}
555555

556556
if (isTypeParameterList) {
@@ -560,12 +560,12 @@ namespace ts.SignatureHelp {
560560
suffixDisplayParts.push(punctuationPart(SyntaxKind.GreaterThanToken));
561561
let parameterParts = mapToDisplayParts(writer =>
562562
typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, invocation));
563-
suffixDisplayParts.push.apply(suffixDisplayParts, parameterParts);
563+
addRange(suffixDisplayParts, parameterParts);
564564
}
565565
else {
566566
let typeParameterParts = mapToDisplayParts(writer =>
567567
typeChecker.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, invocation));
568-
prefixDisplayParts.push.apply(prefixDisplayParts, typeParameterParts);
568+
addRange(prefixDisplayParts, typeParameterParts);
569569
prefixDisplayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
570570

571571
let parameters = candidateSignature.parameters;
@@ -575,7 +575,7 @@ namespace ts.SignatureHelp {
575575

576576
let returnTypeParts = mapToDisplayParts(writer =>
577577
typeChecker.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, invocation));
578-
suffixDisplayParts.push.apply(suffixDisplayParts, returnTypeParts);
578+
addRange(suffixDisplayParts, returnTypeParts);
579579

580580
return {
581581
isVariadic: candidateSignature.hasRestParameter,

0 commit comments

Comments
 (0)