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 <a_s_rusakov@mail.ru>
88
Alex Eagle <alexeagle@google.com>
99
Anatoly Ressin <anatoly.ressin@icloud.com>
1010
Anders Hejlsberg <andersh@microsoft.com> unknown <andersh@AndersX1.NOE.Nokia.com> unknown <andersh@andersh-yoga.redmond.corp.microsoft.com>
11+
about-code <about-code@users.noreply.github.com> # Andreas Martin
1112
Andrej Baran <andrej.baran@gmail.com>
13+
Andrew Ochsner <andrew.ochsner@wipro.com>
1214
Andrew Z Allen <me@andrewzallen.com>
1315
Andy Hanson <anhans@microsoft.com> Andy <anhans@microsoft.com>
1416
Anil Anar <anilanar@hotmail.com>
1517
Anton Tolmachev <myste@mail.ru>
18+
Anubha Mathur <anubmat@microsoft.com> anubmat <anubmat@microsoft.com>
1619
Arnavion <arnavion@gmail.com> # Arnav Singh
1720
Arthur Ozga <aozgaa@umich.edu> Arthur Ozga <t-arthoz@microsoft.com> Arthur Ozga <aozgaa-ms@outlook.com> Arthur Ozga <aozgaa@users.noreply.github.com> Arthur Ozga <arozga@microsoft.com>
1821
Asad Saeeduddin <masaeedu@gmail.com>
@@ -37,6 +40,7 @@ Dan Corder <dev@dancorder.com>
3740
Dan Quirk <danquirk@microsoft.com> Dan Quirk <danquirk@users.noreply.github.com> nknown <danquirk@DANQUIRK1.redmond.corp.microsoft.com>
3841
Daniel Rosenwasser <drosen@microsoft.com> Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> Daniel Rosenwasser <DanielRosenwasser@gmail.com> Daniel Rosenwasser <Daniel.Rosenwasser@microsoft.com> Daniel Rosenwasser <DanielRosenwasser@microsoft.com>
3942
David Li <jiawei.davidli@gmail.com>
43+
David Sheldrick <david@futurice.com>
4044
David Souther <davidsouther@gmail.com>
4145
Denis Nedelyaev <denvned@gmail.com>
4246
Dick van den Brink <d_vandenbrink@outlook.com> unknown <d_vandenbrink@outlook.com> unknown <d_vandenbrink@live.com>
@@ -52,6 +56,7 @@ Evan Sebastian <evanlhoini@gmail.com>
5256
Eyas <eyas.sharaiha@gmail.com> # Eyas Sharaiha
5357
Fabian Cook <faybecook@gmail.com>
5458
falsandtru <falsandtru@users.noreply.github.com> # @falsandtru
59+
flowmemo <flowmemo@outlook.com> # @flowmemo
5560
Frank Wallis <fwallis@outlook.com>
5661
František Žiacik <fziacik@gratex.com> František Žiacik <ziacik@gmail.com>
5762
Gabe Moothart <gmoothart@gmail.com>
@@ -62,6 +67,7 @@ Graeme Wicksted <graeme.wicksted@gmail.com>
6267
Guillaume Salles <guillaume.salles@me.com>
6368
Guy Bedford <guybedford@gmail.com> guybedford <guybedford@gmail.com>
6469
Harald Niesche <harald@niesche.de>
70+
Homa Wong <homawong@gmail.com>
6571
Iain Monro <iain.monro@softwire.com>
6672
Ingvar Stepanyan <me@rreverser.com>
6773
impinball <impinball@gmail.com> # Isiah Meadows
@@ -81,6 +87,7 @@ Jonathan Park <jpark@daptiv.com>
8187
Jonathan Turner <jont@microsoft.com> Jonathan Turner <probata@hotmail.com>
8288
Jonathan Toland <toland@dnalot.com>
8389
Jesse Schalken <me@jesseschalken.com>
90+
Joel Day <joelday@gmail.com>
8491
Josh Abernathy <joshaber@gmail.com> joshaber <joshaber@gmail.com>
8592
Josh Kalderimis <josh.kalderimis@gmail.com>
8693
Josh Soref <jsoref@users.noreply.github.com>
@@ -95,10 +102,12 @@ Kanchalai Tanglertsampan <yuisu@microsoft.com> Yui T <yuisu@microsoft.com>
95102
Kanchalai Tanglertsampan <yuisu@microsoft.com> Yui <yuit@users.noreply.github.com>
96103
Kanchalai Tanglertsampan <yuisu@microsoft.com> Yui <yuisu@microsoft.com>
97104
Kanchalai Tanglertsampan <yuisu@microsoft.com> yui T <yuisu@microsoft.com>
105+
Kārlis Gaņģis <Knagis@users.noreply.github.com>
98106
Keith Mashinter <kmashint@yahoo.com> kmashint <kmashint@yahoo.com>
99107
Ken Howard <ken@simplicatedweb.com>
100108
Kevin Lang <klang2012@gmail.com>
101109
kimamula <kenji.imamula@gmail.com> # Kenji Imamula
110+
Klaus Meinhardt <klaus.meinhardt1@gmail.com>
102111
Kyle Kelley <rgbkrk@gmail.com>
103112
Lorant Pinter <lorant.pinter@prezi.com>
104113
Lucien Greathouse <me@lpghatguy.com>
@@ -107,6 +116,7 @@ Martin Vseticka <vseticka.martin@gmail.com> Martin Všeticka <vseticka.martin@gm
107116
gcnew <gcnew@abv.bg> # Marin Marinov
108117
vvakame <vvakame+dev@gmail.com> # Masahiro Wakame
109118
Matt McCutchen <rmccutch@mit.edu>
119+
MANISH-GIRI <manish.giri.me@gmail.com> # Manish Giri
110120
Max Deepfield <maxdeepfield@absolutefreakout.com>
111121
Micah Zoltu <micah@zoltu.net>
112122
Michael <maykelchiche@gmail.com>
@@ -213,4 +223,6 @@ Tim Perry <tim.perry@softwire.com>
213223
Vidar Tonaas Fauske <vidartf@gmail.com>
214224
Viktor Zozulyak <zozulyakviktor@gmail.com>
215225
rix <rix@rixs-MacBook-Pro.local> # Richard Sentino
216-
rohitverma007 <rohitverma@live.ca> # Rohit Verma
226+
rohitverma007 <rohitverma@live.ca> # Rohit Verma
227+
rdosanjh <me@rajdeep.io> # Raj Dosanjh
228+
gdh1995 <gdh1995@qq.com> # 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)