From 17f445035a100d846df313c92537050a74913d4b Mon Sep 17 00:00:00 2001
From: Sheetal Nandi <shkamat@microsoft.com>
Date: Wed, 8 Jan 2020 09:51:37 -0800
Subject: [PATCH] Disable declaration emit for json files (#36078)

---
 src/compiler/emitter.ts                       | 12 ++--
 src/compiler/program.ts                       |  8 +--
 src/compiler/transformers/declarations.ts     |  5 +-
 src/compiler/utilities.ts                     |  4 ++
 src/harness/harness.ts                        |  2 +-
 .../baselines/reference/jsDeclarationsJson.js | 18 -----
 .../reference/jsDeclarationsPackageJson.js    | 28 --------
 .../reference/requireOfJsonFileTypes.js       | 20 ------
 .../requireOfJsonFileWithDeclaration.js       |  3 -
 ...ved-json-files-and-emits-them-correctly.js | 56 ++++------------
 .../files-containing-json-file.js             |  4 --
 ...ting-json-module-from-project-reference.js |  9 +--
 .../initial-build/include-and-files.js        |  4 --
 ...r-include-and-file-name-matches-ts-file.js | 65 ++++++++++++++++++-
 ...nclude-of-json-along-with-other-include.js |  4 --
 .../initial-build/sourcemap.js                |  4 --
 .../initial-build/without-outDir.js           |  4 --
 17 files changed, 99 insertions(+), 151 deletions(-)

diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts
index 707d278eea0fe..aaebd0d6adc20 100644
--- a/src/compiler/emitter.ts
+++ b/src/compiler/emitter.ts
@@ -91,12 +91,13 @@ namespace ts {
         }
         else {
             const ownOutputFilePath = getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options));
+            const isJsonFile = isJsonSourceFile(sourceFile);
             // If json file emits to the same location skip writing it, if emitDeclarationOnly skip writing it
-            const isJsonEmittedToSameLocation = isJsonSourceFile(sourceFile) &&
+            const isJsonEmittedToSameLocation = isJsonFile &&
                 comparePaths(sourceFile.fileName, ownOutputFilePath, host.getCurrentDirectory(), !host.useCaseSensitiveFileNames()) === Comparison.EqualTo;
             const jsFilePath = options.emitDeclarationOnly || isJsonEmittedToSameLocation ? undefined : ownOutputFilePath;
             const sourceMapFilePath = !jsFilePath || isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options);
-            const declarationFilePath = (forceDtsPaths || getEmitDeclarations(options)) ? getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined;
+            const declarationFilePath = (forceDtsPaths || (getEmitDeclarations(options) && !isJsonFile)) ? getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined;
             const declarationMapPath = declarationFilePath && getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
             return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath: undefined };
         }
