Skip to content

Commit 9e985c9

Browse files
committed
Merge branch 'master' into fix15618
2 parents 80a7716 + b325790 commit 9e985c9

18 files changed

+854
-116
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: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6841,21 +6841,46 @@ namespace ts {
68416841
return undefined;
68426842
}
68436843

6844-
function resolveTypeReferenceName(typeReferenceName: EntityNameExpression | EntityName) {
6844+
function resolveTypeReferenceName(typeReferenceName: EntityNameExpression | EntityName, meaning: SymbolFlags) {
68456845
if (!typeReferenceName) {
68466846
return unknownSymbol;
68476847
}
68486848

6849-
return resolveEntityName(typeReferenceName, SymbolFlags.Type) || unknownSymbol;
6849+
return resolveEntityName(typeReferenceName, meaning) || unknownSymbol;
68506850
}
68516851

68526852
function getTypeReferenceType(node: TypeReferenceType, symbol: Symbol) {
68536853
const typeArguments = typeArgumentsFromTypeReferenceNode(node); // Do unconditionally so we mark type arguments as referenced.
6854-
68556854
if (symbol === unknownSymbol) {
68566855
return unknownType;
68576856
}
68586857

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 {
68596884
if (symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
68606885
return getTypeFromClassOrInterfaceReference(node, symbol, typeArguments);
68616886
}
@@ -6864,14 +6889,9 @@ namespace ts {
68646889
return getTypeFromTypeAliasReference(node, symbol, typeArguments);
68656890
}
68666891

6867-
if (symbol.flags & SymbolFlags.Value && node.kind === SyntaxKind.JSDocTypeReference) {
6868-
// A JSDocTypeReference may have resolved to a value (as opposed to a type). In
6869-
// that case, the type of this reference is just the type of the value we resolved
6870-
// to.
6871-
return getTypeOfSymbol(symbol);
6892+
if (symbol.flags & SymbolFlags.Function && node.kind === SyntaxKind.JSDocTypeReference && (symbol.members || getJSDocClassTag(symbol.valueDeclaration))) {
6893+
return getInferredClassType(symbol);
68726894
}
6873-
6874-
return getTypeFromNonGenericTypeReference(node, symbol);
68756895
}
68766896

68776897
function getPrimitiveTypeFromJSDocTypeReference(node: JSDocTypeReference): Type {
@@ -6914,22 +6934,13 @@ namespace ts {
69146934
if (!links.resolvedType) {
69156935
let symbol: Symbol;
69166936
let type: Type;
6937+
let meaning = SymbolFlags.Type;
69176938
if (node.kind === SyntaxKind.JSDocTypeReference) {
6918-
type = getPrimitiveTypeFromJSDocTypeReference(<JSDocTypeReference>node);
6919-
if (!type) {
6920-
const typeReferenceName = getTypeReferenceName(node);
6921-
symbol = resolveTypeReferenceName(typeReferenceName);
6922-
type = getTypeReferenceType(node, symbol);
6923-
}
6939+
type = getPrimitiveTypeFromJSDocTypeReference(node);
6940+
meaning |= SymbolFlags.Value;
69246941
}
6925-
else {
6926-
// We only support expressions that are simple qualified names. For other expressions this produces undefined.
6927-
const typeNameOrExpression: EntityNameOrEntityNameExpression = node.kind === SyntaxKind.TypeReference
6928-
? (<TypeReferenceNode>node).typeName
6929-
: isEntityNameExpression((<ExpressionWithTypeArguments>node).expression)
6930-
? <EntityNameExpression>(<ExpressionWithTypeArguments>node).expression
6931-
: undefined;
6932-
symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, SymbolFlags.Type) || unknownSymbol;
6942+
if (!type) {
6943+
symbol = resolveTypeReferenceName(getTypeReferenceName(node), meaning);
69336944
type = getTypeReferenceType(node, symbol);
69346945
}
69356946
// Cache both the resolved symbol and the resolved type. The resolved symbol is needed in when we check the
@@ -8058,7 +8069,7 @@ namespace ts {
80588069
const result = createSignature(signature.declaration, freshTypeParameters,
80598070
signature.thisParameter && instantiateSymbol(signature.thisParameter, mapper),
80608071
instantiateList(signature.parameters, mapper, instantiateSymbol),
8061-
instantiateType(signature.resolvedReturnType, mapper),
8072+
/*resolvedReturnType*/ undefined,
80628073
freshTypePredicate,
80638074
signature.minArgumentCount, signature.hasRestParameter, signature.hasLiteralTypes);
80648075
result.target = signature;
@@ -16176,6 +16187,12 @@ namespace ts {
1617616187
return links.inferredClassType;
1617716188
}
1617816189

16190+
function isInferredClassType(type: Type) {
16191+
return type.symbol
16192+
&& getObjectFlags(type) & ObjectFlags.Anonymous
16193+
&& getSymbolLinks(type.symbol).inferredClassType === type;
16194+
}
16195+
1617916196
/**
1618016197
* Syntactically and semantically checks a call or new expression.
1618116198
* @param node The call/new expression to be checked.
@@ -19398,8 +19415,8 @@ namespace ts {
1939819415

1939919416
function checkFunctionDeclaration(node: FunctionDeclaration): void {
1940019417
if (produceDiagnostics) {
19401-
checkFunctionOrMethodDeclaration(node) || checkGrammarForGenerator(node);
19402-
19418+
checkFunctionOrMethodDeclaration(node);
19419+
checkGrammarForGenerator(node);
1940319420
checkCollisionWithCapturedSuperVariable(node, node.name);
1940419421
checkCollisionWithCapturedThisVariable(node, node.name);
1940519422
checkCollisionWithCapturedNewTargetVariable(node, node.name);

src/compiler/emitter.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ namespace ts {
959959
function emitConstructorType(node: ConstructorTypeNode) {
960960
write("new ");
961961
emitTypeParameters(node, node.typeParameters);
962-
emitParametersForArrow(node, node.parameters);
962+
emitParameters(node, node.parameters);
963963
write(" => ");
964964
emit(node.type);
965965
}
@@ -2283,11 +2283,25 @@ namespace ts {
22832283
emitList(parentNode, parameters, ListFormat.Parameters);
22842284
}
22852285

2286-
function emitParametersForArrow(parentNode: Node, parameters: NodeArray<ParameterDeclaration>) {
2287-
if (parameters &&
2288-
parameters.length === 1 &&
2289-
parameters[0].type === undefined &&
2290-
parameters[0].pos === parentNode.pos) {
2286+
function canEmitSimpleArrowHead(parentNode: FunctionTypeNode | ArrowFunction, parameters: NodeArray<ParameterDeclaration>) {
2287+
const parameter = singleOrUndefined(parameters);
2288+
return parameter
2289+
&& parameter.pos === parentNode.pos // may not have parsed tokens between parent and parameter
2290+
&& !(isArrowFunction(parentNode) && parentNode.type) // arrow function may not have return type annotation
2291+
&& !some(parentNode.decorators) // parent may not have decorators
2292+
&& !some(parentNode.modifiers) // parent may not have modifiers
2293+
&& !some(parentNode.typeParameters) // parent may not have type parameters
2294+
&& !some(parameter.decorators) // parameter may not have decorators
2295+
&& !some(parameter.modifiers) // parameter may not have modifiers
2296+
&& !parameter.dotDotDotToken // parameter may not be rest
2297+
&& !parameter.questionToken // parameter may not be optional
2298+
&& !parameter.type // parameter may not have a type annotation
2299+
&& !parameter.initializer // parameter may not have an initializer
2300+
&& isIdentifier(parameter.name); // parameter name must be identifier
2301+
}
2302+
2303+
function emitParametersForArrow(parentNode: FunctionTypeNode | ArrowFunction, parameters: NodeArray<ParameterDeclaration>) {
2304+
if (canEmitSimpleArrowHead(parentNode, parameters)) {
22912305
emit(parameters[0]);
22922306
}
22932307
else {

src/compiler/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ namespace ts {
228228

229229
// Signature elements
230230

231-
export function createTypeParameterDeclaration(name: string | Identifier, constraint: TypeNode | undefined, defaultType: TypeNode | undefined) {
231+
export function createTypeParameterDeclaration(name: string | Identifier, constraint?: TypeNode, defaultType?: TypeNode) {
232232
const node = createSynthesizedNode(SyntaxKind.TypeParameter) as TypeParameterDeclaration;
233233
node.name = asName(name);
234234
node.constraint = constraint;

src/compiler/tsc.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,10 @@ namespace ts {
662662
}
663663
}
664664

665+
if (ts.Debug.isDebugging) {
666+
ts.Debug.enableDebugInfo();
667+
}
668+
665669
if (ts.sys.tryEnableSourceMapsForHost && /^development$/i.test(ts.sys.getEnvironmentVariable("NODE_ENV"))) {
666670
ts.sys.tryEnableSourceMapsForHost();
667671
}

0 commit comments

Comments
 (0)