@@ -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;
@@ -717,7 +721,7 @@ namespace ts {
717
721
}
718
722
// declaration is after usage
719
723
// can be legal if usage is deferred (i.e. inside function or in initializer of instance property)
720
- if (isUsedInFunctionOrInstanceProperty(usage)) {
724
+ if (isUsedInFunctionOrInstanceProperty(usage, declaration )) {
721
725
return true;
722
726
}
723
727
const sourceFiles = host.getSourceFiles();
@@ -748,8 +752,7 @@ namespace ts {
748
752
// 1. inside a function
749
753
// 2. inside an instance property initializer, a reference to a non-instance property
750
754
const container = getEnclosingBlockScopeContainer(declaration);
751
- const isInstanceProperty = declaration.kind === SyntaxKind.PropertyDeclaration && !(getModifierFlags(declaration) & ModifierFlags.Static);
752
- return isUsedInFunctionOrInstanceProperty(usage, isInstanceProperty, container);
755
+ return isUsedInFunctionOrInstanceProperty(usage, declaration, container);
753
756
754
757
function isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration: VariableDeclaration, usage: Node): boolean {
755
758
const container = getEnclosingBlockScopeContainer(declaration);
@@ -778,7 +781,7 @@ namespace ts {
778
781
return false;
779
782
}
780
783
781
- function isUsedInFunctionOrInstanceProperty(usage: Node, isDeclarationInstanceProperty?: boolean , container?: Node): boolean {
784
+ function isUsedInFunctionOrInstanceProperty(usage: Node, declaration: Node , container?: Node): boolean {
782
785
let current = usage;
783
786
while (current) {
784
787
if (current === container) {
@@ -795,7 +798,8 @@ namespace ts {
795
798
(<PropertyDeclaration>current.parent).initializer === current;
796
799
797
800
if (initializerOfInstanceProperty) {
798
- return !isDeclarationInstanceProperty;
801
+ const isDeclarationInstanceProperty = declaration.kind === SyntaxKind.PropertyDeclaration && !(getModifierFlags(declaration) & ModifierFlags.Static);
802
+ return !isDeclarationInstanceProperty || getContainingClass(usage) !== getContainingClass(declaration);
799
803
}
800
804
801
805
current = current.parent;
@@ -1540,9 +1544,9 @@ namespace ts {
1540
1544
}
1541
1545
}
1542
1546
else if (name.kind === SyntaxKind.ParenthesizedExpression) {
1543
- // If the expression in parenthsizedExpression is not an entity-name (e.g. it is a call expression), it won't be able to successfully resolve the name.
1544
- // This is the case when we are trying to do any language service operation in heritage clauses. By return undefined, the getSymbolOfEntityNameOrPropertyAccessExpression
1545
- // will attempt to checkPropertyAccessExpression to resolve symbol.
1547
+ // If the expression in parenthesizedExpression is not an entity-name (e.g. it is a call expression), it won't be able to successfully resolve the name.
1548
+ // This is the case when we are trying to do any language service operation in heritage clauses.
1549
+ // By return undefined, the getSymbolOfEntityNameOrPropertyAccessExpression will attempt to checkPropertyAccessExpression to resolve symbol.
1546
1550
// i.e class C extends foo()./*do language service operation here*/B {}
1547
1551
return isEntityNameExpression(name.expression) ?
1548
1552
resolveEntityName(name.expression as EntityNameOrEntityNameExpression, meaning, ignoreErrors, dontResolveAlias, location) :
@@ -1560,7 +1564,7 @@ namespace ts {
1560
1564
}
1561
1565
1562
1566
function resolveExternalModuleNameWorker(location: Node, moduleReferenceExpression: Expression, moduleNotFoundError: DiagnosticMessage, isForAugmentation = false): Symbol {
1563
- if (moduleReferenceExpression.kind !== SyntaxKind.StringLiteral) {
1567
+ if (moduleReferenceExpression.kind !== SyntaxKind.StringLiteral && moduleReferenceExpression.kind !== SyntaxKind.NoSubstitutionTemplateLiteral ) {
1564
1568
return;
1565
1569
}
1566
1570
@@ -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[] = [];
@@ -10347,6 +10382,8 @@ namespace ts {
10347
10382
getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(<Identifier>source)) === getSymbolOfNode(target);
10348
10383
case SyntaxKind.ThisKeyword:
10349
10384
return target.kind === SyntaxKind.ThisKeyword;
10385
+ case SyntaxKind.SuperKeyword:
10386
+ return target.kind === SyntaxKind.SuperKeyword;
10350
10387
case SyntaxKind.PropertyAccessExpression:
10351
10388
return target.kind === SyntaxKind.PropertyAccessExpression &&
10352
10389
(<PropertyAccessExpression>source).name.text === (<PropertyAccessExpression>target).name.text &&
@@ -11483,6 +11520,7 @@ namespace ts {
11483
11520
switch (expr.kind) {
11484
11521
case SyntaxKind.Identifier:
11485
11522
case SyntaxKind.ThisKeyword:
11523
+ case SyntaxKind.SuperKeyword:
11486
11524
case SyntaxKind.PropertyAccessExpression:
11487
11525
return narrowTypeByTruthiness(type, expr, assumeTrue);
11488
11526
case SyntaxKind.CallExpression:
@@ -11613,9 +11651,7 @@ namespace ts {
11613
11651
}
11614
11652
}
11615
11653
11616
- if (node.flags & NodeFlags.AwaitContext) {
11617
- getNodeLinks(container).flags |= NodeCheckFlags.CaptureArguments;
11618
- }
11654
+ getNodeLinks(container).flags |= NodeCheckFlags.CaptureArguments;
11619
11655
return getTypeOfSymbol(symbol);
11620
11656
}
11621
11657
@@ -14854,6 +14890,21 @@ namespace ts {
14854
14890
}
14855
14891
}
14856
14892
14893
+ if (signatures.length === 1) {
14894
+ const declaration = signatures[0].declaration;
14895
+ if (declaration && isInJavaScriptFile(declaration) && !hasJSDocParameterTags(declaration)) {
14896
+ if (containsArgumentsReference(<FunctionLikeDeclaration>declaration)) {
14897
+ const signatureWithRest = cloneSignature(signatures[0]);
14898
+ const syntheticArgsSymbol = createSymbol(SymbolFlags.Variable, "args");
14899
+ syntheticArgsSymbol.type = anyArrayType;
14900
+ syntheticArgsSymbol.isRestParameter = true;
14901
+ signatureWithRest.parameters = concatenate(signatureWithRest.parameters, [syntheticArgsSymbol]);
14902
+ signatureWithRest.hasRestParameter = true;
14903
+ signatures = [signatureWithRest];
14904
+ }
14905
+ }
14906
+ }
14907
+
14857
14908
const candidates = candidatesOutArray || [];
14858
14909
// reorderCandidates fills up the candidates array directly
14859
14910
reorderCandidates(signatures, candidates);
0 commit comments