mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(codegen): only print necessary parentheses in TSAsExpression (#6429)
Part of fixing #6385
This commit is contained in:
parent
7458089e3c
commit
702b574afb
3 changed files with 27 additions and 9 deletions
|
|
@ -2092,13 +2092,13 @@ impl<'a> GenExpr for NewExpression<'a> {
|
||||||
|
|
||||||
impl<'a> GenExpr for TSAsExpression<'a> {
|
impl<'a> GenExpr for TSAsExpression<'a> {
|
||||||
fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) {
|
fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) {
|
||||||
p.print_char(b'(');
|
let wrap = precedence >= Precedence::Shift;
|
||||||
p.print_char(b'(');
|
|
||||||
self.expression.print_expr(p, precedence, Context::default());
|
p.wrap(wrap, |p| {
|
||||||
p.print_char(b')');
|
self.expression.print_expr(p, Precedence::Exponentiation, ctx);
|
||||||
p.print_str(" as ");
|
p.print_str(" as ");
|
||||||
self.type_annotation.print(p, ctx);
|
self.type_annotation.print(p, ctx);
|
||||||
p.print_char(b')');
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@ a = x!;
|
||||||
########## 25
|
########## 25
|
||||||
b = (x as y);
|
b = (x as y);
|
||||||
----------
|
----------
|
||||||
b = ((x) as y);
|
b = x as y;
|
||||||
|
|
||||||
########## 26
|
########## 26
|
||||||
c = foo<string>;
|
c = foo<string>;
|
||||||
|
|
@ -210,3 +210,18 @@ export type Component<
|
||||||
E extends EmitsOptions | Record<string, any[]> = {},
|
E extends EmitsOptions | Record<string, any[]> = {},
|
||||||
S extends Record<string, any> = any
|
S extends Record<string, any> = any
|
||||||
> = ConcreteComponent<Props, RawBindings, D, C, M, E, S> | ComponentPublicInstanceConstructor<Props>;
|
> = ConcreteComponent<Props, RawBindings, D, C, M, E, S> | ComponentPublicInstanceConstructor<Props>;
|
||||||
|
|
||||||
|
########## 32
|
||||||
|
(a || b) as any
|
||||||
|
----------
|
||||||
|
(a || b) as any;
|
||||||
|
|
||||||
|
########## 33
|
||||||
|
(a ** b) as any
|
||||||
|
----------
|
||||||
|
(a ** b) as any;
|
||||||
|
|
||||||
|
########## 34
|
||||||
|
(function g() {}) as any
|
||||||
|
----------
|
||||||
|
(function g() {}) as any;
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,10 @@ export type Component<
|
||||||
> =
|
> =
|
||||||
| ConcreteComponent<Props, RawBindings, D, C, M, E, S>
|
| ConcreteComponent<Props, RawBindings, D, C, M, E, S>
|
||||||
| ComponentPublicInstanceConstructor<Props>
|
| ComponentPublicInstanceConstructor<Props>
|
||||||
"
|
",
|
||||||
|
"(a || b) as any",
|
||||||
|
"(a ** b) as any",
|
||||||
|
"(function g() {}) as any",
|
||||||
];
|
];
|
||||||
|
|
||||||
snapshot("ts", &cases);
|
snapshot("ts", &cases);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue