@@ -91,6 +91,7 @@ import {
91
91
ImportTypeNode ,
92
92
IndexSignatureDeclaration ,
93
93
InterfaceDeclaration ,
94
+ isAmbientModule ,
94
95
isAnyImportSyntax ,
95
96
isArray ,
96
97
isArrayBindingElement ,
@@ -163,8 +164,10 @@ import {
163
164
MethodSignature ,
164
165
Modifier ,
165
166
ModifierFlags ,
167
+ ModifierLike ,
166
168
ModuleBody ,
167
169
ModuleDeclaration ,
170
+ ModuleName ,
168
171
NamedDeclaration ,
169
172
NamespaceDeclaration ,
170
173
needsScopeMarker ,
@@ -1422,6 +1425,31 @@ export function transformDeclarations(context: TransformationContext) {
1422
1425
return factory . updateModifiers ( statement , modifiers ) ;
1423
1426
}
1424
1427
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
+
1425
1453
function transformTopLevelDeclaration ( input : LateVisibilityPaintedStatement ) {
1426
1454
if ( lateMarkedStatements ) {
1427
1455
while ( orderedRemoveItem ( lateMarkedStatements , input ) ) ;
@@ -1598,7 +1626,8 @@ export function transformDeclarations(context: TransformationContext) {
1598
1626
needsScopeFixMarker = oldNeedsScopeFix ;
1599
1627
resultHasScopeMarker = oldHasScopeFix ;
1600
1628
const mods = ensureModifiers ( input ) ;
1601
- return cleanup ( factory . updateModuleDeclaration (
1629
+
1630
+ return cleanup ( updateModuleDeclarationAndKeyword (
1602
1631
input ,
1603
1632
mods ,
1604
1633
isExternalModuleAugmentation ( input ) ? rewriteModuleSpecifier ( input , input . name ) : input . name ,
@@ -1614,7 +1643,7 @@ export function transformDeclarations(context: TransformationContext) {
1614
1643
const id = getOriginalNodeId ( inner ! ) ; // TODO: GH#18217
1615
1644
const body = lateStatementReplacementMap . get ( id ) ;
1616
1645
lateStatementReplacementMap . delete ( id ) ;
1617
- return cleanup ( factory . updateModuleDeclaration (
1646
+ return cleanup ( updateModuleDeclarationAndKeyword (
1618
1647
input ,
1619
1648
mods ,
1620
1649
input . name ,
0 commit comments