plugins/minify.js
function minifyCodeEsprima(code,callback,description) {
    if ((typeof esprima == "undefined") ||
        (typeof esmangle == "undefined") ||
        (typeof escodegen == "undefined")) {
      console.warn("esprima/esmangle/escodegen not defined - not minifying")
      return callback(code);
    }

    var code, syntax, option, str, before, after;
    var options = {};
    options["mangle"] = Espruino.Config.MINIFICATION_Mangle;
    options["remove-unreachable-branch"] = Espruino.Config.MINIFICATION_Unreachable;
    options["remove-unused-vars"] = Espruino.Config.MINIFICATION_Unused;
    options["fold-constant"] = Espruino.Config.MINIFICATION_Literal;
    options["eliminate-dead-code"] = Espruino.Config.MINIFICATION_DeadCode;
    option = {format: {indent: {style: ''},quotes: 'auto',compact: true}};
    str = '';
    try {
        before = code.length;
        syntax = esprima.parse(code, { raw: true, loc: true });
        syntax = obfuscate(syntax,options);
        code = escodegen.generate(syntax, option);
        after = code.length;
        if (before > after) {
          Espruino.Core.Notifications.info('No errors'+description+'. Minified ' + before + ' bytes to ' + after + ' bytes.');
        } else {
          Espruino.Core.Notifications.info('Can not minify further'+description+', code is already optimized.');
        }
        callback(code);
    } catch (e) {
      Espruino.Core.Notifications.error(e.toString()+description);
      console.error(e.stack);
      callback(code);
    } finally { }
  }
function minifyCodeEsprima(code,callback,description) {
    if ((typeof esprima == "undefined") ||
        (typeof esmangle == "undefined") ||
        (typeof escodegen == "undefined")) {
      console.warn("esprima/esmangle/escodegen not defined - not minifying")
      return callback(code);
    }

    var code, syntax, option, str, before, after;
    var options = {};
    options["mangle"] = Espruino.Config.MINIFICATION_Mangle;
    options["remove-unreachable-branch"] = Espruino.Config.MINIFICATION_Unreachable;
    options["remove-unused-vars"] = Espruino.Config.MINIFICATION_Unused;
    options["fold-constant"] = Espruino.Config.MINIFICATION_Literal;
    options["eliminate-dead-code"] = Espruino.Config.MINIFICATION_DeadCode;
    option = {format: {indent: {style: ''},quotes: 'auto',compact: true}};
    str = '';
    try {
        before = code.length;
        syntax = esprima.parse(code, { raw: true, loc: true });
        syntax = obfuscate(syntax,options);
        code = escodegen.generate(syntax, option);
        after = code.length;
        if (before > after) {
          Espruino.Core.Notifications.info('No errors'+description+'. Minified ' + before + ' bytes to ' + after + ' bytes.');
        } else {
          Espruino.Core.Notifications.info('Can not minify further'+description+', code is already optimized.');
        }
        callback(code);
    } catch (e) {
      Espruino.Core.Notifications.error(e.toString()+description);
      console.error(e.stack);
      callback(code);
    } finally { }
  }
function minifyCodeEsprima ( code , callback , description ) { if ( ( typeof esprima == "undefined" ) || ( typeof esmangle == "undefined" ) || ( typeof escodegen == "undefined" ) ) { console . warn ( "esprima/esmangle/escodegen not defined - not minifying" ) return callback ( code ) ; } var code , syntax , option , str , before , after ; var options = { } ; options [ "mangle" ] = Espruino . Config . MINIFICATION_Mangle ; options [ "remove-unreachable-branch" ] = Espruino . Config . MINIFICATION_Unreachable ; options [ "remove-unused-vars" ] = Espruino . Config . MINIFICATION_Unused ; options [ "fold-constant" ] = Espruino . Config . MINIFICATION_Literal ; options [ "eliminate-dead-code" ] = Espruino . Config . MINIFICATION_DeadCode ; option = { format : { indent : { style : '' } , quotes : 'auto' , compact : true } } ; str = '' ; try { before = code . length ; syntax = esprima . parse ( code , { raw : true , loc : true } ) ; syntax = obfuscate ( syntax , options ) ; code = escodegen . generate ( syntax , option ) ; after = code . length ; if ( before > after ) { Espruino . Core . Notifications . info ( 'No errors' + description + '. Minified ' + before + ' bytes to ' + after + ' bytes.' ) ; } else { Espruino . Core . Notifications . info ( 'Can not minify further' + description + ', code is already optimized.' ) ; } callback ( code ) ; } catch ( e ) { Espruino . Core . Notifications . error ( e . toString ( ) + description ) ; console . error ( e . stack ) ; callback ( code ) ; } finally { } }
Use the 'offline' Esprima compile
Use the offline Esprima compile