@@ -2832,6 +2832,17 @@ namespace ts {
2832
2832
2833
2833
function symbolToParameterDeclaration(parameterSymbol: Symbol, context: NodeBuilderContext): ParameterDeclaration {
2834
2834
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
+ }
2835
2846
const modifiers = parameterDeclaration.modifiers && parameterDeclaration.modifiers.map(getSynthesizedClone);
2836
2847
const dotDotDotToken = isRestParameter(parameterDeclaration) ? createToken(SyntaxKind.DotDotDotToken) : undefined;
2837
2848
const name = parameterDeclaration.name ?
@@ -6391,8 +6402,17 @@ namespace ts {
6391
6402
const typePredicate = declaration.type && declaration.type.kind === SyntaxKind.TypePredicate ?
6392
6403
createTypePredicateFromTypePredicateNode(declaration.type as TypePredicateNode) :
6393
6404
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
+ }
6394
6414
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);
6396
6416
}
6397
6417
return links.resolvedSignature;
6398
6418
}
@@ -6427,14 +6447,14 @@ namespace ts {
6427
6447
}
6428
6448
}
6429
6449
6430
- function containsArgumentsReference(declaration: FunctionLikeDeclaration ): boolean {
6450
+ function containsArgumentsReference(declaration: SignatureDeclaration ): boolean {
6431
6451
const links = getNodeLinks(declaration);
6432
6452
if (links.containsArgumentsReference === undefined) {
6433
6453
if (links.flags & NodeCheckFlags.CaptureArguments) {
6434
6454
links.containsArgumentsReference = true;
6435
6455
}
6436
6456
else {
6437
- links.containsArgumentsReference = traverse(declaration.body);
6457
+ links.containsArgumentsReference = traverse(( declaration as FunctionLikeDeclaration) .body);
6438
6458
}
6439
6459
}
6440
6460
return links.containsArgumentsReference;
@@ -6821,21 +6841,46 @@ namespace ts {
6821
6841
return undefined;
6822
6842
}
6823
6843
6824
- function resolveTypeReferenceName(typeReferenceName: EntityNameExpression | EntityName) {
6844
+ function resolveTypeReferenceName(typeReferenceName: EntityNameExpression | EntityName, meaning: SymbolFlags ) {
6825
6845
if (!typeReferenceName) {
6826
6846
return unknownSymbol;
6827
6847
}
6828
6848
6829
- return resolveEntityName(typeReferenceName, SymbolFlags.Type ) || unknownSymbol;
6849
+ return resolveEntityName(typeReferenceName, meaning ) || unknownSymbol;
6830
6850
}
6831
6851
6832
6852
function getTypeReferenceType(node: TypeReferenceType, symbol: Symbol) {
6833
6853
const typeArguments = typeArgumentsFromTypeReferenceNode(node); // Do unconditionally so we mark type arguments as referenced.
6834
-
6835
6854
if (symbol === unknownSymbol) {
6836
6855
return unknownType;
6837
6856
}
6838
6857
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 {
6839
6884
if (symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
6840
6885
return getTypeFromClassOrInterfaceReference(node, symbol, typeArguments);
6841
6886
}
@@ -6844,14 +6889,9 @@ namespace ts {
6844
6889
return getTypeFromTypeAliasReference(node, symbol, typeArguments);
6845
6890
}
6846
6891
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);
6852
6894
}
6853
-
6854
- return getTypeFromNonGenericTypeReference(node, symbol);
6855
6895
}
6856
6896
6857
6897
function getPrimitiveTypeFromJSDocTypeReference(node: JSDocTypeReference): Type {
@@ -6894,22 +6934,13 @@ namespace ts {
6894
6934
if (!links.resolvedType) {
6895
6935
let symbol: Symbol;
6896
6936
let type: Type;
6937
+ let meaning = SymbolFlags.Type;
6897
6938
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;
6904
6941
}
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);
6913
6944
type = getTypeReferenceType(node, symbol);
6914
6945
}
6915
6946
// 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 {
15501
15532
}
15502
15533
}
15503
15534
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
-
15519
15535
const candidates = candidatesOutArray || [];
15520
15536
// reorderCandidates fills up the candidates array directly
15521
15537
reorderCandidates(signatures, candidates);
@@ -16164,6 +16180,12 @@ namespace ts {
16164
16180
return links.inferredClassType;
16165
16181
}
16166
16182
16183
+ function isInferredClassType(type: Type) {
16184
+ return type.symbol
16185
+ && getObjectFlags(type) & ObjectFlags.Anonymous
16186
+ && getSymbolLinks(type.symbol).inferredClassType === type;
16187
+ }
16188
+
16167
16189
/**
16168
16190
* Syntactically and semantically checks a call or new expression.
16169
16191
* @param node The call/new expression to be checked.
@@ -16831,8 +16853,9 @@ namespace ts {
16831
16853
(expr as PropertyAccessExpression | ElementAccessExpression).expression.kind === SyntaxKind.ThisKeyword) {
16832
16854
// Look for if this is the constructor for the class that `symbol` is a property of.
16833
16855
const func = getContainingFunction(expr);
16834
- if (!(func && func.kind === SyntaxKind.Constructor))
16856
+ if (!(func && func.kind === SyntaxKind.Constructor)) {
16835
16857
return true;
16858
+ }
16836
16859
// If func.parent is a class and symbol is a (readonly) property of that class, or
16837
16860
// if func is a constructor and symbol is a (readonly) parameter property declared in it,
16838
16861
// then symbol is writeable here.
@@ -19386,8 +19409,8 @@ namespace ts {
19386
19409
19387
19410
function checkFunctionDeclaration(node: FunctionDeclaration): void {
19388
19411
if (produceDiagnostics) {
19389
- checkFunctionOrMethodDeclaration(node) || checkGrammarForGenerator(node) ;
19390
-
19412
+ checkFunctionOrMethodDeclaration(node);
19413
+ checkGrammarForGenerator(node);
19391
19414
checkCollisionWithCapturedSuperVariable(node, node.name);
19392
19415
checkCollisionWithCapturedThisVariable(node, node.name);
19393
19416
checkCollisionWithCapturedNewTargetVariable(node, node.name);
@@ -21864,6 +21887,10 @@ namespace ts {
21864
21887
if (moduleSymbol && hasExportAssignmentSymbol(moduleSymbol)) {
21865
21888
error(node.moduleSpecifier, Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol));
21866
21889
}
21890
+
21891
+ if (modulekind !== ModuleKind.System && modulekind !== ModuleKind.ES2015) {
21892
+ checkExternalEmitHelpers(node, ExternalEmitHelpers.ExportStar);
21893
+ }
21867
21894
}
21868
21895
}
21869
21896
}
@@ -23538,7 +23565,8 @@ namespace ts {
23538
23565
case ExternalEmitHelpers.AsyncGenerator: return "__asyncGenerator";
23539
23566
case ExternalEmitHelpers.AsyncDelegator: return "__asyncDelegator";
23540
23567
case ExternalEmitHelpers.AsyncValues: return "__asyncValues";
23541
- default: Debug.fail("Unrecognized helper.");
23568
+ case ExternalEmitHelpers.ExportStar: return "__exportStar";
23569
+ default: Debug.fail("Unrecognized helper");
23542
23570
}
23543
23571
}
23544
23572
0 commit comments