react-magnetic-di
Advanced tools
Comparing version 3.1.3 to 3.1.4
@@ -104,4 +104,7 @@ "use strict"; | ||
depRef.findParent(function (p) { | ||
var _p$parentPath; | ||
if (p.isFunction() && ((_p$parentPath = p.parentPath) === null || _p$parentPath === void 0 || (_p$parentPath = _p$parentPath.node) === null || _p$parentPath === void 0 || (_p$parentPath = _p$parentPath.callee) === null || _p$parentPath === void 0 ? void 0 : _p$parentPath.name) !== INJECT_FUNCTION) { | ||
var _p$node, _depRef$parentPath, _p$parentPath; | ||
// avoid dynamyc object getters/setters `get [dep]() {}` to be marked as dependencies | ||
// on their created scope (odd behaviour of scope.getBinding) | ||
var isComputedSelfPath = ((_p$node = p.node) === null || _p$node === void 0 ? void 0 : _p$node.computed) && (depRef.parentPath === p || ((_depRef$parentPath = depRef.parentPath) === null || _depRef$parentPath === void 0 ? void 0 : _depRef$parentPath.parentPath) === p); | ||
if (p.isFunction() && ((_p$parentPath = p.parentPath) === null || _p$parentPath === void 0 || (_p$parentPath = _p$parentPath.node) === null || _p$parentPath === void 0 || (_p$parentPath = _p$parentPath.callee) === null || _p$parentPath === void 0 ? void 0 : _p$parentPath.name) !== INJECT_FUNCTION && !isComputedSelfPath) { | ||
// add ref for every function scope up to the root one | ||
@@ -108,0 +111,0 @@ _this.getValueOrInit(p).dependencyRefs.add(depRef); |
@@ -21,3 +21,3 @@ "use strict"; | ||
var depNames = []; | ||
Array.from(locationValue.dependencyRefs).forEach(function (n) { | ||
locationValue.dependencyRefs.forEach(function (n) { | ||
var _n$node; | ||
@@ -70,2 +70,3 @@ var name = (_n$node = n.node) === null || _n$node === void 0 ? void 0 : _n$node.name; | ||
argsPaths.forEach(function (argPath) { | ||
var _bodyPath$parentPath; | ||
// For each argument we get the dependency variable name | ||
@@ -76,4 +77,24 @@ // then we rename it locally so we get a new unique identifier. | ||
var name = argPath.node.name; | ||
bodyPath.scope.rename(name, state.getAlias(name, bodyPath.scope)); | ||
var newName = state.getAlias(name, bodyPath.scope); | ||
bodyPath.scope.rename(name, newName); | ||
argPath.replaceWith(t.identifier(name)); | ||
// this is ugly but scope also renames dynamic object computed props | ||
// so we revert that change too | ||
if ((_bodyPath$parentPath = bodyPath.parentPath) !== null && _bodyPath$parentPath !== void 0 && (_bodyPath$parentPath = _bodyPath$parentPath.node) !== null && _bodyPath$parentPath !== void 0 && _bodyPath$parentPath.computed) { | ||
var key = bodyPath.parentPath.get('key'); | ||
if (key.isIdentifier() && key.node.name === newName) { | ||
// get [foo] () | ||
key.replaceWith(t.identifier(name)); | ||
} else { | ||
// get [foo()] {} / get [foo.bar] {} / ... | ||
key.traverse({ | ||
Identifier: function Identifier(keyPath) { | ||
if (keyPath.node.name === newName) { | ||
keyPath.replaceWith(t.identifier(name)); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
@@ -80,0 +101,0 @@ |
@@ -75,4 +75,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
depRef.findParent(p => { | ||
var _p$parentPath; | ||
if (p.isFunction() && ((_p$parentPath = p.parentPath) == null || (_p$parentPath = _p$parentPath.node) == null || (_p$parentPath = _p$parentPath.callee) == null ? void 0 : _p$parentPath.name) !== INJECT_FUNCTION) { | ||
var _p$node, _depRef$parentPath, _p$parentPath; | ||
// avoid dynamyc object getters/setters `get [dep]() {}` to be marked as dependencies | ||
// on their created scope (odd behaviour of scope.getBinding) | ||
const isComputedSelfPath = ((_p$node = p.node) == null ? void 0 : _p$node.computed) && (depRef.parentPath === p || ((_depRef$parentPath = depRef.parentPath) == null ? void 0 : _depRef$parentPath.parentPath) === p); | ||
if (p.isFunction() && ((_p$parentPath = p.parentPath) == null || (_p$parentPath = _p$parentPath.node) == null || (_p$parentPath = _p$parentPath.callee) == null ? void 0 : _p$parentPath.name) !== INJECT_FUNCTION && !isComputedSelfPath) { | ||
// add ref for every function scope up to the root one | ||
@@ -79,0 +82,0 @@ this.getValueOrInit(p).dependencyRefs.add(depRef); |
@@ -20,3 +20,3 @@ const { | ||
const depNames = []; | ||
Array.from(locationValue.dependencyRefs).forEach(n => { | ||
locationValue.dependencyRefs.forEach(n => { | ||
var _n$node; | ||
@@ -65,2 +65,3 @@ const name = (_n$node = n.node) == null ? void 0 : _n$node.name; | ||
argsPaths.forEach(argPath => { | ||
var _bodyPath$parentPath; | ||
// For each argument we get the dependency variable name | ||
@@ -71,4 +72,24 @@ // then we rename it locally so we get a new unique identifier. | ||
const name = argPath.node.name; | ||
bodyPath.scope.rename(name, state.getAlias(name, bodyPath.scope)); | ||
const newName = state.getAlias(name, bodyPath.scope); | ||
bodyPath.scope.rename(name, newName); | ||
argPath.replaceWith(t.identifier(name)); | ||
// this is ugly but scope also renames dynamic object computed props | ||
// so we revert that change too | ||
if ((_bodyPath$parentPath = bodyPath.parentPath) != null && (_bodyPath$parentPath = _bodyPath$parentPath.node) != null && _bodyPath$parentPath.computed) { | ||
const key = bodyPath.parentPath.get('key'); | ||
if (key.isIdentifier() && key.node.name === newName) { | ||
// get [foo] () | ||
key.replaceWith(t.identifier(name)); | ||
} else { | ||
// get [foo()] {} / get [foo.bar] {} / ... | ||
key.traverse({ | ||
Identifier(keyPath) { | ||
if (keyPath.node.name === newName) { | ||
keyPath.replaceWith(t.identifier(name)); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
@@ -75,0 +96,0 @@ |
{ | ||
"name": "react-magnetic-di", | ||
"version": "3.1.3", | ||
"version": "3.1.4", | ||
"description": "Context driven dependency injection", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138300
2680