Skip to content

Commit

Permalink
Allow to combine --resolveJsonModule with --isolatedModules (#28207)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy authored Oct 29, 2018
1 parent 672b0e3 commit 24febc2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2667,13 +2667,13 @@ namespace ts {
const languageVersion = options.target || ScriptTarget.ES3;
const outFile = options.outFile || options.out;

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

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

// 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
if (options.outDir && dir === "" && forEach(files, file => getRootLength(file.fileName) > 1)) {
if (options.outDir && dir === "" && files.some(file => getRootLength(file.fileName) > 1)) {
createDiagnosticForOptionName(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files, "outDir");
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/baselines/reference/isolatedModules_resolveJsonModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//// [tests/cases/compiler/isolatedModules_resolveJsonModule.ts] ////

//// [a.ts]
import j = require("./j.json");

//// [j.json]
{}


//// [a.js]
"use strict";
exports.__esModule = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== /a.ts ===
import j = require("./j.json");
>j : Symbol(j, Decl(a.ts, 0, 0))

=== /j.json ===
{}
No type information for this code.
No type information for this code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== /a.ts ===
import j = require("./j.json");
>j : {}

=== /j.json ===
{}
>{} : {}

8 changes: 8 additions & 0 deletions tests/cases/compiler/isolatedModules_resolveJsonModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @isolatedModules: true
// @resolveJsonModule: true

// @Filename: /a.ts
import j = require("./j.json");

// @Filename: /j.json
{}

0 comments on commit 24febc2

Please sign in to comment.