Skip to content

Commit bcd1ef8

Browse files
committed
Merge branch 'master' into typeof-string-literal-union-type
2 parents d23f692 + 94aeff2 commit bcd1ef8

File tree

64 files changed

+6283
-3311
lines changed

Some content is hidden

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

64 files changed

+6283
-3311
lines changed

.mailmap

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ Alexander Rusakov <[email protected]>
88
Alex Eagle <[email protected]>
99
Anatoly Ressin <[email protected]>
1010
Anders Hejlsberg <[email protected]> unknown <[email protected]> unknown <[email protected]>
11+
about-code <[email protected]> # Andreas Martin
1112
Andrej Baran <[email protected]>
13+
Andrew Ochsner <[email protected]>
1214
Andrew Z Allen <[email protected]>
1315
1416
Anil Anar <[email protected]>
1517
Anton Tolmachev <[email protected]>
18+
Anubha Mathur <[email protected]> anubmat <[email protected]>
1619
Arnavion <[email protected]> # Arnav Singh
1720
Arthur Ozga <[email protected]> Arthur Ozga <[email protected]> Arthur Ozga <[email protected]> Arthur Ozga <[email protected]> Arthur Ozga <[email protected]>
1821
Asad Saeeduddin <[email protected]>
@@ -37,6 +40,7 @@ Dan Corder <[email protected]>
3740
3841
Daniel Rosenwasser <[email protected]> Daniel Rosenwasser <[email protected]> Daniel Rosenwasser <[email protected]> Daniel Rosenwasser <[email protected]> Daniel Rosenwasser <[email protected]>
3942
43+
David Sheldrick <[email protected]>
4044
David Souther <[email protected]>
4145
Denis Nedelyaev <[email protected]>
4246
Dick van den Brink <[email protected]> unknown <[email protected]> unknown <[email protected]>
@@ -52,6 +56,7 @@ Evan Sebastian <[email protected]>
5256
Eyas <[email protected]> # Eyas Sharaiha
5357
Fabian Cook <[email protected]>
5458
falsandtru <[email protected]> # @falsandtru
59+
flowmemo <[email protected]> # @flowmemo
5560
Frank Wallis <[email protected]>
5661
František Žiacik <[email protected]> František Žiacik <[email protected]>
5762
Gabe Moothart <[email protected]>
@@ -62,6 +67,7 @@ Graeme Wicksted <[email protected]>
6267
Guillaume Salles <[email protected]>
6368
Guy Bedford <[email protected]> guybedford <[email protected]>
6469
Harald Niesche <[email protected]>
70+
Homa Wong <[email protected]>
6571
Iain Monro <[email protected]>
6672
Ingvar Stepanyan <[email protected]>
6773
impinball <[email protected]> # Isiah Meadows
@@ -81,6 +87,7 @@ Jonathan Park <[email protected]>
8187
Jonathan Turner <[email protected]> Jonathan Turner <[email protected]>
8288
Jonathan Toland <[email protected]>
8389
Jesse Schalken <[email protected]>
90+
8491
Josh Abernathy <[email protected]> joshaber <[email protected]>
8592
Josh Kalderimis <[email protected]>
8693
Josh Soref <[email protected]>
@@ -95,10 +102,12 @@ Kanchalai Tanglertsampan <[email protected]> Yui T <[email protected]>
95102
Kanchalai Tanglertsampan <[email protected]> Yui <[email protected]>
96103
Kanchalai Tanglertsampan <[email protected]> Yui <[email protected]>
97104
Kanchalai Tanglertsampan <[email protected]> yui T <[email protected]>
105+
Kārlis Gaņģis <[email protected]>
98106
Keith Mashinter <[email protected]> kmashint <[email protected]>
99107
Ken Howard <[email protected]>
100108
Kevin Lang <[email protected]>
101109
kimamula <[email protected]> # Kenji Imamula
110+
Klaus Meinhardt <[email protected]>
102111
Kyle Kelley <[email protected]>
103112
Lorant Pinter <[email protected]>
104113
Lucien Greathouse <[email protected]>
@@ -107,6 +116,7 @@ Martin Vseticka <[email protected]> Martin Všeticka <vseticka.martin@gm
107116
gcnew <[email protected]> # Marin Marinov
108117
vvakame <[email protected]> # Masahiro Wakame
109118
Matt McCutchen <[email protected]>
119+
MANISH-GIRI <[email protected]> # Manish Giri
110120
Max Deepfield <[email protected]>
111121
Micah Zoltu <[email protected]>
112122
@@ -213,4 +223,6 @@ Tim Perry <[email protected]>
213223
Vidar Tonaas Fauske <[email protected]>
214224
Viktor Zozulyak <[email protected]>
215225
rix <[email protected]> # Richard Sentino
216-
rohitverma007 <[email protected]> # Rohit Verma
226+
rohitverma007 <[email protected]> # Rohit Verma
227+
rdosanjh <[email protected]> # Raj Dosanjh
228+
gdh1995 <[email protected]> # Dahan Gong

