Skip to content

Commit 5e57507

Browse files
committed
Merge branch 'master' into modify-extends
2 parents 570575a + 91f0194 commit 5e57507

File tree

224 files changed

+3181
-1552
lines changed

Some content is hidden

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

224 files changed

+3181
-1552
lines changed

.mailmap

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,45 @@ zhongsp <[email protected]> # Patrick Zhong
172172
T18970237136 <[email protected]> # @T18970237136
173173
174174
bootstraponline <[email protected]> # @bootstraponline
175-
yortus <[email protected]> # @yortus
175+
yortus <[email protected]> # @yortus
176+
András Parditka <[email protected]>
177+
Anton Khlynovskiy <[email protected]>
178+
Charly POLY <[email protected]>
179+
Cotton Hou <[email protected]>
180+
Ethan Resnick <[email protected]>
181+
Marius Schulz <[email protected]>
182+
Mattias Buelens <[email protected]>
183+
Myles Megyesi <[email protected]>
184+
Tim Lancina <[email protected]>
185+
Aaron Holmes <[email protected]> Aaron Holmes <[email protected]>
186+
Akshar Patel <[email protected]>
187+
Ali Sabzevari <[email protected]>
188+
Aliaksandr Radzivanovich <[email protected]>
189+
BuildTools <[email protected]> # Franklin Tse
190+
ChogyDan <[email protected]> # Daniel Hollocher
191+
Daniel Rosenwasser <[email protected]> Daniel Rosenwasser <[email protected]>
192+
David Kmenta <[email protected]>
193+
E020873 <[email protected]> # Nicolas Henry
194+
Elisée Maurer <[email protected]>
195+
Emilio García-Pumarino <[email protected]> dashaus <[email protected]>
196+
Guilherme Oenning <[email protected]>
197+
Herrington Darkholme <[email protected]>
198+
Ivo Gabe de Wolff <[email protected]>
199+
Joey Wilson <[email protected]>
200+
Jonathon Smith <[email protected]>
201+
Juan Luis Boya García <[email protected]>
202+
Kagami Sascha Rosylight <[email protected]>
203+
Lucien Greathouse <[email protected]>
204+
Martin Vseticka <[email protected]>
205+
Mattias Buelens <[email protected]>
206+
Michael Bromley <[email protected]>
207+
Paul Jolly <[email protected]>
208+
Perry Jiang <[email protected]>
209+
Peter Burns <[email protected]>
210+
Robert Coie <[email protected]>
211+
Thomas Loubiou <[email protected]>
212+
Tim Perry <[email protected]>
213+
Vidar Tonaas Fauske <[email protected]>
214+
Viktor Zozulyak <[email protected]>
215+
rix <[email protected]> # Richard Sentino
216+
rohitverma007 <[email protected]> # Rohit Verma