@@ -144,7 +145,7 @@ namespace ts {
 
     /* @internal */
     export function getOutputDeclarationFileName(inputFileName: string, configFile: ParsedCommandLine, ignoreCase: boolean) {
-        Debug.assert(!fileExtensionIs(inputFileName, Extension.Dts));
+        Debug.assert(!fileExtensionIs(inputFileName, Extension.Dts) && !fileExtensionIs(inputFileName, Extension.Json));
         return changeExtension(
             getOutputPathWithoutChangingExt(inputFileName, configFile, ignoreCase, configFile.options.declarationDir || configFile.options.outDir),
             Extension.Dts
@@ -399,12 +400,13 @@ namespace ts {
                 return;
             }
             const sourceFiles = isSourceFile(sourceFileOrBundle) ? [sourceFileOrBundle] : sourceFileOrBundle.sourceFiles;
+            const filesForEmit = forceDtsEmit ? sourceFiles : filter(sourceFiles, isSourceFileNotJson);
             // Setup and perform the transformation to retrieve declarations from the input files
-            const inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [createBundle(sourceFiles, !isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : sourceFiles;
+            const inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [createBundle(filesForEmit, !isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : filesForEmit;
             if (emitOnlyDtsFiles && !getEmitDeclarations(compilerOptions)) {
                 // Checker wont collect the linked aliases since thats only done when declaration is enabled.
                 // Do that here when emitting only dts files
-                sourceFiles.forEach(collectLinkedAliases);
+                filesForEmit.forEach(collectLinkedAliases);
             }
             const declarationTransform = transformNodes(resolver, host, compilerOptions, inputListOrBundle, declarationTransformers, /*allowDtsFiles*/ false);
             if (length(declarationTransform.diagnostics)) {
diff --git a/src/compiler/program.ts b/src/compiler/program.ts
index 4fd4d864138d7..ffe4faca7eb9e 100644
--- a/src/compiler/program.ts
+++ b/src/compiler/program.ts
@@ -860,7 +860,7 @@ namespace ts {
                             }
                             else if (getEmitModuleKind(parsedRef.commandLine.options) === ModuleKind.None) {
                                 for (const fileName of parsedRef.commandLine.fileNames) {
-                                    if (!fileExtensionIs(fileName, Extension.Dts)) {
+                                    if (!fileExtensionIs(fileName, Extension.Dts) && !fileExtensionIs(fileName, Extension.Json)) {
                                         processSourceFile(getOutputDeclarationFileName(fileName, parsedRef.commandLine, !host.useCaseSensitiveFileNames()), /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined);
                                     }
                                 }
@@ -2459,8 +2459,8 @@ namespace ts {
         }
 
         function getProjectReferenceRedirectProject(fileName: string) {
-            // Ignore dts
-            if (!resolvedProjectReferences || !resolvedProjectReferences.length || fileExtensionIs(fileName, Extension.Dts)) {
+            // Ignore dts or any json files
+            if (!resolvedProjectReferences || !resolvedProjectReferences.length || fileExtensionIs(fileName, Extension.Dts) || fileExtensionIs(fileName, Extension.Json)) {
                 return undefined;
             }
 
@@ -2521,7 +2521,7 @@ namespace ts {
                         }
                         else {
                             forEach(resolvedRef.commandLine.fileNames, fileName => {
-                                if (!fileExtensionIs(fileName, Extension.Dts)) {
+                                if (!fileExtensionIs(fileName, Extension.Dts) && !fileExtensionIs(fileName, Extension.Json)) {
                                     const outputDts = getOutputDeclarationFileName(fileName, resolvedRef.commandLine, host.useCaseSensitiveFileNames());
                                     mapFromToProjectReferenceRedirectSource!.set(toPath(outputDts), fileName);
                                 }
diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts
index 7746ad00b430e..eacced30efe75 100644
--- a/src/compiler/transformers/declarations.ts
+++ b/src/compiler/transformers/declarations.ts
@@ -1,8 +1,11 @@
 /*@internal*/
 namespace ts {
     export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, file: SourceFile | undefined): DiagnosticWithLocation[] | undefined {
+        if (file && isJsonSourceFile(file)) {
+            return []; // No declaration diagnostics for json for now
+        }
         const compilerOptions = host.getCompilerOptions();
-        const result = transformNodes(resolver, host, compilerOptions, file ? [file] : host.getSourceFiles(), [transformDeclarations], /*allowDtsFiles*/ false);
+        const result = transformNodes(resolver, host, compilerOptions, file ? [file] : filter(host.getSourceFiles(), isSourceFileNotJson), [transformDeclarations], /*allowDtsFiles*/ false);
         return result.diagnostics;
     }
 
diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts
index daef302d6e676..5abb2042adda6 100644
--- a/src/compiler/utilities.ts
+++ b/src/compiler/utilities.ts
@@ -1802,6 +1802,10 @@ namespace ts {
         return !!node && !!(node.flags & NodeFlags.JsonFile);
     }
 
+    export function isSourceFileNotJson(file: SourceFile) {
+        return !isJsonSourceFile(file);
+    }
+
     export function isInJSDoc(node: Node | undefined): boolean {
         return !!node && !!(node.flags & NodeFlags.JSDoc);
     }
diff --git a/src/harness/harness.ts b/src/harness/harness.ts
index e93033e126bdc..1dfd7839efa0e 100644
--- a/src/harness/harness.ts
+++ b/src/harness/harness.ts
@@ -888,7 +888,7 @@ namespace Harness {
                         throw new Error("Only declaration files should be generated when emitDeclarationOnly:true");
                     }
                 }
-                else if (result.dts.size !== result.getNumberOfJsFiles(/*includeJson*/ true)) {
+                else if (result.dts.size !== result.getNumberOfJsFiles(/*includeJson*/ false)) {
                     throw new Error("There were no errors and declFiles generated did not match number of js files generated");
                 }
             }
diff --git a/tests/baselines/reference/jsDeclarationsJson.js b/tests/baselines/reference/jsDeclarationsJson.js
index 2cebc7b583a8f..0a01bac6c178b 100644
--- a/tests/baselines/reference/jsDeclarationsJson.js
+++ b/tests/baselines/reference/jsDeclarationsJson.js
@@ -25,24 +25,6 @@ var j = require("./obj.json");
 module.exports = j;
 
 
-//// [obj.d.ts]
-export declare const x: number;
-export declare const y: number;
-export declare namespace obj {
-    export const items: ({
-        "x": number;
-        "y"?: undefined;
-        "err"?: undefined;
-    } | {
-        "x": number;
-        "y": number;
-        "err"?: undefined;
-    } | {
-        "x": number;
-        "err": boolean;
-        "y"?: undefined;
-    })[];
-}
 //// [index.d.ts]
 export = j;
 declare const j: {
diff --git a/tests/baselines/reference/jsDeclarationsPackageJson.js b/tests/baselines/reference/jsDeclarationsPackageJson.js
index 66da073d33882..84e3eb20a72ff 100644
--- a/tests/baselines/reference/jsDeclarationsPackageJson.js
+++ b/tests/baselines/reference/jsDeclarationsPackageJson.js
@@ -74,34 +74,6 @@ var j = require("./package.json");
 module.exports = j;
 
 
-//// [package.d.ts]
-export declare const name: string;
-export declare const version: string;
-export declare const description: string;
-export declare const main: string;
-export declare namespace bin {
-    export const cli: string;
-}
-export declare namespace engines {
-    export const node: string;
-}
-export declare namespace scripts {
-    export const scriptname: string;
-}
-export declare const devDependencies: {
-    "@ns/dep": string;
-};
-export declare namespace dependencies {
-    export const dep: string;
-}
-export declare const repository: string;
-export declare const keywords: string[];
-export declare const author: string;
-export declare const license: string;
-export declare const homepage: string;
-export declare namespace config {
-    export const o: string[];
-}
 //// [index.d.ts]
 export = j;
 declare const j: {
diff --git a/tests/baselines/reference/requireOfJsonFileTypes.js b/tests/baselines/reference/requireOfJsonFileTypes.js
index 31bd1f5b11e67..bcbf0e966c757 100644
--- a/tests/baselines/reference/requireOfJsonFileTypes.js
+++ b/tests/baselines/reference/requireOfJsonFileTypes.js
@@ -85,25 +85,5 @@ numberLiteral = f[0];
 booleanLiteral = g[0];
 
 
-//// [out/b.d.ts]
-export declare const a: boolean;
-export declare const b: string;
-export declare const c: null;
-export declare const d: boolean;
-//// [out/c.d.ts]
-declare const _exports: (string | null)[];
-export = _exports;
-//// [out/d.d.ts]
-declare const _exports: string;
-export = _exports;
-//// [out/e.d.ts]
-declare const _exports: number;
-export = _exports;
-//// [out/f.d.ts]
-declare const _exports: number[];
-export = _exports;
-//// [out/g.d.ts]
-declare const _exports: boolean[];
-export = _exports;
 //// [out/file1.d.ts]
 export {};
diff --git a/tests/baselines/reference/requireOfJsonFileWithDeclaration.js b/tests/baselines/reference/requireOfJsonFileWithDeclaration.js
index cae409add9708..2cb5085ffb7ff 100644
--- a/tests/baselines/reference/requireOfJsonFileWithDeclaration.js
+++ b/tests/baselines/reference/requireOfJsonFileWithDeclaration.js
@@ -32,8 +32,5 @@ if (x) {
 }
 
 
-//// [out/b.d.ts]
-export declare const a: boolean;
-export declare const b: string;
 //// [out/file1.d.ts]
 export {};
diff --git a/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/loads-js-based-projects-with-non-moved-json-files-and-emits-them-correctly.js b/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/loads-js-based-projects-with-non-moved-json-files-and-emits-them-correctly.js
index 3c49c99688d6c..4953fab663c14 100644
--- a/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/loads-js-based-projects-with-non-moved-json-files-and-emits-them-correctly.js
+++ b/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/loads-js-based-projects-with-non-moved-json-files-and-emits-them-correctly.js
@@ -4,8 +4,9 @@ exitCode:: ExitStatus.Success
 
 
 //// [/out/sub-project/index.d.ts]
-export const m: typeof mod;
-import mod from "../common";
+export const m: {
+    "val": number;
+};
 
 
 //// [/out/sub-project/index.js]
@@ -27,8 +28,7 @@ exports.m = common_1["default"];
         "signature": "-32082413277-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n    readonly species: symbol;\n    readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n    readonly [Symbol.toStringTag]: string;\n}\n"
       },
       "../../src/common/obj.json": {
-        "version": "-6323167306-export declare const val: number;\r\n",
-        "signature": "-6323167306-export declare const val: number;\r\n"
+        "version": "2151907832-{\n    \"val\": 42\n}"
       },
       "../../src/common/index.ts": {
         "version": "-4085459678-import x = require(\"./obj.json\");\r\nexport = x;\r\n",
@@ -36,7 +36,7 @@ exports.m = common_1["default"];
       },
       "../../src/sub-project/index.js": {
         "version": "-14684157955-import mod from '../common';\n\nexport const m = mod;\n",
-        "signature": "-229957289-export const m: typeof mod;\r\nimport mod from \"../common\";\r\n"
+        "signature": "-12693309262-export const m: {\r\n    \"val\": number;\r\n};\r\n"
       }
     },
     "options": {
@@ -53,7 +53,7 @@ exports.m = common_1["default"];
     },
     "referencedMap": {
       "../../src/common/index.ts": [
-        "../../src/common/obj.d.ts"
+        "../../src/common/obj.json"
       ],
       "../../src/sub-project/index.js": [
         "../../src/common/index.d.ts"
@@ -61,7 +61,7 @@ exports.m = common_1["default"];
     },
     "exportedModulesMap": {
       "../../src/common/index.ts": [
-        "../../src/common/obj.d.ts"
+        "../../src/common/obj.json"
       ]
     },
     "semanticDiagnosticsPerFile": [
@@ -76,7 +76,9 @@ exports.m = common_1["default"];
 
 //// [/out/sub-project-2/index.d.ts]
 export function getVar(): {
-    key: typeof import("../common/obj.json");
+    key: {
+        "val": number;
+    };
 };
 
 
@@ -101,21 +103,13 @@ exports.getVar = getVar;
         "version": "-32082413277-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n    readonly species: symbol;\n    readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n    readonly [Symbol.toStringTag]: string;\n}\n",
         "signature": "-32082413277-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n    readonly species: symbol;\n    readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n    readonly [Symbol.toStringTag]: string;\n}\n"
       },
-      "../../src/common/obj.json": {
-        "version": "-6323167306-export declare const val: number;\r\n",
-        "signature": "-6323167306-export declare const val: number;\r\n"
-      },
-      "../../src/common/index.ts": {
-        "version": "-4085459678-import x = require(\"./obj.json\");\r\nexport = x;\r\n",
-        "signature": "-4085459678-import x = require(\"./obj.json\");\r\nexport = x;\r\n"
-      },
       "../../src/sub-project/index.js": {
-        "version": "-229957289-export const m: typeof mod;\r\nimport mod from \"../common\";\r\n",
-        "signature": "-229957289-export const m: typeof mod;\r\nimport mod from \"../common\";\r\n"
+        "version": "-12693309262-export const m: {\r\n    \"val\": number;\r\n};\r\n",
+        "signature": "-12693309262-export const m: {\r\n    \"val\": number;\r\n};\r\n"
       },
       "../../src/sub-project-2/index.js": {
         "version": "13545386800-import { m } from '../sub-project/index';\n\nconst variable = {\n    key: m,\n};\n\nexport function getVar() {\n    return variable;\n}\n",
-        "signature": "-9206156860-export function getVar(): {\r\n    key: typeof import(\"../common/obj.json\");\r\n};\r\n"
+        "signature": "-11261617214-export function getVar(): {\r\n    key: {\r\n        \"val\": number;\r\n    };\r\n};\r\n"
       }
     },
     "options": {
@@ -131,31 +125,13 @@ exports.getVar = getVar;
       "configFilePath": "../../src/sub-project-2/tsconfig.json"
     },
     "referencedMap": {
-      "../../src/common/index.ts": [
-        "../../src/common/obj.d.ts"
-      ],
       "../../src/sub-project-2/index.js": [
         "../sub-project/index.d.ts"
-      ],
-      "../../src/sub-project/index.js": [
-        "../../src/common/index.d.ts"
-      ]
-    },
-    "exportedModulesMap": {
-      "../../src/common/index.ts": [
-        "../../src/common/obj.d.ts"
-      ],
-      "../../src/sub-project-2/index.js": [
-        "../../src/common/obj.d.ts"
-      ],
-      "../../src/sub-project/index.js": [
-        "../../src/common/index.d.ts"
       ]
     },
+    "exportedModulesMap": {},
     "semanticDiagnosticsPerFile": [
       "../../lib/lib.d.ts",
-      "../../src/common/index.ts",
-      "../../src/common/obj.json",
       "../../src/sub-project-2/index.js",
       "../../src/sub-project/index.js"
     ]
@@ -174,10 +150,6 @@ var x = require("./obj.json");
 module.exports = x;
 
 
-//// [/src/common/obj.d.ts]
-export declare const val: number;
-
-
 //// [/src/common/tsconfig.tsbuildinfo]
 {
   "program": {
diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/files-containing-json-file.js b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/files-containing-json-file.js
index 1d9537452199b..9ee6d281fbecf 100644
--- a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/files-containing-json-file.js
+++ b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/files-containing-json-file.js
@@ -3,10 +3,6 @@
 exitCode:: ExitStatus.Success
 
 
-//// [/src/dist/src/hello.d.ts]
-export declare const hello: string;
-
-
 //// [/src/dist/src/hello.json]
 {
     "hello": "world"
diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/importing-json-module-from-project-reference.js b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/importing-json-module-from-project-reference.js
index 12542f5574914..9048c8205b67b 100644
--- a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/importing-json-module-from-project-reference.js
+++ b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/importing-json-module-from-project-reference.js
@@ -36,8 +36,7 @@ console.log(foo_json_1.foo);
         "signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };"
       },
       "../strings/foo.json": {
-        "version": "-1457151099-export declare const foo: string;\r\n",
-        "signature": "-1457151099-export declare const foo: string;\r\n"
+        "version": "4395333385-{\n    \"foo\": \"bar baz\"\n}"
       },
       "./index.ts": {
         "version": "-4651661680-import { foo } from '../strings/foo.json';\n\nconsole.log(foo);",
@@ -56,7 +55,7 @@ console.log(foo_json_1.foo);
     },
     "referencedMap": {
       "./index.ts": [
-        "../strings/foo.d.ts"
+        "../strings/foo.json"
       ]
     },
     "exportedModulesMap": {},
@@ -69,10 +68,6 @@ console.log(foo_json_1.foo);
   "version": "FakeTSVersion"
 }
 
-//// [/src/strings/foo.d.ts]
-export declare const foo: string;
-
-
 //// [/src/strings/tsconfig.tsbuildinfo]
 {
   "program": {
diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-and-files.js b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-and-files.js
index b4404190e27ce..4e16377294463 100644
--- a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-and-files.js
+++ b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-and-files.js
@@ -3,10 +3,6 @@
 exitCode:: ExitStatus.Success
 
 
-//// [/src/dist/src/hello.d.ts]
-export declare const hello: string;
-
-
 //// [/src/dist/src/hello.json]
 {
     "hello": "world"
diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-of-json-along-with-other-include-and-file-name-matches-ts-file.js b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-of-json-along-with-other-include-and-file-name-matches-ts-file.js
index 0b516b4944f40..e37540f6ad6df 100644
--- a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-of-json-along-with-other-include-and-file-name-matches-ts-file.js
+++ b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-of-json-along-with-other-include-and-file-name-matches-ts-file.js
@@ -1,9 +1,70 @@
 //// [/lib/initial-buildOutput.txt]
 /lib/tsc --b /src/tsconfig_withIncludeOfJson.json
-error TS5056: Cannot write file '/src/dist/src/index.d.ts' because it would be overwritten by multiple input files.
-exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped
+exitCode:: ExitStatus.Success
 
 
+//// [/src/dist/src/index.d.ts]
+declare const _default: string;
+export default _default;
+
+
+//// [/src/dist/src/index.js]
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+    return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+exports.__esModule = true;
+var index_json_1 = __importDefault(require("./index.json"));
+exports["default"] = index_json_1["default"].hello;
+
+
+//// [/src/dist/src/index.json]
+{ "hello": "world" }
+
+
+//// [/src/dist/tsconfig_withIncludeOfJson.tsbuildinfo]
+{
+  "program": {
+    "fileInfos": {
+      "../../lib/lib.d.ts": {
+        "version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
+        "signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };"
+      },
+      "../src/index.json": {
+        "version": "-2379406821-{\"hello\":\"world\"}",
+        "signature": "-4341462827-export declare const hello: string;\r\n"
+      },
+      "../src/index.ts": {
+        "version": "-6335882310-import hello from \"./index.json\"\n\nexport default hello.hello",
+        "signature": "-1680156224-declare const _default: string;\r\nexport default _default;\r\n"
+      }
+    },
+    "options": {
+      "composite": true,
+      "moduleResolution": 2,
+      "module": 1,
+      "resolveJsonModule": true,
+      "esModuleInterop": true,
+      "allowSyntheticDefaultImports": true,
+      "outDir": "./",
+      "skipDefaultLibCheck": true,
+      "configFilePath": "../tsconfig_withIncludeOfJson.json"
+    },
+    "referencedMap": {
+      "../src/index.ts": [
+        "../src/index.json"
+      ]
+    },
+    "exportedModulesMap": {},
+    "semanticDiagnosticsPerFile": [
+      "../../lib/lib.d.ts",
+      "../src/index.json",
+      "../src/index.ts"
+    ]
+  },
+  "version": "FakeTSVersion"
+}
+
 //// [/src/src/hello.json] unlink
 //// [/src/src/index.json]
 {"hello":"world"}
diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-of-json-along-with-other-include.js b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-of-json-along-with-other-include.js
index 5bedb91c4bea2..4c021f8e349dd 100644
--- a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-of-json-along-with-other-include.js
+++ b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-of-json-along-with-other-include.js
@@ -3,10 +3,6 @@
 exitCode:: ExitStatus.Success
 
 
-//// [/src/dist/src/hello.d.ts]
-export declare const hello: string;
-
-
 //// [/src/dist/src/hello.json]
 {
     "hello": "world"
diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/sourcemap.js b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/sourcemap.js
index 92ff87ebcad85..5160faa127f1a 100644
--- a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/sourcemap.js
+++ b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/sourcemap.js
@@ -10,10 +10,6 @@
 exitCode:: ExitStatus.Success
 
 
-//// [/src/dist/src/hello.d.ts]
-export declare const hello: string;
-
-
 //// [/src/dist/src/hello.json]
 {
     "hello": "world"
diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/without-outDir.js b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/without-outDir.js
index b8756d8bf4b50..be2910bdbbd90 100644
--- a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/without-outDir.js
+++ b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/without-outDir.js
@@ -10,10 +10,6 @@
 exitCode:: ExitStatus.Success
 
 
-//// [/src/src/hello.d.ts]
-export declare const hello: string;
-
-
 //// [/src/src/index.d.ts]
 declare const _default: string;
 export default _default;