* Adds an exportStar function to a statement list if it is needed for the file. * * @param statements A statement list.
(statements)
| 106046 | * @param statements A statement list. |
| 106047 | */ |
| 106048 | function addExportStarIfNeeded(statements) { |
| 106049 | if (!moduleInfo.hasExportStarsToExportValues) { |
| 106050 | return; |
| 106051 | } |
| 106052 | // when resolving exports local exported entries/indirect exported entries in the module |
| 106053 | // should always win over entries with similar names that were added via star exports |
| 106054 | // to support this we store names of local/indirect exported entries in a set. |
| 106055 | // this set is used to filter names brought by star expors. |
| 106056 | // local names set should only be added if we have anything exported |
| 106057 | if (!moduleInfo.exportedNames && moduleInfo.exportSpecifiers.size === 0) { |
| 106058 | // no exported declarations (export var ...) or export specifiers (export {x}) |
| 106059 | // check if we have any non star export declarations. |
| 106060 | var hasExportDeclarationWithExportClause = false; |
| 106061 | for (var _i = 0, _a = moduleInfo.externalImports; _i < _a.length; _i++) { |
| 106062 | var externalImport = _a[_i]; |
| 106063 | if (externalImport.kind === 272 /* SyntaxKind.ExportDeclaration */ && externalImport.exportClause) { |
| 106064 | hasExportDeclarationWithExportClause = true; |
| 106065 | break; |
| 106066 | } |
| 106067 | } |
| 106068 | if (!hasExportDeclarationWithExportClause) { |
| 106069 | // we still need to emit exportStar helper |
| 106070 | var exportStarFunction_1 = createExportStarFunction(/*localNames*/ undefined); |
| 106071 | statements.push(exportStarFunction_1); |
| 106072 | return exportStarFunction_1.name; |
| 106073 | } |
| 106074 | } |
| 106075 | var exportedNames = []; |
| 106076 | if (moduleInfo.exportedNames) { |
| 106077 | for (var _b = 0, _c = moduleInfo.exportedNames; _b < _c.length; _b++) { |
| 106078 | var exportedLocalName = _c[_b]; |
| 106079 | if (exportedLocalName.escapedText === "default") { |
| 106080 | continue; |
| 106081 | } |
| 106082 | // write name of exported declaration, i.e 'export var x...' |
| 106083 | exportedNames.push(factory.createPropertyAssignment(factory.createStringLiteralFromNode(exportedLocalName), factory.createTrue())); |
| 106084 | } |
| 106085 | } |
| 106086 | var exportedNamesStorageRef = factory.createUniqueName("exportedNames"); |
| 106087 | statements.push(factory.createVariableStatement( |
| 106088 | /*modifiers*/ undefined, factory.createVariableDeclarationList([ |
| 106089 | factory.createVariableDeclaration(exportedNamesStorageRef, |
| 106090 | /*exclamationToken*/ undefined, |
| 106091 | /*type*/ undefined, factory.createObjectLiteralExpression(exportedNames, /*multiline*/ true)) |
| 106092 | ]))); |
| 106093 | var exportStarFunction = createExportStarFunction(exportedNamesStorageRef); |
| 106094 | statements.push(exportStarFunction); |
| 106095 | return exportStarFunction.name; |
| 106096 | } |
| 106097 | /** |
| 106098 | * Creates an exportStar function for the file, with an optional set of excluded local |
| 106099 | * names. |
no test coverage detected