AUTHORS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ TypeScript is authored by:
1212
* Aliaksandr Radzivanovich
1313
* Anatoly Ressin
1414
* Anders Hejlsberg
15+
* Andreas Martin
1516
* Andrej Baran
17+
* Andrew Ochsner
1618
* Andrew Z Allen
1719
* András Parditka
1820
* Andy Hanson
1921
* Anil Anar
2022
* Anton Khlynovskiy
2123
* Anton Tolmachev
24+
* Anubha Mathur
2225
* Arnav Singh
2326
* Arthur Ozga
2427
* Asad Saeeduddin
@@ -42,12 +45,14 @@ TypeScript is authored by:
4245
* Cotton Hou
4346
* Cyrus Najmabadi
4447
* Dafrok Zhang
48+
* Dahan Gong
4549
* Dan Corder
4650
* Dan Quirk
4751
* Daniel Hollocher
4852
* Daniel Rosenwasser
4953
* David Kmenta
5054
* David Li
55+
* David Sheldrick
5156
* David Souther
5257
* Denis Nedelyaev
5358
* Dick van den Brink
@@ -66,6 +71,7 @@ TypeScript is authored by:
6671
* Eyas Sharaiha
6772
* Fabian Cook
6873
* @falsandtru
74+
* @flowmemo
6975
* Frank Wallis
7076
* Franklin Tse
7177
* František Žiacik
@@ -79,6 +85,7 @@ TypeScript is authored by:
7985
* Guy Bedford
8086
* Harald Niesche
8187
* Herrington Darkholme
88+
* Homa Wong
8289
* Iain Monro
8390
* Ingvar Stepanyan
8491
* Isiah Meadows
@@ -93,6 +100,7 @@ TypeScript is authored by:
93100
* Jeffrey Morlan
94101
* Jesse Schalken
95102
* Jiri Tobisek
103+
* Joel Day
96104
* Joey Wilson
97105
* Johannes Rieken
98106
* John Vilk
@@ -114,10 +122,13 @@ TypeScript is authored by:
114122
* Ken Howard
115123
* Kenji Imamula
116124
* Kevin Lang
125+
* Klaus Meinhardt
117126
* Kyle Kelley
127+
* Kārlis Gaņģis
118128
* Lorant Pinter
119129
* Lucien Greathouse
120130
* Lukas Elmer
131+
* Manish Giri
121132
* Marin Marinov
122133
* Marius Schulz
123134
* Martin Vseticka
@@ -155,6 +166,7 @@ TypeScript is authored by:
155166
* @progre
156167
* Punya Biswal
157168
* Rado Kirov
169+
* Raj Dosanjh
158170
* Richard Knoll
159171
* Richard Sentino
160172
* Robert Coie

