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;

0 commit comments

Comments
 (0)