feat(codegen): minify yield "s" -> yield"s" (#8084)

This commit is contained in:
Boshen 2024-12-24 00:41:28 +00:00
parent f8f067bfc6
commit 414c118309
2 changed files with 4 additions and 7 deletions

View file

@ -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());
}
});

View file

@ -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}");
}