diff --git a/src/compiler/program.ts b/src/compiler/program.ts index fab35141ba4af..431479752d1c3 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -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; } } } diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_notSupported3.errors.txt b/tests/baselines/reference/moduleResolutionWithExtensions_notSupported3.errors.txt new file mode 100644 index 0000000000000..45e058bae54ed --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithExtensions_notSupported3.errors.txt @@ -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`. + + \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_notSupported3.js b/tests/baselines/reference/moduleResolutionWithExtensions_notSupported3.js new file mode 100644 index 0000000000000..f362701bbda71 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithExtensions_notSupported3.js @@ -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"; diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_notSupported3.trace.json b/tests/baselines/reference/moduleResolutionWithExtensions_notSupported3.trace.json new file mode 100644 index 0000000000000..c366843ce86e6 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithExtensions_notSupported3.trace.json @@ -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'. ========" +] \ No newline at end of file diff --git a/tests/cases/compiler/moduleResolutionWithExtensions_notSupported3.ts b/tests/cases/compiler/moduleResolutionWithExtensions_notSupported3.ts new file mode 100644 index 0000000000000..e06f603377c19 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithExtensions_notSupported3.ts @@ -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";