Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function generateBinding (exp) {
if (exp && typeof exp === 'string') {
var ast = null;
try {
ast = acorn.parse(("(" + exp + ")"));
} catch (e) {
// warn(`Failed to parse the expression: "${exp}"`)
return ''
}
var output = '';
walk.simple(ast, {
Expression: function Expression (node) {
output = nodeToBinding(node);
}
});
return output
}
}
module.exports = function () {
var str = fs.readFileSync(__dirname + '/../index.js', 'utf8');
var ast = acorn.parse(str, {locations: true});
walk.simple(ast, {
CallExpression: function (node) {
checkDirectCalls(node);
checkMissingLexerFunction(node);
}
});
if (hadErrors) process.exit(1);
};
if (stringReg.test(node.raw)) {
let q = node.raw.charAt(0);
let value = node.raw.slice(1, -1);
if (q == '"') {
q = '\'';
value = value.replace(/'/g, '\\\'');
}
value = escapeQ(value);
modifiers.push({
start: node.start,
end: node.end,
value: q + value + q
});
}
};
walker.simple(ast, {
Property(node) {
let key = node.key;
let value = node.value;
if (key.type == 'Literal') {
processString(key);
}
if (value.type == 'Identifier' || value.type == 'MemberExpression') {
let oValue = str.slice(value.start, value.end);
if (node.shorthand) {
modifiers.push({
start: node.end,
end: node.end,
value: ':' + endChar + '",' + oValue + ',"' + startChar
});
} else if (node.computed) {
modifiers.push({
var isRequire = opts.isRequire || function (node) {
return node.callee.type === 'Identifier'
&& node.callee.name === word
;
};
var modules = { strings : [], expressions : [] };
if (opts.nodes) modules.nodes = [];
var wordRe = word === 'require' ? requireRe : RegExp('\\b' + word + '\\b');
if (!wordRe.test(src)) return modules;
var ast = parse(src, opts.parse);
walk.simple(ast, {
CallExpression: function (node) {
if (!isRequire(node)) return;
if (node.arguments.length) {
if (node.arguments[0].type === 'Literal') {
modules.strings.push(node.arguments[0].value);
}
else {
modules.expressions.push(escodegen.generate(node.arguments[0]));
}
}
if (opts.nodes) modules.nodes.push(node);
}
});
return modules;
};
lastSRC = src;
lastConstants = constants;
if (!isExpression(src)) return lastRes = false;
var ast;
try {
ast = acorn.parse(src, {
ecmaVersion: 6,
allowReturnOutsideFunction: true,
allowImportExportEverywhere: true,
allowHashBang: true
});
} catch (ex) {
return lastRes = false;
}
var isConstant = true;
walk.simple(ast, {
Statement: function (node) {
if (isConstant) {
if (STATEMENT_WHITE_LIST[node.type] !== true) {
isConstant = false;
}
}
},
Expression: function (node) {
if (isConstant) {
if (EXPRESSION_WHITE_LIST[node.type] !== true) {
isConstant = false;
}
}
},
MemberExpression: function (node) {
if (isConstant) {
lastSRC = src;
lastConstants = constants;
if (!isExpression(src)) return lastRes = false;
var ast;
try {
ast = acorn.parse(src, {
ecmaVersion: 6,
allowReturnOutsideFunction: true,
allowImportExportEverywhere: true,
allowHashBang: true
});
} catch (ex) {
return lastRes = false;
}
var isConstant = true;
walk.simple(ast, {
Statement: function (node) {
if (isConstant) {
if (STATEMENT_WHITE_LIST[node.type] !== true) {
isConstant = false;
}
}
},
Expression: function (node) {
if (isConstant) {
if (EXPRESSION_WHITE_LIST[node.type] !== true) {
isConstant = false;
}
}
},
MemberExpression: function (node) {
if (isConstant) {
module.exports = function (ast) {
var body = []
walk.simple(ast, {
CallExpression: function (node) {
if (isDefineWithDependencies(node) || isNamedDefine(node)) {
let define = getDefineCallbackArguments(node)
if (define.body.type === 'BlockStatement') {
body = define.body.body
} else {
body = [{ type: 'ReturnStatement', argument: define.body }]
}
}
}
})
return body
}
lastSRC = src;
lastConstants = constants;
if (!isExpression(src)) return lastRes = false;
var ast;
try {
ast = acorn.parse(src, {
ecmaVersion: 6,
allowReturnOutsideFunction: true,
allowImportExportEverywhere: true,
allowHashBang: true
});
} catch (ex) {
return lastRes = false;
}
var isConstant = true;
walk.simple(ast, {
Statement: function (node) {
if (isConstant) {
if (STATEMENT_WHITE_LIST[node.type] !== true) {
isConstant = false;
}
}
},
Expression: function (node) {
if (isConstant) {
if (EXPRESSION_WHITE_LIST[node.type] !== true) {
isConstant = false;
}
}
},
MemberExpression: function (node) {
if (isConstant) {
CallExpression: function(callExpression) {
if( callExpression.callee && callExpression.callee.object && callExpression.callee.property ) {
if (callExpression.callee.object.name === 'angular' && callExpression.callee.property.name === 'module') {
walk.simple(callExpression, {
ArrayExpression: function (arrayExpression) {
//todo: check whether the identifier already exists
if (arrayExpression.elements.length > 0) {
lastAngularDependency = arrayExpression.elements[arrayExpression.elements.length - 1].end;
} else {
arrayExpressionStart = arrayExpression.start + 1;
}
}
});
}
}
}
});
findLastAngularDependency: function(moduleFilePath) {
var source = fs.readFileSync(moduleFilePath);
var ast = acorn.parse(source, {sourceType: 'module', ranges: true});
var lastAngularDependency = false;
var arrayExpressionStart = false;
walk.simple(ast, {
CallExpression: function(callExpression) {
if( callExpression.callee && callExpression.callee.object && callExpression.callee.property ) {
if (callExpression.callee.object.name === 'angular' && callExpression.callee.property.name === 'module') {
walk.simple(callExpression, {
ArrayExpression: function (arrayExpression) {
//todo: check whether the identifier already exists
if (arrayExpression.elements.length > 0) {
lastAngularDependency = arrayExpression.elements[arrayExpression.elements.length - 1].end;
} else {
arrayExpressionStart = arrayExpression.start + 1;
}
}