From 58d543a480463ed24de77ec155f1d7e87bb7b234 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 1 Nov 2023 19:04:54 -0400 Subject: [PATCH] fix(repl): jsxImportSource was not working (#21049) I made some fixes in deno_ast to make this possible and we forgot to update this. --- Cargo.lock | 4 ++-- cli/Cargo.toml | 2 +- cli/args/flags.rs | 4 ++-- cli/args/mod.rs | 4 ++-- cli/factory.rs | 2 +- cli/tests/integration/repl_tests.rs | 17 +++++++++++++++++ cli/tools/repl/session.rs | 6 ++++-- 7 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 06f4415f2f..2f8e61d906 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1213,9 +1213,9 @@ dependencies = [ [[package]] name = "deno_doc" -version = "0.72.1" +version = "0.72.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bea5dacf0b7739d8e829e7c1ccd236929d9ff9a9fd63fb8aefb0c0b5e64fa86" +checksum = "48c00aff446bb7a0b9ef34418420650ee803e41251c034b9a944538dc80f1b65" dependencies = [ "anyhow", "cfg-if", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index c9eb3aa3ca..52ceb7c7af 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -49,7 +49,7 @@ deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "dep_gra deno_cache_dir = "=0.6.1" deno_config = "=0.5.0" deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] } -deno_doc = { version = "=0.72.1", features = ["html"] } +deno_doc = { version = "=0.72.2", features = ["html"] } deno_emit = "=0.31.1" deno_graph = "=0.59.2" deno_lint = { version = "=0.52.2", features = ["docs"] } diff --git a/cli/args/flags.rs b/cli/args/flags.rs index e558fe3918..fa1534e0c7 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -417,7 +417,7 @@ pub struct Flags { pub reload: bool, pub seed: Option, pub unstable: bool, - pub unstable_bare_node_builtlins: bool, + pub unstable_bare_node_builtins: bool, pub unstable_byonm: bool, pub unstable_features: Vec, pub unsafely_ignore_certificate_errors: Option>, @@ -856,7 +856,7 @@ pub fn flags_from_vec(args: Vec) -> clap::error::Result { .push(deno_runtime::deno_cron::UNSTABLE_FEATURE_NAME.to_string()); } - flags.unstable_bare_node_builtlins = + flags.unstable_bare_node_builtins = matches.get_flag("unstable-bare-node-builtins"); flags.unstable_byonm = matches.get_flag("unstable-byonm"); diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 1d28df1245..fa8d94de51 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1249,8 +1249,8 @@ impl CliOptions { self.flags.unstable } - pub fn unstable_bare_node_builtlins(&self) -> bool { - self.flags.unstable_bare_node_builtlins + pub fn unstable_bare_node_builtins(&self) -> bool { + self.flags.unstable_bare_node_builtins || self .maybe_config_file() .as_ref() diff --git a/cli/factory.rs b/cli/factory.rs index 06c9472fad..037ba4e2f1 100644 --- a/cli/factory.rs +++ b/cli/factory.rs @@ -392,7 +392,7 @@ impl CliFactory { maybe_vendor_dir: self.options.vendor_dir_path(), bare_node_builtins_enabled: self .options - .unstable_bare_node_builtlins(), + .unstable_bare_node_builtins(), }))) }) .await diff --git a/cli/tests/integration/repl_tests.rs b/cli/tests/integration/repl_tests.rs index fe075d37c8..c161477d52 100644 --- a/cli/tests/integration/repl_tests.rs +++ b/cli/tests/integration/repl_tests.rs @@ -504,6 +504,23 @@ fn jsx_errors_without_pragma() { }); } +#[test] +fn jsx_import_source() { + let context = TestContextBuilder::default() + .use_temp_cwd() + .use_http_server() + .build(); + context + .new_command() + .args_vec(["repl", "-A"]) + .with_pty(|mut console| { + console.write_line("/** @jsxImportSource http://localhost:4545/jsx */"); + console.expect("undefined"); + console.write_line("const element =
;"); + console.expect("undefined"); + }); +} + #[test] fn type_error() { util::with_pty(&["repl"], |mut console| { diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs index 65f45652d3..df9a63772c 100644 --- a/cli/tools/repl/session.rs +++ b/cli/tools/repl/session.rs @@ -590,11 +590,11 @@ impl ReplSession { imports_not_used_as_values: ImportsNotUsedAsValues::Preserve, transform_jsx: true, precompile_jsx: false, - jsx_automatic: false, + jsx_automatic: self.jsx.import_source.is_some(), jsx_development: false, jsx_factory: self.jsx.factory.clone(), jsx_fragment_factory: self.jsx.frag_factory.clone(), - jsx_import_source: None, + jsx_import_source: self.jsx.import_source.clone(), var_decl_imports: true, })? .text; @@ -620,9 +620,11 @@ impl ReplSession { if let Some(jsx) = analyzed_pragmas.jsx { self.jsx.factory = jsx.text; + self.jsx.import_source = None; } if let Some(jsx_frag) = analyzed_pragmas.jsx_fragment { self.jsx.frag_factory = jsx_frag.text; + self.jsx.import_source = None; } if let Some(jsx_import_source) = analyzed_pragmas.jsx_import_source { self.jsx.import_source = Some(jsx_import_source.text);