@@ -493,6 +493,10 @@ namespace ts {
493
493
return symbol;
494
494
}
495
495
496
+ function isTransientSymbol(symbol: Symbol): symbol is TransientSymbol {
497
+ return (symbol.flags & SymbolFlags.Transient) !== 0;
498
+ }
499
+
496
500
function getExcludedSymbolFlags(flags: SymbolFlags): SymbolFlags {
497
501
let result: SymbolFlags = 0;
498
502
if (flags & SymbolFlags.BlockScopedVariable) result |= SymbolFlags.BlockScopedVariableExcludes;
@@ -3385,23 +3389,23 @@ namespace ts {
3385
3389
3386
3390
function buildParameterDisplay(p: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
3387
3391
const parameterNode = <ParameterDeclaration>p.valueDeclaration;
3388
- if (isRestParameter(parameterNode)) {
3392
+ if (parameterNode ? isRestParameter(parameterNode) : isTransientSymbol(p) && p.isRestParameter ) {
3389
3393
writePunctuation(writer, SyntaxKind.DotDotDotToken);
3390
3394
}
3391
- if (isBindingPattern(parameterNode.name)) {
3395
+ if (parameterNode && isBindingPattern(parameterNode.name)) {
3392
3396
buildBindingPatternDisplay(<BindingPattern>parameterNode.name, writer, enclosingDeclaration, flags, symbolStack);
3393
3397
}
3394
3398
else {
3395
3399
appendSymbolNameOnly(p, writer);
3396
3400
}
3397
- if (isOptionalParameter(parameterNode)) {
3401
+ if (parameterNode && isOptionalParameter(parameterNode)) {
3398
3402
writePunctuation(writer, SyntaxKind.QuestionToken);
3399
3403
}
3400
3404
writePunctuation(writer, SyntaxKind.ColonToken);
3401
3405
writeSpace(writer);
3402
3406
3403
3407
let type = getTypeOfSymbol(p);
3404
- if (isRequiredInitializedParameter(parameterNode)) {
3408
+ if (parameterNode && isRequiredInitializedParameter(parameterNode)) {
3405
3409
type = includeFalsyTypes(type, TypeFlags.Undefined);
3406
3410
}
3407
3411
buildTypeDisplay(type, writer, enclosingDeclaration, flags, symbolStack);
@@ -6170,6 +6174,37 @@ namespace ts {
6170
6174
}
6171
6175
}
6172
6176
6177
+ function containsArgumentsReference(declaration: FunctionLikeDeclaration): boolean {
6178
+ const links = getNodeLinks(declaration);
6179
+ if (links.containsArgumentsReference === undefined) {
6180
+ if (links.flags & NodeCheckFlags.CaptureArguments) {
6181
+ links.containsArgumentsReference = true;
6182
+ }
6183
+ else {
6184
+ links.containsArgumentsReference = traverse(declaration.body);
6185
+ }
6186
+ }
6187
+ return links.containsArgumentsReference;
6188
+
6189
+ function traverse(node: Node): boolean {
6190
+ if (!node) return false;
6191
+ switch (node.kind) {
6192
+ case SyntaxKind.Identifier:
6193
+ return (<Identifier>node).text === "arguments" && isPartOfExpression(node);
6194
+
6195
+ case SyntaxKind.PropertyDeclaration:
6196
+ case SyntaxKind.MethodDeclaration:
6197
+ case SyntaxKind.GetAccessor:
6198
+ case SyntaxKind.SetAccessor:
6199
+ return (<Declaration>node).name.kind === SyntaxKind.ComputedPropertyName
6200
+ && traverse((<Declaration>node).name);
6201
+
6202
+ default:
6203
+ return !nodeStartsNewLexicalEnvironment(node) && !isPartOfTypeNode(node) && forEachChild(node, traverse);
6204
+ }
6205
+ }
6206
+ }
6207
+
6173
6208
function getSignaturesOfSymbol(symbol: Symbol): Signature[] {
6174
6209
if (!symbol) return emptyArray;
6175
6210
const result: Signature[] = [];
@@ -11613,9 +11648,7 @@ namespace ts {
11613
11648
}
11614
11649
}
11615
11650
11616
- if (node.flags & NodeFlags.AwaitContext) {
11617
- getNodeLinks(container).flags |= NodeCheckFlags.CaptureArguments;
11618
- }
11651
+ getNodeLinks(container).flags |= NodeCheckFlags.CaptureArguments;
11619
11652
return getTypeOfSymbol(symbol);
11620
11653
}
11621
11654
@@ -14854,6 +14887,21 @@ namespace ts {
14854
14887
}
14855
14888
}
14856
14889
14890
+ if (signatures.length === 1) {
14891
+ const declaration = signatures[0].declaration;
14892
+ if (declaration && isInJavaScriptFile(declaration) && !hasJSDocParameterTags(declaration)) {
14893
+ if (containsArgumentsReference(<FunctionLikeDeclaration>declaration)) {
14894
+ const signatureWithRest = cloneSignature(signatures[0]);
14895
+ const syntheticArgsSymbol = createSymbol(SymbolFlags.Variable, "args");
14896
+ syntheticArgsSymbol.type = anyArrayType;
14897
+ syntheticArgsSymbol.isRestParameter = true;
14898
+ signatureWithRest.parameters = concatenate(signatureWithRest.parameters, [syntheticArgsSymbol]);
14899
+ signatureWithRest.hasRestParameter = true;
14900
+ signatures = [signatureWithRest];
14901
+ }
14902
+ }
14903
+ }
14904
+
14857
14905
const candidates = candidatesOutArray || [];
14858
14906
// reorderCandidates fills up the candidates array directly
14859
14907
reorderCandidates(signatures, candidates);
0 commit comments