From a87dae15a980e8d9b5e31fa1bd063733a6bb260c Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 12 Oct 2015 12:44:21 -0700 Subject: [PATCH] Verify that when emit blocking error occurs rest of the emit occurs as expected --- src/harness/compilerRunner.ts | 2 +- .../fileReferencesWithNoExtensions.js | 34 +++++++++++++++++++ ...CompilationEmitBlockedCorrectly.errors.txt | 17 ++++++++++ .../jsFileCompilationEmitBlockedCorrectly.js | 23 +++++++++++++ ...ationWithDeclarationEmitPathSameAsInput.js | 15 ++++++++ ...OutDeclarationFileNameSameAsInputJsFile.js | 15 ++++++++ .../jsFileCompilationEmitBlockedCorrectly.ts | 13 +++++++ 7 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/fileReferencesWithNoExtensions.js create mode 100644 tests/baselines/reference/jsFileCompilationEmitBlockedCorrectly.errors.txt create mode 100644 tests/baselines/reference/jsFileCompilationEmitBlockedCorrectly.js create mode 100644 tests/baselines/reference/jsFileCompilationWithDeclarationEmitPathSameAsInput.js create mode 100644 tests/baselines/reference/jsFileCompilationWithOutDeclarationFileNameSameAsInputJsFile.js create mode 100644 tests/cases/compiler/jsFileCompilationEmitBlockedCorrectly.ts diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index d9082532cb5..e3c48e33e5c 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -151,7 +151,7 @@ class CompilerBaselineRunner extends RunnerBase { }); it("Correct JS output for " + fileName, () => { - if (!ts.fileExtensionIs(lastUnit.name, "d.ts") && this.emit) { + if (!(units.length === 1 && ts.fileExtensionIs(lastUnit.name, "d.ts")) && this.emit) { if (result.files.length === 0 && result.errors.length === 0) { throw new Error("Expected at least one js file to be emitted or at least one error to be created."); } diff --git a/tests/baselines/reference/fileReferencesWithNoExtensions.js b/tests/baselines/reference/fileReferencesWithNoExtensions.js new file mode 100644 index 00000000000..48421954c3a --- /dev/null +++ b/tests/baselines/reference/fileReferencesWithNoExtensions.js @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/fileReferencesWithNoExtensions.ts] //// + +//// [t.ts] +/// +/// +/// +var a = aa; // Check that a.ts is referenced +var b = bb; // Check that b.d.ts is referenced +var c = cc; // Check that c.ts has precedence over c.d.ts + +//// [a.ts] +var aa = 1; + +//// [b.d.ts] +declare var bb: number; + +//// [c.ts] +var cc = 1; + +//// [c.d.ts] +declare var xx: number; + + +//// [a.js] +var aa = 1; +//// [c.js] +var cc = 1; +//// [t.js] +/// +/// +/// +var a = aa; // Check that a.ts is referenced +var b = bb; // Check that b.d.ts is referenced +var c = cc; // Check that c.ts has precedence over c.d.ts diff --git a/tests/baselines/reference/jsFileCompilationEmitBlockedCorrectly.errors.txt b/tests/baselines/reference/jsFileCompilationEmitBlockedCorrectly.errors.txt new file mode 100644 index 00000000000..eb9e11e574b --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationEmitBlockedCorrectly.errors.txt @@ -0,0 +1,17 @@ +error TS5055: Cannot write file 'tests/cases/compiler/a.js' which is one of the input files. + + +!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' which is one of the input files. +==== tests/cases/compiler/a.ts (0 errors) ==== + class c { + } + +==== tests/cases/compiler/b.ts (0 errors) ==== + // this should be emitted + class d { + } + +==== tests/cases/compiler/a.js (0 errors) ==== + function foo() { + } + \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationEmitBlockedCorrectly.js b/tests/baselines/reference/jsFileCompilationEmitBlockedCorrectly.js new file mode 100644 index 00000000000..ea9c9f62b8d --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationEmitBlockedCorrectly.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/jsFileCompilationEmitBlockedCorrectly.ts] //// + +//// [a.ts] +class c { +} + +//// [b.ts] +// this should be emitted +class d { +} + +//// [a.js] +function foo() { +} + + +//// [b.js] +// this should be emitted +var d = (function () { + function d() { + } + return d; +})(); diff --git a/tests/baselines/reference/jsFileCompilationWithDeclarationEmitPathSameAsInput.js b/tests/baselines/reference/jsFileCompilationWithDeclarationEmitPathSameAsInput.js new file mode 100644 index 00000000000..a7ba8b49985 --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationWithDeclarationEmitPathSameAsInput.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/jsFileCompilationWithDeclarationEmitPathSameAsInput.ts] //// + +//// [a.ts] +class c { +} + +//// [a.d.ts] +declare function isC(): boolean; + +//// [a.js] +var c = (function () { + function c() { + } + return c; +})(); diff --git a/tests/baselines/reference/jsFileCompilationWithOutDeclarationFileNameSameAsInputJsFile.js b/tests/baselines/reference/jsFileCompilationWithOutDeclarationFileNameSameAsInputJsFile.js new file mode 100644 index 00000000000..d3b2f788d66 --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationWithOutDeclarationFileNameSameAsInputJsFile.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/jsFileCompilationWithOutDeclarationFileNameSameAsInputJsFile.ts] //// + +//// [a.ts] +class c { +} + +//// [b.d.ts] +declare function foo(): boolean; + +//// [b.js] +var c = (function () { + function c() { + } + return c; +})(); diff --git a/tests/cases/compiler/jsFileCompilationEmitBlockedCorrectly.ts b/tests/cases/compiler/jsFileCompilationEmitBlockedCorrectly.ts new file mode 100644 index 00000000000..80f9358fb7f --- /dev/null +++ b/tests/cases/compiler/jsFileCompilationEmitBlockedCorrectly.ts @@ -0,0 +1,13 @@ +// @jsExtensions: js +// @filename: a.ts +class c { +} + +// @filename: b.ts +// this should be emitted +class d { +} + +// @filename: a.js +function foo() { +}