@nodesecure/js-x-ray
Version:
JavaScript AST XRay analysis
29 lines • 877 B
JavaScript
import safeRegex from "safe-regex";
// Import Internal Dependencies
import { SourceFile } from "../SourceFile.js";
import { generateWarning } from "../warnings.js";
/**
* @description Search for RegExpLiteral AST Node
* @see https://github.com/estree/estree/blob/master/es5.md#regexpliteral
* @example
* /hello/
*/
function validateNode(node) {
return [
node.type === "Literal" && "regex" in node
];
}
function main(node, options) {
const { sourceFile } = options;
// We use the safe-regex package to detect whether or not regex is safe!
if (!safeRegex(node.regex.pattern)) {
sourceFile.warnings.push(generateWarning("unsafe-regex", { value: node.regex.pattern, location: node.loc }));
}
}
export default {
name: "isLiteralRegex",
validateNode,
main,
breakOnMatch: false
};
//# sourceMappingURL=isLiteralRegex.js.map