Skip to content

Commit

Permalink
fix(cli): Don't panic on invalid emit options (#23463)
Browse files Browse the repository at this point in the history
Fixes #23456.
  • Loading branch information
nathanwhit committed Apr 23, 2024
1 parent 804b97c commit 8a367d3
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 8 deletions.
9 changes: 5 additions & 4 deletions cli/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ pub fn jsr_api_url() -> &'static Url {

pub fn ts_config_to_transpile_and_emit_options(
config: deno_config::TsConfig,
) -> (deno_ast::TranspileOptions, deno_ast::EmitOptions) {
) -> Result<(deno_ast::TranspileOptions, deno_ast::EmitOptions), AnyError> {
let options: deno_config::EmitConfigOptions =
serde_json::from_value(config.0).unwrap();
serde_json::from_value(config.0)
.context("Failed to parse compilerOptions")?;
let imports_not_used_as_values =
match options.imports_not_used_as_values.as_str() {
"preserve" => deno_ast::ImportsNotUsedAsValues::Preserve,
Expand All @@ -174,7 +175,7 @@ pub fn ts_config_to_transpile_and_emit_options(
} else {
SourceMapOption::None
};
(
Ok((
deno_ast::TranspileOptions {
use_ts_decorators: options.experimental_decorators,
use_decorators_proposal: !options.experimental_decorators,
Expand All @@ -195,7 +196,7 @@ pub fn ts_config_to_transpile_and_emit_options(
keep_comments: false,
source_map,
},
)
))
}

/// Indicates how cached source files should be handled.
Expand Down
2 changes: 1 addition & 1 deletion cli/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ impl CliFactory {
let (transpile_options, emit_options) =
crate::args::ts_config_to_transpile_and_emit_options(
ts_config_result.ts_config,
);
)?;
Ok(Arc::new(Emitter::new(
self.emit_cache()?.clone(),
self.parsed_source_cache().clone(),
Expand Down
2 changes: 1 addition & 1 deletion cli/tools/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn bundle_module_graph(
let (transpile_options, emit_options) =
crate::args::ts_config_to_transpile_and_emit_options(
ts_config_result.ts_config,
);
)?;
deno_emit::bundle_graph(
graph,
deno_emit::BundleOptions {
Expand Down
2 changes: 1 addition & 1 deletion cli/tools/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub async fn compile(
let (transpile_options, emit_options) =
crate::args::ts_config_to_transpile_and_emit_options(
ts_config_for_emit.ts_config,
);
)?;
let parser = parsed_source_cache.as_capturing_parser();
let eszip = eszip::EszipV2::from_graph(
graph,
Expand Down
2 changes: 1 addition & 1 deletion cli/tools/repl/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl ReplSession {
let (transpile_options, _) =
crate::args::ts_config_to_transpile_and_emit_options(
ts_config_for_emit.ts_config,
);
)?;
let experimental_decorators = transpile_options.use_ts_decorators;
let mut repl_session = ReplSession {
npm_resolver,
Expand Down
5 changes: 5 additions & 0 deletions tests/specs/run/invalid_emit_options/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"args": "run main.ts",
"output": "main.out",
"exitCode": 1
}
5 changes: 5 additions & 0 deletions tests/specs/run/invalid_emit_options/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"jsx": 1234
}
}
4 changes: 4 additions & 0 deletions tests/specs/run/invalid_emit_options/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: Failed to parse compilerOptions

Caused by:
invalid type: integer `1234`, expected a string
Empty file.

0 comments on commit 8a367d3

Please sign in to comment.