From fa52b5e73374dfd1e76f82207dd59020b6520148 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 27 Jul 2023 14:09:02 -0400 Subject: [PATCH] fix: do not include jsx without `@ts-check` in tsc roots (#19964) Closes #19928 --- cli/tests/integration/check_tests.rs | 8 +++++++ .../testdata/check/jsx_not_checked/main.jsx | 21 +++++++++++++++++++ .../testdata/check/jsx_not_checked/main.out | 11 ++++++++++ .../testdata/check/jsx_not_checked/other.ts | 5 +++++ cli/tools/check.rs | 10 ++++++--- 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 cli/tests/testdata/check/jsx_not_checked/main.jsx create mode 100644 cli/tests/testdata/check/jsx_not_checked/main.out create mode 100644 cli/tests/testdata/check/jsx_not_checked/other.ts diff --git a/cli/tests/integration/check_tests.rs b/cli/tests/integration/check_tests.rs index 04e5dedba8..54e93ca35d 100644 --- a/cli/tests/integration/check_tests.rs +++ b/cli/tests/integration/check_tests.rs @@ -58,6 +58,14 @@ itest!(bundle_jsximportsource_importmap_config { output: "check/jsximportsource_importmap_config/main.bundle.js", }); +itest!(jsx_not_checked { + args: "check check/jsx_not_checked/main.jsx", + output: "check/jsx_not_checked/main.out", + envs: env_vars_for_npm_tests_no_sync_download(), + http_server: true, + exit_code: 1, +}); + itest!(check_npm_install_diagnostics { args: "check --quiet check/npm_install_diagnostics/main.ts", output: "check/npm_install_diagnostics/main.out", diff --git a/cli/tests/testdata/check/jsx_not_checked/main.jsx b/cli/tests/testdata/check/jsx_not_checked/main.jsx new file mode 100644 index 0000000000..8de05f9f7c --- /dev/null +++ b/cli/tests/testdata/check/jsx_not_checked/main.jsx @@ -0,0 +1,21 @@ +// should not error about jsx-runtime not being found in types here +/** @jsxImportSource npm:react@18.2.0 */ + +import "./other.ts"; + +export default ( + <> +

Hello world

+

This is a JSX page

+ +); + +/** + * @param {number} a + * @param {number} b + */ +function add(a, b) { + return a + b; +} + +console.log(add("1", "2")); diff --git a/cli/tests/testdata/check/jsx_not_checked/main.out b/cli/tests/testdata/check/jsx_not_checked/main.out new file mode 100644 index 0000000000..a4e1c60e41 --- /dev/null +++ b/cli/tests/testdata/check/jsx_not_checked/main.out @@ -0,0 +1,11 @@ +Download http://localhost:4545/npm/registry/react +Download http://localhost:4545/npm/registry/loose-envify +Download http://localhost:4545/npm/registry/js-tokens +Download http://localhost:4545/npm/registry/react/react-18.2.0.tgz +Download http://localhost:4545/npm/registry/loose-envify/loose-envify-1.4.0.tgz +Download http://localhost:4545/npm/registry/js-tokens/js-tokens-4.0.0.tgz +Check file:///[WILDCARD]/jsx_not_checked/main.jsx +error: TS2345 [ERROR]: Argument of type 'string' is not assignable to parameter of type 'number'. +console.log(add("1", "2")); + ~~~ + at file:///[WILDCARD]/other.ts:5:17 diff --git a/cli/tests/testdata/check/jsx_not_checked/other.ts b/cli/tests/testdata/check/jsx_not_checked/other.ts new file mode 100644 index 0000000000..47995cb0f2 --- /dev/null +++ b/cli/tests/testdata/check/jsx_not_checked/other.ts @@ -0,0 +1,5 @@ +function add(a: number, b: number) { + return a + b; +} + +console.log(add("1", "2")); diff --git a/cli/tools/check.rs b/cli/tools/check.rs index 75ac2dc96b..f2e31b153c 100644 --- a/cli/tools/check.rs +++ b/cli/tools/check.rs @@ -308,9 +308,13 @@ fn get_tsc_roots( | MediaType::Cts | MediaType::Dts | MediaType::Dmts - | MediaType::Dcts - | MediaType::Jsx => Some((module.specifier.clone(), module.media_type)), - MediaType::JavaScript | MediaType::Mjs | MediaType::Cjs => { + | MediaType::Dcts => { + Some((module.specifier.clone(), module.media_type)) + } + MediaType::JavaScript + | MediaType::Mjs + | MediaType::Cjs + | MediaType::Jsx => { if check_js || has_ts_check(module.media_type, &module.source) { Some((module.specifier.clone(), module.media_type)) } else {