Transform namespaces declared with module keyword to namespace keyword in d.ts files (#54134)

Signed-off-by: Chi Leung <chiguan.leung@gmail.com>
Co-authored-by: Titian Cernicova-Dragomir <dragomirtitian@yahoo.com>
Co-authored-by: Titian Cernicova-Dragomir <tcernicovad1@bloomberg.net>
This commit is contained in:
Chi Leung
2023-06-26 17:58:23 +01:00
committed by GitHub
parent 7dd7caaf7c
commit a94eb319eb
174 changed files with 547 additions and 518 deletions

View File

@@ -91,6 +91,7 @@ import {
ImportTypeNode,
IndexSignatureDeclaration,
InterfaceDeclaration,
isAmbientModule,
isAnyImportSyntax,
isArray,
isArrayBindingElement,
@@ -163,8 +164,10 @@ import {
MethodSignature,
Modifier,
ModifierFlags,
ModifierLike,
ModuleBody,
ModuleDeclaration,
ModuleName,
NamedDeclaration,
NamespaceDeclaration,
needsScopeMarker,
@@ -1422,6 +1425,31 @@ export function transformDeclarations(context: TransformationContext) {
return factory.updateModifiers(statement, modifiers);
}
function updateModuleDeclarationAndKeyword(
node: ModuleDeclaration,
modifiers: readonly ModifierLike[] | undefined,
name: ModuleName,
body: ModuleBody | undefined
) {
const updated = factory.updateModuleDeclaration(node, modifiers, name, body);
if (isAmbientModule(updated) || updated.flags & NodeFlags.Namespace) {
return updated;
}
const fixed = factory.createModuleDeclaration(
updated.modifiers,
updated.name,
updated.body,
updated.flags | NodeFlags.Namespace
);
setOriginalNode(fixed, updated);
setTextRange(fixed, updated);
return fixed;
}
function transformTopLevelDeclaration(input: LateVisibilityPaintedStatement) {
if (lateMarkedStatements) {
while (orderedRemoveItem(lateMarkedStatements, input));
@@ -1598,7 +1626,8 @@ export function transformDeclarations(context: TransformationContext) {
needsScopeFixMarker = oldNeedsScopeFix;
resultHasScopeMarker = oldHasScopeFix;
const mods = ensureModifiers(input);
return cleanup(factory.updateModuleDeclaration(
return cleanup(updateModuleDeclarationAndKeyword(
input,
mods,
isExternalModuleAugmentation(input) ? rewriteModuleSpecifier(input, input.name) : input.name,
@@ -1614,7 +1643,7 @@ export function transformDeclarations(context: TransformationContext) {
const id = getOriginalNodeId(inner!); // TODO: GH#18217
const body = lateStatementReplacementMap.get(id);
lateStatementReplacementMap.delete(id);
return cleanup(factory.updateModuleDeclaration(
return cleanup(updateModuleDeclarationAndKeyword(
input,
mods,
input.name,