Bitcoin-com / slp-sdk

Simple Ledger Protocol SDK powered by BITBOX
https://developer.bitcoin.com/slp
MIT License
20 stars 32 forks source link

Babel broken - needs upgrade #38

Open ekkis opened 5 years ago

ekkis commented 5 years ago

this module relies on Babel 6, which is broken:

$ node
> Object.prototype.test = () => null
[Function]
> require('bitbox-sdk')

yields:

Error: You passed traverse() a visitor object with the property "Block" that has the invalid property "test" at verify (/Users/ekkis/dev/otc-trader/node_modules/babel-traverse/lib/visitors.js:205:17) at Function.explode (/Users/ekkis/dev/otc-trader/node_modules/babel-traverse/lib/visitors.js:72:3) at Plugin.normaliseVisitor (/Users/ekkis/dev/otc-trader/node_modules/babel-core/lib/transformation/plugin.js:155:29) at new Plugin (/Users/ekkis/dev/otc-trader/node_modules/babel-core/lib/transformation/plugin.js:66:27)

I reached out to the Babel guys and they said v6 is no longer maintained and your package should upgrade. please see: https://github.com/babel/babel/issues/9786

please upgrade and let me know when I can refresh

ekkis commented 5 years ago

this issue is correlated to https://github.com/Bitcoin-com/slp-sdk/issues/32 which describes a similar bug in lodash. the issue was closed because lodash is not a direct dependency of slp-sdk. however that issue, and this one will be solved once slp-sdk upgrades to Babel 6. the version in current use is no longer supported

I have verified that the problems in Babel were fixed as of:

https://github.com/babel/babel/commit/0345c1bc1ded6af8d66f8605e6fdbeeb9b70c5b3#diff-726a7b1ebcc4ecc81357266f8395ac19

and for anyone interested, until slp-sdk upgrades, the patch below fixes the problem with babel:

diff --git a/node_modules/babel-traverse/lib/visitors.js b/node_modules/babel-traverse/lib/visitors.js
index dadf5d0..708d825 100644
--- a/node_modules/babel-traverse/lib/visitors.js
+++ b/node_modules/babel-traverse/lib/visitors.js
@@ -131,12 +131,18 @@ function explode(visitor) {

   for (var _nodeType in visitor) {
     if (shouldIgnoreKey(_nodeType)) continue;
+    if (!visitor.hasOwnProperty(_nodeType)) continue;

     var _fns = visitor[_nodeType];

-    var aliases = t.FLIPPED_ALIAS_KEYS[_nodeType];
+    var aliases = t.FLIPPED_ALIAS_KEYS.hasOwnProperty(_nodeType)
+       ? t.FLIPPED_ALIAS_KEYS[_nodeType]
+       : null;
+
+    var deprecratedKey = t.DEPRECATED_KEYS.hasOwnProperty(_nodeType)
+       ? t.DEPRECATED_KEYS[_nodeType]
+       : null;

-    var deprecratedKey = t.DEPRECATED_KEYS[_nodeType];
     if (deprecratedKey) {
       console.trace("Visitor defined for " + _nodeType + " but it has been renamed to " + deprecratedKey);
       aliases = [deprecratedKey];
@@ -199,6 +205,7 @@ function verify(visitor) {
     var visitors = visitor[nodeType];
     if ((typeof visitors === "undefined" ? "undefined" : (0, _typeof3.default)(visitors)) === "object") {
       for (var visitorKey in visitors) {
+        if (!visitors.hasOwnProperty(visitorKey)) continue;
         if (visitorKey === "enter" || visitorKey === "exit") {
           validateVisitorMethods(nodeType + "." + visitorKey, visitors[visitorKey]);
         } else {

also, the patch for the lodash problem:

diff --git a/node_modules/lodash/lodash.js b/node_modules/lodash/lodash.js
index cb139dd..9730f52 100644
--- a/node_modules/lodash/lodash.js
+++ b/node_modules/lodash/lodash.js
@@ -17039,8 +17039,11 @@
     baseForOwn(LazyWrapper.prototype, function(func, methodName) {
       var lodashFunc = lodash[methodName];
       if (lodashFunc) { 
-        var key = (lodashFunc.name + ''),
-            names = realNames[key] || (realNames[key] = []);
+        var key = (lodashFunc.name + ''), names;
+       if (realNames.hasOwnProperty(key))
+           names = realNames[key];
+       else
+            names = realNames[key] = [];

         names.push({ 'name': methodName, 'func': lodashFunc });
       }