Skip to content

@studnicky/v8/computed-class-properties

Disallows computed property keys in class bodies (class Foo { [key]() {} }). Computed keys force a hidden-class transition on every instantiation because V8 cannot statically determine the property layout at parse time.

Fixable: No · Options: No · Suggested severity: error

✗ Incorrect

ts
class Foo {
  [Symbol.iterator]() { return this; }
  [Symbol.toPrimitive]() { return 0; }
}
ts
const key = 'dynamic';
class Bar {
  [key]() { return true; }
}

✓ Correct

ts
// Use string-keyed methods
class Foo {
  toValue() { return 0; }
  iterate() { return this; }
}
ts
// Add well-known symbol methods via a separate Object.assign if needed
class Bar {
  getValue() { return true; }
}