Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function U2_parse(code, options) {
// if (options) {
// SYS.error("--- parsing " + options.filename);
// }
try {
code = code.replace(/\r/g, ""); //
return U2.parse(code, options);
} catch(ex) {
if (ex instanceof U2.JS_Parse_Error) {
console.log(options.filename);
console.log(ex);
}
}
}
async function append(entry, { dependencies, factory, fpath }) {
const id = `${name}/${version}/${entry}`
if (doneIds[id]) return
if (entry !== mainEntry && enableBundle === false) {
return wildModules.push({ name, version, entry })
}
doneIds[id] = true
if (!dependencies) dependencies = matchRequire.findAll(factory)
for (let i = dependencies.length - 1; i >= 0; i--) {
if (dependencies[i].endsWith('heredoc')) dependencies.splice(i, 1)
}
try {
toplevel = UglifyJS.parse(define(id, dependencies, factory), {
// fpath might be undefined because we allow virtual components.
filename: fpath ? path.relative(root, fpath) : id,
toplevel
})
} catch (err) {
throw new Error(`${err.message} (${err.filename}:${err.line}:${err.col})`)
}
await satisfy(entry, dependencies)
}
const dependencies = opts.dependencies || matchRequire.findAll(factory)
const requiredMap = {}
const bundleResult = await _bundle(id, {
root, paths,
dependencies, factory,
toplevel,
includeModules, includeComponents, dependenciesMap, requiredMap
})
toplevel = bundleResult.toplevel
if (includeLoader) {
// If not all modules are included, use the full dependencies map instead of
// the required map generated while bundling.
Object.assign(loaderConfig, parseSystem(includeModules ? requiredMap : dependenciesMap))
toplevel = UglifyJS.parse(`
porter.config(${JSON.stringify(loaderConfig)})
porter["import"](${JSON.stringify(id)})
`, { filename: `${entry}.js`, toplevel })
}
const dest = opts.dest && path.resolve(root, opts.dest)
const { js, map } = _process(id, toplevel, {
sourceMaps: bundleResult.sourceMaps,
sourceRoot: opts.sourceRoot
})
if (dest) {
await _compileFile(id, { dest, js, map })
}
const { moduleIds, componentIds } = bundleResult
it('test replace ast_call node', function() {
var ast = UglifyJS.parse('var c = seajs.importStyle(".a{color:#000;background:#fff}", "alice/a.css");');
var seajsNode = null;
var findImportStyle = new UglifyJS.TreeWalker(function(node, descend) {
if (node instanceof UglifyJS.AST_Call && node.start.value === 'seajs') {
seajsNode = node.clone();
return true;
}
});
ast.walk(findImportStyle);
var ast2 = getAst(astModule, 'src/foo.js');
var replace = new UglifyJS.TreeTransformer(function(node, descend) {
if (node instanceof UglifyJS.AST_Call && node.start.value === 'require') {
//console.info(node);
if (seajsNode) {
function fixDeps(fn,deps) {
//uglify2��֧������תast
var code = fn.toString().replace('function','function ___kmdjs_temp');
var ast = U2.parse(code);
ast.figure_out_scope();
var nodes = [];
var topArr = [];
each(deps,function(item){
topArr.push(item.split('.')[0]);
})
ast.walk(new U2.TreeWalker(function (node) {
if (node instanceof U2.AST_New) {
var ex = node.expression;
var name = ex.name;
isInArray(name,topArr)||isInWindow(name) || isInScopeChainVariables(ex.scope, name) || nodes.push({name:name,node:node});
}
.use(shim({
alias: 'backbone',
path: path.join(vendorDir, 'backbone.js'),
exports: null
}))
.use(shim({
alias: 'mustache',
path: path.join(vendorDir, 'mustache.js'),
exports: null
}))
.addEntry(entryFile)
.bundle()
.shim();
if (!debug) {
var ast = UglifyJS.parse(bundled);
ast.figure_out_scope();
ast = ast.transform(UglifyJS.Compressor());
bundled = ast.print_to_string();
}
fs.writeFileSync(builtFile, bundled);
}
var fileWriter = "" +
"(function( $ ) { $.widget( \"jtsage.datebox\"," +
pretty(module.exports.JTSageDateBox, 4, "PRINT", true) +
" ); })( jQuery );";
if ( framework !== "jqm" ) {
fileWriter = fileWriter +
"\n\n(function( $ ) { " +
"$(document).ready( function() { " +
"$( \"[data-role='datebox']\" ).each( function() { " +
"$( this ).datebox(); " +
" }); }); })( jQuery );\n"
}
var ast = UglifyJS.parse(fileWriter, { filename: "file1.js" });
var stream = UglifyJS.OutputStream({ beautify: true });
var code = ast.print(stream);
var preamble = [
"/*",
" * JTSage-DateBox",
" * For: " + framework,
" * Date: " + today.toJSON(),
" * http://dev.jtsage.com/DateBox/",
" * https://github.com/jtsage/jquery-mobile-datebox",
" *",
" * Copyright 2010, " + today.getFullYear() + " JTSage. and other contributors",
" * Released under the MIT license.",
" * https://github.com/jtsage/jquery-mobile-datebox/blob/master/LICENSE.txt",
" *",
" */" ].join("\n");
function _lint_js(code, args) {
var results = args.results;
var filename = args.filename;
try {
var ast = U2.parse(code, { filename: filename });
} catch(ex) {
if (ex instanceof U2.JS_Parse_Error) {
results.push({
filename : filename,
message : ex.message,
line : ex.line,
col : ex.col
});
return;
}
throw ex;
}
var m;
var warnings = [];
ast.walk(new U2.TreeWalker(function(node){
if (node instanceof U2.AST_Call
dataFilter: function(args) {
if (args.zipFilePath == 'tinymce.gzip.js') {
var source = args.data.toString().replace(/tinymce\.gzip\.php/g, page);
var ast = UglifyJS.parse(source);
ast.figure_out_scope();
ast = ast.transform(UglifyJS.Compressor());
ast.figure_out_scope();
ast.compute_char_frequency();
ast.mangle_names();
var stream = UglifyJS.OutputStream();
ast.print(stream);
args.data = stream.toString();
}
},
parse: function(content){
return UglifyJS.parse(content);
},