Jakefile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ var harnessSources = harnessCoreSources.concat([
269269
"projectErrors.ts",
270270
"matchFiles.ts",
271271
"initializeTSConfig.ts",
272+
"printer.ts",
272273
].map(function (f) {
273274
return path.join(unittestsDirectory, f);
274275
})).concat([

src/compiler/checker.ts

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ namespace ts {
640640
}
641641
// declaration is after usage
642642
// can be legal if usage is deferred (i.e. inside function or in initializer of instance property)
643-
if (isUsedInFunctionOrNonStaticProperty(usage)) {
643+
if (isUsedInFunctionOrInstanceProperty(usage)) {
644644
return true;
645645
}
646646
const sourceFiles = host.getSourceFiles();
@@ -667,10 +667,12 @@ namespace ts {
667667
}
668668

669669

670-
// declaration is after usage
671-
// can be legal if usage is deferred (i.e. inside function or in initializer of instance property)
670+
// declaration is after usage, but it can still be legal if usage is deferred:
671+
// 1. inside a function
672+
// 2. inside an instance property initializer, a reference to a non-instance property
672673
const container = getEnclosingBlockScopeContainer(declaration);
673-
return isUsedInFunctionOrNonStaticProperty(usage, container);
674+
const isInstanceProperty = declaration.kind === SyntaxKind.PropertyDeclaration && !(getModifierFlags(declaration) & ModifierFlags.Static);
675+
return isUsedInFunctionOrInstanceProperty(usage, isInstanceProperty, container);
674676

675677
function isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration: VariableDeclaration, usage: Node): boolean {
676678
const container = getEnclosingBlockScopeContainer(declaration);
@@ -699,7 +701,7 @@ namespace ts {
699701
return false;
700702
}
701703

702-
function isUsedInFunctionOrNonStaticProperty(usage: Node, container?: Node): boolean {
704+
function isUsedInFunctionOrInstanceProperty(usage: Node, isDeclarationInstanceProperty?: boolean, container?: Node): boolean {
703705
let current = usage;
704706
while (current) {
705707
if (current === container) {
@@ -710,13 +712,13 @@ namespace ts {
710712
return true;
711713
}
712714

713-
const initializerOfNonStaticProperty = current.parent &&
715+
const initializerOfInstanceProperty = current.parent &&
714716
current.parent.kind === SyntaxKind.PropertyDeclaration &&
715717
(getModifierFlags(current.parent) & ModifierFlags.Static) === 0 &&
716718
(<PropertyDeclaration>current.parent).initializer === current;
717719

718-
if (initializerOfNonStaticProperty) {
719-
return true;
720+
if (initializerOfInstanceProperty) {
721+
return !isDeclarationInstanceProperty;
720722
}
721723

722724
current = current.parent;
@@ -985,10 +987,10 @@ namespace ts {
985987
// interface bar {}
986988
// }
987989
// const foo/*1*/: foo/*2*/.bar;
988-
// The foo at /*1*/ and /*2*/ will share same symbol with two meaning
989-
// block - scope variable and namespace module. However, only when we
990+
// The foo at /*1*/ and /*2*/ will share same symbol with two meanings:
991+
// block-scoped variable and namespace module. However, only when we
990992
// try to resolve name in /*1*/ which is used in variable position,
991-
// we want to check for block- scoped
993+
// we want to check for block-scoped
992994
if (meaning & SymbolFlags.BlockScopedVariable) {
993995
const exportOrLocalSymbol = getExportSymbolOfValueSymbolIfExported(result);
994996
if (exportOrLocalSymbol.flags & SymbolFlags.BlockScopedVariable) {
@@ -1012,7 +1014,7 @@ namespace ts {
10121014
return false;
10131015
}
10141016

1015-
const container = getThisContainer(errorLocation, /* includeArrowFunctions */ true);
1017+
const container = getThisContainer(errorLocation, /*includeArrowFunctions*/ true);
10161018
let location = container;
10171019
while (location) {
10181020
if (isClassLike(location.parent)) {
@@ -3994,7 +3996,7 @@ namespace ts {
39943996
// A valid base type is any non-generic object type or intersection of non-generic
39953997
// object types.
39963998
function isValidBaseType(type: Type): boolean {
3997-
return type.flags & TypeFlags.Object && !isGenericMappedType(type) ||
3999+
return type.flags & (TypeFlags.Object | TypeFlags.NonPrimitive) && !isGenericMappedType(type) ||
39984000
type.flags & TypeFlags.Intersection && !forEach((<IntersectionType>type).types, t => !isValidBaseType(t));
39994001
}
40004002

@@ -4932,7 +4934,7 @@ namespace ts {
49324934
}
49334935

49344936
function getApparentTypeOfIntersectionType(type: IntersectionType) {
4935-
return type.resolvedIndexType || (type.resolvedApparentType = getTypeWithThisArgument(type, type));
4937+
return type.resolvedApparentType || (type.resolvedApparentType = getTypeWithThisArgument(type, type));
49364938
}
49374939

49384940
/**
@@ -4947,7 +4949,7 @@ namespace ts {
49474949
t.flags & TypeFlags.NumberLike ? globalNumberType :
49484950
t.flags & TypeFlags.BooleanLike ? globalBooleanType :
49494951
t.flags & TypeFlags.ESSymbol ? getGlobalESSymbolType() :
4950-
t.flags & TypeFlags.NonPrimitive ? globalObjectType :
4952+
t.flags & TypeFlags.NonPrimitive ? emptyObjectType :
49514953
t;
49524954
}
49534955

@@ -12546,6 +12548,16 @@ namespace ts {
1254612548
}
1254712549
}
1254812550

12551+
function isInPropertyInitializer(node: Node): boolean {
12552+
while (node) {
12553+
if (node.parent && node.parent.kind === SyntaxKind.PropertyDeclaration && (node.parent as PropertyDeclaration).initializer === node) {
12554+
return true;
12555+
}
12556+
node = node.parent;
12557+
}
12558+
return false;
12559+
}
12560+
1254912561
function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) {
1255012562
const type = checkNonNullExpression(left);
1255112563
if (isTypeAny(type) || type === silentNeverType) {
@@ -12568,6 +12580,11 @@ namespace ts {
1256812580
}
1256912581
return unknownType;
1257012582
}
12583+
if (prop.valueDeclaration &&
12584+
isInPropertyInitializer(node) &&
12585+
!isBlockScopedNameDeclaredBeforeUse(prop.valueDeclaration, right)) {
12586+
error(right, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, right.text);
12587+
}
1257112588

1257212589
markPropertyAsReferenced(prop);
1257312590

0 commit comments

Comments
 (0)