Skip to content

Commit 3adcbc7

Browse files
committed
Slight cleanup from code review feedback
1 parent 4c639b8 commit 3adcbc7

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/compiler/emitter.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace ts {
4343
}
4444

4545
/*@internal*/
46-
export function getOutputPathsFor(sourceFile: SourceFile | Bundle, host: EmitHost, forceDtsPaths?: boolean) {
46+
export function getOutputPathsFor(sourceFile: SourceFile | Bundle, host: EmitHost, forceDtsPaths: boolean) {
4747
const options = host.getCompilerOptions();
4848
if (sourceFile.kind === SyntaxKind.Bundle) {
4949
const jsFilePath = options.outFile || options.out;
@@ -129,7 +129,8 @@ namespace ts {
129129
let declarationPrinter: Printer;
130130
if (emitOnlyDtsFiles || compilerOptions.declaration) {
131131
const nonJsFiles = filter(sourceFiles, isSourceFileNotJavaScript);
132-
declarationTransform = transformNodes(resolver, host, compilerOptions, (compilerOptions.outFile || compilerOptions.out) ? [createBundle(nonJsFiles)] : nonJsFiles, [transformDeclarations], /*allowDtsFiles*/ false);
132+
const inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [createBundle(nonJsFiles)] : nonJsFiles;
133+
declarationTransform = transformNodes(resolver, host, compilerOptions, inputListOrBundle, [transformDeclarations], /*allowDtsFiles*/ false);
133134
declarationPrinter = createPrinter({ ...compilerOptions, onlyPrintJsDocStyle: true } as PrinterOptions, {
134135
// resolver hooks
135136
hasGlobalName: resolver.hasGlobalName,
@@ -182,9 +183,9 @@ namespace ts {
182183
return getOriginalNode(n) === getOriginalNode(sourceFileOrBundle);
183184
});
184185
if (associatedDeclarationTree) {
185-
const previousState = sourceMap.setDisabled(true);
186+
const previousState = sourceMap.setState(/*disabled*/ true);
186187
printSourceFileOrBundle(declarationFilePath, /*sourceMapFilePath*/ undefined, associatedDeclarationTree, declarationPrinter, /*shouldSkipSourcemap*/ true);
187-
sourceMap.setDisabled(previousState);
188+
sourceMap.setState(previousState);
188189
}
189190
else {
190191
Debug.fail(`No declaration output found for path "${declarationFilePath}" for js output file: "${jsFilePath}".`);

src/compiler/sourcemap.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace ts {
7171
/**
7272
* @returns the previous disabled state
7373
*/
74-
setDisabled(state: boolean): boolean;
74+
setState(disabled: boolean): boolean;
7575
}
7676

7777
// Used for initialize lastEncodedSourceMapSpan and reset lastEncodedSourceMapSpan when updateLastEncodedAndRecordedSpans
@@ -112,10 +112,10 @@ namespace ts {
112112
emitTokenWithSourceMap,
113113
getText,
114114
getSourceMappingURL,
115-
setDisabled,
115+
setState,
116116
};
117117

118-
function setDisabled(state: boolean) {
118+
function setState(state: boolean) {
119119
const last = disabled;
120120
disabled = state;
121121
return last;

src/compiler/transformers/declarations.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ namespace ts {
184184
possibleImports = undefined;
185185
importDeclarationMap = createMap();
186186
necessaryTypeRefernces = undefined;
187-
const refs = collectReferences(currentSourceFile);
187+
const refs = collectReferences(currentSourceFile, createMap());
188188
const references: FileReference[] = [];
189189
const outputFilePath = getDirectoryPath(normalizeSlashes(getOutputPathsFor(node, host, /*forceDtsPaths*/ true).declarationFilePath));
190190
const referenceVisitor = mapReferencesIntoArray(references, outputFilePath);
@@ -234,7 +234,7 @@ namespace ts {
234234
}
235235
}
236236

237-
function collectReferences(sourceFile: SourceFile, ret = createMap<SourceFile>()) {
237+
function collectReferences(sourceFile: SourceFile, ret: Map<SourceFile>) {
238238
if (noResolve || isSourceFileJavaScript(sourceFile)) return ret;
239239
forEach(sourceFile.referencedFiles, f => {
240240
const elem = tryResolveScriptReference(host, sourceFile, f);
@@ -497,7 +497,7 @@ namespace ts {
497497
}
498498
if (decl.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) {
499499
// Namespace import (optionally with visible default)
500-
const namedBindings = resolver.isDeclarationVisible(decl.importClause.namedBindings as NamespaceImport) ? decl.importClause.namedBindings : /*namedBindings*/ undefined;
500+
const namedBindings = resolver.isDeclarationVisible(decl.importClause.namedBindings) ? decl.importClause.namedBindings : /*namedBindings*/ undefined;
501501
return visibleDefaultBinding || namedBindings ? updateImportDeclaration(decl, /*decorators*/ undefined, decl.modifiers, updateImportClause(
502502
decl.importClause,
503503
visibleDefaultBinding,
@@ -797,7 +797,7 @@ namespace ts {
797797

798798
switch (input.kind) {
799799
case SyntaxKind.ExportDeclaration: {
800-
if (!resultHasExternalModuleIndicator && isSourceFile(input.parent)) {
800+
if (isSourceFile(input.parent)) {
801801
resultHasExternalModuleIndicator = true;
802802
}
803803
// Always visible if the parent node isn't dropped for being not visible
@@ -806,7 +806,7 @@ namespace ts {
806806
}
807807
case SyntaxKind.ExportAssignment: {
808808
// Always visible if the parent node isn't dropped for being not visible
809-
if (!resultHasExternalModuleIndicator && isSourceFile(input.parent)) {
809+
if (isSourceFile(input.parent)) {
810810
resultHasExternalModuleIndicator = true;
811811
}
812812
if (input.expression.kind === SyntaxKind.Identifier) {

0 commit comments

Comments
 (0)