@@ -2832,6 +2832,17 @@ namespace ts {
28322832
28332833 function symbolToParameterDeclaration(parameterSymbol: Symbol, context: NodeBuilderContext): ParameterDeclaration {
28342834 const parameterDeclaration = getDeclarationOfKind<ParameterDeclaration>(parameterSymbol, SyntaxKind.Parameter);
2835+ if (isTransientSymbol(parameterSymbol) && parameterSymbol.isRestParameter) {
2836+ // special-case synthetic rest parameters in JS files
2837+ return createParameter(
2838+ /*decorators*/ undefined,
2839+ /*modifiers*/ undefined,
2840+ parameterSymbol.isRestParameter ? createToken(SyntaxKind.DotDotDotToken) : undefined,
2841+ "args",
2842+ /*questionToken*/ undefined,
2843+ typeToTypeNodeHelper(anyArrayType, context),
2844+ /*initializer*/ undefined);
2845+ }
28352846 const modifiers = parameterDeclaration.modifiers && parameterDeclaration.modifiers.map(getSynthesizedClone);
28362847 const dotDotDotToken = isRestParameter(parameterDeclaration) ? createToken(SyntaxKind.DotDotDotToken) : undefined;
28372848 const name = parameterDeclaration.name ?
@@ -6391,8 +6402,17 @@ namespace ts {
63916402 const typePredicate = declaration.type && declaration.type.kind === SyntaxKind.TypePredicate ?
63926403 createTypePredicateFromTypePredicateNode(declaration.type as TypePredicateNode) :
63936404 undefined;
6405+ // JS functions get a free rest parameter if they reference `arguments`
6406+ let hasRestLikeParameter = hasRestParameter(declaration);
6407+ if (!hasRestLikeParameter && isInJavaScriptFile(declaration) && !hasJSDocParameterTags(declaration) && containsArgumentsReference(declaration)) {
6408+ hasRestLikeParameter = true;
6409+ const syntheticArgsSymbol = createSymbol(SymbolFlags.Variable, "args");
6410+ syntheticArgsSymbol.type = anyArrayType;
6411+ syntheticArgsSymbol.isRestParameter = true;
6412+ parameters.push(syntheticArgsSymbol);
6413+ }
63946414
6395- links.resolvedSignature = createSignature(declaration, typeParameters, thisParameter, parameters, returnType, typePredicate, minArgumentCount, hasRestParameter(declaration) , hasLiteralTypes);
6415+ links.resolvedSignature = createSignature(declaration, typeParameters, thisParameter, parameters, returnType, typePredicate, minArgumentCount, hasRestLikeParameter , hasLiteralTypes);
63966416 }
63976417 return links.resolvedSignature;
63986418 }
@@ -6427,14 +6447,14 @@ namespace ts {
64276447 }
64286448 }
64296449
6430- function containsArgumentsReference(declaration: FunctionLikeDeclaration ): boolean {
6450+ function containsArgumentsReference(declaration: SignatureDeclaration ): boolean {
64316451 const links = getNodeLinks(declaration);
64326452 if (links.containsArgumentsReference === undefined) {
64336453 if (links.flags & NodeCheckFlags.CaptureArguments) {
64346454 links.containsArgumentsReference = true;
64356455 }
64366456 else {
6437- links.containsArgumentsReference = traverse(declaration.body);
6457+ links.containsArgumentsReference = traverse(( declaration as FunctionLikeDeclaration) .body);
64386458 }
64396459 }
64406460 return links.containsArgumentsReference;
@@ -6821,21 +6841,46 @@ namespace ts {
68216841 return undefined;
68226842 }
68236843
6824- function resolveTypeReferenceName(typeReferenceName: EntityNameExpression | EntityName) {
6844+ function resolveTypeReferenceName(typeReferenceName: EntityNameExpression | EntityName, meaning: SymbolFlags ) {
68256845 if (!typeReferenceName) {
68266846 return unknownSymbol;
68276847 }
68286848
6829- return resolveEntityName(typeReferenceName, SymbolFlags.Type ) || unknownSymbol;
6849+ return resolveEntityName(typeReferenceName, meaning ) || unknownSymbol;
68306850 }
68316851
68326852 function getTypeReferenceType(node: TypeReferenceType, symbol: Symbol) {
68336853 const typeArguments = typeArgumentsFromTypeReferenceNode(node); // Do unconditionally so we mark type arguments as referenced.
6834-
68356854 if (symbol === unknownSymbol) {
68366855 return unknownType;
68376856 }
68386857
6858+ const type = getTypeReferenceTypeWorker(node, symbol, typeArguments);
6859+ if (type) {
6860+ return type;
6861+ }
6862+
6863+ if (symbol.flags & SymbolFlags.Value && node.kind === SyntaxKind.JSDocTypeReference) {
6864+ // A JSDocTypeReference may have resolved to a value (as opposed to a type). If
6865+ // the symbol is a constructor function, return the inferred class type; otherwise,
6866+ // the type of this reference is just the type of the value we resolved to.
6867+ const valueType = getTypeOfSymbol(symbol);
6868+ if (valueType.symbol && !isInferredClassType(valueType)) {
6869+ const referenceType = getTypeReferenceTypeWorker(node, valueType.symbol, typeArguments);
6870+ if (referenceType) {
6871+ return referenceType;
6872+ }
6873+ }
6874+
6875+ // Resolve the type reference as a Type for the purpose of reporting errors.
6876+ resolveTypeReferenceName(getTypeReferenceName(node), SymbolFlags.Type);
6877+ return valueType;
6878+ }
6879+
6880+ return getTypeFromNonGenericTypeReference(node, symbol);
6881+ }
6882+
6883+ function getTypeReferenceTypeWorker(node: TypeReferenceType, symbol: Symbol, typeArguments: Type[]): Type | undefined {
68396884 if (symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
68406885 return getTypeFromClassOrInterfaceReference(node, symbol, typeArguments);
68416886 }
@@ -6844,14 +6889,9 @@ namespace ts {
68446889 return getTypeFromTypeAliasReference(node, symbol, typeArguments);
68456890 }
68466891
6847- if (symbol.flags & SymbolFlags.Value && node.kind === SyntaxKind.JSDocTypeReference) {
6848- // A JSDocTypeReference may have resolved to a value (as opposed to a type). In
6849- // that case, the type of this reference is just the type of the value we resolved
6850- // to.
6851- return getTypeOfSymbol(symbol);
6892+ if (symbol.flags & SymbolFlags.Function && node.kind === SyntaxKind.JSDocTypeReference && (symbol.members || getJSDocClassTag(symbol.valueDeclaration))) {
6893+ return getInferredClassType(symbol);
68526894 }
6853-
6854- return getTypeFromNonGenericTypeReference(node, symbol);
68556895 }
68566896
68576897 function getPrimitiveTypeFromJSDocTypeReference(node: JSDocTypeReference): Type {
@@ -6894,22 +6934,13 @@ namespace ts {
68946934 if (!links.resolvedType) {
68956935 let symbol: Symbol;
68966936 let type: Type;
6937+ let meaning = SymbolFlags.Type;
68976938 if (node.kind === SyntaxKind.JSDocTypeReference) {
6898- type = getPrimitiveTypeFromJSDocTypeReference(<JSDocTypeReference>node);
6899- if (!type) {
6900- const typeReferenceName = getTypeReferenceName(node);
6901- symbol = resolveTypeReferenceName(typeReferenceName);
6902- type = getTypeReferenceType(node, symbol);
6903- }
6939+ type = getPrimitiveTypeFromJSDocTypeReference(node);
6940+ meaning |= SymbolFlags.Value;
69046941 }
6905- else {
6906- // We only support expressions that are simple qualified names. For other expressions this produces undefined.
6907- const typeNameOrExpression: EntityNameOrEntityNameExpression = node.kind === SyntaxKind.TypeReference
6908- ? (<TypeReferenceNode>node).typeName
6909- : isEntityNameExpression((<ExpressionWithTypeArguments>node).expression)
6910- ? <EntityNameExpression>(<ExpressionWithTypeArguments>node).expression
6911- : undefined;
6912- symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, SymbolFlags.Type) || unknownSymbol;
6942+ if (!type) {
6943+ symbol = resolveTypeReferenceName(getTypeReferenceName(node), meaning);
69136944 type = getTypeReferenceType(node, symbol);
69146945 }
69156946 // Cache both the resolved symbol and the resolved type. The resolved symbol is needed in when we check the
@@ -15501,21 +15532,6 @@ namespace ts {
1550115532 }
1550215533 }
1550315534
15504- if (signatures.length === 1) {
15505- const declaration = signatures[0].declaration;
15506- if (declaration && isInJavaScriptFile(declaration) && !hasJSDocParameterTags(declaration)) {
15507- if (containsArgumentsReference(<FunctionLikeDeclaration>declaration)) {
15508- const signatureWithRest = cloneSignature(signatures[0]);
15509- const syntheticArgsSymbol = createSymbol(SymbolFlags.Variable, "args");
15510- syntheticArgsSymbol.type = anyArrayType;
15511- syntheticArgsSymbol.isRestParameter = true;
15512- signatureWithRest.parameters = concatenate(signatureWithRest.parameters, [syntheticArgsSymbol]);
15513- signatureWithRest.hasRestParameter = true;
15514- signatures = [signatureWithRest];
15515- }
15516- }
15517- }
15518-
1551915535 const candidates = candidatesOutArray || [];
1552015536 // reorderCandidates fills up the candidates array directly
1552115537 reorderCandidates(signatures, candidates);
@@ -16164,6 +16180,12 @@ namespace ts {
1616416180 return links.inferredClassType;
1616516181 }
1616616182
16183+ function isInferredClassType(type: Type) {
16184+ return type.symbol
16185+ && getObjectFlags(type) & ObjectFlags.Anonymous
16186+ && getSymbolLinks(type.symbol).inferredClassType === type;
16187+ }
16188+
1616716189 /**
1616816190 * Syntactically and semantically checks a call or new expression.
1616916191 * @param node The call/new expression to be checked.
@@ -16831,8 +16853,9 @@ namespace ts {
1683116853 (expr as PropertyAccessExpression | ElementAccessExpression).expression.kind === SyntaxKind.ThisKeyword) {
1683216854 // Look for if this is the constructor for the class that `symbol` is a property of.
1683316855 const func = getContainingFunction(expr);
16834- if (!(func && func.kind === SyntaxKind.Constructor))
16856+ if (!(func && func.kind === SyntaxKind.Constructor)) {
1683516857 return true;
16858+ }
1683616859 // If func.parent is a class and symbol is a (readonly) property of that class, or
1683716860 // if func is a constructor and symbol is a (readonly) parameter property declared in it,
1683816861 // then symbol is writeable here.
@@ -19386,8 +19409,8 @@ namespace ts {
1938619409
1938719410 function checkFunctionDeclaration(node: FunctionDeclaration): void {
1938819411 if (produceDiagnostics) {
19389- checkFunctionOrMethodDeclaration(node) || checkGrammarForGenerator(node) ;
19390-
19412+ checkFunctionOrMethodDeclaration(node);
19413+ checkGrammarForGenerator(node);
1939119414 checkCollisionWithCapturedSuperVariable(node, node.name);
1939219415 checkCollisionWithCapturedThisVariable(node, node.name);
1939319416 checkCollisionWithCapturedNewTargetVariable(node, node.name);
@@ -21864,6 +21887,10 @@ namespace ts {
2186421887 if (moduleSymbol && hasExportAssignmentSymbol(moduleSymbol)) {
2186521888 error(node.moduleSpecifier, Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol));
2186621889 }
21890+
21891+ if (modulekind !== ModuleKind.System && modulekind !== ModuleKind.ES2015) {
21892+ checkExternalEmitHelpers(node, ExternalEmitHelpers.ExportStar);
21893+ }
2186721894 }
2186821895 }
2186921896 }
@@ -23538,7 +23565,8 @@ namespace ts {
2353823565 case ExternalEmitHelpers.AsyncGenerator: return "__asyncGenerator";
2353923566 case ExternalEmitHelpers.AsyncDelegator: return "__asyncDelegator";
2354023567 case ExternalEmitHelpers.AsyncValues: return "__asyncValues";
23541- default: Debug.fail("Unrecognized helper.");
23568+ case ExternalEmitHelpers.ExportStar: return "__exportStar";
23569+ default: Debug.fail("Unrecognized helper");
2354223570 }
2354323571 }
2354423572
0 commit comments