AUTHORS.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
TypeScript is authored by:
2+
* Aaron Holmes
23
* Abubaker Bashir
34
* Adam Freidin
45
* Adi Dahiya
56
* Ahmad Farid
7+
* Akshar Patel
68
* Alex Eagle
79
* Alexander Kuvaev
810
* Alexander Rusakov
11+
* Ali Sabzevari
12+
* Aliaksandr Radzivanovich
913
* Anatoly Ressin
1014
* Anders Hejlsberg
1115
* Andrej Baran
1216
* Andrew Z Allen
17+
* András Parditka
1318
* Andy Hanson
1419
* Anil Anar
20+
* Anton Khlynovskiy
1521
* Anton Tolmachev
1622
* Arnav Singh
1723
* Arthur Ozga
@@ -27,16 +33,20 @@ TypeScript is authored by:
2733
* Brett Mayen
2834
* Bryan Forbes
2935
* Caitlin Potter
36+
* Charly POLY
3037
* Chris Bubernak
3138
* Christophe Vidal
3239
* Chuck Jazdzewski
3340
* Colby Russell
3441
* Colin Snover
42+
* Cotton Hou
3543
* Cyrus Najmabadi
3644
* Dafrok Zhang
3745
* Dan Corder
3846
* Dan Quirk
47+
* Daniel Hollocher
3948
* Daniel Rosenwasser
49+
* David Kmenta
4050
* David Li
4151
* David Souther
4252
* Denis Nedelyaev
@@ -45,21 +55,26 @@ TypeScript is authored by:
4555
* Dirk Holtwick
4656
* Dom Chen
4757
* Doug Ilijev
58+
* Elisée Maurer
59+
* Emilio García-Pumarino
4860
* Eric Tsang
4961
* Erik Edrosa
62+
* Ethan Resnick
5063
* Ethan Rubio
5164
* Evan Martin
5265
* Evan Sebastian
5366
* Eyas Sharaiha
5467
* Fabian Cook
5568
* @falsandtru
5669
* Frank Wallis
70+
* Franklin Tse
5771
* František Žiacik
5872
* Gabe Moothart
5973
* Gabriel Isenberg
6074
* Gilad Peleg
6175
* Godfrey Chan
6276
* Graeme Wicksted
77+
* Guilherme Oenning
6378
* Guillaume Salles
6479
* Guy Bedford
6580
* Harald Niesche
@@ -78,12 +93,14 @@ TypeScript is authored by:
7893
* Jeffrey Morlan
7994
* Jesse Schalken
8095
* Jiri Tobisek
96+
* Joey Wilson
8197
* Johannes Rieken
8298
* John Vilk
8399
* Jonathan Bond-Caron
84100
* Jonathan Park
85101
* Jonathan Toland
86102
* Jonathan Turner
103+
* Jonathon Smith
87104
* Josh Abernathy
88105
* Josh Kalderimis
89106
* Josh Soref
@@ -102,15 +119,21 @@ TypeScript is authored by:
102119
* Lucien Greathouse
103120
* Lukas Elmer
104121
* Marin Marinov
122+
* Marius Schulz
105123
* Martin Vseticka
106124
* Masahiro Wakame
107125
* Matt McCutchen
126+
* Mattias Buelens
127+
* Mattias Buelens
108128
* Max Deepfield
109129
* Micah Zoltu
110130
* Michael
131+
* Michael Bromley
111132
* Mohamed Hegazy
133+
* Myles Megyesi
112134
* Nathan Shively-Sanders
113135
* Nathan Yee
136+
* Nicolas Henry
114137
* Nima Zahedi
115138
* Noah Chen
116139
* Noj Vek
@@ -119,9 +142,12 @@ TypeScript is authored by:
119142
* Omer Sheikh
120143
* Oskar Segersva¨rd
121144
* Patrick Zhong
145+
* Paul Jolly
122146
* Paul van Brenk
123147
* @pcbro
124148
* Pedro Maltez
149+
* Perry Jiang
150+
* Peter Burns
125151
* Philip Bulley
126152
* Piero Cangianiello
127153
* @piloopin
@@ -130,6 +156,9 @@ TypeScript is authored by:
130156
* Punya Biswal
131157
* Rado Kirov
132158
* Richard Knoll
159+
* Richard Sentino
160+
* Robert Coie
161+
* Rohit Verma
133162
* Ron Buckton
134163
* Rostislav Galimsky
135164
* Rowan Wyborn
@@ -152,7 +181,9 @@ TypeScript is authored by:
152181
* @T18970237136
153182
* Tarik Ozket
154183
* Tetsuharu Ohzeki
184+
* Thomas Loubiou
155185
* Tien Hoanhtien
186+
* Tim Lancina
156187
* Tim Perry
157188
* Tim Viiding-Spader
158189
* Tingan Ho
@@ -161,6 +192,8 @@ TypeScript is authored by:
161192
* Tomas Grubliauskas
162193
* Torben Fitschen
163194
* TruongSinh Tran-Nguyen
195+
* Vidar Tonaas Fauske
196+
* Viktor Zozulyak
164197
* Vilic Vane
165198
* Vladimir Matveev
166199
* Wesley Wigham

