diff options
author | Luca Casonato <hello@lcas.dev> | 2024-04-30 20:12:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-30 18:12:35 +0000 |
commit | 6cdf81db7c4a41d036eefc17e41ffb8db0cf54a1 (patch) | |
tree | 6e21e240c12d8fc9856fbc342aab3d986e338e70 /cli | |
parent | 8c3f8ba13605d1c69eba4272179bce5ca0d10fe3 (diff) |
feat(cli): add support for jsxImportSourceTypes (#23419)
Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'cli')
-rw-r--r-- | cli/Cargo.toml | 6 | ||||
-rw-r--r-- | cli/args/mod.rs | 1 | ||||
-rw-r--r-- | cli/lsp/config.rs | 10 | ||||
-rw-r--r-- | cli/resolver.rs | 9 | ||||
-rw-r--r-- | cli/schemas/config-file.v1.json | 6 | ||||
-rw-r--r-- | cli/tools/repl/session.rs | 1 | ||||
-rw-r--r-- | cli/tools/vendor/build.rs | 2 |
7 files changed, 30 insertions, 5 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 605b1075e..02f44563e 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -65,11 +65,11 @@ winres.workspace = true [dependencies] deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] } deno_cache_dir = { workspace = true } -deno_config = "=0.16.2" +deno_config = "=0.16.3" deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] } deno_doc = { version = "=0.128.1", features = ["html", "syntect"] } -deno_emit = "=0.40.1" -deno_graph = { version = "=0.74.0", features = ["tokio_executor"] } +deno_emit = "=0.40.2" +deno_graph = { version = "=0.74.2", features = ["tokio_executor"] } deno_lint = { version = "=0.58.4", features = ["docs"] } deno_lockfile.workspace = true deno_npm = "=0.18.0" diff --git a/cli/args/mod.rs b/cli/args/mod.rs index b77a8afdb..f4d5743dc 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -196,6 +196,7 @@ pub fn ts_config_to_transpile_and_emit_options( inline_sources: options.inline_sources, keep_comments: false, source_map, + source_map_file: None, }, )) } diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index e5703a21a..ec209e0e6 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -1071,8 +1071,14 @@ impl LspTsConfig { let import_map = import_map?; let referrer = &config_file?.specifier; let compiler_options = ts_config.inner.0.as_object_mut()?; - let jsx_import_source = - compiler_options.get("jsxImportSource")?.as_str()?; + let jsx_import_source = compiler_options + .get("jsxImportSourceTypes") + .and_then(|v| v.as_str()) + .or_else(|| { + compiler_options + .get("jsxImportSource") + .and_then(|v| v.as_str()) + })?; let jsx_import_source = import_map.resolve(jsx_import_source, referrer).ok()?; compiler_options diff --git a/cli/resolver.rs b/cli/resolver.rs index dfee9a704..32233e961 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -447,6 +447,7 @@ pub struct CliGraphResolver { sloppy_imports_resolver: Option<SloppyImportsResolver>, mapped_specifier_resolver: MappedSpecifierResolver, maybe_default_jsx_import_source: Option<String>, + maybe_default_jsx_import_source_types: Option<String>, maybe_jsx_import_source_module: Option<String>, maybe_vendor_specifier: Option<ModuleSpecifier>, node_resolver: Option<Arc<CliNodeResolver>>, @@ -488,6 +489,10 @@ impl CliGraphResolver { .maybe_jsx_import_source_config .as_ref() .and_then(|c| c.default_specifier.clone()), + maybe_default_jsx_import_source_types: options + .maybe_jsx_import_source_config + .as_ref() + .and_then(|c| c.default_types_specifier.clone()), maybe_jsx_import_source_module: options .maybe_jsx_import_source_config .map(|c| c.module), @@ -554,6 +559,10 @@ impl Resolver for CliGraphResolver { self.maybe_default_jsx_import_source.clone() } + fn default_jsx_import_source_types(&self) -> Option<String> { + self.maybe_default_jsx_import_source_types.clone() + } + fn jsx_import_source_module(&self) -> &str { self .maybe_jsx_import_source_module diff --git a/cli/schemas/config-file.v1.json b/cli/schemas/config-file.v1.json index a18894016..bfcae271b 100644 --- a/cli/schemas/config-file.v1.json +++ b/cli/schemas/config-file.v1.json @@ -76,6 +76,12 @@ "default": "react", "markdownDescription": "Specify module specifier used to import the JSX factory functions when using jsx: `react-jsx*`.\n\nSee more: https://www.typescriptlang.org/tsconfig/#jsxImportSource" }, + "jsxImportSourceTypes": { + "description": "Specify module specifier used to import the types for the JSX factory functions when using jsx: 'react-jsx*'. This is the logical equivalent of prefixing an import to the jsxImportSource with `// @deno-types=\"...\"`.", + "type": "string", + "default": "@types/react", + "markdownDescription": "Specify module specifier used to import the types for the JSX factory functions when using jsx: `react-jsx*`. This is the logical equivalent of prefixing an import to the jsxImportSource with `// @deno-types=\"...\"`." + }, "jsxPrecompileSkipElements": { "description": "Specify list of elements that should be exempt from being precompiled when the jsx 'precompile' transform is used.", "type": "array", diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs index 671dad4b5..1bc8a96d0 100644 --- a/cli/tools/repl/session.rs +++ b/cli/tools/repl/session.rs @@ -637,6 +637,7 @@ impl ReplSession { }, &deno_ast::EmitOptions { source_map: deno_ast::SourceMapOption::None, + source_map_file: None, inline_sources: false, keep_comments: false, }, diff --git a/cli/tools/vendor/build.rs b/cli/tools/vendor/build.rs index 0590992b0..5ff986f0c 100644 --- a/cli/tools/vendor/build.rs +++ b/cli/tools/vendor/build.rs @@ -1205,6 +1205,7 @@ mod test { builder.add_entry_point("/mod.tsx"); builder.set_jsx_import_source_config(JsxImportSourceConfig { default_specifier: Some("preact".to_string()), + default_types_specifier: None, module: "jsx-runtime".to_string(), base_url: builder.resolve_to_url("/deno.json"), }); @@ -1254,6 +1255,7 @@ mod test { builder.add_entry_point("/mod.ts"); builder.set_jsx_import_source_config(JsxImportSourceConfig { default_specifier: Some("preact".to_string()), + default_types_specifier: None, module: "jsx-runtime".to_string(), base_url: builder.resolve_to_url("/deno.json"), }); |