Skip to content

Commit 017355c

Browse files
committed
Merge pull request microsoft#4388 from Microsoft/outFile
--outFile support
2 parents 425ad02 + b395fb9 commit 017355c

35 files changed

Lines changed: 481 additions & 110 deletions

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ namespace ts {
388388
return node1.pos <= node2.pos;
389389
}
390390

391-
if (!compilerOptions.out) {
391+
if (!compilerOptions.outFile && !compilerOptions.out) {
392392
return true;
393393
}
394394

src/compiler/commandLineParser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ namespace ts {
120120
{
121121
name: "out",
122122
type: "string",
123+
isFilePath: false, // This is intentionally broken to support compatability with existing tsconfig files
124+
// for correct behaviour, please use outFile
125+
paramType: Diagnostics.FILE,
126+
},
127+
{
128+
name: "outFile",
129+
type: "string",
123130
isFilePath: true,
124131
description: Diagnostics.Concatenate_and_emit_output_to_single_file,
125132
paramType: Diagnostics.FILE,

src/compiler/declarationEmitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ namespace ts {
15741574
? referencedFile.fileName // Declaration file, use declaration file name
15751575
: shouldEmitToOwnFile(referencedFile, compilerOptions)
15761576
? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") // Own output file so get the .d.ts file
1577-
: removeFileExtension(compilerOptions.out) + ".d.ts"; // Global out file
1577+
: removeFileExtension(compilerOptions.outFile || compilerOptions.out) + ".d.ts"; // Global out file
15781578

15791579
declFileName = getRelativePathToDirectoryOrUrl(
15801580
getDirectoryPath(normalizeSlashes(jsFilePath)),

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -506,19 +506,11 @@ namespace ts {
506506
Unknown_compiler_option_0: { code: 5023, category: DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." },
507507
Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." },
508508
Could_not_write_file_0_Colon_1: { code: 5033, category: DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },
509-
Option_mapRoot_cannot_be_specified_without_specifying_sourceMap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourceMap' option." },
510-
Option_sourceRoot_cannot_be_specified_without_specifying_sourceMap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option." },
511-
Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." },
512-
Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." },
513509
Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." },
514-
Option_declaration_cannot_be_specified_with_option_isolatedModules: { code: 5044, category: DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'isolatedModules'." },
515-
Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules: { code: 5045, category: DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'isolatedModules'." },
516-
Option_out_cannot_be_specified_with_option_isolatedModules: { code: 5046, category: DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'isolatedModules'." },
517510
Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: DiagnosticCategory.Error, key: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." },
518-
Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap: { code: 5048, category: DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'inlineSourceMap'." },
519-
Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5049, category: DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'." },
520-
Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5050, category: DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified with option 'inlineSourceMap'." },
521511
Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided: { code: 5051, category: DiagnosticCategory.Error, key: "Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided." },
512+
Option_0_cannot_be_specified_without_specifying_option_1: { code: 5052, category: DiagnosticCategory.Error, key: "Option '{0}' cannot be specified without specifying option '{1}'." },
513+
Option_0_cannot_be_specified_with_option_1: { code: 5053, category: DiagnosticCategory.Error, key: "Option '{0}' cannot be specified with option '{1}'." },
522514
Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." },
523515
Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." },
524516
Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." },
@@ -569,7 +561,6 @@ namespace ts {
569561
Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." },
570562
Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: DiagnosticCategory.Message, key: "Specify JSX code generation: 'preserve' or 'react'" },
571563
Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." },
572-
Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified: { code: 6064, category: DiagnosticCategory.Error, key: "Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified." },
573564
Enables_experimental_support_for_ES7_decorators: { code: 6065, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." },
574565
Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." },
575566
Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower: { code: 6067, category: DiagnosticCategory.Message, key: "Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower." },

src/compiler/diagnosticMessages.json

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,59 +2013,27 @@
20132013
"category": "Error",
20142014
"code": 5033
20152015
},
2016-
"Option 'mapRoot' cannot be specified without specifying 'sourceMap' option.": {
2017-
"category": "Error",
2018-
"code": 5038
2019-
},
2020-
"Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option.": {
2021-
"category": "Error",
2022-
"code": 5039
2023-
},
2024-
"Option 'noEmit' cannot be specified with option 'out' or 'outDir'.": {
2025-
"category": "Error",
2026-
"code": 5040
2027-
},
2028-
"Option 'noEmit' cannot be specified with option 'declaration'.": {
2029-
"category": "Error",
2030-
"code": 5041
2031-
},
20322016
"Option 'project' cannot be mixed with source files on a command line.": {
20332017
"category": "Error",
20342018
"code": 5042
20352019
},
2036-
"Option 'declaration' cannot be specified with option 'isolatedModules'.": {
2037-
"category": "Error",
2038-
"code": 5044
2039-
},
2040-
"Option 'noEmitOnError' cannot be specified with option 'isolatedModules'.": {
2041-
"category": "Error",
2042-
"code": 5045
2043-
},
2044-
"Option 'out' cannot be specified with option 'isolatedModules'.": {
2045-
"category": "Error",
2046-
"code": 5046
2047-
},
20482020
"Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher.": {
20492021
"category": "Error",
20502022
"code": 5047
20512023
},
2052-
"Option 'sourceMap' cannot be specified with option 'inlineSourceMap'.": {
2053-
"category": "Error",
2054-
"code": 5048
2055-
},
2056-
"Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'.": {
2024+
"Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.": {
20572025
"category": "Error",
2058-
"code": 5049
2026+
"code": 5051
20592027
},
2060-
"Option 'mapRoot' cannot be specified with option 'inlineSourceMap'.": {
2028+
"Option '{0}' cannot be specified without specifying option '{1}'.": {
20612029
"category": "Error",
2062-
"code": 5050
2030+
"code": 5052
20632031
},
2064-
"Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.": {
2032+
"Option '{0}' cannot be specified with option '{1}'.": {
20652033
"category": "Error",
2066-
"code": 5051
2034+
"code": 5053
20672035
},
2068-
2036+
20692037
"Concatenate and emit output to single file.": {
20702038
"category": "Message",
20712039
"code": 6001
@@ -2266,10 +2234,6 @@
22662234
"category": "Message",
22672235
"code": 6081
22682236
},
2269-
"Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified.": {
2270-
"category": "Error",
2271-
"code": 6064
2272-
},
22732237
"Enables experimental support for ES7 decorators.": {
22742238
"category": "Message",
22752239
"code": 6065
@@ -2286,7 +2250,7 @@
22862250
"category": "Message",
22872251
"code": 6068
22882252
},
2289-
2253+
22902254
"Variable '{0}' implicitly has an '{1}' type.": {
22912255
"category": "Error",
22922256
"code": 7005

src/compiler/emitter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
7878
}
7979
});
8080

81-
if (compilerOptions.out) {
82-
emitFile(compilerOptions.out);
81+
if (compilerOptions.outFile || compilerOptions.out) {
82+
emitFile(compilerOptions.outFile || compilerOptions.out);
8383
}
8484
}
8585
else {
@@ -88,8 +88,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
8888
let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, shouldEmitJsx(targetSourceFile) ? ".jsx" : ".js");
8989
emitFile(jsFilePath, targetSourceFile);
9090
}
91-
else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) {
92-
emitFile(compilerOptions.out);
91+
else if (!isDeclarationFile(targetSourceFile) && (compilerOptions.outFile || compilerOptions.out)) {
92+
emitFile(compilerOptions.outFile || compilerOptions.out);
9393
}
9494
}
9595

src/compiler/program.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ namespace ts {
413413
// This is because in the -out scenario all files need to be emitted, and therefore all
414414
// files need to be type checked. And the way to specify that all files need to be type
415415
// checked is to not pass the file to getEmitResolver.
416-
let emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(options.out ? undefined : sourceFile);
416+
let emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver((options.outFile || options.out)? undefined : sourceFile);
417417

418418
let start = new Date().getTime();
419419

@@ -794,27 +794,31 @@ namespace ts {
794794
function verifyCompilerOptions() {
795795
if (options.isolatedModules) {
796796
if (options.declaration) {
797-
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_declaration_cannot_be_specified_with_option_isolatedModules));
797+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules"));
798798
}
799799

800800
if (options.noEmitOnError) {
801-
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules));
801+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules"));
802802
}
803803

804804
if (options.out) {
805-
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_out_cannot_be_specified_with_option_isolatedModules));
805+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules"));
806+
}
807+
808+
if (options.outFile) {
809+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules"));
806810
}
807811
}
808812

809813
if (options.inlineSourceMap) {
810814
if (options.sourceMap) {
811-
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap));
815+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap"));
812816
}
813817
if (options.mapRoot) {
814-
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap));
818+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap"));
815819
}
816820
if (options.sourceRoot) {
817-
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap));
821+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap"));
818822
}
819823
}
820824

@@ -825,18 +829,23 @@ namespace ts {
825829
}
826830
}
827831

