2020-11-18 10:06:59 -05:00

25 lines
536 B
JavaScript

import { declare } from "@babel/helper-plugin-utils";
import { types as t } from "@babel/core";
export default declare(api => {
api.assertVersion(7);
return {
name: "transform-sticky-regex",
visitor: {
RegExpLiteral(path) {
const { node } = path;
if (!node.flags.includes("y")) return;
path.replaceWith(
t.newExpression(t.identifier("RegExp"), [
t.stringLiteral(node.pattern),
t.stringLiteral(node.flags),
]),
);
},
},
};
});