From fb21e70d71e54d8d09826361130c5f8f7c4a1467 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 29 Apr 2019 12:59:53 -0700 Subject: [PATCH] Target affects emit hence mark the option so that all files are reemitted when target changes Fixes #31118 --- src/compiler/commandLineParser.ts | 1 + src/testRunner/unittests/tsbuild/helpers.ts | 2 +- src/testRunner/unittests/tsbuild/sample.ts | 54 +++++++++++- .../when-target-option-changes.js | 71 +++++++++++++++ .../when-target-option-changes.js | 88 +++++++++++++++++++ 5 files changed, 212 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-target-option-changes.js create mode 100644 tests/baselines/reference/tsbuild/sample1/initial-Build/when-target-option-changes.js diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 527217e860e6f..6a03781a758a8 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -218,6 +218,7 @@ namespace ts { }), affectsSourceFile: true, affectsModuleResolution: true, + affectsEmit: true, paramType: Diagnostics.VERSION, showInSimplifiedHelpView: true, category: Diagnostics.Basic_Options, diff --git a/src/testRunner/unittests/tsbuild/helpers.ts b/src/testRunner/unittests/tsbuild/helpers.ts index 88eb61cd422c4..579573a876e6e 100644 --- a/src/testRunner/unittests/tsbuild/helpers.ts +++ b/src/testRunner/unittests/tsbuild/helpers.ts @@ -62,7 +62,7 @@ namespace ts { } } - const libContent = `${TestFSWithWatch.libFile.content} + export const libContent = `${TestFSWithWatch.libFile.content} interface ReadonlyArray {} declare const console: { log(msg: any): void; };`; diff --git a/src/testRunner/unittests/tsbuild/sample.ts b/src/testRunner/unittests/tsbuild/sample.ts index 6e31ada9ee575..5ad63d76dc7ee 100644 --- a/src/testRunner/unittests/tsbuild/sample.ts +++ b/src/testRunner/unittests/tsbuild/sample.ts @@ -279,7 +279,6 @@ namespace ts { [Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/logic/tsconfig.json", "src/logic/index.ts", "src/logic/index.js"], [Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2, "src/tests/tsconfig.json", "src/tests/index.js", "src/tests/tsconfig.json"], [Diagnostics.Building_project_0, "/src/tests/tsconfig.json"], - [Diagnostics.Updating_unchanged_output_timestamps_of_project_0, "/src/tests/tsconfig.json"] ); }); @@ -309,8 +308,7 @@ namespace ts { [Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/core/tsconfig.json", "src/core/anotherModule.ts", "src/core/anotherModule.js"], [Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/logic/tsconfig.json", "src/logic/index.ts", "src/logic/index.js"], [Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2, "src/tests/tsconfig.json", "src/tests/index.js", "src/tests/tsconfig.base.json"], - [Diagnostics.Building_project_0, "/src/tests/tsconfig.json"], - [Diagnostics.Updating_unchanged_output_timestamps_of_project_0, "/src/tests/tsconfig.json"] + [Diagnostics.Building_project_0, "/src/tests/tsconfig.json"] ); }); }); @@ -761,6 +759,56 @@ class someClass { }`), baselineOnly: true, verifyDiagnostics: true }); + + verifyTsbuildOutput({ + scenario: "when target option changes", + projFs: () => projFs, + time, + tick, + proj: "sample1", + rootNames: ["/src/core"], + expectedMapFileNames: emptyArray, + lastProjectOutputJs: "/src/core/index.js", + initialBuild: { + modifyFs: fs => { + fs.writeFileSync("/lib/lib.esnext.full.d.ts", `/// +/// `); + fs.writeFileSync("/lib/lib.esnext.d.ts", libContent); + fs.writeFileSync("/lib/lib.d.ts", `/// +/// `); + fs.writeFileSync("/src/core/tsconfig.json", `{ + "compilerOptions": { + "incremental": true, +"listFiles": true, +"listEmittedFiles": true, + "target": "esnext", + } +}`); + }, + expectedDiagnostics: [ + getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json"), + [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/core/anotherModule.js"], + [Diagnostics.Building_project_0, "/src/core/tsconfig.json"], + ] + }, + incrementalDtsChangedBuild: { + modifyFs: fs => replaceText(fs, "/src/core/tsconfig.json", "esnext", "es5"), + expectedDiagnostics: [ + getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json"), + [Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2, "src/core/tsconfig.json", "src/core/anotherModule.js", "src/core/tsconfig.json"], + [Diagnostics.Building_project_0, "/src/core/tsconfig.json"] + ] + }, + outputFiles: [ + "/src/core/anotherModule.js", + "/src/core/anotherModule.d.ts", + "/src/core/index.js", + "/src/core/index.d.ts", + "/src/core/tsconfig.tsbuildinfo", + ], + baselineOnly: true, + verifyDiagnostics: true + }); }); }); } diff --git a/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-target-option-changes.js b/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-target-option-changes.js new file mode 100644 index 0000000000000..53bd9b167fb6e --- /dev/null +++ b/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-target-option-changes.js @@ -0,0 +1,71 @@ +//// [/src/core/anotherModule.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.World = "hello"; + + +//// [/src/core/index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.someString = "HELLO WORLD"; +function leftPad(s, n) { return s + n; } +exports.leftPad = leftPad; +function multiply(a, b) { return a * b; } +exports.multiply = multiply; + + +//// [/src/core/tsconfig.json] +{ + "compilerOptions": { + "incremental": true, +"listFiles": true, +"listEmittedFiles": true, + "target": "es5", + } +} + +//// [/src/core/tsconfig.tsbuildinfo] +{ + "program": { + "fileInfos": { + "/lib/lib.d.ts": { + "version": "8926001564", + "signature": "8926001564" + }, + "/lib/lib.esnext.d.ts": { + "version": "-15964756381", + "signature": "-15964756381" + }, + "/src/core/anothermodule.ts": { + "version": "-2676574883", + "signature": "-8396256275" + }, + "/src/core/index.ts": { + "version": "-18749805970", + "signature": "1874987148" + }, + "/src/core/some_decl.d.ts": { + "version": "-9253692965", + "signature": "-9253692965" + } + }, + "options": { + "incremental": true, + "listFiles": true, + "listEmittedFiles": true, + "target": 1, + "configFilePath": "/src/core/tsconfig.json" + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "/lib/lib.d.ts", + "/lib/lib.esnext.d.ts", + "/src/core/anothermodule.ts", + "/src/core/index.ts", + "/src/core/some_decl.d.ts" + ] + }, + "version": "FakeTSVersion" +} + diff --git a/tests/baselines/reference/tsbuild/sample1/initial-Build/when-target-option-changes.js b/tests/baselines/reference/tsbuild/sample1/initial-Build/when-target-option-changes.js new file mode 100644 index 0000000000000..fdf7cc3841291 --- /dev/null +++ b/tests/baselines/reference/tsbuild/sample1/initial-Build/when-target-option-changes.js @@ -0,0 +1,88 @@ +//// [/lib/lib.d.ts] +/// +/// + +//// [/lib/lib.esnext.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array {} +interface ReadonlyArray {} +declare const console: { log(msg: any): void; }; + +//// [/lib/lib.esnext.full.d.ts] +/// +/// + +//// [/src/core/anotherModule.js] +export const World = "hello"; + + +//// [/src/core/index.js] +export const someString = "HELLO WORLD"; +export function leftPad(s, n) { return s + n; } +export function multiply(a, b) { return a * b; } + + +//// [/src/core/tsconfig.json] +{ + "compilerOptions": { + "incremental": true, +"listFiles": true, +"listEmittedFiles": true, + "target": "esnext", + } +} + +//// [/src/core/tsconfig.tsbuildinfo] +{ + "program": { + "fileInfos": { + "/lib/lib.esnext.d.ts": { + "version": "-15964756381", + "signature": "-15964756381" + }, + "/lib/lib.esnext.full.d.ts": { + "version": "8926001564", + "signature": "8926001564" + }, + "/src/core/anothermodule.ts": { + "version": "-2676574883", + "signature": "-8396256275" + }, + "/src/core/index.ts": { + "version": "-18749805970", + "signature": "1874987148" + }, + "/src/core/some_decl.d.ts": { + "version": "-9253692965", + "signature": "-9253692965" + } + }, + "options": { + "incremental": true, + "listFiles": true, + "listEmittedFiles": true, + "target": 8, + "configFilePath": "/src/core/tsconfig.json" + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "/lib/lib.esnext.d.ts", + "/lib/lib.esnext.full.d.ts", + "/src/core/anothermodule.ts", + "/src/core/index.ts", + "/src/core/some_decl.d.ts" + ] + }, + "version": "FakeTSVersion" +} +