(symbol, localName, modifierFlags)
| 54845 | }); |
| 54846 | } |
| 54847 | function serializeAsAlias(symbol, localName, modifierFlags) { |
| 54848 | var _a, _b, _c, _d, _e; |
| 54849 | // synthesize an alias, eg `export { symbolName as Name }` |
| 54850 | // need to mark the alias `symbol` points at |
| 54851 | // as something we need to serialize as a private declaration as well |
| 54852 | var node = getDeclarationOfAliasSymbol(symbol); |
| 54853 | if (!node) |
| 54854 | return ts.Debug.fail(); |
| 54855 | var target = getMergedSymbol(getTargetOfAliasDeclaration(node, /*dontRecursivelyResolve*/ true)); |
| 54856 | if (!target) { |
| 54857 | return; |
| 54858 | } |
| 54859 | // If `target` refers to a shorthand module symbol, the name we're trying to pull out isn;t recoverable from the target symbol |
| 54860 | // In such a scenario, we must fall back to looking for an alias declaration on `symbol` and pulling the target name from that |
| 54861 | var verbatimTargetName = ts.isShorthandAmbientModuleSymbol(target) && getSomeTargetNameFromDeclarations(symbol.declarations) || ts.unescapeLeadingUnderscores(target.escapedName); |
| 54862 | if (verbatimTargetName === "export=" /* InternalSymbolName.ExportEquals */ && (ts.getESModuleInterop(compilerOptions) || compilerOptions.allowSyntheticDefaultImports)) { |
| 54863 | // target refers to an `export=` symbol that was hoisted into a synthetic default - rename here to match |
| 54864 | verbatimTargetName = "default" /* InternalSymbolName.Default */; |
| 54865 | } |
| 54866 | var targetName = getInternalSymbolName(target, verbatimTargetName); |
| 54867 | includePrivateSymbol(target); // the target may be within the same scope - attempt to serialize it first |
| 54868 | switch (node.kind) { |
| 54869 | case 203 /* SyntaxKind.BindingElement */: |
| 54870 | if (((_b = (_a = node.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.kind) === 254 /* SyntaxKind.VariableDeclaration */) { |
| 54871 | // const { SomeClass } = require('./lib'); |
| 54872 | var specifier_1 = getSpecifierForModuleSymbol(target.parent || target, context); // './lib' |
| 54873 | var propertyName = node.propertyName; |
| 54874 | addResult(ts.factory.createImportDeclaration( |
| 54875 | /*decorators*/ undefined, |
| 54876 | /*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, ts.factory.createNamedImports([ts.factory.createImportSpecifier( |
| 54877 | /*isTypeOnly*/ false, propertyName && ts.isIdentifier(propertyName) ? ts.factory.createIdentifier(ts.idText(propertyName)) : undefined, ts.factory.createIdentifier(localName))])), ts.factory.createStringLiteral(specifier_1), |
| 54878 | /*importClause*/ undefined), 0 /* ModifierFlags.None */); |
| 54879 | break; |
| 54880 | } |
| 54881 | // We don't know how to serialize this (nested?) binding element |
| 54882 | ts.Debug.failBadSyntaxKind(((_c = node.parent) === null || _c === void 0 ? void 0 : _c.parent) || node, "Unhandled binding element grandparent kind in declaration serialization"); |
| 54883 | break; |
| 54884 | case 297 /* SyntaxKind.ShorthandPropertyAssignment */: |
| 54885 | if (((_e = (_d = node.parent) === null || _d === void 0 ? void 0 : _d.parent) === null || _e === void 0 ? void 0 : _e.kind) === 221 /* SyntaxKind.BinaryExpression */) { |
| 54886 | // module.exports = { SomeClass } |
| 54887 | serializeExportSpecifier(ts.unescapeLeadingUnderscores(symbol.escapedName), targetName); |
| 54888 | } |
| 54889 | break; |
| 54890 | case 254 /* SyntaxKind.VariableDeclaration */: |
| 54891 | // commonjs require: const x = require('y') |
| 54892 | if (ts.isPropertyAccessExpression(node.initializer)) { |
| 54893 | // const x = require('y').z |
| 54894 | var initializer = node.initializer; // require('y').z |
| 54895 | var uniqueName = ts.factory.createUniqueName(localName); // _x |
| 54896 | var specifier_2 = getSpecifierForModuleSymbol(target.parent || target, context); // 'y' |
| 54897 | // import _x = require('y'); |
| 54898 | addResult(ts.factory.createImportEqualsDeclaration( |
| 54899 | /*decorators*/ undefined, |
| 54900 | /*modifiers*/ undefined, |
| 54901 | /*isTypeOnly*/ false, uniqueName, ts.factory.createExternalModuleReference(ts.factory.createStringLiteral(specifier_2))), 0 /* ModifierFlags.None */); |
| 54902 | // import x = _x.z |
| 54903 | addResult(ts.factory.createImportEqualsDeclaration( |
| 54904 | /*decorators*/ undefined, |
no test coverage detected