Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
enter(path) {
if (path.isProgram()) {
return;
}
if (hasEval(path.scope)) {
return;
}
const { scope } = path;
// if the scope is created by a function, we obtain its
// parameter list
const canRemoveParams = path.isFunction() && path.node.kind !== "set";
const paramsList = canRemoveParams ? path.get("params") : [];
for (let i = paramsList.length - 1; i >= 0; i--) {
const param = paramsList[i];
if (param.isIdentifier()) {
const binding = scope.bindings[param.node.name];
if (!binding) continue;
mangleScope(scope) {
const mangler = this;
const { scopeTracker } = mangler;
// Unsafe Scope
if (!mangler.eval && hasEval(scope)) {
return;
}
// Already visited
// This is because for a function, in Babel, the function and
// the function body's BlockStatement has the same scope, and will
// be visited twice by the Scopable handler, and we want to mangle
// it only once
if (mangler.visitedScopes.has(scope)) {
return;
}
mangler.visitedScopes.add(scope);
const bindings = scopeTracker.bindings.get(scope);
const names = [...bindings.keys()];
enter(path) {
if (path.isProgram()) {
return;
}
if (hasEval(path.scope)) {
return;
}
const { scope } = path;
// if the scope is created by a function, we obtain its
// parameter list
const canRemoveParams = path.isFunction() && path.node.kind !== "set";
const paramsList = canRemoveParams ? path.get("params") : [];
for (let i = paramsList.length - 1; i >= 0; i--) {
const param = paramsList[i];
if (param.isIdentifier()) {
const binding = scope.bindings[param.node.name];
if (!binding)
continue;
if (binding.referenced) {
// when the first binding is referenced (right to left)
// exit without marking anything after this