From 23ae8aeee266e8e25c0662487b9bf60dbc7eb012 Mon Sep 17 00:00:00 2001
From: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
Date: Thu, 7 Mar 2024 11:11:27 -0800
Subject: [PATCH 01/16] Do not perserve references in declaration emit, unless
preserve=true
---
src/compiler/checker.ts | 104 ---------
src/compiler/emitter.ts | 14 +-
src/compiler/parser.ts | 9 +-
src/compiler/program.ts | 1 -
src/compiler/transformers/declarations.ts | 170 +++++---------
src/compiler/types.ts | 7 +-
.../reference/amdLikeInputDeclarationEmit.js | 1 -
tests/baselines/reference/api/typescript.d.ts | 1 +
.../reference/commonSourceDirectory.js | 1 -
.../reference/commonSourceDirectory_dts.js | 1 -
...tExternalModuleWithSingleExportedModule.js | 25 ++-
...eclFileWithErrorsInInputDeclarationFile.js | 1 -
...WithErrorsInInputDeclarationFileWithOut.js | 1 -
...larationEmitBundleWithAmbientReferences.js | 1 -
...nEmitCrossFileImportTypeOfAmbientModule.js | 1 -
...nedNamespaceNoTripleSlashTypesReference.js | 1 -
...eclarationEmitHasTypesRefOnNamespaceUse.js | 1 -
.../declarationEmitPathMappingMonorepo.js | 1 -
...onEmitTripleSlashReferenceAmbientModule.js | 3 -
...eclarationFilesGeneratingTypeReferences.js | 22 --
.../declarationFilesWithTypeReferences2.js | 1 -
.../declarationFilesWithTypeReferences3.js | 1 -
...ipleSlashAvoidUnnecessaryResolutionMode.js | 39 +++-
.../reference/importAliasFromNamespace.js | 1 -
tests/baselines/reference/importDecl.js | 2 -
...importTypeGenericArrowTypeParenthesized.js | 1 -
.../jsDeclarationsReactComponents.js | 93 +++++++-
.../reference/jsDeclarationsTypeReferences.js | 1 -
.../jsDeclarationsTypeReferences3.js | 1 -
.../jsDeclarationsTypeReferences4.js | 1 -
...eclarationsWithJsFileReferenceWithNoOut.js | 1 -
...clarationsWithJsFileReferenceWithOutDir.js | 1 -
...xDeclarationsWithEsModuleInteropNoCrash.js | 32 ++-
.../reference/libReferenceDeclarationEmit.js | 18 +-
.../libReferenceDeclarationEmitBundle.js | 19 +-
.../missingImportAfterModuleImport.js | 29 ++-
.../moduleAugmentationExtendAmbientModule2.js | 1 -
.../reference/moduleAugmentationGlobal5.js | 2 -
.../moduleAugmentationInAmbientModule1.js | 1 -
.../moduleAugmentationInAmbientModule5.js | 1 -
.../reference/moduleAugmentationsImports1.js | 1 -
.../reference/moduleAugmentationsImports2.js | 1 -
.../reference/moduleAugmentationsImports3.js | 51 ++++-
.../reference/moduleAugmentationsImports4.js | 2 -
.../reference/moduleSymbolMerging.js | 23 +-
...sAllowJsImportAssignment(module=node16).js | 3 -
...llowJsImportAssignment(module=nodenext).js | 3 -
...ImportHelpersCollisions2(module=node16).js | 2 -
...portHelpersCollisions2(module=nodenext).js | 2 -
...ModulesImportAssignments(module=node16).js | 3 -
...dulesImportAssignments(module=nodenext).js | 3 -
...ImportHelpersCollisions2(module=node16).js | 2 -
...portHelpersCollisions2(module=nodenext).js | 2 -
...ImportHelpersCollisions3(module=node16).js | 2 -
...portHelpersCollisions3(module=nodenext).js | 2 -
...enceModeDeclarationEmit1(module=node16).js | 34 ++-
...ceModeDeclarationEmit1(module=nodenext).js | 34 ++-
...enceModeDeclarationEmit2(module=node16).js | 39 +++-
...ceModeDeclarationEmit2(module=nodenext).js | 39 +++-
...enceModeDeclarationEmit3(module=node16).js | 39 +++-
...ceModeDeclarationEmit3(module=nodenext).js | 39 +++-
...enceModeDeclarationEmit4(module=node16).js | 34 ++-
...ceModeDeclarationEmit4(module=nodenext).js | 34 ++-
...enceModeDeclarationEmit5(module=node16).js | 38 +++-
...ceModeDeclarationEmit5(module=nodenext).js | 38 +++-
...enceModeDeclarationEmit6(module=node16).js | 41 +++-
...ceModeDeclarationEmit6(module=nodenext).js | 41 +++-
...enceModeDeclarationEmit7(module=node16).js | 65 +++++-
...ceModeDeclarationEmit7(module=nodenext).js | 65 +++++-
.../reference/outModuleTripleSlashRefs.js | 1 -
.../privacyCannotNameAccessorDeclFile.js | 73 +++++-
.../privacyCannotNameVarTypeDeclFile.js | 83 ++++++-
...FunctionCannotNameParameterTypeDeclFile.js | 123 +++++++++-
...acyFunctionCannotNameReturnTypeDeclFile.js | 83 ++++++-
...elAmbientExternalModuleImportWithExport.js | 2 -
...mbientExternalModuleImportWithoutExport.js | 2 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../amd/outdir/simple/test.d.ts | 2 -
.../node/outdir/simple/test.d.ts | 2 -
.../node/bin/test.d.ts | 1 -
.../node/bin/outAndOutDirFile.d.ts | 1 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../amd/test.d.ts | 1 -
.../node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../amd/test.d.ts | 1 -
.../node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../amd/outdir/simple/test.d.ts | 2 -
.../node/outdir/simple/test.d.ts | 2 -
.../node/bin/test.d.ts | 1 -
.../node/bin/outAndOutDirFile.d.ts | 1 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../amd/test.d.ts | 1 -
.../node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../amd/test.d.ts | 1 -
.../node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../amd/outdir/simple/test.d.ts | 2 -
.../node/outdir/simple/test.d.ts | 2 -
.../node/bin/test.d.ts | 1 -
.../node/bin/outAndOutDirFile.d.ts | 1 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../maprootUrlSimpleNoOutdir/amd/test.d.ts | 1 -
.../maprootUrlSimpleNoOutdir/node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../maprootUrlSubfolderNoOutdir/amd/test.d.ts | 1 -
.../node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../amd/outdir/simple/test.d.ts | 2 -
.../node/outdir/simple/test.d.ts | 2 -
.../node/bin/test.d.ts | 1 -
.../node/bin/outAndOutDirFile.d.ts | 1 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../amd/test.d.ts | 1 -
.../node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../amd/test.d.ts | 1 -
.../node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../outMixedSubfolderNoOutdir/amd/test.d.ts | 2 -
.../outMixedSubfolderNoOutdir/node/test.d.ts | 2 -
.../amd/outdir/simple/test.d.ts | 2 -
.../node/outdir/simple/test.d.ts | 2 -
.../node/bin/test.d.ts | 1 -
.../node/bin/outAndOutDirFile.d.ts | 1 -
.../outMultifolderNoOutdir/amd/test.d.ts | 2 -
.../outMultifolderNoOutdir/node/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../project/outSimpleNoOutdir/amd/test.d.ts | 1 -
.../project/outSimpleNoOutdir/node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../outSubfolderNoOutdir/amd/test.d.ts | 1 -
.../outSubfolderNoOutdir/node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../amd/m'ain.d.ts | 1 -
.../node/m'ain.d.ts | 1 -
.../amd/diskFile1.d.ts | 1 -
.../amd/foo.d.ts | 1 -
.../node/diskFile1.d.ts | 1 -
.../node/foo.d.ts | 1 -
.../amd/bar/bar.d.ts | 1 -
.../amd/src/ts/foo/foo.d.ts | 1 -
.../node/bar/bar.d.ts | 1 -
.../node/src/ts/foo/foo.d.ts | 1 -
.../amd/diskFile1.d.ts | 1 -
.../amd/foo.d.ts | 1 -
.../node/diskFile1.d.ts | 1 -
.../node/foo.d.ts | 1 -
.../amd/outdir/simple/FolderB/fileB.d.ts | 1 -
.../node/outdir/simple/FolderB/fileB.d.ts | 1 -
.../amd/FolderA/FolderB/fileB.d.ts | 1 -
.../node/FolderA/FolderB/fileB.d.ts | 1 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../amd/outdir/simple/test.d.ts | 2 -
.../node/outdir/simple/test.d.ts | 2 -
.../node/bin/test.d.ts | 1 -
.../node/bin/outAndOutDirFile.d.ts | 1 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../amd/test.d.ts | 1 -
.../node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../amd/test.d.ts | 1 -
.../node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../amd/outdir/simple/test.d.ts | 2 -
.../node/outdir/simple/test.d.ts | 2 -
.../node/bin/test.d.ts | 1 -
.../node/bin/outAndOutDirFile.d.ts | 1 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../amd/test.d.ts | 1 -
.../node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../amd/test.d.ts | 1 -
.../node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../amd/outdir/simple/test.d.ts | 2 -
.../node/outdir/simple/test.d.ts | 2 -
.../node/bin/test.d.ts | 1 -
.../node/bin/outAndOutDirFile.d.ts | 1 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../sourcemapSimpleNoOutdir/amd/test.d.ts | 1 -
.../sourcemapSimpleNoOutdir/node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../sourcemapSubfolderNoOutdir/amd/test.d.ts | 1 -
.../sourcemapSubfolderNoOutdir/node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../amd/outdir/simple/test.d.ts | 2 -
.../node/outdir/simple/test.d.ts | 2 -
.../node/bin/test.d.ts | 1 -
.../node/bin/outAndOutDirFile.d.ts | 1 -
.../amd/test.d.ts | 2 -
.../node/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../simple/outputdir_multifolder/test.d.ts | 2 -
.../sourcerootUrlSimpleNoOutdir/amd/test.d.ts | 1 -
.../node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
.../amd/test.d.ts | 1 -
.../node/test.d.ts | 1 -
.../amd/outdir/simple/test.d.ts | 1 -
.../node/outdir/simple/test.d.ts | 1 -
...eactTransitiveImportHasValidDeclaration.js | 1 -
.../referenceTypesPreferedToPathIfPossible.js | 1 -
...ugh-triple-slash-but-uses-no-references.js | 9 +-
...file-is-referenced-through-triple-slash.js | 212 ++++--------------
.../with-config-with-redirection.js | 11 +-
.../tsbuild/libraryResolution/with-config.js | 11 +-
...t-resolution-options-referenced-project.js | 18 +-
.../with-config-with-redirection.js | 11 +-
.../libraryResolution/with-config.js | 11 +-
...le-is-added,-the-signatures-are-updated.js | 99 ++++----
.../with-config-with-redirection.js | 11 +-
.../tsc/libraryResolution/with-config.js | 11 +-
.../with-config-with-redirection.js | 67 +++---
.../tscWatch/libraryResolution/with-config.js | 67 +++---
.../reference/typeReferenceDirectives1.js | 1 -
.../reference/typeReferenceDirectives13.js | 1 -
.../reference/typeReferenceDirectives2.js | 1 -
.../reference/typeReferenceDirectives3.js | 22 +-
.../reference/typeReferenceDirectives4.js | 25 ++-
.../reference/typeReferenceDirectives5.js | 1 -
.../reference/typeReferenceDirectives6.js | 2 -
.../reference/typeReferenceDirectives8.js | 2 -
.../reference/typeReferenceDirectives9.js | 2 -
.../reference/typeReferenceRelatedFiles.js | 1 -
tests/baselines/reference/withImportDecl.js | 1 -
281 files changed, 1519 insertions(+), 993 deletions(-)
diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts
index f175b6806551b..626a270c65949 100644
--- a/src/compiler/checker.ts
+++ b/src/compiler/checker.ts
@@ -8006,14 +8006,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return file.moduleName;
}
if (!file) {
- if (context.tracker.trackReferencedAmbientModule) {
- const ambientDecls = filter(symbol.declarations, isAmbientModule);
- if (length(ambientDecls)) {
- for (const decl of ambientDecls!) {
- context.tracker.trackReferencedAmbientModule(decl, symbol);
- }
- }
- }
if (ambientModuleSymbolRegex.test(symbol.escapedName as string)) {
return (symbol.escapedName as string).substring(1, (symbol.escapedName as string).length - 1);
}
@@ -48571,8 +48563,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const node = getParseTreeNode(nodeIn, hasPossibleExternalModuleReference);
return node && getExternalModuleFileFromDeclaration(node);
},
- getTypeReferenceDirectivesForEntityName,
- getTypeReferenceDirectivesForSymbol,
isLiteralConstDeclaration,
isLateBound: (nodeIn: Declaration): nodeIn is LateBoundDeclaration => {
const node = getParseTreeNode(nodeIn, isDeclaration);
@@ -48642,93 +48632,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return false;
}
- function isInHeritageClause(node: PropertyAccessEntityNameExpression) {
- return node.parent && node.parent.kind === SyntaxKind.ExpressionWithTypeArguments && node.parent.parent && node.parent.parent.kind === SyntaxKind.HeritageClause;
- }
-
- // defined here to avoid outer scope pollution
- function getTypeReferenceDirectivesForEntityName(node: EntityNameOrEntityNameExpression): [specifier: string, mode: ResolutionMode][] | undefined {
- // program does not have any files with type reference directives - bail out
- if (!fileToDirective) {
- return undefined;
- }
- // computed property name should use node as value
- // property access can only be used as values, or types when within an expression with type arguments inside a heritage clause
- // qualified names can only be used as types\namespaces
- // identifiers are treated as values only if they appear in type queries
- let meaning;
- if (node.parent.kind === SyntaxKind.ComputedPropertyName) {
- meaning = SymbolFlags.Value | SymbolFlags.ExportValue;
- }
- else {
- meaning = SymbolFlags.Type | SymbolFlags.Namespace;
- if ((node.kind === SyntaxKind.Identifier && isInTypeQuery(node)) || (node.kind === SyntaxKind.PropertyAccessExpression && !isInHeritageClause(node))) {
- meaning = SymbolFlags.Value | SymbolFlags.ExportValue;
- }
- }
-
- const symbol = resolveEntityName(node, meaning, /*ignoreErrors*/ true);
- return symbol && symbol !== unknownSymbol ? getTypeReferenceDirectivesForSymbol(symbol, meaning) : undefined;
- }
-
- // defined here to avoid outer scope pollution
- function getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): [specifier: string, mode: ResolutionMode][] | undefined {
- // program does not have any files with type reference directives - bail out
- if (!fileToDirective || !isSymbolFromTypeDeclarationFile(symbol)) {
- return undefined;
- }
- // check what declarations in the symbol can contribute to the target meaning
- let typeReferenceDirectives: [specifier: string, mode: ResolutionMode][] | undefined;
- for (const decl of symbol.declarations!) {
- // check meaning of the local symbol to see if declaration needs to be analyzed further
- if (decl.symbol && decl.symbol.flags & meaning!) {
- const file = getSourceFileOfNode(decl);
- const typeReferenceDirective = fileToDirective.get(file.path);
- if (typeReferenceDirective) {
- (typeReferenceDirectives || (typeReferenceDirectives = [])).push(typeReferenceDirective);
- }
- else {
- // found at least one entry that does not originate from type reference directive
- return undefined;
- }
- }
- }
- return typeReferenceDirectives;
- }
-
- function isSymbolFromTypeDeclarationFile(symbol: Symbol): boolean {
- // bail out if symbol does not have associated declarations (i.e. this is transient symbol created for property in binding pattern)
- if (!symbol.declarations) {
- return false;
- }
-
- // walk the parent chain for symbols to make sure that top level parent symbol is in the global scope
- // external modules cannot define or contribute to type declaration files
- let current = symbol;
- while (true) {
- const parent = getParentOfSymbol(current);
- if (parent) {
- current = parent;
- }
- else {
- break;
- }
- }
-
- if (current.valueDeclaration && current.valueDeclaration.kind === SyntaxKind.SourceFile && current.flags & SymbolFlags.ValueModule) {
- return false;
- }
-
- // check that at least one declaration of top level symbol originates from type declaration file
- for (const decl of symbol.declarations) {
- const file = getSourceFileOfNode(decl);
- if (fileToDirective.has(file.path)) {
- return true;
- }
- }
- return false;
- }
-
function addReferencedFilesToTypeDirective(file: SourceFile, key: string, mode: ResolutionMode) {
if (fileToDirective.has(file.path)) return;
fileToDirective.set(file.path, [key, mode]);
@@ -51106,13 +51009,6 @@ class SymbolTrackerImpl implements SymbolTracker {
}
}
- trackReferencedAmbientModule(decl: ModuleDeclaration, symbol: Symbol): void {
- if (this.inner?.trackReferencedAmbientModule) {
- this.onDiagnosticReported();
- this.inner.trackReferencedAmbientModule(decl, symbol);
- }
- }
-
trackExternalModuleSymbolOfImportTypeNode(symbol: Symbol): void {
if (this.inner?.trackExternalModuleSymbolOfImportTypeNode) {
this.onDiagnosticReported();
diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts
index 1abd8cdf05c31..232c0f9440d6a 100644
--- a/src/compiler/emitter.ts
+++ b/src/compiler/emitter.ts
@@ -1109,8 +1109,6 @@ export const notImplementedResolver: EmitResolver = {
moduleExportsSomeValue: notImplemented,
isArgumentsLocalBinding: notImplemented,
getExternalModuleFileFromDeclaration: notImplemented,
- getTypeReferenceDirectivesForEntityName: notImplemented,
- getTypeReferenceDirectivesForSymbol: notImplemented,
isLiteralConstDeclaration: notImplemented,
getJsxFactoryEntity: notImplemented,
getJsxFragmentFactoryEntity: notImplemented,
@@ -4185,19 +4183,23 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
writeLine();
}
}
+ // TODO(jakebailey): clean up preserve duplication
for (const directive of files) {
- writeComment(`/// `);
+ const preserve = directive.preserve ? `preserve="true" ` : "";
+ writeComment(`/// `);
writeLine();
}
for (const directive of types) {
+ const preserve = directive.preserve ? `preserve="true" ` : "";
const resolutionMode = directive.resolutionMode && directive.resolutionMode !== currentSourceFile?.impliedNodeFormat
- ? `resolution-mode="${directive.resolutionMode === ModuleKind.ESNext ? "import" : "require"}"`
+ ? `resolution-mode="${directive.resolutionMode === ModuleKind.ESNext ? "import" : "require"}" `
: "";
- writeComment(`/// `);
+ writeComment(`/// `);
writeLine();
}
for (const directive of libs) {
- writeComment(`/// `);
+ const preserve = directive.preserve ? `preserve="true" ` : "";
+ writeComment(`/// `);
writeLine();
}
}
diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts
index eaa8bbef47237..7aba677fccb80 100644
--- a/src/compiler/parser.ts
+++ b/src/compiler/parser.ts
@@ -10510,19 +10510,20 @@ export function processPragmasIntoFields(context: PragmaContext, reportDiagnosti
const typeReferenceDirectives = context.typeReferenceDirectives;
const libReferenceDirectives = context.libReferenceDirectives;
forEach(toArray(entryOrList) as PragmaPseudoMap["reference"][], arg => {
- const { types, lib, path, ["resolution-mode"]: res } = arg.arguments;
+ const { types, lib, path, ["resolution-mode"]: res, preserve: _preserve } = arg.arguments;
+ const preserve = !!_preserve ? true : undefined;
if (arg.arguments["no-default-lib"]) {
context.hasNoDefaultLib = true;
}
else if (types) {
const parsed = parseResolutionMode(res, types.pos, types.end, reportDiagnostic);
- typeReferenceDirectives.push({ pos: types.pos, end: types.end, fileName: types.value, ...(parsed ? { resolutionMode: parsed } : {}) });
+ typeReferenceDirectives.push({ pos: types.pos, end: types.end, fileName: types.value, ...(parsed ? { resolutionMode: parsed } : {}), ...(preserve ? { preserve } : {}) });
}
else if (lib) {
- libReferenceDirectives.push({ pos: lib.pos, end: lib.end, fileName: lib.value });
+ libReferenceDirectives.push({ pos: lib.pos, end: lib.end, fileName: lib.value, ...(preserve ? { preserve } : {}) });
}
else if (path) {
- referencedFiles.push({ pos: path.pos, end: path.end, fileName: path.value });
+ referencedFiles.push({ pos: path.pos, end: path.end, fileName: path.value, ...(preserve ? { preserve } : {}) });
}
else {
reportDiagnostic(arg.range.pos, arg.range.end - arg.range.pos, Diagnostics.Invalid_reference_directive_syntax);
diff --git a/src/compiler/program.ts b/src/compiler/program.ts
index 98aeccc9cf747..80ba1d4a5a23d 100644
--- a/src/compiler/program.ts
+++ b/src/compiler/program.ts
@@ -2630,7 +2630,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
getSourceFile: program.getSourceFile,
getSourceFileByPath: program.getSourceFileByPath,
getSourceFiles: program.getSourceFiles,
- getLibFileFromReference: program.getLibFileFromReference,
isSourceFileFromExternalLibrary,
getResolvedProjectReferenceToRedirect,
getProjectReferenceRedirect,
diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts
index e4163f67d8762..917a80b634120 100644
--- a/src/compiler/transformers/declarations.ts
+++ b/src/compiler/transformers/declarations.ts
@@ -2,7 +2,6 @@ import {
AccessorDeclaration,
addRelatedInfo,
AllAccessorDeclarations,
- AnyImportSyntax,
append,
ArrayBindingElement,
arrayFrom,
@@ -88,7 +87,6 @@ import {
IndexSignatureDeclaration,
InterfaceDeclaration,
isAmbientModule,
- isAnyImportSyntax,
isArray,
isArrayBindingElement,
isBindingElement,
@@ -106,13 +104,11 @@ import {
isExternalModule,
isExternalModuleAugmentation,
isExternalModuleIndicator,
- isExternalModuleReference,
isExternalOrCommonJsModule,
isFunctionDeclaration,
isFunctionLike,
isGlobalScopeAugmentation,
isIdentifierText,
- isImportDeclaration,
isImportEqualsDeclaration,
isIndexSignatureDeclaration,
isInterfaceDeclaration,
@@ -134,7 +130,6 @@ import {
isSourceFileNotJson,
isStatement,
isStringANonContextualKeyword,
- isStringLiteral,
isStringLiteralLike,
isTupleTypeNode,
isTypeAliasDeclaration,
@@ -178,7 +173,6 @@ import {
PropertySignature,
pushIfUnique,
removeAllComments,
- ResolutionMode,
ScriptTarget,
SetAccessorDeclaration,
setCommentRange,
@@ -197,11 +191,9 @@ import {
SymbolFlags,
SymbolTracker,
SyntaxKind,
- toFileNameLowerCase,
TransformationContext,
transformNodes,
tryCast,
- tryGetModuleSpecifierFromDeclaration,
TypeAliasDeclaration,
TypeNode,
TypeParameterDeclaration,
@@ -250,7 +242,6 @@ export function transformDeclarations(context: TransformationContext) {
let needsScopeFixMarker = false;
let resultHasScopeMarker = false;
let enclosingDeclaration: Node;
- let necessaryTypeReferences: Set<[specifier: string, mode: ResolutionMode]> | undefined;
let lateMarkedStatements: LateVisibilityPaintedStatement[] | undefined;
let lateStatementReplacementMap: Map>;
let suppressNewDiagnosticContexts: boolean;
@@ -267,7 +258,6 @@ export function transformDeclarations(context: TransformationContext) {
reportLikelyUnsafeImportRequiredError,
reportTruncationError,
moduleResolverHost: host,
- trackReferencedAmbientModule,
trackExternalModuleSymbolOfImportTypeNode,
reportNonlocalAugmentation,
reportNonSerializableProperty,
@@ -276,47 +266,14 @@ export function transformDeclarations(context: TransformationContext) {
let errorFallbackNode: Declaration | undefined;
let currentSourceFile: SourceFile;
- let refs: Map;
- let libs: Map;
- let emittedImports: readonly AnyImportSyntax[] | undefined; // must be declared in container so it can be `undefined` while transformer's first pass
+ let rawReferencedFiles: Map;
+ let rawTypeReferenceDirectives: Map;
+ let rawLibReferenceDirectives: Map;
const resolver = context.getEmitResolver();
const options = context.getCompilerOptions();
- const { noResolve, stripInternal } = options;
+ const { stripInternal } = options;
return transformRoot;
- function recordTypeReferenceDirectivesIfNecessary(typeReferenceDirectives: readonly [specifier: string, mode: ResolutionMode][] | undefined): void {
- if (!typeReferenceDirectives) {
- return;
- }
- necessaryTypeReferences = necessaryTypeReferences || new Set();
- for (const ref of typeReferenceDirectives) {
- necessaryTypeReferences.add(ref);
- }
- }
-
- function trackReferencedAmbientModule(node: ModuleDeclaration, symbol: Symbol) {
- // If it is visible via `// `, then we should just use that
- const directives = resolver.getTypeReferenceDirectivesForSymbol(symbol, SymbolFlags.All);
- if (length(directives)) {
- return recordTypeReferenceDirectivesIfNecessary(directives);
- }
- // Otherwise we should emit a path-based reference
- const container = getSourceFileOfNode(node);
- refs.set(getOriginalNodeId(container), container);
- }
-
- function trackReferencedAmbientModuleFromImport(node: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration | ImportTypeNode) {
- const moduleSpecifier = tryGetModuleSpecifierFromDeclaration(node);
- const symbol = moduleSpecifier && resolver.tryFindAmbientModule(moduleSpecifier);
- if (symbol?.declarations) {
- for (const decl of symbol.declarations) {
- if (isAmbientModule(decl) && getSourceFileOfNode(decl) !== currentSourceFile) {
- trackReferencedAmbientModule(decl, symbol);
- }
- }
- }
- }
-
function handleSymbolAccessibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) {
if (symbolAccessibilityResult.accessibility === SymbolAccessibility.Accessible) {
// Add aliases back onto the possible imports list if they're not there so we can try them again with updated visibility info
@@ -357,7 +314,6 @@ export function transformDeclarations(context: TransformationContext) {
function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) {
if (symbol.flags & SymbolFlags.TypeParameter) return false;
const issuedDiagnostic = handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning, /*shouldComputeAliasToMarkVisible*/ true));
- recordTypeReferenceDirectivesIfNecessary(resolver.getTypeReferenceDirectivesForSymbol(symbol, meaning));
return issuedDiagnostic;
}
@@ -448,8 +404,9 @@ export function transformDeclarations(context: TransformationContext) {
if (node.kind === SyntaxKind.Bundle) {
isBundledEmit = true;
- refs = new Map();
- libs = new Map();
+ rawReferencedFiles = new Map();
+ rawTypeReferenceDirectives = new Map();
+ rawLibReferenceDirectives = new Map();
let hasNoDefaultLib = false;
const bundle = factory.createBundle(
map(node.sourceFiles, sourceFile => {
@@ -463,8 +420,9 @@ export function transformDeclarations(context: TransformationContext) {
getSymbolAccessibilityDiagnostic = throwDiagnostic;
needsScopeFixMarker = false;
resultHasScopeMarker = false;
- collectReferences(sourceFile, refs);
- collectLibs(sourceFile, libs);
+ collectReferencedFiles(sourceFile, rawReferencedFiles);
+ collectTypeReferenceDirectives(sourceFile, rawTypeReferenceDirectives);
+ collectLibReferenceDirectives(sourceFile, rawLibReferenceDirectives);
if (isExternalOrCommonJsModule(sourceFile) || isJsonSourceFile(sourceFile)) {
resultHasExternalModuleIndicator = false; // unused in external module bundle emit (all external modules are within module blocks, therefore are known to be modules)
needsDeclare = false;
@@ -490,12 +448,13 @@ export function transformDeclarations(context: TransformationContext) {
}),
);
bundle.syntheticFileReferences = [];
- bundle.syntheticTypeReferences = getFileReferencesForUsedTypeReferences();
+ bundle.syntheticTypeReferences = getTypeReferences();
bundle.syntheticLibReferences = getLibReferences();
bundle.hasNoDefaultLib = hasNoDefaultLib;
const outputFilePath = getDirectoryPath(normalizeSlashes(getOutputPathsFor(node, host, /*forceDtsPaths*/ true).declarationFilePath!));
+ // TODO(jakebailey): clean up
const referenceVisitor = mapReferencesIntoArray(bundle.syntheticFileReferences as FileReference[], outputFilePath);
- refs.forEach(referenceVisitor);
+ rawReferencedFiles.forEach(referenceVisitor);
return bundle;
}
@@ -511,64 +470,47 @@ export function transformDeclarations(context: TransformationContext) {
suppressNewDiagnosticContexts = false;
lateMarkedStatements = undefined;
lateStatementReplacementMap = new Map();
- necessaryTypeReferences = undefined;
- refs = collectReferences(currentSourceFile, new Map());
- libs = collectLibs(currentSourceFile, new Map());
- const references: FileReference[] = [];
+ rawReferencedFiles = new Map();
+ rawTypeReferenceDirectives = new Map();
+ rawLibReferenceDirectives = new Map();
+ collectReferencedFiles(currentSourceFile, rawReferencedFiles);
+ collectTypeReferenceDirectives(currentSourceFile, rawTypeReferenceDirectives);
+ collectLibReferenceDirectives(currentSourceFile, rawLibReferenceDirectives);
+ // TODO(jakebailey): simplify
+ const referencedFiles: FileReference[] = [];
const outputFilePath = getDirectoryPath(normalizeSlashes(getOutputPathsFor(node, host, /*forceDtsPaths*/ true).declarationFilePath!));
- const referenceVisitor = mapReferencesIntoArray(references, outputFilePath);
+ const referenceVisitor = mapReferencesIntoArray(referencedFiles, outputFilePath);
let combinedStatements: NodeArray;
if (isSourceFileJS(currentSourceFile)) {
combinedStatements = factory.createNodeArray(transformDeclarationsForJS(node));
- refs.forEach(referenceVisitor);
- emittedImports = filter(combinedStatements, isAnyImportSyntax);
+ rawReferencedFiles.forEach(referenceVisitor);
}
else {
const statements = visitNodes(node.statements, visitDeclarationStatements, isStatement);
combinedStatements = setTextRange(factory.createNodeArray(transformAndReplaceLatePaintedStatements(statements)), node.statements);
- refs.forEach(referenceVisitor);
- emittedImports = filter(combinedStatements, isAnyImportSyntax);
+ rawReferencedFiles.forEach(referenceVisitor);
if (isExternalModule(node) && (!resultHasExternalModuleIndicator || (needsScopeFixMarker && !resultHasScopeMarker))) {
combinedStatements = setTextRange(factory.createNodeArray([...combinedStatements, createEmptyExports(factory)]), combinedStatements);
}
}
- const updated = factory.updateSourceFile(node, combinedStatements, /*isDeclarationFile*/ true, references, getFileReferencesForUsedTypeReferences(), node.hasNoDefaultLib, getLibReferences());
+ const updated = factory.updateSourceFile(node, combinedStatements, /*isDeclarationFile*/ true, referencedFiles, getTypeReferences(), node.hasNoDefaultLib, getLibReferences());
updated.exportedModulesFromDeclarationEmit = exportedModulesFromDeclarationEmit;
return updated;
- function getLibReferences() {
- return arrayFrom(libs.keys(), lib => ({ fileName: lib, pos: -1, end: -1 }));
+ function getTypeReferences(): readonly FileReference[] {
+ // TODO(jakebailey): simplify
+ // TODO(jakebailey): Do we want to keep `preserve`?
+ return arrayFrom(rawTypeReferenceDirectives.keys(), lib => ({ fileName: lib, pos: -1, end: -1, preserve: true }));
}
- function getFileReferencesForUsedTypeReferences() {
- return necessaryTypeReferences ? mapDefined(arrayFrom(necessaryTypeReferences.keys()), getFileReferenceForSpecifierModeTuple) : [];
- }
-
- function getFileReferenceForSpecifierModeTuple([typeName, mode]: [specifier: string, mode: ResolutionMode]): FileReference | undefined {
- // Elide type references for which we have imports
- if (emittedImports) {
- for (const importStatement of emittedImports) {
- if (isImportEqualsDeclaration(importStatement) && isExternalModuleReference(importStatement.moduleReference)) {
- const expr = importStatement.moduleReference.expression;
- if (isStringLiteralLike(expr) && expr.text === typeName) {
- return undefined;
- }
- }
- else if (isImportDeclaration(importStatement) && isStringLiteral(importStatement.moduleSpecifier) && importStatement.moduleSpecifier.text === typeName) {
- return undefined;
- }
- }
- }
- return { fileName: typeName, pos: -1, end: -1, ...(mode ? { resolutionMode: mode } : undefined) };
+ function getLibReferences(): readonly FileReference[] {
+ // TODO(jakebailey): simplify
+ // TODO(jakebailey): Do we want to keep `preserve`?
+ return arrayFrom(rawLibReferenceDirectives.keys(), lib => ({ fileName: lib, pos: -1, end: -1, preserve: true }));
}
function mapReferencesIntoArray(references: FileReference[], outputFilePath: string): (file: SourceFile) => void {
return file => {
- if (exportedModulesFromDeclarationEmit?.includes(file.symbol)) {
- // Already have an import declaration resolving to this file
- return;
- }
-
let declFileName: string;
if (file.isDeclarationFile) { // Neither decl files or js should have their refs changed
declFileName = file.fileName;
@@ -580,6 +522,8 @@ export function transformDeclarations(context: TransformationContext) {
}
if (declFileName) {
+ // TODO(jakebailey): do we need to do any of this anymore?
+
const specifier = moduleSpecifiers.getModuleSpecifier(
options,
currentSourceFile,
@@ -591,7 +535,6 @@ export function transformDeclarations(context: TransformationContext) {
// If some compiler option/symlink/whatever allows access to the file containing the ambient module declaration
// via a non-relative name, emit a type reference directive to that non-relative name, rather than
// a relative path to the declaration file
- recordTypeReferenceDirectivesIfNecessary([[specifier, /*mode*/ undefined]]);
return;
}
@@ -612,31 +555,38 @@ export function transformDeclarations(context: TransformationContext) {
return;
}
- references.push({ pos: -1, end: -1, fileName });
+ // TODO(jakebailey): Do we want to keep `preserve`?
+ references.push({ pos: -1, end: -1, fileName, preserve: true });
}
};
}
}
- function collectReferences(sourceFile: SourceFile, ret: Map) {
- if (noResolve || isSourceFileJS(sourceFile)) return ret;
+ function collectReferencedFiles(sourceFile: SourceFile, ret: Map) {
+ // TODO(jakebailey): simplify
forEach(sourceFile.referencedFiles, f => {
+ if (!f.preserve) return;
const elem = host.getSourceFileFromReference(sourceFile, f);
if (elem) {
ret.set(getOriginalNodeId(elem), elem);
}
});
- return ret;
}
- function collectLibs(sourceFile: SourceFile, ret: Map) {
+ function collectTypeReferenceDirectives(sourceFile: SourceFile, ret: Map) {
+ // TODO(jakebailey): simplify
+ forEach(sourceFile.typeReferenceDirectives, ref => {
+ if (!ref.preserve) return;
+ ret.set(ref.fileName, true);
+ });
+ }
+
+ function collectLibReferenceDirectives(sourceFile: SourceFile, ret: Map) {
+ // TODO(c): simplify
forEach(sourceFile.libReferenceDirectives, ref => {
- const lib = host.getLibFileFromReference(ref);
- if (lib) {
- ret.set(toFileNameLowerCase(ref.fileName), true);
- }
+ if (!ref.preserve) return;
+ ret.set(ref.fileName, true);
});
- return ret;
}
function filterBindingPatternInitializers(name: BindingName) {
@@ -869,7 +819,6 @@ export function transformDeclarations(context: TransformationContext) {
function checkEntityNameVisibility(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node) {
const visibilityResult = resolver.isEntityNameVisible(entityName, enclosingDeclaration);
handleSymbolAccessibilityError(visibilityResult);
- recordTypeReferenceDirectivesIfNecessary(resolver.getTypeReferenceDirectivesForEntityName(entityName));
}
function preserveJsDoc(updated: T, original: Node): T {
@@ -1277,7 +1226,6 @@ export function transformDeclarations(context: TransformationContext) {
}
case SyntaxKind.ImportType: {
if (!isLiteralImportTypeNode(input)) return cleanup(input);
- trackReferencedAmbientModuleFromImport(input);
return cleanup(factory.updateImportTypeNode(
input,
factory.updateLiteralTypeNode(input.argument, rewriteModuleSpecifier(input, input.argument.literal)),
@@ -1335,8 +1283,6 @@ export function transformDeclarations(context: TransformationContext) {
resultHasExternalModuleIndicator = true;
}
resultHasScopeMarker = true;
- // Always visible if the parent node isn't dropped for being not visible
- trackReferencedAmbientModuleFromImport(input);
// Rewrite external module names if necessary
return factory.updateExportDeclaration(
input,
@@ -1423,18 +1369,10 @@ export function transformDeclarations(context: TransformationContext) {
if (shouldStripInternal(input)) return;
switch (input.kind) {
case SyntaxKind.ImportEqualsDeclaration: {
- const transformed = transformImportEqualsDeclaration(input);
- if (transformed) {
- trackReferencedAmbientModuleFromImport(input);
- }
- return transformed;
+ return transformImportEqualsDeclaration(input);
}
case SyntaxKind.ImportDeclaration: {
- const transformed = transformImportDeclaration(input);
- if (transformed) {
- trackReferencedAmbientModuleFromImport(input);
- }
- return transformed;
+ return transformImportDeclaration(input);
}
}
if (isDeclaration(input) && isDeclarationAndNotVisible(input)) return;
diff --git a/src/compiler/types.ts b/src/compiler/types.ts
index bc6d608584359..a5f400b18cdaa 100644
--- a/src/compiler/types.ts
+++ b/src/compiler/types.ts
@@ -3782,6 +3782,7 @@ export interface ExportAssignment extends DeclarationStatement, JSDocContainer {
export interface FileReference extends TextRange {
fileName: string;
resolutionMode?: ResolutionMode;
+ preserve?: boolean;
}
export interface CheckJsDirective extends TextRange {
@@ -5621,8 +5622,6 @@ export interface EmitResolver {
moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean;
isArgumentsLocalBinding(node: Identifier): boolean;
getExternalModuleFileFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode | ImportCall): SourceFile | undefined;
- getTypeReferenceDirectivesForEntityName(name: EntityNameOrEntityNameExpression): [specifier: string, mode: ResolutionMode][] | undefined;
- getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): [specifier: string, mode: ResolutionMode][] | undefined;
isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean;
getJsxFactoryEntity(location?: Node): EntityName | undefined;
getJsxFragmentFactoryEntity(location?: Node): EntityName | undefined;
@@ -8118,8 +8117,6 @@ export interface EmitHost extends ScriptReferenceHost, ModuleSpecifierResolution
useCaseSensitiveFileNames(): boolean;
getCurrentDirectory(): string;
- getLibFileFromReference(ref: FileReference): SourceFile | undefined;
-
getCommonSourceDirectory(): string;
getCanonicalFileName(fileName: string): string;
@@ -9542,7 +9539,6 @@ export interface SymbolTracker {
reportLikelyUnsafeImportRequiredError?(specifier: string): void;
reportTruncationError?(): void;
moduleResolverHost?: ModuleSpecifierResolutionHost & { getCommonSourceDirectory(): string; };
- trackReferencedAmbientModule?(decl: ModuleDeclaration, symbol: Symbol): void;
trackExternalModuleSymbolOfImportTypeNode?(symbol: Symbol): void;
reportNonlocalAugmentation?(containingFile: SourceFile, parentSymbol: Symbol, augmentingSymbol: Symbol): void;
reportNonSerializableProperty?(propertyName: string): void;
@@ -9722,6 +9718,7 @@ export const commentPragmas = {
{ name: "path", optional: true, captureSpan: true },
{ name: "no-default-lib", optional: true },
{ name: "resolution-mode", optional: true },
+ { name: "preserve", optional: true },
],
kind: PragmaKindFlags.TripleSlashXML,
},
diff --git a/tests/baselines/reference/amdLikeInputDeclarationEmit.js b/tests/baselines/reference/amdLikeInputDeclarationEmit.js
index 584a304216a35..8067260169d7b 100644
--- a/tests/baselines/reference/amdLikeInputDeclarationEmit.js
+++ b/tests/baselines/reference/amdLikeInputDeclarationEmit.js
@@ -33,7 +33,6 @@ define("lib/ExtendedClass", ["deps/BaseClass"],
//// [ExtendedClass.d.ts]
-///
export = ExtendedClass;
declare const ExtendedClass: new () => {
f: () => "something";
diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts
index 61c467dc32ec9..4f394c5b33c1e 100644
--- a/tests/baselines/reference/api/typescript.d.ts
+++ b/tests/baselines/reference/api/typescript.d.ts
@@ -5565,6 +5565,7 @@ declare namespace ts {
interface FileReference extends TextRange {
fileName: string;
resolutionMode?: ResolutionMode;
+ preserve?: boolean;
}
interface CheckJsDirective extends TextRange {
enabled: boolean;
diff --git a/tests/baselines/reference/commonSourceDirectory.js b/tests/baselines/reference/commonSourceDirectory.js
index e78efd5bb1515..332598b82eb70 100644
--- a/tests/baselines/reference/commonSourceDirectory.js
+++ b/tests/baselines/reference/commonSourceDirectory.js
@@ -25,5 +25,4 @@ foo_1.x + bar_1.y;
//# sourceMappingURL=../myMapRoot/index.js.map
//// [/app/bin/index.d.ts]
-///
export {};
diff --git a/tests/baselines/reference/commonSourceDirectory_dts.js b/tests/baselines/reference/commonSourceDirectory_dts.js
index 877937abab853..2ce0a0febaff1 100644
--- a/tests/baselines/reference/commonSourceDirectory_dts.js
+++ b/tests/baselines/reference/commonSourceDirectory_dts.js
@@ -17,5 +17,4 @@ exports.x = y;
//# sourceMappingURL=../src/myMapRoot/index.js.map
//// [/app/bin/index.d.ts]
-///
export declare const x: number;
diff --git a/tests/baselines/reference/declFileAmbientExternalModuleWithSingleExportedModule.js b/tests/baselines/reference/declFileAmbientExternalModuleWithSingleExportedModule.js
index c1279fb02999b..0e119d9c7d43d 100644
--- a/tests/baselines/reference/declFileAmbientExternalModuleWithSingleExportedModule.js
+++ b/tests/baselines/reference/declFileAmbientExternalModuleWithSingleExportedModule.js
@@ -34,6 +34,29 @@ declare module "SubModule" {
}
}
//// [declFileAmbientExternalModuleWithSingleExportedModule_1.d.ts]
-///
import SubModule = require('SubModule');
export declare var x: SubModule.m.m3.c;
+
+
+//// [DtsFileErrors]
+
+
+declFileAmbientExternalModuleWithSingleExportedModule_1.d.ts(1,28): error TS2307: Cannot find module 'SubModule' or its corresponding type declarations.
+
+
+==== declFileAmbientExternalModuleWithSingleExportedModule_1.d.ts (1 errors) ====
+ import SubModule = require('SubModule');
+ ~~~~~~~~~~~
+!!! error TS2307: Cannot find module 'SubModule' or its corresponding type declarations.
+ export declare var x: SubModule.m.m3.c;
+
+==== declFileAmbientExternalModuleWithSingleExportedModule_0.d.ts (0 errors) ====
+ declare module "SubModule" {
+ namespace m {
+ namespace m3 {
+ interface c {
+ }
+ }
+ }
+ }
+
\ No newline at end of file
diff --git a/tests/baselines/reference/declFileWithErrorsInInputDeclarationFile.js b/tests/baselines/reference/declFileWithErrorsInInputDeclarationFile.js
index a615e15584980..7440f04f3cf12 100644
--- a/tests/baselines/reference/declFileWithErrorsInInputDeclarationFile.js
+++ b/tests/baselines/reference/declFileWithErrorsInInputDeclarationFile.js
@@ -21,5 +21,4 @@ var x = new M.C(); // Declaration file wont get emitted because there are errors
//// [client.d.ts]
-///
declare var x: M.C;
diff --git a/tests/baselines/reference/declFileWithErrorsInInputDeclarationFileWithOut.js b/tests/baselines/reference/declFileWithErrorsInInputDeclarationFileWithOut.js
index c2f4765a6794b..67f44d3784cb5 100644
--- a/tests/baselines/reference/declFileWithErrorsInInputDeclarationFileWithOut.js
+++ b/tests/baselines/reference/declFileWithErrorsInInputDeclarationFileWithOut.js
@@ -21,5 +21,4 @@ var x = new M.C(); // Declaration file wont get emitted because there are errors
//// [out.d.ts]
-///
declare var x: M.C;
diff --git a/tests/baselines/reference/declarationEmitBundleWithAmbientReferences.js b/tests/baselines/reference/declarationEmitBundleWithAmbientReferences.js
index ece01c1794a0b..0d6946277ad26 100644
--- a/tests/baselines/reference/declarationEmitBundleWithAmbientReferences.js
+++ b/tests/baselines/reference/declarationEmitBundleWithAmbientReferences.js
@@ -37,7 +37,6 @@ define("conditional_directive_field", ["require", "exports"], function (require,
//// [datastore.bundle.d.ts]
-///
declare module "datastore_result" {
import { Result } from "lib/result";
export type T = Result;
diff --git a/tests/baselines/reference/declarationEmitCrossFileImportTypeOfAmbientModule.js b/tests/baselines/reference/declarationEmitCrossFileImportTypeOfAmbientModule.js
index 71fb76c0fc0c9..cd15beebdf7d9 100644
--- a/tests/baselines/reference/declarationEmitCrossFileImportTypeOfAmbientModule.js
+++ b/tests/baselines/reference/declarationEmitCrossFileImportTypeOfAmbientModule.js
@@ -21,5 +21,4 @@ exports.reeexported = somepackage_1.item;
//// [index.d.ts]
-///
export declare const reeexported: typeof import("@namespace/component").Foo;
diff --git a/tests/baselines/reference/declarationEmitExportAssignedNamespaceNoTripleSlashTypesReference.js b/tests/baselines/reference/declarationEmitExportAssignedNamespaceNoTripleSlashTypesReference.js
index 1f08efb9e7258..e77dba15e3a8b 100644
--- a/tests/baselines/reference/declarationEmitExportAssignedNamespaceNoTripleSlashTypesReference.js
+++ b/tests/baselines/reference/declarationEmitExportAssignedNamespaceNoTripleSlashTypesReference.js
@@ -78,7 +78,6 @@ __exportStar(require("@emotion/core"), exports);
import { Component } from 'react';
export declare function getComp(): Component;
//// [inferred-comp-export.d.ts]
-///
export declare const obj: {
comp: import("react").Component;
};
diff --git a/tests/baselines/reference/declarationEmitHasTypesRefOnNamespaceUse.js b/tests/baselines/reference/declarationEmitHasTypesRefOnNamespaceUse.js
index 751ca63bebe92..5fa05a28139d9 100644
--- a/tests/baselines/reference/declarationEmitHasTypesRefOnNamespaceUse.js
+++ b/tests/baselines/reference/declarationEmitHasTypesRefOnNamespaceUse.js
@@ -22,6 +22,5 @@ var Src = /** @class */ (function () {
//// [index.d.ts]
-///
declare class Src implements NS.Dep {
}
diff --git a/tests/baselines/reference/declarationEmitPathMappingMonorepo.js b/tests/baselines/reference/declarationEmitPathMappingMonorepo.js
index ba7bc512b5984..83bec88a44ed6 100644
--- a/tests/baselines/reference/declarationEmitPathMappingMonorepo.js
+++ b/tests/baselines/reference/declarationEmitPathMappingMonorepo.js
@@ -26,5 +26,4 @@ function b(text) {
//// [index.d.ts]
-///
export declare function b(text: string): import("@ts-bug/a").AText;
diff --git a/tests/baselines/reference/declarationEmitTripleSlashReferenceAmbientModule.js b/tests/baselines/reference/declarationEmitTripleSlashReferenceAmbientModule.js
index b283b08edcd9e..609a7ebfbb39d 100644
--- a/tests/baselines/reference/declarationEmitTripleSlashReferenceAmbientModule.js
+++ b/tests/baselines/reference/declarationEmitTripleSlashReferenceAmbientModule.js
@@ -21,11 +21,8 @@ export const thing = parse();
//// [usage1.d.ts]
-///
export { parse } from "url";
//// [usage2.d.ts]
-///
export declare const thing: import("url").Url;
//// [usage3.d.ts]
-///
export declare const thing: import("url").Url;
diff --git a/tests/baselines/reference/declarationFilesGeneratingTypeReferences.js b/tests/baselines/reference/declarationFilesGeneratingTypeReferences.js
index bbcd9f7f69b36..58b2418510e65 100644
--- a/tests/baselines/reference/declarationFilesGeneratingTypeReferences.js
+++ b/tests/baselines/reference/declarationFilesGeneratingTypeReferences.js
@@ -20,28 +20,6 @@ var Test;
//// [out.d.ts]
-///
declare namespace Test {
var x: JQuery;
}
-
-
-//// [DtsFileErrors]
-
-
-out.d.ts(1,23): error TS2688: Cannot find type definition file for 'jquery'.
-
-
-==== /a/node_modules/@types/jquery/index.d.ts (0 errors) ====
- interface JQuery {
-
- }
-
-==== out.d.ts (1 errors) ====
- ///
- ~~~~~~
-!!! error TS2688: Cannot find type definition file for 'jquery'.
- declare namespace Test {
- var x: JQuery;
- }
-
\ No newline at end of file
diff --git a/tests/baselines/reference/declarationFilesWithTypeReferences2.js b/tests/baselines/reference/declarationFilesWithTypeReferences2.js
index 6852d90d594b6..0f01a6d8f8e37 100644
--- a/tests/baselines/reference/declarationFilesWithTypeReferences2.js
+++ b/tests/baselines/reference/declarationFilesWithTypeReferences2.js
@@ -17,5 +17,4 @@ function foo() {
//// [app.d.ts]
-///
declare function foo(): Error2;
diff --git a/tests/baselines/reference/declarationFilesWithTypeReferences3.js b/tests/baselines/reference/declarationFilesWithTypeReferences3.js
index dafec09848f75..20e3a8ce683bd 100644
--- a/tests/baselines/reference/declarationFilesWithTypeReferences3.js
+++ b/tests/baselines/reference/declarationFilesWithTypeReferences3.js
@@ -19,5 +19,4 @@ function foo() {
//// [app.d.ts]
-///
declare function foo(): Error2;
diff --git a/tests/baselines/reference/dtsEmitTripleSlashAvoidUnnecessaryResolutionMode.js b/tests/baselines/reference/dtsEmitTripleSlashAvoidUnnecessaryResolutionMode.js
index 5ff9411dc18e7..b58b26032c323 100644
--- a/tests/baselines/reference/dtsEmitTripleSlashAvoidUnnecessaryResolutionMode.js
+++ b/tests/baselines/reference/dtsEmitTripleSlashAvoidUnnecessaryResolutionMode.js
@@ -24,5 +24,42 @@ export async function drainStream(stream: NodeJS.ReadableStream): Promise
//// [app.d.mts]
-///
export declare function drainStream(stream: NodeJS.ReadableStream): Promise;
+
+
+//// [DtsFileErrors]
+
+
+/app.d.mts(1,45): error TS2503: Cannot find namespace 'NodeJS'.
+
+
+==== /tsconfig.json (0 errors) ====
+ {
+ "compilerOptions": {
+ "module": "nodenext",
+ "types": [],
+ "declaration": true,
+ "emitDeclarationOnly": true,
+ }
+ }
+
+==== /app.d.mts (1 errors) ====
+ export declare function drainStream(stream: NodeJS.ReadableStream): Promise;
+ ~~~~~~
+!!! error TS2503: Cannot find namespace 'NodeJS'.
+
+==== /node_modules/@types/node/package.json (0 errors) ====
+ {
+ "name": "@types/node",
+ "version": "1.0.0",
+ "types": "index.d.ts"
+ }
+
+==== /node_modules/@types/node/globals.d.ts (0 errors) ====
+ declare namespace NodeJS {
+ interface ReadableStream {}
+ }
+
+==== /node_modules/@types/node/index.d.ts (0 errors) ====
+ ///
+
\ No newline at end of file
diff --git a/tests/baselines/reference/importAliasFromNamespace.js b/tests/baselines/reference/importAliasFromNamespace.js
index 0b24d2c091c79..e8249dc241fe4 100644
--- a/tests/baselines/reference/importAliasFromNamespace.js
+++ b/tests/baselines/reference/importAliasFromNamespace.js
@@ -59,7 +59,6 @@ declare namespace My.Internal {
}
}
//// [usage.d.ts]
-///
declare namespace SomeOther.Thing {
class Foo {
private _which;
diff --git a/tests/baselines/reference/importDecl.js b/tests/baselines/reference/importDecl.js
index d7bb1ddd647e3..f14a53fa15140 100644
--- a/tests/baselines/reference/importDecl.js
+++ b/tests/baselines/reference/importDecl.js
@@ -209,8 +209,6 @@ export declare function foo(): d;
import m4 = require("./importDecl_require");
export declare function foo2(): m4.d;
//// [importDecl_1.d.ts]
-///
-///
import m4 = require("./importDecl_require");
export declare var x4: m4.d;
export declare var d4: typeof m4.d;
diff --git a/tests/baselines/reference/importTypeGenericArrowTypeParenthesized.js b/tests/baselines/reference/importTypeGenericArrowTypeParenthesized.js
index adb6657cb2a34..94810d2ab8480 100644
--- a/tests/baselines/reference/importTypeGenericArrowTypeParenthesized.js
+++ b/tests/baselines/reference/importTypeGenericArrowTypeParenthesized.js
@@ -33,7 +33,6 @@ exports.works2 = (0, module_1.fn)(function (x) { return x; });
//// [index.d.ts]
-///
export declare const fail1: import("module").Modifier<((x: T) => T)>;
export declare const fail2: import("module").Modifier<((x: T) => T)>;
export declare const works1: import("module").Modifier<(x: number) => number>;
diff --git a/tests/baselines/reference/jsDeclarationsReactComponents.js b/tests/baselines/reference/jsDeclarationsReactComponents.js
index d0c4a2415283a..55e9e5c827e8b 100644
--- a/tests/baselines/reference/jsDeclarationsReactComponents.js
+++ b/tests/baselines/reference/jsDeclarationsReactComponents.js
@@ -185,7 +185,6 @@ exports.default = Tree;
//// [jsDeclarationsReactComponents1.d.ts]
-///
export default TabbedShowLayout;
declare function TabbedShowLayout({}: {}): JSX.Element;
declare namespace TabbedShowLayout {
@@ -198,7 +197,6 @@ declare namespace TabbedShowLayout {
}
import PropTypes from "prop-types";
//// [jsDeclarationsReactComponents2.d.ts]
-///
export default TabbedShowLayout;
/**
* @type {React.SFC}
@@ -228,7 +226,6 @@ declare namespace TabbedShowLayout {
}
}
//// [jsDeclarationsReactComponents5.d.ts]
-///
export default Tree;
declare function Tree({ allowDropOnRoot }: {
allowDropOnRoot: any;
@@ -244,3 +241,93 @@ declare namespace Tree {
}
}
import PropTypes from 'prop-types';
+
+
+//// [DtsFileErrors]
+
+
+out/jsDeclarationsReactComponents1.d.ts(2,44): error TS2503: Cannot find namespace 'JSX'.
+out/jsDeclarationsReactComponents1.d.ts(11,23): error TS2307: Cannot find module 'prop-types' or its corresponding type declarations.
+out/jsDeclarationsReactComponents2.d.ts(6,19): error TS2307: Cannot find module 'react' or its corresponding type declarations.
+out/jsDeclarationsReactComponents3.d.ts(11,7): error TS2503: Cannot find namespace 'JSX'.
+out/jsDeclarationsReactComponents4.d.ts(4,5): error TS2503: Cannot find namespace 'JSX'.
+out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespace 'JSX'.
+out/jsDeclarationsReactComponents5.d.ts(15,23): error TS2307: Cannot find module 'prop-types' or its corresponding type declarations.
+
+
+==== out/jsDeclarationsReactComponents1.d.ts (2 errors) ====
+ export default TabbedShowLayout;
+ declare function TabbedShowLayout({}: {}): JSX.Element;
+ ~~~
+!!! error TS2503: Cannot find namespace 'JSX'.
+ declare namespace TabbedShowLayout {
+ namespace propTypes {
+ let version: PropTypes.Requireable;
+ }
+ namespace defaultProps {
+ let tabs: undefined;
+ }
+ }
+ import PropTypes from "prop-types";
+ ~~~~~~~~~~~~
+!!! error TS2307: Cannot find module 'prop-types' or its corresponding type declarations.
+
+==== out/jsDeclarationsReactComponents2.d.ts (1 errors) ====
+ export default TabbedShowLayout;
+ /**
+ * @type {React.SFC}
+ */
+ declare const TabbedShowLayout: React.SFC;
+ import React from "react";
+ ~~~~~~~
+!!! error TS2307: Cannot find module 'react' or its corresponding type declarations.
+
+==== out/jsDeclarationsReactComponents3.d.ts (1 errors) ====
+ export default TabbedShowLayout;
+ /**
+ * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)}
+ */
+ declare const TabbedShowLayout: {
+ defaultProps: {
+ tabs: string;
+ };
+ } & ((props?: {
+ elem: string;
+ }) => JSX.Element);
+ ~~~
+!!! error TS2503: Cannot find namespace 'JSX'.
+
+==== out/jsDeclarationsReactComponents4.d.ts (1 errors) ====
+ export default TabbedShowLayout;
+ declare function TabbedShowLayout(prop: {
+ className: string;
+ }): JSX.Element;
+ ~~~
+!!! error TS2503: Cannot find namespace 'JSX'.
+ declare namespace TabbedShowLayout {
+ namespace defaultProps {
+ let tabs: string;
+ }
+ }
+
+==== out/jsDeclarationsReactComponents5.d.ts (2 errors) ====
+ export default Tree;
+ declare function Tree({ allowDropOnRoot }: {
+ allowDropOnRoot: any;
+ }): JSX.Element;
+ ~~~
+!!! error TS2503: Cannot find namespace 'JSX'.
+ declare namespace Tree {
+ namespace propTypes {
+ let classes: PropTypes.Requireable