Files
oxc-project__oxc/tasks/coverage/misc/fail/oxc-13284.ts
overlookmotel 9fa551a6ce fix(semantic): handle edge cases checking super (#13499)
Fixes #13284.

Fix semantic's checking of `super()` and `super.prop`.

This fixes various TS test cases, notably correctly identifying that these are all illegal:

```js
class C {
  prop = function() { super.foo };
  [super.foo]() {}
  @super.foo method() {}
};
```

It also fixes various edge cases related to classes nested within other classes that aren't covered by existing conformance tests.

It's pretty much a complete re-write. I've combined the 2 paths for in a class and not in a class into one, to avoid repeated code.

This PR includes pass + fail test fixtures which include `super` in every conceivable position I could think of. There are so many errors in the fail test fixtures, that I had to write a script to check the snapshot includes them all!

Hopefully this solves this issue for once and for all!

Note: The large pass fixture seems to be revealing bugs somewhere in transformer - there's a mismatch, as well as lots of wrong scopes. But that's incidental to this PR, and can be addressed separately.
2025-09-10 03:23:41 +00:00

37 lines
745 B
TypeScript

// Not sure this is correct, but adding this test to make sure it doesn't panic at least.
// See comment in `check_super` in `oxc_semantic`.
// `super()`
class C extends Super {
[keys: string]: typeof import('x', { with: super() }).y;
}
class D extends Super {
[keys: typeof import('x', { with: super() }).y]: string;
}
class Outer extends Super {
constructor() {
class Inner {
[keys: string]: typeof import('x', { with: super() }).y;
}
}
}
class Outer2 {
constructor() {
class Inner extends Super {
[keys: typeof import('x', { with: super() }).y]: string;
}
}
}
// `super.foo`
class E {
[keys: typeof super.foo]: string;
}
class F {
[keys: typeof import('x', { with: super.foo }).y]: string;
}