removeClassCallCheck option

This commit is contained in:
Henry Zhu
2016-11-16 09:42:08 -05:00
parent cce83a0cea
commit 4081f3e23e
7 changed files with 39 additions and 2 deletions

View File

@@ -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();

View File

@@ -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)));