Merge pull request #25566 from Microsoft/nonCommonJsResolveJsonIsError

Report errors for module generation other than "commonjs" with --resolveJsonModule
This commit is contained in:
Sheetal Nandi
2018-07-10 15:30:23 -07:00
committed by GitHub
45 changed files with 636 additions and 0 deletions
+4
View File
@@ -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",
+4
View File
@@ -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
@@ -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"
}
@@ -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;
@@ -0,0 +1,4 @@
=== tests/cases/compiler/file1.ts ===
import * as b from './b.json';
>b : Symbol(b, Decl(file1.ts, 0, 6))
@@ -0,0 +1,4 @@
=== tests/cases/compiler/file1.ts ===
import * as b from './b.json';
>b : any
@@ -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;
@@ -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))
}
@@ -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"
}
@@ -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"
}
@@ -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;
});
@@ -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))
}
@@ -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"
}
@@ -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"
}
@@ -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]
@@ -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))
}
@@ -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"
}
@@ -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"
}
@@ -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]
@@ -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))
}
@@ -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"
}
@@ -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"
}
@@ -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;
@@ -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))
}
@@ -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"
}
@@ -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"
}
@@ -0,0 +1,26 @@
//// [tests/cases/compiler/requireOfJsonFileWithModuleNodeResolutionEmitSystem.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]
System.register([], function (exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
}
};
});
@@ -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))
}
@@ -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"
}
@@ -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"
}
@@ -0,0 +1,29 @@
//// [tests/cases/compiler/requireOfJsonFileWithModuleNodeResolutionEmitUmd.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]
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
exports.__esModule = true;
});
@@ -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))
}
@@ -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"
}
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/requireOfJsonFileWithModuleNodeResolutionEmitUndefined.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;
@@ -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))
}
@@ -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"
}
@@ -0,0 +1,13 @@
// @module: none
// @outdir: out/
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import * as b from './b.json';
// @Filename: b.json
{
"a": true,
"b": "hello"
}
@@ -0,0 +1,12 @@
// @outdir: out/
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import * as b from './b.json';
// @Filename: b.json
{
"a": true,
"b": "hello"
}
@@ -0,0 +1,14 @@
// @module: amd
// @moduleResolution: node
// @outdir: out/
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import * as b from './b.json';
// @Filename: b.json
{
"a": true,
"b": "hello"
}
@@ -0,0 +1,14 @@
// @module: es2015
// @moduleResolution: node
// @outdir: out/
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import * as b from './b.json';
// @Filename: b.json
{
"a": true,
"b": "hello"
}
@@ -0,0 +1,14 @@
// @module: esnext
// @moduleResolution: node
// @outdir: out/
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import * as b from './b.json';
// @Filename: b.json
{
"a": true,
"b": "hello"
}
@@ -0,0 +1,14 @@
// @module: none
// @moduleResolution: node
// @outdir: out/
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import * as b from './b.json';
// @Filename: b.json
{
"a": true,
"b": "hello"
}
@@ -0,0 +1,14 @@
// @module: system
// @moduleResolution: node
// @outdir: out/
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import * as b from './b.json';
// @Filename: b.json
{
"a": true,
"b": "hello"
}
@@ -0,0 +1,14 @@
// @module: umd
// @moduleResolution: node
// @outdir: out/
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import * as b from './b.json';
// @Filename: b.json
{
"a": true,
"b": "hello"
}
@@ -0,0 +1,13 @@
// @moduleResolution: node
// @outdir: out/
// @fullEmitPaths: true
// @resolveJsonModule: true
// @Filename: file1.ts
import * as b from './b.json';
// @Filename: b.json
{
"a": true,
"b": "hello"
}