Skip to content

Commit 5d219b8

Browse files
authored
fix(es/codegen): Fix codegen of classes with minify enabled (#1767)
1 parent 65ffd87 commit 5d219b8

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

ecmascript/codegen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
77
license = "Apache-2.0/MIT"
88
name = "swc_ecma_codegen"
99
repository = "https://github.com/swc-project/swc.git"
10-
version = "0.55.3"
10+
version = "0.55.4"
1111

1212
[dependencies]
1313
bitflags = "1"

ecmascript/codegen/src/decl.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ impl<'a> Emitter<'a> {
3737
space!();
3838
emit!(node.ident);
3939
emit!(node.class.type_params);
40-
formatting_space!();
4140

4241
self.emit_class_trailing(&node.class)?;
4342
}
@@ -117,6 +116,15 @@ mod tests {
117116
);
118117
}
119118

119+
#[test]
120+
fn issue_1764() {
121+
assert_min(
122+
"class Hoge {};
123+
class HogeFuga extends Hoge {};",
124+
"class Hoge{};class HogeFuga extends Hoge{};",
125+
);
126+
}
127+
120128
#[test]
121129
fn single_argument_arrow_expression() {
122130
assert_min("function* f(){ yield x => x}", "function*f(){yield x=>x}");

ecmascript/codegen/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,6 @@ impl<'a> Emitter<'a> {
823823
space!();
824824
emit!(i);
825825
emit!(node.class.type_params);
826-
827-
formatting_space!();
828-
} else {
829-
space!();
830826
}
831827

832828
self.emit_class_trailing(&node.class)?;
@@ -835,12 +831,13 @@ impl<'a> Emitter<'a> {
835831
#[emitter]
836832
fn emit_class_trailing(&mut self, node: &Class) -> Result {
837833
if node.super_class.is_some() {
834+
space!();
838835
keyword!("extends");
839836
space!();
840837
emit!(node.super_class);
841-
space!();
842838
}
843839

840+
formatting_space!();
844841
punct!("{");
845842
self.emit_list(node.span, Some(&node.body), ListFormat::ClassMembers)?;
846843
punct!("}");

0 commit comments

Comments
 (0)