Skip to content

Commit 1a5911a

Browse files
committed
Merge branch 'master' into fix36604
2 parents 669797a + 5c8def9 commit 1a5911a

21 files changed

+342
-26
lines changed

src/compiler/checker.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -10510,7 +10510,7 @@ namespace ts {
1051010510
const signature = getSignatureFromDeclaration(node.parent);
1051110511
const parameterIndex = node.parent.parameters.indexOf(node);
1051210512
Debug.assert(parameterIndex >= 0);
10513-
return parameterIndex >= getMinArgumentCount(signature);
10513+
return parameterIndex >= getMinArgumentCount(signature, /*strongArityForUntypedJS*/ true);
1051410514
}
1051510515
const iife = getImmediatelyInvokedFunctionExpression(node.parent);
1051610516
if (iife) {
@@ -10601,6 +10601,9 @@ namespace ts {
1060110601
isValueSignatureDeclaration(declaration) &&
1060210602
!hasJSDocParameterTags(declaration) &&
1060310603
!getJSDocType(declaration);
10604+
if (isUntypedSignatureInJSFile) {
10605+
flags |= SignatureFlags.IsUntypedSignatureInJSFile;
10606+
}
1060410607

1060510608
// If this is a JSDoc construct signature, then skip the first parameter in the
1060610609
// parameter list. The first parameter represents the return type of the construct
@@ -10631,7 +10634,6 @@ namespace ts {
1063110634
const isOptionalParameter = isOptionalJSDocParameterTag(param) ||
1063210635
param.initializer || param.questionToken || param.dotDotDotToken ||
1063310636
iife && parameters.length > iife.arguments.length && !type ||
10634-
isUntypedSignatureInJSFile ||
1063510637
isJSDocOptionalParameter(param);
1063610638
if (!isOptionalParameter) {
1063710639
minArgumentCount = parameters.length;
@@ -21107,8 +21109,10 @@ namespace ts {
2110721109
if (isInJS && className) {
2110821110
const classSymbol = checkExpression(className).symbol;
2110921111
if (classSymbol && classSymbol.members && (classSymbol.flags & SymbolFlags.Function)) {
21110-
const classType = (getDeclaredTypeOfSymbol(classSymbol) as InterfaceType).thisType!;
21111-
return getFlowTypeOfReference(node, classType);
21112+
const classType = (getDeclaredTypeOfSymbol(classSymbol) as InterfaceType).thisType;
21113+
if (classType) {
21114+
return getFlowTypeOfReference(node, classType);
21115+
}
2111221116
}
2111321117
}
2111421118
// Check if it's a constructor definition, can be either a variable decl or function decl
@@ -26377,7 +26381,7 @@ namespace ts {
2637726381
return length;
2637826382
}
2637926383

26380-
function getMinArgumentCount(signature: Signature) {
26384+
function getMinArgumentCount(signature: Signature, strongArityForUntypedJS?: boolean) {
2638126385
if (signatureHasRestParameter(signature)) {
2638226386
const restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]);
2638326387
if (isTupleType(restType)) {
@@ -26387,6 +26391,9 @@ namespace ts {
2638726391
}
2638826392
}
2638926393
}
26394+
if (!strongArityForUntypedJS && signature.flags & SignatureFlags.IsUntypedSignatureInJSFile) {
26395+
return 0;
26396+
}
2639026397
return signature.minArgumentCount;
2639126398
}
2639226399

src/compiler/emitter.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,7 @@ namespace ts {
22732273

22742274
function emitPropertyAccessExpression(node: PropertyAccessExpression) {
22752275
const expression = cast(emitExpression(node.expression), isExpression);
2276-
const token = getDotOrQuestionDotToken(node);
2276+
const token = node.questionDotToken || createNode(SyntaxKind.DotToken, node.expression.end, node.name.pos) as DotToken;
22772277
const indentBeforeDot = needsIndentation(node, node.expression, token);
22782278
const indentAfterDot = needsIndentation(node, token, node.name);
22792279

@@ -2289,7 +2289,12 @@ namespace ts {
22892289
writePunctuation(".");
22902290
}
22912291

2292-
emitTokenWithComment(token.kind, node.expression.end, writePunctuation, node);
2292+
if (node.questionDotToken) {
2293+
emit(token);
2294+
}
2295+
else {
2296+
emitTokenWithComment(token.kind, node.expression.end, writePunctuation, node);
2297+
}
22932298
increaseIndentIf(indentAfterDot, /*writeSpaceIfNotIndenting*/ false);
22942299
emit(node.name);
22952300
decreaseIndentIf(indentBeforeDot, indentAfterDot);

src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4817,6 +4817,7 @@ namespace ts {
48174817
HasLiteralTypes = 1 << 1, // Indicates signature is specialized
48184818
IsInnerCallChain = 1 << 2, // Indicates signature comes from a CallChain nested in an outer OptionalChain
48194819
IsOuterCallChain = 1 << 3, // Indicates signature comes from a CallChain that is the outermost chain of an optional expression
4820+
IsUntypedSignatureInJSFile = 1 << 4, // Indicates signature is from a js file and has no types
48204821

48214822
// We do not propagate `IsInnerCallChain` to instantiated signatures, as that would result in us
48224823
// attempting to add `| undefined` on each recursive call to `getReturnTypeOfSignature` when

src/compiler/utilities.ts

-4
Original file line numberDiff line numberDiff line change
@@ -5052,10 +5052,6 @@ namespace ts {
50525052
}
50535053
}
50545054

5055-
export function getDotOrQuestionDotToken(node: PropertyAccessExpression) {
5056-
return node.questionDotToken || createNode(SyntaxKind.DotToken, node.expression.end, node.name.pos) as DotToken;
5057-
}
5058-
50595055
export function isNamedImportsOrExports(node: Node): node is NamedImportsOrExports {
50605056
return node.kind === SyntaxKind.NamedImports || node.kind === SyntaxKind.NamedExports;
50615057
}

src/compiler/visitorPublic.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ namespace ts {
459459
if (node.flags & NodeFlags.OptionalChain) {
460460
return updatePropertyAccessChain(<PropertyAccessChain>node,
461461
visitNode((<PropertyAccessChain>node).expression, visitor, isExpression),
462-
visitNode((<PropertyAccessChain>node).questionDotToken, visitor, isToken),
462+
visitNode((<PropertyAccessChain>node).questionDotToken, tokenVisitor, isToken),
463463
visitNode((<PropertyAccessChain>node).name, visitor, isIdentifier));
464464
}
465465
return updatePropertyAccess(<PropertyAccessExpression>node,
@@ -470,7 +470,7 @@ namespace ts {
470470
if (node.flags & NodeFlags.OptionalChain) {
471471
return updateElementAccessChain(<ElementAccessChain>node,
472472
visitNode((<ElementAccessChain>node).expression, visitor, isExpression),
473-
visitNode((<ElementAccessChain>node).questionDotToken, visitor, isToken),
473+
visitNode((<ElementAccessChain>node).questionDotToken, tokenVisitor, isToken),
474474
visitNode((<ElementAccessChain>node).argumentExpression, visitor, isExpression));
475475
}
476476
return updateElementAccess(<ElementAccessExpression>node,
@@ -481,7 +481,7 @@ namespace ts {
481481
if (node.flags & NodeFlags.OptionalChain) {
482482
return updateCallChain(<CallChain>node,
483483
visitNode((<CallChain>node).expression, visitor, isExpression),
484-
visitNode((<CallChain>node).questionDotToken, visitor, isToken),
484+
visitNode((<CallChain>node).questionDotToken, tokenVisitor, isToken),
485485
nodesVisitor((<CallChain>node).typeArguments, visitor, isTypeNode),
486486
nodesVisitor((<CallChain>node).arguments, visitor, isExpression));
487487
}
@@ -527,7 +527,7 @@ namespace ts {
527527
nodesVisitor((<ArrowFunction>node).typeParameters, visitor, isTypeParameterDeclaration),
528528
visitParameterList((<ArrowFunction>node).parameters, visitor, context, nodesVisitor),
529529
visitNode((<ArrowFunction>node).type, visitor, isTypeNode),
530-
visitNode((<ArrowFunction>node).equalsGreaterThanToken, visitor, isToken),
530+
visitNode((<ArrowFunction>node).equalsGreaterThanToken, tokenVisitor, isToken),
531531
visitFunctionBody((<ArrowFunction>node).body, visitor, context));
532532

533533
case SyntaxKind.DeleteExpression:
@@ -558,14 +558,14 @@ namespace ts {
558558
return updateBinary(<BinaryExpression>node,
559559
visitNode((<BinaryExpression>node).left, visitor, isExpression),
560560
visitNode((<BinaryExpression>node).right, visitor, isExpression),
561-
visitNode((<BinaryExpression>node).operatorToken, visitor, isToken));
561+
visitNode((<BinaryExpression>node).operatorToken, tokenVisitor, isToken));
562562

563563
case SyntaxKind.ConditionalExpression:
564564
return updateConditional(<ConditionalExpression>node,
565565
visitNode((<ConditionalExpression>node).condition, visitor, isExpression),
566-
visitNode((<ConditionalExpression>node).questionToken, visitor, isToken),
566+
visitNode((<ConditionalExpression>node).questionToken, tokenVisitor, isToken),
567567
visitNode((<ConditionalExpression>node).whenTrue, visitor, isExpression),
568-
visitNode((<ConditionalExpression>node).colonToken, visitor, isToken),
568+
visitNode((<ConditionalExpression>node).colonToken, tokenVisitor, isToken),
569569
visitNode((<ConditionalExpression>node).whenFalse, visitor, isExpression));
570570

571571
case SyntaxKind.TemplateExpression:
@@ -659,7 +659,7 @@ namespace ts {
659659

660660
case SyntaxKind.ForOfStatement:
661661
return updateForOf(<ForOfStatement>node,
662-
visitNode((<ForOfStatement>node).awaitModifier, visitor, isToken),
662+
visitNode((<ForOfStatement>node).awaitModifier, tokenVisitor, isToken),
663663
visitNode((<ForOfStatement>node).initializer, visitor, isForInitializer),
664664
visitNode((<ForOfStatement>node).expression, visitor, isExpression),
665665
visitNode((<ForOfStatement>node).statement, visitor, isStatement, liftToBlock));

src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl

+27-3
Original file line numberDiff line numberDiff line change
@@ -7020,6 +7020,12 @@
70207020
</Str>
70217021
<Disp Icon="Str" />
70227022
</Item>
7023+
<Item ItemId=";Only_named_exports_may_use_export_type_1383" ItemType="0" PsrId="306" Leaf="true">
7024+
<Str Cat="Text">
7025+
<Val><![CDATA[Only named exports may use 'export type'.]]></Val>
7026+
</Str>
7027+
<Disp Icon="Str" />
7028+
</Item>
70237029
<Item ItemId=";Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword_2340" ItemType="0" PsrId="306" Leaf="true">
70247030
<Str Cat="Text">
70257031
<Val><![CDATA[Only public and protected methods of the base class are accessible via the 'super' keyword.]]></Val>
@@ -7047,11 +7053,20 @@
70477053
</Str>
70487054
<Disp Icon="Str" />
70497055
</Item>
7050-
<Item ItemId=";Option_0_can_only_be_specified_in_tsconfig_json_file_6064" ItemType="0" PsrId="306" Leaf="true">
7056+
<Item ItemId=";Option_0_can_only_be_specified_in_tsconfig_json_file_or_set_to_false_or_null_on_command_line_6230" ItemType="0" PsrId="306" Leaf="true">
7057+
<Str Cat="Text">
7058+
<Val><![CDATA[Option '{0}' can only be specified in 'tsconfig.json' file or set to 'false' or 'null' on command line.]]></Val>
7059+
<Tgt Cat="Text" Stat="Loc" Orig="New">
7060+
<Val><![CDATA[La opción "{0}" solo puede especificarse en el archivo "tsconfig.json" o establecerse en "false" o "null" en la línea de comandos.]]></Val>
7061+
</Tgt>
7062+
</Str>
7063+
<Disp Icon="Str" />
7064+
</Item>
7065+
<Item ItemId=";Option_0_can_only_be_specified_in_tsconfig_json_file_or_set_to_null_on_command_line_6064" ItemType="0" PsrId="306" Leaf="true">
70517066
<Str Cat="Text">
7052-
<Val><![CDATA[Option '{0}' can only be specified in 'tsconfig.json' file.]]></Val>
7067+
<Val><![CDATA[Option '{0}' can only be specified in 'tsconfig.json' file or set to 'null' on command line.]]></Val>
70537068
<Tgt Cat="Text" Stat="Loc" Orig="New">
7054-
<Val><![CDATA[La opción '{0}' solo se puede especificar en el archivo 'tsconfig.json'.]]></Val>
7069+
<Val><![CDATA[La opción "{0}" solo puede especificarse en el archivo "tsconfig.json" o establecerse en "null" en la línea de comandos.]]></Val>
70557070
</Tgt>
70567071
</Str>
70577072
<Disp Icon="Str" />
@@ -9543,6 +9558,9 @@
95439558
<Item ItemId=";Tag_0_expects_at_least_1_arguments_but_the_JSX_factory_2_provides_at_most_3_6229" ItemType="0" PsrId="306" Leaf="true">
95449559
<Str Cat="Text">
95459560
<Val><![CDATA[Tag '{0}' expects at least '{1}' arguments, but the JSX factory '{2}' provides at most '{3}'.]]></Val>
9561+
<Tgt Cat="Text" Stat="Loc" Orig="New">
9562+
<Val><![CDATA[La etiqueta "{0}" espera al menos "{1}" argumentos, pero el generador de JSX "{2}" proporciona como máximo "{3}".]]></Val>
9563+
</Tgt>
95469564
</Str>
95479565
<Disp Icon="Str" />
95489566
</Item>
@@ -10869,6 +10887,12 @@
1086910887
</Str>
1087010888
<Disp Icon="Str" />
1087110889
</Item>
10890+
<Item ItemId=";Type_of_property_0_circularly_references_itself_in_mapped_type_1_2615" ItemType="0" PsrId="306" Leaf="true">
10891+
<Str Cat="Text">
10892+
<Val><![CDATA[Type of property '{0}' circularly references itself in mapped type '{1}'.]]></Val>
10893+
</Str>
10894+
<Disp Icon="Str" />
10895+
</Item>
1087210896
<Item ItemId=";Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_cal_1321" ItemType="0" PsrId="306" Leaf="true">
1087310897
<Str Cat="Text">
1087410898
<Val><![CDATA[Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.]]></Val>

src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl

+27-3
Original file line numberDiff line numberDiff line change
@@ -7008,6 +7008,12 @@
70087008
</Str>
70097009
<Disp Icon="Str" />
70107010
</Item>
7011+
<Item ItemId=";Only_named_exports_may_use_export_type_1383" ItemType="0" PsrId="306" Leaf="true">
7012+
<Str Cat="Text">
7013+
<Val><![CDATA[Only named exports may use 'export type'.]]></Val>
7014+
</Str>
7015+
<Disp Icon="Str" />
7016+
</Item>
70117017
<Item ItemId=";Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword_2340" ItemType="0" PsrId="306" Leaf="true">
70127018
<Str Cat="Text">
70137019
<Val><![CDATA[Only public and protected methods of the base class are accessible via the 'super' keyword.]]></Val>
@@ -7035,11 +7041,20 @@
70357041
</Str>
70367042
<Disp Icon="Str" />
70377043
</Item>
7038-
<Item ItemId=";Option_0_can_only_be_specified_in_tsconfig_json_file_6064" ItemType="0" PsrId="306" Leaf="true">
7044+
<Item ItemId=";Option_0_can_only_be_specified_in_tsconfig_json_file_or_set_to_false_or_null_on_command_line_6230" ItemType="0" PsrId="306" Leaf="true">
7045+
<Str Cat="Text">
7046+
<Val><![CDATA[Option '{0}' can only be specified in 'tsconfig.json' file or set to 'false' or 'null' on command line.]]></Val>
7047+
<Tgt Cat="Text" Stat="Loc" Orig="New">
7048+
<Val><![CDATA[L'opzione '{0}' può essere specificata solo nel file 'tsconfig.json' oppure impostata su 'false' o 'null' sulla riga di comando.]]></Val>
7049+
</Tgt>
7050+
</Str>
7051+
<Disp Icon="Str" />
7052+
</Item>
7053+
<Item ItemId=";Option_0_can_only_be_specified_in_tsconfig_json_file_or_set_to_null_on_command_line_6064" ItemType="0" PsrId="306" Leaf="true">
70397054
<Str Cat="Text">
7040-
<Val><![CDATA[Option '{0}' can only be specified in 'tsconfig.json' file.]]></Val>
7055+
<Val><![CDATA[Option '{0}' can only be specified in 'tsconfig.json' file or set to 'null' on command line.]]></Val>
70417056
<Tgt Cat="Text" Stat="Loc" Orig="New">
7042-
<Val><![CDATA[L'opzione '{0}' può essere specificata solo nel file 'tsconfig.json'.]]></Val>
7057+
<Val><![CDATA[L'opzione '{0}' può essere specificata solo nel file 'tsconfig.json' oppure impostata su 'null' sulla riga di comando.]]></Val>
70437058
</Tgt>
70447059
</Str>
70457060
<Disp Icon="Str" />
@@ -9531,6 +9546,9 @@
95319546
<Item ItemId=";Tag_0_expects_at_least_1_arguments_but_the_JSX_factory_2_provides_at_most_3_6229" ItemType="0" PsrId="306" Leaf="true">
95329547
<Str Cat="Text">
95339548
<Val><![CDATA[Tag '{0}' expects at least '{1}' arguments, but the JSX factory '{2}' provides at most '{3}'.]]></Val>
9549+
<Tgt Cat="Text" Stat="Loc" Orig="New">
9550+
<Val><![CDATA[Con il tag '{0}' sono previsti almeno '{1}' argomenti, ma la factory JSX '{2}' ne fornisce al massimo '{3}'.]]></Val>
9551+
</Tgt>
95349552
</Str>
95359553
<Disp Icon="Str" />
95369554
</Item>
@@ -10857,6 +10875,12 @@
1085710875
</Str>
1085810876
<Disp Icon="Str" />
1085910877
</Item>
10878+
<Item ItemId=";Type_of_property_0_circularly_references_itself_in_mapped_type_1_2615" ItemType="0" PsrId="306" Leaf="true">
10879+
<Str Cat="Text">
10880+
<Val><![CDATA[Type of property '{0}' circularly references itself in mapped type '{1}'.]]></Val>
10881+
</Str>
10882+
<Disp Icon="Str" />
10883+
</Item>
1086010884
<Item ItemId=";Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_cal_1321" ItemType="0" PsrId="306" Leaf="true">
1086110885
<Str Cat="Text">
1086210886
<Val><![CDATA[Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.]]></Val>

src/services/textChanges.ts

-1
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,6 @@ namespace ts.textChanges {
966966
function createWriter(newLine: string): TextChangesWriter {
967967
let lastNonTriviaPosition = 0;
968968

969-
970969
const writer = createTextWriter(newLine);
971970
const onEmitNode: PrintHandlers["onEmitNode"] = (hint, node, printCallback) => {
972971
if (node) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/app.js ===
2+
const f = function() {};
3+
>f : Symbol(f, Decl(app.js, 0, 5))
4+
5+
var g = f;
6+
>g : Symbol(g, Decl(app.js, 1, 3))
7+
>f : Symbol(f, Decl(app.js, 0, 5))
8+
9+
g.prototype.m = function () {
10+
>g.prototype : Symbol(g.m, Decl(app.js, 1, 10))
11+
>g : Symbol(g, Decl(app.js, 1, 3))
12+
>prototype : Symbol(Function.prototype, Decl(lib.es5.d.ts, --, --))
13+
>m : Symbol(g.m, Decl(app.js, 1, 10))
14+
15+
this;
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/compiler/app.js ===
2+
const f = function() {};
3+
>f : () => void
4+
>function() {} : () => void
5+
6+
var g = f;
7+
>g : () => void
8+
>f : () => void
9+
10+
g.prototype.m = function () {
11+
>g.prototype.m = function () { this;} : () => void
12+
>g.prototype.m : any
13+
>g.prototype : any
14+
>g : () => void
15+
>prototype : any
16+
>m : any
17+
>function () { this;} : () => void
18+
19+
this;
20+
>this : any
21+
22+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [bar.js]
2+
export class Z {
3+
f(x = 1, y) {
4+
return [x, y];
5+
}
6+
}
7+
8+
//// [bar.js]
9+
"use strict";
10+
Object.defineProperty(exports, "__esModule", { value: true });
11+
exports.Z = void 0;
12+
var Z = /** @class */ (function () {
13+
function Z() {
14+
}
15+
Z.prototype.f = function (x, y) {
16+
if (x === void 0) { x = 1; }
17+
return [x, y];
18+
};
19+
return Z;
20+
}());
21+
exports.Z = Z;
22+
23+
24+
//// [bar.d.ts]
25+
export class Z {
26+
f(x: number, y: any): any[];
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/conformance/jsdoc/declarations/bar.js ===
2+
export class Z {
3+
>Z : Symbol(Z, Decl(bar.js, 0, 0))
4+
5+
f(x = 1, y) {
6+
>f : Symbol(Z.f, Decl(bar.js, 0, 16))
7+
>x : Symbol(x, Decl(bar.js, 1, 6))
8+
>y : Symbol(y, Decl(bar.js, 1, 12))
9+
10+
return [x, y];
11+
>x : Symbol(x, Decl(bar.js, 1, 6))
12+
>y : Symbol(y, Decl(bar.js, 1, 12))
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/conformance/jsdoc/declarations/bar.js ===
2+
export class Z {
3+
>Z : Z
4+
5+
f(x = 1, y) {
6+
>f : (x: number, y: any) => any[]
7+
>x : number
8+
>1 : 1
9+
>y : any
10+
11+
return [x, y];
12+
>[x, y] : any[]
13+
>x : number
14+
>y : any
15+
}
16+
}

0 commit comments

Comments
 (0)