Skip to content

Commit

Permalink
Emit forced type assertions for ESModules
Browse files Browse the repository at this point in the history
Reviewed By: alunyov

Differential Revision: D42792490

fbshipit-source-id: 1dbfdfa82bb2a23b34edfcd76fcb62aea644d9a8
  • Loading branch information
captbaritone authored and facebook-github-bot committed Jan 30, 2023
1 parent 45db15b commit 1802a7d
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions compiler/crates/relay-compiler/src/artifact_content/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,22 +824,22 @@ fn write_export_generated_node(
variable_node: &str,
forced_type: Option<String>,
) -> FmtResult {
if typegen_config.eager_es_modules {
writeln!(section, "export default {};", variable_node)
} else {
match (typegen_config.language, forced_type) {
(TypegenLanguage::Flow, None) | (TypegenLanguage::JavaScript, _) => {
writeln!(section, "module.exports = {};", variable_node)
}
(TypegenLanguage::Flow, Some(forced_type)) => writeln!(
section,
"module.exports = (({}/*: any*/)/*: {}*/);",
variable_node, forced_type
),
(TypegenLanguage::TypeScript, _) => {
writeln!(section, "export default {};", variable_node)
}
let export_value = match (typegen_config.language, forced_type) {
(TypegenLanguage::Flow, None) | (TypegenLanguage::JavaScript, _) => {
variable_node.to_string()
}
(TypegenLanguage::TypeScript, _) => {
// TODO: Support force_type for TypeScript
variable_node.to_string()
}
(TypegenLanguage::Flow, Some(forced_type)) => {
format!("(({}/*: any*/)/*: {}*/)", variable_node, forced_type)
}
};
if typegen_config.eager_es_modules || typegen_config.language == TypegenLanguage::TypeScript {
writeln!(section, "export default {};", export_value)
} else {
writeln!(section, "module.exports = {};", export_value)
}
}

Expand Down

0 comments on commit 1802a7d

Please sign in to comment.