832+
if (options.out && options.outFile) {
833+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile"));
834+
}
835+
828836
if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) {
829837
// Error to specify --mapRoot or --sourceRoot without mapSourceFiles
830838
if (options.mapRoot) {
831-
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourceMap_option));
839+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap"));
832840
}
833841
if (options.sourceRoot) {
834-
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourceMap_option));
842+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap"));
835843
}
836844
return;
837845
}
838846

839847
let languageVersion = options.target || ScriptTarget.ES3;
848+
let outFile = options.outFile || options.out;
840849

841850
let firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined);
842851
if (options.isolatedModules) {
@@ -866,7 +875,7 @@ namespace ts {
866875
if (options.outDir || // there is --outDir specified
867876
options.sourceRoot || // there is --sourceRoot specified
868877
(options.mapRoot && // there is --mapRoot specified and there would be multiple js files generated
869-
(!options.out || firstExternalModuleSourceFile !== undefined))) {
878+
(!outFile || firstExternalModuleSourceFile !== undefined))) {
870879

871880
if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) {
872881
// If a rootDir is specified and is valid use it as the commonSourceDirectory
@@ -886,18 +895,26 @@ namespace ts {
886895
}
887896

888897
if (options.noEmit) {
889-
if (options.out || options.outDir) {
890-
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_out_or_outDir));
898+
if (options.out) {
899+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out"));
900+
}
901+
902+
if (options.outFile) {
903+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile"));
904+
}
905+
906+
if (options.outDir) {
907+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir"));
891908
}
892909

893910
if (options.declaration) {
894-
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration));
911+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration"));
895912
}
896913
}
897914

898915
if (options.emitDecoratorMetadata &&
899916
!options.experimentalDecorators) {
900-
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified));
917+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators"));
901918
}
902919

903920
if (options.experimentalAsyncFunctions &&

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,7 @@ namespace ts {
20322032
noLib?: boolean;
20332033
noResolve?: boolean;
20342034
out?: string;
2035+
outFile?: string;
20352036
outDir?: string;
20362037
preserveConstEnums?: boolean;
20372038
project?: string;

src/compiler/utilities.ts

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

17671767
export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean {
17681768
if (!isDeclarationFile(sourceFile)) {
1769-
if ((isExternalModule(sourceFile) || !compilerOptions.out)) {
1769+
if ((isExternalModule(sourceFile) || !(compilerOptions.outFile || compilerOptions.out))) {
17701770
// 1. in-browser single file compilation scenario
17711771
// 2. non .js file
17721772
return compilerOptions.isolatedModules || !fileExtensionIs(sourceFile.fileName, ".js");

0 commit comments

Comments
 (0)