Ejemplo n.º 1
0
function errorDetails(script) {
    try {
        jsp.parse(script);
        return null;
    } catch (e) {
        return e;
    }
}
Ejemplo n.º 2
0
stdin.on('end', function () {
    var ast = jsp.parse(orig_code); // parse code and get the initial AST
    ast = pro.ast_mangle(ast); // get a new AST with mangled names
    ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
    var finalCode = pro.gen_code(ast); // compressed code here

    console.log(finalCode + ';');
});
Ejemplo n.º 3
0
function compressJS(values)
{
  var complete = values.join("\n");
  var ast = jsp.parse(complete); // parse code and get the initial AST
  ast = pro.ast_mangle(ast); // get a new AST with mangled names
  ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
  return pro.gen_code(ast); // compressed code here
}
Ejemplo n.º 4
0
function collectTokens(code, tokens) {
  var tok = uglify.parser.tokenizer(code),
      token;

  do {
    tokens.push(token = tok());
  } while (token.type !== 'eof');
};
Ejemplo n.º 5
0
 _parse: function(src) {
   try {
     return parser.parse(src, false, true);
   } catch (e) {
     this.error = new Error(this._errorMessageWithContext(e.message, src, e.line));
     throw this.error;
   }
 },
Ejemplo n.º 6
0
function instrument(code) {
    var ast = jsp.parse(code, false, true); // true for the third arg specifies that we want
    // to have start/end tokens embedded in the
    // statements
    var w = pro.ast_walker();

    // we're gonna need this to push elements that we're currently looking at, to avoid
    // endless recursion.
    var analyzing = [];

    function do_stat() {
        var ret;
        if (this[0].start && analyzing.indexOf(this) < 0) {
            // without the `analyzing' hack, w.walk(this) would re-enter here leading
            // to infinite recursion
            analyzing.push(this);
            ret = [ "splice", // XXX: "block" is safer
                [
                    [ "stat",
                        [ "call", [ "name", "trace" ],
                            [
                                [ "string", this[0].toString() ],
                                [ "num", this[0].start.line ],
                                [ "num", this[0].start.col ],
                                [ "num", this[0].end.line ],
                                [ "num", this[0].end.col ]
                            ]]],
                    w.walk(this)
                ]];
            analyzing.pop(this);
        }
        return ret;
    };
    var new_ast = w.with_walkers({
        "stat":do_stat,
        "label":do_stat,
        "break":do_stat,
        "continue":do_stat,
        "debugger":do_stat,
        "var":do_stat,
        "const":do_stat,
        "return":do_stat,
        "throw":do_stat,
        "try":do_stat,
        "defun":do_stat,
        "if":do_stat,
        "while":do_stat,
        "do":do_stat,
        "for":do_stat,
        "for-in":do_stat,
        "switch":do_stat,
        "with":do_stat
    }, function () {
        return w.walk(ast);
    });
    return pro.gen_code(new_ast, { beautify:true });
}
Ejemplo n.º 7
0
task({'default': ['coffee', 'handlebars']}, function (params) {
  var template = fs.readFileSync('src/faqjs-template.handlebars.js', 'utf8');
  var js = fs.readFileSync('src/faqjs.js', 'utf8');
  var ast = jsp.parse(template + js); // parse code and get the initial AST
  ast = uglify.ast_mangle(ast); // get a new AST with mangled names
  ast = uglify.ast_squeeze(ast); // get an AST with compression optimizations
  var minJs = uglify.gen_code(ast); // compressed code here
  fs.writeFileSync('faqjs.min.js', minJs, 'utf8');
});
Ejemplo n.º 8
0
   taskRunner.push(function(next) {
      var ast;

      ast = uglifyParser.parse(concatenatedOutput);    // parse code and get the initial AST
      ast = uglify.ast_mangle(ast);          // get a new AST with mangled names
      ast = uglify.ast_squeeze(ast);         // get an AST with compression optimizations

      fs.writeFile(jsOutputFile.replace(/\.js$/, '.min.js'), uglify.gen_code(ast), 'utf-8', next);
   }, 'Save minified JS file');
