Closed retorquere closed 1 year ago
Could you please provide code example: before and after?
One of the ways to transform regular expressions is using Traverser:
export const report = () => `Remove regular expression`;
export const fix = (path) => {
path.remove();
};
export const traverse = () => ({
RegExpLiteral(path) {
push(path);
}
});
Check out in 🐊Putout Editor
You can also use Replacer:
export const report = () => `Drop regexp`;
export const replace = () => ({
'/__a/': ({__a}, path) => {
return '';
}
});
Check out in 🐊Putout Editor
You can find more examples in sources of @putout/plugin-regexp.
I'm going to give this a try -- super thanks! This will make maintenance much easier.
I'll close it if all questions resolved, feel free to reopen if you have any questions :)
I have to maintain code that is targeted both at environments that support unicode regexes as some that don't; it'd be great if I could use putout to rewrite the code towards plain regexp (not incredibly hard), but I have to find and parse the regexes themselves. If I can find the regexes, I could use https://www.npmjs.com/package/regexp-to-ast to parse them and return the rewritten ones.