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/tools/repl/session.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'cli/tools/repl') diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs index 3da862e7d..e98f4b430 100644 --- a/cli/tools/repl/session.rs +++ b/cli/tools/repl/session.rs @@ -184,6 +184,7 @@ pub struct ReplSession { /// This is only optional because it's temporarily taken when evaluating. test_event_receiver: Option>, jsx: ReplJsxState, + experimental_decorators: bool, } impl ReplSession { @@ -240,6 +241,11 @@ impl ReplSession { deno_core::resolve_path("./$deno$repl.ts", cli_options.initial_cwd()) .unwrap(); + let ts_config_for_emit = cli_options + .resolve_ts_config_for_emit(deno_config::TsConfigType::Emit)?; + let emit_options = + crate::args::ts_config_to_emit_options(ts_config_for_emit.ts_config); + let experimental_decorators = emit_options.use_ts_decorators; let mut repl_session = ReplSession { npm_resolver, resolver, @@ -260,6 +266,7 @@ impl ReplSession { frag_factory: "React.Fragment".to_string(), import_source: None, }, + experimental_decorators, }; // inject prelude @@ -596,10 +603,8 @@ impl ReplSession { let transpiled_src = parsed_source .transpile(&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: self.experimental_decorators, + use_decorators_proposal: !self.experimental_decorators, emit_metadata: false, source_map: false, inline_source_map: false, -- cgit v1.2.3