Skip to content

Commit d110f3c

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/widen-compound-like
2 parents 104b97a + df40c7a commit d110f3c

File tree

205 files changed

+1493
-667
lines changed

Some content is hidden

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

205 files changed

+1493
-667
lines changed

src/compiler/checker.ts

Lines changed: 43 additions & 58 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,10 +1860,6 @@
18601860
"category": "Error",
18611861
"code": 2345
18621862
},
1863-
"Call target does not contain any signatures.": {
1864-
"category": "Error",
1865-
"code": 2346
1866-
},
18671863
"Untyped function calls may not accept type arguments.": {
18681864
"category": "Error",
18691865
"code": 2347
@@ -4277,10 +4273,6 @@
42774273
"category": "Error",
42784274
"code": 5083
42794275
},
4280-
"Tuple members must all have names or all not have names.": {
4281-
"category": "Error",
4282-
"code": 5084
4283-
},
42844276
"A tuple member cannot be both optional and rest.": {
42854277
"category": "Error",
42864278
"code": 5085

src/compiler/transformers/declarations.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import {
9191
ImportTypeNode,
9292
IndexSignatureDeclaration,
9393
InterfaceDeclaration,
94+
isAmbientModule,
9495
isAnyImportSyntax,
9596
isArray,
9697
isArrayBindingElement,
@@ -163,8 +164,10 @@ import {
163164
MethodSignature,
164165
Modifier,
165166
ModifierFlags,
167+
ModifierLike,
166168
ModuleBody,
167169
ModuleDeclaration,
170+
ModuleName,
168171
NamedDeclaration,
169172
NamespaceDeclaration,
170173
needsScopeMarker,
@@ -1422,6 +1425,31 @@ export function transformDeclarations(context: TransformationContext) {
14221425
return factory.updateModifiers(statement, modifiers);
14231426
}
14241427

1428+
function updateModuleDeclarationAndKeyword(
1429+
node: ModuleDeclaration,
1430+
modifiers: readonly ModifierLike[] | undefined,
1431+
name: ModuleName,
1432+
body: ModuleBody | undefined
1433+
) {
1434+
const updated = factory.updateModuleDeclaration(node, modifiers, name, body);
1435+
1436+
if (isAmbientModule(updated) || updated.flags & NodeFlags.Namespace) {
1437+
return updated;
1438+
}
1439+
1440+
const fixed = factory.createModuleDeclaration(
1441+
updated.modifiers,
1442+
updated.name,
1443+
updated.body,
1444+
updated.flags | NodeFlags.Namespace
1445+
);
1446+
1447+
setOriginalNode(fixed, updated);
1448+
setTextRange(fixed, updated);
1449+
1450+
return fixed;
1451+
}
1452+
14251453
function transformTopLevelDeclaration(input: LateVisibilityPaintedStatement) {
14261454
if (lateMarkedStatements) {
14271455
while (orderedRemoveItem(lateMarkedStatements, input));
@@ -1598,7 +1626,8 @@ export function transformDeclarations(context: TransformationContext) {
15981626
needsScopeFixMarker = oldNeedsScopeFix;
15991627
resultHasScopeMarker = oldHasScopeFix;
16001628
const mods = ensureModifiers(input);
1601-
return cleanup(factory.updateModuleDeclaration(
1629+
1630+
return cleanup(updateModuleDeclarationAndKeyword(
16021631
input,
16031632
mods,
16041633
isExternalModuleAugmentation(input) ? rewriteModuleSpecifier(input, input.name) : input.name,
@@ -1614,7 +1643,7 @@ export function transformDeclarations(context: TransformationContext) {
16141643
const id = getOriginalNodeId(inner!); // TODO: GH#18217
16151644
const body = lateStatementReplacementMap.get(id);
16161645
lateStatementReplacementMap.delete(id);
1617-
return cleanup(factory.updateModuleDeclaration(
1646+
return cleanup(updateModuleDeclarationAndKeyword(
16181647
input,
16191648
mods,
16201649
input.name,

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6434,7 +6434,7 @@ export interface TupleType extends GenericType {
64346434
hasRestElement: boolean;
64356435
combinedFlags: ElementFlags;
64366436
readonly: boolean;
6437-
labeledElementDeclarations?: readonly (NamedTupleMember | ParameterDeclaration)[];
6437+
labeledElementDeclarations?: readonly (NamedTupleMember | ParameterDeclaration | undefined)[];
64386438
}
64396439

64406440
export interface TupleTypeReference extends TypeReference {

src/services/completions.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,7 +2439,7 @@ export function getCompletionEntriesFromSymbols(
24392439
includeSymbol = false
24402440
): UniqueNameSet {
24412441
const start = timestamp();
2442-
const variableOrParameterDeclaration = getVariableOrParameterDeclaration(contextToken);
2442+
const variableOrParameterDeclaration = getVariableOrParameterDeclaration(contextToken, location);
24432443
const useSemicolons = probablyUsesSemicolons(sourceFile);
24442444
const typeChecker = program.getTypeChecker();
24452445
// Tracks unique names.
@@ -5516,14 +5516,20 @@ function isModuleSpecifierMissingOrEmpty(specifier: ModuleReference | Expression
55165516
return !tryCast(isExternalModuleReference(specifier) ? specifier.expression : specifier, isStringLiteralLike)?.text;
55175517
}
55185518

5519-
function getVariableOrParameterDeclaration(contextToken: Node | undefined) {
5519+
function getVariableOrParameterDeclaration(contextToken: Node | undefined, location: Node) {
55205520
if (!contextToken) return;
55215521

5522-
const declaration = findAncestor(contextToken, node =>
5522+
const possiblyParameterDeclaration = findAncestor(contextToken, node =>
55235523
isFunctionBlock(node) || isArrowFunctionBody(node) || isBindingPattern(node)
55245524
? "quit"
5525-
: isVariableDeclaration(node) || ((isParameter(node) || isTypeParameterDeclaration(node)) && !isIndexSignatureDeclaration(node.parent)));
5526-
return declaration as ParameterDeclaration | TypeParameterDeclaration | VariableDeclaration | undefined;
5525+
: ((isParameter(node) || isTypeParameterDeclaration(node)) && !isIndexSignatureDeclaration(node.parent)));
5526+
5527+
const possiblyVariableDeclaration = findAncestor(location, node =>
5528+
isFunctionBlock(node) || isArrowFunctionBody(node) || isBindingPattern(node)
5529+
? "quit"
5530+
: isVariableDeclaration(node));
5531+
5532+
return (possiblyParameterDeclaration || possiblyVariableDeclaration) as ParameterDeclaration | TypeParameterDeclaration | VariableDeclaration | undefined;
55275533
}
55285534

55295535
function isArrowFunctionBody(node: Node) {

src/services/refactors/inlineVariable.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import {
2020
isFunctionLike,
2121
isIdentifier,
2222
isInitializedVariable,
23+
isNumericLiteral,
24+
isObjectLiteralExpression,
25+
isPropertyAccessExpression,
2326
isTypeQueryNode,
2427
isVariableDeclarationInVariableStatement,
2528
isVariableStatement,
@@ -228,7 +231,13 @@ function getReplacementExpression(reference: Node, replacement: Expression): Exp
228231

229232
// Functions also need to be parenthesized.
230233
// E.g.: const f = () => {}; f(); -> (() => {})();
231-
if (isFunctionLike(replacement) && isCallLikeExpression(parent)) {
234+
if (isFunctionLike(replacement) && (isCallLikeExpression(parent) || isPropertyAccessExpression(parent))) {
235+
return factory.createParenthesizedExpression(replacement);
236+
}
237+
238+
// Property access of numeric literals and objects need parentheses.
239+
// E.g.: const x = 1; x.toString(); -> (1).toString();
240+
if (isPropertyAccessExpression(parent) && (isNumericLiteral(replacement) || isObjectLiteralExpression(replacement))) {
232241
return factory.createParenthesizedExpression(replacement);
233242
}
234243

tests/baselines/reference/aliasInaccessibleModule.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ var M;
1414

1515

1616
//// [aliasInaccessibleModule.d.ts]
17-
declare module M {
18-
module N {
17+
declare namespace M {
18+
namespace N {
1919
}
2020
export import X = N;
2121
export {};

tests/baselines/reference/aliasInaccessibleModule2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ var M;
2828

2929

3030
//// [aliasInaccessibleModule2.d.ts]
31-
declare module M {
32-
module N {
31+
declare namespace M {
32+
namespace N {
3333
}
3434
import R = N;
3535
export import X = R;

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6951,7 +6951,7 @@ declare namespace ts {
69516951
hasRestElement: boolean;
69526952
combinedFlags: ElementFlags;
69536953
readonly: boolean;
6954-
labeledElementDeclarations?: readonly (NamedTupleMember | ParameterDeclaration)[];
6954+
labeledElementDeclarations?: readonly (NamedTupleMember | ParameterDeclaration | undefined)[];
69556955
}
69566956
interface TupleTypeReference extends TypeReference {
69576957
target: TupleType;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2898,7 +2898,7 @@ declare namespace ts {
28982898
hasRestElement: boolean;
28992899
combinedFlags: ElementFlags;
29002900
readonly: boolean;
2901-
labeledElementDeclarations?: readonly (NamedTupleMember | ParameterDeclaration)[];
2901+
labeledElementDeclarations?: readonly (NamedTupleMember | ParameterDeclaration | undefined)[];
29022902
}
29032903
interface TupleTypeReference extends TypeReference {
29042904
target: TupleType;

tests/baselines/reference/classConstructorAccessibility.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,5 @@ declare class E {
100100
declare var c: C;
101101
declare var d: any;
102102
declare var e: any;
103-
declare module Generic {
103+
declare namespace Generic {
104104
}

tests/baselines/reference/classDoesNotDependOnPrivateMember.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var M;
2121

2222

2323
//// [classDoesNotDependOnPrivateMember.d.ts]
24-
declare module M {
24+
declare namespace M {
2525
class C {
2626
private x;
2727
}

tests/baselines/reference/classdecl.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ declare class a {
235235
}
236236
declare class b extends a {
237237
}
238-
declare module m1 {
238+
declare namespace m1 {
239239
class b {
240240
}
241241
interface ib {
242242
}
243243
}
244-
declare module m2 {
245-
module m3 {
244+
declare namespace m2 {
245+
namespace m3 {
246246
class c extends b {
247247
}
248248
class ib2 implements m1.ib {

tests/baselines/reference/commentsDottedModuleName.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ define(["require", "exports"], function (require, exports) {
3232

3333
//// [commentsDottedModuleName.d.ts]
3434
/** this is multi declare module*/
35-
export declare module outerModule.InnerModule {
35+
export declare namespace outerModule.InnerModule {
3636
class b {
3737
}
3838
}

tests/baselines/reference/commentsExternalModules.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ define(["require", "exports", "commentsExternalModules_0"], function (require, e
139139

140140
//// [commentsExternalModules_0.d.ts]
141141
/** Module comment*/
142-
export declare module m1 {
142+
export declare namespace m1 {
143143
/** b's comment*/
144144
var b: number;
145145
/** m2 comments*/
146-
module m2 {
146+
namespace m2 {
147147
/** class comment;*/
148148
class c {
149149
}
@@ -154,12 +154,12 @@ export declare module m1 {
154154
function fooExport(): number;
155155
}
156156
/** Module comment */
157-
export declare module m4 {
157+
export declare namespace m4 {
158158
/** b's comment */
159159
var b: number;
160160
/** m2 comments
161161
*/
162-
module m2 {
162+
namespace m2 {
163163
/** class comment; */
164164
class c {
165165
}

tests/baselines/reference/commentsExternalModules2.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ define(["require", "exports", "commentsExternalModules2_0"], function (require,
140140

141141
//// [commentsExternalModules2_0.d.ts]
142142
/** Module comment*/
143-
export declare module m1 {
143+
export declare namespace m1 {
144144
/** b's comment*/
145145
var b: number;
146146
/** m2 comments*/
147-
module m2 {
147+
namespace m2 {
148148
/** class comment;*/
149149
class c {
150150
}
@@ -155,12 +155,12 @@ export declare module m1 {
155155
function fooExport(): number;
156156
}
157157
/** Module comment */
158-
export declare module m4 {
158+
export declare namespace m4 {
159159
/** b's comment */
160160
var b: number;
161161
/** m2 comments
162162
*/
163-
module m2 {
163+
namespace m2 {
164164
/** class comment; */
165165
class c {
166166
}

tests/baselines/reference/commentsExternalModules3.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ exports.newVar2 = new extMod.m4.m2.c();
138138

139139
//// [commentsExternalModules2_0.d.ts]
140140
/** Module comment*/
141-
export declare module m1 {
141+
export declare namespace m1 {
142142
/** b's comment*/
143143
var b: number;
144144
/** m2 comments*/
145-
module m2 {
145+
namespace m2 {
146146
/** class comment;*/
147147
class c {
148148
}
@@ -153,12 +153,12 @@ export declare module m1 {
153153
function fooExport(): number;
154154
}
155155
/** Module comment */
156-
export declare module m4 {
156+
export declare namespace m4 {
157157
/** b's comment */
158158
var b: number;
159159
/** m2 comments
160160
*/
161-
module m2 {
161+
namespace m2 {
162162
/** class comment; */
163163
class c {
164164
}

tests/baselines/reference/commentsFormatting.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ this is 4 spaces left aligned but above line is empty
190190

191191

192192
//// [commentsFormatting.d.ts]
193-
declare module m {
193+
declare namespace m {
194194
/** this is first line - aligned to class declaration
195195
* this is 4 spaces left aligned
196196
* this is 3 spaces left aligned

0 commit comments

Comments
 (0)