@@ -1134,6 +1134,7 @@ import {
11341134 WithStatement,
11351135 WriterContextOut,
11361136 YieldExpression,
1137+ ModuleName,
11371138} from "./_namespaces/ts.js";
11381139import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers.js";
11391140import * as performance from "./_namespaces/ts.performance.js";
@@ -9802,7 +9803,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
98029803 // than whatever scope we traverse to them in. That's a bit of a complex rewrite, since we're not _actually_ tracking privates at all in advance,
98039804 // so we don't even have placeholders to fill in.
98049805 if (length(realMembers) || unfolding) {
9805- const localName = getInternalSymbolName(symbol, symbolName);
9806+ let localName: ModuleName;
9807+ if (unfolding) {
9808+ // Use the same name as symbol display.
9809+ const oldFlags = context.flags;
9810+ context.flags |= NodeBuilderFlags.WriteTypeParametersInQualifiedName | SymbolFormatFlags.UseOnlyExternalAliasing;
9811+ localName = symbolToNode(symbol, context, /*meaning*/ SymbolFlags.All) as ModuleName;
9812+ context.flags = oldFlags;
9813+ }
9814+ else {
9815+ const localText = getInternalSymbolName(symbol, symbolName);
9816+ localName = factory.createIdentifier(localText);
9817+ context.approximateLength += localText.length;
9818+ }
98069819 serializeAsNamespaceDeclaration(realMembers, localName, modifierFlags, !!(symbol.flags & (SymbolFlags.Function | SymbolFlags.Assignment)));
98079820 }
98089821 if (length(mergedMembers)) {
@@ -9898,7 +9911,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
98989911 // Module symbol emit will take care of module-y members, provided it has exports
98999912 if (!(symbol.flags & (SymbolFlags.ValueModule | SymbolFlags.NamespaceModule) && !!symbol.exports && !!symbol.exports.size)) {
99009913 const props = filter(getPropertiesOfType(type), isNamespaceMember);
9901- serializeAsNamespaceDeclaration(props, localName, modifierFlags, /*suppressNewPrivateContext*/ true);
9914+ context.approximateLength += localName.length;
9915+ serializeAsNamespaceDeclaration(props, factory.createIdentifier(localName), modifierFlags, /*suppressNewPrivateContext*/ true);
99029916 }
99039917 }
99049918
@@ -9919,10 +9933,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
99199933 return signature.declaration;
99209934 }
99219935
9922- function serializeAsNamespaceDeclaration(props: readonly Symbol[], localName: string, modifierFlags: ModifierFlags, suppressNewPrivateContext: boolean) {
9936+ function serializeAsNamespaceDeclaration(props: readonly Symbol[], localName: ModuleName, modifierFlags: ModifierFlags, suppressNewPrivateContext: boolean) {
9937+ const nodeFlags = isIdentifier(localName) ? NodeFlags.Namespace : NodeFlags.None;
99239938 const unfolding = isUnfolding(context);
99249939 if (length(props)) {
9925- context.approximateLength += localName.length + 14; // "namespace localName { }"
9940+ context.approximateLength += 14; // "namespace { }"
99269941 const localVsRemoteMap = arrayToMultiMap(props, p => !length(p.declarations) || some(p.declarations, d => getSourceFileOfNode(d) === getSourceFileOfNode(context.enclosingDeclaration!)) || unfolding ? "local" : "remote");
99279942 const localProps = localVsRemoteMap.get("local") || emptyArray;
99289943 // handle remote props first - we need to make an `import` declaration that points at the module containing each remote
@@ -9942,7 +9957,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
99429957
99439958 // Add a namespace
99449959 // Create namespace as non-synthetic so it is usable as an enclosing declaration
9945- let fakespace = parseNodeFactory.createModuleDeclaration(/*modifiers*/ undefined, factory.createIdentifier( localName) , factory.createModuleBlock([]), NodeFlags.Namespace );
9960+ let fakespace = parseNodeFactory.createModuleDeclaration(/*modifiers*/ undefined, localName, factory.createModuleBlock([]), nodeFlags );
99469961 setParent(fakespace, enclosingDeclaration as SourceFile | NamespaceDeclaration);
99479962 fakespace.locals = createSymbolTable(props);
99489963 fakespace.symbol = props[0].parent!;
@@ -9977,13 +9992,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
99779992 addResult(fakespace, modifierFlags); // namespaces can never be default exported
99789993 }
99799994 else if (unfolding) {
9980- context.approximateLength += localName.length + 14; // "namespace { }"
9995+ context.approximateLength += 14; // "namespace { }"
99819996 addResult(
99829997 factory.createModuleDeclaration(
99839998 /*modifiers*/ undefined,
9984- factory.createIdentifier( localName) ,
9999+ localName,
998510000 factory.createModuleBlock([]),
9986- NodeFlags.Namespace ,
10001+ nodeFlags ,
998710002 ),
998810003 modifierFlags,
998910004 );
0 commit comments