Skip to content
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
32 changes: 27 additions & 5 deletions crates/oxc_isolated_declarations/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,30 @@ impl<'a> IsolatedDeclarations<'a> {
}
}

pub(crate) fn report_property_key(&self, key: &PropertyKey<'a>, computed: bool) -> bool {
if computed && !self.is_literal_key(key) {
/// Check the property key whether it is a `Symbol.iterator` or `global.Symbol.iterator`
pub(crate) fn is_global_symbol(key: &PropertyKey<'a>) -> bool {
let PropertyKey::StaticMemberExpression(member) = key else {
return false;
};

// TODO: Unsupported checking if it is a global Symbol yet
match &member.object {
// `Symbol.iterator`
Expression::Identifier(ident) => ident.name == "Symbol",
// `global.Symbol.iterator`
Expression::StaticMemberExpression(expr) => {
expr.property.name == "Symbol"
&& matches!(
&expr.object, Expression::Identifier(ident)
if matches!(ident.name.as_str(), "window" | "globalThis")
)
}
_ => false,
}
}

pub(crate) fn report_property_key(&self, key: &PropertyKey<'a>) -> bool {
if !self.is_literal_key(key) && !Self::is_global_symbol(key) {
self.error(computed_property_name(key.span()));
true
} else {
Expand Down Expand Up @@ -367,7 +389,7 @@ impl<'a> IsolatedDeclarations<'a> {
has_private_key = true;
continue;
}
if self.report_property_key(&method.key, method.computed) {
if method.computed && self.report_property_key(&method.key) {
continue;
}

Expand Down Expand Up @@ -462,7 +484,7 @@ impl<'a> IsolatedDeclarations<'a> {
continue;
}

if self.report_property_key(&property.key, property.computed) {
if property.computed && self.report_property_key(&property.key) {
continue;
}

Expand All @@ -477,7 +499,7 @@ impl<'a> IsolatedDeclarations<'a> {
continue;
}

if self.report_property_key(&property.key, property.computed) {
if property.computed && self.report_property_key(&property.key) {
return None;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_isolated_declarations/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<'a> IsolatedDeclarations<'a> {
let members =
self.ast.vec_from_iter(expr.properties.iter().filter_map(|property| match property {
ObjectPropertyKind::ObjectProperty(object) => {
if self.report_property_key(&object.key, object.computed) {
if object.computed && self.report_property_key(&object.key) {
return None;
}

Expand Down
40 changes: 4 additions & 36 deletions tasks/coverage/snapshots/transpile.snap
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ export interface B {
[Math.random() > .5 ? "f1" : "f2"]: number;
}
export declare class C {
[Symbol.iterator]: number;
[globalThis.Symbol.toStringTag]: number;
[1]: number;
["2"]: number;
}
export declare const D: {
Symbol.iterator: number;
globalThis.Symbol.toStringTag: number;
1: number;
"2": number;
};
Expand Down Expand Up @@ -195,24 +199,6 @@ export {};
39 | [Symbol.iterator]: number = 1;
`----

x TS9038: Computed property names on class or object literals cannot be
| inferred with --isolatedDeclarations.
,-[declarationComputedPropertyNames.d.ts:39:6]
38 | [presentNs.a]: number = 1;
39 | [Symbol.iterator]: number = 1;
: ^^^^^^^^^^^^^^^
40 | [globalThis.Symbol.toStringTag]: number = 1;
`----

x TS9038: Computed property names on class or object literals cannot be
| inferred with --isolatedDeclarations.
,-[declarationComputedPropertyNames.d.ts:40:6]
39 | [Symbol.iterator]: number = 1;
40 | [globalThis.Symbol.toStringTag]: number = 1;
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41 | [(globalThis.Symbol).unscopables]: number = 1;
`----

x TS9038: Computed property names on class or object literals cannot be
| inferred with --isolatedDeclarations.
,-[declarationComputedPropertyNames.d.ts:41:6]
Expand Down Expand Up @@ -276,24 +262,6 @@ export {};
53 | [Symbol.iterator]: 1,
`----

x TS9038: Computed property names on class or object literals cannot be
| inferred with --isolatedDeclarations.
,-[declarationComputedPropertyNames.d.ts:53:6]
52 | [presentNs.a]: 1,
53 | [Symbol.iterator]: 1,
: ^^^^^^^^^^^^^^^
54 | [globalThis.Symbol.toStringTag]: 1,
`----

x TS9038: Computed property names on class or object literals cannot be
| inferred with --isolatedDeclarations.
,-[declarationComputedPropertyNames.d.ts:54:6]
53 | [Symbol.iterator]: 1,
54 | [globalThis.Symbol.toStringTag]: 1,
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55 | [(globalThis.Symbol).unscopables]: 1,
`----

x TS9038: Computed property names on class or object literals cannot be
| inferred with --isolatedDeclarations.
,-[declarationComputedPropertyNames.d.ts:55:6]
Expand Down
Loading