Bogdan Savluk 4108524856
Update prettier to v2 (#11579)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2020-06-07 22:21:33 +02:00

24 lines
625 B
JavaScript

import syntaxOptionalCatchBinding from "@babel/plugin-syntax-optional-catch-binding";
export default function ({ types: t }) {
return {
inherits: syntaxOptionalCatchBinding,
visitor: {
CatchClause(path) {
if (path.node.param === null || !t.isIdentifier(path.node.param)) {
return;
}
const binding = path.scope.getOwnBinding(path.node.param.name);
if (binding.constantViolations.length > 0) {
return;
}
if (!binding.referenced) {
const paramPath = path.get("param");
paramPath.remove();
}
},
},
};
}