babel-plugin-transform-regexp-constructors
Advanced tools
+12
-6
| "use strict"; | ||
| function createRegExpLiteral(args, prettify, t) { | ||
| const evaluatedArgs = args.map(a => a.evaluate()); | ||
| if (!evaluatedArgs.every(a => a.confident && typeof a.value === "string")) { | ||
| var evaluatedArgs = args.map(function (a) { | ||
| return a.evaluate(); | ||
| }); | ||
| if (!evaluatedArgs.every(function (a) { | ||
| return a.confident && typeof a.value === "string"; | ||
| })) { | ||
| return; | ||
| } | ||
| let pattern = evaluatedArgs.length >= 1 && evaluatedArgs[0].value !== "" ? evaluatedArgs[0].value : "(?:)"; | ||
| const flags = evaluatedArgs.length >= 2 ? evaluatedArgs[1].value : ""; | ||
| var pattern = evaluatedArgs.length >= 1 && evaluatedArgs[0].value !== "" ? evaluatedArgs[0].value : "(?:)"; | ||
| var flags = evaluatedArgs.length >= 2 ? evaluatedArgs[1].value : ""; | ||
@@ -25,3 +29,3 @@ pattern = new RegExp(pattern).source; | ||
| } | ||
| const regExpLiteral = createRegExpLiteral(path.get("arguments"), true, t); | ||
| var regExpLiteral = createRegExpLiteral(path.get("arguments"), true, t); | ||
| if (regExpLiteral) { | ||
@@ -32,3 +36,5 @@ path.replaceWith(regExpLiteral); | ||
| module.exports = function ({ types: t }) { | ||
| module.exports = function (_ref) { | ||
| var t = _ref.types; | ||
| return { | ||
@@ -35,0 +41,0 @@ name: "transform-regexp-constructors", |
+1
-1
| { | ||
| "name": "babel-plugin-transform-regexp-constructors", | ||
| "version": "0.3.0-alpha.5ee3078e", | ||
| "version": "0.3.0-alpha.636ae276", | ||
| "description": "This changes RegExp constructors into literals if the RegExp arguments are strings.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
2667
2.34%42
13.51%