mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 09:38:16 +03:00
fix(es/codegen): Emit ?
for an optional computed property (#8481)
**Description:** Emits optional `?` for a computed property.
This commit is contained in:
parent
8997ed1547
commit
e0bdc0f7c2
@ -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!("!");
|
||||
|
@ -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[];
|
||||
}
|
||||
|
@ -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[];
|
||||
}
|
||||
|
@ -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[]}
|
||||
|
Loading…
Reference in New Issue
Block a user