Valid JS, not valid for Espruino

Posted on
  • Here's some code that webpack and uglify produced, but Espruino web IDE says it has a lot of problems. I don't see what's wrong with it though.

    !function(modules){function __webpack_require__(moduleId){if(install­edModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={expor­ts:{},id:moduleId,loaded:!1};return modules[moduleId].call(module.exports,mo­dule,module.exports,__webpack_require__)­,module.loaded=!0,module.exports}var installedModules={};return __webpack_require__.m=modules,__webpack_­require__.c=installedModules,__webpack_r­equire__.p="",__webpack_require__(0)}([f­unction(module,exports,__webpack_require­__){!function(){var mqtt,wifi,WIFI_NAME="XXXXXX",WIFI_PASS="­XXXXXX",MQTT_HOST="192.168.1.145";mqtt=r­equire("MQTT"),wifi=require("EspruinoWiF­i");var client=mqtt.create(MQTT_HOST);client.on(­"connected",function(){client.subscribe(­"root/branch")}),client.on("publish",fun­ction(pub){console.log("topic: "+pub.topic),console.log("message: "+pub.message)}),wifi.connect(WIFI_NAME,­{password:WIFI_PASS},function(err){retur­n err?void console.log("Connection error: "+err):(console.log("Connected!"),void client.connect())})}()}]);
    
  • Here's the code before minifying.

    
    ;(function(){
      var WIFI_NAME = "XXXXXX";
      var WIFI_PASS = "XXXXXX";
      var MQTT_HOST = "192.168.1.145";
    
      var mqtt, wifi;
    
      mqtt = __non_webpack_require__("MQTT");
      wifi = __non_webpack_require__("EspruinoWiFi");­
    
      var client = mqtt.create(MQTT_HOST);
    
      client.on('connected', function() {
        client.subscribe("root/branch");
      });
    
      client.on('publish', function(pub) {
        console.log("topic: "+pub.topic);
        console.log("message: "+pub.message);
      });
    
      wifi.connect(WIFI_NAME, { password: WIFI_PASS }, function(err) {
        if (err) {
          console.log("Connection error: "+err);
          return;
        }
        console.log("Connected!");
        client.connect();
      });
    })();
    
  • Here's the output that I get when I run the minified code from terminal:

    =undefined
    Connected!
    Uncaught Error: Field or method "connect" does not already exist, and can't create it on undefined
     at line 1 col 86
    ...g("Connected!"),void client.connect())
                                  ^
    in function called from system
    

    If I paste the unminified code into the web IDE, it works.

  • Looks like an issue with void only parsing an ID, not the whole expression - I just created a bug for it: github.com/espruino/Espruino/iss­ues/1079

    Bit busy now but it should be an easy fix.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Valid JS, not valid for Espruino

Posted by Avatar for CriscoCrusader @CriscoCrusader

Actions