1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(cli): Don't panic on invalid emit options (#23463)

Fixes #23456.
This commit is contained in:
Nathan Whitaker 2024-04-23 08:50:50 -07:00 committed by GitHub
parent 804b97c636
commit 8a367d3cc3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 23 additions and 8 deletions

View file

@ -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,
@ -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,
@ -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.

View file

@ -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(),

View file

@ -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 {

View file

@ -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,

View file

@ -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,

View file

@ -0,0 +1,5 @@
{
"args": "run main.ts",
"output": "main.out",
"exitCode": 1
}

View file

@ -0,0 +1,5 @@
{
"compilerOptions": {
"jsx": 1234
}
}

View file

@ -0,0 +1,4 @@
error: Failed to parse compilerOptions
Caused by:
invalid type: integer `1234`, expected a string