Skip to content

Commit 24febc2

Browse files
author
Andy
authored
Allow to combine --resolveJsonModule with --isolatedModules (#28207)
1 parent 672b0e3 commit 24febc2

5 files changed

+39
-3
lines changed

src/compiler/program.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2667,13 +2667,13 @@ namespace ts {
26672667
const languageVersion = options.target || ScriptTarget.ES3;
26682668
const outFile = options.outFile || options.out;
26692669

2670-
const firstNonAmbientExternalModuleSourceFile = forEach(files, f => isExternalModule(f) && !f.isDeclarationFile ? f : undefined);
2670+
const firstNonAmbientExternalModuleSourceFile = find(files, f => isExternalModule(f) && !f.isDeclarationFile);
26712671
if (options.isolatedModules) {
26722672
if (options.module === ModuleKind.None && languageVersion < ScriptTarget.ES2015) {
26732673
createDiagnosticForOptionName(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES2015_or_higher, "isolatedModules", "target");
26742674
}
26752675

2676-
const firstNonExternalModuleSourceFile = forEach(files, f => !isExternalModule(f) && !f.isDeclarationFile ? f : undefined);
2676+
const firstNonExternalModuleSourceFile = find(files, f => !isExternalModule(f) && !f.isDeclarationFile && f.scriptKind !== ScriptKind.JSON);
26772677
if (firstNonExternalModuleSourceFile) {
26782678
const span = getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile);
26792679
programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided));
@@ -2716,7 +2716,7 @@ namespace ts {
27162716
const dir = getCommonSourceDirectory();
27172717

27182718
// If we failed to find a good common directory, but outDir is specified and at least one of our files is on a windows drive/URL/other resource, add a failure
2719-
if (options.outDir && dir === "" && forEach(files, file => getRootLength(file.fileName) > 1)) {
2719+
if (options.outDir && dir === "" && files.some(file => getRootLength(file.fileName) > 1)) {
27202720
createDiagnosticForOptionName(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files, "outDir");
27212721
}
27222722
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [tests/cases/compiler/isolatedModules_resolveJsonModule.ts] ////
2+
3+
//// [a.ts]
4+
import j = require("./j.json");
5+
6+
//// [j.json]
7+
{}
8+
9+
10+
//// [a.js]
11+
"use strict";
12+
exports.__esModule = true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== /a.ts ===
2+
import j = require("./j.json");
3+
>j : Symbol(j, Decl(a.ts, 0, 0))
4+
5+
=== /j.json ===
6+
{}
7+
No type information for this code.
8+
No type information for this code.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== /a.ts ===
2+
import j = require("./j.json");
3+
>j : {}
4+
5+
=== /j.json ===
6+
{}
7+
>{} : {}
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @isolatedModules: true
2+
// @resolveJsonModule: true
3+
4+
// @Filename: /a.ts
5+
import j = require("./j.json");
6+
7+
// @Filename: /j.json
8+
{}

0 commit comments

Comments
 (0)