2015-06-15 15:17:04 +01:00

36 lines
817 B
JavaScript

import * as t from "../../../types";
export var metadata = {
group: "builtin-trailing"
};
function remap(path, key, create) {
// ensure that we're shadowed
if (!path.inShadow()) return;
var fnPath = path.findParent((path) => !path.is("shadow") && (path.isFunction() || path.isProgram()));
var cached = fnPath.getData(key);
if (cached) return cached;
var init = create();
var id = path.scope.generateUidIdentifier(key);
fnPath.setData(key, id);
fnPath.scope.push({ id, init });
return id;
}
export var visitor = {
ThisExpression() {
return remap(this, "this", () => t.thisExpression());
},
ReferencedIdentifier(node) {
if (node.name === "arguments" && !node._shadowedFunctionLiteral) {
return remap(this, "arguments", () => t.identifier("arguments"));
}
}
};