Webpack's removes classnames when minifying/uglifying ES6 code with inheritance
The problem in the given setup is not in the code of webpack or uglify but in this part of the code:
class Parent {
constructor() {
if (this.constructor.name === 'Parent') {
throw new TypeError("Parent class is abstract - cant be instance");
}
}
}
module.exports = Parent;
The this.constructor.name === 'Parent'
relays on the the class
/function
name, to test if Parent
was directly instanced.
Instead of relaying one the name which can result in various problems, it would be a better idea to test if the constructor equals the class.
class Parent {
constructor() {
if (this.constructor === Parent) {
throw new TypeError("Parent class is abstract - cant be instance");
}
}
}
module.exports = Parent;