Skip to content

Commit 2eea098

Browse files
committed
Merge branch 'master' into delay-signature-return-type-instantiation
2 parents c0b8c21 + 158a637 commit 2eea098

File tree

61 files changed

+1468
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1468
-395
lines changed

.mailmap

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,23 @@ rdosanjh <[email protected]> # Raj Dosanjh
248248
gdh1995 <[email protected]> # Dahan Gong
249249
cedvdb <[email protected]> # @cedvdb
250250
kpreisser <[email protected]> # K. Preißer
251-
e-cloud <[email protected]> # @e-cloud
251+
e-cloud <[email protected]> # @e-cloud
252+
Andrew Casey <[email protected]> Andrew Casey <[email protected]>
253+
Andrew Stegmaier <[email protected]>
254+
Benny Neugebauer <[email protected]>
255+
Blaine Bublitz <[email protected]>
256+
Charles Pierce <[email protected]>
257+
Daniel Król <[email protected]>
258+
Diogo Franco (Kovensky) <[email protected]>
259+
Donald Pipowitch <[email protected]>
260+
Halasi Tamás <[email protected]>
261+
262+
Joe Chung <[email protected]>
263+
Kate Miháliková <[email protected]>
264+
Mohsen Azimi <[email protected]>
265+
Noel Varanda <[email protected]>
266+
Reiner Dolp <[email protected]>
267+
268+
TravCav <[email protected]> # @TravCav
269+
Vladimir Kurchatkin <[email protected]>
270+
William Orr <[email protected]>

AUTHORS.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ TypeScript is authored by:
1515
* Anders Hejlsberg
1616
* Andreas Martin
1717
* Andrej Baran
18+
* Andrew Casey
1819
* Andrew Ochsner
20+
* Andrew Stegmaier
1921
* Andrew Z Allen
2022
* András Parditka
2123
* Andy Hanson
@@ -31,14 +33,17 @@ TypeScript is authored by:
3133
* Ben Duffield
3234
* Ben Mosher
3335
* Benjamin Bock
36+
* Benny Neugebauer
3437
* Bill Ticehurst
38+
* Blaine Bublitz
3539
* Blake Embrey
3640
* @bootstraponline
3741
* Bowden Kelly
3842
* Brett Mayen
3943
* Bryan Forbes
4044
* Caitlin Potter
4145
* @cedvdb
46+
* Charles Pierce
4247
* Charly POLY
4348
* Chris Bubernak
4449
* Christophe Vidal
@@ -52,6 +57,7 @@ TypeScript is authored by:
5257
* Dan Corder
5358
* Dan Quirk
5459
* Daniel Hollocher
60+
* Daniel Król
5561
* Daniel Lehenbauer
5662
* Daniel Rosenwasser
5763
* David Kmenta
@@ -60,9 +66,11 @@ TypeScript is authored by:
6066
* David Souther
6167
* Denis Nedelyaev
6268
* Dick van den Brink
69+
* Diogo Franco (Kovensky)
6370
* Dirk Bäumer
6471
* Dirk Holtwick
6572
* Dom Chen
73+
* Donald Pipowitch
6674
* Doug Ilijev
6775
* @e-cloud
6876
* Elisée Maurer
@@ -89,12 +97,14 @@ TypeScript is authored by:
8997
* Guilherme Oenning
9098
* Guillaume Salles
9199
* Guy Bedford
100+
* Halasi Tamás
92101
* Harald Niesche
93102
* Hendrik Liebau
94103
* Herrington Darkholme
95104
* Homa Wong
96105
* Iain Monro
97106
* Igor Novozhilov
107+
* Ika
98108
* Ingvar Stepanyan
99109
* Isiah Meadows
100110
* Ivo Gabe de Wolff
@@ -111,6 +121,7 @@ TypeScript is authored by:
111121
* Jeffrey Morlan
112122
* Jesse Schalken
113123
* Jiri Tobisek
124+
* Joe Chung
114125
* Joel Day
115126
* Joey Wilson
116127
* Johannes Rieken
@@ -131,6 +142,7 @@ TypeScript is authored by:
131142
* K. Preißer
132143
* Kagami Sascha Rosylight
133144
* Kanchalai Tanglertsampan
145+
* Kate Miháliková
134146
* Keith Mashinter
135147
* Ken Howard
136148
* Kenji Imamula
@@ -159,13 +171,15 @@ TypeScript is authored by:
159171
* Mike Busyrev
160172
* Mine Starks
161173
* Mohamed Hegazy
174+
* Mohsen Azimi
162175
* Myles Megyesi
163176
* Natalie Coley
164177
* Nathan Shively-Sanders
165178
* Nathan Yee
166179
* Nicolas Henry
167180
* Nima Zahedi
168181
* Noah Chen
182+
* Noel Varanda
169183
* Noj Vek
170184
* Oleg Mihailik
171185
* Oleksandr Chekhovskyi
@@ -186,6 +200,7 @@ TypeScript is authored by:
186200
* Punya Biswal
187201
* Rado Kirov
188202
* Raj Dosanjh
203+
* Reiner Dolp
189204
* Richard Karmazín
190205
* Richard Knoll
191206
* Richard Sentino
@@ -213,6 +228,7 @@ TypeScript is authored by:
213228
* Sudheesh Singanamalla
214229
* Sébastien Arod
215230
* @T18970237136
231+
* @t_
216232
* Tarik Ozket
217233
* Tetsuharu Ohzeki
218234
* Thomas Loubiou
@@ -225,13 +241,16 @@ TypeScript is authored by:
225241
* togru
226242
* Tomas Grubliauskas
227243
* Torben Fitschen
244+
* @TravCav
228245
* TruongSinh Tran-Nguyen
229246
* Vadi Taslim
230247
* Vidar Tonaas Fauske
231248
* Viktor Zozulyak
232249
* Vilic Vane
250+
* Vladimir Kurchatkin
233251
* Vladimir Matveev
234252
* Wesley Wigham
253+
* William Orr
235254
* York Yao
236255
* @yortus
237256
* Yuichi Nukiyama

src/compiler/checker.ts

Lines changed: 74 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)