Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function () {
return {
visitor: visitors.merge([{
ArrowFunctionExpression(path) {
// default/rest visitors require access to `arguments`
let params = path.get("params");
for (let param of params) {
if (param.isRestElement() || param.isAssignmentPattern()) {
path.arrowFunctionToShadowed();
break;
}
}
}
}, destructuring.visitor, rest.visitor, def.visitor])
};
}
})
`);
let noMethodVisitor = {
"FunctionExpression|FunctionDeclaration"(path) {
if (!path.is("shadow")) {
path.skip();
}
},
Method(path) {
path.skip();
}
};
let verifyConstructorVisitor = visitors.merge([noMethodVisitor, {
Super(path) {
if (this.isDerived && !this.hasBareSuper && !path.parentPath.isCallExpression({ callee: path.node })) {
throw path.buildCodeFrameError("'super.*' is not allowed before super()");
}
},
CallExpression: {
exit(path) {
if (path.get("callee").isSuper()) {
this.hasBareSuper = true;
if (!this.isDerived) {
throw path.buildCodeFrameError("super() is only allowed in a derived constructor");
}
}
}
throw path.buildCodeFrameError("super() is only allowed in a derived constructor");
}
}
}
},
ThisExpression(path) {
if (this.isDerived && !this.hasBareSuper) {
if (!path.inShadow("this")) {
throw path.buildCodeFrameError("'this' is not allowed before super()");
}
}
}
}]);
let findThisesVisitor = visitors.merge([noMethodVisitor, {
ThisExpression(path) {
this.superThises.push(path);
}
}]);
export default class ClassTransformer {
constructor(path, file) {
this.parent = path.parent;
this.scope = path.scope;
this.node = path.node;
this.path = path;
this.file = file;
this.clearDescriptors();
this.instancePropBody = [];
import { visitors } from "babel-traverse";
import * as def from "./default";
import * as rest from "./rest";
export let metadata = {
group: "builtin-advanced"
};
export let visitor = visitors.merge([rest.visitor, def.visitor]);