CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel-plugin-transform-es2015-sticky-regex

Babel plugin that transforms ES2015 sticky regex literals to ES5-compatible RegExp constructor calls

Overall
score

100%

Overview
Eval results
Files

task.mdevals/scenario-2/

Sticky Regex Rewriter

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

Capabilities

Sticky literal rewriting

  • Input const r = /foo/y; becomes const r = new RegExp("foo", "y"); @test
  • Input const r = /foo/gy; becomes const r = new RegExp("foo", "gy"); @test

Non-sticky passthrough

  • Input const r = /foo/g; stays const r = /foo/g; @test

Babel version gate

  • Loading the plugin with a Babel major version below 7 throws a clear error explaining that Babel 7 or later is required. @test

API

export 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 code

Dependencies { .dependencies }

@babel/plugin-transform-sticky-regex { .dependency }

Rewrites 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

tile.json