| 54678 | return signature.declaration; |
| 54679 | } |
| 54680 | function serializeAsNamespaceDeclaration(props, localName, modifierFlags, suppressNewPrivateContext) { |
| 54681 | if (ts.length(props)) { |
| 54682 | var localVsRemoteMap = ts.arrayToMultiMap(props, function (p) { |
| 54683 | return !ts.length(p.declarations) || ts.some(p.declarations, function (d) { |
| 54684 | return ts.getSourceFileOfNode(d) === ts.getSourceFileOfNode(context.enclosingDeclaration); |
| 54685 | }) ? "local" : "remote"; |
| 54686 | }); |
| 54687 | var localProps = localVsRemoteMap.get("local") || ts.emptyArray; |
| 54688 | // handle remote props first - we need to make an `import` declaration that points at the module containing each remote |
| 54689 | // prop in the outermost scope (TODO: a namespace within a namespace would need to be appropriately handled by this) |
| 54690 | // Example: |
| 54691 | // import Foo_1 = require("./exporter"); |
| 54692 | // export namespace ns { |
| 54693 | // import Foo = Foo_1.Foo; |
| 54694 | // export { Foo }; |
| 54695 | // export const c: number; |
| 54696 | // } |
| 54697 | // This is needed because in JS, statements like `const x = require("./f")` support both type and value lookup, even if they're |
| 54698 | // normally just value lookup (so it functions kinda like an alias even when it's not an alias) |
| 54699 | // _Usually_, we'll simply print the top-level as an alias instead of a `var` in such situations, however is is theoretically |
| 54700 | // possible to encounter a situation where a type has members from both the current file and other files - in those situations, |
| 54701 | // emit akin to the above would be needed. |
| 54702 | // Add a namespace |
| 54703 | // Create namespace as non-synthetic so it is usable as an enclosing declaration |
| 54704 | var fakespace = ts.parseNodeFactory.createModuleDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, ts.factory.createIdentifier(localName), ts.factory.createModuleBlock([]), 16 /* NodeFlags.Namespace */); |
| 54705 | ts.setParent(fakespace, enclosingDeclaration); |
| 54706 | fakespace.locals = ts.createSymbolTable(props); |
| 54707 | fakespace.symbol = props[0].parent; |
| 54708 | var oldResults = results; |
| 54709 | results = []; |
| 54710 | var oldAddingDeclare = addingDeclare; |
| 54711 | addingDeclare = false; |
| 54712 | var subcontext = __assign(__assign({}, context), { enclosingDeclaration: fakespace }); |
| 54713 | var oldContext = context; |
| 54714 | context = subcontext; |
| 54715 | // TODO: implement handling for the localVsRemoteMap.get("remote") - should be difficult to trigger (see comment above), as only interesting cross-file js merges should make this possible |
| 54716 | visitSymbolTable(ts.createSymbolTable(localProps), suppressNewPrivateContext, /*propertyAsAlias*/ true); |
| 54717 | context = oldContext; |
| 54718 | addingDeclare = oldAddingDeclare; |
| 54719 | var declarations = results; |
| 54720 | results = oldResults; |
| 54721 | // replace namespace with synthetic version |
| 54722 | var defaultReplaced = ts.map(declarations, function (d) { return ts.isExportAssignment(d) && !d.isExportEquals && ts.isIdentifier(d.expression) ? ts.factory.createExportDeclaration( |
| 54723 | /*decorators*/ undefined, |
| 54724 | /*modifiers*/ undefined, |
| 54725 | /*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, d.expression, ts.factory.createIdentifier("default" /* InternalSymbolName.Default */))])) : d; }); |
| 54726 | var exportModifierStripped = ts.every(defaultReplaced, function (d) { return ts.hasSyntacticModifier(d, 1 /* ModifierFlags.Export */); }) ? ts.map(defaultReplaced, removeExportModifier) : defaultReplaced; |
| 54727 | fakespace = ts.factory.updateModuleDeclaration(fakespace, fakespace.decorators, fakespace.modifiers, fakespace.name, ts.factory.createModuleBlock(exportModifierStripped)); |
| 54728 | addResult(fakespace, modifierFlags); // namespaces can never be default exported |
| 54729 | } |
| 54730 | } |
| 54731 | function isNamespaceMember(p) { |
| 54732 | return !!(p.flags & (788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */)) || |
| 54733 | !(p.flags & 4194304 /* SymbolFlags.Prototype */ || p.escapedName === "prototype" || p.valueDeclaration && ts.isStatic(p.valueDeclaration) && ts.isClassLike(p.valueDeclaration.parent)); |