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="";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.

      var WIFI_NAME = "XXXXXX";
      var WIFI_PASS = "XXXXXX";
      var MQTT_HOST = "";
      var mqtt, wifi;
      mqtt = __non_webpack_require__("MQTT");
      wifi = __non_webpack_require__("EspruinoWiFi");­
      var client = mqtt.create(MQTT_HOST);
      client.on('connected', function() {
      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);
  • Here's the output that I get when I run the minified code from terminal:

    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:­ues/1079

    Bit busy now but it should be an easy fix.

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

Valid JS, not valid for Espruino

Posted by Avatar for CriscoCrusader @CriscoCrusader