Skip to content

Report errors for module generation other than "commonjs" with --resolveJsonModule #25566

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
merged 2 commits into from
Jul 10, 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
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2864,6 +2864,10 @@
"category": "Error",
"code": 5070
},
"Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs'.": {
"category": "Error",
"code": 5071
},

"Generates a sourcemap for each corresponding '.d.ts' file.": {
"category": "Message",
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2548,6 +2548,10 @@ namespace ts {
if (getEmitModuleResolutionKind(options) !== ModuleResolutionKind.NodeJs) {
createDiagnosticForOptionName(Diagnostics.Option_resolveJsonModule_cannot_be_specified_without_node_module_resolution_strategy, "resolveJsonModule");
}
// Any emit other than common js is error
else if (getEmitModuleKind(options) !== ModuleKind.CommonJS) {
createDiagnosticForOptionName(Diagnostics.Option_resolveJsonModule_can_only_be_specified_when_module_code_generation_is_commonjs, "resolveJsonModule", "module");
}
}

// there has to be common source directory if user specified --outdir || --sourceRoot
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error TS5070: Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy.
tests/cases/compiler/file1.ts(1,1): error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'.
tests/cases/compiler/file1.ts(1,20): error TS2307: Cannot find module './b.json'.


!!! error TS5070: Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy.
==== tests/cases/compiler/file1.ts (2 errors) ====
import * as b from './b.json';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'.
~~~~~~~~~~
!!! error TS2307: Cannot find module './b.json'.

==== tests/cases/compiler/b.json (0 errors) ====
{
"a": true,
"b": "hello"
}
14 changes: 14 additions & 0 deletions tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//// [tests/cases/compiler/requireOfJsonFileWithModuleEmitNone.ts] ////

//// [file1.ts]
import * as b from './b.json';

//// [b.json]
{
"a": true,
"b": "hello"
}

//// [out/file1.js]
"use strict";
exports.__esModule = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== tests/cases/compiler/file1.ts ===
import * as b from './b.json';
>b : Symbol(b, Decl(file1.ts, 0, 6))

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== tests/cases/compiler/file1.ts ===
import * as b from './b.json';
>b : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/requireOfJsonFileWithModuleEmitUndefined.ts] ////

//// [file1.ts]
import * as b from './b.json';

//// [b.json]
{
"a": true,
"b": "hello"
}

//// [out/b.json]
{
"a": true,
"b": "hello"
}
//// [out/file1.js]
"use strict";
exports.__esModule = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/compiler/file1.ts ===
import * as b from './b.json';
>b : Symbol(b, Decl(file1.ts, 0, 6))

