Skip to content

Commit def7b66

Browse files
committed
PR feedback
1 parent 51caf1a commit def7b66

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

src/compiler/program.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ namespace ts {
286286
}
287287

288288
export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[] {
289-
let diagnostics = program.getOptionsDiagnostics(cancellationToken).concat(
289+
let diagnostics = program.getOptionsDiagnostics().concat(
290290
program.getSyntacticDiagnostics(sourceFile, cancellationToken),
291291
program.getGlobalDiagnostics(cancellationToken),
292292
program.getSemanticDiagnostics(sourceFile, cancellationToken));
@@ -337,6 +337,7 @@ namespace ts {
337337
let classifiableNames: Map<string>;
338338

339339
let skipDefaultLib = options.noLib;
340+
let supportedExtensions = getSupportedExtensions(options);
340341

341342
let start = new Date().getTime();
342343

@@ -369,14 +370,13 @@ namespace ts {
369370
}
370371

371372
if (!tryReuseStructureFromOldProgram()) {
372-
let supportedExtensions = getSupportedExtensions(options);
373-
forEach(rootNames, name => processRootFile(name, false, supportedExtensions));
373+
forEach(rootNames, name => processRootFile(name, false));
374374
// Do not process the default library if:
375375
// - The '--noLib' flag is used.
376376
// - A 'no-default-lib' reference comment is encountered in
377377
// processing the root files.
378378
if (!skipDefaultLib) {
379-
processRootFile(host.getDefaultLibFileName(options), true, supportedExtensions);
379+
processRootFile(host.getDefaultLibFileName(options), true);
380380
}
381381
}
382382

@@ -833,7 +833,7 @@ namespace ts {
833833
});
834834
}
835835

836-
function getOptionsDiagnostics(cancellationToken?: CancellationToken): Diagnostic[] {
836+
function getOptionsDiagnostics(): Diagnostic[] {
837837
let allDiagnostics: Diagnostic[] = [];
838838
addRange(allDiagnostics, fileProcessingDiagnostics.getGlobalDiagnostics());
839839
addRange(allDiagnostics, programDiagnostics.getGlobalDiagnostics());
@@ -851,8 +851,8 @@ namespace ts {
851851
return getBaseFileName(fileName).indexOf(".") >= 0;
852852
}
853853

854-
function processRootFile(fileName: string, isDefaultLib: boolean, supportedExtensions: string[]) {
855-
processSourceFile(normalizePath(fileName), isDefaultLib, supportedExtensions);
854+
function processRootFile(fileName: string, isDefaultLib: boolean) {
855+
processSourceFile(normalizePath(fileName), isDefaultLib);
856856
}
857857

858858
function fileReferenceIsEqualTo(a: FileReference, b: FileReference): boolean {
@@ -911,15 +911,15 @@ namespace ts {
911911
}
912912
}
913913

914-
function processSourceFile(fileName: string, isDefaultLib: boolean, supportedExtensions: string[], refFile?: SourceFile, refPos?: number, refEnd?: number) {
914+
function processSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) {
915915
let diagnosticArgument: string[];
916916
let diagnostic: DiagnosticMessage;
917917
if (hasExtension(fileName)) {
918918
if (!options.allowNonTsExtensions && !forEach(supportedExtensions, extension => fileExtensionIs(host.getCanonicalFileName(fileName), extension))) {
919919
diagnostic = Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1;
920920
diagnosticArgument = [fileName, "'" + supportedExtensions.join("', '") + "'"];
921921
}
922-
else if (!findSourceFile(fileName, toPath(fileName, currentDirectory, getCanonicalFileName), isDefaultLib, supportedExtensions, refFile, refPos, refEnd)) {
922+
else if (!findSourceFile(fileName, toPath(fileName, currentDirectory, getCanonicalFileName), isDefaultLib, refFile, refPos, refEnd)) {
923923
diagnostic = Diagnostics.File_0_not_found;
924924
diagnosticArgument = [fileName];
925925
}
@@ -929,13 +929,13 @@ namespace ts {
929929
}
930930
}
931931
else {
932-
let nonTsFile: SourceFile = options.allowNonTsExtensions && findSourceFile(fileName, toPath(fileName, currentDirectory, getCanonicalFileName), isDefaultLib, supportedExtensions, refFile, refPos, refEnd);
932+
let nonTsFile: SourceFile = options.allowNonTsExtensions && findSourceFile(fileName, toPath(fileName, currentDirectory, getCanonicalFileName), isDefaultLib, refFile, refPos, refEnd);
933933
if (!nonTsFile) {
934934
if (options.allowNonTsExtensions) {
935935
diagnostic = Diagnostics.File_0_not_found;
936936
diagnosticArgument = [fileName];
937937
}
938-
else if (!forEach(getSupportedExtensions(options), extension => findSourceFile(fileName + extension, toPath(fileName + extension, currentDirectory, getCanonicalFileName), isDefaultLib, supportedExtensions, refFile, refPos, refEnd))) {
938+
else if (!forEach(supportedExtensions, extension => findSourceFile(fileName + extension, toPath(fileName + extension, currentDirectory, getCanonicalFileName), isDefaultLib, refFile, refPos, refEnd))) {
939939
// (TODO: shkamat) Should this message be different given we support multiple extensions
940940
diagnostic = Diagnostics.File_0_not_found;
941941
fileName += ".ts";
@@ -965,7 +965,7 @@ namespace ts {
965965
}
966966

967967
// Get source file from normalized fileName
968-
function findSourceFile(fileName: string, normalizedAbsolutePath: Path, isDefaultLib: boolean, supportedExtensions: string[], refFile?: SourceFile, refPos?: number, refEnd?: number): SourceFile {
968+
function findSourceFile(fileName: string, normalizedAbsolutePath: Path, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number): SourceFile {
969969
if (filesByName.contains(normalizedAbsolutePath)) {
970970
const file = filesByName.get(normalizedAbsolutePath);
971971
// try to check if we've already seen this file but with a different casing in path
@@ -1007,11 +1007,11 @@ namespace ts {
10071007

10081008
let basePath = getDirectoryPath(fileName);
10091009
if (!options.noResolve) {
1010-
processReferencedFiles(file, basePath, supportedExtensions);
1010+
processReferencedFiles(file, basePath);
10111011
}
10121012

10131013
// always process imported modules to record module name resolutions
1014-
processImportedModules(file, basePath, supportedExtensions);
1014+
processImportedModules(file, basePath);
10151015

10161016
if (isDefaultLib) {
10171017
file.isDefaultLib = true;
@@ -1025,18 +1025,18 @@ namespace ts {
10251025
return file;
10261026
}
10271027

1028-
function processReferencedFiles(file: SourceFile, basePath: string, supportedExtensions: string[]) {
1028+
function processReferencedFiles(file: SourceFile, basePath: string) {
10291029
forEach(file.referencedFiles, ref => {
10301030
let referencedFileName = resolveTripleslashReference(ref.fileName, file.fileName);
1031-
processSourceFile(referencedFileName, /* isDefaultLib */ false, supportedExtensions, file, ref.pos, ref.end);
1031+
processSourceFile(referencedFileName, /* isDefaultLib */ false, file, ref.pos, ref.end);
10321032
});
10331033
}
10341034

10351035
function getCanonicalFileName(fileName: string): string {
10361036
return host.getCanonicalFileName(fileName);
10371037
}
10381038

1039-
function processImportedModules(file: SourceFile, basePath: string, supportedExtensions: string[]) {
1039+
function processImportedModules(file: SourceFile, basePath: string) {
10401040
collectExternalModuleReferences(file);
10411041
if (file.imports.length) {
10421042
file.resolvedModules = {};
@@ -1046,7 +1046,7 @@ namespace ts {
10461046
let resolution = resolutions[i];
10471047
setResolvedModule(file, moduleNames[i], resolution);
10481048
if (resolution && !options.noResolve) {
1049-
const importedFile = findSourceFile(resolution.resolvedFileName, toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /* isDefaultLib */ false, supportedExtensions, file, skipTrivia(file.text, file.imports[i].pos), file.imports[i].end);
1049+
const importedFile = findSourceFile(resolution.resolvedFileName, toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /* isDefaultLib */ false, file, skipTrivia(file.text, file.imports[i].pos), file.imports[i].end);
10501050

10511051
if (importedFile && resolution.isExternalLibraryImport) {
10521052
if (!isExternalModule(importedFile)) {
@@ -1255,6 +1255,7 @@ namespace ts {
12551255
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators"));
12561256
}
12571257

1258+
// If the emit is enabled make sure that every output file is unique and not overwriting any of the input files
12581259
if (!options.noEmit) {
12591260
let emitHost = getEmitHost();
12601261
let emitFilesSeen = createFileMap<boolean>(!host.useCaseSensitiveFileNames() ? key => key.toLocaleLowerCase() : undefined);

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,7 @@ namespace ts {
18311831

18321832
function onBundledEmit(host: EmitHost) {
18331833
let bundledSources = filter(host.getSourceFiles(),
1834-
sourceFile => !shouldEmitToOwnFile(sourceFile, host.getCompilerOptions()) && !isDeclarationFile(sourceFile));
1834+
sourceFile => !shouldEmitToOwnFile(sourceFile, options) && !isDeclarationFile(sourceFile));
18351835
let jsFilePath = options.outFile || options.out;
18361836
let emitFileNames: EmitFileNames = {
18371837
jsFilePath,

0 commit comments

Comments
 (0)