| 54171 | return ts.filter([ts.getNameOfDeclaration(statement)], isIdentifierAndNotUndefined); |
| 54172 | } |
| 54173 | function flattenExportAssignedNamespace(statements) { |
| 54174 | var exportAssignment = ts.find(statements, ts.isExportAssignment); |
| 54175 | var nsIndex = ts.findIndex(statements, ts.isModuleDeclaration); |
| 54176 | var ns = nsIndex !== -1 ? statements[nsIndex] : undefined; |
| 54177 | if (ns && exportAssignment && exportAssignment.isExportEquals && |
| 54178 | ts.isIdentifier(exportAssignment.expression) && ts.isIdentifier(ns.name) && ts.idText(ns.name) === ts.idText(exportAssignment.expression) && |
| 54179 | ns.body && ts.isModuleBlock(ns.body)) { |
| 54180 | // Pass 0: Correct situations where a module has both an `export = ns` and multiple top-level exports by stripping the export modifiers from |
| 54181 | // the top-level exports and exporting them in the targeted ns, as can occur when a js file has both typedefs and `module.export` assignments |
| 54182 | var excessExports = ts.filter(statements, function (s) { return !!(ts.getEffectiveModifierFlags(s) & 1 /* ModifierFlags.Export */); }); |
| 54183 | var name_3 = ns.name; |
| 54184 | var body = ns.body; |
| 54185 | if (ts.length(excessExports)) { |
| 54186 | ns = ts.factory.updateModuleDeclaration(ns, ns.decorators, ns.modifiers, ns.name, body = ts.factory.updateModuleBlock(body, ts.factory.createNodeArray(__spreadArray(__spreadArray([], ns.body.statements, true), [ts.factory.createExportDeclaration( |
| 54187 | /*decorators*/ undefined, |
| 54188 | /*modifiers*/ undefined, |
| 54189 | /*isTypeOnly*/ false, ts.factory.createNamedExports(ts.map(ts.flatMap(excessExports, function (e) { return getNamesOfDeclaration(e); }), function (id) { return ts.factory.createExportSpecifier(/*isTypeOnly*/ false, /*alias*/ undefined, id); })), |
| 54190 | /*moduleSpecifier*/ undefined)], false)))); |
| 54191 | statements = __spreadArray(__spreadArray(__spreadArray([], statements.slice(0, nsIndex), true), [ns], false), statements.slice(nsIndex + 1), true); |
| 54192 | } |
| 54193 | // Pass 1: Flatten `export namespace _exports {} export = _exports;` so long as the `export=` only points at a single namespace declaration |
| 54194 | if (!ts.find(statements, function (s) { return s !== ns && ts.nodeHasName(s, name_3); })) { |
| 54195 | results = []; |
| 54196 | // If the namespace contains no export assignments or declarations, and no declarations flagged with `export`, then _everything_ is exported - |
| 54197 | // to respect this as the top level, we need to add an `export` modifier to everything |
| 54198 | var mixinExportFlag_1 = !ts.some(body.statements, function (s) { return ts.hasSyntacticModifier(s, 1 /* ModifierFlags.Export */) || ts.isExportAssignment(s) || ts.isExportDeclaration(s); }); |
| 54199 | ts.forEach(body.statements, function (s) { |
| 54200 | addResult(s, mixinExportFlag_1 ? 1 /* ModifierFlags.Export */ : 0 /* ModifierFlags.None */); // Recalculates the ambient (and export, if applicable from above) flag |
| 54201 | }); |
| 54202 | statements = __spreadArray(__spreadArray([], ts.filter(statements, function (s) { return s !== ns && s !== exportAssignment; }), true), results, true); |
| 54203 | } |
| 54204 | } |
| 54205 | return statements; |
| 54206 | } |
| 54207 | function mergeExportDeclarations(statements) { |
| 54208 | // Pass 2: Combine all `export {}` declarations |
| 54209 | var exports = ts.filter(statements, function (d) { return ts.isExportDeclaration(d) && !d.moduleSpecifier && !!d.exportClause && ts.isNamedExports(d.exportClause); }); |