Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2269,20 +2269,13 @@ impl GenExpr for TSAsExpression<'_> {

impl GenExpr for TSSatisfiesExpression<'_> {
fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) {
p.print_ascii_byte(b'(');
let should_wrap =
if let Expression::FunctionExpression(func) = &self.expression.without_parentheses() {
// pife is handled on Function side
!func.pife
} else {
true
};
p.wrap(should_wrap, |p| {
self.expression.print_expr(p, precedence, Context::default());
let wrap = precedence >= Precedence::Compare;

p.wrap(wrap, |p| {
self.expression.print_expr(p, Precedence::Exponentiation, ctx);
p.print_str(" satisfies ");
self.type_annotation.print(p, ctx);
});
p.print_str(" satisfies ");
self.type_annotation.print(p, ctx);
p.print_ascii_byte(b')');
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/tests/integration/snapshots/minify.snap
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ new Map<string,number>;
########## 32
d = x satisfies y;
----------
d=((x) satisfies y);
d=x satisfies y;
########## 33
export @x declare abstract class C {}
----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ const Foo = (/* @__PURE__ */ (() => {})() as unknown) as {
########## 27
const Foo = /* @__PURE__ */ (() => {})() satisfies X
----------
const Foo = ((/* @__PURE__ */ (() => {})()) satisfies X);
const Foo = /* @__PURE__ */ (() => {})() satisfies X;

########## 28
const Foo = /* @__PURE__ */ (() => {})()<X>
Expand All @@ -466,7 +466,7 @@ const Foo = (<Foo>(/* @__PURE__ */ (() => {})())!);
########## 30
const Foo = /* @__PURE__ */ <Foo>(() => {})()! as X satisfies Y
----------
const Foo = (((<Foo>(/* @__PURE__ */ (() => {})())!) as X) satisfies Y);
const Foo = ((<Foo>(/* @__PURE__ */ (() => {})())!) as X) satisfies Y;

########## 31
/* @__NO_SIDE_EFFECTS__ */ ((options, extraOptions) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/tests/integration/snapshots/ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ new Map<string, number>();
########## 32
d = x satisfies y;
----------
d = ((x) satisfies y);
d = x satisfies y;

########## 33
export @x declare abstract class C {}
Expand Down
13 changes: 13 additions & 0 deletions crates/oxc_codegen/tests/integration/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,16 @@ fn ts_as_expression_in_binary_expr() {
"!(typeof that === 'object' && 'keys' in that && typeof (that as object & { keys: unknown }).keys === 'function')",
);
}

#[test]
fn ts_satisfies_expression() {
test_idempotency("d = x satisfies y");
test_idempotency("const Foo = (() => {})() satisfies X");
test_idempotency("const Bar = (x as Y) satisfies Z");
test_idempotency("(x satisfies Y).foo");
test_idempotency("(x satisfies Y)[0]");
test_idempotency("(x satisfies Y)()");
test_idempotency("x satisfies Y || z");
test_idempotency("x satisfies Y && z");
test_idempotency("x satisfies Y === z");
}
Loading