src/compiler/checker.ts

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,7 +2673,7 @@ namespace ts {
26732673
}
26742674
Debug.assert(bindingElement.kind === SyntaxKind.BindingElement);
26752675
if (bindingElement.propertyName) {
2676-
writer.writeSymbol(getTextOfNode(bindingElement.propertyName), bindingElement.symbol);
2676+
writer.writeProperty(getTextOfNode(bindingElement.propertyName));
26772677
writePunctuation(writer, SyntaxKind.ColonToken);
26782678
writeSpace(writer);
26792679
}
@@ -4523,7 +4523,7 @@ namespace ts {
45234523
// First, if the constraint type is a type parameter, obtain the base constraint. Then,
45244524
// if the key type is a 'keyof X', obtain 'keyof C' where C is the base constraint of X.
45254525
// Finally, iterate over the constituents of the resulting iteration type.
4526-
const keyType = constraintType.flags & TypeFlags.TypeParameter ? getApparentType(constraintType) : constraintType;
4526+
const keyType = constraintType.flags & TypeFlags.TypeVariable ? getApparentType(constraintType) : constraintType;
45274527
const iterationType = keyType.flags & TypeFlags.Index ? getIndexType(getApparentType((<IndexType>keyType).type)) : keyType;
45284528
forEachType(iterationType, t => {
45294529
// Create a mapper from T to the current iteration type constituent. Then, if the
@@ -4579,7 +4579,7 @@ namespace ts {
45794579
function isGenericMappedType(type: Type) {
45804580
if (getObjectFlags(type) & ObjectFlags.Mapped) {
45814581
const constraintType = getConstraintTypeFromMappedType(<MappedType>type);
4582-
return !!(constraintType.flags & (TypeFlags.TypeParameter | TypeFlags.Index));
4582+
return maybeTypeOfKind(constraintType, TypeFlags.TypeVariable | TypeFlags.Index);
45834583
}
45844584
return false;
45854585
}
@@ -5912,7 +5912,7 @@ namespace ts {
59125912
return links.resolvedType;
59135913
}
59145914

5915-
function getIndexTypeForTypeVariable(type: TypeVariable) {
5915+
function getIndexTypeForGenericType(type: TypeVariable | UnionOrIntersectionType) {
59165916
if (!type.resolvedIndexType) {
59175917
type.resolvedIndexType = <IndexType>createType(TypeFlags.Index);
59185918
type.resolvedIndexType.type = type;
@@ -5931,7 +5931,7 @@ namespace ts {
59315931
}
59325932

59335933
function getIndexType(type: Type): Type {
5934-
return type.flags & TypeFlags.TypeVariable ? getIndexTypeForTypeVariable(<TypeVariable>type) :
5934+
return maybeTypeOfKind(type, TypeFlags.TypeVariable) ? getIndexTypeForGenericType(<TypeVariable | UnionOrIntersectionType>type) :
59355935
getObjectFlags(type) & ObjectFlags.Mapped ? getConstraintTypeFromMappedType(<MappedType>type) :
59365936
type.flags & TypeFlags.Any || getIndexInfoOfType(type, IndexKind.String) ? stringType :
59375937
getLiteralTypeFromPropertyNames(type);
@@ -6032,14 +6032,14 @@ namespace ts {
60326032
}
60336033

60346034
function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode) {
6035-
if (indexType.flags & TypeFlags.TypeVariable ||
6036-
objectType.flags & TypeFlags.TypeVariable && indexType.flags & TypeFlags.Index ||
6037-
isGenericMappedType(objectType)) {
6038-
// If the object type is a type variable (a type parameter or another indexed access type), if the
6039-
// index type is a type variable or an index type, or if the object type is a mapped type with a
6040-
// generic constraint, we are performing a higher-order index access where we cannot meaningfully
6041-
// access the properties of the object type. In those cases, we first check that the index type is
6042-
// assignable to 'keyof T' for the object type.
6035+
if (maybeTypeOfKind(indexType, TypeFlags.TypeVariable | TypeFlags.Index) || isGenericMappedType(objectType)) {
6036+
if (objectType.flags & TypeFlags.Any) {
6037+
return objectType;
6038+
}
6039+
// If the index type is generic or if the object type is a mapped type with a generic constraint,
6040+
// we are performing a higher-order index access where we cannot meaningfully access the properties
6041+
// of the object type. In those cases, we first check that the index type is assignable to 'keyof T'
6042+
// for the object type.
60436043
if (accessNode) {
60446044
if (!isTypeAssignableTo(indexType, getIndexType(objectType))) {
60456045
error(accessNode, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(indexType), typeToString(objectType));
@@ -6539,7 +6539,7 @@ namespace ts {
65396539
// union type A | undefined, we produce { [P in keyof A]: X } | undefined.
65406540
const constraintType = getConstraintTypeFromMappedType(type);
65416541
if (constraintType.flags & TypeFlags.Index) {
6542-
const typeVariable = <TypeParameter>(<IndexType>constraintType).type;
6542+
const typeVariable = (<IndexType>constraintType).type;
65436543
const mappedTypeVariable = instantiateType(typeVariable, mapper);
65446544
if (typeVariable !== mappedTypeVariable) {
65456545
return mapType(mappedTypeVariable, t => {
@@ -8706,12 +8706,15 @@ namespace ts {
87068706
if (constraintType.flags & TypeFlags.Index) {
87078707
// We're inferring from some source type S to a homomorphic mapped type { [P in keyof T]: X },
87088708
// where T is a type variable. Use inferTypeForHomomorphicMappedType to infer a suitable source
8709-
// type and then infer from that type to T.
8709+
// type and then make a secondary inference from that type to T. We make a secondary inference
8710+
// such that direct inferences to T get priority over inferences to Partial<T>, for example.
87108711
const index = indexOf(typeVariables, (<IndexType>constraintType).type);
87118712
if (index >= 0 && !typeInferences[index].isFixed) {
87128713
const inferredType = inferTypeForHomomorphicMappedType(source, <MappedType>target);
87138714
if (inferredType) {
8715+
inferiority++;
87148716
inferFromTypes(inferredType, typeVariables[index]);
8717+
inferiority--;
87158718
}
87168719
}
87178720
return;
@@ -10402,33 +10405,37 @@ namespace ts {
1040210405
return baseConstructorType === nullWideningType;
1040310406
}
1040410407

10408+
function checkThisBeforeSuper(node: Node, container: Node, diagnosticMessage: DiagnosticMessage) {
10409+
const containingClassDecl = <ClassDeclaration>container.parent;
10410+
const baseTypeNode = getClassExtendsHeritageClauseElement(containingClassDecl);
10411+
10412+
// If a containing class does not have extends clause or the class extends null
10413+
// skip checking whether super statement is called before "this" accessing.
10414+
if (baseTypeNode && !classDeclarationExtendsNull(containingClassDecl)) {
10415+
const superCall = getSuperCallInConstructor(<ConstructorDeclaration>container);
10416+
10417+
// We should give an error in the following cases:
10418+
// - No super-call
10419+
// - "this" is accessing before super-call.
10420+
// i.e super(this)
10421+
// this.x; super();
10422+
// We want to make sure that super-call is done before accessing "this" so that
10423+
// "this" is not accessed as a parameter of the super-call.
10424+
if (!superCall || superCall.end > node.pos) {
10425+
// In ES6, super inside constructor of class-declaration has to precede "this" accessing
10426+
error(node, diagnosticMessage);
10427+
}
10428+
}
10429+
}
10430+
1040510431
function checkThisExpression(node: Node): Type {
1040610432
// Stop at the first arrow function so that we can
1040710433
// tell whether 'this' needs to be captured.
1040810434
let container = getThisContainer(node, /* includeArrowFunctions */ true);
1040910435
let needToCaptureLexicalThis = false;
1041010436

1041110437
if (container.kind === SyntaxKind.Constructor) {
10412-
const containingClassDecl = <ClassDeclaration>container.parent;
10413-
const baseTypeNode = getClassExtendsHeritageClauseElement(containingClassDecl);
10414-
10415-
// If a containing class does not have extends clause or the class extends null
10416-
// skip checking whether super statement is called before "this" accessing.
10417-
if (baseTypeNode && !classDeclarationExtendsNull(containingClassDecl)) {
10418-
const superCall = getSuperCallInConstructor(<ConstructorDeclaration>container);
10419-
10420-
// We should give an error in the following cases:
10421-
// - No super-call
10422-
// - "this" is accessing before super-call.
10423-
// i.e super(this)
10424-
// this.x; super();
10425-
// We want to make sure that super-call is done before accessing "this" so that
10426-
// "this" is not accessed as a parameter of the super-call.
10427-
if (!superCall || superCall.end > node.pos) {
10428-
// In ES6, super inside constructor of class-declaration has to precede "this" accessing
10429-
error(node, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class);
10430-
}
10431-
}
10438+
checkThisBeforeSuper(node, container, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class);
1043210439
}
1043310440

1043410441
// Now skip arrow functions to get the "real" owner of 'this'.
@@ -10576,6 +10583,10 @@ namespace ts {
1057610583
return unknownType;
1057710584
}
1057810585

10586+
if (!isCallExpression && container.kind === SyntaxKind.Constructor) {
10587+
checkThisBeforeSuper(node, container, Diagnostics.super_must_be_called_before_accessing_a_property_of_super_in_the_constructor_of_a_derived_class);
10588+
}
10589+
1057910590
if ((getModifierFlags(container) & ModifierFlags.Static) || isCallExpression) {
1058010591
nodeCheckFlag = NodeCheckFlags.SuperStatic;
1058110592
}
@@ -16196,7 +16207,7 @@ namespace ts {
1619616207
return undefined;
1619716208
}
1619816209

16199-
const onfulfilledParameterType = getTypeWithFacts(getUnionType(map(thenSignatures, getTypeOfFirstParameterOfSignature)), TypeFacts.NEUndefined);
16210+
const onfulfilledParameterType = getTypeWithFacts(getUnionType(map(thenSignatures, getTypeOfFirstParameterOfSignature)), TypeFacts.NEUndefinedOrNull);
1620016211
if (isTypeAny(onfulfilledParameterType)) {
1620116212
return undefined;
1620216213
}

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -549,14 +549,7 @@ namespace ts {
549549

550550
/* @internal */
551551
export function parseCustomTypeOption(opt: CommandLineOptionOfCustomType, value: string, errors: Diagnostic[]) {
552-
const key = trimString((value || "")).toLowerCase();
553-
const map = opt.type;
554-
if (key in map) {
555-
return map[key];
556-
}
557-
else {
558-
errors.push(createCompilerDiagnosticForInvalidCustomType(opt));
559-
}
552+
return convertJsonOptionOfCustomType(opt, trimString(value || ""), errors);
560553
}
561554

562555
/* @internal */

src/compiler/declarationEmitter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ namespace ts {
194194
writer.writeSpace = writer.write;
195195
writer.writeStringLiteral = writer.writeLiteral;
196196
writer.writeParameter = writer.write;
197+
writer.writeProperty = writer.write;
197198
writer.writeSymbol = writer.write;
198199
setWriter(writer);
199200
}

0 commit comments

Comments
 (0)