Ejemplo n.º 9
0
function uglify(src, dst) {
  var jsp = require("uglify-js").parser;
  var pro = require("uglify-js").uglify;
  var orig_code = read(src);
  var ast = jsp.parse(orig_code); // parse code and get the initial AST
  ast = pro.ast_mangle(ast); // get a new AST with mangled names
  ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
  fs.writeFileSync(dst, minlicense + pro.gen_code(ast));
}
Ejemplo n.º 10
0
function staticRequire (filePath, options) {
    state = exports.state = new_sate();
    filePath = fs.realpathSync(filePath);
    state.currentPath = filePath;
    var newOptions = {};
    options = Object.create(options || {});
    
    options.searchPaths = options.searchPaths ? options.searchPaths : [];
    options.searchPaths = [path.dirname(state.currentPath)].concat(options.searchPaths);
    
    options.serverRoot = options.serverRoot ? 
        fs.realpathSync(options.serverRoot) : 
        path.dirname(currentPath);
        
    state.options = options;
        
    state.requiredAsts = [];
    
    addFileToAstList(filePath, true);
    
    var code = 'var global = this;';
    code    += 'function require(index) { if (!require.cache[index]) {var module = require.cache[index] = {exports: {}}; require.modules[index].call(module.exports, global, module);} return require.cache[index].exports; }\n';
    code    += 'var require_modules = require.modules = []; require.cache = [];';
    var body = jsp.parse(code)[1];
    
    if (state.requiredCssUsed) {
        var code = state.requiredCssFiles.map(function(filePath) {
            return processCssIncludes(filePath);
        }).join('\n');
        body.push( ['var', [['__requiredCss', ['string', code]]]] );
    }
    for (var i=0; i < state.requiredCount; i++) {
        body[body.length] =
            [ 'stat', 
                ['assign', 
                    true,
                    ['sub',
                        ['name', 'require_modules'],
                        ['num', i]
                    ],
                    state.requiredAsts[i][1][0][1]
                ]
            ];
    };
    body.push(['stat', ['call', ['name', 'require'], [['num', '0']]]]);
    
    return [ 'toplevel',
      [ [ 'stat',
          [ 'call',
            [ 'function',
              null,
              [],
              body
            ],
            [] ] ] ] ];
    
}
Ejemplo n.º 11
0
var js = function(inputFile, outputFile) {
  console.log('require: npm install uglify-js@1');
  console.log('minifier', inputFile, outputFile);
  var ast = jsp.parse(fs.readFileSync(inputFile).toString()); // parse code and get the initial AST
  ast = pro.ast_mangle(ast); // get a new AST with mangled names
  ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
  var final_code = pro.gen_code(ast); // compressed code here
  fs.writeFileSync(outputFile, final_code, "utf-8");
};
Ejemplo n.º 12
0
	function packIntoJSHeader(js){
		if (!cSettings.debug === true) {
			var ast = jsp.parse(js);
			ast = pro.ast_mangle(ast);
			ast = pro.ast_squeeze(ast);
			js = pro.gen_code(ast);
		}
		return "<script type=\"text/javascript\">" + js + "</script>\n";
	}
Ejemplo n.º 13
0
 this._getApi(aRequest, aResponse, function (err, str) {
     if(err) {
         return aRequest.next(err);
     }
     var ast = jsp.parse(str);
     var final_code = pro.gen_code(ast, {
         beautify: true
     });
     aResponse.send(final_code);
 });
Ejemplo n.º 14
0
  minifySource: function() {
    var ast, opts = util.extend({}, this.builder.options.minify || {});
    util.extend(opts, this.builder.minifyOptions);

    ast = uglify.parser.parse(this.derived.generated);
    ast = uglify.uglify.ast_mangle(ast, opts);
    ast = uglify.uglify.ast_squeeze(ast, opts);

    return uglify.uglify.gen_code(ast, opts);
  },
Ejemplo n.º 15
0
	uglifyjs = function(str){//使用uglify-js压缩,生成压缩后的js文件
		var jsp = require("uglify-js").parser,
		    pro = require("uglify-js").uglify,		
		    orig_code = str,
			ast = jsp.parse(orig_code); // parse code and get the initial AST
		ast = pro.ast_mangle(ast); // get a new AST with mangled names
		ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
		var final_code = pro.gen_code(ast); // compressed code here
		return final_code+';';
	},
Ejemplo n.º 16
0
 function(file, path, index, isLast, callback) {
   if (env.production) {
     var ast = uglify_jsp.parse(file);
     ast = uglify_pro.ast_mangle(ast);
     ast = uglify_pro.ast_squeeze(ast);
     callback(uglify_pro.gen_code(ast, { beautify: true, indent_level: 0 }));
   } else {
     callback(file);
   }
 }
Ejemplo n.º 17
0
exports.uglify = function (code) {
	var pro = uglifyjs.uglify;

	var ast = uglifyjs.parser.parse(code);
	ast = pro.ast_mangle(ast);
	ast = pro.ast_squeeze(ast, {keep_comps: false});
	ast = pro.ast_squeeze_more(ast);

	return pro.gen_code(ast);
};
Ejemplo n.º 18
0
  function () {
    console.log('uglify jquery.fenster.js');

    var ast = ugp.parse(fs.readFileSync('production/jquery.fenster.full.js').toString());
    ast = ugu.ast_mangle(ast);
    ast = ugu.ast_squeeze(ast);

    var result = ugu.split_lines(ugu.gen_code(ast), 1024 * 8);
    fs.writeFileSync(this.name, getComment() + result);
  }
