Fix bug: Return a resolution diagnostic for a .jsx import if --allowJs is turned off

This commit is contained in:
Andy Hanson
2016-10-27 08:08:02 -07:00
parent b5ba3152ff
commit 8448e741c9
5 changed files with 60 additions and 4 deletions

View File

@@ -1580,13 +1580,19 @@ namespace ts {
case Extension.Dts:
// These are always allowed.
return undefined;
case Extension.Tsx:
return needJsx();
case Extension.Jsx:
return options.jsx ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set;
return needJsx() || needAllowJs();
case Extension.Js:
return options.allowJs ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_allowJs_is_not_set;
return needAllowJs();
}
function needJsx() {
return options.jsx ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set;
}
function needAllowJs() {
return options.allowJs ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_allowJs_is_not_set;
}
}
}

View File

@@ -0,0 +1,12 @@
/a.ts(1,17): error TS6143: Module './jsx' was resolved to '/jsx.jsx', but '--allowJs' is not set.
==== /a.ts (1 errors) ====
import jsx from "./jsx";
~~~~~~~
!!! error TS6143: Module './jsx' was resolved to '/jsx.jsx', but '--allowJs' is not set.
==== /jsx.jsx (0 errors) ====
// Test the error message if we have `--jsx` but not `--allowJw`.

View File

@@ -0,0 +1,12 @@
//// [tests/cases/compiler/moduleResolutionWithExtensions_notSupported3.ts] ////
//// [jsx.jsx]
// Test the error message if we have `--jsx` but not `--allowJw`.
//// [a.ts]
import jsx from "./jsx";
//// [a.js]
"use strict";

View File

@@ -0,0 +1,17 @@
[
"======== Resolving module './jsx' from '/a.ts'. ========",
"Module resolution kind is not specified, using 'NodeJs'.",
"Loading module as file / folder, candidate module location '/jsx'.",
"File '/jsx.ts' does not exist.",
"File '/jsx.tsx' does not exist.",
"File '/jsx.d.ts' does not exist.",
"File '/jsx/package.json' does not exist.",
"File '/jsx/index.ts' does not exist.",
"File '/jsx/index.tsx' does not exist.",
"File '/jsx/index.d.ts' does not exist.",
"Loading module as file / folder, candidate module location '/jsx'.",
"File '/jsx.js' does not exist.",
"File '/jsx.jsx' exist - use it as a name resolution result.",
"Resolving real path for '/jsx.jsx', result '/jsx.jsx'",
"======== Module name './jsx' was successfully resolved to '/jsx.jsx'. ========"
]

View File

@@ -0,0 +1,9 @@
// @noImplicitReferences: true
// @jsx: preserve
// @traceResolution: true
// Test the error message if we have `--jsx` but not `--allowJw`.
// @Filename: /jsx.jsx
// @Filename: /a.ts
import jsx from "./jsx";