From b66f5ed00e83927a976ffdbe45c2ace9641de086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 24 Jan 2024 14:16:23 +0100 Subject: feat: TC39 decorator proposal support (#22040) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds support for [TC39 Decorator Proposal](https://github.com/tc39/proposal-decorators). These decorators are only available in transpiled sources - ie. non-JavaScript files (because of lack of support in V8). This entails that "experimental TypeScript decorators" are not available by default and require to be configured, with a configuration like this: ``` { "compilerOptions": { "experimentalDecorators": true } } ``` Closes https://github.com/denoland/deno/issues/19160 --------- Signed-off-by: Bartek IwaƄczuk Co-authored-by: crowlkats Co-authored-by: Divy Srivastava --- cli/args/mod.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'cli/args') diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 34448e633..13ee9eeef 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -158,10 +158,8 @@ pub fn ts_config_to_emit_options( _ => (false, false, false, false), }; deno_ast::EmitOptions { - // TODO(bartlomieju): change it to default to `false` and only enable - // if tsconfig.json enabled experimental decorators - use_ts_decorators: true, - use_decorators_proposal: false, + use_ts_decorators: options.experimental_decorators, + use_decorators_proposal: !options.experimental_decorators, emit_metadata: options.emit_decorator_metadata, imports_not_used_as_values, inline_source_map: options.inline_source_map, @@ -1088,10 +1086,26 @@ impl CliOptions { &self, config_type: TsConfigType, ) -> Result { - deno_config::get_ts_config_for_emit( + let result = deno_config::get_ts_config_for_emit( config_type, self.maybe_config_file.as_ref(), - ) + ); + + match result { + Ok(mut ts_config_for_emit) => { + if matches!(self.flags.subcommand, DenoSubcommand::Bundle(..)) { + // For backwards compatibility, force `experimentalDecorators` setting + // to true. + *ts_config_for_emit + .ts_config + .0 + .get_mut("experimentalDecorators") + .unwrap() = serde_json::Value::Bool(true); + } + Ok(ts_config_for_emit) + } + Err(err) => Err(err), + } } pub fn resolve_inspector_server(&self) -> Option { -- cgit v1.2.3