Files
babel/packages/babel-plugin-transform-es2015-parameters/src/index.js
Logan Smyth 14584c218c Kill the "shadow-functions.js" internal plugin in favor of an explicit helper (#5677)
* Handle arrow function processing via shared API rather than default plugin.

* Fix a few small PR comments.

* Preserve existing spec arrow 'this' rewrites, and support spec in subclass constructors.
2017-05-05 13:27:18 -07:00

28 lines
899 B
JavaScript

import type { NodePath } from "babel-traverse";
import { visitors } from "babel-traverse";
import * as destructuring from "./destructuring";
import * as def from "./default";
import * as rest from "./rest";
export default function () {
return {
visitor: visitors.merge([{
ArrowFunctionExpression(path) {
// In some conversion cases, it may have already been converted to a function while this callback
// was queued up.
if (!path.isArrowFunctionExpression()) return;
// default/rest visitors require access to `arguments`
const params: Array<NodePath> = path.get("params");
for (const param of params) {
if (param.isRestElement() || param.isAssignmentPattern()) {
path.arrowFunctionToExpression();
break;
}
}
},
}, destructuring.visitor, rest.visitor, def.visitor]),
};
}