babel-plugin-transform-regexp-constructors

Example

In

  1. const foo = 'ab+';
  2. var a = new RegExp(foo+'c', 'i');

Out

  1. const foo = 'ab+';
  2. var a = /ab+c/i;

Installation

  1. npm install babel-plugin-transform-regexp-constructors --save-dev

Usage

  1. {
  2. "plugins": ["transform-regexp-constructors"]
  3. }

Via CLI

  1. babel --plugins transform-regexp-constructors script.js

Via Node API

  1. require("@babel/core").transform("code", {
  2. plugins: ["transform-regexp-constructors"]
  3. });