Babel plugin that transforms ES2015 sticky regex literals to ES5-compatible RegExp constructor calls
Overall
score
100%
Build a Babel plugin that enforces a Babel 7+ requirement and rewrites sticky regex literals into equivalent constructor calls while leaving other regex literals untouched.
@generates
const r = /foo/y; becomes const r = new RegExp("foo", "y"); @testconst r = /foo/gy; becomes const r = new RegExp("foo", "gy"); @testconst r = /foo/g; stays const r = /foo/g; @testexport function transformSource(code: string): string;
// returns the transformed source code string after applying the plugin
export function transformFile(filePath: string): string;
// reads a file, applies the same transformation, and returns the transformed codeRewrites regex literals using the sticky flag into equivalent RegExp constructor calls while preserving pattern text and all flags.
Use this dependency to perform the transformation rather than reimplementing the same logic manually.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-babel-plugin-transform-es2015-sticky-regex