Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
walk: function(config) {
var call_expression = null, walker = new _uglify.TreeWalker(function(node, descend){
if (node instanceof _uglify.AST_Call) {
var tmp = call_expression;
call_expression = node;
descend();
call_expression = tmp;
return true; // prevent descending again
}
if (node instanceof _uglify.AST_String && call_expression) {
console.log("Found string: %s at %d,%d", node.getValue(),
node.start.line, node.start.col);
}
}), baseCode = _code(config);
if (baseCode.ast) {
baseCode.ast.walk(walker);
}
var i = 0,
len = ex.col,
buffer = ' ';
for (; i < len; i++) {
buffer += '-';
}
errmsg.push(buffer + '^');
}
errmsg.push('');
}
} catch (ex2) {}
throw new Error(errmsg.join('\n'));
}
// find all of the titanium symbols
var walker = new UglifyJS.TreeWalker(function (node, descend) {
if (node instanceof UglifyJS.AST_SymbolRef && tiNodeRegExp.test(node.name)) {
var p = walker.stack,
buffer = [],
symbol,
i = p.length - 1; // we already know the top of the stack is Ti
// loop until 2nd from bottom of stack since the bottom is the toplevel node which we don't care about
while (--i) {
if (p[i] instanceof UglifyJS.AST_Dot) {
buffer.push(p[i].property);
} else if (p[i] instanceof UglifyJS.AST_Symbol || p[i] instanceof UglifyJS.AST_SymbolRef) {
buffer.push(p[i].name);
} else {
break;
}
}
var originalSource = src
var hasReturn = false
var ast = uglify.parse(src)
var ref
src = src.split('')
// get a reference to the function that was inserted to add an inner context
if ((ref = ast.body).length !== 1
|| (ref = ref[0]).TYPE !== 'SimpleStatement'
|| (ref = ref.body).TYPE !== 'Call'
|| (ref = ref.expression).TYPE !== 'Dot' || ref.property !== 'call'
|| (ref = ref.expression).TYPE !== 'Function')
throw new Error('AST does not seem to represent a self-calling function')
var fn = ref
var walker = new uglify.TreeWalker(visitor)
function visitor(node, descend) {
if (node !== fn && (node.TYPE === 'Defun' || node.TYPE === 'Function')) {
return true //don't descend into functions
}
if (node.TYPE === 'Return') {
descend()
hasReturn = true
replace(node, 'return {value: ' + source(node.value) + '};')
return true //don't descend again
}
}
function source(node) {
return src.slice(node.start.pos, node.end.endpos).join('')
}
function replace(node, str) {
for (var i = node.start.pos; i < node.end.endpos; i++) {
function do_js_code(code, filename) {
var ast = U2_parse(code, { filename: filename }, errors);
if (ast) ast.walk(new U2.TreeWalker(function(node){
var m;
if (node instanceof U2.AST_Call
&& node.expression instanceof U2.AST_Dot) {
// (...).kendoSomething()
if (m = /^kendo(.*)$/.exec(node.expression.property)) {
push_uniq(widgets, m[1]);
}
// kendo.bind(...) should enable MVVM
if (node.expression.expression instanceof U2.AST_Symbol &&
node.expression.expression.name == "kendo" &&
node.expression.property == "bind") {
uses_binder = true;
}
}
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
&& node.expression instanceof U2.AST_Dot
&& node.args[0] instanceof U2.AST_Object) {
// (...).kendoSomething()
if ((m = /^kendo(.*)$/.exec(node.expression.property))) {
var widget = m[1];
check_widget_options(widget, node.args[0], warnings, node.expression.end);
}
}
}));
warnings.forEach(function(w){
w.filename = filename;
if (args.position) {
if (args.position.line == 1) w.col += args.position.col;
else w.line += args.position.line - 1;
});
}
if (ast.globals.has("module")) {
cached.difficult = true;
ast = uglify.parse(`(function(){ var exports = {}; var module = { exports: exports }; var global = this; ${project.readContent(name)}
__bbe['${name}']=module.exports; }).call(window);`);
cached.ast = ast;
project.cache[name.toLowerCase()] = cached;
order.push(cached);
return;
}
let exportsSymbol = ast.globals["exports"];
let unshiftToBody = [];
let selfExpNames = Object.create(null);
let varDecls = null;
let walker = new uglify.TreeWalker((node, descend) => {
if (node instanceof uglify.AST_Block) {
node.body = node.body
.map((stm) => {
if (stm instanceof uglify.AST_Directive) {
// skip "use strict";
return null;
}
else if (stm instanceof uglify.AST_SimpleStatement) {
let stmbody = stm
.body;
let pea = paternAssignExports(stmbody);
if (pea) {
let newName = "__export_" + pea.name;
if (selfExpNames[pea.name] &&
stmbody instanceof uglify.AST_Assign) {
stmbody.left = new uglify.AST_SymbolRef({
function readATNewFileContent(res, fileContent, fileName) {
var foundClassDef = null;
var walker = new UglifyJS.TreeWalker(function (node) {
var isAssignment = node instanceof UglifyJS.AST_Assign && node.operator == "=";
if (!isAssignment) return;
var moduleExports = node.left;
var isDotExports = moduleExports instanceof UglifyJS.AST_Dot && moduleExports.property == "exports";
if (!isDotExports) return;
var moduleVar = moduleExports.expression;
var isModuleDotExports = moduleVar instanceof UglifyJS.AST_SymbolRef && moduleVar.name == "module" && moduleVar.thedef.undeclared;
if (!isModuleDotExports) return;
var callAriaClassDefinition = node.right;
var isFnCallWithParam = callAriaClassDefinition instanceof UglifyJS.AST_Call && callAriaClassDefinition.args.length >= 1;
if (!isFnCallWithParam) return;
var ariaClassDefinition = callAriaClassDefinition.expression;
var isDotClassDefinition = ariaClassDefinition instanceof UglifyJS.AST_Dot && ariaClassDefinition.property == "classDefinition";
if (!isDotClassDefinition) return;
var ariaRef = readRequire(ariaClassDefinition.expression);
if (!(ariaRef && /^aria(templates)?\/Aria(\.js)?$/.test(ariaRef))) return;
function walkAST(ast, walker) {
var returnValue, exit = {
exit: function(ret) {
returnValue = ret;
throw exit;
}
};
try {
ast.walk(new U2.TreeWalker(function(node, descend){
return walker.call(exit, node, descend);
}));
} catch(ex) {
if (ex === exit) return returnValue;
throw ex;
}
}
function parseRequire(ast) {
ast = getAst(ast)
var deps = []
var call_expression = null
var walker = new UglifyJS.TreeWalker(function(node, descend) {
if ( node instanceof UglifyJS.AST_Call && node.start.value === 'require' && node.expression.name === 'require') {
var temp = call_expression
call_expression = node
descend()
call_expression = temp
return true
}
if (call_expression && node instanceof UglifyJS.AST_String) {
deps.push(node.getValue())
}
})
ast.walk(walker)
return deps
}