• when I use Esprima(offline) to minify the code, It's not okay when use AT.js. But If I don't use Esprima, all goes well.

    Uncaught Error: Cannot read property 'substr' of undefined
    at line 1 col 222
    ...;if(e)for(var c in e)for(;b.substr(0,c.length)==c;)if(a=b,b­=...

    I think the position of the error right here:

    if (line[0]=="\n") {line=line.substr(1);}
        if (handlers) {
          for (var h in handlers) {
            while (line.substr(0,h.length)==h) {
              // console.log("execute handler", h)
              var pre = line;
              line = handlers[h](line);
              if (pre==line) {return;} // handler needs more data
              //if (dbg) console.log("HANDLER] "+JSON.stringify(pre)+"=>"+JSON.stringif­y(line)+" ("+h+")");
            }
          }
        }
    

    How can I avoid this error?

    Otherwise, when I tried to uncheck the Esprima: Mangle(Shorten variable name), the result of this error still use the short variable name, I wonder if WEB IDE didn't work?

    =======================================
    I tried to write a simple code in WEB-IDE,

    Serial2.setup(19200, {rx: A3, tx: A2});
    let at = require('AT').connect(Serial2);
    //console.log
    at.cmd("AT+CIPOPEN?\r\n",1000,function(r­){console.log(r)});
    

    and use Esprima to minify the code, like these. It's the same with the original AT.js.

    Serial2.on("data", function (d) {if(console.log('res',JSON.stringify(d))­,d[0]==='extends typeof'&&(d=d.replace('extends typeof','')),dataCount){if(line&&(d=line­+d,line=''),d.length<=dataCount){dataCou­nt-=d.length,dataCallback(d),dataCount==­0&&(dataCallback=undefined);return;}data­Callback(d.substr(0,dataCount)),d=d.subs­tr(dataCount),dataCount=0,dataCallback=u­ndefined;}if(line+=d,line[0]=='\n'&&(lin­e=line.substr(1)),handlers)for(var h in handlers)while(line.substr(0,h.length)==­h){var pre=line;if(line=handlersh,pre==line)return;}var i=line.indexOf('\r');while(i>=0){var l=line.substr(0,i);var handled=!1;if(l.length>0)for(var h in lineHandlers){let namee='ddddd';l.substr(0,h.length)==h&&(­lineHandlersh,handled=!0),handled||lineCallback&&l&&l­ineCallback(l);}if(line=line.substr(i+1)­,handled&&dataCount)return cb('');if(line[0]=='\n'&&(line=line.subs­tr(1)),line.length&&handlers)for(var h in handlers)line.substr(0,h.length)==h&&(li­ne=handlersh);line||(line=''),i=line.indexOf('\r');}­});

    However, when I pick up the same position code from my project by dump(), the AT.js part is different with the previous one.

    function Cnet(ua) {
      iam = this;
      uart = ua;
      at = require("AT").connect(ua);
      setTimeout(function () {
        init1();
      }, 3000);
    }
    

    Serial2.on("data", function (a) {
    if(d){b&&(a=b+a,b="");if(a.length<=d){d-­=a.length;l(a);0==d&&(l=void 0);return}l(a.substr(0,d));a=a.substr(d)­;d=0;l=void 0}b+=a;m&&console.log("] "+JSON.stringify(a));"\n"==b[0]&&(b=b.su­bstr(1));if(e)for(var c in e)for(;b.substr(0,c.length)==c;)if(a=b,b­=ec,a==b)return;for(a=b.indexOf("\r");0<=a;­){var f=b.substr(0,a),p=!1;if(0<f.length){for(­c in h)f.substr(0,c.length)==c&&(hc,p=!0);p||g&&
    g(f)}b=b.substr(a+1);if(p&&d)return q("");"\n"==b[0]&&(b=b.substr(1));if(b.l­ength&&e)for(c in e)b.substr(0,c.length)==c&&(b=ec);a=b.indexOf("\r")}
    });

About

Avatar for user109783 @user109783 started