change obj references to a unique identifier
This commit is contained in:
parent
4c2e7ddb9e
commit
0f7da020e3
@ -1,3 +1,3 @@
|
||||
(function (obj) {
|
||||
return obj;
|
||||
(function (KEY) {
|
||||
return KEY;
|
||||
}).call(this, OBJECT)
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
(function (obj) {
|
||||
return obj;
|
||||
(function (KEY) {
|
||||
return KEY;
|
||||
})(OBJECT)
|
||||
|
||||
@ -1 +1 @@
|
||||
obj[KEY] = VALUE;
|
||||
OBJECT_KEY[KEY] = VALUE;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
(function (obj) {
|
||||
(function (KEY) {
|
||||
CONTENT;
|
||||
return obj;
|
||||
return KEY;
|
||||
})(OBJECT);
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
var traverse = require("../traverse");
|
||||
var util = require("../util");
|
||||
var b = require("ast-types").builders;
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.ObjectExpression = function (node) {
|
||||
exports.ObjectExpression = function (node, parent, opts, generateUid) {
|
||||
var hasComputed = false;
|
||||
var hasThis = false;
|
||||
|
||||
@ -24,7 +25,10 @@ exports.ObjectExpression = function (node) {
|
||||
var templateName = "function-return-obj";
|
||||
if (hasThis) templateName += "-this";
|
||||
|
||||
var objId = b.identifier(generateUid("ref"));
|
||||
|
||||
var container = util.template(templateName, {
|
||||
KEY: objId,
|
||||
OBJECT: node
|
||||
});
|
||||
|
||||
@ -37,6 +41,7 @@ exports.ObjectExpression = function (node) {
|
||||
|
||||
_.each(computed, function (prop) {
|
||||
containerBody.unshift(util.template("obj-key-set", {
|
||||
OBJECT_KEY: objId,
|
||||
KEY: prop.key,
|
||||
VALUE: prop.value
|
||||
}, true));
|
||||
|
||||
@ -22,7 +22,7 @@ exports.ForOfStatement = function (node, parent, opts, generateUid) {
|
||||
util.ensureBlock(node);
|
||||
|
||||
var block = node2.body;
|
||||
block.body = block.body.concat(node.body.body || []);
|
||||
block.body = block.body.concat(node.body.body);
|
||||
|
||||
var declar = block.body[0];
|
||||
declar.kind = declar.kind;
|
||||
|
||||
@ -6,7 +6,7 @@ exports.Property = function (node) {
|
||||
if (node.method) node.method = false;
|
||||
};
|
||||
|
||||
exports.ObjectExpression = function (node) {
|
||||
exports.ObjectExpression = function (node, parent, opts, generateUid) {
|
||||
var mutatorMap = {};
|
||||
|
||||
node.properties = node.properties.filter(function (prop) {
|
||||
@ -20,8 +20,11 @@ exports.ObjectExpression = function (node) {
|
||||
|
||||
if (_.isEmpty(mutatorMap)) return;
|
||||
|
||||
var objId = b.identifier(generateUid("ref"))
|
||||
|
||||
return util.template("object-define-properties-closure", {
|
||||
KEY: objId,
|
||||
OBJECT: node,
|
||||
CONTENT: util.buildDefineProperties(mutatorMap, b.identifier("obj")).expression
|
||||
CONTENT: util.buildDefineProperties(mutatorMap, objId).expression
|
||||
});
|
||||
};
|
||||
|
||||
@ -11,7 +11,9 @@ var traverse = module.exports = function (parent, callbacks, blacklistTypes) {
|
||||
return;
|
||||
}
|
||||
|
||||
var keys = VISITOR_KEYS[parent.type] || [];
|
||||
var keys = VISITOR_KEYS[parent.type];
|
||||
if (!keys) return;
|
||||
|
||||
blacklistTypes = blacklistTypes || [];
|
||||
|
||||
if (_.isFunction(callbacks)) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
var obj = function (obj) {
|
||||
obj[foobar] = function () {
|
||||
var obj = function (_ref) {
|
||||
_ref[foobar] = function () {
|
||||
return "foobar";
|
||||
};
|
||||
return obj;
|
||||
return _ref;
|
||||
}({});
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var obj = function (obj) {
|
||||
obj["x" + foo] = "heh";
|
||||
obj["y" + bar] = "noo";
|
||||
return obj;
|
||||
var obj = function (_ref) {
|
||||
_ref["x" + foo] = "heh";
|
||||
_ref["y" + bar] = "noo";
|
||||
return _ref;
|
||||
}({
|
||||
foo: "foo",
|
||||
bar: "bar"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
var obj = function (obj) {
|
||||
obj["x" + foo] = "heh";
|
||||
obj["y" + bar] = "noo";
|
||||
return obj;
|
||||
var obj = function (_ref) {
|
||||
_ref["x" + foo] = "heh";
|
||||
_ref["y" + bar] = "noo";
|
||||
return _ref;
|
||||
}({});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
var obj = function (obj) {
|
||||
obj["x" + foo] = "heh";
|
||||
return obj;
|
||||
var obj = function (_ref) {
|
||||
_ref["x" + foo] = "heh";
|
||||
return _ref;
|
||||
}({});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
var obj = function (obj) {
|
||||
obj["x" + this.foo] = "heh";
|
||||
return obj;
|
||||
var obj = function (_ref) {
|
||||
_ref["x" + this.foo] = "heh";
|
||||
return _ref;
|
||||
}.call(this, {});
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
var obj = function (obj) {
|
||||
Object.defineProperties(obj, {
|
||||
var obj = function (_ref) {
|
||||
Object.defineProperties(_ref, {
|
||||
foo: {
|
||||
get: function () {
|
||||
return 5 + 5;
|
||||
@ -9,5 +9,5 @@ var obj = function (obj) {
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
return _ref;
|
||||
}({});
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var obj = function (obj) {
|
||||
Object.defineProperties(obj, {
|
||||
var obj = function (_ref) {
|
||||
Object.defineProperties(_ref, {
|
||||
foo: {
|
||||
get: function () {
|
||||
return 5 + 5;
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
return _ref;
|
||||
}({});
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var obj = function (obj) {
|
||||
Object.defineProperties(obj, {
|
||||
var obj = function (_ref) {
|
||||
Object.defineProperties(_ref, {
|
||||
foo: {
|
||||
set: function (value) {
|
||||
this._foo = value;
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
return _ref;
|
||||
}({});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user