summaryrefslogtreecommitdiff
path: root/cli/args/config_file.rs
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2022-08-24 19:36:05 +0200
committerGitHub <noreply@github.com>2022-08-24 19:36:05 +0200
commit33c4d45328166d103e99a8c243727eead626080c (patch)
tree70331a9964f8faf780942696c34aab867accf7bf /cli/args/config_file.rs
parent6bb72a80863ac3913d32ea21aae32dd327ce6b71 (diff)
fix: resolve `jsxImportSource` relative to module (#15561)
Previously `jsxImportSource` was resolved relative to the config file during graph building, and relative to the emitted module during runtime. This is now fixed so that the JSX import source is resolved relative to the module both during graph building and at runtime.
Diffstat (limited to 'cli/args/config_file.rs')
-rw-r--r--cli/args/config_file.rs31
1 files changed, 15 insertions, 16 deletions
diff --git a/cli/args/config_file.rs b/cli/args/config_file.rs
index 1739309ff..ab6e57cb1 100644
--- a/cli/args/config_file.rs
+++ b/cli/args/config_file.rs
@@ -11,7 +11,6 @@ use crate::fs_util::specifier_to_file_path;
use deno_core::anyhow::anyhow;
use deno_core::anyhow::bail;
use deno_core::anyhow::Context;
-use deno_core::error::custom_error;
use deno_core::error::AnyError;
use deno_core::serde::Deserialize;
use deno_core::serde::Serialize;
@@ -30,6 +29,11 @@ use std::path::PathBuf;
pub type MaybeImportsResult =
Result<Option<Vec<(ModuleSpecifier, Vec<String>)>>, AnyError>;
+pub struct JsxImportSourceConfig {
+ pub default_specifier: Option<String>,
+ pub module: String,
+}
+
/// The transpile options that are significant out of a user provided tsconfig
/// file, that we want to deserialize out of the final config for a transpile.
#[derive(Debug, Deserialize)]
@@ -680,17 +684,6 @@ impl ConfigFile {
if let Some(types) = compiler_options.types {
imports.extend(types);
}
- if compiler_options.jsx == Some("react-jsx".to_string()) {
- imports.push(format!(
- "{}/jsx-runtime",
- compiler_options.jsx_import_source.ok_or_else(|| custom_error("TypeError", "Compiler option 'jsx' set to 'react-jsx', but no 'jsxImportSource' defined."))?
- ));
- } else if compiler_options.jsx == Some("react-jsxdev".to_string()) {
- imports.push(format!(
- "{}/jsx-dev-runtime",
- compiler_options.jsx_import_source.ok_or_else(|| custom_error("TypeError", "Compiler option 'jsx' set to 'react-jsxdev', but no 'jsxImportSource' defined."))?
- ));
- }
if !imports.is_empty() {
let referrer = self.specifier.clone();
Ok(Some(vec![(referrer, imports)]))
@@ -700,16 +693,22 @@ impl ConfigFile {
}
/// Based on the compiler options in the configuration file, return the
- /// implied JSX import source module.
- pub fn to_maybe_jsx_import_source_module(&self) -> Option<String> {
+ /// JSX import source configuration.
+ pub fn to_maybe_jsx_import_source_config(
+ &self,
+ ) -> Option<JsxImportSourceConfig> {
let compiler_options_value = self.json.compiler_options.as_ref()?;
let compiler_options: CompilerOptions =
serde_json::from_value(compiler_options_value.clone()).ok()?;
- match compiler_options.jsx.as_deref() {
+ let module = match compiler_options.jsx.as_deref() {
Some("react-jsx") => Some("jsx-runtime".to_string()),
Some("react-jsxdev") => Some("jsx-dev-runtime".to_string()),
_ => None,
- }
+ };
+ module.map(|module| JsxImportSourceConfig {
+ default_specifier: compiler_options.jsx_import_source,
+ module,
+ })
}
pub fn to_fmt_config(&self) -> Result<Option<FmtConfig>, AnyError> {