Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function parseClass(
classNode: estree.ClassExpression
): ParsingResult {
let innerJsxElementNode;
// If there is at least a JSXElement in the body of the class, then it's a React component.
acornWalk.simple(
classNode.body,
{
JSXElement(node: any) {
innerJsxElementNode = node;
},
},
ACORN_WALK_VISITORS
);
const inferedType: any = {
type: !isNil(innerJsxElementNode) ? InspectionType.ELEMENT : InspectionType.CLASS,
identifier: extractIdentifierName(classNode.id),
};
return {
inferedType,
module.exports = (
pAST,
pDependencies,
pModuleSystem,
pExoticRequireStrings
) => {
// var/const lalala = require('./lalala');
// require('./lalala');
// require('./lalala').doFunkyStuff();
// require('zoinks!./wappie')
// require(`./withatemplateliteral`)
// as well as renamed requires/ require wrappers
// as passed in pExoticRequireStrings ("need", "window.require")
walk.simple(
pAST,
{
CallExpression: pushRequireCallsToDependencies(
pDependencies,
pModuleSystem,
pExoticRequireStrings
)
},
// see https://github.com/acornjs/acorn/issues/746
walk.base
);
};
});
const extract = (node: Node) => {
const req =
getRequireSource(node) ||
getImportSource(node) ||
getExportSource(node);
if (req) {
const { start, end } = req;
const newPath = rewrite(req.value, options.map);
magicString.overwrite(start, end, `'${newPath}'`);
}
};
simple(ast, {
ImportDeclaration: extract,
CallExpression: extract,
ExportAllDeclaration: extract,
ExportNamedDeclaration: extract,
});
if (sourceMaps) {
file.map = magicString.generateMap();
}
file.code = magicString.toString();
}
delete bundle[key];
bundle[rewrite(key, options.map) || key] = file;
}
sourceType: 'module',
});
const remove = (node: any) => {
if (
node.callee.type === 'CallExpression' &&
node.callee.callee.name === 'Function' &&
node.callee.arguments.length === 2 &&
node.callee.arguments[0].value === 'r' &&
node.callee.arguments[1].value === 'regeneratorRuntime = r'
) {
magicString.remove(node.start, node.end);
}
};
simple(ast, {
CallExpression: remove,
});
return {
code: magicString.toString(),
map: magicString.generateMap().toString(),
};
},
};
const changeThisExpressionsToSelfIdentifier = (ast) => {
walk.simple(ast, {
ThisExpression(node) {
node.type = 'Identifier'
node.name = 'self'
},
})
}
function deleteExampleRoute(path) {
const file = readFileSync(path).toString();
const ast = acorn.Parser.extend(jsx()).parse(file, {
ranges: true,
onComment: comments,
onToken: tokens,
sourceType: 'module',
plugins: {
stage3: true,
jsx: true
}
});
try {
escodegen.attachComments(ast, comments, tokens);
walk.simple(ast, {
Program(node) {
const excludes = [
'./Pages/404',
'./Login',
'./Register',
'@/utils/core',
'@/layouts/BasicLayout',
'@/layouts/UserLayout'
];
for (let i = node.body.length - 1; i >= 0; i--) {
if (
node.body[i].type === 'ImportDeclaration' &&
excludes.indexOf(node.body[i].source.value) === -1
) {
node.body.splice(i, 1);
}
function check(node, dir) {
var known = vars[node.name];
if (!known) return;
if (dir > 0 && known.down && !known.up ||
dir < 0 && known.up && !known.down)
fail("Suspiciously infinite-looking loop", node.loc);
}
walk.simple(test, {
BinaryExpression: function(node) {
if (node.left.type == "Identifier")
store(node.left.name, compDir(node.operator));
if (node.right.type == "Identifier")
store(node.right.name, -compDir(node.operator));
}
});
walk.simple(update, {
UpdateExpression: function(node) {
if (node.argument.type == "Identifier")
check(node.argument, opDir(node.operator));
},
AssignmentExpression: function(node) {
if (node.left.type == "Identifier") {
if (node.operator == "=" && node.right.type == "BinaryExpression" && node.right.left.name == node.left.name)
check(node.left, opDir(node.right.operator));
else
check(node.left, opDir(node.operator));
}
}
});
};
src.substring(start, end)
);
}
var args = node.arguments;
var name = args[0];
var nameStr = name.name;
var expr = args[1];
var e = eval;
constants[nameStr] = {
identifier: name,
value: e(nodeToString(expr))
};
walk.simple( expr, {
Identifier: function( node ) {
ignore.push(node);
}
});
global[nameStr] = constants[nameStr].value;
}
}
});
}
const params = node.value ? node.value.params : node.params;
ret.push(...params.map((p: any) => {
switch (p.type) {
case 'AssignmentPattern':
return p.left.name;
case 'RestElement':
return '...' + p.argument.name;
default:
return p.name;
}
}));
};
walk(parsed, {
MethodDefinition: (node: any) => checkNode(node, methodName),
FunctionDeclaration: (node: any) => checkNode(node, methodName),
});
return ret;
}