Skip to content

Commit 8448e74

Browse files
author
Andy Hanson
committed
Fix bug: Return a resolution diagnostic for a .jsx import if --allowJs is turned off
1 parent b5ba315 commit 8448e74

5 files changed

+60
-4
lines changed

src/compiler/program.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,13 +1580,19 @@ namespace ts {
15801580
case Extension.Dts:
15811581
// These are always allowed.
15821582
return undefined;
1583-
15841583
case Extension.Tsx:
1584+
return needJsx();
15851585
case Extension.Jsx:
1586-
return options.jsx ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set;
1587-
1586+
return needJsx() || needAllowJs();
15881587
case Extension.Js:
1589-
return options.allowJs ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_allowJs_is_not_set;
1588+
return needAllowJs();
1589+
}
1590+
1591+
function needJsx() {
1592+
return options.jsx ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set;
1593+
}
1594+
function needAllowJs() {
1595+
return options.allowJs ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_allowJs_is_not_set;
15901596
}
15911597
}
15921598
}
Lines changed: 12 additions & 0 deletions
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+
Lines changed: 12 additions & 0 deletions
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";
Lines changed: 17 additions & 0 deletions
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+
]
Lines changed: 9 additions & 0 deletions
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)