Skip to content

Commit e0e9bcf

Browse files
Don't call push.apply, it can stack overflow with large arrays.
1 parent 9b2d44a commit e0e9bcf

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

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
}

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);

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
}
@@ -3812,7 +3812,7 @@ namespace ts {
38123812
displayParts.push(spacePart());
38133813
}
38143814
if (!(type.flags & TypeFlags.Anonymous)) {
3815-
displayParts.push.apply(displayParts, symbolToDisplayParts(typeChecker, type.symbol, enclosingDeclaration, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments));
3815+
addRange(displayParts, symbolToDisplayParts(typeChecker, type.symbol, enclosingDeclaration, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments));
38163816
}
38173817
addSignatureDisplayParts(signature, allSignatures, TypeFormatFlags.WriteArrowStyleSignature);
38183818
break;
@@ -3873,7 +3873,7 @@ namespace ts {
38733873
displayParts.push(spacePart());
38743874
displayParts.push(operatorPart(SyntaxKind.EqualsToken));
38753875
displayParts.push(spacePart());
3876-
displayParts.push.apply(displayParts, typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration));
3876+
addRange(displayParts, typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration));
38773877
}
38783878
if (symbolFlags & SymbolFlags.Enum) {
38793879
addNewLineIfDisplayPartsExist();
@@ -3919,7 +3919,7 @@ namespace ts {
39193919
else if (signatureDeclaration.kind !== SyntaxKind.CallSignature && signatureDeclaration.name) {
39203920
addFullSymbolName(signatureDeclaration.symbol);
39213921
}
3922-
displayParts.push.apply(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature));
3922+
addRange(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature));
39233923
}
39243924
}
39253925
if (symbolFlags & SymbolFlags.EnumMember) {
@@ -3980,10 +3980,10 @@ namespace ts {
39803980
let typeParameterParts = mapToDisplayParts(writer => {
39813981
typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(<TypeParameter>type, writer, enclosingDeclaration);
39823982
});
3983-
displayParts.push.apply(displayParts, typeParameterParts);
3983+
addRange(displayParts, typeParameterParts);
39843984
}
39853985
else {
3986-
displayParts.push.apply(displayParts, typeToDisplayParts(typeChecker, type, enclosingDeclaration));
3986+
addRange(displayParts, typeToDisplayParts(typeChecker, type, enclosingDeclaration));
39873987
}
39883988
}
39893989
else if (symbolFlags & SymbolFlags.Function ||
@@ -4017,7 +4017,7 @@ namespace ts {
40174017
function addFullSymbolName(symbol: Symbol, enclosingDeclaration?: Node) {
40184018
let fullSymbolDisplayParts = symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration || sourceFile, /*meaning*/ undefined,
40194019
SymbolFormatFlags.WriteTypeParametersOrArguments | SymbolFormatFlags.UseOnlyExternalAliasing);
4020-
displayParts.push.apply(displayParts, fullSymbolDisplayParts);
4020+
addRange(displayParts, fullSymbolDisplayParts);
40214021
}
40224022

40234023
function addPrefixForAnyFunctionOrVar(symbol: Symbol, symbolKind: string) {
@@ -4047,7 +4047,7 @@ namespace ts {
40474047
}
40484048

40494049
function addSignatureDisplayParts(signature: Signature, allSignatures: Signature[], flags?: TypeFormatFlags) {
4050-
displayParts.push.apply(displayParts, signatureToDisplayParts(typeChecker, signature, enclosingDeclaration, flags | TypeFormatFlags.WriteTypeArgumentsOfSignature));
4050+
addRange(displayParts, signatureToDisplayParts(typeChecker, signature, enclosingDeclaration, flags | TypeFormatFlags.WriteTypeArgumentsOfSignature));
40514051
if (allSignatures.length > 1) {
40524052
displayParts.push(spacePart());
40534053
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
@@ -4064,7 +4064,7 @@ namespace ts {
40644064
let typeParameterParts = mapToDisplayParts(writer => {
40654065
typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration);
40664066
});
4067-
displayParts.push.apply(displayParts, typeParameterParts);
4067+
addRange(displayParts, typeParameterParts);
40684068
}
40694069
}
40704070

@@ -5578,7 +5578,7 @@ namespace ts {
55785578
// type to the search set
55795579
if (isNameOfPropertyAssignment(location)) {
55805580
forEach(getPropertySymbolsFromContextualType(location), contextualSymbol => {
5581-
result.push.apply(result, typeChecker.getRootSymbols(contextualSymbol));
5581+
addRange(result, typeChecker.getRootSymbols(contextualSymbol));
55825582
});
55835583

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

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)