function Squash(script) {
  // (let me (pretend (it-is-real LISP))) ;)
  if(opts.pretty_test) { return script; }
  else { // var Uglify = require ('uglify-js');
    return Uglify.uglify.gen_code(
      Uglify.uglify.ast_squeeze(
        Uglify.parser.parse(
          String(script)
          ))); }
} /* Squash */
Ejemplo n.º 20
0
fs.readFile('src.js', 'utf-8', function(err, js) {
    var ast = parser.parse(js);
    ast = uglify.ast_mangle(ast);
    ast = uglify.ast_squeeze(ast);
    var final_code = uglify.gen_code(ast);

    fs.writeFileSync('bookmarklet.js', 'javascript:' + final_code);
    console.log('Saved a new build to bookmarklet.js');
    process.exit();
});
Ejemplo n.º 21
0
    fs.readFile(config.libOut, function (err, data) {
      var libCode = data.toString();

      var ast = jsp.parse(libCode); // parse code and get the initial AST
      ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
      var compiledCode = pro.gen_code(ast); // compressed code here
      fs.writeFile(config.libOut, compiledCode, function () {
        console.log('Built the lib code.');
      });
    })
Ejemplo n.º 22
0
 , uglify = function (src) {
     try {
       var ast = jsp.parse(src)
       ast = pro.ast_squeeze(ast)
       return pro.gen_code(ast)
     }
     catch (ex) {
       return src
     }
   }
Ejemplo n.º 23
0
 this._getApi(aRequest, aResponse, function (err, str) {
     if(err) {
         return aRequest.next(err);
     }
     var ast = jsp.parse(str);
     ast = pro.ast_mangle(ast);
     ast = pro.ast_squeeze(ast);
     var final_code = pro.gen_code(ast);
     aResponse.send(final_code);
 });
Ejemplo n.º 24
0
exports.uglify = function (code) {
	var pro = uglifyjs.uglify;

	var ast = uglifyjs.parser.parse(code);
	ast = pro.ast_mangle(ast, {mangle: true});
	ast = pro.ast_squeeze(ast);
	ast = pro.ast_squeeze_more(ast);

	return pro.gen_code(ast) + ';';
};
Ejemplo n.º 25
0
exports.run = function(path, data, o) {
    var ast = min.parser.parse(data);

    if (o.verbose) {
        min.uglify.set_logger(console.log);
    }

    ast = min.uglify.ast_mangle(ast);
    ast = min.uglify.ast_squeeze(ast);
    return min.uglify.gen_code(ast);
};
Ejemplo n.º 26
0
Archivo: test.js Proyecto: Aksent/jsdox
 fs.readFile(file, function (err, data) {
   if (err) {
     throw err;
   }
   var ast = jsp.parse(data.toString());
   console.log(util.inspect(ast, false, 20, true));
   /* term */
   // console.log(util.inspect(ast[1][0][1]));
   // console.log(util.inspect(ast[1][3][1]));
   console.log(util.inspect(ast[1][5][1]));
 });
Ejemplo n.º 27
0
var getCopyright = exports.getCopytight = function(input){
	var tok = jsp.tokenizer(input);
	var show_copyright = function(comments){
		var c = comments[0];
		if (c && c.type != "comment1" && c.value[0] == '!') {
			return "/*" + c.value + "*/";
		}
		return "";
	}
	return show_copyright(tok().comments_before);
}
Ejemplo n.º 28
0
loopRead(function(){
	var ast;
	combineFile = '(function(){' + combineFile + '})();';
	ast = jsp.parse(combineFile);
	ast = pro.ast_mangle(ast);
	ast = pro.ast_squeeze(ast);
	ast = pro.gen_code(ast);
	fs.writeFile('youkuhtml5playerbookmark2.js', ast, function() {
		console.log('-----youkuhtml5playerbookmark2.js updated!----');
	});
});
function runUglify(mergedFile) {
    var ast;
    try {
        ast = jsp.parse(mergedFile); // parse code and get the initial AST
    } catch (e) {
        console.log('UglifyJS parse failed', e);
    }
    ast = pro.ast_mangle(ast); // get a new AST with mangled names
    ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
    return pro.gen_code(ast); // compressed code here
}
Ejemplo n.º 30
0
    TARGETS.uglifyJS = function(code){
        console.log('[uglifyJS] compress js');

        var ast = jsp.parse(code);
        ast = pro.ast_mangle(ast);
        ast = pro.ast_squeeze(ast);

        return pro.gen_code(ast, {
            inline_script: true  //to escape occurrences of </script in strings
        });
    };