=== tests/cases/compiler/b.json ===
{
"a": true,
>"a" : Symbol("a", Decl(b.json, 0, 1))

"b": "hello"
>"b" : Symbol("b", Decl(b.json, 1, 14))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
=== tests/cases/compiler/file1.ts ===
import * as b from './b.json';
>b : { "a": boolean; "b": string; }

=== tests/cases/compiler/b.json ===
{
>{ "a": true, "b": "hello"} : { "a": boolean; "b": string; }

"a": true,
>"a" : boolean
>true : true

"b": "hello"
>"b" : string
>"hello" : "hello"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error TS5071: Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs'.


!!! error TS5071: Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs'.
==== tests/cases/compiler/file1.ts (0 errors) ====
import * as b from './b.json';

==== tests/cases/compiler/b.json (0 errors) ====
{
"a": true,
"b": "hello"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [tests/cases/compiler/requireOfJsonFileWithModuleNodeResolutionEmitAmd.ts] ////

//// [file1.ts]
import * as b from './b.json';

//// [b.json]
{
"a": true,
"b": "hello"
}

//// [out/b.json]
{
"a": true,
"b": "hello"
}
//// [out/file1.js]
define(["require", "exports"], function (require, exports) {
"use strict";
exports.__esModule = true;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/compiler/file1.ts ===
import * as b from './b.json';
>b : Symbol(b, Decl(file1.ts, 0, 6))

=== tests/cases/compiler/b.json ===
{
"a": true,
>"a" : Symbol("a", Decl(b.json, 0, 1))

"b": "hello"
>"b" : Symbol("b", Decl(b.json, 1, 14))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
=== tests/cases/compiler/file1.ts ===
import * as b from './b.json';
>b : { "a": boolean; "b": string; }

=== tests/cases/compiler/b.json ===
{
>{ "a": true, "b": "hello"} : { "a": boolean; "b": string; }

"a": true,
>"a" : boolean
>true : true

"b": "hello"
>"b" : string
>"hello" : "hello"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error TS5071: Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs'.


!!! error TS5071: Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs'.
==== tests/cases/compiler/file1.ts (0 errors) ====
import * as b from './b.json';

==== tests/cases/compiler/b.json (0 errors) ====
{
"a": true,
"b": "hello"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [tests/cases/compiler/requireOfJsonFileWithModuleNodeResolutionEmitEs2015.ts] ////

//// [file1.ts]
import * as b from './b.json';

//// [b.json]
{
"a": true,
"b": "hello"
}

//// [out/b.json]
{
"a": true,
"b": "hello"
}
//// [out/file1.js]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/compiler/file1.ts ===
import * as b from './b.json';
>b : Symbol(b, Decl(file1.ts, 0, 6))

=== tests/cases/compiler/b.json ===
{
"a": true,
>"a" : Symbol("a", Decl(b.json, 0, 1))

"b": "hello"
>"b" : Symbol("b", Decl(b.json, 1, 14))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
=== tests/cases/compiler/file1.ts ===
import * as b from './b.json';
>b : { "a": boolean; "b": string; }

=== tests/cases/compiler/b.json ===
{
>{ "a": true, "b": "hello"} : { "a": boolean; "b": string; }

"a": true,
>"a" : boolean
>true : true

"b": "hello"
>"b" : string
>"hello" : "hello"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error TS5071: Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs'.


!!! error TS5071: Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs'.
==== tests/cases/compiler/file1.ts (0 errors) ====
import * as b from './b.json';

==== tests/cases/compiler/b.json (0 errors) ====
{
"a": true,
"b": "hello"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [tests/cases/compiler/requireOfJsonFileWithModuleNodeResolutionEmitEsNext.ts] ////

//// [file1.ts]
import * as b from './b.json';

//// [b.json]
{
"a": true,
"b": "hello"
}

//// [out/b.json]
{
"a": true,
"b": "hello"
}
//// [out/file1.js]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/compiler/file1.ts ===
import * as b from './b.json';
>b : Symbol(b, Decl(file1.ts, 0, 6))

=== tests/cases/compiler/b.json ===
{
"a": true,
>"a" : Symbol("a", Decl(b.json, 0, 1))

"b": "hello"
>"b" : Symbol("b", Decl(b.json, 1, 14))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
=== tests/cases/compiler/file1.ts ===
import * as b from './b.json';
>b : { "a": boolean; "b": string; }

=== tests/cases/compiler/b.json ===
{
>{ "a": true, "b": "hello"} : { "a": boolean; "b": string; }

"a": true,
>"a" : boolean
>true : true

"b": "hello"
>"b" : string
>"hello" : "hello"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error TS5071: Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs'.
tests/cases/compiler/file1.ts(1,1): error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'.


!!! error TS5071: Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs'.
==== tests/cases/compiler/file1.ts (1 errors) ====
import * as b from './b.json';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'.

==== tests/cases/compiler/b.json (0 errors) ====
{
"a": true,
"b": "hello"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/requireOfJsonFileWithModuleNodeResolutionEmitNone.ts] ////

//// [file1.ts]
import * as b from './b.json';

//// [b.json]
{
"a": true,
"b": "hello"
}

//// [out/b.json]
{
"a": true,
"b": "hello"
}
//// [out/file1.js]
"use strict";
exports.__esModule = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/compiler/file1.ts ===
import * as b from './b.json';
>b : Symbol(b, Decl(file1.ts, 0, 6))

=== tests/cases/compiler/b.json ===
{
"a": true,
>"a" : Symbol("a", Decl(b.json, 0, 1))

"b": "hello"
>"b" : Symbol("b", Decl(b.json, 1, 14))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
=== tests/cases/compiler/file1.ts ===
import * as b from './b.json';
>b : { "a": boolean; "b": string; }

=== tests/cases/compiler/b.json ===
{
>{ "a": true, "b": "hello"} : { "a": boolean; "b": string; }

"a": true,
>"a" : boolean
>true : true

"b": "hello"
>"b" : string
>"hello" : "hello"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error TS5071: Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs'.


!!! error TS5071: Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs'.
==== tests/cases/compiler/file1.ts (0 errors) ====
import * as b from './b.json';

==== tests/cases/compiler/b.json (0 errors) ====
{
"a": true,
"b": "hello"
}
Loading