* Returns `true` if an export assignment or declaration was produced for the symbol
(symbol)
| 55001 | * Returns `true` if an export assignment or declaration was produced for the symbol |
| 55002 | */ |
| 55003 | function serializeMaybeAliasAssignment(symbol) { |
| 55004 | if (symbol.flags & 4194304 /* SymbolFlags.Prototype */) { |
| 55005 | return false; |
| 55006 | } |
| 55007 | var name = ts.unescapeLeadingUnderscores(symbol.escapedName); |
| 55008 | var isExportEquals = name === "export=" /* InternalSymbolName.ExportEquals */; |
| 55009 | var isDefault = name === "default" /* InternalSymbolName.Default */; |
| 55010 | var isExportAssignmentCompatibleSymbolName = isExportEquals || isDefault; |
| 55011 | // synthesize export = ref |
| 55012 | // ref should refer to either be a locally scoped symbol which we need to emit, or |
| 55013 | // a reference to another namespace/module which we may need to emit an `import` statement for |
| 55014 | var aliasDecl = symbol.declarations && getDeclarationOfAliasSymbol(symbol); |
| 55015 | // serialize what the alias points to, preserve the declaration's initializer |
| 55016 | var target = aliasDecl && getTargetOfAliasDeclaration(aliasDecl, /*dontRecursivelyResolve*/ true); |
| 55017 | // If the target resolves and resolves to a thing defined in this file, emit as an alias, otherwise emit as a const |
| 55018 | if (target && ts.length(target.declarations) && ts.some(target.declarations, function (d) { return ts.getSourceFileOfNode(d) === ts.getSourceFileOfNode(enclosingDeclaration); })) { |
| 55019 | // In case `target` refers to a namespace member, look at the declaration and serialize the leftmost symbol in it |
| 55020 | // eg, `namespace A { export class B {} }; exports = A.B;` |
| 55021 | // Technically, this is all that's required in the case where the assignment is an entity name expression |
| 55022 | var expr = aliasDecl && ((ts.isExportAssignment(aliasDecl) || ts.isBinaryExpression(aliasDecl)) ? ts.getExportAssignmentExpression(aliasDecl) : ts.getPropertyAssignmentAliasLikeExpression(aliasDecl)); |
| 55023 | var first_1 = expr && ts.isEntityNameExpression(expr) ? getFirstNonModuleExportsIdentifier(expr) : undefined; |
| 55024 | var referenced = first_1 && resolveEntityName(first_1, 67108863 /* SymbolFlags.All */, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, enclosingDeclaration); |
| 55025 | if (referenced || target) { |
| 55026 | includePrivateSymbol(referenced || target); |
| 55027 | } |
| 55028 | // We disable the context's symbol tracker for the duration of this name serialization |
| 55029 | // as, by virtue of being here, the name is required to print something, and we don't want to |
| 55030 | // issue a visibility error on it. Only anonymous classes that an alias points at _would_ issue |
| 55031 | // a visibility error here (as they're not visible within any scope), but we want to hoist them |
| 55032 | // into the containing scope anyway, so we want to skip the visibility checks. |
| 55033 | var oldTrack = context.tracker.trackSymbol; |
| 55034 | context.tracker.trackSymbol = function () { return false; }; |
| 55035 | if (isExportAssignmentCompatibleSymbolName) { |
| 55036 | results.push(ts.factory.createExportAssignment( |
| 55037 | /*decorators*/ undefined, |
| 55038 | /*modifiers*/ undefined, isExportEquals, symbolToExpression(target, context, 67108863 /* SymbolFlags.All */))); |
| 55039 | } |
| 55040 | else { |
| 55041 | if (first_1 === expr && first_1) { |
| 55042 | // serialize as `export {target as name}` |
| 55043 | serializeExportSpecifier(name, ts.idText(first_1)); |
| 55044 | } |
| 55045 | else if (expr && ts.isClassExpression(expr)) { |
| 55046 | serializeExportSpecifier(name, getInternalSymbolName(target, ts.symbolName(target))); |
| 55047 | } |
| 55048 | else { |
| 55049 | // serialize as `import _Ref = t.arg.et; export { _Ref as name }` |
| 55050 | var varName = getUnusedName(name, symbol); |
| 55051 | addResult(ts.factory.createImportEqualsDeclaration( |
| 55052 | /*decorators*/ undefined, |
| 55053 | /*modifiers*/ undefined, |
| 55054 | /*isTypeOnly*/ false, ts.factory.createIdentifier(varName), symbolToName(target, context, 67108863 /* SymbolFlags.All */, /*expectsIdentifier*/ false)), 0 /* ModifierFlags.None */); |
| 55055 | serializeExportSpecifier(name, varName); |
| 55056 | } |
| 55057 | } |
| 55058 | context.tracker.trackSymbol = oldTrack; |
| 55059 | return true; |
| 55060 | } |
no test coverage detected
searching dependent graphs…