From f210cf7873ab479474eae6611fb5ac74650c30a8 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Fri, 16 Aug 2024 09:53:17 +0000 Subject: [PATCH] fix(codegen): print `TSSatisfiesExpression` and `TSInstantiationExpression` (#4936) I can't figure out the precedence so printing extra parentheses instead ... --- crates/oxc_codegen/src/gen.rs | 16 ++++++++++++---- .../tests/integration/snapshots/ts.snap | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 4ccab3952e913..fb4ff8e08d4df 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -2098,7 +2098,7 @@ impl<'a, const MINIFY: bool> GenExpr for TSAsExpression<'a> { fn gen_expr(&self, p: &mut Codegen<{ MINIFY }>, precedence: Precedence, ctx: Context) { p.print_char(b'('); p.print_char(b'('); - self.expression.gen_expr(p, precedence, ctx); + self.expression.gen_expr(p, precedence, Context::default()); p.print_char(b')'); p.print_str(" as "); self.type_annotation.gen(p, ctx); @@ -2108,8 +2108,13 @@ impl<'a, const MINIFY: bool> GenExpr for TSAsExpression<'a> { impl<'a, const MINIFY: bool> GenExpr for TSSatisfiesExpression<'a> { fn gen_expr(&self, p: &mut Codegen<{ MINIFY }>, precedence: Precedence, ctx: Context) { - // TODO: print properly - self.expression.gen_expr(p, precedence, ctx); + p.print_char(b'('); + p.print_char(b'('); + self.expression.gen_expr(p, precedence, Context::default()); + p.print_char(b')'); + p.print_str(" satisfies "); + self.type_annotation.gen(p, ctx); + p.print_char(b')'); } } @@ -2127,8 +2132,11 @@ impl<'a, const MINIFY: bool> GenExpr for TSNonNullExpression<'a> { impl<'a, const MINIFY: bool> GenExpr for TSInstantiationExpression<'a> { fn gen_expr(&self, p: &mut Codegen<{ MINIFY }>, precedence: Precedence, ctx: Context) { - // TODO: print properly self.expression.gen_expr(p, precedence, ctx); + self.type_parameters.gen(p, ctx); + if MINIFY { + p.print_hard_space(); + } } } diff --git a/crates/oxc_codegen/tests/integration/snapshots/ts.snap b/crates/oxc_codegen/tests/integration/snapshots/ts.snap index fdda8c3fe8830..a4eaa09690546 100644 --- a/crates/oxc_codegen/tests/integration/snapshots/ts.snap +++ b/crates/oxc_codegen/tests/integration/snapshots/ts.snap @@ -102,7 +102,7 @@ b = (x as y); b = ((x) as y); c = foo; -c = foo; +c = foo; d = x satisfies y; -d = x; +d = ((x) satisfies y);