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

**Description:**

This fixes the codegen of private properties with `is_optional` or `definite` and class properties with `definite`.
This commit is contained in:
David Sherret 2023-12-17 07:47:20 +01:00 committed by GitHub
parent 4bd15908c1
commit 7566ddf0b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 37 additions and 9 deletions

View File

@ -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);
@ -1583,6 +1589,9 @@ where
emit!(n.key);
if let Some(ty) = &n.type_ann {
if n.definite {
punct!("!");
}
punct!(":");
space!();
emit!(ty);

View File

@ -0,0 +1,8 @@
class MyClass {
prop1?: string;
prop2!: string;
#prop3?: string;
#prop4?: string = "test";
static readonly prop5!: string;
readonly #prop6 = "asdf";
}

View File

@ -0,0 +1,8 @@
class MyClass {
prop1?: string;
prop2!: string;
#prop3?: string;
#prop4?: string = "test";
static readonly prop5!: string;
readonly #prop6 = "asdf";
}

View File

@ -0,0 +1 @@
class MyClass{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf"}

View File

@ -3,7 +3,7 @@ enum MyEnum {
y = "yyy"
}
class Xpto {
value: MyEnum;
value!: MyEnum;
}
_ts_decorate([
Decorator(),

View File

@ -1,5 +1,5 @@
class User {
currency: "usd" | "eur" | "yen";
currency!: "usd" | "eur" | "yen";
}
_ts_decorate([
column(),

View File

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

View File

@ -1,5 +1,5 @@
export class Product extends TimestampedEntity {
id: string;
id!: string;
}
_ts_decorate([
PrimaryGeneratedColumn("uuid")

View File

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