Skip to content

Commit 231b5ac

Browse files
author
Andy
authored
Merge pull request microsoft#11891 from Microsoft/jsx_resolution_diagnostic
Fix bug: Return a resolution diagnostic for a `.jsx` import if `--allowJs` is turned off
2 parents 6f519d8 + 8448e74 commit 231b5ac

5 files changed

+60
-4
lines changed

src/compiler/program.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1579,13 +1579,19 @@ namespace ts {
15791579
case Extension.Dts:
15801580
// These are always allowed.
15811581
return undefined;
1582-
15831582
case Extension.Tsx:
1583+
return needJsx();
15841584
case Extension.Jsx:
1585-
return options.jsx ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set;
1586-
1585+
return needJsx() || needAllowJs();
15871586
case Extension.Js:
1588-
return options.allowJs ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_allowJs_is_not_set;
1587+
return needAllowJs();
1588+
}
1589+
1590+
function needJsx() {
1591+
return options.jsx ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set;
1592+
}
1593+
function needAllowJs() {
1594+
return options.allowJs ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_allowJs_is_not_set;
15891595
}
15901596
}
15911597
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/a.ts(1,17): error TS6143: Module './jsx' was resolved to '/jsx.jsx', but '--allowJs' is not set.
2+
3+
4+
==== /a.ts (1 errors) ====
5+
import jsx from "./jsx";
6+
~~~~~~~
7+
!!! error TS6143: Module './jsx' was resolved to '/jsx.jsx', but '--allowJs' is not set.
8+
9+
==== /jsx.jsx (0 errors) ====
10+
// Test the error message if we have `--jsx` but not `--allowJw`.
11+
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [tests/cases/compiler/moduleResolutionWithExtensions_notSupported3.ts] ////
2+
3+
//// [jsx.jsx]
4+
// Test the error message if we have `--jsx` but not `--allowJw`.
5+
6+
7+
//// [a.ts]
8+
import jsx from "./jsx";
9+
10+
11+
//// [a.js]
12+
"use strict";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
"======== Resolving module './jsx' from '/a.ts'. ========",
3+
"Module resolution kind is not specified, using 'NodeJs'.",
4+
"Loading module as file / folder, candidate module location '/jsx'.",
5+
"File '/jsx.ts' does not exist.",
6+
"File '/jsx.tsx' does not exist.",
7+
"File '/jsx.d.ts' does not exist.",
8+
"File '/jsx/package.json' does not exist.",
9+
"File '/jsx/index.ts' does not exist.",
10+
"File '/jsx/index.tsx' does not exist.",
11+
"File '/jsx/index.d.ts' does not exist.",
12+
"Loading module as file / folder, candidate module location '/jsx'.",
13+
"File '/jsx.js' does not exist.",
14+
"File '/jsx.jsx' exist - use it as a name resolution result.",
15+
"Resolving real path for '/jsx.jsx', result '/jsx.jsx'",
16+
"======== Module name './jsx' was successfully resolved to '/jsx.jsx'. ========"
17+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @noImplicitReferences: true
2+
// @jsx: preserve
3+
// @traceResolution: true
4+
// Test the error message if we have `--jsx` but not `--allowJw`.
5+
6+
// @Filename: /jsx.jsx
7+
8+
// @Filename: /a.ts
9+
import jsx from "./jsx";

0 commit comments

Comments
 (0)