Skip to content

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

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 27, 2016
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
14 changes: 10 additions & 4 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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`.


Original file line number Diff line number Diff line change
@@ -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";
Original file line number Diff line number Diff line change
@@ -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'. ========"
]
Original file line number Diff line number Diff line change
@@ -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";