Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function findModules(path, {imports, scope}) {
let result = [];
estraverse.traverse(scope, {
enter(node) {
switch (node.type) {
case 'MemberExpression':
if (includes(imports, node.object.name)) {
if (node.computed) {
let msg = `Could not id computed function ${node.object.name}[${node.property.name}]`;
throw new Error(msg, path);
}
result.push(node.property.name);
}
break;
case 'CallExpression': { // Detect chaining
let callee = node;
let props = [];
while (callee = callee.callee) {
if (callee.property) {
function processRecurFormIfAny(rootNode, actualArgs, yy) {
var hasRecurForm = false;
estraverse.traverse(rootNode, {
enter: function (node) {
if (node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration') {
return estraverse.VisitorOption.Skip;
} else if (node.type === 'BlockStatement' && node.recurBlock) {
hasRecurForm = true;
var body = node.body;
// get rid of return statement
var lastStmt = body.length > 0 ? body[body.length-1] : null;
if (lastStmt && lastStmt.type === 'ReturnStatement') {
lastStmt.type = 'ExpressionStatement';
lastStmt.expression = lastStmt.argument;
delete lastStmt.argument;
}
estraverse.traverse(node, {
it(testSource, () => {
const ast = espree.parse(testSource, { ecmaVersion: 6 });
const scope = escope.analyze(ast, { ignoreEval: true, ecmaVersion: 6, sourceType: 'script', nodejsScope: true });
estraverse.traverse(ast, {
enter (node, parent) {
node.parent = parent;
},
});
assert.strictEqual(utils.getSourceCodeIdentifiers(scope, ast).size, CASES[testSource]);
});
});
function renderAST(ast, astElement) {
let nodeElements = new Map();
estraverse.traverse(ast, {
enter: (node, parent) => {
let parentElement = parent ? nodeElements.get(parent).children(".children") : astElement;
let nodeElement = $("<div>", { class: "node" }).appendTo(parentElement);
let typeElement = $("<div>", { class: "type", text: node.type }).appendTo(nodeElement);
switch (node.type) {
case "Literal":
$("<span>", { class: "value", text: node.value }).appendTo(typeElement);
typeElement.addClass("leaf");
break;
case "Identifier":
$("<span>", { class: "name", text: node.name }).appendTo(typeElement);
typeElement.addClass("leaf");
break;
default:
let childrenElement = $("<div>", { class: "children" }).hide().appendTo(nodeElement);</div></span></span></div></div>
private getCalleeBlockStatement (targetNode: ESTree.Node, name: string): ESTree.BlockStatement | null {
let calleeBlockStatement: ESTree.BlockStatement | null = null;
estraverse.traverse(targetNode, {
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): estraverse.VisitorOption | void => {
if (
NodeGuards.isFunctionExpressionNode(node) &&
parentNode &&
NodeGuards.isVariableDeclaratorNode(parentNode) &&
NodeGuards.isIdentifierNode(parentNode.id) &&
parentNode.id.name === name
) {
calleeBlockStatement = node.body;
return estraverse.VisitorOption.Break;
}
}
});
return calleeBlockStatement;
vect2tovec3: function(node) {
walk.traverse(node, {
enter: function(node) {
if(node.type == Syntax.NewExpression && ANNO(node).isOfKind(Shade.OBJECT_KINDS.FLOAT2)) {
if(node.arguments.length == 2) {
node.arguments.push({
type: Syntax.Literal,
value: 1
});
}
}
}
});
},
moduleToBeIgnored,
parentHasFunctionExpressionArgument,
defaultRange = defaultValues.defaultRange,
defaultLOC = defaultValues.defaultLOC,
range = node.range || defaultRange,
loc = node.loc || defaultLOC,
dependencyBlacklist = defaultValues.dependencyBlacklist,
shouldOptimize;
startLineNumber = isDefine || isRequire ? node.expression.loc.start.line : node && node.loc && node.loc.start ? node.loc.start.line : null;
shouldBeIgnored = (kclean.matchingCommentLineNumbers[startLineNumber] || kclean.matchingCommentLineNumbers[startLineNumber - 1]);
if(utils.isAMDConditional(node)) {
estraverse.traverse(node, {
'enter': function(node) {
var normalizedModuleName;
if(utils.isDefine(node, kclean)) {
if(node.expression && node.expression.arguments && node.expression.arguments.length) {
if(node.expression.arguments[0].type === 'Literal' && node.expression.arguments[0].value) {
normalizedModuleName = normalizeModuleName.call(kclean, node.expression.arguments[0].value);
if(options.transformAMDChecks !== true) {
kclean.conditionalModulesToIgnore[normalizedModuleName] = true;
} else {
kclean.conditionalModulesToNotOptimize[normalizedModuleName] = true;
}
if(options.createAnonymousAMDModule === true) {
kclean.storedModules[normalizedModuleName] = false;
node.expression.arguments.shift();
}
}
.forEach((declarationNode: ESTree.VariableDeclarator) => {
estraverse.traverse(declarationNode.id, {
enter: (node: ESTree.Node) => {
if (NodeGuards.isPropertyNode(node)) {
return estraverse.VisitorOption.Skip;
}
if (NodeGuards.isIdentifierNode(node)) {
callback(node);
}
}
});
});
}
export function splitSTORYOF(ast, source) {
let lastIndex = 0;
const parts = [source];
estraverse.traverse(ast, {
fallback: 'iteration',
enter: node => {
patchNode(node);
if (node.type === 'CallExpression') {
lastIndex = handleSTORYOF(node, parts, source, lastIndex);
}
},
});
return parts;
}
export function splitExports(ast, source) {
module.exports = function instrument(source) {
var ast = esprima.parse(source);
var firstRequireDeclarationIndex;
var requireDeclarationsByName = {};
estraverse.traverse(ast, {
enter: function (node, parent) {
if (t.isRequireDeclaration(node)) {
if (!firstRequireDeclarationIndex) {
firstRequireDeclarationIndex = parent.body.indexOf(node);
}
requireDeclarationsByName[node.declarations[0].id.name] = node.declarations[0].init.arguments[0].value
}
}
});
estraverse.replace(ast, {
enter: function (node) {
if (t.isTopLevelAPIRender(node)) {
var rootWrapperTemplate = esprima.parse(
'__electronHot__.registerRoot(ARGS)'
);