Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/codegen): Fix codegen of ts specific syntax in class props #8426

Merged
merged 4 commits into from
Dec 17, 2023
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
9 changes: 9 additions & 0 deletions crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,12 @@ where

emit!(n.key);
if let Some(type_ann) = &n.type_ann {
if n.is_optional {
punct!("?");
}
if n.definite {
punct!("!");
}
punct!(":");
space!();
emit!(type_ann);
Expand Down Expand Up @@ -1583,6 +1589,9 @@ where
emit!(n.key);

if let Some(ty) = &n.type_ann {
if n.definite {
punct!("!");
}
punct!(":");
space!();
emit!(ty);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class MyClass {
prop1?: string;
prop2!: string;
#prop3?: string;
#prop4?: string = "test";
static readonly prop5!: string;
readonly #prop6 = "asdf";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class MyClass {
prop1?: string;
prop2!: string;
#prop3?: string;
#prop4?: string = "test";
static readonly prop5!: string;
readonly #prop6 = "asdf";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class MyClass{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf"}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ enum MyEnum {
y = "yyy"
}
class Xpto {
value: MyEnum;
value!: MyEnum;
}
_ts_decorate([
Decorator(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class User {
currency: "usd" | "eur" | "yen";
currency!: "usd" | "eur" | "yen";
}
_ts_decorate([
column(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export class Product extends TimestampedEntity {
id: string;
price: number;
type: ProductType;
productEntityId: string;
/* ANCHOR: Relations ------------------------------------------------------ */ orders: Order[];
discounts: Discount[];
id!: string;
price!: number;
type!: ProductType;
productEntityId!: string;
/* ANCHOR: Relations ------------------------------------------------------ */ orders!: Order[];
discounts!: Discount[];
}
_ts_decorate([
PrimaryGeneratedColumn("uuid")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class Product extends TimestampedEntity {
id: string;
id!: string;
}
_ts_decorate([
PrimaryGeneratedColumn("uuid")
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 @@ -144,6 +144,7 @@ impl VisitMut for StripType {
prop.readonly = false;
prop.is_override = false;
prop.is_optional = false;
prop.definite = false;
prop.accessibility = None;
prop.visit_mut_children_with(self);
}
Expand All @@ -152,6 +153,7 @@ impl VisitMut for StripType {
prop.readonly = false;
prop.is_override = false;
prop.is_optional = false;
prop.definite = false;
prop.accessibility = None;
prop.visit_mut_children_with(self);
}
Expand Down
Loading