static private field exists before it is actually defined
Author: sapphi-redCreated Sep 30, 2026Updated Sep 30, 2026
Labelsi: needs triage
- Would you like to work on a fix?
How are you using Babel?
Programmatic API (babel.transform, babel.parse)
Input code
class Foo {
static { console.log(#b in this) }
static #b = 0;
static { console.log(#b in this) }
}Configuration file name
No response
Configuration
{
"filename": "repl.js",
"presets": [
[
"env",
{
"targets": "chrome 80",
"modules": false
}
]
],
"sourceType": "module"
}Current and expected behavior
The output is
var _Foo;
function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null")); return e; }
class Foo {}
_Foo = Foo;
console.log(_checkInRHS(_Foo) === _Foo);
var _b = {
_: 0
};
console.log(_checkInRHS(_Foo) === _Foo);This outputs true\true, but when running the input code directly it outputs false\ntrue.
Environment
Found it on REPL
Possible solution
No response
Additional context
This is not a real world code I encounted. I found it while trying some code on REPL.
Source: babel/babel