Skip to content

Allow to combine --resolveJsonModule with --isolatedModules #28207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
{}