mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 04:43:37 -05:00
Expose visible to outside import declarations and dynamic imports through emitDts output
This commit is contained in:
@@ -3908,6 +3908,7 @@ namespace ts {
|
||||
const typeParameterNodes = overrideTypeArguments || lookupTypeParameterNodes(chain, 0, context);
|
||||
const specifier = getSpecifierForModuleSymbol(chain[0], context);
|
||||
const lit = createLiteralTypeNode(createLiteral(specifier));
|
||||
if (context.tracker.trackExternalModuleSymbolOfImportTypeNode) context.tracker.trackExternalModuleSymbolOfImportTypeNode(chain[0]);
|
||||
context.approximateLength += specifier.length + 10; // specifier + import("")
|
||||
if (!nonRootParts || isEntityName(nonRootParts)) {
|
||||
if (nonRootParts) {
|
||||
|
||||
@@ -113,6 +113,7 @@ namespace ts {
|
||||
|
||||
let bundleInfo: BundleInfo = createDefaultBundleInfo();
|
||||
let emitSkipped = false;
|
||||
let exportedModulesFromDeclarationEmit: ExportedModulesFromDeclarationEmit | undefined;
|
||||
|
||||
// Emit each output file
|
||||
performance.mark("beforePrint");
|
||||
@@ -125,6 +126,7 @@ namespace ts {
|
||||
diagnostics: emitterDiagnostics.getDiagnostics(),
|
||||
emittedFiles: emittedFilesList,
|
||||
sourceMaps: sourceMapDataList,
|
||||
exportedModulesFromDeclarationEmit
|
||||
};
|
||||
|
||||
function emitSourceFileOrBundle({ jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath }: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle) {
|
||||
@@ -222,6 +224,11 @@ namespace ts {
|
||||
if (!declBlocked || emitOnlyDtsFiles) {
|
||||
Debug.assert(declarationTransform.transformed.length === 1, "Should only see one output from the decl transform");
|
||||
printSourceFileOrBundle(declarationFilePath, declarationMapPath, declarationTransform.transformed[0], /* bundleInfopath*/ undefined, declarationPrinter, declarationSourceMap);
|
||||
if (emitOnlyDtsFiles && declarationTransform.transformed[0].kind === SyntaxKind.SourceFile) {
|
||||
const sourceFile = declarationTransform.transformed[0] as SourceFile;
|
||||
exportedModulesFromDeclarationEmit = sourceFile.getExportedModulesFromDeclarationEmit &&
|
||||
sourceFile.getExportedModulesFromDeclarationEmit();
|
||||
}
|
||||
}
|
||||
declarationTransform.dispose();
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ namespace ts {
|
||||
let lateMarkedStatements: LateVisibilityPaintedStatement[] | undefined;
|
||||
let lateStatementReplacementMap: Map<VisitResult<LateVisibilityPaintedStatement>>;
|
||||
let suppressNewDiagnosticContexts: boolean;
|
||||
let exportedModuleSpecifiers: StringLiteralLike[] | undefined;
|
||||
let exportedModuleSymbolsUsingImportTypeNodes: Symbol[] | undefined;
|
||||
|
||||
const host = context.getEmitHost();
|
||||
const symbolTracker: SymbolTracker = {
|
||||
@@ -46,6 +48,7 @@ namespace ts {
|
||||
reportPrivateInBaseOfClassExpression,
|
||||
moduleResolverHost: host,
|
||||
trackReferencedAmbientModule,
|
||||
trackExternalModuleSymbolOfImportTypeNode
|
||||
};
|
||||
let errorNameNode: DeclarationName | undefined;
|
||||
|
||||
@@ -115,6 +118,12 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function trackExternalModuleSymbolOfImportTypeNode(symbol: Symbol) {
|
||||
if (!isBundledEmit) {
|
||||
(exportedModuleSymbolsUsingImportTypeNodes || (exportedModuleSymbolsUsingImportTypeNodes = [])).push(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) {
|
||||
if (symbol.flags & SymbolFlags.TypeParameter) return;
|
||||
handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning, /*shouldComputeAliasesToMakeVisible*/ true));
|
||||
@@ -224,6 +233,12 @@ namespace ts {
|
||||
combinedStatements = setTextRange(createNodeArray([...combinedStatements, createExportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, createNamedExports([]), /*moduleSpecifier*/ undefined)]), combinedStatements);
|
||||
}
|
||||
const updated = updateSourceFileNode(node, combinedStatements, /*isDeclarationFile*/ true, references, getFileReferencesForUsedTypeReferences(), node.hasNoDefaultLib);
|
||||
if (exportedModuleSpecifiers || exportedModuleSymbolsUsingImportTypeNodes) {
|
||||
updated.getExportedModulesFromDeclarationEmit = () => ({
|
||||
exportedModuleSpecifiers: exportedModuleSpecifiers || emptyArray,
|
||||
exportedModuleSymbolsUsingImportTypeNodes: exportedModuleSymbolsUsingImportTypeNodes || emptyArray
|
||||
});
|
||||
}
|
||||
return updated;
|
||||
|
||||
function getFileReferencesForUsedTypeReferences() {
|
||||
@@ -483,10 +498,15 @@ namespace ts {
|
||||
function rewriteModuleSpecifier<T extends Node>(parent: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode, input: T | undefined): T | StringLiteral {
|
||||
if (!input) return undefined!; // TODO: GH#18217
|
||||
resultHasExternalModuleIndicator = resultHasExternalModuleIndicator || (parent.kind !== SyntaxKind.ModuleDeclaration && parent.kind !== SyntaxKind.ImportType);
|
||||
if (input.kind === SyntaxKind.StringLiteral && isBundledEmit) {
|
||||
const newName = getExternalModuleNameFromDeclaration(context.getEmitHost(), resolver, parent);
|
||||
if (newName) {
|
||||
return createLiteral(newName);
|
||||
if (isStringLiteralLike(input)) {
|
||||
if (isBundledEmit) {
|
||||
const newName = getExternalModuleNameFromDeclaration(context.getEmitHost(), resolver, parent);
|
||||
if (newName) {
|
||||
return createLiteral(newName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
(exportedModuleSpecifiers || (exportedModuleSpecifiers = [])).push(input);
|
||||
}
|
||||
}
|
||||
return input;
|
||||
|
||||
@@ -2624,6 +2624,14 @@ namespace ts {
|
||||
/* @internal */ pragmas: PragmaMap;
|
||||
/* @internal */ localJsxNamespace?: __String;
|
||||
/* @internal */ localJsxFactory?: EntityName;
|
||||
|
||||
/*@internal*/ getExportedModulesFromDeclarationEmit?(): ExportedModulesFromDeclarationEmit;
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
export interface ExportedModulesFromDeclarationEmit {
|
||||
exportedModuleSpecifiers: ReadonlyArray<StringLiteralLike>;
|
||||
exportedModuleSymbolsUsingImportTypeNodes: ReadonlyArray<Symbol>;
|
||||
}
|
||||
|
||||
export interface Bundle extends Node {
|
||||
@@ -2866,6 +2874,7 @@ namespace ts {
|
||||
diagnostics: ReadonlyArray<Diagnostic>;
|
||||
emittedFiles?: string[]; // Array of files the compiler wrote to disk
|
||||
/* @internal */ sourceMaps?: SourceMapData[]; // Array of sourceMapData if compiler emitted sourcemaps
|
||||
/* @internal */ exportedModulesFromDeclarationEmit?: ExportedModulesFromDeclarationEmit;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
@@ -5324,6 +5333,7 @@ namespace ts {
|
||||
reportInaccessibleUniqueSymbolError?(): void;
|
||||
moduleResolverHost?: ModuleSpecifierResolutionHost;
|
||||
trackReferencedAmbientModule?(decl: ModuleDeclaration, symbol: Symbol): void;
|
||||
trackExternalModuleSymbolOfImportTypeNode?(symbol: Symbol): void;
|
||||
}
|
||||
|
||||
export interface TextSpan {
|
||||
|
||||
Reference in New Issue
Block a user