Skip to content

Commit

Permalink
feat(codegen): minify yield "s" -> yield"s" (#8084)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Dec 24, 2024
1 parent f8f067b commit 414c118
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 1 addition & 3 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1807,9 +1807,7 @@ impl GenExpr for YieldExpression<'_> {
p.print_soft_space();
}
if let Some(argument) = self.argument.as_ref() {
if !self.delegate {
p.print_hard_space();
}
p.print_soft_space();
argument.print_expr(p, Precedence::Yield, Context::empty());
}
});
Expand Down
7 changes: 3 additions & 4 deletions crates/oxc_codegen/tests/integration/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,13 @@ fn r#yield() {
test_minify("function *foo() { yield * async () => {} }", "function*foo(){yield*async()=>{}}");
test_minify("function *foo() { yield a ? b : c }", "function*foo(){yield a?b:c}");
test_minify("function *foo() { yield yield a }", "function*foo(){yield yield a}");
test_minify("function *foo() { yield () => {} }", "function*foo(){yield ()=>{}}");
test_minify("function *foo() { yield () => {} }", "function*foo(){yield()=>{}}");
test_minify("function *foo() { yield async () => {} }", "function*foo(){yield async()=>{}}");
test_minify(
"function *foo() { yield { a } = [ b ] = c ? b : d }",
"function*foo(){yield {a}=[b]=c?b:d}",
"function*foo(){yield{a}=[b]=c?b:d}",
);
// TODO: remove the extra space in `yield (a,b)`
test_minify("function *foo() { yield (a, b) }", "function*foo(){yield (a,b)}");
test_minify("function *foo() { yield (a, b) }", "function*foo(){yield(a,b)}");
test_minify("function *foo() { yield a, b }", "function*foo(){yield a,b}");
}

Expand Down

0 comments on commit 414c118

Please sign in to comment.