Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
data = fs.readFileSync('scripts/ixf-utilities.js','utf8').replace("Y_Y_Y_Y", now.getFullYear()).replace('ixf.version = "X.X.X"','ixf.version = "' + versionNumber + '"').replace("X.X.X",versionNumber + " - " + now.getFullYear() + "/" + (now.getMonth()+1) + "/" + now.getDate()),
outMin = fs.openSync('scripts/ixf-utilities.min.js','w'),
index = data.indexOf("/*"), lastIndex = data.indexOf("*/",index),
ast, minCode, buffer, comment;
// Write permanent comment to minified file
if(index != -1 && lastIndex != -1) {
comment = data.substring(index,lastIndex+2);
console.log(comment);
buffer = new Buffer(comment + "\n");
fs.writeSync(outMin, buffer, 0, buffer.length);
data = data.substring(lastIndex+2);
}
//Minify the code
ast = jsp.parse(data); // 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
minCode = pro.gen_code(ast); // compressed code here
// Write minified code to file
buffer = new Buffer(minCode+"\n");
fs.writeSync(outMin, buffer, 0, buffer.length);
fs.closeSync(outMin);
console.log(" Output: scripts/ixf-utilities.min.js");
if(callback)
callback();
}
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
}
function parseDepsByModuleCode(defineId, moduleCode) {
var ast = astParser.parse(moduleCode);
var deps = [];
Ast.walk(ast, 'stat', function(stat) {
if (stat.toString().indexOf('stat,call,name,define,string,' +
defineId) !== 0) {
return stat;
}
//[ 'stat', [ 'call', [ 'name', 'define' ],
// [ [Object], [Object], [Object] ] ] ]
var depsArr = stat[1][2][1][1];
depsArr.forEach(function(dep) {
deps.push(dep[1]);
});
deps.unshift(defineId);
return stat;
});
function compress (filename, content) {
var ret = "";
content = jsp.parse(content.toString());
content = pro.ast_mangle(content);
content = pro.ast_squeeze(content);
// Add the records
ret += "\/\/ " + filename;
ret += "\n" + pro.gen_code(content) + ";\n\n";
return ret;
};
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!----');
});
});
var reducedRoot, optimizedRoot;
try {
/*
* reducedRoot = FaxReducer.reduceAndCacheModule(baseName, src);
* if (!reducedRoot) {
* console.error("ERROR: Reduced root returned as empty:" + fileName);
* }
* optimizedRoot =
* FaxTailConstructionOptimizer.optimizeTailConstructions(reducedRoot);
*/
optimizedRoot =
FaxTailConstructionOptimizer.optimizeTailConstructions(jsParser.parse(src));
} catch (e) {
console.error("ERROR: CAUGHT EXCEPTION OPTIMIZING:" + fileName);
optimizedRoot = jsParser.parse(src);
}
if (squeeze) {
optimizedRoot = uglify.ast_squeeze(optimizedRoot);
}
if (mangle) {
optimizedRoot = uglify.ast_mangle(optimizedRoot);
}
var gened = uglify.gen_code(optimizedRoot);
if(gened !== src) {
require('sys').puts("Found optimizations in file:" + fileName);
} else {
require('sys').puts("Did not find optimizations in:" + fileName);
}
return gened;
};
* Reduce constructions into optimized rendering functions. Then transform
* tail constructions into optimal tail constructions.
*/
var reducedRoot, optimizedRoot;
try {
/*
* reducedRoot = FaxReducer.reduceAndCacheModule(baseName, src);
* if (!reducedRoot) {
* console.error("ERROR: Reduced root returned as empty:" + fileName);
* }
* optimizedRoot =
* FaxTailConstructionOptimizer.optimizeTailConstructions(reducedRoot);
*/
optimizedRoot =
FaxTailConstructionOptimizer.optimizeTailConstructions(jsParser.parse(src));
} catch (e) {
console.error("ERROR: CAUGHT EXCEPTION OPTIMIZING:" + fileName);
optimizedRoot = jsParser.parse(src);
}
if (squeeze) {
optimizedRoot = uglify.ast_squeeze(optimizedRoot);
}
if (mangle) {
optimizedRoot = uglify.ast_mangle(optimizedRoot);
}
var gened = uglify.gen_code(optimizedRoot);
if(gened !== src) {
require('sys').puts("Found optimizations in file:" + fileName);
} else {
require('sys').puts("Did not find optimizations in:" + fileName);
if (!isSrc && existsSync(path)) {
this.filepath = Path.resolve(path);
src = this.source = FS.readFileSync(this.filepath, "utf8");
}
else {
this.filepath = process.cwd();
src = this.source = path;
}
this.dirpath = Path.dirname(this.filepath);
this.infusions = this.options.infusions ||
new Infusions({
embed: this.options.embed
});
return this.infuseAst(jsp.parse(src));
},
function minifyjs(js) {
var ast = jsp.parse(js);
ast = pro.ast_mangle(ast);
ast = pro.ast_squeeze(ast);
var minJs = pro.gen_code(ast);
return minJs;
}