Skip to content

Commit 0978639

Browse files
committed
Merge branch 'master' into fixDecoratedClassName
2 parents 39077f6 + cb6dd18 commit 0978639

36 files changed

Lines changed: 869 additions & 57 deletions

AUTHORS.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ TypeScript is authored by:
22

33
* Adam Freidin
44
* Ahmad Farid
5+
* Akshar Patel
56
* Anders Hejlsberg
67
* Arnav Singh
78
* Arthur Ozga
9+
* Asad Saeeduddin
810
* Basarat Ali Syed
911
* Ben Duffield
1012
* Bill Ticehurst
@@ -15,52 +17,67 @@ TypeScript is authored by:
1517
* Colby Russell
1618
* Colin Snover
1719
* Cyrus Najmabadi
20+
* Dan Corder
1821
* Dan Quirk
1922
* Daniel Rosenwasser
23+
* @dashaus
2024
* David Li
2125
* Denis Nedelyaev
2226
* Dick van den Brink
2327
* Dirk Bäumer
28+
* Dirk Holtwick
2429
* Eyas Sharaiha
30+
* @falsandtru
2531
* Frank Wallis
2632
* Gabriel Isenberg
2733
* Gilad Peleg
2834
* Graeme Wicksted
2935
* Guillaume Salles
36+
* Guy Bedford
3037
* Harald Niesche
38+
* Iain Monro
3139
* Ingvar Stepanyan
3240
* Ivo Gabe de Wolff
3341
* James Whitney
3442
* Jason Freeman
43+
* Jason Killian
3544
* Jason Ramsay
3645
* Jed Mao
46+
* Jeffrey Morlan
3747
* Johannes Rieken
3848
* John Vilk
3949
* Jonathan Bond-Caron
4050
* Jonathan Park
4151
* Jonathan Turner
52+
* Jonathon Smith
4253
* Josh Kalderimis
4354
* Julian Williams
4455
* Kagami Sascha Rosylight
4556
* Keith Mashinter
4657
* Ken Howard
4758
* Kenji Imamula
4859
* Lorant Pinter
60+
* Lucien Greathouse
4961
* Martin Všetička
5062
* Masahiro Wakame
63+
* Mattias Buelens
5164
* Max Deepfield
5265
* Micah Zoltu
5366
* Mohamed Hegazy
5467
* Nathan Shively-Sanders
68+
* Nathan Yee
5569
* Oleg Mihailik
5670
* Oleksandr Chekhovskyi
5771
* Paul van Brenk
72+
* @pcbro
5873
* Pedro Maltez
5974
* Philip Bulley
6075
* piloopin
6176
* @progre
6277
* Punya Biswal
78+
* Richard Sentino
6379
* Ron Buckton
80+
* Rowan Wyborn
6481
* Ryan Cavanaugh
6582
* Ryohei Ikegami
6683
* Sébastien Arod
@@ -71,7 +88,9 @@ TypeScript is authored by:
7188
* Solal Pirelli
7289
* Stan Thomas
7390
* Steve Lucco
91+
* Thomas Loubiou
7492
* Tien Hoanhtien
93+
* Tim Perry
7594
* Tingan Ho
7695
* togru
7796
* Tomas Grubliauskas
@@ -81,5 +100,6 @@ TypeScript is authored by:
81100
* Wesley Wigham
82101
* York Yao
83102
* Yui Tanglertsampan
103+
* Yuichi Nukiyama
84104
* Zev Spitz
85105
* Zhengbo Li

src/compiler/checker.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10442,7 +10442,8 @@ namespace ts {
1044210442
}
1044310443
else {
1044410444
error(func, Diagnostics.No_best_common_type_exists_among_return_expressions);
10445-
return unknownType;
10445+
// Defer to unioning the return types so we get a) downstream errors earlier and b) better Salsa experience
10446+
return getUnionType(types);
1044610447
}
1044710448
}
1044810449

@@ -15379,6 +15380,20 @@ namespace ts {
1537915380
return getSymbolOfNode(entityName.parent);
1538015381
}
1538115382

15383+
if (isInJavaScriptFile(entityName) && entityName.parent.kind === SyntaxKind.PropertyAccessExpression) {
15384+
const specialPropertyAssignmentKind = getSpecialPropertyAssignmentKind(entityName.parent.parent);
15385+
switch (specialPropertyAssignmentKind) {
15386+
case SpecialPropertyAssignmentKind.ExportsProperty:
15387+
case SpecialPropertyAssignmentKind.PrototypeProperty:
15388+
return getSymbolOfNode(entityName.parent);
15389+
case SpecialPropertyAssignmentKind.ThisProperty:
15390+
case SpecialPropertyAssignmentKind.ModuleExports:
15391+
return getSymbolOfNode(entityName.parent.parent);
15392+
default:
15393+
// Fall through if it is not a special property assignment
15394+
}
15395+
}
15396+
1538215397
if (entityName.parent.kind === SyntaxKind.ExportAssignment) {
1538315398
return resolveEntityName(<Identifier>entityName,
1538415399
/*all meanings*/ SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);

src/compiler/declarationEmitter.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -637,18 +637,21 @@ namespace ts {
637637
}
638638
}
639639

