removeClassCallCheck option
This commit is contained in:
parent
cce83a0cea
commit
4081f3e23e
@ -45,7 +45,7 @@ export default function ({ types: t }) {
|
||||
let Constructor = VanillaTransformer;
|
||||
if (state.opts.loose) Constructor = LooseTransformer;
|
||||
|
||||
path.replaceWith(new Constructor(path, state.file).run());
|
||||
path.replaceWith(new Constructor(path, state.file, state.opts).run());
|
||||
|
||||
if (path.isCallExpression() && path.get("callee").isArrowFunctionExpression()) {
|
||||
path.get("callee").arrowFunctionToExpression();
|
||||
|
||||
@ -66,7 +66,7 @@ const findThisesVisitor = visitors.merge([noMethodVisitor, {
|
||||
}]);
|
||||
|
||||
export default class ClassTransformer {
|
||||
constructor(path: NodePath, file) {
|
||||
constructor(path: NodePath, file, opts) {
|
||||
this.parent = path.parent;
|
||||
this.scope = path.scope;
|
||||
this.node = path.node;
|
||||
@ -86,6 +86,7 @@ export default class ClassTransformer {
|
||||
this.pushedConstructor = false;
|
||||
this.pushedInherits = false;
|
||||
this.isLoose = false;
|
||||
this.removeClassCallCheck = opts.removeClassCallCheck;
|
||||
|
||||
this.superThises = [];
|
||||
|
||||
@ -129,12 +130,14 @@ export default class ClassTransformer {
|
||||
this.buildBody();
|
||||
|
||||
// make sure this class isn't directly called
|
||||
if (!this.removeClassCallCheck) {
|
||||
constructorBody.body.unshift(t.expressionStatement(t.callExpression(
|
||||
file.addHelper("classCallCheck"), [
|
||||
t.thisExpression(),
|
||||
this.classRef,
|
||||
]
|
||||
)));
|
||||
}
|
||||
|
||||
body = body.concat(this.staticPropBody.map((fn) => fn(this.classRef)));
|
||||
|
||||
|
||||
@ -0,0 +1 @@
|
||||
class A {}
|
||||
@ -0,0 +1 @@
|
||||
let A = function A() {};
|
||||
@ -0,0 +1,8 @@
|
||||
{
|
||||
"plugins": [
|
||||
["transform-es2015-classes", {
|
||||
"removeClassCallCheck": true,
|
||||
"loose": true
|
||||
}]
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
class A {
|
||||
constructor() {
|
||||
console.log('a');
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
b() {
|
||||
console.log('b');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
let A = function A() {
|
||||
console.log('a');
|
||||
};
|
||||
|
||||
let B = function () {
|
||||
function B() {}
|
||||
|
||||
B.prototype.b = function b() {
|
||||
console.log('b');
|
||||
};
|
||||
|
||||
return B;
|
||||
}();
|
||||
Loading…
x
Reference in New Issue
Block a user