Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rewatch/src/build/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,10 @@ impl Package {
self.config.get_jsx_module_args()
}

pub fn get_jsx_preserve_args(&self) -> Vec<String> {
self.config.get_jsx_preserve_args()
}

pub fn get_uncurried_args(&self, version: &str, root_package: &packages::Package) -> Vec<String> {
root_package.config.get_uncurried_args(version)
}
Expand Down
2 changes: 2 additions & 0 deletions rewatch/src/build/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ pub fn parser_args(
let jsx_args = root_config.get_jsx_args();
let jsx_module_args = root_config.get_jsx_module_args();
let jsx_mode_args = root_config.get_jsx_mode_args();
let jsx_preserve_args = root_config.get_jsx_preserve_args();
let uncurried_args = root_config.get_uncurried_args(version);
let bsc_flags = config::flatten_flags(&config.bsc_flags);

Expand All @@ -285,6 +286,7 @@ pub fn parser_args(
jsx_args,
jsx_module_args,
jsx_mode_args,
jsx_preserve_args,
uncurried_args,
bsc_flags,
vec![
Expand Down
40 changes: 40 additions & 0 deletions rewatch/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ pub struct JsxSpecs {
pub mode: Option<JsxMode>,
#[serde(rename = "v3-dependencies")]
pub v3_dependencies: Option<Vec<String>>,
pub preserve: Option<bool>,
}

/// We do not care about the internal structure because the gentype config is loaded by bsc.
Expand Down Expand Up @@ -434,6 +435,16 @@ impl Config {
}
}

pub fn get_jsx_preserve_args(&self) -> Vec<String> {
match self.jsx.to_owned() {
Some(jsx) => match jsx.preserve {
Some(true) => vec!["-bs-jsx-preserve".to_string()],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not any new options with -bs prefix (and get rid of the old ones eventually).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the BSC flag; it was already in place. Why didn't you speak up when it was introduced?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. Must have overlooked it at that point.

_ => vec![],
},
_ => vec![],
}
}

pub fn get_uncurried_args(&self, version: &str) -> Vec<String> {
match check_if_rescript11_or_higher(version) {
Ok(true) => match self.uncurried.to_owned() {
Expand Down Expand Up @@ -614,6 +625,35 @@ mod tests {
module: Some(JsxModule::Other(String::from("Voby.JSX"))),
mode: None,
v3_dependencies: None,
preserve: None,
},
);
}

#[test]
fn test_jsx_preserve() {
let json = r#"
{
"name": "my-monorepo",
"sources": [ { "dir": "src/", "subdirs": true } ],
"package-specs": [ { "module": "es6", "in-source": true } ],
"suffix": ".mjs",
"pinned-dependencies": [ "@teamwalnut/app" ],
"bs-dependencies": [ "@teamwalnut/app" ],
"jsx": { "version": 4, "preserve": true }
}
"#;

let config = serde_json::from_str::<Config>(json).unwrap();
assert!(config.jsx.is_some());
assert_eq!(
config.jsx.unwrap(),
JsxSpecs {
version: Some(4),
module: None,
mode: None,
v3_dependencies: None,
preserve: Some(true),
},
);
}
Expand Down