fix(es/codegen): Emit ? for an optional computed property (#8481)

**Description:**

Emits optional `?` for a computed property.
This commit is contained in:
David Sherret 2024-01-03 23:48:07 -05:00 committed by GitHub
parent 8997ed1547
commit e0bdc0f7c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 4 deletions

View File

@ -1566,10 +1566,12 @@ where
}
emit!(n.key);
if n.is_optional {
punct!("?");
}
if let Some(type_ann) = &n.type_ann {
if n.is_optional {
punct!("?");
}
if n.definite {
punct!("!");
}
@ -1635,6 +1637,12 @@ where
emit!(n.key);
// emit for a computed property, but not an identifier already marked as
// optional
if n.is_optional && !n.key.as_ident().map(|i| i.optional).unwrap_or(false) {
punct!("?");
}
if let Some(ty) = &n.type_ann {
if n.definite {
punct!("!");

View File

@ -3,9 +3,11 @@ class MyClass extends Base {
prop2!: string;
#prop3?: string;
#prop4?: string = "test";
#privateOptionalNoType?;
static readonly prop5!: string;
readonly #prop6 = "asdf";
public abstract override readonly prop7 = 5;
override readonly #prop8 = 5;
declare public static readonly prop9: string;
[value]?: string[];
}

View File

@ -3,9 +3,11 @@ class MyClass extends Base {
prop2!: string;
#prop3?: string;
#prop4?: string = "test";
#privateOptionalNoType?;
static readonly prop5!: string;
readonly #prop6 = "asdf";
public abstract override readonly prop7 = 5;
override readonly #prop8 = 5;
declare public static readonly prop9: string;
[value]?: string[];
}

View File

@ -1 +1 @@
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;declare public static readonly prop9: string}
class MyClass extends Base{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";#privateOptionalNoType?;static readonly prop5!: string;readonly #prop6="asdf";public abstract override readonly prop7=5;override readonly #prop8=5;declare public static readonly prop9: string;[value]?: string[]}