Add --outFile and revert change make --out relative in tsconfig.json

This commit is contained in:
Mohamed Hegazy 2015-08-20 17:37:56 -07:00
parent cfc164b044
commit 00cd8ad745
21 changed files with 379 additions and 15 deletions

View File

@ -388,7 +388,7 @@ namespace ts {
return node1.pos <= node2.pos;
}
if (!compilerOptions.out) {
if (!compilerOptions.outFile && !compilerOptions.out) {
return true;
}

View File

@ -120,6 +120,13 @@ namespace ts {
{
name: "out",
type: "string",
isFilePath: false, // This is intentionally broken to support compatability with existing tsconfig files
// for correct behaviour, please use outFile
paramType: Diagnostics.FILE,
},
{
name: "outFile",
type: "string",
isFilePath: true,
description: Diagnostics.Concatenate_and_emit_output_to_single_file,
paramType: Diagnostics.FILE,

View File

@ -1574,7 +1574,7 @@ namespace ts {
? referencedFile.fileName // Declaration file, use declaration file name
: shouldEmitToOwnFile(referencedFile, compilerOptions)
? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") // Own output file so get the .d.ts file
: removeFileExtension(compilerOptions.out) + ".d.ts"; // Global out file
: removeFileExtension(compilerOptions.outFile || compilerOptions.out) + ".d.ts"; // Global out file
declFileName = getRelativePathToDirectoryOrUrl(
getDirectoryPath(normalizeSlashes(jsFilePath)),

View File

@ -78,8 +78,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
});
if (compilerOptions.out) {
emitFile(compilerOptions.out);
if (compilerOptions.outFile || compilerOptions.out) {
emitFile(compilerOptions.outFile || compilerOptions.out);
}
}
else {
@ -88,8 +88,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, forEach(host.getSourceFiles(), shouldEmitJsx) ? ".jsx" : ".js");
emitFile(jsFilePath, targetSourceFile);
}
else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) {
emitFile(compilerOptions.out);
else if (!isDeclarationFile(targetSourceFile) && (compilerOptions.outFile || compilerOptions.out)) {
emitFile(compilerOptions.outFile || compilerOptions.out);
}
}

View File

@ -413,7 +413,7 @@ namespace ts {
// This is because in the -out scenario all files need to be emitted, and therefore all
// files need to be type checked. And the way to specify that all files need to be type
// checked is to not pass the file to getEmitResolver.
let emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(options.out ? undefined : sourceFile);
let emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver((options.outFile || options.out)? undefined : sourceFile);
let start = new Date().getTime();
@ -804,6 +804,10 @@ namespace ts {
if (options.out) {
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules"));
}
if (options.outFile) {
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules"));
}
}
if (options.inlineSourceMap) {
@ -825,6 +829,10 @@ namespace ts {
}
}
if (options.out && options.outFile) {
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile"));
}
if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) {
// Error to specify --mapRoot or --sourceRoot without mapSourceFiles
if (options.mapRoot) {
@ -837,6 +845,7 @@ namespace ts {
}
let languageVersion = options.target || ScriptTarget.ES3;
let outFile = options.outFile || options.out;
let firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined);
if (options.isolatedModules) {
@ -866,7 +875,7 @@ namespace ts {
if (options.outDir || // there is --outDir specified
options.sourceRoot || // there is --sourceRoot specified
(options.mapRoot && // there is --mapRoot specified and there would be multiple js files generated
(!options.out || firstExternalModuleSourceFile !== undefined))) {
(!outFile || firstExternalModuleSourceFile !== undefined))) {
if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) {
// If a rootDir is specified and is valid use it as the commonSourceDirectory
@ -890,6 +899,10 @@ namespace ts {
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out"));
}
if (options.outFile) {
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile"));
}
if (options.outDir) {
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir"));
}

View File

@ -2032,6 +2032,7 @@ namespace ts {
noLib?: boolean;
noResolve?: boolean;
out?: string;
outFile?: string;
outDir?: string;
preserveConstEnums?: boolean;
project?: string;

View File

@ -1766,7 +1766,7 @@ namespace ts {
export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean {
if (!isDeclarationFile(sourceFile)) {
if ((isExternalModule(sourceFile) || !compilerOptions.out)) {
if ((isExternalModule(sourceFile) || !(compilerOptions.outFile || compilerOptions.out))) {
// 1. in-browser single file compilation scenario
// 2. non .js file
return compilerOptions.isolatedModules || !fileExtensionIs(sourceFile.fileName, ".js");

View File

@ -123,6 +123,7 @@ module FourSlash {
mapRoot: "mapRoot",
module: "module",
out: "out",
outFile: "outFile",
outDir: "outDir",
sourceMap: "sourceMap",
sourceRoot: "sourceRoot",
@ -133,7 +134,7 @@ module FourSlash {
// List of allowed metadata names
let fileMetadataNames = [metadataOptionNames.fileName, metadataOptionNames.emitThisFile, metadataOptionNames.resolveReference];
let globalMetadataNames = [metadataOptionNames.allowNonTsExtensions, metadataOptionNames.baselineFile, metadataOptionNames.declaration,
metadataOptionNames.mapRoot, metadataOptionNames.module, metadataOptionNames.out,
metadataOptionNames.mapRoot, metadataOptionNames.module, metadataOptionNames.out, metadataOptionNames.outFile,
metadataOptionNames.outDir, metadataOptionNames.sourceMap, metadataOptionNames.sourceRoot];
function convertGlobalOptionsToCompilerOptions(globalOptions: { [idx: string]: string }): ts.CompilerOptions {
@ -169,6 +170,9 @@ module FourSlash {
case metadataOptionNames.out:
settings.out = globalOptions[prop];
break;
case metadataOptionNames.outFile:
settings.outFile = globalOptions[prop];
break;
case metadataOptionNames.outDir:
settings.outDir = globalOptions[prop];
break;
@ -2407,7 +2411,7 @@ module FourSlash {
ts.ScriptTarget.Latest,
ts.sys.useCaseSensitiveFileNames);
let program = ts.createProgram([Harness.Compiler.fourslashFileName, fileName], { out: "fourslashTestOutput.js", noResolve: true, target: ts.ScriptTarget.ES3 }, host);
let program = ts.createProgram([Harness.Compiler.fourslashFileName, fileName], { outFile: "fourslashTestOutput.js", noResolve: true, target: ts.ScriptTarget.ES3 }, host);
let sourceFile = host.getSourceFile(fileName, ts.ScriptTarget.ES3);

View File

@ -1091,6 +1091,10 @@ module Harness {
options.out = setting.value;
break;
case "outfile":
options.outFile = setting.value;
break;
case "outdiroption":
case "outdir":
options.outDir = setting.value;
@ -1229,7 +1233,8 @@ module Harness {
assert(sourceFile, "Program has no source file with name '" + fileName + "'");
// Is this file going to be emitted separately
let sourceFileName: string;
if (ts.isExternalModule(sourceFile) || !options.out) {
let outFile = options.outFile || options.out;
if (ts.isExternalModule(sourceFile) || !outFile) {
if (options.outDir) {
let sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, result.currentDirectoryForProgram);
sourceFilePath = sourceFilePath.replace(result.program.getCommonSourceDirectory(), "");
@ -1241,7 +1246,7 @@ module Harness {
}
else {
// Goes to single --out file
sourceFileName = options.out;
sourceFileName = outFile;
}
let dTsFileName = ts.removeFileExtension(sourceFileName) + ".d.ts";

View File

@ -158,7 +158,7 @@ class ProjectRunner extends RunnerBase {
return {
declaration: !!testCase.declaration,
sourceMap: !!testCase.sourceMap,
out: testCase.out,
outFile: testCase.out,
outDir: testCase.outDir,
mapRoot: testCase.resolveMapRoot && testCase.mapRoot ? ts.sys.resolvePath(testCase.mapRoot) : testCase.mapRoot,
sourceRoot: testCase.resolveSourceRoot && testCase.sourceRoot ? ts.sys.resolvePath(testCase.sourceRoot) : testCase.sourceRoot,
@ -299,7 +299,7 @@ class ProjectRunner extends RunnerBase {
allInputFiles.unshift(findOutpuDtsFile(outputDtsFileName));
}
else {
let outputDtsFileName = ts.removeFileExtension(compilerOptions.out) + ".d.ts";
let outputDtsFileName = ts.removeFileExtension(compilerOptions.outFile|| compilerOptions.out) + ".d.ts";
let outputDtsFile = findOutpuDtsFile(outputDtsFileName);
if (!ts.contains(allInputFiles, outputDtsFile)) {
allInputFiles.unshift(outputDtsFile);

View File

@ -0,0 +1,27 @@
//// [tests/cases/compiler/out-flag2.ts] ////
//// [a.ts]
class A { }
//// [b.ts]
class B { }
//// [c.js]
var A = (function () {
function A() {
}
return A;
})();
var B = (function () {
function B() {
}
return B;
})();
//# sourceMappingURL=c.js.map
//// [c.d.ts]
declare class A {
}
declare class B {
}

View File

@ -0,0 +1,2 @@
//// [c.js.map]
{"version":3,"file":"c.js","sourceRoot":"","sources":["tests/cases/compiler/a.ts","tests/cases/compiler/b.ts"],"names":["A","A.constructor","B","B.constructor"],"mappings":"AACA;IAAAA;IAAUC,CAACA;IAADD,QAACA;AAADA,CAACA,AAAX,IAAW;ACDX;IAAAE;IAAUC,CAACA;IAADD,QAACA;AAADA,CAACA,AAAX,IAAW"}

View File

@ -0,0 +1,104 @@
===================================================================
JsFile: c.js
mapUrl: c.js.map
sourceRoot:
sources: tests/cases/compiler/a.ts,tests/cases/compiler/b.ts
===================================================================
-------------------------------------------------------------------
emittedFile:c.js
sourceFile:tests/cases/compiler/a.ts
-------------------------------------------------------------------
>>>var A = (function () {
1 >
2 >^^^^^^^^^^^^^^^^^^^->
1 >
>
1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0)
---
>>> function A() {
1->^^^^
2 > ^^->
1->
1->Emitted(2, 5) Source(2, 1) + SourceIndex(0) name (A)
---
>>> }
1->^^^^
2 > ^
3 > ^^^^^^^^^->
1->class A {
2 > }
1->Emitted(3, 5) Source(2, 11) + SourceIndex(0) name (A.constructor)
2 >Emitted(3, 6) Source(2, 12) + SourceIndex(0) name (A.constructor)
---
>>> return A;
1->^^^^
2 > ^^^^^^^^
1->
2 > }
1->Emitted(4, 5) Source(2, 11) + SourceIndex(0) name (A)
2 >Emitted(4, 13) Source(2, 12) + SourceIndex(0) name (A)
---
>>>})();
1 >
2 >^
3 >
4 > ^^^^
5 > ^^^^^^^^^^^^^^^^^^->
1 >
2 >}
3 >
4 > class A { }
1 >Emitted(5, 1) Source(2, 11) + SourceIndex(0) name (A)
2 >Emitted(5, 2) Source(2, 12) + SourceIndex(0) name (A)
3 >Emitted(5, 2) Source(2, 1) + SourceIndex(0)
4 >Emitted(5, 6) Source(2, 12) + SourceIndex(0)
---
-------------------------------------------------------------------
emittedFile:c.js
sourceFile:tests/cases/compiler/b.ts
-------------------------------------------------------------------
>>>var B = (function () {
1->
2 >^^^^^^^^^^^^^^^^^^^->
1->
1->Emitted(6, 1) Source(1, 1) + SourceIndex(1)
---
>>> function B() {
1->^^^^
2 > ^^->
1->
1->Emitted(7, 5) Source(1, 1) + SourceIndex(1) name (B)
---
>>> }
1->^^^^
2 > ^
3 > ^^^^^^^^^->
1->class B {
2 > }
1->Emitted(8, 5) Source(1, 11) + SourceIndex(1) name (B.constructor)
2 >Emitted(8, 6) Source(1, 12) + SourceIndex(1) name (B.constructor)
---
>>> return B;
1->^^^^
2 > ^^^^^^^^
1->
2 > }
1->Emitted(9, 5) Source(1, 11) + SourceIndex(1) name (B)
2 >Emitted(9, 13) Source(1, 12) + SourceIndex(1) name (B)
---
>>>})();
1 >
2 >^
3 >
4 > ^^^^
5 > ^^^^^^^^^^^^^^^^^^^^^^^->
1 >
2 >}
3 >
4 > class B { }
1 >Emitted(10, 1) Source(1, 11) + SourceIndex(1) name (B)
2 >Emitted(10, 2) Source(1, 12) + SourceIndex(1) name (B)
3 >Emitted(10, 2) Source(1, 1) + SourceIndex(1)
4 >Emitted(10, 6) Source(1, 12) + SourceIndex(1)
---
>>>//# sourceMappingURL=c.js.map

View File

@ -0,0 +1,9 @@
=== tests/cases/compiler/a.ts ===
class A { }
>A : Symbol(A, Decl(a.ts, 0, 0))
=== tests/cases/compiler/b.ts ===
class B { }
>B : Symbol(B, Decl(b.ts, 0, 0))

View File

@ -0,0 +1,9 @@
=== tests/cases/compiler/a.ts ===
class A { }
>A : A
=== tests/cases/compiler/b.ts ===
class B { }
>B : B

View File

@ -0,0 +1,12 @@
error TS5053: Option 'out' cannot be specified with option 'outFile'.
!!! error TS5053: Option 'out' cannot be specified with option 'outFile'.
==== tests/cases/compiler/a.ts (0 errors) ====
// --out and --outFile error
class A { }
==== tests/cases/compiler/b.ts (0 errors) ====
class B { }

View File

@ -0,0 +1,30 @@
//// [tests/cases/compiler/out-flag3.ts] ////
//// [a.ts]
// --out and --outFile error
class A { }
//// [b.ts]
class B { }
//// [c.js]
// --out and --outFile error
var A = (function () {
function A() {
}
return A;
})();
var B = (function () {
function B() {
}
return B;
})();
//# sourceMappingURL=c.js.map
//// [c.d.ts]
declare class A {
}
declare class B {
}

View File

@ -0,0 +1,2 @@
//// [c.js.map]
{"version":3,"file":"c.js","sourceRoot":"","sources":["tests/cases/compiler/a.ts","tests/cases/compiler/b.ts"],"names":["A","A.constructor","B","B.constructor"],"mappings":"AACA,4BAA4B;AAE5B;IAAAA;IAAUC,CAACA;IAADD,QAACA;AAADA,CAACA,AAAX,IAAW;ACHX;IAAAE;IAAUC,CAACA;IAADD,QAACA;AAADA,CAACA,AAAX,IAAW"}

View File

@ -0,0 +1,114 @@
===================================================================
JsFile: c.js
mapUrl: c.js.map
sourceRoot:
sources: tests/cases/compiler/a.ts,tests/cases/compiler/b.ts
===================================================================
-------------------------------------------------------------------
emittedFile:c.js
sourceFile:tests/cases/compiler/a.ts
-------------------------------------------------------------------
>>>// --out and --outFile error
1 >
2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1 >
>
2 >// --out and --outFile error
1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0)
2 >Emitted(1, 29) Source(2, 29) + SourceIndex(0)
---
>>>var A = (function () {
1 >
2 >^^^^^^^^^^^^^^^^^^^->
1 >
>
>
1 >Emitted(2, 1) Source(4, 1) + SourceIndex(0)
---
>>> function A() {
1->^^^^
2 > ^^->
1->
1->Emitted(3, 5) Source(4, 1) + SourceIndex(0) name (A)
---
>>> }
1->^^^^
2 > ^
3 > ^^^^^^^^^->
1->class A {
2 > }
1->Emitted(4, 5) Source(4, 11) + SourceIndex(0) name (A.constructor)
2 >Emitted(4, 6) Source(4, 12) + SourceIndex(0) name (A.constructor)
---
>>> return A;
1->^^^^
2 > ^^^^^^^^
1->
2 > }
1->Emitted(5, 5) Source(4, 11) + SourceIndex(0) name (A)
2 >Emitted(5, 13) Source(4, 12) + SourceIndex(0) name (A)
---
>>>})();
1 >
2 >^
3 >
4 > ^^^^
5 > ^^^^^^^^^^^^^^^^^^->
1 >
2 >}
3 >
4 > class A { }
1 >Emitted(6, 1) Source(4, 11) + SourceIndex(0) name (A)
2 >Emitted(6, 2) Source(4, 12) + SourceIndex(0) name (A)
3 >Emitted(6, 2) Source(4, 1) + SourceIndex(0)
4 >Emitted(6, 6) Source(4, 12) + SourceIndex(0)
---
-------------------------------------------------------------------
emittedFile:c.js
sourceFile:tests/cases/compiler/b.ts
-------------------------------------------------------------------
>>>var B = (function () {
1->
2 >^^^^^^^^^^^^^^^^^^^->
1->
1->Emitted(7, 1) Source(1, 1) + SourceIndex(1)
---
>>> function B() {
1->^^^^
2 > ^^->
1->
1->Emitted(8, 5) Source(1, 1) + SourceIndex(1) name (B)
---
>>> }
1->^^^^
2 > ^
3 > ^^^^^^^^^->
1->class B {
2 > }
1->Emitted(9, 5) Source(1, 11) + SourceIndex(1) name (B.constructor)
2 >Emitted(9, 6) Source(1, 12) + SourceIndex(1) name (B.constructor)
---
>>> return B;
1->^^^^
2 > ^^^^^^^^
1->
2 > }
1->Emitted(10, 5) Source(1, 11) + SourceIndex(1) name (B)
2 >Emitted(10, 13) Source(1, 12) + SourceIndex(1) name (B)
---
>>>})();
1 >
2 >^
3 >
4 > ^^^^
5 > ^^^^^^^^^^^^^^^^^^^^^^^->
1 >
2 >}
3 >
4 > class B { }
1 >Emitted(11, 1) Source(1, 11) + SourceIndex(1) name (B)
2 >Emitted(11, 2) Source(1, 12) + SourceIndex(1) name (B)
3 >Emitted(11, 2) Source(1, 1) + SourceIndex(1)
4 >Emitted(11, 6) Source(1, 12) + SourceIndex(1)
---
>>>//# sourceMappingURL=c.js.map

View File

@ -0,0 +1,11 @@
// @target: ES5
// @sourcemap: true
// @declaration: true
// @module: commonjs
// @outFile: c.js
// @Filename: a.ts
class A { }
// @Filename: b.ts
class B { }

View File

@ -0,0 +1,14 @@
// @target: ES5
// @sourcemap: true
// @declaration: true
// @module: commonjs
// @outFile: c.js
// @out: d.js
// --out and --outFile error
// @Filename: a.ts
class A { }
// @Filename: b.ts
class B { }