Skip to content

Commit

Permalink
fix(es/codegen): Emit abstract keyword (#8479)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Jan 3, 2024
1 parent fed943f commit a12eaae
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 7 deletions.
5 changes: 5 additions & 0 deletions crates/swc_ecma_codegen/src/decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ where
}
}

if node.class.is_abstract {
keyword!(self, "abstract");
space!(self);
}

keyword!(self, "class");
space!(self);
emit!(self, node.ident);
Expand Down
10 changes: 10 additions & 0 deletions crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,11 @@ where
}
}

if n.is_abstract {
keyword!("abstract");
space!()
}

if n.is_override {
keyword!("override");
space!()
Expand Down Expand Up @@ -1608,6 +1613,11 @@ where
space!();
}

if n.is_abstract {
keyword!("abstract");
space!()
}

if n.is_override {
keyword!("override");
space!()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
abstract class A {
}
export abstract class B {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
abstract class A {
}
export abstract class B {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abstract class A{}export abstract class B{}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class MyClass extends Base {
public override method(param: number): string {
}
public abstract override log(msg: string): void;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class MyClass extends Base {
public override method(param: number): string {}
public abstract override log(msg: string): void;
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
class MyClass extends Base{public override method(param:number):string{}}
class MyClass extends Base{public override method(param:number):string{}public abstract override log(msg:string):void}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ class MyClass extends Base {
#prop4?: string = "test";
static readonly prop5!: string;
readonly #prop6 = "asdf";
public override readonly prop7 = 5;
public abstract override readonly prop7 = 5;
override readonly #prop8 = 5;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ class MyClass extends Base {
#prop4?: string = "test";
static readonly prop5!: string;
readonly #prop6 = "asdf";
public override readonly prop7 = 5;
public abstract override readonly prop7 = 5;
override readonly #prop8 = 5;
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
class MyClass extends Base{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";public override readonly prop7=5;override readonly #prop8=5}
class MyClass extends Base{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";public abstract override readonly prop7=5;override readonly #prop8=5}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
interface Mixin1__2 {
mixinMethod__0(): void;
}
class AbstractBase__2 {
abstractBaseMethod(): void;
abstract class AbstractBase__2 {
abstract abstractBaseMethod(): void;
}
function Mixin2__2<TBase__4 extends abstract new(...args: any[]) => any>(baseClass__4: TBase__4) {
class MixinClass__4 extends baseClass__4 implements Mixin1__2 {
abstract class MixinClass__4 extends baseClass__4 implements Mixin1__2 {
mixinMethod(): void {}
static staticMixinMethod(): void {}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/swc_ecma_transforms_typescript/src/strip_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,15 @@ impl VisitMut for StripType {
fn visit_mut_class_method(&mut self, n: &mut ClassMethod) {
n.accessibility = None;
n.is_override = false;
n.is_abstract = false;
n.visit_mut_children_with(self);
}

fn visit_mut_class_prop(&mut self, prop: &mut ClassProp) {
prop.readonly = false;
prop.is_override = false;
prop.is_optional = false;
prop.is_abstract = false;
prop.definite = false;
prop.accessibility = None;
prop.visit_mut_children_with(self);
Expand Down

0 comments on commit a12eaae

Please sign in to comment.