Any property declared in a class with # prefix is treated as private property. But there is no private properties concept in Javascript by design. However, we can mimic private properties by defining them outside the function and then using them inside the function. This way those properties are not accessible outside the module unless we export. So, the transpiled version for the above code will be like this.
var _a = /*#__PURE__*/new WeakMap();
var A = function A() {
_classCallCheck(this, A);
_a.set(this, {
writable: true,
value: 1
});
};
As you can see the #a variable is transformed as _a and declared outside the function as WeakMap and being used inside the function.
So if you have another static property with the same name #a
it tries to create another variable outside the function with the same name _a. Since it is private static property it will not be attached to the function. So the transpiled code will look like this.
var _a = /*#__PURE__*/new WeakMap();
var A = function A() {
_classCallCheck(this, A);
_a.set(this, {
writable: true,
value: 1
});
};
var _a = {
writable: true,
value: 2
};
So as you can see it tries to create another variable with the same name and throws the error. This is the limitation of the javascript and can be easily avoided by giving a different name obviously.
The later case is valid because they are not private properties.