From d9ad55904294c75a7a4d3a9b3c7153fa561772e9 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 7 Aug 2019 12:36:27 -0700 Subject: [PATCH 01/18] Verify demo build --- src/harness/virtualFileSystemWithWatch.ts | 2 +- src/testRunner/tsconfig.json | 1 + src/testRunner/unittests/tsbuild/demo.ts | 80 +++++++++++++++++++ .../inferred-type-from-transitive-module.js | 4 +- .../inferred-type-from-transitive-module.js | 4 +- ...s-merged-and-contains-late-bound-member.js | 4 +- ...s-merged-and-contains-late-bound-member.js | 4 +- .../incremental-declaration-changes/sample.js | 12 +-- .../when-declaration-option-changes.js | 4 +- .../when-esModuleInterop-option-changes.js | 4 +- ...en-logic-config-changes-declaration-dir.js | 8 +- .../when-module-option-changes.js | 4 +- .../when-target-option-changes.js | 4 +- .../sample.js | 4 +- .../tsbuild/sample1/initial-Build/sample.js | 12 +-- .../when-declaration-option-changes.js | 4 +- .../when-esModuleInterop-option-changes.js | 12 +-- ...en-logic-config-changes-declaration-dir.js | 12 +-- .../when-logic-specifies-tsBuildInfoFile.js | 12 +-- .../when-module-option-changes.js | 4 +- .../when-target-option-changes.js | 6 +- tests/projects/demo/animals/animal.ts | 4 + tests/projects/demo/animals/dog.ts | 18 +++++ tests/projects/demo/animals/index.ts | 5 ++ tests/projects/demo/animals/tsconfig.json | 10 +++ tests/projects/demo/core/tsconfig.json | 7 ++ tests/projects/demo/core/utilities.ts | 10 +++ tests/projects/demo/tsconfig-base.json | 13 +++ tests/projects/demo/tsconfig.json | 14 ++++ tests/projects/demo/zoo/tsconfig.json | 12 +++ tests/projects/demo/zoo/zoo.ts | 9 +++ 31 files changed, 243 insertions(+), 60 deletions(-) create mode 100644 src/testRunner/unittests/tsbuild/demo.ts create mode 100644 tests/projects/demo/animals/animal.ts create mode 100644 tests/projects/demo/animals/dog.ts create mode 100644 tests/projects/demo/animals/index.ts create mode 100644 tests/projects/demo/animals/tsconfig.json create mode 100644 tests/projects/demo/core/tsconfig.json create mode 100644 tests/projects/demo/core/utilities.ts create mode 100644 tests/projects/demo/tsconfig-base.json create mode 100644 tests/projects/demo/tsconfig.json create mode 100644 tests/projects/demo/zoo/tsconfig.json create mode 100644 tests/projects/demo/zoo/zoo.ts diff --git a/src/harness/virtualFileSystemWithWatch.ts b/src/harness/virtualFileSystemWithWatch.ts index 13b87e1c91a..ffb1e19f653 100644 --- a/src/harness/virtualFileSystemWithWatch.ts +++ b/src/harness/virtualFileSystemWithWatch.ts @@ -11,7 +11,7 @@ interface Number { toExponential: any; } interface Object {} interface RegExp {} interface String { charAt: any; } -interface Array {}` +interface Array { length: number; [n: number]: T; }` }; export const safeList = { diff --git a/src/testRunner/tsconfig.json b/src/testRunner/tsconfig.json index e7ff655ce10..c395b05e154 100644 --- a/src/testRunner/tsconfig.json +++ b/src/testRunner/tsconfig.json @@ -93,6 +93,7 @@ "unittests/services/transpile.ts", "unittests/tsbuild/amdModulesWithOut.ts", "unittests/tsbuild/containerOnlyReferenced.ts", + "unittests/tsbuild/demo.ts", "unittests/tsbuild/emptyFiles.ts", "unittests/tsbuild/graphOrdering.ts", "unittests/tsbuild/inferredTypeFromTransitiveModule.ts", diff --git a/src/testRunner/unittests/tsbuild/demo.ts b/src/testRunner/unittests/tsbuild/demo.ts new file mode 100644 index 00000000000..ae34f033b79 --- /dev/null +++ b/src/testRunner/unittests/tsbuild/demo.ts @@ -0,0 +1,80 @@ +namespace ts { + describe("unittests:: tsbuild:: on demo project", () => { + let projFs: vfs.FileSystem; + const { time } = getTime(); + + before(() => { + projFs = loadProjectFromDisk("tests/projects/demo", time); + }); + + after(() => { + projFs = undefined!; // Release the contents + }); + + function coreOutputs(): string[] { + return [ + "/src/lib/core/utilities.js", + "/src/lib/core/utilities.d.ts", + "/src/lib/core/tsconfig.tsbuildinfo" + ]; + } + + function animalOutputs(): string[] { + return [ + "/src/lib/animals/animal.js", + "/src/lib/animals/animal.d.ts", + "/src/lib/animals/index.js", + "/src/lib/animals/index.d.ts", + "/src/lib/animals/dog.js", + "/src/lib/animals/dog.d.ts", + "/src/lib/animals/tsconfig.tsbuildinfo" + ]; + } + + function zooOutputs(): string[] { + return [ + "/src/lib/zoo/zoo.js", + "/src/lib/zoo/zoo.d.ts", + "/src/lib/zoo/tsconfig.tsbuildinfo" + ]; + } + + interface VerifyBuild { + modifyDiskLayout: (fs: vfs.FileSystem) => void; + expectedExitStatus: ExitStatus; + expectedDiagnostics: fakes.ExpectedDiagnostic[]; + expectedOutputs: readonly string[]; + notExpectedOutputs: readonly string[]; + } + + function verifyBuild({ modifyDiskLayout, expectedExitStatus, expectedDiagnostics, expectedOutputs, notExpectedOutputs }: VerifyBuild) { + const fs = projFs.shadow(); + const host = new fakes.SolutionBuilderHost(fs); + modifyDiskLayout(fs); + const builder = createSolutionBuilder(host, ["/src/tsconfig.json"], { verbose: true }); + const exitStatus = builder.build(); + assert.equal(exitStatus, expectedExitStatus); + host.assertDiagnosticMessages(...expectedDiagnostics); + verifyOutputsPresent(fs, expectedOutputs); + verifyOutputsAbsent(fs, notExpectedOutputs); + } + + it("in master branch with everything setup correctly, reports no error", () => { + verifyBuild({ + modifyDiskLayout: noop, + expectedExitStatus: ExitStatus.Success, + expectedDiagnostics: [ + getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json", "src/animals/tsconfig.json", "src/zoo/tsconfig.json", "src/tsconfig.json"), + [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/lib/core/utilities.js"], + [Diagnostics.Building_project_0, "/src/core/tsconfig.json"], + [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/animals/tsconfig.json", "src/lib/animals/animal.js"], + [Diagnostics.Building_project_0, "/src/animals/tsconfig.json"], + [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/zoo/tsconfig.json", "src/lib/zoo/zoo.js"], + [Diagnostics.Building_project_0, "/src/zoo/tsconfig.json"] + ], + expectedOutputs: [...coreOutputs(), ...animalOutputs(), ...zooOutputs()], + notExpectedOutputs: emptyArray + }); + }); + }); +} diff --git a/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/incremental-declaration-changes/inferred-type-from-transitive-module.js b/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/incremental-declaration-changes/inferred-type-from-transitive-module.js index c9334a7bcc9..0c32ba7c167 100644 --- a/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/incremental-declaration-changes/inferred-type-from-transitive-module.js +++ b/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/incremental-declaration-changes/inferred-type-from-transitive-module.js @@ -31,8 +31,8 @@ export declare const lazyBar: LazyAction<() => void, typeof import("./lazyIndex" "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../bar.ts": { "version": "747071916", diff --git a/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/initial-Build/inferred-type-from-transitive-module.js b/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/initial-Build/inferred-type-from-transitive-module.js index 88e0b710bb4..2a6aee9c8db 100644 --- a/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/initial-Build/inferred-type-from-transitive-module.js +++ b/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/initial-Build/inferred-type-from-transitive-module.js @@ -69,8 +69,8 @@ exports.bar = bar_1.default; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../bar.ts": { "version": "5936740878", diff --git a/tests/baselines/reference/tsbuild/lateBoundSymbol/incremental-declaration-doesnt-change/interface-is-merged-and-contains-late-bound-member.js b/tests/baselines/reference/tsbuild/lateBoundSymbol/incremental-declaration-doesnt-change/interface-is-merged-and-contains-late-bound-member.js index bfd580e9a99..84fe88219b1 100644 --- a/tests/baselines/reference/tsbuild/lateBoundSymbol/incremental-declaration-doesnt-change/interface-is-merged-and-contains-late-bound-member.js +++ b/tests/baselines/reference/tsbuild/lateBoundSymbol/incremental-declaration-doesnt-change/interface-is-merged-and-contains-late-bound-member.js @@ -22,8 +22,8 @@ type A = HKT[typeof sym]; "program": { "fileInfos": { "../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "./src/globals.d.ts": { "version": "-1994196675", diff --git a/tests/baselines/reference/tsbuild/lateBoundSymbol/initial-Build/interface-is-merged-and-contains-late-bound-member.js b/tests/baselines/reference/tsbuild/lateBoundSymbol/initial-Build/interface-is-merged-and-contains-late-bound-member.js index d1e15d4ca99..afb887c35f8 100644 --- a/tests/baselines/reference/tsbuild/lateBoundSymbol/initial-Build/interface-is-merged-and-contains-late-bound-member.js +++ b/tests/baselines/reference/tsbuild/lateBoundSymbol/initial-Build/interface-is-merged-and-contains-late-bound-member.js @@ -15,8 +15,8 @@ var x = 10; "program": { "fileInfos": { "../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "./src/globals.d.ts": { "version": "-1994196675", diff --git a/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/sample.js b/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/sample.js index cc92be46021..be4e09ba5b5 100644 --- a/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/sample.js +++ b/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/sample.js @@ -172,8 +172,8 @@ export class someClass { } "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "./anothermodule.ts": { "version": "-2676574883", @@ -212,8 +212,8 @@ export class someClass { } "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../core/index.ts": { "version": "-2069755619", @@ -262,8 +262,8 @@ export class someClass { } "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../core/index.ts": { "version": "-2069755619", diff --git a/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-declaration-option-changes.js b/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-declaration-option-changes.js index d58354590cb..bf28ddcc386 100644 --- a/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-declaration-option-changes.js +++ b/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-declaration-option-changes.js @@ -21,8 +21,8 @@ export declare function multiply(a: number, b: number): number; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "./anothermodule.ts": { "version": "-2676574883", diff --git a/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-esModuleInterop-option-changes.js b/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-esModuleInterop-option-changes.js index 28c559ee72a..e93ed540970 100644 --- a/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-esModuleInterop-option-changes.js +++ b/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-esModuleInterop-option-changes.js @@ -37,8 +37,8 @@ exports.m = mod; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../core/index.ts": { "version": "-13851440507", diff --git a/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-logic-config-changes-declaration-dir.js b/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-logic-config-changes-declaration-dir.js index feefdf8f816..13204cdf566 100644 --- a/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-logic-config-changes-declaration-dir.js +++ b/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-logic-config-changes-declaration-dir.js @@ -25,8 +25,8 @@ export declare const m: typeof mod; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../core/index.ts": { "version": "-13851440507", @@ -76,8 +76,8 @@ export declare const m: typeof mod; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../core/index.ts": { "version": "-13851440507", diff --git a/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-module-option-changes.js b/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-module-option-changes.js index a73ad73c155..bda1af5741c 100644 --- a/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-module-option-changes.js +++ b/tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-module-option-changes.js @@ -31,8 +31,8 @@ define(["require", "exports"], function (require, exports) { "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "./anothermodule.ts": { "version": "-2676574883", 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 index 8e740f6a235..99721cc54b9 100644 --- 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 @@ -33,8 +33,8 @@ exports.multiply = multiply; "signature": "8926001564" }, "../../lib/lib.esnext.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "./anothermodule.ts": { "version": "-2676574883", diff --git a/tests/baselines/reference/tsbuild/sample1/incremental-declaration-doesnt-change/sample.js b/tests/baselines/reference/tsbuild/sample1/incremental-declaration-doesnt-change/sample.js index ed2fb38595b..2b4b56abbf8 100644 --- a/tests/baselines/reference/tsbuild/sample1/incremental-declaration-doesnt-change/sample.js +++ b/tests/baselines/reference/tsbuild/sample1/incremental-declaration-doesnt-change/sample.js @@ -25,8 +25,8 @@ class someClass { } "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "./anothermodule.ts": { "version": "-2676574883", diff --git a/tests/baselines/reference/tsbuild/sample1/initial-Build/sample.js b/tests/baselines/reference/tsbuild/sample1/initial-Build/sample.js index 75e23dfa0af..829dbe1718f 100644 --- a/tests/baselines/reference/tsbuild/sample1/initial-Build/sample.js +++ b/tests/baselines/reference/tsbuild/sample1/initial-Build/sample.js @@ -185,8 +185,8 @@ exports.multiply = multiply; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "./anothermodule.ts": { "version": "-2676574883", @@ -370,8 +370,8 @@ sourceFile:index.ts "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../core/index.ts": { "version": "-13851440507", @@ -436,8 +436,8 @@ exports.m = mod; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../core/index.ts": { "version": "-13851440507", diff --git a/tests/baselines/reference/tsbuild/sample1/initial-Build/when-declaration-option-changes.js b/tests/baselines/reference/tsbuild/sample1/initial-Build/when-declaration-option-changes.js index 8a66ec9da1f..7c05255bfd1 100644 --- a/tests/baselines/reference/tsbuild/sample1/initial-Build/when-declaration-option-changes.js +++ b/tests/baselines/reference/tsbuild/sample1/initial-Build/when-declaration-option-changes.js @@ -27,8 +27,8 @@ exports.multiply = multiply; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "./anothermodule.ts": { "version": "-2676574883", diff --git a/tests/baselines/reference/tsbuild/sample1/initial-Build/when-esModuleInterop-option-changes.js b/tests/baselines/reference/tsbuild/sample1/initial-Build/when-esModuleInterop-option-changes.js index b6f0b53b89c..998c09d4710 100644 --- a/tests/baselines/reference/tsbuild/sample1/initial-Build/when-esModuleInterop-option-changes.js +++ b/tests/baselines/reference/tsbuild/sample1/initial-Build/when-esModuleInterop-option-changes.js @@ -35,8 +35,8 @@ exports.multiply = multiply; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "./anothermodule.ts": { "version": "-2676574883", @@ -96,8 +96,8 @@ exports.m = mod; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../core/index.ts": { "version": "-13851440507", @@ -178,8 +178,8 @@ exports.m = mod; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../core/index.ts": { "version": "-13851440507", diff --git a/tests/baselines/reference/tsbuild/sample1/initial-Build/when-logic-config-changes-declaration-dir.js b/tests/baselines/reference/tsbuild/sample1/initial-Build/when-logic-config-changes-declaration-dir.js index 75e23dfa0af..829dbe1718f 100644 --- a/tests/baselines/reference/tsbuild/sample1/initial-Build/when-logic-config-changes-declaration-dir.js +++ b/tests/baselines/reference/tsbuild/sample1/initial-Build/when-logic-config-changes-declaration-dir.js @@ -185,8 +185,8 @@ exports.multiply = multiply; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "./anothermodule.ts": { "version": "-2676574883", @@ -370,8 +370,8 @@ sourceFile:index.ts "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../core/index.ts": { "version": "-13851440507", @@ -436,8 +436,8 @@ exports.m = mod; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../core/index.ts": { "version": "-13851440507", diff --git a/tests/baselines/reference/tsbuild/sample1/initial-Build/when-logic-specifies-tsBuildInfoFile.js b/tests/baselines/reference/tsbuild/sample1/initial-Build/when-logic-specifies-tsBuildInfoFile.js index f419af6508a..5dab84c64ac 100644 --- a/tests/baselines/reference/tsbuild/sample1/initial-Build/when-logic-specifies-tsBuildInfoFile.js +++ b/tests/baselines/reference/tsbuild/sample1/initial-Build/when-logic-specifies-tsBuildInfoFile.js @@ -185,8 +185,8 @@ exports.multiply = multiply; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "./anothermodule.ts": { "version": "-2676574883", @@ -370,8 +370,8 @@ sourceFile:index.ts "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../core/index.ts": { "version": "-13851440507", @@ -453,8 +453,8 @@ exports.m = mod; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../core/index.ts": { "version": "-13851440507", diff --git a/tests/baselines/reference/tsbuild/sample1/initial-Build/when-module-option-changes.js b/tests/baselines/reference/tsbuild/sample1/initial-Build/when-module-option-changes.js index 54e0f764dac..abc90d83d09 100644 --- a/tests/baselines/reference/tsbuild/sample1/initial-Build/when-module-option-changes.js +++ b/tests/baselines/reference/tsbuild/sample1/initial-Build/when-module-option-changes.js @@ -27,8 +27,8 @@ exports.multiply = multiply; "program": { "fileInfos": { "../../lib/lib.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "./anothermodule.ts": { "version": "-2676574883", 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 index c31d39c0647..74efec1e633 100644 --- 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 @@ -13,7 +13,7 @@ interface Number { toExponential: any; } interface Object {} interface RegExp {} interface String { charAt: any; } -interface Array {} +interface Array { length: number; [n: number]: T; } interface ReadonlyArray {} declare const console: { log(msg: any): void; }; @@ -46,8 +46,8 @@ export function multiply(a, b) { return a * b; } "program": { "fileInfos": { "../../lib/lib.esnext.d.ts": { - "version": "-15964756381", - "signature": "-15964756381" + "version": "3858781397", + "signature": "3858781397" }, "../../lib/lib.esnext.full.d.ts": { "version": "8926001564", diff --git a/tests/projects/demo/animals/animal.ts b/tests/projects/demo/animals/animal.ts new file mode 100644 index 00000000000..30727d46489 --- /dev/null +++ b/tests/projects/demo/animals/animal.ts @@ -0,0 +1,4 @@ +export type Size = "small" | "medium" | "large"; +export default interface Animal { + size: Size; +} diff --git a/tests/projects/demo/animals/dog.ts b/tests/projects/demo/animals/dog.ts new file mode 100644 index 00000000000..3e51978e7f0 --- /dev/null +++ b/tests/projects/demo/animals/dog.ts @@ -0,0 +1,18 @@ +import Animal from '.'; +import { makeRandomName } from '../core/utilities'; + +export interface Dog extends Animal { + woof(): void; + name: string; +} + +export function createDog(): Dog { + return ({ + size: "medium", + woof: function(this: Dog) { + console.log(`${this.name} says "Woof"!`); + }, + name: makeRandomName() + }); +} + diff --git a/tests/projects/demo/animals/index.ts b/tests/projects/demo/animals/index.ts new file mode 100644 index 00000000000..9d4734f2eb7 --- /dev/null +++ b/tests/projects/demo/animals/index.ts @@ -0,0 +1,5 @@ +import Animal from './animal'; + +export default Animal; +import { createDog, Dog } from './dog'; +export { createDog, Dog }; diff --git a/tests/projects/demo/animals/tsconfig.json b/tests/projects/demo/animals/tsconfig.json new file mode 100644 index 00000000000..f6b2cc49e44 --- /dev/null +++ b/tests/projects/demo/animals/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig-base.json", + "compilerOptions": { + "outDir": "../lib/animals", + "rootDir": ".", + }, + "references": [ + { "path": "../core" } + ] +} diff --git a/tests/projects/demo/core/tsconfig.json b/tests/projects/demo/core/tsconfig.json new file mode 100644 index 00000000000..9b381b9a5cf --- /dev/null +++ b/tests/projects/demo/core/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../tsconfig-base.json", + "compilerOptions": { + "outDir": "../lib/core", + "rootDir": "." + } +} \ No newline at end of file diff --git a/tests/projects/demo/core/utilities.ts b/tests/projects/demo/core/utilities.ts new file mode 100644 index 00000000000..0988afaf4c3 --- /dev/null +++ b/tests/projects/demo/core/utilities.ts @@ -0,0 +1,10 @@ + +export function makeRandomName() { + return "Bob!?! "; +} + +export function lastElementOf(arr: T[]): T | undefined { + if (arr.length === 0) return undefined; + return arr[arr.length - 1]; +} + diff --git a/tests/projects/demo/tsconfig-base.json b/tests/projects/demo/tsconfig-base.json new file mode 100644 index 00000000000..e5d5ba5c7ce --- /dev/null +++ b/tests/projects/demo/tsconfig-base.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "declaration": true, + "target": "es5", + "module": "commonjs", + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "composite": true + } +} \ No newline at end of file diff --git a/tests/projects/demo/tsconfig.json b/tests/projects/demo/tsconfig.json new file mode 100644 index 00000000000..a140d4ef8e2 --- /dev/null +++ b/tests/projects/demo/tsconfig.json @@ -0,0 +1,14 @@ +{ + "files": [], + "references": [ + { + "path": "./core" + }, + { + "path": "./animals" + }, + { + "path": "./zoo" + } + ] +} \ No newline at end of file diff --git a/tests/projects/demo/zoo/tsconfig.json b/tests/projects/demo/zoo/tsconfig.json new file mode 100644 index 00000000000..318c0dc06b6 --- /dev/null +++ b/tests/projects/demo/zoo/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../tsconfig-base.json", + "compilerOptions": { + "outDir": "../lib/zoo", + "rootDir": "." + }, + "references": [ + { + "path": "../animals" + } + ] +} \ No newline at end of file diff --git a/tests/projects/demo/zoo/zoo.ts b/tests/projects/demo/zoo/zoo.ts new file mode 100644 index 00000000000..a00ad8a79e4 --- /dev/null +++ b/tests/projects/demo/zoo/zoo.ts @@ -0,0 +1,9 @@ +// import Animal from '../animals/index'; +import { Dog, createDog } from '../animals/index'; + +export function createZoo(): Array { + return [ + createDog() + ]; +} + From 94d54b967de8723acf965a31007746a72e3a0ff8 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 7 Aug 2019 13:17:02 -0700 Subject: [PATCH 02/18] Circular reference in the build queue is build stoppable error --- src/compiler/tsbuild.ts | 107 +++++++++++++----- src/compiler/types.ts | 3 + src/testRunner/unittests/tsbuild/demo.ts | 31 +++++ .../unittests/tsbuild/graphOrdering.ts | 32 ++++-- src/testRunner/unittests/tsbuild/watchMode.ts | 87 +++++++++++++- .../reference/api/tsserverlibrary.d.ts | 3 +- tests/baselines/reference/api/typescript.d.ts | 3 +- 7 files changed, 222 insertions(+), 44 deletions(-) diff --git a/src/compiler/tsbuild.ts b/src/compiler/tsbuild.ts index ba051ac23b2..4012619a0c6 100644 --- a/src/compiler/tsbuild.ts +++ b/src/compiler/tsbuild.ts @@ -273,6 +273,26 @@ namespace ts { export interface SolutionBuilderWithWatchHost extends SolutionBuilderHostBase, WatchHost { } + /*@internal*/ + export type BuildOrder = readonly ResolvedConfigFileName[]; + /*@internal*/ + export interface CircularBuildOrder { + buildOrder: BuildOrder; + circularDiagnostics: readonly Diagnostic[]; + } + /*@internal*/ + export type AnyBuildOrder = BuildOrder | CircularBuildOrder; + + /*@internal*/ + export function isCircularBuildOrder(buildOrder: AnyBuildOrder): buildOrder is CircularBuildOrder { + return !!buildOrder && !!(buildOrder as CircularBuildOrder).buildOrder; + } + + /*@internal*/ + export function getBuildOrderFromAnyBuildOrder(anyBuildOrder: AnyBuildOrder): BuildOrder { + return isCircularBuildOrder(anyBuildOrder) ? anyBuildOrder.buildOrder : anyBuildOrder; + } + export interface SolutionBuilder { build(project?: string, cancellationToken?: CancellationToken): ExitStatus; clean(project?: string): ExitStatus; @@ -281,7 +301,7 @@ namespace ts { getNextInvalidatedProject(cancellationToken?: CancellationToken): InvalidatedProject | undefined; // Currently used for testing but can be made public if needed: - /*@internal*/ getBuildOrder(): ReadonlyArray; + /*@internal*/ getBuildOrder(): AnyBuildOrder; // Testing only /*@internal*/ getUpToDateStatusOfProject(project: string): UpToDateStatus; @@ -379,7 +399,7 @@ namespace ts { readonly moduleResolutionCache: ModuleResolutionCache | undefined; // Mutable state - buildOrder: readonly ResolvedConfigFileName[] | undefined; + buildOrder: AnyBuildOrder | undefined; readFileWithCache: (f: string) => string | undefined; projectCompilerOptions: CompilerOptions; cache: SolutionBuilderStateCache | undefined; @@ -523,16 +543,19 @@ namespace ts { return resolveConfigFileProjectName(resolvePath(state.currentDirectory, name)); } - function createBuildOrder(state: SolutionBuilderState, roots: readonly ResolvedConfigFileName[]): readonly ResolvedConfigFileName[] { + function createBuildOrder(state: SolutionBuilderState, roots: readonly ResolvedConfigFileName[]): AnyBuildOrder { const temporaryMarks = createMap() as ConfigFileMap; const permanentMarks = createMap() as ConfigFileMap; const circularityReportStack: string[] = []; let buildOrder: ResolvedConfigFileName[] | undefined; + let circularDiagnostics: Diagnostic[] | undefined; for (const root of roots) { visit(root); } - return buildOrder || emptyArray; + return circularDiagnostics ? + { buildOrder: buildOrder || emptyArray, circularDiagnostics } : + buildOrder || emptyArray; function visit(configFileName: ResolvedConfigFileName, inCircularContext?: boolean) { const projPath = toResolvedConfigFilePath(state, configFileName); @@ -541,8 +564,12 @@ namespace ts { // Circular if (temporaryMarks.has(projPath)) { if (!inCircularContext) { - // TODO:: Do we report this as error? - reportStatus(state, Diagnostics.Project_references_may_not_form_a_circular_graph_Cycle_detected_Colon_0, circularityReportStack.join("\r\n")); + (circularDiagnostics || (circularDiagnostics = [])).push( + createCompilerDiagnostic( + Diagnostics.Project_references_may_not_form_a_circular_graph_Cycle_detected_Colon_0, + circularityReportStack.join("\r\n") + ) + ); } return; } @@ -569,12 +596,11 @@ namespace ts { function createStateBuildOrder(state: SolutionBuilderState) { const buildOrder = createBuildOrder(state, state.rootNames.map(f => resolveProjectName(state, f))); - if (arrayIsEqualTo(state.buildOrder, buildOrder)) return state.buildOrder!; // Clear all to ResolvedConfigFilePaths cache to start fresh state.resolvedConfigFilePaths.clear(); const currentProjects = arrayToSet( - buildOrder, + getBuildOrderFromAnyBuildOrder(buildOrder), resolved => toResolvedConfigFilePath(state, resolved) ) as ConfigFileMap; @@ -611,9 +637,10 @@ namespace ts { return state.buildOrder = buildOrder; } - function getBuildOrderFor(state: SolutionBuilderState, project: string | undefined, onlyReferences: boolean | undefined) { + function getBuildOrderFor(state: SolutionBuilderState, project: string | undefined, onlyReferences: boolean | undefined): AnyBuildOrder | undefined { const resolvedProject = project && resolveProjectName(state, project); const buildOrderFromState = getBuildOrder(state); + if (isCircularBuildOrder(buildOrderFromState)) return buildOrderFromState; if (resolvedProject) { const projectPath = toResolvedConfigFilePath(state, resolvedProject); const projectIndex = findIndex( @@ -622,7 +649,8 @@ namespace ts { ); if (projectIndex === -1) return undefined; } - const buildOrder = resolvedProject ? createBuildOrder(state, [resolvedProject]) : buildOrderFromState; + const buildOrder = resolvedProject ? createBuildOrder(state, [resolvedProject]) as BuildOrder : buildOrderFromState; + Debug.assert(!isCircularBuildOrder(buildOrder)); Debug.assert(!onlyReferences || resolvedProject !== undefined); Debug.assert(!onlyReferences || buildOrder[buildOrder.length - 1] === resolvedProject); return onlyReferences ? buildOrder.slice(0, buildOrder.length - 1) : buildOrder; @@ -702,7 +730,7 @@ namespace ts { state.allProjectBuildPending = false; if (state.options.watch) { reportWatchStatus(state, Diagnostics.Starting_compilation_in_watch_mode); } enableCache(state); - const buildOrder = getBuildOrder(state); + const buildOrder = getBuildOrderFromAnyBuildOrder(getBuildOrder(state)); buildOrder.forEach(configFileName => state.projectPendingBuild.set( toResolvedConfigFilePath(state, configFileName), @@ -1237,10 +1265,11 @@ namespace ts { function getNextInvalidatedProject( state: SolutionBuilderState, - buildOrder: readonly ResolvedConfigFileName[], + buildOrder: AnyBuildOrder, reportQueue: boolean ): InvalidatedProject | undefined { if (!state.projectPendingBuild.size) return undefined; + if (isCircularBuildOrder(buildOrder)) return undefined; if (state.currentInvalidatedProject) { // Only if same buildOrder the currentInvalidated project can be sent again return arrayIsEqualTo(state.currentInvalidatedProject.buildOrder, buildOrder) ? @@ -1763,17 +1792,24 @@ namespace ts { reportErrorSummary(state, buildOrder); startWatching(state, buildOrder); - return errorProjects ? - successfulProjects ? - ExitStatus.DiagnosticsPresent_OutputsGenerated : - ExitStatus.DiagnosticsPresent_OutputsSkipped : - ExitStatus.Success; + return isCircularBuildOrder(buildOrder) ? + ExitStatus.ProjectReferenceCycle_OutputsSkupped : + errorProjects ? + successfulProjects ? + ExitStatus.DiagnosticsPresent_OutputsGenerated : + ExitStatus.DiagnosticsPresent_OutputsSkipped : + ExitStatus.Success; } function clean(state: SolutionBuilderState, project?: string, onlyReferences?: boolean) { const buildOrder = getBuildOrderFor(state, project, onlyReferences); if (!buildOrder) return ExitStatus.InvalidProject_OutputsSkipped; + if (isCircularBuildOrder(buildOrder)) { + reportErrors(state, buildOrder.circularDiagnostics); + return ExitStatus.ProjectReferenceCycle_OutputsSkupped; + } + const { options, host } = state; const filesToDelete = options.dry ? [] as string[] : undefined; for (const proj of buildOrder) { @@ -1955,10 +1991,10 @@ namespace ts { ); } - function startWatching(state: SolutionBuilderState, buildOrder: readonly ResolvedConfigFileName[]) { + function startWatching(state: SolutionBuilderState, buildOrder: AnyBuildOrder) { if (!state.watchAllProjectsPending) return; state.watchAllProjectsPending = false; - for (const resolved of buildOrder) { + for (const resolved of getBuildOrderFromAnyBuildOrder(buildOrder)) { const resolvedPath = toResolvedConfigFilePath(state, resolved); // Watch this file watchConfigFile(state, resolved, resolvedPath); @@ -2032,24 +2068,33 @@ namespace ts { reportAndStoreErrors(state, proj, [state.configFileCache.get(proj) as Diagnostic]); } - function reportErrorSummary(state: SolutionBuilderState, buildOrder: readonly ResolvedConfigFileName[]) { - if (!state.needsSummary || (!state.watch && !state.host.reportErrorSummary)) return; + function reportErrorSummary(state: SolutionBuilderState, buildOrder: AnyBuildOrder) { + if (!state.needsSummary) return; state.needsSummary = false; + const canReportSummary = state.watch || !!state.host.reportErrorSummary; const { diagnostics } = state; - // Report errors from the other projects - buildOrder.forEach(project => { - const projectPath = toResolvedConfigFilePath(state, project); - if (!state.projectErrorsReported.has(projectPath)) { - reportErrors(state, diagnostics.get(projectPath) || emptyArray); - } - }); let totalErrors = 0; - diagnostics.forEach(singleProjectErrors => totalErrors += getErrorCountForSummary(singleProjectErrors)); + if (isCircularBuildOrder(buildOrder)) { + reportBuildQueue(state, buildOrder.buildOrder); + reportErrors(state, buildOrder.circularDiagnostics); + if (canReportSummary) totalErrors += getErrorCountForSummary(buildOrder.circularDiagnostics); + } + else { + // Report errors from the other projects + buildOrder.forEach(project => { + const projectPath = toResolvedConfigFilePath(state, project); + if (!state.projectErrorsReported.has(projectPath)) { + reportErrors(state, diagnostics.get(projectPath) || emptyArray); + } + }); + if (canReportSummary) diagnostics.forEach(singleProjectErrors => totalErrors += getErrorCountForSummary(singleProjectErrors)); + } + if (state.watch) { reportWatchStatus(state, getWatchErrorSummaryDiagnosticMessage(totalErrors), totalErrors); } - else { - state.host.reportErrorSummary!(totalErrors); + else if (state.host.reportErrorSummary) { + state.host.reportErrorSummary(totalErrors); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3f1b30feb45..2d835c5a84f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3079,6 +3079,9 @@ namespace ts { // When build skipped because passed in project is invalid InvalidProject_OutputsSkipped = 3, + + // When build is skipped because project references form cycle + ProjectReferenceCycle_OutputsSkupped = 4, } export interface EmitResult { diff --git a/src/testRunner/unittests/tsbuild/demo.ts b/src/testRunner/unittests/tsbuild/demo.ts index ae34f033b79..b5cd72b2db7 100644 --- a/src/testRunner/unittests/tsbuild/demo.ts +++ b/src/testRunner/unittests/tsbuild/demo.ts @@ -76,5 +76,36 @@ namespace ts { notExpectedOutputs: emptyArray }); }); + + it("in circular branch reports the error about it by stopping build", () => { + verifyBuild({ + modifyDiskLayout: fs => replaceText( + fs, + "/src/core/tsconfig.json", + "}", + `}, + "references": [ + { + "path": "../zoo" + } + ]` + ), + expectedExitStatus: ExitStatus.ProjectReferenceCycle_OutputsSkupped, + expectedDiagnostics: [ + getExpectedDiagnosticForProjectsInBuild("src/animals/tsconfig.json", "src/zoo/tsconfig.json", "src/core/tsconfig.json", "src/tsconfig.json"), + [ + Diagnostics.Project_references_may_not_form_a_circular_graph_Cycle_detected_Colon_0, + [ + "/src/tsconfig.json", + "/src/core/tsconfig.json", + "/src/zoo/tsconfig.json", + "/src/animals/tsconfig.json" + ].join("\r\n") + ] + ], + expectedOutputs: emptyArray, + notExpectedOutputs: [...coreOutputs(), ...animalOutputs(), ...zooOutputs()] + }); + }); }); } diff --git a/src/testRunner/unittests/tsbuild/graphOrdering.ts b/src/testRunner/unittests/tsbuild/graphOrdering.ts index a8f4c3a57a9..d2fa94abd03 100644 --- a/src/testRunner/unittests/tsbuild/graphOrdering.ts +++ b/src/testRunner/unittests/tsbuild/graphOrdering.ts @@ -8,13 +8,17 @@ namespace ts { ["B", "D"], ["C", "D"], ["C", "E"], - ["F", "E"] + ["F", "E"], + ["H", "I"], + ["I", "J"], + ["J", "H"], + ["J", "E"] ]; before(() => { const fs = new vfs.FileSystem(false); host = new fakes.SolutionBuilderHost(fs); - writeProjects(fs, ["A", "B", "C", "D", "E", "F", "G"], deps); + writeProjects(fs, ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"], deps); }); after(() => { @@ -37,17 +41,25 @@ namespace ts { checkGraphOrdering(["F", "C", "A"], ["E", "F", "D", "C", "B", "A"]); }); - function checkGraphOrdering(rootNames: string[], expectedBuildSet: string[]) { - const builder = createSolutionBuilder(host!, rootNames.map(getProjectFileName), { dry: true, force: false, verbose: false }); - const buildQueue = builder.getBuildOrder(); + it("returns circular order", () => { + checkGraphOrdering(["H"], ["E", "J", "I", "H"], /*circular*/ true); + checkGraphOrdering(["A", "H"], ["D", "E", "C", "B", "A", "J", "I", "H"], /*circular*/ true); + }); + function checkGraphOrdering(rootNames: string[], expectedBuildSet: string[], circular?: true) { + const builder = createSolutionBuilder(host!, rootNames.map(getProjectFileName), { dry: true, force: false, verbose: false }); + const buildOrder = builder.getBuildOrder(); + assert.equal(isCircularBuildOrder(buildOrder), !!circular); + const buildQueue = getBuildOrderFromAnyBuildOrder(buildOrder); assert.deepEqual(buildQueue, expectedBuildSet.map(getProjectFileName)); - for (const dep of deps) { - const child = getProjectFileName(dep[0]); - if (buildQueue.indexOf(child) < 0) continue; - const parent = getProjectFileName(dep[1]); - assert.isAbove(buildQueue.indexOf(child), buildQueue.indexOf(parent), `Expecting child ${child} to be built after parent ${parent}`); + if (!circular) { + for (const dep of deps) { + const child = getProjectFileName(dep[0]); + if (buildQueue.indexOf(child) < 0) continue; + const parent = getProjectFileName(dep[1]); + assert.isAbove(buildQueue.indexOf(child), buildQueue.indexOf(parent), `Expecting child ${child} to be built after parent ${parent}`); + } } } diff --git a/src/testRunner/unittests/tsbuild/watchMode.ts b/src/testRunner/unittests/tsbuild/watchMode.ts index bd7653b6bea..5c4fd5c5259 100644 --- a/src/testRunner/unittests/tsbuild/watchMode.ts +++ b/src/testRunner/unittests/tsbuild/watchMode.ts @@ -16,7 +16,6 @@ namespace ts.tscWatch { return host; } - export function createSolutionBuilder(system: WatchedSystem, rootNames: ReadonlyArray, defaultOptions?: BuildOptions) { const host = createSolutionBuilderHost(system); host.now = system.now.bind(system); @@ -1229,4 +1228,90 @@ export function someFn() { }`); ]); }); }); + + describe("unittests:: tsbuild:: watchMode:: with demo project", () => { + const projectLocation = `${projectsLocation}/demo`; + let coreFiles: File[]; + let animalFiles: File[]; + let zooFiles: File[]; + let solutionFile: File; + let baseConfig: File; + let allFilesExceptBase: File[]; + before(() => { + coreFiles = subProjectFiles("core", ["tsconfig.json", "utilities.ts"]); + animalFiles = subProjectFiles("animals", ["tsconfig.json", "animal.ts", "dog.ts", "index.ts"]); + zooFiles = subProjectFiles("zoo", ["tsconfig.json", "zoo.ts"]); + solutionFile = projectFile("tsconfig.json"); + baseConfig = projectFile("tsconfig-base.json"); + allFilesExceptBase = [...coreFiles, ...animalFiles, ...zooFiles, solutionFile]; + }); + + after(() => { + coreFiles = undefined!; + animalFiles = undefined!; + zooFiles = undefined!; + solutionFile = undefined!; + baseConfig = undefined!; + allFilesExceptBase = undefined!; + }); + + it("updates with circular reference", () => { + const host = createTsBuildWatchSystem([ + ...allFilesExceptBase, + baseConfig, + { path: libFile.path, content: libContent } + ], { currentDirectory: projectLocation }); + host.writeFile(coreFiles[0].path, coreFiles[0].content.replace( + "}", + `}, + "references": [ + { + "path": "../zoo" + } + ]` + )); + createSolutionBuilderWithWatch(host, ["tsconfig.json"], { verbose: true, watch: true }); + checkOutputErrorsInitial(host, [ + `error TS6202: Project references may not form a circular graph. Cycle detected: /user/username/projects/demo/tsconfig.json\r\n/user/username/projects/demo/core/tsconfig.json\r\n/user/username/projects/demo/zoo/tsconfig.json\r\n/user/username/projects/demo/animals/tsconfig.json\n` + ], /*disableConsoleClears*/ undefined, [ + `Projects in this build: \r\n * animals/tsconfig.json\r\n * zoo/tsconfig.json\r\n * core/tsconfig.json\r\n * tsconfig.json\n\n` + ]); + verifyWatches(host); + + // Make changes + host.writeFile(coreFiles[0].path, coreFiles[0].content); + host.checkTimeoutQueueLengthAndRun(1); // build core + host.checkTimeoutQueueLengthAndRun(1); // build animals + host.checkTimeoutQueueLengthAndRun(1); // build zoo + host.checkTimeoutQueueLengthAndRun(1); // build solution + host.checkTimeoutQueueLength(0); + checkOutputErrorsIncremental(host, emptyArray, /*disableConsoleClears*/ undefined, /*logsBeforeWatchDiagnostics*/ undefined, [ + `Project 'core/tsconfig.json' is out of date because output file 'lib/core/utilities.js' does not exist\n\n`, + `Building project '/user/username/projects/demo/core/tsconfig.json'...\n\n`, + `Project 'animals/tsconfig.json' is out of date because output file 'lib/animals/animal.js' does not exist\n\n`, + `Building project '/user/username/projects/demo/animals/tsconfig.json'...\n\n`, + `Project 'zoo/tsconfig.json' is out of date because output file 'lib/zoo/zoo.js' does not exist\n\n`, + `Building project '/user/username/projects/demo/zoo/tsconfig.json'...\n\n`, + ]); + }); + + function subProjectFiles(subProject: string, fileNames: readonly string[]): File[] { + return fileNames.map(file => projectFile(`${subProject}/${file}`)); + } + + function projectFile(fileName: string): File { + return getFileFromProject("demo", fileName); + } + + function verifyWatches(host: TsBuildWatchSystem) { + checkWatchedFilesDetailed(host, allFilesExceptBase.map(f => f.path), 1); + checkWatchedDirectories(host, emptyArray, /*recursive*/ false); + checkWatchedDirectoriesDetailed( + host, + [`${projectLocation}/core`, `${projectLocation}/animals`, `${projectLocation}/zoo`], + 1, + /*recursive*/ true + ); + } + }); } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 2f5960f9c21..b47170aacf7 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -1917,7 +1917,8 @@ declare namespace ts { Success = 0, DiagnosticsPresent_OutputsSkipped = 1, DiagnosticsPresent_OutputsGenerated = 2, - InvalidProject_OutputsSkipped = 3 + InvalidProject_OutputsSkipped = 3, + ProjectReferenceCycle_OutputsSkupped = 4 } export interface EmitResult { emitSkipped: boolean; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 0b7ee8d086d..d7e6d9f8d5d 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1917,7 +1917,8 @@ declare namespace ts { Success = 0, DiagnosticsPresent_OutputsSkipped = 1, DiagnosticsPresent_OutputsGenerated = 2, - InvalidProject_OutputsSkipped = 3 + InvalidProject_OutputsSkipped = 3, + ProjectReferenceCycle_OutputsSkupped = 4 } export interface EmitResult { emitSkipped: boolean; From 9e8fbcd7f8d5f1edc91655418f74da9ce87fd525 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 8 Aug 2019 12:40:43 -0700 Subject: [PATCH 03/18] Transitively upstream blocked project should not build --- src/compiler/diagnosticMessages.json | 8 +++++++ src/compiler/tsbuild.ts | 22 ++++++++++++++---- src/testRunner/unittests/tsbuild/demo.ts | 29 ++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 4528d504d0d..23f60c22a64 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4172,6 +4172,14 @@ "category": "Message", "code": 6381 }, + "Skipping build of project '{0}' because its dependency '{1}' was not built": { + "category": "Message", + "code": 6382 + }, + "Project '{0}' can't be built because its dependency '{1}' was not built": { + "category": "Message", + "code": 6383 + }, "The expected type comes from property '{0}' which is declared here on type '{1}'": { "category": "Message", diff --git a/src/compiler/tsbuild.ts b/src/compiler/tsbuild.ts index 4012619a0c6..0503d0a49da 100644 --- a/src/compiler/tsbuild.ts +++ b/src/compiler/tsbuild.ts @@ -116,6 +116,7 @@ namespace ts { export interface UpstreamBlocked { type: UpToDateStatusType.UpstreamBlocked; upstreamProjectName: string; + upstreamProjectBlocked: boolean; } /** @@ -1338,7 +1339,16 @@ namespace ts { if (status.type === UpToDateStatusType.UpstreamBlocked) { reportAndStoreErrors(state, projectPath, config.errors); projectPendingBuild.delete(projectPath); - if (options.verbose) reportStatus(state, Diagnostics.Skipping_build_of_project_0_because_its_dependency_1_has_errors, project, status.upstreamProjectName); + if (options.verbose) { + reportStatus( + state, + status.upstreamProjectBlocked ? + Diagnostics.Skipping_build_of_project_0_because_its_dependency_1_was_not_built : + Diagnostics.Skipping_build_of_project_0_because_its_dependency_1_has_errors, + project, + status.upstreamProjectName + ); + } continue; } @@ -1540,10 +1550,12 @@ namespace ts { } // An upstream project is blocked - if (refStatus.type === UpToDateStatusType.Unbuildable) { + if (refStatus.type === UpToDateStatusType.Unbuildable || + refStatus.type === UpToDateStatusType.UpstreamBlocked) { return { type: UpToDateStatusType.UpstreamBlocked, - upstreamProjectName: ref.path + upstreamProjectName: ref.path, + upstreamProjectBlocked: refStatus.type === UpToDateStatusType.UpstreamBlocked }; } @@ -2167,7 +2179,9 @@ namespace ts { case UpToDateStatusType.UpstreamBlocked: return reportStatus( state, - Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_has_errors, + status.upstreamProjectBlocked ? + Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_was_not_built : + Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_has_errors, relName(state, configFileName), relName(state, status.upstreamProjectName) ); diff --git a/src/testRunner/unittests/tsbuild/demo.ts b/src/testRunner/unittests/tsbuild/demo.ts index b5cd72b2db7..71e82fc5334 100644 --- a/src/testRunner/unittests/tsbuild/demo.ts +++ b/src/testRunner/unittests/tsbuild/demo.ts @@ -107,5 +107,34 @@ namespace ts { notExpectedOutputs: [...coreOutputs(), ...animalOutputs(), ...zooOutputs()] }); }); + + it("in bad-ref branch reports the error about files not in rootDir at the import location", () => { + verifyBuild({ + modifyDiskLayout: fs => prependText( + fs, + "/src/core/utilities.ts", + `import * as A from '../animals'; +` + ), + expectedExitStatus: ExitStatus.DiagnosticsPresent_OutputsSkipped, + expectedDiagnostics: [ + getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json", "src/animals/tsconfig.json", "src/zoo/tsconfig.json", "src/tsconfig.json"), + [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/lib/core/utilities.js"], + [Diagnostics.Building_project_0, "/src/core/tsconfig.json"], + [Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/animal.ts", "/src/core"], + [Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/dog.ts", "/src/core"], + [Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/index.ts", "/src/core"], + [Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/animal.ts", "/src/core/tsconfig.json"], + [Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/dog.ts", "/src/core/tsconfig.json"], + [Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/index.ts", "/src/core/tsconfig.json"], + [Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_has_errors, "src/animals/tsconfig.json", "src/core"], + [Diagnostics.Skipping_build_of_project_0_because_its_dependency_1_has_errors, "/src/animals/tsconfig.json", "/src/core"], + [Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_was_not_built, "src/zoo/tsconfig.json", "src/animals"], + [Diagnostics.Skipping_build_of_project_0_because_its_dependency_1_was_not_built, "/src/zoo/tsconfig.json", "/src/animals"], + ], + expectedOutputs: emptyArray, + notExpectedOutputs: [...coreOutputs(), ...animalOutputs(), ...zooOutputs()] + }); + }); }); } From fd515b519ef1b643071cd4179c6fe4bf36c38a99 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 8 Aug 2019 14:29:42 -0700 Subject: [PATCH 04/18] Handle status and error messages for better checking --- src/harness/fakes.ts | 119 ++++++++++++++++-- src/testRunner/unittests/tsbuild/demo.ts | 16 +-- .../unittests/tsbuild/emptyFiles.ts | 9 +- src/testRunner/unittests/tsbuild/helpers.ts | 20 +++ .../unittests/tsbuild/missingExtendedFile.ts | 8 +- .../tsbuild/referencesWithRootDirInParent.ts | 18 ++- .../unittests/tsbuild/resolveJsonModule.ts | 13 +- src/testRunner/unittests/tsbuild/sample.ts | 9 +- .../unittests/tsbuild/transitiveReferences.ts | 9 +- 9 files changed, 191 insertions(+), 30 deletions(-) diff --git a/src/harness/fakes.ts b/src/harness/fakes.ts index 31e64e2c931..522cac95f30 100644 --- a/src/harness/fakes.ts +++ b/src/harness/fakes.ts @@ -375,8 +375,47 @@ namespace fakes { } } - export type ExpectedDiagnostic = [ts.DiagnosticMessage, ...(string | number)[]]; - function expectedDiagnosticToText([message, ...args]: ExpectedDiagnostic) { + export type ExpectedDiagnosticMessage = [ts.DiagnosticMessage, ...(string | number)[]]; + export interface ExpectedDiagnosticMessageChain { + message: ExpectedDiagnosticMessage; + next?: ExpectedDiagnosticMessageChain[]; + } + + export interface ExpectedDiagnosticLocation { + file: string; + start: number; + length: number; + } + export interface ExpectedDiagnosticRelatedInformation extends ExpectedDiagnosticMessageChain { + location?: ExpectedDiagnosticLocation; + } + + export enum DiagnosticKind { + Error = "Error", + Status = "Status" + } + export interface ExpectedErrorDiagnostic extends ExpectedDiagnosticRelatedInformation { + relatedInformation?: ExpectedDiagnosticRelatedInformation[]; + } + + export type ExpectedDiagnostic = ExpectedDiagnosticMessage | ExpectedErrorDiagnostic; + + interface SolutionBuilderDiagnostic { + kind: DiagnosticKind; + diagnostic: ts.Diagnostic; + } + + function indentedText(indent: number, text: string) { + if (!indent) return text; + let indentText = ""; + for (let i = 0; i < indent; i++) { + indentText += " "; + } + return ` +${indentText}${text}`; + } + + function expectedDiagnosticMessageToText([message, ...args]: ExpectedDiagnosticMessage) { let text = ts.getLocaleSpecificMessage(message); if (args.length) { text = ts.formatStringFromArgs(text, args); @@ -384,6 +423,70 @@ namespace fakes { return text; } + function expectedDiagnosticMessageChainToText({ message, next }: ExpectedDiagnosticMessageChain, indent = 0) { + let text = indentedText(indent, expectedDiagnosticMessageToText(message)); + if (next) { + indent++; + next.forEach(kid => text += expectedDiagnosticMessageChainToText(kid, indent)); + } + return text; + } + + function expectedDiagnosticRelatedInformationToText({ location, ...diagnosticMessage }: ExpectedDiagnosticRelatedInformation) { + const text = expectedDiagnosticMessageChainToText(diagnosticMessage); + if (location) { + const { file, start, length } = location; + return `${file}(${start}:${length}):: ${text}`; + } + return text; + } + + function expectedErrorDiagnosticToText({ relatedInformation, ...diagnosticRelatedInformation }: ExpectedErrorDiagnostic) { + let text = `${DiagnosticKind.Error}!: ${expectedDiagnosticRelatedInformationToText(diagnosticRelatedInformation)}`; + if (relatedInformation) { + for (const kid of relatedInformation) { + text += ` + related:: ${expectedDiagnosticRelatedInformationToText(kid)}`; + } + } + return text; + } + + function expectedDiagnosticToText(errorOrStatus: ExpectedDiagnostic) { + return ts.isArray(errorOrStatus) ? + `${DiagnosticKind.Status}!: ${expectedDiagnosticMessageToText(errorOrStatus)}` : + expectedErrorDiagnosticToText(errorOrStatus); + } + + function diagnosticMessageChainToText({ messageText, next}: ts.DiagnosticMessageChain, indent = 0) { + let text = indentedText(indent, messageText); + if (next) { + indent++; + next.forEach(kid => text += diagnosticMessageChainToText(kid, indent)); + } + return text; + } + + function diagnosticRelatedInformationToText({ file, start, length, messageText }: ts.DiagnosticRelatedInformation) { + const text = typeof messageText === "string" ? + messageText : + diagnosticMessageChainToText(messageText); + return file ? + `${file.fileName}(${start}:${length}):: ${text}` : + text; + } + + function diagnosticToText({ kind, diagnostic: { relatedInformation, ...diagnosticRelatedInformation } }: SolutionBuilderDiagnostic) { + let text = `${kind}!: ${diagnosticRelatedInformationToText(diagnosticRelatedInformation)}`; + if (relatedInformation) { + for (const kid of relatedInformation) { + text += ` + related:: ${diagnosticRelatedInformationToText(kid)}`; + } + } + return text; + } + function compareProgramBuildInfoDiagnostic(a: ts.ProgramBuildInfoDiagnostic, b: ts.ProgramBuildInfoDiagnostic) { return ts.compareStringsCaseSensitive(ts.isString(a) ? a : a[0], ts.isString(b) ? b : b[0]); } @@ -446,14 +549,14 @@ namespace fakes { return new Date(this.sys.vfs.time()); } - diagnostics: ts.Diagnostic[] = []; + diagnostics: SolutionBuilderDiagnostic[] = []; reportDiagnostic(diagnostic: ts.Diagnostic) { - this.diagnostics.push(diagnostic); + this.diagnostics.push({ kind: DiagnosticKind.Error, diagnostic }); } reportSolutionBuilderStatus(diagnostic: ts.Diagnostic) { - this.diagnostics.push(diagnostic); + this.diagnostics.push({ kind: DiagnosticKind.Status, diagnostic }); } clearDiagnostics() { @@ -461,7 +564,7 @@ namespace fakes { } assertDiagnosticMessages(...expectedDiagnostics: ExpectedDiagnostic[]) { - const actual = this.diagnostics.slice().map(d => d.messageText as string); + const actual = this.diagnostics.slice().map(diagnosticToText); const expected = expectedDiagnostics.map(expectedDiagnosticToText); assert.deepEqual(actual, expected, `Diagnostic arrays did not match: Actual: ${JSON.stringify(actual, /*replacer*/ undefined, " ")} @@ -471,8 +574,8 @@ Expected: ${JSON.stringify(expected, /*replacer*/ undefined, " ")}`); printDiagnostics(header = "== Diagnostics ==") { const out = ts.createDiagnosticReporter(ts.sys); ts.sys.write(header + "\r\n"); - for (const d of this.diagnostics) { - out(d); + for (const { diagnostic } of this.diagnostics) { + out(diagnostic); } } } diff --git a/src/testRunner/unittests/tsbuild/demo.ts b/src/testRunner/unittests/tsbuild/demo.ts index 71e82fc5334..559e49718b9 100644 --- a/src/testRunner/unittests/tsbuild/demo.ts +++ b/src/testRunner/unittests/tsbuild/demo.ts @@ -93,7 +93,7 @@ namespace ts { expectedExitStatus: ExitStatus.ProjectReferenceCycle_OutputsSkupped, expectedDiagnostics: [ getExpectedDiagnosticForProjectsInBuild("src/animals/tsconfig.json", "src/zoo/tsconfig.json", "src/core/tsconfig.json", "src/tsconfig.json"), - [ + errorDiagnostic([ Diagnostics.Project_references_may_not_form_a_circular_graph_Cycle_detected_Colon_0, [ "/src/tsconfig.json", @@ -101,7 +101,7 @@ namespace ts { "/src/zoo/tsconfig.json", "/src/animals/tsconfig.json" ].join("\r\n") - ] + ]) ], expectedOutputs: emptyArray, notExpectedOutputs: [...coreOutputs(), ...animalOutputs(), ...zooOutputs()] @@ -121,12 +121,12 @@ namespace ts { getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json", "src/animals/tsconfig.json", "src/zoo/tsconfig.json", "src/tsconfig.json"), [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/lib/core/utilities.js"], [Diagnostics.Building_project_0, "/src/core/tsconfig.json"], - [Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/animal.ts", "/src/core"], - [Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/dog.ts", "/src/core"], - [Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/index.ts", "/src/core"], - [Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/animal.ts", "/src/core/tsconfig.json"], - [Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/dog.ts", "/src/core/tsconfig.json"], - [Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/index.ts", "/src/core/tsconfig.json"], + errorDiagnostic([Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/animal.ts", "/src/core"]), + errorDiagnostic([Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/dog.ts", "/src/core"]), + errorDiagnostic([Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/index.ts", "/src/core"]), + errorDiagnostic([Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/animal.ts", "/src/core/tsconfig.json"]), + errorDiagnostic([Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/dog.ts", "/src/core/tsconfig.json"]), + errorDiagnostic([Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/index.ts", "/src/core/tsconfig.json"]), [Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_has_errors, "src/animals/tsconfig.json", "src/core"], [Diagnostics.Skipping_build_of_project_0_because_its_dependency_1_has_errors, "/src/animals/tsconfig.json", "/src/core"], [Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_was_not_built, "src/zoo/tsconfig.json", "src/animals"], diff --git a/src/testRunner/unittests/tsbuild/emptyFiles.ts b/src/testRunner/unittests/tsbuild/emptyFiles.ts index 38b8b4b5379..0b52c4f8485 100644 --- a/src/testRunner/unittests/tsbuild/emptyFiles.ts +++ b/src/testRunner/unittests/tsbuild/emptyFiles.ts @@ -15,7 +15,14 @@ namespace ts { host.clearDiagnostics(); builder.build(); - host.assertDiagnosticMessages([Diagnostics.The_files_list_in_config_file_0_is_empty, "/src/no-references/tsconfig.json"]); + host.assertDiagnosticMessages({ + message: [Diagnostics.The_files_list_in_config_file_0_is_empty, "/src/no-references/tsconfig.json"], + location: { + file: "/src/no-references/tsconfig.json", + start: lastIndexOf(fs, "/src/no-references/tsconfig.json", "[]"), + length: 2 + } + }); // Check for outputs to not be written. verifyOutputsAbsent(fs, allExpectedOutputs); diff --git a/src/testRunner/unittests/tsbuild/helpers.ts b/src/testRunner/unittests/tsbuild/helpers.ts index 7aeaba36199..7b33e3018d1 100644 --- a/src/testRunner/unittests/tsbuild/helpers.ts +++ b/src/testRunner/unittests/tsbuild/helpers.ts @@ -1,4 +1,8 @@ namespace ts { + export function errorDiagnostic(message: fakes.ExpectedDiagnosticMessage): fakes.ExpectedErrorDiagnostic { + return { message }; + } + export function getExpectedDiagnosticForProjectsInBuild(...projects: string[]): fakes.ExpectedDiagnostic { return [Diagnostics.Projects_in_this_build_Colon_0, projects.map(p => "\r\n * " + p).join("")]; } @@ -42,6 +46,22 @@ namespace ts { fs.writeFileSync(path, `${old}${additionalContent}`); } + export function indexOf(fs: vfs.FileSystem, path: string, searchStr: string) { + if (!fs.statSync(path).isFile()) { + throw new Error(`File ${path} does not exist`); + } + const content = fs.readFileSync(path, "utf-8"); + return content.indexOf(searchStr); + } + + export function lastIndexOf(fs: vfs.FileSystem, path: string, searchStr: string) { + if (!fs.statSync(path).isFile()) { + throw new Error(`File ${path} does not exist`); + } + const content = fs.readFileSync(path, "utf-8"); + return content.lastIndexOf(searchStr); + } + export function getTime() { let currentTime = 100; return { tick, time, touch }; diff --git a/src/testRunner/unittests/tsbuild/missingExtendedFile.ts b/src/testRunner/unittests/tsbuild/missingExtendedFile.ts index 881f3fbc030..907ed9202fa 100644 --- a/src/testRunner/unittests/tsbuild/missingExtendedFile.ts +++ b/src/testRunner/unittests/tsbuild/missingExtendedFile.ts @@ -7,10 +7,10 @@ namespace ts { const builder = createSolutionBuilder(host, ["/src/tsconfig.json"], {}); builder.build(); host.assertDiagnosticMessages( - [Diagnostics.The_specified_path_does_not_exist_Colon_0, "/src/foobar.json"], - [Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2, "/src/tsconfig.first.json", "[\"**/*\"]", "[]"], - [Diagnostics.The_specified_path_does_not_exist_Colon_0, "/src/foobar.json"], - [Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2, "/src/tsconfig.second.json", "[\"**/*\"]", "[]"] + errorDiagnostic([Diagnostics.The_specified_path_does_not_exist_Colon_0, "/src/foobar.json"]), + errorDiagnostic([Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2, "/src/tsconfig.first.json", "[\"**/*\"]", "[]"]), + errorDiagnostic([Diagnostics.The_specified_path_does_not_exist_Colon_0, "/src/foobar.json"]), + errorDiagnostic([Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2, "/src/tsconfig.second.json", "[\"**/*\"]", "[]"]) ); }); }); diff --git a/src/testRunner/unittests/tsbuild/referencesWithRootDirInParent.ts b/src/testRunner/unittests/tsbuild/referencesWithRootDirInParent.ts index f6a2dca6c2e..9e067367c41 100644 --- a/src/testRunner/unittests/tsbuild/referencesWithRootDirInParent.ts +++ b/src/testRunner/unittests/tsbuild/referencesWithRootDirInParent.ts @@ -43,7 +43,14 @@ namespace ts { [Diagnostics.Building_project_0, "/src/src/other/tsconfig.json"], [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/src/main/tsconfig.json", "src/dist/a.js"], [Diagnostics.Building_project_0, "/src/src/main/tsconfig.json"], - [Diagnostics.Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_file_generated_by_referenced_project_1, "/src/dist/tsconfig.tsbuildinfo", "/src/src/other"] + { + message: [Diagnostics.Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_file_generated_by_referenced_project_1, "/src/dist/tsconfig.tsbuildinfo", "/src/src/other"], + location: { + file: "/src/src/main/tsconfig.json", + start: indexOf(fs, "/src/src/main/tsconfig.json", `{ "path": "../other" }`), + length: `{ "path": "../other" }`.length + } + } ); verifyOutputsPresent(fs, allExpectedOutputs); verifyOutputsAbsent(fs, missingOutputs); @@ -75,7 +82,14 @@ namespace ts { [Diagnostics.Building_project_0, "/src/src/other/tsconfig.json"], [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/src/main/tsconfig.json", "src/dist/a.js"], [Diagnostics.Building_project_0, "/src/src/main/tsconfig.json"], - [Diagnostics.Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_file_generated_by_referenced_project_1, "/src/dist/tsconfig.tsbuildinfo", "/src/src/other"] + { + message: [Diagnostics.Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_file_generated_by_referenced_project_1, "/src/dist/tsconfig.tsbuildinfo", "/src/src/other"], + location: { + file: "/src/src/main/tsconfig.json", + start: indexOf(fs, "/src/src/main/tsconfig.json", `{"path":"../other"}`), + length: `{"path":"../other"}`.length + } + } ); verifyOutputsPresent(fs, allExpectedOutputs); verifyOutputsAbsent(fs, missingOutputs); diff --git a/src/testRunner/unittests/tsbuild/resolveJsonModule.ts b/src/testRunner/unittests/tsbuild/resolveJsonModule.ts index 7793ef5375c..719e4beaed7 100644 --- a/src/testRunner/unittests/tsbuild/resolveJsonModule.ts +++ b/src/testRunner/unittests/tsbuild/resolveJsonModule.ts @@ -28,11 +28,14 @@ namespace ts { } it("with resolveJsonModule and include only", () => { - verifyProjectWithResolveJsonModule("/src/tsconfig_withInclude.json", [ - Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, - "/src/src/hello.json", - "/src/tsconfig_withInclude.json" - ]); + verifyProjectWithResolveJsonModule( + "/src/tsconfig_withInclude.json", + errorDiagnostic([ + Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, + "/src/src/hello.json", + "/src/tsconfig_withInclude.json" + ]) + ); }); it("with resolveJsonModule and include of *.json along with other include", () => { diff --git a/src/testRunner/unittests/tsbuild/sample.ts b/src/testRunner/unittests/tsbuild/sample.ts index 420c7a468aa..260bbff1436 100644 --- a/src/testRunner/unittests/tsbuild/sample.ts +++ b/src/testRunner/unittests/tsbuild/sample.ts @@ -450,7 +450,14 @@ namespace ts { [Diagnostics.Building_project_0, "/src/core/tsconfig.json"], [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/logic/tsconfig.json", "src/logic/index.js"], [Diagnostics.Building_project_0, "/src/logic/tsconfig.json"], - [Diagnostics.Property_0_does_not_exist_on_type_1, "muitply", `typeof import("/src/core/index")`], + { + message: [Diagnostics.Property_0_does_not_exist_on_type_1, "muitply", `typeof import("/src/core/index")`], + location: { + file: "/src/logic/index.ts", + start: indexOf(fs, "/src/logic/index.ts", "muitply"), + length: "muitply".length + } + }, [Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_has_errors, "src/tests/tsconfig.json", "src/logic"], [Diagnostics.Skipping_build_of_project_0_because_its_dependency_1_has_errors, "/src/tests/tsconfig.json", "/src/logic"] ); diff --git a/src/testRunner/unittests/tsbuild/transitiveReferences.ts b/src/testRunner/unittests/tsbuild/transitiveReferences.ts index 614796b2a85..6245a692c9d 100644 --- a/src/testRunner/unittests/tsbuild/transitiveReferences.ts +++ b/src/testRunner/unittests/tsbuild/transitiveReferences.ts @@ -69,7 +69,14 @@ export const b = new A();`); verifyBuild(fs => modifyFsBTsToNonRelativeImport(fs, "node"), allExpectedOutputs, expectedFileTraces, - [Diagnostics.Cannot_find_module_0, "a"], + { + message: [Diagnostics.Cannot_find_module_0, "a"], + location: { + file: "/src/b.ts", + start: `import {A} from 'a';`.indexOf(`'a'`), + length: `'a'`.length + } + }, ); }); }); From 8ac45805c0a716ef3335fe302556cc0ab61d5a2e Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 9 Aug 2019 11:15:20 -0700 Subject: [PATCH 05/18] Add error related to file not in rootDir and file not part of included root files at the references --- src/compiler/program.ts | 223 +++++++++++++----- src/compiler/types.ts | 16 ++ src/compiler/utilities.ts | 2 +- .../unittests/config/projectReferences.ts | 7 +- src/testRunner/unittests/tsbuild/demo.ts | 44 +++- .../unittests/tsbuild/emptyFiles.ts | 6 +- src/testRunner/unittests/tsbuild/helpers.ts | 16 ++ .../tsbuild/referencesWithRootDirInParent.ts | 12 +- .../unittests/tsbuild/resolveJsonModule.ts | 13 +- src/testRunner/unittests/tsbuild/sample.ts | 6 +- src/testRunner/unittests/tsbuild/watchMode.ts | 56 +++++ src/testRunner/unittests/tscWatch/helpers.ts | 149 ++++++++---- .../unittests/tscWatch/programUpdates.ts | 37 +++ 13 files changed, 444 insertions(+), 143 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index a7cb013c8ee..ca4453bd749 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -552,6 +552,12 @@ namespace ts { allDiagnostics?: Diagnostic[]; } + interface RefFile extends TextRange { + kind: RefFileKind; + index: number; + file: SourceFile; + } + /** * Determines if program structure is upto date or needs to be recreated */ @@ -717,6 +723,8 @@ namespace ts { let noDiagnosticsTypeChecker: TypeChecker; let classifiableNames: UnderscoreEscapedMap; const ambientModuleNameToUnmodifiedFileName = createMap(); + // Todo:: Use this to report why file was included in --extendedDiagnostics + let refFileMap: MultiMap | undefined; const cachedSemanticDiagnosticsForFile: DiagnosticCache = {}; const cachedDeclarationDiagnosticsForFile: DiagnosticCache = {}; @@ -913,6 +921,7 @@ namespace ts { getSourceFileByPath, getSourceFiles: () => files, getMissingFilePaths: () => missingFilePaths!, // TODO: GH#18217 + getRefFileMap: () => refFileMap, getCompilerOptions: () => options, getSyntacticDiagnostics, getOptionsDiagnostics, @@ -1391,6 +1400,7 @@ namespace ts { } missingFilePaths = oldProgram.getMissingFilePaths(); + refFileMap = oldProgram.getRefFileMap(); // update fileName -> file mapping for (const newSourceFile of newSourceFiles) { @@ -2179,25 +2189,24 @@ namespace ts { } /** This has side effects through `findSourceFile`. */ - function processSourceFile(fileName: string, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, packageId: PackageId | undefined, refFile?: SourceFile, refPos?: number, refEnd?: number): void { - getSourceFileFromReferenceWorker(fileName, - fileName => findSourceFile(fileName, toPath(fileName), isDefaultLib, ignoreNoDefaultLib, refFile!, refPos!, refEnd!, packageId), // TODO: GH#18217 - (diagnostic, ...args) => { - fileProcessingDiagnostics.add(refFile !== undefined && refEnd !== undefined && refPos !== undefined - ? createFileDiagnostic(refFile, refPos, refEnd - refPos, diagnostic, ...args) - : createCompilerDiagnostic(diagnostic, ...args)); - }, - refFile); + function processSourceFile(fileName: string, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, packageId: PackageId | undefined, refFile?: RefFile): void { + getSourceFileFromReferenceWorker( + fileName, + fileName => findSourceFile(fileName, toPath(fileName), isDefaultLib, ignoreNoDefaultLib, refFile, packageId), // TODO: GH#18217 + (diagnostic, ...args) => fileProcessingDiagnostics.add( + createRefFileDiagnostic(refFile, diagnostic, ...args) + ), + refFile && refFile.file + ); } - function reportFileNamesDifferOnlyInCasingError(fileName: string, existingFileName: string, refFile: SourceFile, refPos: number, refEnd: number): void { - if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - fileProcessingDiagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, - Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, existingFileName)); - } - else { - fileProcessingDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, existingFileName)); - } + function reportFileNamesDifferOnlyInCasingError(fileName: string, existingFileName: string, refFile: RefFile | undefined): void { + fileProcessingDiagnostics.add(createRefFileDiagnostic( + refFile, + Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, + fileName, + existingFileName + )); } function createRedirectSourceFile(redirectTarget: SourceFile, unredirected: SourceFile, fileName: string, path: Path, resolvedPath: Path, originalFileName: string): SourceFile { @@ -2222,7 +2231,7 @@ namespace ts { } // Get source file from normalized fileName - function findSourceFile(fileName: string, path: Path, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, refFile: SourceFile, refPos: number, refEnd: number, packageId: PackageId | undefined): SourceFile | undefined { + function findSourceFile(fileName: string, path: Path, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, refFile: RefFile | undefined, packageId: PackageId | undefined): SourceFile | undefined { const originalFileName = fileName; if (filesByName.has(path)) { const file = filesByName.get(path); @@ -2239,7 +2248,7 @@ namespace ts { const checkedAbsolutePath = getNormalizedAbsolutePathWithoutRoot(checkedName, currentDirectory); const inputAbsolutePath = getNormalizedAbsolutePathWithoutRoot(inputName, currentDirectory); if (checkedAbsolutePath !== inputAbsolutePath) { - reportFileNamesDifferOnlyInCasingError(inputName, checkedName, refFile, refPos, refEnd); + reportFileNamesDifferOnlyInCasingError(inputName, checkedName, refFile); } } @@ -2266,6 +2275,7 @@ namespace ts { } } + addFileToRefFileMap(file || undefined, refFile); return file || undefined; } @@ -2289,15 +2299,17 @@ namespace ts { } // We haven't looked for this file, do so now and cache result - const file = host.getSourceFile(fileName, options.target!, hostErrorMessage => { // TODO: GH#18217 - if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - fileProcessingDiagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, - Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); - } - else { - fileProcessingDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); - } - }, shouldCreateNewSourceFile); + const file = host.getSourceFile( + fileName, + options.target!, + hostErrorMessage => fileProcessingDiagnostics.add(createRefFileDiagnostic( + refFile, + Diagnostics.Cannot_read_file_0_Colon_1, + fileName, + hostErrorMessage + )), + shouldCreateNewSourceFile + ); if (packageId) { const packageIdKey = packageIdToString(packageId); @@ -2331,7 +2343,7 @@ namespace ts { // for case-sensitive file systems check if we've already seen some file with similar filename ignoring case const existingFile = filesByNameIgnoreCase!.get(pathLowerCase); if (existingFile) { - reportFileNamesDifferOnlyInCasingError(fileName, existingFile.fileName, refFile, refPos, refEnd); + reportFileNamesDifferOnlyInCasingError(fileName, existingFile.fileName, refFile); } else { filesByNameIgnoreCase!.set(pathLowerCase, file); @@ -2359,10 +2371,20 @@ namespace ts { processingOtherFiles!.push(file); } } - + addFileToRefFileMap(file, refFile); return file; } + function addFileToRefFileMap(file: SourceFile | undefined, refFile: RefFile | undefined) { + if (refFile && file) { + (refFileMap || (refFileMap = createMultiMap())).add(file.path, { + kind: refFile.kind, + index: refFile.index, + file: refFile.file.path + }); + } + } + function addFileToFilesByName(file: SourceFile | undefined, path: Path, redirectedPath: Path | undefined) { if (redirectedPath) { filesByName.set(redirectedPath, file); @@ -2479,9 +2501,21 @@ namespace ts { } function processReferencedFiles(file: SourceFile, isDefaultLib: boolean) { - forEach(file.referencedFiles, ref => { + forEach(file.referencedFiles, (ref, index) => { const referencedFileName = resolveTripleslashReference(ref.fileName, file.originalFileName); - processSourceFile(referencedFileName, isDefaultLib, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined, file, ref.pos, ref.end); + processSourceFile( + referencedFileName, + isDefaultLib, + /*ignoreNoDefaultLib*/ false, + /*packageId*/ undefined, + { + kind: RefFileKind.ReferenceFile, + index, + file, + pos: ref.pos, + end: ref.end + } + ); }); } @@ -2500,12 +2534,25 @@ namespace ts { // store resolved type directive on the file const fileName = ref.fileName.toLocaleLowerCase(); setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective); - processTypeReferenceDirective(fileName, resolvedTypeReferenceDirective, file, ref.pos, ref.end); + processTypeReferenceDirective( + fileName, + resolvedTypeReferenceDirective, + { + kind: RefFileKind.TypeReferenceDirective, + index: i, + file, + pos: ref.pos, + end: ref.end + } + ); } } - function processTypeReferenceDirective(typeReferenceDirective: string, resolvedTypeReferenceDirective?: ResolvedTypeReferenceDirective, - refFile?: SourceFile, refPos?: number, refEnd?: number): void { + function processTypeReferenceDirective( + typeReferenceDirective: string, + resolvedTypeReferenceDirective?: ResolvedTypeReferenceDirective, + refFile?: RefFile + ): void { // If we already found this library as a primary reference - nothing to do const previousResolution = resolvedTypeReferenceDirectives.get(typeReferenceDirective); @@ -2518,7 +2565,7 @@ namespace ts { if (resolvedTypeReferenceDirective.primary) { // resolved from the primary path - processSourceFile(resolvedTypeReferenceDirective.resolvedFileName!, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, resolvedTypeReferenceDirective.packageId, refFile, refPos, refEnd); // TODO: GH#18217 + processSourceFile(resolvedTypeReferenceDirective.resolvedFileName!, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, resolvedTypeReferenceDirective.packageId, refFile); // TODO: GH#18217 } else { // If we already resolved to this file, it must have been a secondary reference. Check file contents @@ -2528,12 +2575,15 @@ namespace ts { if (resolvedTypeReferenceDirective.resolvedFileName !== previousResolution.resolvedFileName) { const otherFileText = host.readFile(resolvedTypeReferenceDirective.resolvedFileName!); if (otherFileText !== getSourceFile(previousResolution.resolvedFileName!)!.text) { - fileProcessingDiagnostics.add(createDiagnostic(refFile!, refPos!, refEnd!, // TODO: GH#18217 - Diagnostics.Conflicting_definitions_for_0_found_at_1_and_2_Consider_installing_a_specific_version_of_this_library_to_resolve_the_conflict, - typeReferenceDirective, - resolvedTypeReferenceDirective.resolvedFileName, - previousResolution.resolvedFileName - )); + fileProcessingDiagnostics.add( + createRefFileDiagnostic( + refFile, + Diagnostics.Conflicting_definitions_for_0_found_at_1_and_2_Consider_installing_a_specific_version_of_this_library_to_resolve_the_conflict, + typeReferenceDirective, + resolvedTypeReferenceDirective.resolvedFileName, + previousResolution.resolvedFileName + ) + ); } } // don't overwrite previous resolution result @@ -2541,14 +2591,18 @@ namespace ts { } else { // First resolution of this library - processSourceFile(resolvedTypeReferenceDirective.resolvedFileName!, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, resolvedTypeReferenceDirective.packageId, refFile, refPos, refEnd); + processSourceFile(resolvedTypeReferenceDirective.resolvedFileName!, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, resolvedTypeReferenceDirective.packageId, refFile); } } if (resolvedTypeReferenceDirective.isExternalLibraryImport) currentNodeModulesDepth--; } else { - fileProcessingDiagnostics.add(createDiagnostic(refFile!, refPos!, refEnd!, Diagnostics.Cannot_find_type_definition_file_for_0, typeReferenceDirective)); // TODO: GH#18217 + fileProcessingDiagnostics.add(createRefFileDiagnostic( + refFile, + Diagnostics.Cannot_find_type_definition_file_for_0, + typeReferenceDirective + )); } if (saveResolution) { @@ -2568,17 +2622,24 @@ namespace ts { const unqualifiedLibName = removeSuffix(removePrefix(libName, "lib."), ".d.ts"); const suggestion = getSpellingSuggestion(unqualifiedLibName, libs, identity); const message = suggestion ? Diagnostics.Cannot_find_lib_definition_for_0_Did_you_mean_1 : Diagnostics.Cannot_find_lib_definition_for_0; - fileProcessingDiagnostics.add(createDiagnostic(file, libReference.pos, libReference.end, message, libName, suggestion)); + fileProcessingDiagnostics.add(createFileDiagnostic( + file, + libReference.pos, + libReference.end - libReference.pos, + message, + libName, + suggestion + )); } }); } - function createDiagnostic(refFile: SourceFile, refPos: number, refEnd: number, message: DiagnosticMessage, ...args: any[]): Diagnostic { - if (refFile === undefined || refPos === undefined || refEnd === undefined) { + function createRefFileDiagnostic(refFile: RefFile | undefined, message: DiagnosticMessage, ...args: any[]): Diagnostic { + if (!refFile) { return createCompilerDiagnostic(message, ...args); } else { - return createFileDiagnostic(refFile, refPos, refEnd - refPos, message, ...args); + return createFileDiagnostic(refFile.file, refFile.pos, refFile.end - refFile.pos, message, ...args); } } @@ -2632,7 +2693,20 @@ namespace ts { else if (shouldAddFile) { const path = toPath(resolvedFileName); const pos = skipTrivia(file.text, file.imports[i].pos); - findSourceFile(resolvedFileName, path, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, file, pos, file.imports[i].end, resolution.packageId); + findSourceFile( + resolvedFileName, + path, + /*isDefaultLib*/ false, + /*ignoreNoDefaultLib*/ false, + { + kind: RefFileKind.Import, + index: i, + file, + pos, + end: file.imports[i].end + }, + resolution.packageId + ); } if (isFromNodeModulesSearch) { @@ -2654,12 +2728,20 @@ namespace ts { function checkSourceFilesBelongToPath(sourceFiles: ReadonlyArray, rootDirectory: string): boolean { let allFilesBelongToPath = true; const absoluteRootDirectoryPath = host.getCanonicalFileName(getNormalizedAbsolutePath(rootDirectory, currentDirectory)); + let rootPaths: Map | undefined; for (const sourceFile of sourceFiles) { if (!sourceFile.isDeclarationFile) { const absoluteSourceFilePath = host.getCanonicalFileName(getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory)); if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) { - programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, rootDirectory)); + if (!rootPaths) rootPaths = arrayToSet(rootNames, toPath); + addProgramDiagnosticAtRefPath( + sourceFile, + rootPaths, + Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, + sourceFile.fileName, + rootDirectory + ); allFilesBelongToPath = false; } } @@ -2771,12 +2853,18 @@ namespace ts { // List of collected files is complete; validate exhautiveness if this is a project with a file list if (options.composite) { - const rootPaths = rootNames.map(toPath); + const rootPaths = arrayToSet(rootNames, toPath); for (const file of files) { // Ignore file that is not emitted if (!sourceFileMayBeEmitted(file, options, isSourceFileFromExternalLibrary, getResolvedProjectReferenceToRedirect)) continue; - if (rootPaths.indexOf(file.path) === -1) { - programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, file.fileName, options.configFilePath || "")); + if (!rootPaths.has(file.path)) { + addProgramDiagnosticAtRefPath( + file, + rootPaths, + Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, + file.fileName, + options.configFilePath || "" + ); } } } @@ -2984,6 +3072,35 @@ namespace ts { } } + function addProgramDiagnosticAtRefPath(file: SourceFile, rootPaths: Map, message: DiagnosticMessage, ...args: (string | number | undefined)[]) { + const refPaths = refFileMap && refFileMap.get(file.path); + const refPathToReportErrorOn = forEach(refPaths, refPath => rootPaths.has(refPath.file) ? refPath : undefined) || + elementAt(refPaths, 0); + if (refPathToReportErrorOn) { + const refFile = Debug.assertDefined(getSourceFileByPath(refPathToReportErrorOn.file)); + const { kind, index } = refPathToReportErrorOn; + let pos: number, end: number; + switch (kind) { + case RefFileKind.Import: + pos = skipTrivia(refFile.text, refFile.imports[index].pos); + end = refFile.imports[index].end; + break; + case RefFileKind.ReferenceFile: + ({ pos, end } = refFile.referencedFiles[index]); + break; + case RefFileKind.TypeReferenceDirective: + ({ pos, end } = refFile.typeReferenceDirectives[index]); + break; + default: + return Debug.assertNever(kind); + } + programDiagnostics.add(createFileDiagnostic(refFile, pos, end - pos, message, ...args)); + } + else { + programDiagnostics.add(createCompilerDiagnostic(message, ...args)); + } + } + function verifyProjectReferences() { const buildInfoPath = !options.noEmit && !options.suppressOutputPathCheck ? getOutputPathForBuildInfo(options) : undefined; forEachProjectReference(projectReferences, resolvedProjectReferences, (resolvedRef, index, parent) => { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 2d835c5a84f..37df60a4787 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2914,6 +2914,20 @@ namespace ts { throwIfCancellationRequested(): void; } + /*@internal*/ + export enum RefFileKind { + Import, + ReferenceFile, + TypeReferenceDirective + } + + /*@internal*/ + export interface RefFile { + kind: RefFileKind; + index: number; + file: Path; + } + // TODO: This should implement TypeCheckerHost but that's an internal type. export interface Program extends ScriptReferenceHost { @@ -2933,6 +2947,8 @@ namespace ts { */ /* @internal */ getMissingFilePaths(): ReadonlyArray; + /* @internal */ + getRefFileMap(): MultiMap | undefined; /** * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4ca13e663ab..f34fe8ff504 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -192,7 +192,7 @@ namespace ts { export function arrayToSet(array: ReadonlyArray, makeKey: (value: T) => string | undefined): Map; export function arrayToSet(array: ReadonlyArray, makeKey: (value: T) => __String | undefined): UnderscoreEscapedMap; export function arrayToSet(array: ReadonlyArray, makeKey?: (value: any) => string | __String | undefined): Map | UnderscoreEscapedMap { - return arrayToMap(array, makeKey || (s => s), () => true); + return arrayToMap(array, makeKey || (s => s), returnTrue); } export function cloneMap(map: SymbolTable): SymbolTable; diff --git a/src/testRunner/unittests/config/projectReferences.ts b/src/testRunner/unittests/config/projectReferences.ts index 305cc726c97..24a85f5285f 100644 --- a/src/testRunner/unittests/config/projectReferences.ts +++ b/src/testRunner/unittests/config/projectReferences.ts @@ -193,7 +193,7 @@ namespace ts { }; testProjectReferences(spec, "/primary/tsconfig.json", program => { - const errs = program.getOptionsDiagnostics(); + const errs = program.getSemanticDiagnostics(program.getSourceFile("/primary/a.ts")); assertHasError("Reports an error about b.ts not being in the list", errs, Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern); }); }); @@ -343,8 +343,9 @@ namespace ts { } }; testProjectReferences(spec, "/alpha/tsconfig.json", (program) => { - assertHasError("Issues an error about the rootDir", program.getOptionsDiagnostics(), Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files); - assertHasError("Issues an error about the fileList", program.getOptionsDiagnostics(), Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern); + const semanticDiagnostics = program.getSemanticDiagnostics(program.getSourceFile("/alpha/src/a.ts")); + assertHasError("Issues an error about the rootDir", semanticDiagnostics, Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files); + assertHasError("Issues an error about the fileList", semanticDiagnostics, Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern); }); }); }); diff --git a/src/testRunner/unittests/tsbuild/demo.ts b/src/testRunner/unittests/tsbuild/demo.ts index 559e49718b9..c345ad1e372 100644 --- a/src/testRunner/unittests/tsbuild/demo.ts +++ b/src/testRunner/unittests/tsbuild/demo.ts @@ -42,7 +42,7 @@ namespace ts { interface VerifyBuild { modifyDiskLayout: (fs: vfs.FileSystem) => void; expectedExitStatus: ExitStatus; - expectedDiagnostics: fakes.ExpectedDiagnostic[]; + expectedDiagnostics: (fs: vfs.FileSystem) => fakes.ExpectedDiagnostic[]; expectedOutputs: readonly string[]; notExpectedOutputs: readonly string[]; } @@ -54,7 +54,7 @@ namespace ts { const builder = createSolutionBuilder(host, ["/src/tsconfig.json"], { verbose: true }); const exitStatus = builder.build(); assert.equal(exitStatus, expectedExitStatus); - host.assertDiagnosticMessages(...expectedDiagnostics); + host.assertDiagnosticMessages(...expectedDiagnostics(fs)); verifyOutputsPresent(fs, expectedOutputs); verifyOutputsAbsent(fs, notExpectedOutputs); } @@ -63,7 +63,7 @@ namespace ts { verifyBuild({ modifyDiskLayout: noop, expectedExitStatus: ExitStatus.Success, - expectedDiagnostics: [ + expectedDiagnostics: () => [ getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json", "src/animals/tsconfig.json", "src/zoo/tsconfig.json", "src/tsconfig.json"), [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/lib/core/utilities.js"], [Diagnostics.Building_project_0, "/src/core/tsconfig.json"], @@ -91,7 +91,7 @@ namespace ts { ]` ), expectedExitStatus: ExitStatus.ProjectReferenceCycle_OutputsSkupped, - expectedDiagnostics: [ + expectedDiagnostics: () => [ getExpectedDiagnosticForProjectsInBuild("src/animals/tsconfig.json", "src/zoo/tsconfig.json", "src/core/tsconfig.json", "src/tsconfig.json"), errorDiagnostic([ Diagnostics.Project_references_may_not_form_a_circular_graph_Cycle_detected_Colon_0, @@ -117,16 +117,38 @@ namespace ts { ` ), expectedExitStatus: ExitStatus.DiagnosticsPresent_OutputsSkipped, - expectedDiagnostics: [ + expectedDiagnostics: fs => [ getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json", "src/animals/tsconfig.json", "src/zoo/tsconfig.json", "src/tsconfig.json"), [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/lib/core/utilities.js"], [Diagnostics.Building_project_0, "/src/core/tsconfig.json"], - errorDiagnostic([Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/animal.ts", "/src/core"]), - errorDiagnostic([Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/dog.ts", "/src/core"]), - errorDiagnostic([Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/index.ts", "/src/core"]), - errorDiagnostic([Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/animal.ts", "/src/core/tsconfig.json"]), - errorDiagnostic([Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/dog.ts", "/src/core/tsconfig.json"]), - errorDiagnostic([Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/index.ts", "/src/core/tsconfig.json"]), + { + message: [Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/animal.ts", "/src/core"], + location: expectedLocationIndexOf(fs, "/src/animals/index.ts", `'./animal'`), + }, + { + message: [Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/animal.ts", "/src/core/tsconfig.json"], + location: expectedLocationIndexOf(fs, "/src/animals/index.ts", `'./animal'`), + }, + { + message: [Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/dog.ts", "/src/core"], + location: expectedLocationIndexOf(fs, "/src/animals/index.ts", `'./dog'`), + }, + { + message: [Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/dog.ts", "/src/core/tsconfig.json"], + location: expectedLocationIndexOf(fs, "/src/animals/index.ts", `'./dog'`), + }, + { + message: [Diagnostics._0_is_declared_but_its_value_is_never_read, "A"], + location: expectedLocationIndexOf(fs, "/src/core/utilities.ts", `import * as A from '../animals';`), + }, + { + message: [Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/index.ts", "/src/core"], + location: expectedLocationIndexOf(fs, "/src/core/utilities.ts", `'../animals'`), + }, + { + message: [Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/index.ts", "/src/core/tsconfig.json"], + location: expectedLocationIndexOf(fs, "/src/core/utilities.ts", `'../animals'`), + }, [Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_has_errors, "src/animals/tsconfig.json", "src/core"], [Diagnostics.Skipping_build_of_project_0_because_its_dependency_1_has_errors, "/src/animals/tsconfig.json", "/src/core"], [Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_was_not_built, "src/zoo/tsconfig.json", "src/animals"], diff --git a/src/testRunner/unittests/tsbuild/emptyFiles.ts b/src/testRunner/unittests/tsbuild/emptyFiles.ts index 0b52c4f8485..a2e7aedf290 100644 --- a/src/testRunner/unittests/tsbuild/emptyFiles.ts +++ b/src/testRunner/unittests/tsbuild/emptyFiles.ts @@ -17,11 +17,7 @@ namespace ts { builder.build(); host.assertDiagnosticMessages({ message: [Diagnostics.The_files_list_in_config_file_0_is_empty, "/src/no-references/tsconfig.json"], - location: { - file: "/src/no-references/tsconfig.json", - start: lastIndexOf(fs, "/src/no-references/tsconfig.json", "[]"), - length: 2 - } + location: expectedLocationLastIndexOf(fs, "/src/no-references/tsconfig.json", "[]"), }); // Check for outputs to not be written. diff --git a/src/testRunner/unittests/tsbuild/helpers.ts b/src/testRunner/unittests/tsbuild/helpers.ts index 7b33e3018d1..165aab84916 100644 --- a/src/testRunner/unittests/tsbuild/helpers.ts +++ b/src/testRunner/unittests/tsbuild/helpers.ts @@ -62,6 +62,22 @@ namespace ts { return content.lastIndexOf(searchStr); } + export function expectedLocationIndexOf(fs: vfs.FileSystem, file: string, searchStr: string): fakes.ExpectedDiagnosticLocation { + return { + file, + start: indexOf(fs, file, searchStr), + length: searchStr.length + }; + } + + export function expectedLocationLastIndexOf(fs: vfs.FileSystem, file: string, searchStr: string): fakes.ExpectedDiagnosticLocation { + return { + file, + start: lastIndexOf(fs, file, searchStr), + length: searchStr.length + }; + } + export function getTime() { let currentTime = 100; return { tick, time, touch }; diff --git a/src/testRunner/unittests/tsbuild/referencesWithRootDirInParent.ts b/src/testRunner/unittests/tsbuild/referencesWithRootDirInParent.ts index 9e067367c41..79cc34ce016 100644 --- a/src/testRunner/unittests/tsbuild/referencesWithRootDirInParent.ts +++ b/src/testRunner/unittests/tsbuild/referencesWithRootDirInParent.ts @@ -45,11 +45,7 @@ namespace ts { [Diagnostics.Building_project_0, "/src/src/main/tsconfig.json"], { message: [Diagnostics.Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_file_generated_by_referenced_project_1, "/src/dist/tsconfig.tsbuildinfo", "/src/src/other"], - location: { - file: "/src/src/main/tsconfig.json", - start: indexOf(fs, "/src/src/main/tsconfig.json", `{ "path": "../other" }`), - length: `{ "path": "../other" }`.length - } + location: expectedLocationIndexOf(fs, "/src/src/main/tsconfig.json", `{ "path": "../other" }`), } ); verifyOutputsPresent(fs, allExpectedOutputs); @@ -84,11 +80,7 @@ namespace ts { [Diagnostics.Building_project_0, "/src/src/main/tsconfig.json"], { message: [Diagnostics.Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_file_generated_by_referenced_project_1, "/src/dist/tsconfig.tsbuildinfo", "/src/src/other"], - location: { - file: "/src/src/main/tsconfig.json", - start: indexOf(fs, "/src/src/main/tsconfig.json", `{"path":"../other"}`), - length: `{"path":"../other"}`.length - } + location: expectedLocationIndexOf(fs, "/src/src/main/tsconfig.json", `{"path":"../other"}`), } ); verifyOutputsPresent(fs, allExpectedOutputs); diff --git a/src/testRunner/unittests/tsbuild/resolveJsonModule.ts b/src/testRunner/unittests/tsbuild/resolveJsonModule.ts index 719e4beaed7..7531fac65af 100644 --- a/src/testRunner/unittests/tsbuild/resolveJsonModule.ts +++ b/src/testRunner/unittests/tsbuild/resolveJsonModule.ts @@ -30,11 +30,14 @@ namespace ts { it("with resolveJsonModule and include only", () => { verifyProjectWithResolveJsonModule( "/src/tsconfig_withInclude.json", - errorDiagnostic([ - Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, - "/src/src/hello.json", - "/src/tsconfig_withInclude.json" - ]) + { + message: [ + Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, + "/src/src/hello.json", + "/src/tsconfig_withInclude.json" + ], + location: expectedLocationIndexOf(projFs, "/src/src/index.ts", `"./hello.json"`) + } ); }); diff --git a/src/testRunner/unittests/tsbuild/sample.ts b/src/testRunner/unittests/tsbuild/sample.ts index 260bbff1436..8dcc69d06d9 100644 --- a/src/testRunner/unittests/tsbuild/sample.ts +++ b/src/testRunner/unittests/tsbuild/sample.ts @@ -452,11 +452,7 @@ namespace ts { [Diagnostics.Building_project_0, "/src/logic/tsconfig.json"], { message: [Diagnostics.Property_0_does_not_exist_on_type_1, "muitply", `typeof import("/src/core/index")`], - location: { - file: "/src/logic/index.ts", - start: indexOf(fs, "/src/logic/index.ts", "muitply"), - length: "muitply".length - } + location: expectedLocationIndexOf(fs, "/src/logic/index.ts", "muitply"), }, [Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_has_errors, "src/tests/tsconfig.json", "src/logic"], [Diagnostics.Skipping_build_of_project_0_because_its_dependency_1_has_errors, "/src/tests/tsconfig.json", "/src/logic"] diff --git a/src/testRunner/unittests/tsbuild/watchMode.ts b/src/testRunner/unittests/tsbuild/watchMode.ts index 5c4fd5c5259..3d819337e8c 100644 --- a/src/testRunner/unittests/tsbuild/watchMode.ts +++ b/src/testRunner/unittests/tsbuild/watchMode.ts @@ -1295,6 +1295,62 @@ export function someFn() { }`); ]); }); + it("updates with bad reference", () => { + const host = createTsBuildWatchSystem([ + ...allFilesExceptBase, + baseConfig, + { path: libFile.path, content: libContent } + ], { currentDirectory: projectLocation }); + host.writeFile(coreFiles[1].path, `import * as A from '../animals'; +${coreFiles[1].content}`); + createSolutionBuilderWithWatch(host, ["tsconfig.json"], { verbose: true, watch: true }); + const errors = [ + `animals/index.ts(1,20): error TS6059: File '/user/username/projects/demo/animals/animal.ts' is not under 'rootDir' '/user/username/projects/demo/core'. 'rootDir' is expected to contain all source files.\n`, + `animals/index.ts(1,20): error TS6307: File '/user/username/projects/demo/animals/animal.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern.\n`, + `animals/index.ts(4,32): error TS6059: File '/user/username/projects/demo/animals/dog.ts' is not under 'rootDir' '/user/username/projects/demo/core'. 'rootDir' is expected to contain all source files.\n`, + `animals/index.ts(4,32): error TS6307: File '/user/username/projects/demo/animals/dog.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern.\n`, + `core/utilities.ts(1,1): error TS6133: 'A' is declared but its value is never read.\n`, + `core/utilities.ts(1,20): error TS6059: File '/user/username/projects/demo/animals/index.ts' is not under 'rootDir' '/user/username/projects/demo/core'. 'rootDir' is expected to contain all source files.\n`, + `core/utilities.ts(1,20): error TS6307: File '/user/username/projects/demo/animals/index.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern.\n` + ].map(hostOutputDiagnostic); + checkOutputErrors(host, [ + startingCompilationInWatchMode(), + hostOutputLog(`Projects in this build: \r\n * core/tsconfig.json\r\n * animals/tsconfig.json\r\n * zoo/tsconfig.json\r\n * tsconfig.json\n\n`), + hostOutputLog(`Project 'core/tsconfig.json' is out of date because output file 'lib/core/utilities.js' does not exist\n\n`), + hostOutputLog(`Building project '/user/username/projects/demo/core/tsconfig.json'...\n\n`), + ...errors, + hostOutputLog(`Project 'animals/tsconfig.json' can't be built because its dependency 'core' has errors\n\n`), + hostOutputLog(`Skipping build of project '/user/username/projects/demo/animals/tsconfig.json' because its dependency '/user/username/projects/demo/core' has errors\n\n`), + hostOutputLog(`Project 'zoo/tsconfig.json' can't be built because its dependency 'animals' was not built\n\n`), + hostOutputLog(`Skipping build of project '/user/username/projects/demo/zoo/tsconfig.json' because its dependency '/user/username/projects/demo/animals' was not built\n\n`), + foundErrorsWatching(errors) + ]); + verifyWatches(host); + + // Make changes + host.writeFile(coreFiles[1].path, ` +import * as A from '../animals'; +${coreFiles[1].content}`); + const newErrors = [ + `animals/index.ts(1,20): error TS6059: File '/user/username/projects/demo/animals/animal.ts' is not under 'rootDir' '/user/username/projects/demo/core'. 'rootDir' is expected to contain all source files.\n`, + `animals/index.ts(1,20): error TS6307: File '/user/username/projects/demo/animals/animal.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern.\n`, + `animals/index.ts(4,32): error TS6059: File '/user/username/projects/demo/animals/dog.ts' is not under 'rootDir' '/user/username/projects/demo/core'. 'rootDir' is expected to contain all source files.\n`, + `animals/index.ts(4,32): error TS6307: File '/user/username/projects/demo/animals/dog.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern.\n`, + `core/utilities.ts(2,1): error TS6133: 'A' is declared but its value is never read.\n`, + `core/utilities.ts(2,20): error TS6059: File '/user/username/projects/demo/animals/index.ts' is not under 'rootDir' '/user/username/projects/demo/core'. 'rootDir' is expected to contain all source files.\n`, + `core/utilities.ts(2,20): error TS6307: File '/user/username/projects/demo/animals/index.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern.\n` + ].map(hostOutputDiagnostic); + host.checkTimeoutQueueLengthAndRun(1); // build core + host.checkTimeoutQueueLength(0); + checkOutputErrors(host, [ + fileChangeDetected(), + hostOutputLog(`Project 'core/tsconfig.json' is out of date because output file 'lib/core/utilities.js' does not exist\n\n`), + hostOutputLog(`Building project '/user/username/projects/demo/core/tsconfig.json'...\n\n`), + ...newErrors, + foundErrorsWatching(newErrors) + ]); + }); + function subProjectFiles(subProject: string, fileNames: readonly string[]): File[] { return fileNames.map(file => projectFile(`${subProject}/${file}`)); } diff --git a/src/testRunner/unittests/tscWatch/helpers.ts b/src/testRunner/unittests/tscWatch/helpers.ts index ce5fd9d4725..3a9cb9a4fd8 100644 --- a/src/testRunner/unittests/tscWatch/helpers.ts +++ b/src/testRunner/unittests/tscWatch/helpers.ts @@ -54,30 +54,51 @@ namespace ts.tscWatch { const elapsedRegex = /^Elapsed:: [0-9]+ms/; const buildVerboseLogRegEx = /^.+ \- /; - function checkOutputErrors( + export enum HostOutputKind { + Log, + Diagnostic, + WatchDiagnostic + } + + export interface HostOutputLog { + kind: HostOutputKind.Log; + expected: string; + caption?: string; + } + + export interface HostOutputDiagnostic { + kind: HostOutputKind.Diagnostic; + diagnostic: Diagnostic | string; + } + + export interface HostOutputWatchDiagnostic { + kind: HostOutputKind.WatchDiagnostic; + diagnostic: Diagnostic | string; + } + + export type HostOutput = HostOutputLog | HostOutputDiagnostic | HostOutputWatchDiagnostic; + + export function checkOutputErrors( host: WatchedSystem, - logsBeforeWatchDiagnostic: string[] | undefined, - preErrorsWatchDiagnostic: Diagnostic | undefined, - logsBeforeErrors: string[] | undefined, - errors: ReadonlyArray | ReadonlyArray, - disableConsoleClears?: boolean | undefined, - ...postErrorsWatchDiagnostics: Diagnostic[] | string[] + expected: readonly HostOutput[], + disableConsoleClears?: boolean | undefined ) { let screenClears = 0; const outputs = host.getOutput(); - const expectedOutputCount = (preErrorsWatchDiagnostic ? 1 : 0) + - errors.length + - postErrorsWatchDiagnostics.length + - (logsBeforeWatchDiagnostic ? logsBeforeWatchDiagnostic.length : 0) + - (logsBeforeErrors ? logsBeforeErrors.length : 0); - assert.equal(outputs.length, expectedOutputCount, JSON.stringify(outputs)); + assert.equal(outputs.length, expected.length, JSON.stringify(outputs)); let index = 0; - forEach(logsBeforeWatchDiagnostic, log => assertLog("logsBeforeWatchDiagnostic", log)); - if (preErrorsWatchDiagnostic) assertWatchDiagnostic(preErrorsWatchDiagnostic); - forEach(logsBeforeErrors, log => assertLog("logBeforeError", log)); - // Verify errors - forEach(errors, assertDiagnostic); - forEach(postErrorsWatchDiagnostics, assertWatchDiagnostic); + forEach(expected, expected => { + switch (expected.kind) { + case HostOutputKind.Log: + return assertLog(expected); + case HostOutputKind.Diagnostic: + return assertDiagnostic(expected); + case HostOutputKind.WatchDiagnostic: + return assertWatchDiagnostic(expected); + default: + return Debug.assertNever(expected); + } + }); assert.equal(host.screenClears.length, screenClears, "Expected number of screen clears"); host.clearOutput(); @@ -85,7 +106,7 @@ namespace ts.tscWatch { return !!(diagnostic as Diagnostic).messageText; } - function assertDiagnostic(diagnostic: Diagnostic | string) { + function assertDiagnostic({ diagnostic }: HostOutputDiagnostic) { const expected = isDiagnostic(diagnostic) ? formatDiagnostic(diagnostic, host) : diagnostic; assert.equal(outputs[index], expected, getOutputAtFailedMessage("Diagnostic", expected)); index++; @@ -95,13 +116,13 @@ namespace ts.tscWatch { return log.replace(elapsedRegex, "").replace(buildVerboseLogRegEx, ""); } - function assertLog(caption: string, expected: string) { + function assertLog({ caption, expected }: HostOutputLog) { const actual = outputs[index]; - assert.equal(getCleanLogString(actual), getCleanLogString(expected), getOutputAtFailedMessage(caption, expected)); + assert.equal(getCleanLogString(actual), getCleanLogString(expected), getOutputAtFailedMessage(caption || "Log", expected)); index++; } - function assertWatchDiagnostic(diagnostic: Diagnostic | string) { + function assertWatchDiagnostic({ diagnostic }: HostOutputWatchDiagnostic) { if (isString(diagnostic)) { assert.equal(outputs[index], diagnostic, getOutputAtFailedMessage("Diagnostic", diagnostic)); } @@ -128,54 +149,82 @@ namespace ts.tscWatch { } } - function createErrorsFoundCompilerDiagnostic(errors: ReadonlyArray | ReadonlyArray) { - return errors.length === 1 - ? createCompilerDiagnostic(Diagnostics.Found_1_error_Watching_for_file_changes) - : createCompilerDiagnostic(Diagnostics.Found_0_errors_Watching_for_file_changes, errors.length); + export function hostOutputLog(expected: string, caption?: string): HostOutputLog { + return { kind: HostOutputKind.Log, expected, caption }; + } + export function hostOutputDiagnostic(diagnostic: Diagnostic | string): HostOutputDiagnostic { + return { kind: HostOutputKind.Diagnostic, diagnostic }; + } + export function hostOutputWatchDiagnostic(diagnostic: Diagnostic | string): HostOutputWatchDiagnostic { + return { kind: HostOutputKind.WatchDiagnostic, diagnostic }; + } + + export function startingCompilationInWatchMode() { + return hostOutputWatchDiagnostic(createCompilerDiagnostic(Diagnostics.Starting_compilation_in_watch_mode)); + } + export function foundErrorsWatching(errors: readonly any[]) { + return hostOutputWatchDiagnostic(errors.length === 1 ? + createCompilerDiagnostic(Diagnostics.Found_1_error_Watching_for_file_changes) : + createCompilerDiagnostic(Diagnostics.Found_0_errors_Watching_for_file_changes, errors.length) + ); + } + export function fileChangeDetected() { + return hostOutputWatchDiagnostic(createCompilerDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation)); } export function checkOutputErrorsInitial(host: WatchedSystem, errors: ReadonlyArray | ReadonlyArray, disableConsoleClears?: boolean, logsBeforeErrors?: string[]) { checkOutputErrors( host, - /*logsBeforeWatchDiagnostic*/ undefined, - createCompilerDiagnostic(Diagnostics.Starting_compilation_in_watch_mode), - logsBeforeErrors, - errors, - disableConsoleClears, - createErrorsFoundCompilerDiagnostic(errors)); + [ + startingCompilationInWatchMode(), + ...map(logsBeforeErrors || emptyArray, expected => hostOutputLog(expected, "logBeforeError")), + ...map(errors, hostOutputDiagnostic), + foundErrorsWatching(errors) + ], + disableConsoleClears + ); } export function checkOutputErrorsIncremental(host: WatchedSystem, errors: ReadonlyArray | ReadonlyArray, disableConsoleClears?: boolean, logsBeforeWatchDiagnostic?: string[], logsBeforeErrors?: string[]) { checkOutputErrors( host, - logsBeforeWatchDiagnostic, - createCompilerDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation), - logsBeforeErrors, - errors, - disableConsoleClears, - createErrorsFoundCompilerDiagnostic(errors)); + [ + ...map(logsBeforeWatchDiagnostic || emptyArray, expected => hostOutputLog(expected, "logsBeforeWatchDiagnostic")), + fileChangeDetected(), + ...map(logsBeforeErrors || emptyArray, expected => hostOutputLog(expected, "logBeforeError")), + ...map(errors, hostOutputDiagnostic), + foundErrorsWatching(errors) + ], + disableConsoleClears + ); } export function checkOutputErrorsIncrementalWithExit(host: WatchedSystem, errors: ReadonlyArray | ReadonlyArray, expectedExitCode: ExitStatus, disableConsoleClears?: boolean, logsBeforeWatchDiagnostic?: string[], logsBeforeErrors?: string[]) { checkOutputErrors( host, - logsBeforeWatchDiagnostic, - createCompilerDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation), - logsBeforeErrors, - errors, - disableConsoleClears); + [ + ...map(logsBeforeWatchDiagnostic || emptyArray, expected => hostOutputLog(expected, "logsBeforeWatchDiagnostic")), + fileChangeDetected(), + ...map(logsBeforeErrors || emptyArray, expected => hostOutputLog(expected, "logBeforeError")), + ...map(errors, hostOutputDiagnostic), + ], + disableConsoleClears + ); assert.equal(host.exitCode, expectedExitCode); } export function checkNormalBuildErrors(host: WatchedSystem, errors: ReadonlyArray | ReadonlyArray, reportErrorSummary?: boolean) { checkOutputErrors( host, - /*logsBeforeWatchDiagnostic*/ undefined, - /*preErrorsWatchDiagnostic*/ undefined, - /*logsBeforeErrors*/ undefined, - errors, - /*disableConsoleClears*/ undefined, - ...(reportErrorSummary ? [getErrorSummaryText(errors.length, host.newLine)] : emptyArray) + [ + ...map(errors, hostOutputDiagnostic), + ...map( + reportErrorSummary ? + [getErrorSummaryText(errors.length, host.newLine)] : + emptyArray, + hostOutputWatchDiagnostic + ) + ] ); } diff --git a/src/testRunner/unittests/tscWatch/programUpdates.ts b/src/testRunner/unittests/tscWatch/programUpdates.ts index 3fd54264260..6fead1a1afe 100644 --- a/src/testRunner/unittests/tscWatch/programUpdates.ts +++ b/src/testRunner/unittests/tscWatch/programUpdates.ts @@ -1335,5 +1335,42 @@ exports.a = 1; checkProgramActualFiles(watch(), [aFile.path, bFile.path, libFile.path]); } }); + + it("reports errors correctly with file not in rootDir", () => { + const currentDirectory = "/user/username/projects/myproject"; + const aFile: File = { + path: `${currentDirectory}/a.ts`, + content: `import { x } from "../b";` + }; + const bFile: File = { + path: `/user/username/projects/b.ts`, + content: `export const x = 10;` + }; + const configFile: File = { + path: `${currentDirectory}/tsconfig.json`, + content: JSON.stringify({ + compilerOptions: { + rootDir: ".", + outDir: "lib" + } + }) + }; + + const files = [aFile, bFile, libFile, configFile]; + + const host = createWatchedSystem(files, { currentDirectory }); + const watch = createWatchOfConfigFile("tsconfig.json", host); + checkOutputErrorsInitial(host, [ + getDiagnosticOfFileFromProgram(watch(), aFile.path, aFile.content.indexOf(`"../b"`), `"../b"`.length, Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, bFile.path, currentDirectory) + ]); + const aContent = ` + +${aFile.content}`; + host.writeFile(aFile.path, aContent); + host.runQueuedTimeoutCallbacks(); + checkOutputErrorsIncremental(host, [ + getDiagnosticOfFileFromProgram(watch(), aFile.path, aContent.indexOf(`"../b"`), `"../b"`.length, Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, bFile.path, currentDirectory) + ]); + }); }); } From 1a9198a53af6fc56bbcc408fdc7c3ef5bd933213 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 12 Aug 2019 16:06:09 -0700 Subject: [PATCH 06/18] PR feedback --- src/testRunner/unittests/tscWatch/helpers.ts | 9 +++------ tests/projects/demo/zoo/zoo.ts | 1 - 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/testRunner/unittests/tscWatch/helpers.ts b/src/testRunner/unittests/tscWatch/helpers.ts index 3a9cb9a4fd8..a032c44ee0f 100644 --- a/src/testRunner/unittests/tscWatch/helpers.ts +++ b/src/testRunner/unittests/tscWatch/helpers.ts @@ -218,12 +218,9 @@ namespace ts.tscWatch { host, [ ...map(errors, hostOutputDiagnostic), - ...map( - reportErrorSummary ? - [getErrorSummaryText(errors.length, host.newLine)] : - emptyArray, - hostOutputWatchDiagnostic - ) + ...reportErrorSummary ? + [hostOutputWatchDiagnostic(getErrorSummaryText(errors.length, host.newLine))] : + emptyArray ] ); } diff --git a/tests/projects/demo/zoo/zoo.ts b/tests/projects/demo/zoo/zoo.ts index a00ad8a79e4..8958a65aac1 100644 --- a/tests/projects/demo/zoo/zoo.ts +++ b/tests/projects/demo/zoo/zoo.ts @@ -1,4 +1,3 @@ -// import Animal from '../animals/index'; import { Dog, createDog } from '../animals/index'; export function createZoo(): Array { From 8b45b3dd25284a3db0cc0ad58bb60b983321e253 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Wed, 14 Aug 2019 09:03:27 -0700 Subject: [PATCH 07/18] Update user baselines (#32886) --- .../baselines/reference/docker/azure-sdk.log | 20 ++++++------- .../baselines/reference/user/graceful-fs.log | 29 +++++++++++-------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/tests/baselines/reference/docker/azure-sdk.log b/tests/baselines/reference/docker/azure-sdk.log index 2c8c866ea20..f5295f07652 100644 --- a/tests/baselines/reference/docker/azure-sdk.log +++ b/tests/baselines/reference/docker/azure-sdk.log @@ -33,7 +33,6 @@ npm ERR! /root/.npm/_logs/XXXX-XX-XXXXXXXXX-debug.log ERROR: "build:lib" exited with 1. XX of XX: [@azure/core-paging] completed successfully in ? seconds XX of XX: [@azure/core-tracing] completed successfully in ? seconds -XX of XX: [@azure/cosmos] completed successfully in ? seconds npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! @azure/keyvault-certificates@X.X.X extract-api: `tsc -p . && api-extractor run --local` @@ -45,19 +44,19 @@ npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/XXXX-XX-XXXXXXXXX-debug.log npm ERR! code ELIFECYCLE npm ERR! errno 2 -npm ERR! @azure/keyvault-keys@X.X.X-preview.3 extract-api: `tsc -p . && api-extractor run --local` +npm ERR! @azure/keyvault-keys@X.X.X-preview.4 extract-api: `tsc -p . && api-extractor run --local` npm ERR! Exit status 2 npm ERR! -npm ERR! Failed at the @azure/keyvault-keys@X.X.X-preview.3 extract-api script. +npm ERR! Failed at the @azure/keyvault-keys@X.X.X-preview.4 extract-api script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/XXXX-XX-XXXXXXXXX-debug.log npm ERR! code ELIFECYCLE npm ERR! errno 2 -npm ERR! @azure/keyvault-secrets@X.X.X-preview.4 extract-api: `tsc -p . && api-extractor run --local` +npm ERR! @azure/keyvault-secrets@X.X.X-preview.5 extract-api: `tsc -p . && api-extractor run --local` npm ERR! Exit status 2 npm ERR! -npm ERR! Failed at the @azure/keyvault-secrets@X.X.X-preview.4 extract-api script. +npm ERR! Failed at the @azure/keyvault-secrets@X.X.X-preview.5 extract-api script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/XXXX-XX-XXXXXXXXX-debug.log @@ -67,7 +66,7 @@ XX of XX: [@azure/storage-file] completed successfully in ? seconds XX of XX: [@azure/storage-queue] completed successfully in ? seconds XX of XX: [@azure/template] completed successfully in ? seconds XX of XX: [testhub] completed successfully in ? seconds -SUCCESS (15) +SUCCESS (14) ================================ @azure/abort-controller (? seconds) @azure/core-arm (? seconds) @@ -75,7 +74,6 @@ SUCCESS (15) @azure/core-auth (? seconds) @azure/core-paging (? seconds) @azure/core-tracing (? seconds) -@azure/cosmos (? seconds) @azure/event-processor-host (? seconds) @azure/identity (? seconds) @azure/service-bus (? seconds) @@ -132,20 +130,20 @@ npm ERR! /root/.npm/_logs/XXXX-XX-XXXXXXXXX-debug.log @azure/keyvault-keys ( ? seconds) npm ERR! code ELIFECYCLE npm ERR! errno 2 -npm ERR! @azure/keyvault-keys@X.X.X-preview.3 extract-api: `tsc -p . && api-extractor run --local` +npm ERR! @azure/keyvault-keys@X.X.X-preview.4 extract-api: `tsc -p . && api-extractor run --local` npm ERR! Exit status 2 npm ERR! -npm ERR! Failed at the @azure/keyvault-keys@X.X.X-preview.3 extract-api script. +npm ERR! Failed at the @azure/keyvault-keys@X.X.X-preview.4 extract-api script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/XXXX-XX-XXXXXXXXX-debug.log @azure/keyvault-secrets ( ? seconds) npm ERR! code ELIFECYCLE npm ERR! errno 2 -npm ERR! @azure/keyvault-secrets@X.X.X-preview.4 extract-api: `tsc -p . && api-extractor run --local` +npm ERR! @azure/keyvault-secrets@X.X.X-preview.5 extract-api: `tsc -p . && api-extractor run --local` npm ERR! Exit status 2 npm ERR! -npm ERR! Failed at the @azure/keyvault-secrets@X.X.X-preview.4 extract-api script. +npm ERR! Failed at the @azure/keyvault-secrets@X.X.X-preview.5 extract-api script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/XXXX-XX-XXXXXXXXX-debug.log diff --git a/tests/baselines/reference/user/graceful-fs.log b/tests/baselines/reference/user/graceful-fs.log index 72b23e68414..2a02c52d08d 100644 --- a/tests/baselines/reference/user/graceful-fs.log +++ b/tests/baselines/reference/user/graceful-fs.log @@ -4,18 +4,23 @@ node_modules/graceful-fs/clone.js(12,9): error TS2403: Subsequent variable decla node_modules/graceful-fs/clone.js(15,38): error TS2345: Argument of type 'PropertyDescriptor | undefined' is not assignable to parameter of type 'PropertyDescriptor & ThisType'. Type 'undefined' is not assignable to type 'PropertyDescriptor & ThisType'. Type 'undefined' is not assignable to type 'PropertyDescriptor'. -node_modules/graceful-fs/graceful-fs.js(14,3): error TS2322: Type '(msg: string, ...param: any[]) => void' is not assignable to type '() => void'. -node_modules/graceful-fs/graceful-fs.js(17,37): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[any, ...any[]]'. -node_modules/graceful-fs/graceful-fs.js(24,11): error TS2554: Expected 0 arguments, but got 1. -node_modules/graceful-fs/graceful-fs.js(30,54): error TS2339: Property '__patched' does not exist on type 'typeof import("fs")'. -node_modules/graceful-fs/graceful-fs.js(32,8): error TS2339: Property '__patched' does not exist on type 'typeof import("fs")'. -node_modules/graceful-fs/graceful-fs.js(52,37): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[number]'. -node_modules/graceful-fs/graceful-fs.js(174,5): error TS2539: Cannot assign to 'ReadStream' because it is not a variable. -node_modules/graceful-fs/graceful-fs.js(175,5): error TS2539: Cannot assign to 'WriteStream' because it is not a variable. -node_modules/graceful-fs/graceful-fs.js(197,68): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[any?, any?, ...any[]]'. -node_modules/graceful-fs/graceful-fs.js(220,70): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[any?, any?, ...any[]]'. -node_modules/graceful-fs/graceful-fs.js(269,9): error TS2554: Expected 0 arguments, but got 3. -node_modules/graceful-fs/graceful-fs.js(276,11): error TS2554: Expected 0 arguments, but got 3. +node_modules/graceful-fs/graceful-fs.js(26,3): error TS2322: Type '(msg: string, ...param: any[]) => void' is not assignable to type '() => void'. +node_modules/graceful-fs/graceful-fs.js(29,37): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[any, ...any[]]'. +node_modules/graceful-fs/graceful-fs.js(48,3): error TS2741: Property '__promisify__' is missing in type '(fd: any, cb: any) => void' but required in type 'typeof close'. +node_modules/graceful-fs/graceful-fs.js(70,30): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[number]'. +node_modules/graceful-fs/graceful-fs.js(82,13): error TS2554: Expected 0 arguments, but got 1. +node_modules/graceful-fs/graceful-fs.js(89,54): error TS2339: Property '__patched' does not exist on type 'typeof import("fs")'. +node_modules/graceful-fs/graceful-fs.js(91,8): error TS2339: Property '__patched' does not exist on type 'typeof import("fs")'. +node_modules/graceful-fs/graceful-fs.js(199,5): error TS2539: Cannot assign to 'ReadStream' because it is not a variable. +node_modules/graceful-fs/graceful-fs.js(200,5): error TS2539: Cannot assign to 'WriteStream' because it is not a variable. +node_modules/graceful-fs/graceful-fs.js(220,7): error TS2539: Cannot assign to 'ReadStream' because it is not a variable. +node_modules/graceful-fs/graceful-fs.js(230,7): error TS2539: Cannot assign to 'WriteStream' because it is not a variable. +node_modules/graceful-fs/graceful-fs.js(242,7): error TS2539: Cannot assign to 'ReadStream' because it is not a variable. +node_modules/graceful-fs/graceful-fs.js(252,7): error TS2539: Cannot assign to 'WriteStream' because it is not a variable. +node_modules/graceful-fs/graceful-fs.js(262,68): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[any?, any?, ...any[]]'. +node_modules/graceful-fs/graceful-fs.js(285,70): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[any?, any?, ...any[]]'. +node_modules/graceful-fs/graceful-fs.js(334,9): error TS2554: Expected 0 arguments, but got 3. +node_modules/graceful-fs/graceful-fs.js(341,11): error TS2554: Expected 0 arguments, but got 3. From 0e93cf61fc42f5aaca2f55122f44029dc36dd1c1 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 14 Aug 2019 09:26:35 -0700 Subject: [PATCH 08/18] Disallow incremental with noEmit Fixes #32882 --- src/compiler/program.ts | 4 ++++ .../reference/noEmitAndComposite.errors.txt | 19 ++++++++++++++++++ .../reference/noEmitAndComposite.symbols | 4 ++++ .../reference/noEmitAndComposite.types | 5 +++++ .../reference/noEmitAndIncremental.errors.txt | 20 +++++++++++++++++++ .../reference/noEmitAndIncremental.symbols | 4 ++++ .../reference/noEmitAndIncremental.types | 5 +++++ tests/cases/compiler/noEmitAndComposite.ts | 10 ++++++++++ tests/cases/compiler/noEmitAndIncremental.ts | 11 ++++++++++ 9 files changed, 82 insertions(+) create mode 100644 tests/baselines/reference/noEmitAndComposite.errors.txt create mode 100644 tests/baselines/reference/noEmitAndComposite.symbols create mode 100644 tests/baselines/reference/noEmitAndComposite.types create mode 100644 tests/baselines/reference/noEmitAndIncremental.errors.txt create mode 100644 tests/baselines/reference/noEmitAndIncremental.symbols create mode 100644 tests/baselines/reference/noEmitAndIncremental.types create mode 100644 tests/cases/compiler/noEmitAndComposite.ts create mode 100644 tests/cases/compiler/noEmitAndIncremental.ts diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 12dbe71f590..1c7cb0ca2c4 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2850,6 +2850,10 @@ namespace ts { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_incremental_can_only_be_specified_using_tsconfig_emitting_to_single_file_or_when_option_tsBuildInfoFile_is_specified)); } + if (options.noEmit && isIncrementalCompilation(options)) { + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", options.incremental ? "incremental" : "composite"); + } + verifyProjectReferences(); // List of collected files is complete; validate exhautiveness if this is a project with a file list diff --git a/tests/baselines/reference/noEmitAndComposite.errors.txt b/tests/baselines/reference/noEmitAndComposite.errors.txt new file mode 100644 index 00000000000..fe6de6ae441 --- /dev/null +++ b/tests/baselines/reference/noEmitAndComposite.errors.txt @@ -0,0 +1,19 @@ +/tsconfig.json(3,9): error TS5053: Option 'noEmit' cannot be specified with option 'composite'. +/tsconfig.json(4,9): error TS5053: Option 'noEmit' cannot be specified with option 'composite'. + + +==== /tsconfig.json (2 errors) ==== + { + "compilerOptions": { + "noEmit": true, + ~~~~~~~~ +!!! error TS5053: Option 'noEmit' cannot be specified with option 'composite'. + "composite": true + ~~~~~~~~~~~ +!!! error TS5053: Option 'noEmit' cannot be specified with option 'composite'. + } + } + +==== /a.ts (0 errors) ==== + const x = 10; + \ No newline at end of file diff --git a/tests/baselines/reference/noEmitAndComposite.symbols b/tests/baselines/reference/noEmitAndComposite.symbols new file mode 100644 index 00000000000..05c35bcf58a --- /dev/null +++ b/tests/baselines/reference/noEmitAndComposite.symbols @@ -0,0 +1,4 @@ +=== /a.ts === +const x = 10; +>x : Symbol(x, Decl(a.ts, 0, 5)) + diff --git a/tests/baselines/reference/noEmitAndComposite.types b/tests/baselines/reference/noEmitAndComposite.types new file mode 100644 index 00000000000..ed892fed2ba --- /dev/null +++ b/tests/baselines/reference/noEmitAndComposite.types @@ -0,0 +1,5 @@ +=== /a.ts === +const x = 10; +>x : 10 +>10 : 10 + diff --git a/tests/baselines/reference/noEmitAndIncremental.errors.txt b/tests/baselines/reference/noEmitAndIncremental.errors.txt new file mode 100644 index 00000000000..c257e9ba540 --- /dev/null +++ b/tests/baselines/reference/noEmitAndIncremental.errors.txt @@ -0,0 +1,20 @@ +/tsconfig.json(3,9): error TS5053: Option 'noEmit' cannot be specified with option 'incremental'. +/tsconfig.json(4,9): error TS5053: Option 'noEmit' cannot be specified with option 'incremental'. + + +==== /tsconfig.json (2 errors) ==== + { + "compilerOptions": { + "noEmit": true, + ~~~~~~~~ +!!! error TS5053: Option 'noEmit' cannot be specified with option 'incremental'. + "incremental": true + ~~~~~~~~~~~~~ +!!! error TS5053: Option 'noEmit' cannot be specified with option 'incremental'. + } + } + + +==== /a.ts (0 errors) ==== + const x = 10; + \ No newline at end of file diff --git a/tests/baselines/reference/noEmitAndIncremental.symbols b/tests/baselines/reference/noEmitAndIncremental.symbols new file mode 100644 index 00000000000..05c35bcf58a --- /dev/null +++ b/tests/baselines/reference/noEmitAndIncremental.symbols @@ -0,0 +1,4 @@ +=== /a.ts === +const x = 10; +>x : Symbol(x, Decl(a.ts, 0, 5)) + diff --git a/tests/baselines/reference/noEmitAndIncremental.types b/tests/baselines/reference/noEmitAndIncremental.types new file mode 100644 index 00000000000..ed892fed2ba --- /dev/null +++ b/tests/baselines/reference/noEmitAndIncremental.types @@ -0,0 +1,5 @@ +=== /a.ts === +const x = 10; +>x : 10 +>10 : 10 + diff --git a/tests/cases/compiler/noEmitAndComposite.ts b/tests/cases/compiler/noEmitAndComposite.ts new file mode 100644 index 00000000000..849fdb04da1 --- /dev/null +++ b/tests/cases/compiler/noEmitAndComposite.ts @@ -0,0 +1,10 @@ +// @Filename: /a.ts +const x = 10; + +// @Filename: /tsconfig.json +{ + "compilerOptions": { + "noEmit": true, + "composite": true + } +} diff --git a/tests/cases/compiler/noEmitAndIncremental.ts b/tests/cases/compiler/noEmitAndIncremental.ts new file mode 100644 index 00000000000..0349496c1ef --- /dev/null +++ b/tests/cases/compiler/noEmitAndIncremental.ts @@ -0,0 +1,11 @@ +// @Filename: /a.ts +const x = 10; + +// @Filename: /tsconfig.json +{ + "compilerOptions": { + "noEmit": true, + "incremental": true + } +} + From 8eeb763cdd2bf7611fc98a430d5a9d47e8545a5e Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Wed, 14 Aug 2019 21:00:19 +0200 Subject: [PATCH 09/18] report invalid modifiers on class expression properties Fixes: #32532 --- src/compiler/checker.ts | 4 ++-- .../classExpressionPropertyModifiers.errors.txt | 14 ++++++++++++++ .../compiler/classExpressionPropertyModifiers.ts | 8 ++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/classExpressionPropertyModifiers.errors.txt create mode 100644 tests/cases/compiler/classExpressionPropertyModifiers.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9d6fa60306c..74bf936d5c8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -32406,7 +32406,7 @@ namespace ts { else if (flags & ModifierFlags.Async) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "export", "async"); } - else if (node.parent.kind === SyntaxKind.ClassDeclaration) { + else if (isClassLike(node.parent)) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); } else if (node.kind === SyntaxKind.Parameter) { @@ -32429,7 +32429,7 @@ namespace ts { else if (flags & ModifierFlags.Async) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); } - else if (node.parent.kind === SyntaxKind.ClassDeclaration) { + else if (isClassLike(node.parent)) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); } else if (node.kind === SyntaxKind.Parameter) { diff --git a/tests/baselines/reference/classExpressionPropertyModifiers.errors.txt b/tests/baselines/reference/classExpressionPropertyModifiers.errors.txt new file mode 100644 index 00000000000..f4b3fed7e54 --- /dev/null +++ b/tests/baselines/reference/classExpressionPropertyModifiers.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/classExpressionPropertyModifiers.ts(2,5): error TS1031: 'declare' modifier cannot appear on a class element. +tests/cases/compiler/classExpressionPropertyModifiers.ts(3,5): error TS1031: 'export' modifier cannot appear on a class element. + + +==== tests/cases/compiler/classExpressionPropertyModifiers.ts (2 errors) ==== + const a = class Cat { + declare [Symbol.toStringTag] = "uh"; + ~~~~~~~ +!!! error TS1031: 'declare' modifier cannot appear on a class element. + export foo = 1; + ~~~~~~ +!!! error TS1031: 'export' modifier cannot appear on a class element. + } + \ No newline at end of file diff --git a/tests/cases/compiler/classExpressionPropertyModifiers.ts b/tests/cases/compiler/classExpressionPropertyModifiers.ts new file mode 100644 index 00000000000..be9e66eea8e --- /dev/null +++ b/tests/cases/compiler/classExpressionPropertyModifiers.ts @@ -0,0 +1,8 @@ +// @noEmit: true +// @noTypesAndSymbols: true +// @lib: es6 + +const a = class Cat { + declare [Symbol.toStringTag] = "uh"; + export foo = 1; +} From 11c28d6dd02f4a7d5e0d1f26c327d81b8fb85325 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 14 Aug 2019 13:00:26 -0700 Subject: [PATCH 10/18] Update versions to 3.7 (#32879) * Update versions to 3.7 * Update API baselines --- package.json | 2 +- src/compiler/core.ts | 2 +- tests/baselines/reference/api/tsserverlibrary.d.ts | 2 +- tests/baselines/reference/api/typescript.d.ts | 2 +- tests/cases/user/axios-src/axios-src | 2 +- tests/cases/user/create-react-app/create-react-app | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index a90be2f813c..6b89005c734 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "https://www.typescriptlang.org/", - "version": "3.6.0", + "version": "3.7.0", "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 933c599c41a..12fbd6fb4ff 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1,7 +1,7 @@ namespace ts { // WARNING: The script `configureNightly.ts` uses a regexp to parse out these values. // If changing the text in this section, be sure to test `configureNightly` too. - export const versionMajorMinor = "3.6"; + export const versionMajorMinor = "3.7"; /** The version of the TypeScript compiler release */ export const version = `${versionMajorMinor}.0-dev`; } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index df6363e9897..3c660bbc6db 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -14,7 +14,7 @@ and limitations under the License. ***************************************************************************** */ declare namespace ts { - const versionMajorMinor = "3.6"; + const versionMajorMinor = "3.7"; /** The version of the TypeScript compiler release */ const version: string; } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index cfae470b8e2..515cbd77d05 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -14,7 +14,7 @@ and limitations under the License. ***************************************************************************** */ declare namespace ts { - const versionMajorMinor = "3.6"; + const versionMajorMinor = "3.7"; /** The version of the TypeScript compiler release */ const version: string; } diff --git a/tests/cases/user/axios-src/axios-src b/tests/cases/user/axios-src/axios-src index 283d7b306ce..21ae22dbd3a 160000 --- a/tests/cases/user/axios-src/axios-src +++ b/tests/cases/user/axios-src/axios-src @@ -1 +1 @@ -Subproject commit 283d7b306ce231f092d28e01713905e5c1600d14 +Subproject commit 21ae22dbd3ae3d3a55d9efd4eead3dd7fb6d8e6e diff --git a/tests/cases/user/create-react-app/create-react-app b/tests/cases/user/create-react-app/create-react-app index 1a61db58d43..dc74990b89b 160000 --- a/tests/cases/user/create-react-app/create-react-app +++ b/tests/cases/user/create-react-app/create-react-app @@ -1 +1 @@ -Subproject commit 1a61db58d434d33603f20e73ca643ec83c561b73 +Subproject commit dc74990b89b5c6e143b522c759be3dac2c286514 From 2217f0b859f0d23049d7bbf27473e6989bfa182a Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 14 Aug 2019 15:50:25 -0700 Subject: [PATCH 11/18] Fix export=global auto import exclusion (#32898) --- src/services/completions.ts | 2 +- .../completionsImport_exportEquals_global.ts | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionsImport_exportEquals_global.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index bf7ff041f2d..c7ea7b5a40e 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1289,7 +1289,7 @@ namespace ts.Completions { if (resolvedModuleSymbol !== moduleSymbol && // Don't add another completion for `export =` of a symbol that's already global. // So in `declare namespace foo {} declare module "foo" { export = foo; }`, there will just be the global completion for `foo`. - some(resolvedModuleSymbol.declarations, d => !!d.getSourceFile().externalModuleIndicator)) { + every(resolvedModuleSymbol.declarations, d => !!d.getSourceFile().externalModuleIndicator)) { symbols.push(resolvedModuleSymbol); symbolToSortTextMap[getSymbolId(resolvedModuleSymbol)] = SortText.AutoImportSuggestions; symbolToOriginInfoMap[getSymbolId(resolvedModuleSymbol)] = { kind: SymbolOriginInfoKind.Export, moduleSymbol, isDefaultExport: false }; diff --git a/tests/cases/fourslash/completionsImport_exportEquals_global.ts b/tests/cases/fourslash/completionsImport_exportEquals_global.ts new file mode 100644 index 00000000000..7e11b169579 --- /dev/null +++ b/tests/cases/fourslash/completionsImport_exportEquals_global.ts @@ -0,0 +1,31 @@ +/// + +// @module: es6 + +// @Filename: /console.d.ts +////interface Console {} +////declare var console: Console; +////declare module "console" { +//// export = console; +////} + +// @Filename: /react-native.d.ts +//// import 'console'; +////declare global { +//// interface Console {} +//// var console: Console; +////} + +// @Filename: /a.ts +////conso/**/ + +verify.completions({ + exact: completion.globalsPlus([{ + hasAction: undefined, // asserts that it does *not* have an action + name: "console" + }]), + preferences: { + includeCompletionsForModuleExports: true, + includeInsertTextCompletions: true + } +}); From c555d4df899e8d953b8bdb1d9fe13a66fb00b39c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 14 Aug 2019 16:02:35 -0700 Subject: [PATCH 12/18] Report on base primitives for certain operations. --- src/compiler/checker.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 74bf936d5c8..65722fa6d52 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -24744,18 +24744,23 @@ namespace ts { return false; } - function reportOperatorError(awaitedTypesAreCompatible?: (left: Type, right: Type) => boolean) { + function reportOperatorError(isRelated?: (left: Type, right: Type) => boolean) { let wouldWorkWithAwait = false; const errNode = errorNode || operatorToken; - const [leftStr, rightStr] = getTypeNamesForErrorDisplay(leftType, rightType); - if (awaitedTypesAreCompatible) { + if (isRelated) { const awaitedLeftType = getAwaitedType(leftType); const awaitedRightType = getAwaitedType(rightType); wouldWorkWithAwait = !(awaitedLeftType === leftType && awaitedRightType === rightType) && !!(awaitedLeftType && awaitedRightType) - && awaitedTypesAreCompatible(awaitedLeftType, awaitedRightType); + && isRelated(awaitedLeftType, awaitedRightType); } + let effectiveLeft = leftType; + let effectiveRight = rightType; + if (!wouldWorkWithAwait && isRelated) { + [effectiveLeft, effectiveRight] = getBaseTypesIfUnrelated(leftType, rightType, isRelated); + } + let [leftStr, rightStr] = getTypeNamesForErrorDisplay(effectiveLeft, effectiveRight); if (!tryGiveBetterPrimaryError(errNode, wouldWorkWithAwait, leftStr, rightStr)) { errorAndMaybeSuggestAwait( errNode, @@ -24792,6 +24797,18 @@ namespace ts { } } + function getBaseTypesIfUnrelated(leftType: Type, rightType: Type, isRelated: (left: Type, right: Type) => boolean): [Type, Type] { + let effectiveLeft = leftType; + let effectiveRight = rightType; + const leftBase = getBaseTypeOfLiteralType(leftType); + const rightBase = getBaseTypeOfLiteralType(rightType); + if (!isRelated(leftBase, rightBase)) { + effectiveLeft = leftBase; + effectiveRight = rightBase; + } + return [ effectiveLeft, effectiveRight ]; + } + function isYieldExpressionInClass(node: YieldExpression): boolean { let current: Node = node; let parent = node.parent; From cdd6b418d8e552e382d0e08bedfbb47ab2278052 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 14 Aug 2019 16:02:53 -0700 Subject: [PATCH 13/18] Accepted baselines. --- ...tionOperatorWithInvalidOperands.errors.txt | 24 +-- ...WithNullValueAndInvalidOperator.errors.txt | 4 +- ...ndefinedValueAndInvalidOperands.errors.txt | 4 +- ...onAssignmentWithInvalidOperands.errors.txt | 44 ++--- ...putedPropertiesInDestructuring1.errors.txt | 4 +- ...dPropertiesInDestructuring1_ES6.errors.txt | 4 +- .../for-inStatementsArrayErrors.errors.txt | 4 +- .../numberVsBigIntOperations.errors.txt | 168 +++++++++--------- ...eralTypesWithVariousOperators02.errors.txt | 20 +-- ...sertionsInEqualityComparisons02.errors.txt | 4 +- .../reference/symbolType12.errors.txt | 4 +- .../reference/symbolType6.errors.txt | 8 +- .../reference/symbolType9.errors.txt | 16 +- 13 files changed, 154 insertions(+), 154 deletions(-) diff --git a/tests/baselines/reference/additionOperatorWithInvalidOperands.errors.txt b/tests/baselines/reference/additionOperatorWithInvalidOperands.errors.txt index 124120cef2c..bd71b64b501 100644 --- a/tests/baselines/reference/additionOperatorWithInvalidOperands.errors.txt +++ b/tests/baselines/reference/additionOperatorWithInvalidOperands.errors.txt @@ -6,17 +6,17 @@ tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOpe tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(25,10): error TS2365: Operator '+' cannot be applied to types 'Object' and 'boolean'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(26,10): error TS2365: Operator '+' cannot be applied to types 'Object' and 'number'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(27,10): error TS2365: Operator '+' cannot be applied to types 'Object' and 'Object'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(30,11): error TS2365: Operator '+' cannot be applied to types 'boolean' and 'true'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(31,11): error TS2365: Operator '+' cannot be applied to types 'true' and 'false'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(32,11): error TS2365: Operator '+' cannot be applied to types 'true' and '123'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(30,11): error TS2365: Operator '+' cannot be applied to types 'boolean' and 'boolean'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(31,11): error TS2365: Operator '+' cannot be applied to types 'boolean' and 'boolean'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(32,11): error TS2365: Operator '+' cannot be applied to types 'boolean' and 'number'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(33,11): error TS2365: Operator '+' cannot be applied to types '{}' and '{}'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(34,11): error TS2365: Operator '+' cannot be applied to types 'number' and 'Number'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(35,11): error TS2365: Operator '+' cannot be applied to types 'number' and '() => void'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(36,11): error TS2365: Operator '+' cannot be applied to types 'number' and 'void'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(37,11): error TS2365: Operator '+' cannot be applied to types 'number' and 'typeof C'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(38,11): error TS2365: Operator '+' cannot be applied to types 'E.a' and 'C'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(39,11): error TS2365: Operator '+' cannot be applied to types 'E.a' and 'void'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(40,11): error TS2365: Operator '+' cannot be applied to types 'E.a' and 'typeof M'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(38,11): error TS2365: Operator '+' cannot be applied to types 'E' and 'C'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(39,11): error TS2365: Operator '+' cannot be applied to types 'E' and 'void'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts(40,11): error TS2365: Operator '+' cannot be applied to types 'E' and 'typeof M'. ==== tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithInvalidOperands.ts (19 errors) ==== @@ -67,13 +67,13 @@ tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOpe // other cases var r10 = a + true; ~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'boolean' and 'true'. +!!! error TS2365: Operator '+' cannot be applied to types 'boolean' and 'boolean'. var r11 = true + false; ~~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'true' and 'false'. +!!! error TS2365: Operator '+' cannot be applied to types 'boolean' and 'boolean'. var r12 = true + 123; ~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'true' and '123'. +!!! error TS2365: Operator '+' cannot be applied to types 'boolean' and 'number'. var r13 = {} + {}; ~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types '{}' and '{}'. @@ -91,10 +91,10 @@ tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOpe !!! error TS2365: Operator '+' cannot be applied to types 'number' and 'typeof C'. var r18 = E.a + new C(); ~~~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'E.a' and 'C'. +!!! error TS2365: Operator '+' cannot be applied to types 'E' and 'C'. var r19 = E.a + C.foo(); ~~~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'E.a' and 'void'. +!!! error TS2365: Operator '+' cannot be applied to types 'E' and 'void'. var r20 = E.a + M; ~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'E.a' and 'typeof M'. \ No newline at end of file +!!! error TS2365: Operator '+' cannot be applied to types 'E' and 'typeof M'. \ No newline at end of file diff --git a/tests/baselines/reference/additionOperatorWithNullValueAndInvalidOperator.errors.txt b/tests/baselines/reference/additionOperatorWithNullValueAndInvalidOperator.errors.txt index 891fe86dcd1..04d4606ef9f 100644 --- a/tests/baselines/reference/additionOperatorWithNullValueAndInvalidOperator.errors.txt +++ b/tests/baselines/reference/additionOperatorWithNullValueAndInvalidOperator.errors.txt @@ -5,7 +5,7 @@ tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOpe tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(15,10): error TS2365: Operator '+' cannot be applied to types 'Object' and 'null'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(16,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'void'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(19,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'Number'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(20,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'true'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(20,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'boolean'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(21,10): error TS2365: Operator '+' cannot be applied to types 'null' and '{ a: string; }'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(22,11): error TS2365: Operator '+' cannot be applied to types 'null' and 'void'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(23,11): error TS2365: Operator '+' cannot be applied to types 'null' and '() => void'. @@ -47,7 +47,7 @@ tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOpe !!! error TS2365: Operator '+' cannot be applied to types 'null' and 'Number'. var r8 = null + true; ~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'true'. +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'boolean'. var r9 = null + { a: '' }; ~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'null' and '{ a: string; }'. diff --git a/tests/baselines/reference/additionOperatorWithUndefinedValueAndInvalidOperands.errors.txt b/tests/baselines/reference/additionOperatorWithUndefinedValueAndInvalidOperands.errors.txt index 6be41e81fd5..151ad3cc658 100644 --- a/tests/baselines/reference/additionOperatorWithUndefinedValueAndInvalidOperands.errors.txt +++ b/tests/baselines/reference/additionOperatorWithUndefinedValueAndInvalidOperands.errors.txt @@ -5,7 +5,7 @@ tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOpe tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(15,10): error TS2365: Operator '+' cannot be applied to types 'Object' and 'undefined'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(16,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'void'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(19,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'Number'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(20,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'true'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(20,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'boolean'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(21,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and '{ a: string; }'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(22,11): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'void'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(23,11): error TS2365: Operator '+' cannot be applied to types 'undefined' and '() => void'. @@ -47,7 +47,7 @@ tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOpe !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'Number'. var r8 = undefined + true; ~~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'true'. +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'boolean'. var r9 = undefined + { a: '' }; ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and '{ a: string; }'. diff --git a/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.errors.txt b/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.errors.txt index e570f2f6cf0..f897e127a21 100644 --- a/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.errors.txt +++ b/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.errors.txt @@ -1,29 +1,29 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(6,1): error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'void'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(7,1): error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'true'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(8,1): error TS2365: Operator '+=' cannot be applied to types 'boolean' and '0'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(9,1): error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'E.a'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(7,1): error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'boolean'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(8,1): error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'number'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(9,1): error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'E'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(10,1): error TS2365: Operator '+=' cannot be applied to types 'boolean' and '{}'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(11,1): error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'null'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(12,1): error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'undefined'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(15,1): error TS2365: Operator '+=' cannot be applied to types '{}' and 'void'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(16,1): error TS2365: Operator '+=' cannot be applied to types '{}' and 'true'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(17,1): error TS2365: Operator '+=' cannot be applied to types '{}' and '0'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(18,1): error TS2365: Operator '+=' cannot be applied to types '{}' and 'E.a'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(16,1): error TS2365: Operator '+=' cannot be applied to types '{}' and 'boolean'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(17,1): error TS2365: Operator '+=' cannot be applied to types '{}' and 'number'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(18,1): error TS2365: Operator '+=' cannot be applied to types '{}' and 'E'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(19,1): error TS2365: Operator '+=' cannot be applied to types '{}' and '{}'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(20,1): error TS2365: Operator '+=' cannot be applied to types '{}' and 'null'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(21,1): error TS2365: Operator '+=' cannot be applied to types '{}' and 'undefined'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(24,1): error TS2365: Operator '+=' cannot be applied to types 'void' and 'void'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(25,1): error TS2365: Operator '+=' cannot be applied to types 'void' and 'true'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(26,1): error TS2365: Operator '+=' cannot be applied to types 'void' and '0'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(27,1): error TS2365: Operator '+=' cannot be applied to types 'void' and 'E.a'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(25,1): error TS2365: Operator '+=' cannot be applied to types 'void' and 'boolean'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(26,1): error TS2365: Operator '+=' cannot be applied to types 'void' and 'number'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(27,1): error TS2365: Operator '+=' cannot be applied to types 'void' and 'E'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(28,1): error TS2365: Operator '+=' cannot be applied to types 'void' and '{}'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(29,1): error TS2365: Operator '+=' cannot be applied to types 'void' and 'null'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(30,1): error TS2365: Operator '+=' cannot be applied to types 'void' and 'undefined'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(33,1): error TS2365: Operator '+=' cannot be applied to types 'number' and 'void'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(34,1): error TS2365: Operator '+=' cannot be applied to types 'number' and 'true'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(34,1): error TS2365: Operator '+=' cannot be applied to types 'number' and 'boolean'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(35,1): error TS2365: Operator '+=' cannot be applied to types 'number' and '{}'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(38,1): error TS2365: Operator '+=' cannot be applied to types 'E' and 'void'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(39,1): error TS2365: Operator '+=' cannot be applied to types 'E' and 'true'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(39,1): error TS2365: Operator '+=' cannot be applied to types 'E' and 'boolean'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(40,1): error TS2365: Operator '+=' cannot be applied to types 'E' and '{}'. @@ -38,13 +38,13 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmen !!! error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'void'. x1 += true; ~~~~~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'true'. +!!! error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'boolean'. x1 += 0; ~~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types 'boolean' and '0'. +!!! error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'number'. x1 += E.a; ~~~~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'E.a'. +!!! error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'E'. x1 += {}; ~~~~~~~~ !!! error TS2365: Operator '+=' cannot be applied to types 'boolean' and '{}'. @@ -61,13 +61,13 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmen !!! error TS2365: Operator '+=' cannot be applied to types '{}' and 'void'. x2 += true; ~~~~~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types '{}' and 'true'. +!!! error TS2365: Operator '+=' cannot be applied to types '{}' and 'boolean'. x2 += 0; ~~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types '{}' and '0'. +!!! error TS2365: Operator '+=' cannot be applied to types '{}' and 'number'. x2 += E.a; ~~~~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types '{}' and 'E.a'. +!!! error TS2365: Operator '+=' cannot be applied to types '{}' and 'E'. x2 += {}; ~~~~~~~~ !!! error TS2365: Operator '+=' cannot be applied to types '{}' and '{}'. @@ -84,13 +84,13 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmen !!! error TS2365: Operator '+=' cannot be applied to types 'void' and 'void'. x3 += true; ~~~~~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types 'void' and 'true'. +!!! error TS2365: Operator '+=' cannot be applied to types 'void' and 'boolean'. x3 += 0; ~~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types 'void' and '0'. +!!! error TS2365: Operator '+=' cannot be applied to types 'void' and 'number'. x3 += E.a; ~~~~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types 'void' and 'E.a'. +!!! error TS2365: Operator '+=' cannot be applied to types 'void' and 'E'. x3 += {}; ~~~~~~~~ !!! error TS2365: Operator '+=' cannot be applied to types 'void' and '{}'. @@ -107,7 +107,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmen !!! error TS2365: Operator '+=' cannot be applied to types 'number' and 'void'. x4 += true; ~~~~~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types 'number' and 'true'. +!!! error TS2365: Operator '+=' cannot be applied to types 'number' and 'boolean'. x4 += {}; ~~~~~~~~ !!! error TS2365: Operator '+=' cannot be applied to types 'number' and '{}'. @@ -118,7 +118,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmen !!! error TS2365: Operator '+=' cannot be applied to types 'E' and 'void'. x5 += true; ~~~~~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types 'E' and 'true'. +!!! error TS2365: Operator '+=' cannot be applied to types 'E' and 'boolean'. x5 += {}; ~~~~~~~~ !!! error TS2365: Operator '+=' cannot be applied to types 'E' and '{}'. \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertiesInDestructuring1.errors.txt b/tests/baselines/reference/computedPropertiesInDestructuring1.errors.txt index 3ae69897818..ca6568197a0 100644 --- a/tests/baselines/reference/computedPropertiesInDestructuring1.errors.txt +++ b/tests/baselines/reference/computedPropertiesInDestructuring1.errors.txt @@ -19,7 +19,7 @@ tests/cases/compiler/computedPropertiesInDestructuring1.ts(33,4): error TS2349: Type 'String' has no call signatures. tests/cases/compiler/computedPropertiesInDestructuring1.ts(33,4): error TS2538: Type 'any' cannot be used as an index type. tests/cases/compiler/computedPropertiesInDestructuring1.ts(34,4): error TS2538: Type 'any' cannot be used as an index type. -tests/cases/compiler/computedPropertiesInDestructuring1.ts(34,5): error TS2365: Operator '+' cannot be applied to types '1' and '{}'. +tests/cases/compiler/computedPropertiesInDestructuring1.ts(34,5): error TS2365: Operator '+' cannot be applied to types 'number' and '{}'. ==== tests/cases/compiler/computedPropertiesInDestructuring1.ts (20 errors) ==== @@ -98,7 +98,7 @@ tests/cases/compiler/computedPropertiesInDestructuring1.ts(34,5): error TS2365: ~~~~~~~~ !!! error TS2538: Type 'any' cannot be used as an index type. ~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types '1' and '{}'. +!!! error TS2365: Operator '+' cannot be applied to types 'number' and '{}'. \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertiesInDestructuring1_ES6.errors.txt b/tests/baselines/reference/computedPropertiesInDestructuring1_ES6.errors.txt index 0e4ac5c8aef..4aa606cae20 100644 --- a/tests/baselines/reference/computedPropertiesInDestructuring1_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertiesInDestructuring1_ES6.errors.txt @@ -19,7 +19,7 @@ tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(34,4): error TS23 Type 'String' has no call signatures. tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(34,4): error TS2538: Type 'any' cannot be used as an index type. tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(35,4): error TS2538: Type 'any' cannot be used as an index type. -tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(35,5): error TS2365: Operator '+' cannot be applied to types '1' and '{}'. +tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(35,5): error TS2365: Operator '+' cannot be applied to types 'number' and '{}'. ==== tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts (20 errors) ==== @@ -99,5 +99,5 @@ tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(35,5): error TS23 ~~~~~~~~ !!! error TS2538: Type 'any' cannot be used as an index type. ~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types '1' and '{}'. +!!! error TS2365: Operator '+' cannot be applied to types 'number' and '{}'. \ No newline at end of file diff --git a/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt b/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt index 2eb08a8b1f3..86f35b16985 100644 --- a/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt +++ b/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(4,16): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(5,16): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. -tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(6,9): error TS2367: This condition will always return 'false' since the types 'string' and '1' have no overlap. +tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(6,9): error TS2367: This condition will always return 'false' since the types 'string' and 'number' have no overlap. tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(8,16): error TS2339: Property 'unknownProperty' does not exist on type 'string'. tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(12,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type 'number', but here has type 'string'. tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(16,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'j' must be of type 'any', but here has type 'string'. @@ -18,7 +18,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors. !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. if (x === 1) { ~~~~~~~ -!!! error TS2367: This condition will always return 'false' since the types 'string' and '1' have no overlap. +!!! error TS2367: This condition will always return 'false' since the types 'string' and 'number' have no overlap. } let a3 = x.unknownProperty; ~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/numberVsBigIntOperations.errors.txt b/tests/baselines/reference/numberVsBigIntOperations.errors.txt index fbd49ddd091..ee263533858 100644 --- a/tests/baselines/reference/numberVsBigIntOperations.errors.txt +++ b/tests/baselines/reference/numberVsBigIntOperations.errors.txt @@ -2,48 +2,48 @@ tests/cases/compiler/numberVsBigIntOperations.ts(3,14): error TS2322: Type '2' i tests/cases/compiler/numberVsBigIntOperations.ts(3,26): error TS2322: Type '1n' is not assignable to type 'number'. tests/cases/compiler/numberVsBigIntOperations.ts(4,15): error TS2365: Operator '+=' cannot be applied to types 'bigint' and '2'. tests/cases/compiler/numberVsBigIntOperations.ts(4,28): error TS2365: Operator '+=' cannot be applied to types 'number' and '1n'. -tests/cases/compiler/numberVsBigIntOperations.ts(5,15): error TS2365: Operator '-=' cannot be applied to types 'bigint' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(5,28): error TS2365: Operator '-=' cannot be applied to types 'number' and '1n'. -tests/cases/compiler/numberVsBigIntOperations.ts(6,15): error TS2365: Operator '*=' cannot be applied to types 'bigint' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(6,28): error TS2365: Operator '*=' cannot be applied to types 'number' and '1n'. -tests/cases/compiler/numberVsBigIntOperations.ts(7,15): error TS2365: Operator '/=' cannot be applied to types 'bigint' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(7,28): error TS2365: Operator '/=' cannot be applied to types 'number' and '1n'. -tests/cases/compiler/numberVsBigIntOperations.ts(8,15): error TS2365: Operator '%=' cannot be applied to types 'bigint' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(8,28): error TS2365: Operator '%=' cannot be applied to types 'number' and '1n'. -tests/cases/compiler/numberVsBigIntOperations.ts(9,16): error TS2365: Operator '**=' cannot be applied to types 'bigint' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(9,30): error TS2365: Operator '**=' cannot be applied to types 'number' and '1n'. -tests/cases/compiler/numberVsBigIntOperations.ts(10,16): error TS2365: Operator '<<=' cannot be applied to types 'bigint' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(10,30): error TS2365: Operator '<<=' cannot be applied to types 'number' and '1n'. -tests/cases/compiler/numberVsBigIntOperations.ts(11,16): error TS2365: Operator '>>=' cannot be applied to types 'bigint' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(11,30): error TS2365: Operator '>>=' cannot be applied to types 'number' and '1n'. -tests/cases/compiler/numberVsBigIntOperations.ts(12,15): error TS2365: Operator '&=' cannot be applied to types 'bigint' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(12,28): error TS2365: Operator '&=' cannot be applied to types 'number' and '1n'. -tests/cases/compiler/numberVsBigIntOperations.ts(13,15): error TS2365: Operator '^=' cannot be applied to types 'bigint' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(13,28): error TS2365: Operator '^=' cannot be applied to types 'number' and '1n'. -tests/cases/compiler/numberVsBigIntOperations.ts(14,15): error TS2365: Operator '|=' cannot be applied to types 'bigint' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(14,28): error TS2365: Operator '|=' cannot be applied to types 'number' and '1n'. +tests/cases/compiler/numberVsBigIntOperations.ts(5,15): error TS2365: Operator '-=' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(5,28): error TS2365: Operator '-=' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(6,15): error TS2365: Operator '*=' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(6,28): error TS2365: Operator '*=' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(7,15): error TS2365: Operator '/=' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(7,28): error TS2365: Operator '/=' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(8,15): error TS2365: Operator '%=' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(8,28): error TS2365: Operator '%=' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(9,16): error TS2365: Operator '**=' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(9,30): error TS2365: Operator '**=' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(10,16): error TS2365: Operator '<<=' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(10,30): error TS2365: Operator '<<=' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(11,16): error TS2365: Operator '>>=' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(11,30): error TS2365: Operator '>>=' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(12,15): error TS2365: Operator '&=' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(12,28): error TS2365: Operator '&=' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(13,15): error TS2365: Operator '^=' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(13,28): error TS2365: Operator '^=' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(14,15): error TS2365: Operator '|=' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(14,28): error TS2365: Operator '|=' cannot be applied to types 'number' and 'bigint'. tests/cases/compiler/numberVsBigIntOperations.ts(15,32): error TS2365: Operator '+' cannot be applied to types '1' and '2n'. tests/cases/compiler/numberVsBigIntOperations.ts(15,40): error TS2365: Operator '+' cannot be applied to types '1n' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(16,32): error TS2365: Operator '-' cannot be applied to types '1' and '2n'. -tests/cases/compiler/numberVsBigIntOperations.ts(16,40): error TS2365: Operator '-' cannot be applied to types '1n' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(17,32): error TS2365: Operator '*' cannot be applied to types '1' and '2n'. -tests/cases/compiler/numberVsBigIntOperations.ts(17,40): error TS2365: Operator '*' cannot be applied to types '1n' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(18,32): error TS2365: Operator '/' cannot be applied to types '1' and '2n'. -tests/cases/compiler/numberVsBigIntOperations.ts(18,40): error TS2365: Operator '/' cannot be applied to types '1n' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(19,32): error TS2365: Operator '%' cannot be applied to types '1' and '2n'. -tests/cases/compiler/numberVsBigIntOperations.ts(19,40): error TS2365: Operator '%' cannot be applied to types '1n' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(20,34): error TS2365: Operator '**' cannot be applied to types '1' and '2n'. -tests/cases/compiler/numberVsBigIntOperations.ts(20,43): error TS2365: Operator '**' cannot be applied to types '1n' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(21,32): error TS2365: Operator '&' cannot be applied to types '1' and '2n'. -tests/cases/compiler/numberVsBigIntOperations.ts(21,40): error TS2365: Operator '&' cannot be applied to types '1n' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(22,32): error TS2365: Operator '|' cannot be applied to types '1' and '2n'. -tests/cases/compiler/numberVsBigIntOperations.ts(22,40): error TS2365: Operator '|' cannot be applied to types '1n' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(23,32): error TS2365: Operator '^' cannot be applied to types '1' and '2n'. -tests/cases/compiler/numberVsBigIntOperations.ts(23,40): error TS2365: Operator '^' cannot be applied to types '1n' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(24,34): error TS2365: Operator '<<' cannot be applied to types '1' and '2n'. -tests/cases/compiler/numberVsBigIntOperations.ts(24,43): error TS2365: Operator '<<' cannot be applied to types '1n' and '2'. -tests/cases/compiler/numberVsBigIntOperations.ts(25,34): error TS2365: Operator '>>' cannot be applied to types '1' and '2n'. -tests/cases/compiler/numberVsBigIntOperations.ts(25,43): error TS2365: Operator '>>' cannot be applied to types '1n' and '2'. +tests/cases/compiler/numberVsBigIntOperations.ts(16,32): error TS2365: Operator '-' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(16,40): error TS2365: Operator '-' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(17,32): error TS2365: Operator '*' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(17,40): error TS2365: Operator '*' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(18,32): error TS2365: Operator '/' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(18,40): error TS2365: Operator '/' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(19,32): error TS2365: Operator '%' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(19,40): error TS2365: Operator '%' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(20,34): error TS2365: Operator '**' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(20,43): error TS2365: Operator '**' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(21,32): error TS2365: Operator '&' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(21,40): error TS2365: Operator '&' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(22,32): error TS2365: Operator '|' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(22,40): error TS2365: Operator '|' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(23,32): error TS2365: Operator '^' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(23,40): error TS2365: Operator '^' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(24,34): error TS2365: Operator '<<' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(24,43): error TS2365: Operator '<<' cannot be applied to types 'bigint' and 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(25,34): error TS2365: Operator '>>' cannot be applied to types 'number' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(25,43): error TS2365: Operator '>>' cannot be applied to types 'bigint' and 'number'. tests/cases/compiler/numberVsBigIntOperations.ts(38,1): error TS2365: Operator '>>>=' cannot be applied to types 'bigint' and '1n'. tests/cases/compiler/numberVsBigIntOperations.ts(39,10): error TS2365: Operator '>>>' cannot be applied to types 'bigint' and '1n'. tests/cases/compiler/numberVsBigIntOperations.ts(40,8): error TS2736: Operator '+' cannot be applied to type 'bigint'. @@ -54,8 +54,8 @@ tests/cases/compiler/numberVsBigIntOperations.ts(53,10): error TS2367: This cond tests/cases/compiler/numberVsBigIntOperations.ts(56,7): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/compiler/numberVsBigIntOperations.ts(56,27): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/compiler/numberVsBigIntOperations.ts(57,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. -tests/cases/compiler/numberVsBigIntOperations.ts(57,1): error TS2365: Operator '&' cannot be applied to types '"3"' and '5n'. -tests/cases/compiler/numberVsBigIntOperations.ts(57,11): error TS2365: Operator '**' cannot be applied to types '2n' and 'false'. +tests/cases/compiler/numberVsBigIntOperations.ts(57,1): error TS2365: Operator '&' cannot be applied to types 'string' and 'bigint'. +tests/cases/compiler/numberVsBigIntOperations.ts(57,11): error TS2365: Operator '**' cannot be applied to types 'bigint' and 'boolean'. tests/cases/compiler/numberVsBigIntOperations.ts(57,17): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/compiler/numberVsBigIntOperations.ts(60,1): error TS2365: Operator '+' cannot be applied to types 'number | bigint' and 'number | bigint'. tests/cases/compiler/numberVsBigIntOperations.ts(61,1): error TS2365: Operator '<<' cannot be applied to types 'number | bigint' and 'number | bigint'. @@ -79,54 +79,54 @@ tests/cases/compiler/numberVsBigIntOperations.ts(93,7): error TS1155: 'const' de !!! error TS2365: Operator '+=' cannot be applied to types 'number' and '1n'. bigInt -= 1n; bigInt -= 2; num -= 1n; num -= 2; ~~~~~~~~~~~ -!!! error TS2365: Operator '-=' cannot be applied to types 'bigint' and '2'. +!!! error TS2365: Operator '-=' cannot be applied to types 'bigint' and 'number'. ~~~~~~~~~ -!!! error TS2365: Operator '-=' cannot be applied to types 'number' and '1n'. +!!! error TS2365: Operator '-=' cannot be applied to types 'number' and 'bigint'. bigInt *= 1n; bigInt *= 2; num *= 1n; num *= 2; ~~~~~~~~~~~ -!!! error TS2365: Operator '*=' cannot be applied to types 'bigint' and '2'. +!!! error TS2365: Operator '*=' cannot be applied to types 'bigint' and 'number'. ~~~~~~~~~ -!!! error TS2365: Operator '*=' cannot be applied to types 'number' and '1n'. +!!! error TS2365: Operator '*=' cannot be applied to types 'number' and 'bigint'. bigInt /= 1n; bigInt /= 2; num /= 1n; num /= 2; ~~~~~~~~~~~ -!!! error TS2365: Operator '/=' cannot be applied to types 'bigint' and '2'. +!!! error TS2365: Operator '/=' cannot be applied to types 'bigint' and 'number'. ~~~~~~~~~ -!!! error TS2365: Operator '/=' cannot be applied to types 'number' and '1n'. +!!! error TS2365: Operator '/=' cannot be applied to types 'number' and 'bigint'. bigInt %= 1n; bigInt %= 2; num %= 1n; num %= 2; ~~~~~~~~~~~ -!!! error TS2365: Operator '%=' cannot be applied to types 'bigint' and '2'. +!!! error TS2365: Operator '%=' cannot be applied to types 'bigint' and 'number'. ~~~~~~~~~ -!!! error TS2365: Operator '%=' cannot be applied to types 'number' and '1n'. +!!! error TS2365: Operator '%=' cannot be applied to types 'number' and 'bigint'. bigInt **= 1n; bigInt **= 2; num **= 1n; num **= 2; ~~~~~~~~~~~~ -!!! error TS2365: Operator '**=' cannot be applied to types 'bigint' and '2'. +!!! error TS2365: Operator '**=' cannot be applied to types 'bigint' and 'number'. ~~~~~~~~~~ -!!! error TS2365: Operator '**=' cannot be applied to types 'number' and '1n'. +!!! error TS2365: Operator '**=' cannot be applied to types 'number' and 'bigint'. bigInt <<= 1n; bigInt <<= 2; num <<= 1n; num <<= 2; ~~~~~~~~~~~~ -!!! error TS2365: Operator '<<=' cannot be applied to types 'bigint' and '2'. +!!! error TS2365: Operator '<<=' cannot be applied to types 'bigint' and 'number'. ~~~~~~~~~~ -!!! error TS2365: Operator '<<=' cannot be applied to types 'number' and '1n'. +!!! error TS2365: Operator '<<=' cannot be applied to types 'number' and 'bigint'. bigInt >>= 1n; bigInt >>= 2; num >>= 1n; num >>= 2; ~~~~~~~~~~~~ -!!! error TS2365: Operator '>>=' cannot be applied to types 'bigint' and '2'. +!!! error TS2365: Operator '>>=' cannot be applied to types 'bigint' and 'number'. ~~~~~~~~~~ -!!! error TS2365: Operator '>>=' cannot be applied to types 'number' and '1n'. +!!! error TS2365: Operator '>>=' cannot be applied to types 'number' and 'bigint'. bigInt &= 1n; bigInt &= 2; num &= 1n; num &= 2; ~~~~~~~~~~~ -!!! error TS2365: Operator '&=' cannot be applied to types 'bigint' and '2'. +!!! error TS2365: Operator '&=' cannot be applied to types 'bigint' and 'number'. ~~~~~~~~~ -!!! error TS2365: Operator '&=' cannot be applied to types 'number' and '1n'. +!!! error TS2365: Operator '&=' cannot be applied to types 'number' and 'bigint'. bigInt ^= 1n; bigInt ^= 2; num ^= 1n; num ^= 2; ~~~~~~~~~~~ -!!! error TS2365: Operator '^=' cannot be applied to types 'bigint' and '2'. +!!! error TS2365: Operator '^=' cannot be applied to types 'bigint' and 'number'. ~~~~~~~~~ -!!! error TS2365: Operator '^=' cannot be applied to types 'number' and '1n'. +!!! error TS2365: Operator '^=' cannot be applied to types 'number' and 'bigint'. bigInt |= 1n; bigInt |= 2; num |= 1n; num |= 2; ~~~~~~~~~~~ -!!! error TS2365: Operator '|=' cannot be applied to types 'bigint' and '2'. +!!! error TS2365: Operator '|=' cannot be applied to types 'bigint' and 'number'. ~~~~~~~~~ -!!! error TS2365: Operator '|=' cannot be applied to types 'number' and '1n'. +!!! error TS2365: Operator '|=' cannot be applied to types 'number' and 'bigint'. bigInt = 1n + 2n; num = 1 + 2; 1 + 2n; 1n + 2; ~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types '1' and '2n'. @@ -134,54 +134,54 @@ tests/cases/compiler/numberVsBigIntOperations.ts(93,7): error TS1155: 'const' de !!! error TS2365: Operator '+' cannot be applied to types '1n' and '2'. bigInt = 1n - 2n; num = 1 - 2; 1 - 2n; 1n - 2; ~~~~~~ -!!! error TS2365: Operator '-' cannot be applied to types '1' and '2n'. +!!! error TS2365: Operator '-' cannot be applied to types 'number' and 'bigint'. ~~~~~~ -!!! error TS2365: Operator '-' cannot be applied to types '1n' and '2'. +!!! error TS2365: Operator '-' cannot be applied to types 'bigint' and 'number'. bigInt = 1n * 2n; num = 1 * 2; 1 * 2n; 1n * 2; ~~~~~~ -!!! error TS2365: Operator '*' cannot be applied to types '1' and '2n'. +!!! error TS2365: Operator '*' cannot be applied to types 'number' and 'bigint'. ~~~~~~ -!!! error TS2365: Operator '*' cannot be applied to types '1n' and '2'. +!!! error TS2365: Operator '*' cannot be applied to types 'bigint' and 'number'. bigInt = 1n / 2n; num = 1 / 2; 1 / 2n; 1n / 2; ~~~~~~ -!!! error TS2365: Operator '/' cannot be applied to types '1' and '2n'. +!!! error TS2365: Operator '/' cannot be applied to types 'number' and 'bigint'. ~~~~~~ -!!! error TS2365: Operator '/' cannot be applied to types '1n' and '2'. +!!! error TS2365: Operator '/' cannot be applied to types 'bigint' and 'number'. bigInt = 1n % 2n; num = 1 % 2; 1 % 2n; 1n % 2; ~~~~~~ -!!! error TS2365: Operator '%' cannot be applied to types '1' and '2n'. +!!! error TS2365: Operator '%' cannot be applied to types 'number' and 'bigint'. ~~~~~~ -!!! error TS2365: Operator '%' cannot be applied to types '1n' and '2'. +!!! error TS2365: Operator '%' cannot be applied to types 'bigint' and 'number'. bigInt = 1n ** 2n; num = 1 ** 2; 1 ** 2n; 1n ** 2; ~~~~~~~ -!!! error TS2365: Operator '**' cannot be applied to types '1' and '2n'. +!!! error TS2365: Operator '**' cannot be applied to types 'number' and 'bigint'. ~~~~~~~ -!!! error TS2365: Operator '**' cannot be applied to types '1n' and '2'. +!!! error TS2365: Operator '**' cannot be applied to types 'bigint' and 'number'. bigInt = 1n & 2n; num = 1 & 2; 1 & 2n; 1n & 2; ~~~~~~ -!!! error TS2365: Operator '&' cannot be applied to types '1' and '2n'. +!!! error TS2365: Operator '&' cannot be applied to types 'number' and 'bigint'. ~~~~~~ -!!! error TS2365: Operator '&' cannot be applied to types '1n' and '2'. +!!! error TS2365: Operator '&' cannot be applied to types 'bigint' and 'number'. bigInt = 1n | 2n; num = 1 | 2; 1 | 2n; 1n | 2; ~~~~~~ -!!! error TS2365: Operator '|' cannot be applied to types '1' and '2n'. +!!! error TS2365: Operator '|' cannot be applied to types 'number' and 'bigint'. ~~~~~~ -!!! error TS2365: Operator '|' cannot be applied to types '1n' and '2'. +!!! error TS2365: Operator '|' cannot be applied to types 'bigint' and 'number'. bigInt = 1n ^ 2n; num = 1 ^ 2; 1 ^ 2n; 1n ^ 2; ~~~~~~ -!!! error TS2365: Operator '^' cannot be applied to types '1' and '2n'. +!!! error TS2365: Operator '^' cannot be applied to types 'number' and 'bigint'. ~~~~~~ -!!! error TS2365: Operator '^' cannot be applied to types '1n' and '2'. +!!! error TS2365: Operator '^' cannot be applied to types 'bigint' and 'number'. bigInt = 1n << 2n; num = 1 << 2; 1 << 2n; 1n << 2; ~~~~~~~ -!!! error TS2365: Operator '<<' cannot be applied to types '1' and '2n'. +!!! error TS2365: Operator '<<' cannot be applied to types 'number' and 'bigint'. ~~~~~~~ -!!! error TS2365: Operator '<<' cannot be applied to types '1n' and '2'. +!!! error TS2365: Operator '<<' cannot be applied to types 'bigint' and 'number'. bigInt = 1n >> 2n; num = 1 >> 2; 1 >> 2n; 1n >> 2; ~~~~~~~ -!!! error TS2365: Operator '>>' cannot be applied to types '1' and '2n'. +!!! error TS2365: Operator '>>' cannot be applied to types 'number' and 'bigint'. ~~~~~~~ -!!! error TS2365: Operator '>>' cannot be applied to types '1n' and '2'. +!!! error TS2365: Operator '>>' cannot be applied to types 'bigint' and 'number'. // Plus should still coerce to strings let str: string; @@ -235,9 +235,9 @@ tests/cases/compiler/numberVsBigIntOperations.ts(93,7): error TS1155: 'const' de ~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. ~~~~~~~~ -!!! error TS2365: Operator '&' cannot be applied to types '"3"' and '5n'. +!!! error TS2365: Operator '&' cannot be applied to types 'string' and 'bigint'. ~~~~~~~~~~~ -!!! error TS2365: Operator '**' cannot be applied to types '2n' and 'false'. +!!! error TS2365: Operator '**' cannot be applied to types 'bigint' and 'boolean'. ~~~~~ !!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. num = ~"3"; num = -false; // should infer number diff --git a/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt b/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt index e159a026cf1..4d1970e3b19 100644 --- a/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(6,9): error TS2365: Operator '+' cannot be applied to types 'number | "ABC" | "XYZ"' and '100'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(7,9): error TS2365: Operator '+' cannot be applied to types '100' and 'number | "ABC" | "XYZ"'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(8,9): error TS2365: Operator '+' cannot be applied to types 'number | "ABC" | "XYZ"' and 'number | "ABC" | "XYZ"'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(9,9): error TS2365: Operator '+' cannot be applied to types 'number | "ABC" | "XYZ"' and 'true'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(10,9): error TS2365: Operator '+' cannot be applied to types 'false' and 'number | "ABC" | "XYZ"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(6,9): error TS2365: Operator '+' cannot be applied to types 'string | number' and 'number'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(7,9): error TS2365: Operator '+' cannot be applied to types 'number' and 'string | number'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(8,9): error TS2365: Operator '+' cannot be applied to types 'string | number' and 'string | number'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(9,9): error TS2365: Operator '+' cannot be applied to types 'string | number' and 'boolean'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(10,9): error TS2365: Operator '+' cannot be applied to types 'boolean' and 'string | number'. tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(11,9): error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(12,11): error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(13,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. @@ -19,19 +19,19 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperato let a = abcOrXyzOrNumber + 100; ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'number | "ABC" | "XYZ"' and '100'. +!!! error TS2365: Operator '+' cannot be applied to types 'string | number' and 'number'. let b = 100 + abcOrXyzOrNumber; ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types '100' and 'number | "ABC" | "XYZ"'. +!!! error TS2365: Operator '+' cannot be applied to types 'number' and 'string | number'. let c = abcOrXyzOrNumber + abcOrXyzOrNumber; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'number | "ABC" | "XYZ"' and 'number | "ABC" | "XYZ"'. +!!! error TS2365: Operator '+' cannot be applied to types 'string | number' and 'string | number'. let d = abcOrXyzOrNumber + true; ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'number | "ABC" | "XYZ"' and 'true'. +!!! error TS2365: Operator '+' cannot be applied to types 'string | number' and 'boolean'. let e = false + abcOrXyzOrNumber; ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'false' and 'number | "ABC" | "XYZ"'. +!!! error TS2365: Operator '+' cannot be applied to types 'boolean' and 'string | number'. let f = abcOrXyzOrNumber++; ~~~~~~~~~~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type. diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt index b98939167aa..8cb9e8203e7 100644 --- a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts(3,9): error TS2367: This condition will always return 'false' since the types '"foo"' and '"baz"' have no overlap. -tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts(5,9): error TS2367: This condition will always return 'false' since the types '"foo"' and 'number' have no overlap. +tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts(5,9): error TS2367: This condition will always return 'false' since the types 'string' and 'number' have no overlap. tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts(5,19): error TS2352: Conversion of type 'string' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. @@ -12,7 +12,7 @@ tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparis var b = "foo" !== ("bar" as "foo"); var c = "foo" == ("bar"); ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: This condition will always return 'false' since the types '"foo"' and 'number' have no overlap. +!!! error TS2367: This condition will always return 'false' since the types 'string' and 'number' have no overlap. ~~~~~~~~~~~~~ !!! error TS2352: Conversion of type 'string' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. var d = "foo" === ("bar" as EnhancedString); \ No newline at end of file diff --git a/tests/baselines/reference/symbolType12.errors.txt b/tests/baselines/reference/symbolType12.errors.txt index 1e82b7adb41..b3eefb40ce3 100644 --- a/tests/baselines/reference/symbolType12.errors.txt +++ b/tests/baselines/reference/symbolType12.errors.txt @@ -8,7 +8,7 @@ tests/cases/conformance/es6/Symbols/symbolType12.ts(7,1): error TS2362: The left tests/cases/conformance/es6/Symbols/symbolType12.ts(7,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/es6/Symbols/symbolType12.ts(8,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/es6/Symbols/symbolType12.ts(9,1): error TS2365: Operator '+=' cannot be applied to types 'symbol' and 'symbol'. -tests/cases/conformance/es6/Symbols/symbolType12.ts(10,1): error TS2365: Operator '+=' cannot be applied to types 'symbol' and '0'. +tests/cases/conformance/es6/Symbols/symbolType12.ts(10,1): error TS2365: Operator '+=' cannot be applied to types 'symbol' and 'number'. tests/cases/conformance/es6/Symbols/symbolType12.ts(11,1): error TS2469: The '+=' operator cannot be applied to type 'symbol'. tests/cases/conformance/es6/Symbols/symbolType12.ts(12,8): error TS2469: The '+=' operator cannot be applied to type 'symbol'. tests/cases/conformance/es6/Symbols/symbolType12.ts(13,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. @@ -67,7 +67,7 @@ tests/cases/conformance/es6/Symbols/symbolType12.ts(28,8): error TS2469: The '+= !!! error TS2365: Operator '+=' cannot be applied to types 'symbol' and 'symbol'. s += 0; ~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types 'symbol' and '0'. +!!! error TS2365: Operator '+=' cannot be applied to types 'symbol' and 'number'. s += ""; ~ !!! error TS2469: The '+=' operator cannot be applied to type 'symbol'. diff --git a/tests/baselines/reference/symbolType6.errors.txt b/tests/baselines/reference/symbolType6.errors.txt index a49a4d9d6a3..5df54026088 100644 --- a/tests/baselines/reference/symbolType6.errors.txt +++ b/tests/baselines/reference/symbolType6.errors.txt @@ -3,10 +3,10 @@ tests/cases/conformance/es6/Symbols/symbolType6.ts(4,1): error TS2362: The left- tests/cases/conformance/es6/Symbols/symbolType6.ts(4,5): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/es6/Symbols/symbolType6.ts(5,1): error TS2469: The '+' operator cannot be applied to type 'symbol'. tests/cases/conformance/es6/Symbols/symbolType6.ts(6,1): error TS2469: The '+' operator cannot be applied to type 'symbol'. -tests/cases/conformance/es6/Symbols/symbolType6.ts(7,1): error TS2365: Operator '+' cannot be applied to types 'symbol' and '0'. +tests/cases/conformance/es6/Symbols/symbolType6.ts(7,1): error TS2365: Operator '+' cannot be applied to types 'symbol' and 'number'. tests/cases/conformance/es6/Symbols/symbolType6.ts(8,6): error TS2469: The '+' operator cannot be applied to type 'symbol'. tests/cases/conformance/es6/Symbols/symbolType6.ts(9,5): error TS2469: The '+' operator cannot be applied to type 'symbol'. -tests/cases/conformance/es6/Symbols/symbolType6.ts(10,1): error TS2365: Operator '+' cannot be applied to types '0' and 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType6.ts(10,1): error TS2365: Operator '+' cannot be applied to types 'number' and 'symbol'. tests/cases/conformance/es6/Symbols/symbolType6.ts(11,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/es6/Symbols/symbolType6.ts(12,5): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/es6/Symbols/symbolType6.ts(14,1): error TS2469: The '+' operator cannot be applied to type 'symbol'. @@ -32,7 +32,7 @@ tests/cases/conformance/es6/Symbols/symbolType6.ts(15,6): error TS2469: The '+' !!! error TS2469: The '+' operator cannot be applied to type 'symbol'. s + 0; ~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'symbol' and '0'. +!!! error TS2365: Operator '+' cannot be applied to types 'symbol' and 'number'. "" + s; ~ !!! error TS2469: The '+' operator cannot be applied to type 'symbol'. @@ -41,7 +41,7 @@ tests/cases/conformance/es6/Symbols/symbolType6.ts(15,6): error TS2469: The '+' !!! error TS2469: The '+' operator cannot be applied to type 'symbol'. 0 + s; ~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types '0' and 'symbol'. +!!! error TS2365: Operator '+' cannot be applied to types 'number' and 'symbol'. s - 0; ~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. diff --git a/tests/baselines/reference/symbolType9.errors.txt b/tests/baselines/reference/symbolType9.errors.txt index e697a261929..5b6c233367e 100644 --- a/tests/baselines/reference/symbolType9.errors.txt +++ b/tests/baselines/reference/symbolType9.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/Symbols/symbolType9.ts(3,1): error TS2367: This condition will always return 'false' since the types 'symbol' and 'true' have no overlap. -tests/cases/conformance/es6/Symbols/symbolType9.ts(5,1): error TS2367: This condition will always return 'true' since the types '0' and 'symbol' have no overlap. -tests/cases/conformance/es6/Symbols/symbolType9.ts(7,1): error TS2367: This condition will always return 'false' since the types 'symbol' and '1' have no overlap. -tests/cases/conformance/es6/Symbols/symbolType9.ts(9,1): error TS2367: This condition will always return 'true' since the types 'false' and 'symbol' have no overlap. +tests/cases/conformance/es6/Symbols/symbolType9.ts(3,1): error TS2367: This condition will always return 'false' since the types 'symbol' and 'boolean' have no overlap. +tests/cases/conformance/es6/Symbols/symbolType9.ts(5,1): error TS2367: This condition will always return 'true' since the types 'number' and 'symbol' have no overlap. +tests/cases/conformance/es6/Symbols/symbolType9.ts(7,1): error TS2367: This condition will always return 'false' since the types 'symbol' and 'number' have no overlap. +tests/cases/conformance/es6/Symbols/symbolType9.ts(9,1): error TS2367: This condition will always return 'true' since the types 'boolean' and 'symbol' have no overlap. ==== tests/cases/conformance/es6/Symbols/symbolType9.ts (4 errors) ==== @@ -9,16 +9,16 @@ tests/cases/conformance/es6/Symbols/symbolType9.ts(9,1): error TS2367: This cond s == s; s == true; ~~~~~~~~~ -!!! error TS2367: This condition will always return 'false' since the types 'symbol' and 'true' have no overlap. +!!! error TS2367: This condition will always return 'false' since the types 'symbol' and 'boolean' have no overlap. s != s; 0 != s; ~~~~~~ -!!! error TS2367: This condition will always return 'true' since the types '0' and 'symbol' have no overlap. +!!! error TS2367: This condition will always return 'true' since the types 'number' and 'symbol' have no overlap. s === s; s === 1; ~~~~~~~ -!!! error TS2367: This condition will always return 'false' since the types 'symbol' and '1' have no overlap. +!!! error TS2367: This condition will always return 'false' since the types 'symbol' and 'number' have no overlap. s !== s; false !== s; ~~~~~~~~~~~ -!!! error TS2367: This condition will always return 'true' since the types 'false' and 'symbol' have no overlap. \ No newline at end of file +!!! error TS2367: This condition will always return 'true' since the types 'boolean' and 'symbol' have no overlap. \ No newline at end of file From 3d119304531358524efc8ba2d1191cd5f6387280 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 14 Aug 2019 16:16:43 -0700 Subject: [PATCH 14/18] Get base primitive type for unary operators. --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 65722fa6d52..649fcac83bb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -24083,7 +24083,7 @@ namespace ts { } if (node.operator === SyntaxKind.PlusToken) { if (maybeTypeOfKind(operandType, TypeFlags.BigIntLike)) { - error(node.operand, Diagnostics.Operator_0_cannot_be_applied_to_type_1, tokenToString(node.operator), typeToString(operandType)); + error(node.operand, Diagnostics.Operator_0_cannot_be_applied_to_type_1, tokenToString(node.operator), typeToString(getBaseTypeOfLiteralType(operandType))); } return numberType; } From 465bcc6da09f4d1ff62a24b24237cb0cf891e807 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 14 Aug 2019 16:16:58 -0700 Subject: [PATCH 15/18] Accepted baselines. --- tests/baselines/reference/parseBigInt.errors.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/baselines/reference/parseBigInt.errors.txt b/tests/baselines/reference/parseBigInt.errors.txt index dc791e3325e..4641e88f137 100644 --- a/tests/baselines/reference/parseBigInt.errors.txt +++ b/tests/baselines/reference/parseBigInt.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/parseBigInt.ts(51,20): error TS2736: Operator '+' cannot be applied to type '123n'. -tests/cases/compiler/parseBigInt.ts(52,23): error TS2736: Operator '+' cannot be applied to type '291n'. +tests/cases/compiler/parseBigInt.ts(51,20): error TS2736: Operator '+' cannot be applied to type 'bigint'. +tests/cases/compiler/parseBigInt.ts(52,23): error TS2736: Operator '+' cannot be applied to type 'bigint'. tests/cases/compiler/parseBigInt.ts(56,25): error TS1005: ',' expected. tests/cases/compiler/parseBigInt.ts(57,22): error TS1352: A bigint literal cannot use exponential notation. tests/cases/compiler/parseBigInt.ts(58,19): error TS1353: A bigint literal must be an integer. @@ -70,10 +70,10 @@ tests/cases/compiler/parseBigInt.ts(70,72): error TS2345: Argument of type '3' i // Plus not allowed on literals const unaryPlus = +123n; ~~~~ -!!! error TS2736: Operator '+' cannot be applied to type '123n'. +!!! error TS2736: Operator '+' cannot be applied to type 'bigint'. const unaryPlusHex = +0x123n; ~~~~~~ -!!! error TS2736: Operator '+' cannot be applied to type '291n'. +!!! error TS2736: Operator '+' cannot be applied to type 'bigint'. // Parsing errors // In separate blocks because they each declare an "n" variable From 1ad443ed256eb1eba1cf32cb305a08ec13308f92 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 14 Aug 2019 16:48:24 -0700 Subject: [PATCH 16/18] A bit of cleanup. --- src/compiler/checker.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 649fcac83bb..3e4d646f3d3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -24518,7 +24518,7 @@ namespace ts { resultType = numberType; } // At least one is assignable to bigint, so check that both are - else if (isTypeAssignableToKind(leftType, TypeFlags.BigIntLike) && isTypeAssignableToKind(rightType, TypeFlags.BigIntLike)) { + else if (bothAreBigIntLike(leftType, rightType)) { switch (operator) { case SyntaxKind.GreaterThanGreaterThanGreaterThanToken: case SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken: @@ -24528,7 +24528,7 @@ namespace ts { } // Exactly one of leftType/rightType is assignable to bigint else { - reportOperatorError((awaitedLeft, awaitedRight) => isTypeAssignableToKind(awaitedLeft, TypeFlags.BigIntLike) && isTypeAssignableToKind(awaitedRight, TypeFlags.BigIntLike)); + reportOperatorError(bothAreBigIntLike); resultType = errorType; } if (leftOk && rightOk) { @@ -24578,9 +24578,9 @@ namespace ts { // might be missing an await without doing an exhaustive check that inserting // await(s) will actually be a completely valid binary expression. const closeEnoughKind = TypeFlags.NumberLike | TypeFlags.BigIntLike | TypeFlags.StringLike | TypeFlags.AnyOrUnknown; - reportOperatorError((awaitedLeft, awaitedRight) => - isTypeAssignableToKind(awaitedLeft, closeEnoughKind) && - isTypeAssignableToKind(awaitedRight, closeEnoughKind)); + reportOperatorError((left, right) => + isTypeAssignableToKind(left, closeEnoughKind) && + isTypeAssignableToKind(right, closeEnoughKind)); return anyType; } @@ -24648,6 +24648,10 @@ namespace ts { return Debug.fail(); } + function bothAreBigIntLike(left: Type, right: Type): boolean { + return isTypeAssignableToKind(left, TypeFlags.BigIntLike) && isTypeAssignableToKind(right, TypeFlags.BigIntLike); + } + function checkAssignmentDeclaration(kind: AssignmentDeclarationKind, rightType: Type) { if (kind === AssignmentDeclarationKind.ModuleExports) { for (const prop of getPropertiesOfObjectType(rightType)) { @@ -24760,7 +24764,7 @@ namespace ts { if (!wouldWorkWithAwait && isRelated) { [effectiveLeft, effectiveRight] = getBaseTypesIfUnrelated(leftType, rightType, isRelated); } - let [leftStr, rightStr] = getTypeNamesForErrorDisplay(effectiveLeft, effectiveRight); + const [leftStr, rightStr] = getTypeNamesForErrorDisplay(effectiveLeft, effectiveRight); if (!tryGiveBetterPrimaryError(errNode, wouldWorkWithAwait, leftStr, rightStr)) { errorAndMaybeSuggestAwait( errNode, From 1747ee7a55c3438c1b655553a367a1e3b7d71bc0 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 14 Aug 2019 17:16:17 -0700 Subject: [PATCH 17/18] Perfer the non-module name of a symbol when writing the name of a symbol (#32880) --- src/compiler/checker.ts | 15 +++++++++------ .../reference/augmentExportEquals3.symbols | 4 ++-- .../reference/augmentExportEquals3_1.symbols | 4 ++-- .../reference/augmentExportEquals4.symbols | 4 ++-- .../reference/augmentExportEquals4_1.symbols | 4 ++-- .../reference/augmentExportEquals5.symbols | 4 ++-- .../reference/augmentExportEquals6.symbols | 4 ++-- .../reference/augmentExportEquals6_1.symbols | 4 ++-- .../reference/checkMergedGlobalUMDSymbol.symbols | 4 ++-- ...ssignmentMembersVisibleInAugmentation.symbols | 2 +- ...gmentationDuringSyntheticDefaultCheck.symbols | 10 +++++----- .../module_augmentUninstantiatedModule.symbols | 6 +++--- .../noCrashUMDMergedWithGlobalValue.symbols | 4 ++-- ...ctTransitiveImportHasValidDeclaration.symbols | 4 ++-- .../reference/umd-augmentation-3.symbols | 2 +- .../reference/umd-augmentation-4.symbols | 2 +- .../umdGlobalAugmentationNoCrash.symbols | 6 +++--- .../findAllReferencesUmdModuleAsGlobalConst.ts | 6 ++---- .../moduleReexportedIntoGlobalQuickInfo.ts | 16 ++++++++++++++++ 19 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 tests/cases/fourslash/moduleReexportedIntoGlobalQuickInfo.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 74bf936d5c8..5ad975d118c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4654,9 +4654,6 @@ namespace ts { function createExpressionFromSymbolChain(chain: Symbol[], index: number): Expression { const typeParameterNodes = lookupTypeParameterNodes(chain, index, context); const symbol = chain[index]; - if (some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { - return createLiteral(getSpecifierForModuleSymbol(symbol, context)); - } if (index === 0) { context.flags |= NodeBuilderFlags.InInitialEntityName; @@ -4666,6 +4663,9 @@ namespace ts { context.flags ^= NodeBuilderFlags.InInitialEntityName; } let firstChar = symbolName.charCodeAt(0); + if (isSingleOrDoubleQuote(firstChar) && some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { + return createLiteral(getSpecifierForModuleSymbol(symbol, context)); + } const canUsePropertyAccess = isIdentifierStart(firstChar, languageVersion); if (index === 0 || canUsePropertyAccess) { const identifier = setEmitFlags(createIdentifier(symbolName, typeParameterNodes), EmitFlags.NoAsciiEscaping); @@ -4821,9 +4821,9 @@ namespace ts { return "default"; } if (symbol.declarations && symbol.declarations.length) { - const declaration = symbol.declarations[0]; - const name = getNameOfDeclaration(declaration); - if (name) { + let declaration = firstDefined(symbol.declarations, d => getNameOfDeclaration(d) ? d : undefined); // Try using a declaration with a name, first + const name = declaration && getNameOfDeclaration(declaration); + if (declaration && name) { if (isCallExpression(declaration) && isBindableObjectDefinePropertyCall(declaration)) { return symbolName(symbol); } @@ -4836,6 +4836,9 @@ namespace ts { } return declarationNameToString(name); } + if (!declaration) { + declaration = symbol.declarations[0]; // Declaration may be nameless, but we'll try anyway + } if (declaration.parent && declaration.parent.kind === SyntaxKind.VariableDeclaration) { return declarationNameToString((declaration.parent).name); } diff --git a/tests/baselines/reference/augmentExportEquals3.symbols b/tests/baselines/reference/augmentExportEquals3.symbols index 2644d6d5b21..e4e7a8e1a5f 100644 --- a/tests/baselines/reference/augmentExportEquals3.symbols +++ b/tests/baselines/reference/augmentExportEquals3.symbols @@ -1,9 +1,9 @@ === tests/cases/compiler/file1.ts === function foo() {} ->foo : Symbol("tests/cases/compiler/file1.ts", Decl(file1.ts, 0, 0), Decl(file1.ts, 0, 17), Decl(file2.ts, 1, 8)) +>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 0, 17), Decl(file2.ts, 1, 8)) namespace foo { ->foo : Symbol("tests/cases/compiler/file1.ts", Decl(file1.ts, 0, 0), Decl(file1.ts, 0, 17), Decl(file2.ts, 1, 8)) +>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 0, 17), Decl(file2.ts, 1, 8)) export var v = 1; >v : Symbol(v, Decl(file1.ts, 2, 14)) diff --git a/tests/baselines/reference/augmentExportEquals3_1.symbols b/tests/baselines/reference/augmentExportEquals3_1.symbols index 181ceb343b8..2431b293dea 100644 --- a/tests/baselines/reference/augmentExportEquals3_1.symbols +++ b/tests/baselines/reference/augmentExportEquals3_1.symbols @@ -3,10 +3,10 @@ declare module "file1" { >"file1" : Symbol("file1", Decl(file1.d.ts, 0, 0)) function foo(): void; ->foo : Symbol("tests/cases/compiler/file1.d.ts", Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8)) +>foo : Symbol(foo, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8)) namespace foo { ->foo : Symbol("tests/cases/compiler/file1.d.ts", Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8)) +>foo : Symbol(foo, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8)) export var v: number; >v : Symbol(v, Decl(file1.d.ts, 3, 18)) diff --git a/tests/baselines/reference/augmentExportEquals4.symbols b/tests/baselines/reference/augmentExportEquals4.symbols index 75da60335c3..f1f63762545 100644 --- a/tests/baselines/reference/augmentExportEquals4.symbols +++ b/tests/baselines/reference/augmentExportEquals4.symbols @@ -1,9 +1,9 @@ === tests/cases/compiler/file1.ts === class foo {} ->foo : Symbol("tests/cases/compiler/file1.ts", Decl(file1.ts, 0, 0), Decl(file1.ts, 0, 12), Decl(file2.ts, 1, 8)) +>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 0, 12), Decl(file2.ts, 1, 8)) namespace foo { ->foo : Symbol("tests/cases/compiler/file1.ts", Decl(file1.ts, 0, 0), Decl(file1.ts, 0, 12), Decl(file2.ts, 1, 8)) +>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 0, 12), Decl(file2.ts, 1, 8)) export var v = 1; >v : Symbol(v, Decl(file1.ts, 2, 14)) diff --git a/tests/baselines/reference/augmentExportEquals4_1.symbols b/tests/baselines/reference/augmentExportEquals4_1.symbols index 97d115e453e..d2a3c001825 100644 --- a/tests/baselines/reference/augmentExportEquals4_1.symbols +++ b/tests/baselines/reference/augmentExportEquals4_1.symbols @@ -3,10 +3,10 @@ declare module "file1" { >"file1" : Symbol("file1", Decl(file1.d.ts, 0, 0)) class foo {} ->foo : Symbol("tests/cases/compiler/file1.d.ts", Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 16), Decl(file2.ts, 2, 8)) +>foo : Symbol(foo, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 16), Decl(file2.ts, 2, 8)) namespace foo { ->foo : Symbol("tests/cases/compiler/file1.d.ts", Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 16), Decl(file2.ts, 2, 8)) +>foo : Symbol(foo, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 16), Decl(file2.ts, 2, 8)) export var v: number; >v : Symbol(v, Decl(file1.d.ts, 3, 18)) diff --git a/tests/baselines/reference/augmentExportEquals5.symbols b/tests/baselines/reference/augmentExportEquals5.symbols index ef62f66817e..244073b6515 100644 --- a/tests/baselines/reference/augmentExportEquals5.symbols +++ b/tests/baselines/reference/augmentExportEquals5.symbols @@ -16,12 +16,12 @@ declare module "express" { >"express" : Symbol("express", Decl(express.d.ts, 4, 1)) function e(): e.Express; ->e : Symbol("tests/cases/compiler/express.d.ts", Decl(express.d.ts, 6, 26), Decl(express.d.ts, 7, 28), Decl(augmentation.ts, 1, 29)) +>e : Symbol(e, Decl(express.d.ts, 6, 26), Decl(express.d.ts, 7, 28), Decl(augmentation.ts, 1, 29)) >e : Symbol(e, Decl(express.d.ts, 6, 26), Decl(express.d.ts, 7, 28)) >Express : Symbol(Express, Decl(express.d.ts, 52, 9)) namespace e { ->e : Symbol("tests/cases/compiler/express.d.ts", Decl(express.d.ts, 6, 26), Decl(express.d.ts, 7, 28), Decl(augmentation.ts, 1, 29)) +>e : Symbol(e, Decl(express.d.ts, 6, 26), Decl(express.d.ts, 7, 28), Decl(augmentation.ts, 1, 29)) interface IRoute { >IRoute : Symbol(IRoute, Decl(express.d.ts, 8, 17)) diff --git a/tests/baselines/reference/augmentExportEquals6.symbols b/tests/baselines/reference/augmentExportEquals6.symbols index 72ef677c592..2125b650464 100644 --- a/tests/baselines/reference/augmentExportEquals6.symbols +++ b/tests/baselines/reference/augmentExportEquals6.symbols @@ -1,9 +1,9 @@ === tests/cases/compiler/file1.ts === class foo {} ->foo : Symbol("tests/cases/compiler/file1.ts", Decl(file1.ts, 0, 0), Decl(file1.ts, 0, 12), Decl(file2.ts, 1, 10)) +>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 0, 12), Decl(file2.ts, 1, 10)) namespace foo { ->foo : Symbol("tests/cases/compiler/file1.ts", Decl(file1.ts, 0, 0), Decl(file1.ts, 0, 12), Decl(file2.ts, 1, 10)) +>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 0, 12), Decl(file2.ts, 1, 10)) export class A {} >A : Symbol(A, Decl(file1.ts, 1, 15), Decl(file2.ts, 4, 26)) diff --git a/tests/baselines/reference/augmentExportEquals6_1.symbols b/tests/baselines/reference/augmentExportEquals6_1.symbols index e37b094549a..b75f8131c01 100644 --- a/tests/baselines/reference/augmentExportEquals6_1.symbols +++ b/tests/baselines/reference/augmentExportEquals6_1.symbols @@ -3,10 +3,10 @@ declare module "file1" { >"file1" : Symbol("file1", Decl(file1.d.ts, 0, 0)) class foo {} ->foo : Symbol("tests/cases/compiler/file1.d.ts", Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 16), Decl(file2.ts, 1, 28)) +>foo : Symbol(foo, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 16), Decl(file2.ts, 1, 28)) namespace foo { ->foo : Symbol("tests/cases/compiler/file1.d.ts", Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 16), Decl(file2.ts, 1, 28)) +>foo : Symbol(foo, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 16), Decl(file2.ts, 1, 28)) class A {} >A : Symbol(A, Decl(file1.d.ts, 2, 19), Decl(file2.ts, 4, 24)) diff --git a/tests/baselines/reference/checkMergedGlobalUMDSymbol.symbols b/tests/baselines/reference/checkMergedGlobalUMDSymbol.symbols index 72038e964b6..7ae76fe3382 100644 --- a/tests/baselines/reference/checkMergedGlobalUMDSymbol.symbols +++ b/tests/baselines/reference/checkMergedGlobalUMDSymbol.symbols @@ -17,12 +17,12 @@ declare global { >global : Symbol(global, Decl(global.d.ts, 2, 26)) export const THREE: typeof _three; ->THREE : Symbol("tests/cases/compiler/global", Decl(global.d.ts, 0, 0), Decl(global.d.ts, 5, 14)) +>THREE : Symbol(THREE, Decl(global.d.ts, 0, 0), Decl(global.d.ts, 5, 14)) >_three : Symbol(_three, Decl(global.d.ts, 0, 6)) } === tests/cases/compiler/test.ts === const m = THREE >m : Symbol(m, Decl(test.ts, 0, 5)) ->THREE : Symbol("tests/cases/compiler/global", Decl(global.d.ts, 0, 0), Decl(global.d.ts, 5, 14)) +>THREE : Symbol(THREE, Decl(global.d.ts, 0, 0), Decl(global.d.ts, 5, 14)) diff --git a/tests/baselines/reference/exportAssignmentMembersVisibleInAugmentation.symbols b/tests/baselines/reference/exportAssignmentMembersVisibleInAugmentation.symbols index a9aecc513c4..a5cf5aa514c 100644 --- a/tests/baselines/reference/exportAssignmentMembersVisibleInAugmentation.symbols +++ b/tests/baselines/reference/exportAssignmentMembersVisibleInAugmentation.symbols @@ -3,7 +3,7 @@ export = foo; >foo : Symbol(foo, Decl(index.d.ts, 0, 13)) declare namespace foo { ->foo : Symbol("/node_modules/foo/index.d.ts", Decl(index.d.ts, 0, 13), Decl(a.ts, 0, 27), Decl(b.ts, 0, 27)) +>foo : Symbol(foo, Decl(index.d.ts, 0, 13), Decl(a.ts, 0, 27), Decl(b.ts, 0, 27)) export type T = number; >T : Symbol(T, Decl(index.d.ts, 1, 23)) diff --git a/tests/baselines/reference/moduleAugmentationDuringSyntheticDefaultCheck.symbols b/tests/baselines/reference/moduleAugmentationDuringSyntheticDefaultCheck.symbols index e0b4b180f3e..115bb3b1a2c 100644 --- a/tests/baselines/reference/moduleAugmentationDuringSyntheticDefaultCheck.symbols +++ b/tests/baselines/reference/moduleAugmentationDuringSyntheticDefaultCheck.symbols @@ -6,12 +6,12 @@ import moment = require("moment-timezone"); === tests/cases/compiler/node_modules/moment/index.d.ts === declare function moment(): moment.Moment; ->moment : Symbol("tests/cases/compiler/node_modules/moment/index.d.ts", Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 41), Decl(idx.ts, 0, 34), Decl(index.d.ts, 1, 16)) +>moment : Symbol(moment, Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 41), Decl(idx.ts, 0, 34), Decl(index.d.ts, 1, 16)) >moment : Symbol(moment, Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 41)) >Moment : Symbol(Moment, Decl(index.d.ts, 1, 26)) declare namespace moment { ->moment : Symbol("tests/cases/compiler/node_modules/moment/index.d.ts", Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 41), Decl(idx.ts, 0, 34), Decl(index.d.ts, 1, 16)) +>moment : Symbol(moment, Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 41), Decl(idx.ts, 0, 34), Decl(index.d.ts, 1, 16)) interface Moment extends Object { >Moment : Symbol(Moment, Decl(index.d.ts, 1, 26), Decl(idx.ts, 1, 25), Decl(idx.ts, 6, 34), Decl(index.d.ts, 2, 25)) @@ -32,7 +32,7 @@ export = moment; >moment : Symbol(moment, Decl(index.d.ts, 0, 6)) declare module "moment" { ->"moment" : Symbol("tests/cases/compiler/node_modules/moment/index.d.ts", Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 41), Decl(idx.ts, 0, 34), Decl(index.d.ts, 1, 16)) +>"moment" : Symbol(moment, Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 41), Decl(idx.ts, 0, 34), Decl(index.d.ts, 1, 16)) interface Moment { >Moment : Symbol(Moment, Decl(index.d.ts, 1, 26), Decl(idx.ts, 1, 25), Decl(idx.ts, 6, 34), Decl(index.d.ts, 2, 25)) @@ -46,7 +46,7 @@ import * as _moment from "moment"; >_moment : Symbol(_moment, Decl(idx.ts, 0, 6)) declare module "moment" { ->"moment" : Symbol("tests/cases/compiler/node_modules/moment/index.d.ts", Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 41), Decl(idx.ts, 0, 34), Decl(index.d.ts, 1, 16)) +>"moment" : Symbol(moment, Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 41), Decl(idx.ts, 0, 34), Decl(index.d.ts, 1, 16)) interface Moment { >Moment : Symbol(Moment, Decl(index.d.ts, 1, 26), Decl(idx.ts, 1, 25), Decl(idx.ts, 6, 34), Decl(index.d.ts, 2, 25)) @@ -57,7 +57,7 @@ declare module "moment" { } } declare module "moment-timezone" { ->"moment-timezone" : Symbol("tests/cases/compiler/node_modules/moment/index.d.ts", Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 41), Decl(idx.ts, 0, 34), Decl(idx.ts, 5, 1)) +>"moment-timezone" : Symbol(moment, Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 41), Decl(idx.ts, 0, 34), Decl(idx.ts, 5, 1)) interface Moment { >Moment : Symbol(Moment, Decl(index.d.ts, 1, 26), Decl(idx.ts, 1, 25), Decl(idx.ts, 6, 34), Decl(index.d.ts, 2, 25)) diff --git a/tests/baselines/reference/module_augmentUninstantiatedModule.symbols b/tests/baselines/reference/module_augmentUninstantiatedModule.symbols index 7d07a1db707..e75f6b5567c 100644 --- a/tests/baselines/reference/module_augmentUninstantiatedModule.symbols +++ b/tests/baselines/reference/module_augmentUninstantiatedModule.symbols @@ -3,10 +3,10 @@ declare module "foo" { >"foo" : Symbol("foo", Decl(module_augmentUninstantiatedModule.ts, 0, 0)) namespace M {} ->M : Symbol("tests/cases/compiler/module_augmentUninstantiatedModule.ts", Decl(module_augmentUninstantiatedModule.ts, 0, 22), Decl(module_augmentUninstantiatedModule.ts, 2, 6), Decl(module_augmentUninstantiatedModule.ts, 6, 22)) +>M : Symbol(M, Decl(module_augmentUninstantiatedModule.ts, 0, 22), Decl(module_augmentUninstantiatedModule.ts, 2, 6), Decl(module_augmentUninstantiatedModule.ts, 6, 22)) var M; ->M : Symbol("tests/cases/compiler/module_augmentUninstantiatedModule.ts", Decl(module_augmentUninstantiatedModule.ts, 0, 22), Decl(module_augmentUninstantiatedModule.ts, 2, 6), Decl(module_augmentUninstantiatedModule.ts, 6, 22)) +>M : Symbol(M, Decl(module_augmentUninstantiatedModule.ts, 0, 22), Decl(module_augmentUninstantiatedModule.ts, 2, 6), Decl(module_augmentUninstantiatedModule.ts, 6, 22)) export = M; >M : Symbol(M, Decl(module_augmentUninstantiatedModule.ts, 0, 22), Decl(module_augmentUninstantiatedModule.ts, 2, 6)) @@ -16,5 +16,5 @@ declare module "bar" { >"bar" : Symbol("bar", Decl(module_augmentUninstantiatedModule.ts, 4, 1)) module "foo" {} ->"foo" : Symbol("tests/cases/compiler/module_augmentUninstantiatedModule.ts", Decl(module_augmentUninstantiatedModule.ts, 0, 22), Decl(module_augmentUninstantiatedModule.ts, 2, 6), Decl(module_augmentUninstantiatedModule.ts, 6, 22)) +>"foo" : Symbol(M, Decl(module_augmentUninstantiatedModule.ts, 0, 22), Decl(module_augmentUninstantiatedModule.ts, 2, 6), Decl(module_augmentUninstantiatedModule.ts, 6, 22)) } diff --git a/tests/baselines/reference/noCrashUMDMergedWithGlobalValue.symbols b/tests/baselines/reference/noCrashUMDMergedWithGlobalValue.symbols index c2249abe1d4..3167783f719 100644 --- a/tests/baselines/reference/noCrashUMDMergedWithGlobalValue.symbols +++ b/tests/baselines/reference/noCrashUMDMergedWithGlobalValue.symbols @@ -7,12 +7,12 @@ export type Action = "PUSH" | "POP" | "REPLACE"; === /main.ts === interface SomeInterface { ->SomeInterface : Symbol("/other", Decl(other.d.ts, 0, 0), Decl(main.ts, 0, 0)) +>SomeInterface : Symbol(SomeInterface, Decl(other.d.ts, 0, 0), Decl(main.ts, 0, 0)) readonly length: number; >length : Symbol(length, Decl(main.ts, 0, 25)) } declare const value: SomeInterface; >value : Symbol(value, Decl(main.ts, 3, 13)) ->SomeInterface : Symbol("/other", Decl(other.d.ts, 0, 0), Decl(main.ts, 0, 0)) +>SomeInterface : Symbol(SomeInterface, Decl(other.d.ts, 0, 0), Decl(main.ts, 0, 0)) diff --git a/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.symbols b/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.symbols index 7d17a6cb0a2..aecfd012973 100644 --- a/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.symbols +++ b/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.symbols @@ -1,6 +1,6 @@ === tests/cases/compiler/node_modules/react/index.d.ts === declare namespace React { ->React : Symbol("tests/cases/compiler/node_modules/react/index.d.ts", Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 0)) +>React : Symbol(React, Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 0)) export interface DetailedHTMLProps {} >DetailedHTMLProps : Symbol(DetailedHTMLProps, Decl(index.d.ts, 0, 25)) @@ -20,7 +20,7 @@ export as namespace React; === tests/cases/compiler/node_modules/create-emotion-styled/types/react/index.d.ts === /// declare module 'react' { // augment ->'react' : Symbol("tests/cases/compiler/node_modules/react/index.d.ts", Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 0)) +>'react' : Symbol(React, Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 0)) interface HTMLAttributes { >HTMLAttributes : Symbol(HTMLAttributes, Decl(index.d.ts, 1, 47), Decl(index.d.ts, 1, 24)) diff --git a/tests/baselines/reference/umd-augmentation-3.symbols b/tests/baselines/reference/umd-augmentation-3.symbols index 9ddd303bfc7..606c7cd2398 100644 --- a/tests/baselines/reference/umd-augmentation-3.symbols +++ b/tests/baselines/reference/umd-augmentation-3.symbols @@ -44,7 +44,7 @@ export = M2D; >M2D : Symbol(M2D, Decl(index.d.ts, 2, 13)) declare namespace M2D { ->M2D : Symbol("tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts", Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33)) +>M2D : Symbol(M2D, Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33)) interface Point { >Point : Symbol(Point, Decl(index.d.ts, 4, 23)) diff --git a/tests/baselines/reference/umd-augmentation-4.symbols b/tests/baselines/reference/umd-augmentation-4.symbols index 4a2e8090e9f..90341d679f0 100644 --- a/tests/baselines/reference/umd-augmentation-4.symbols +++ b/tests/baselines/reference/umd-augmentation-4.symbols @@ -42,7 +42,7 @@ export = M2D; >M2D : Symbol(M2D, Decl(index.d.ts, 2, 13)) declare namespace M2D { ->M2D : Symbol("tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts", Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33)) +>M2D : Symbol(M2D, Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33)) interface Point { >Point : Symbol(Point, Decl(index.d.ts, 4, 23)) diff --git a/tests/baselines/reference/umdGlobalAugmentationNoCrash.symbols b/tests/baselines/reference/umdGlobalAugmentationNoCrash.symbols index ac3f57f2d58..0b416615a20 100644 --- a/tests/baselines/reference/umdGlobalAugmentationNoCrash.symbols +++ b/tests/baselines/reference/umdGlobalAugmentationNoCrash.symbols @@ -3,7 +3,7 @@ declare global { >global : Symbol(global, Decl(global.d.ts, 0, 0)) const React: typeof import("./module"); ->React : Symbol("tests/cases/compiler/module", Decl(module.d.ts, 0, 0), Decl(global.d.ts, 1, 9)) +>React : Symbol(React, Decl(module.d.ts, 0, 0), Decl(global.d.ts, 1, 9)) } export {}; @@ -18,7 +18,7 @@ export function foo(): string; export {} React.foo; >React.foo : Symbol(foo, Decl(module.d.ts, 0, 26)) ->React : Symbol("tests/cases/compiler/module", Decl(module.d.ts, 0, 0), Decl(global.d.ts, 1, 9)) +>React : Symbol(React, Decl(module.d.ts, 0, 0), Decl(global.d.ts, 1, 9)) >foo : Symbol(foo, Decl(module.d.ts, 0, 26)) === tests/cases/compiler/emits.ts === @@ -29,6 +29,6 @@ console.log("hello"); React.foo; >React.foo : Symbol(foo, Decl(module.d.ts, 0, 26)) ->React : Symbol("tests/cases/compiler/module", Decl(module.d.ts, 0, 0), Decl(global.d.ts, 1, 9)) +>React : Symbol(React, Decl(module.d.ts, 0, 0), Decl(global.d.ts, 1, 9)) >foo : Symbol(foo, Decl(module.d.ts, 0, 26)) diff --git a/tests/cases/fourslash/findAllReferencesUmdModuleAsGlobalConst.ts b/tests/cases/fourslash/findAllReferencesUmdModuleAsGlobalConst.ts index 479d0d2b9b6..3198a4f0273 100644 --- a/tests/cases/fourslash/findAllReferencesUmdModuleAsGlobalConst.ts +++ b/tests/cases/fourslash/findAllReferencesUmdModuleAsGlobalConst.ts @@ -39,7 +39,5 @@ ////} const [r0Def, r0, r1Def, r1, r2Def, ...rest] = test.ranges(); -// GH#29533 -// TODO:: this should be var THREE: typeof import instead of module name as var but thats existing issue and repros with quickInfo too. -verify.singleReferenceGroup(`module "/node_modules/@types/three/index" -var "/node_modules/@types/three/index": typeof import("/node_modules/@types/three/index")`, [r0, r1, ...rest]); \ No newline at end of file +verify.singleReferenceGroup(`module THREE +var THREE: typeof import("/node_modules/@types/three/index")`, [r0, r1, ...rest]); \ No newline at end of file diff --git a/tests/cases/fourslash/moduleReexportedIntoGlobalQuickInfo.ts b/tests/cases/fourslash/moduleReexportedIntoGlobalQuickInfo.ts new file mode 100644 index 00000000000..8f00a71f5ac --- /dev/null +++ b/tests/cases/fourslash/moduleReexportedIntoGlobalQuickInfo.ts @@ -0,0 +1,16 @@ +/// + +// @Filename: /node_modules/@types/three/index.d.ts +////export class Vector3 {} +////export as namespace THREE; +// @Filename: /global.d.ts +////import * as _THREE from 'three'; +//// +////declare global { +//// const THREE: typeof _THREE; +////} +// @Filename: /index.ts +////let v = new /*1*/THREE.Vector3(); + +verify.quickInfoAt("1", `module THREE +var THREE: typeof import("/node_modules/@types/three/index")`); From 8dec7a2763314d109125cf9230ff465e60cddaf6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 14 Aug 2019 17:22:15 -0700 Subject: [PATCH 18/18] Accepted baselines. --- tests/baselines/reference/expr.errors.txt | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/baselines/reference/expr.errors.txt b/tests/baselines/reference/expr.errors.txt index e1d6a9e4d45..a9244a28d49 100644 --- a/tests/baselines/reference/expr.errors.txt +++ b/tests/baselines/reference/expr.errors.txt @@ -1,17 +1,17 @@ tests/cases/compiler/expr.ts(87,5): error TS2367: This condition will always return 'false' since the types 'number' and 'string' have no overlap. -tests/cases/compiler/expr.ts(88,5): error TS2367: This condition will always return 'false' since the types 'number' and 'false' have no overlap. +tests/cases/compiler/expr.ts(88,5): error TS2367: This condition will always return 'false' since the types 'number' and 'boolean' have no overlap. tests/cases/compiler/expr.ts(94,5): error TS2367: This condition will always return 'false' since the types 'string' and 'number' have no overlap. -tests/cases/compiler/expr.ts(95,5): error TS2367: This condition will always return 'false' since the types 'string' and 'false' have no overlap. +tests/cases/compiler/expr.ts(95,5): error TS2367: This condition will always return 'false' since the types 'string' and 'boolean' have no overlap. tests/cases/compiler/expr.ts(98,5): error TS2367: This condition will always return 'false' since the types 'string' and 'E' have no overlap. tests/cases/compiler/expr.ts(115,5): error TS2367: This condition will always return 'false' since the types 'E' and 'string' have no overlap. -tests/cases/compiler/expr.ts(116,5): error TS2367: This condition will always return 'false' since the types 'E' and 'false' have no overlap. -tests/cases/compiler/expr.ts(142,5): error TS2365: Operator '+' cannot be applied to types 'number' and 'false'. +tests/cases/compiler/expr.ts(116,5): error TS2367: This condition will always return 'false' since the types 'E' and 'boolean' have no overlap. +tests/cases/compiler/expr.ts(142,5): error TS2365: Operator '+' cannot be applied to types 'number' and 'boolean'. tests/cases/compiler/expr.ts(143,5): error TS2365: Operator '+' cannot be applied to types 'number' and 'I'. tests/cases/compiler/expr.ts(161,5): error TS2365: Operator '+' cannot be applied to types 'I' and 'number'. -tests/cases/compiler/expr.ts(163,5): error TS2365: Operator '+' cannot be applied to types 'I' and 'false'. +tests/cases/compiler/expr.ts(163,5): error TS2365: Operator '+' cannot be applied to types 'I' and 'boolean'. tests/cases/compiler/expr.ts(165,5): error TS2365: Operator '+' cannot be applied to types 'I' and 'I'. tests/cases/compiler/expr.ts(166,5): error TS2365: Operator '+' cannot be applied to types 'I' and 'E'. -tests/cases/compiler/expr.ts(170,5): error TS2365: Operator '+' cannot be applied to types 'E' and 'false'. +tests/cases/compiler/expr.ts(170,5): error TS2365: Operator '+' cannot be applied to types 'E' and 'boolean'. tests/cases/compiler/expr.ts(172,5): error TS2365: Operator '+' cannot be applied to types 'E' and 'I'. tests/cases/compiler/expr.ts(176,7): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/compiler/expr.ts(177,7): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. @@ -161,7 +161,7 @@ tests/cases/compiler/expr.ts(242,7): error TS2363: The right-hand side of an ari !!! error TS2367: This condition will always return 'false' since the types 'number' and 'string' have no overlap. n==b; ~~~~ -!!! error TS2367: This condition will always return 'false' since the types 'number' and 'false' have no overlap. +!!! error TS2367: This condition will always return 'false' since the types 'number' and 'boolean' have no overlap. n==i; n==n; n==e; @@ -172,7 +172,7 @@ tests/cases/compiler/expr.ts(242,7): error TS2363: The right-hand side of an ari !!! error TS2367: This condition will always return 'false' since the types 'string' and 'number' have no overlap. s==b; ~~~~ -!!! error TS2367: This condition will always return 'false' since the types 'string' and 'false' have no overlap. +!!! error TS2367: This condition will always return 'false' since the types 'string' and 'boolean' have no overlap. s==i; s==s; s==e; @@ -199,7 +199,7 @@ tests/cases/compiler/expr.ts(242,7): error TS2363: The right-hand side of an ari !!! error TS2367: This condition will always return 'false' since the types 'E' and 'string' have no overlap. e==b; ~~~~ -!!! error TS2367: This condition will always return 'false' since the types 'E' and 'false' have no overlap. +!!! error TS2367: This condition will always return 'false' since the types 'E' and 'boolean' have no overlap. e==a; e==i; e==e; @@ -227,7 +227,7 @@ tests/cases/compiler/expr.ts(242,7): error TS2363: The right-hand side of an ari n+s; n+b; ~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'number' and 'false'. +!!! error TS2365: Operator '+' cannot be applied to types 'number' and 'boolean'. n+i; ~~~ !!! error TS2365: Operator '+' cannot be applied to types 'number' and 'I'. @@ -254,7 +254,7 @@ tests/cases/compiler/expr.ts(242,7): error TS2363: The right-hand side of an ari i+s; i+b; ~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'I' and 'false'. +!!! error TS2365: Operator '+' cannot be applied to types 'I' and 'boolean'. i+a; i+i; ~~~ @@ -267,7 +267,7 @@ tests/cases/compiler/expr.ts(242,7): error TS2363: The right-hand side of an ari e+s; e+b; ~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'E' and 'false'. +!!! error TS2365: Operator '+' cannot be applied to types 'E' and 'boolean'. e+a; e+i; ~~~