640-
function emitClassMemberDeclarationFlags(node: Declaration) {
641-
if (node.flags & NodeFlags.Private) {
640+
function emitClassMemberDeclarationFlags(flags: NodeFlags) {
641+
if (flags & NodeFlags.Private) {
642642
write("private ");
643643
}
644-
else if (node.flags & NodeFlags.Protected) {
644+
else if (flags & NodeFlags.Protected) {
645645
write("protected ");
646646
}
647647

648-
if (node.flags & NodeFlags.Static) {
648+
if (flags & NodeFlags.Static) {
649649
write("static ");
650650
}
651-
if (node.flags & NodeFlags.Abstract) {
651+
if (flags & NodeFlags.Readonly) {
652+
write("readonly ");
653+
}
654+
if (flags & NodeFlags.Abstract) {
652655
write("abstract ");
653656
}
654657
}
@@ -1074,7 +1077,7 @@ namespace ts {
10741077
}
10751078

10761079
emitJsDocComments(node);
1077-
emitClassMemberDeclarationFlags(node);
1080+
emitClassMemberDeclarationFlags(node.flags);
10781081
emitVariableDeclaration(<VariableDeclaration>node);
10791082
write(";");
10801083
writeLine();
@@ -1227,7 +1230,7 @@ namespace ts {
12271230
if (node === accessors.firstAccessor) {
12281231
emitJsDocComments(accessors.getAccessor);
12291232
emitJsDocComments(accessors.setAccessor);
1230-
emitClassMemberDeclarationFlags(node);
1233+
emitClassMemberDeclarationFlags(node.flags | (accessors.setAccessor ? 0 : NodeFlags.Readonly));
12311234
writeTextOfNode(currentText, node.name);
12321235
if (!(node.flags & NodeFlags.Private)) {
12331236
accessorWithTypeAnnotation = node;
@@ -1314,7 +1317,7 @@ namespace ts {
13141317
emitModuleElementDeclarationFlags(node);
13151318
}
13161319
else if (node.kind === SyntaxKind.MethodDeclaration) {
1317-
emitClassMemberDeclarationFlags(node);
1320+
emitClassMemberDeclarationFlags(node.flags);
13181321
}
13191322
if (node.kind === SyntaxKind.FunctionDeclaration) {
13201323
write("function ");
@@ -1342,15 +1345,17 @@ namespace ts {
13421345
const prevEnclosingDeclaration = enclosingDeclaration;
13431346
enclosingDeclaration = node;
13441347

1345-
// Construct signature or constructor type write new Signature
1346-
if (node.kind === SyntaxKind.ConstructSignature || node.kind === SyntaxKind.ConstructorType) {
1347-
write("new ");
1348-
}
1349-
emitTypeParameters(node.typeParameters);
13501348
if (node.kind === SyntaxKind.IndexSignature) {
1349+
// Index signature can have readonly modifier
1350+
emitClassMemberDeclarationFlags(node.flags);
13511351
write("[");
13521352
}
13531353
else {
1354+
// Construct signature or constructor type write new Signature
1355+
if (node.kind === SyntaxKind.ConstructSignature || node.kind === SyntaxKind.ConstructorType) {
1356+
write("new ");
1357+
}
1358+
emitTypeParameters(node.typeParameters);
13541359
write("(");
13551360
}
13561361

src/compiler/emitter.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7123,14 +7123,22 @@ const _super = (function (geti, seti) {
71237123

71247124
for (let i = 0; i < externalImports.length; i++) {
71257125
const text = getExternalModuleNameText(externalImports[i], emitRelativePathAsModuleName);
7126-
if (hasProperty(groupIndices, text)) {
7126+
if (text === undefined) {
7127+
continue;
7128+
}
7129+
7130+
// text should be quoted string
7131+
// for deduplication purposes in key remove leading and trailing quotes so 'a' and "a" will be considered the same
7132+
const key = text.substr(1, text.length - 2);
7133+
7134+
if (hasProperty(groupIndices, key)) {
71277135
// deduplicate/group entries in dependency list by the dependency name
7128-
const groupIndex = groupIndices[text];
7136+
const groupIndex = groupIndices[key];
71297137
dependencyGroups[groupIndex].push(externalImports[i]);
71307138
continue;
71317139
}
71327140
else {
7133-
groupIndices[text] = dependencyGroups.length;
7141+
groupIndices[key] = dependencyGroups.length;
71347142
dependencyGroups.push([externalImports[i]]);
71357143
}
71367144

src/compiler/parser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4017,7 +4017,7 @@ namespace ts {
40174017
setDecoratorContext(/*val*/ true);
40184018
}
40194019

4020-
return finishNode(node);
4020+
return addJSDocComment(finishNode(node));
40214021
}
40224022

40234023
function parseOptionalIdentifier() {
@@ -4301,13 +4301,13 @@ namespace ts {
43014301
const labeledStatement = <LabeledStatement>createNode(SyntaxKind.LabeledStatement, fullStart);
43024302
labeledStatement.label = <Identifier>expression;
43034303
labeledStatement.statement = parseStatement();
4304-
return finishNode(labeledStatement);
4304+
return addJSDocComment(finishNode(labeledStatement));
43054305
}
43064306
else {
43074307
const expressionStatement = <ExpressionStatement>createNode(SyntaxKind.ExpressionStatement, fullStart);
43084308
expressionStatement.expression = expression;
43094309
parseSemicolon();
4310-
return finishNode(expressionStatement);
4310+
return addJSDocComment(finishNode(expressionStatement));
43114311
}
43124312
}
43134313

src/compiler/utilities.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,19 @@ namespace ts {
12051205
node.parent.parent.parent.kind === SyntaxKind.VariableStatement;
12061206

12071207
const variableStatementNode = isInitializerOfVariableDeclarationInStatement ? node.parent.parent.parent : undefined;
1208-
return variableStatementNode && variableStatementNode.jsDocComment;
1208+
if (variableStatementNode) {
1209+
return variableStatementNode.jsDocComment;
1210+
}
1211+
1212+
// Also recognize when the node is the RHS of an assignment expression
1213+
const isSourceOfAssignmentExpressionStatement =
1214+
node.parent && node.parent.parent &&
1215+
node.parent.kind === SyntaxKind.BinaryExpression &&
1216+
(node.parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken &&
1217+
node.parent.parent.kind === SyntaxKind.ExpressionStatement;
1218+
if (isSourceOfAssignmentExpressionStatement) {
1219+
return node.parent.parent.jsDocComment;
1220+
}
12091221
}
12101222

12111223
return undefined;

tests/baselines/reference/classdecl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ declare class a {
211211
pgF(): void;
212212
pv: any;
213213
d: number;
214-
static p2: {
214+
static readonly p2: {
215215
x: number;
216216
y: number;
217217
};
218218
private static d2();
219-
private static p3;
219+
private static readonly p3;
220220
private pv3;
221221
private foo(n);
222222
private foo(s);

tests/baselines/reference/commentsClassMembers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,8 @@ declare var i1_c: typeof c1;
568568
declare class cProperties {
569569
private val;
570570
/** getter only property*/
571-
p1: number;
572-
nc_p1: number;
571+
readonly p1: number;
572+
readonly nc_p1: number;
573573
/**setter only property*/
574574
p2: number;
575575
nc_p2: number;

tests/baselines/reference/commentsInheritance.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,19 +316,19 @@ declare class c2 {
316316
/** c2 c2_f1*/
317317
c2_f1(): void;
318318
/** c2 c2_prop*/
319-
c2_prop: number;
319+
readonly c2_prop: number;
320320
c2_nc_p1: number;
321321
c2_nc_f1(): void;
322-
c2_nc_prop: number;
322+
readonly c2_nc_prop: number;
323323
/** c2 p1*/
324324
p1: number;
325325
/** c2 f1*/
326326
f1(): void;
327327
/** c2 prop*/
328-
prop: number;
328+
readonly prop: number;
329329
nc_p1: number;
330330
nc_f1(): void;
331-
nc_prop: number;
331+
readonly nc_prop: number;
332332
/** c2 constructor*/
333333
constructor(a: number);
334334
}
@@ -339,10 +339,10 @@ declare class c3 extends c2 {
339339
/** c3 f1*/
340340
f1(): void;
341341
/** c3 prop*/
342-
prop: number;
342+
readonly prop: number;
343343
nc_p1: number;
344344
nc_f1(): void;
345-
nc_prop: number;
345+
readonly nc_prop: number;
346346
}
347347
declare var c2_i: c2;
348348
declare var c3_i: c3;

tests/baselines/reference/declFileAccessors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ export declare class c1 {
284284
nc_p3: number;
285285
private nc_pp3;
286286
static nc_s3: string;
287-
onlyGetter: number;
287+
readonly onlyGetter: number;
288288
onlySetter: number;
289289
}
290290
//// [declFileAccessors_1.d.ts]
@@ -302,6 +302,6 @@ declare class c2 {
302302
nc_p3: number;
303303
private nc_pp3;
304304
static nc_s3: string;
305-
onlyGetter: number;
305+
readonly onlyGetter: number;
306306
onlySetter: number;
307307
}

0 commit comments

Comments
 (0)