Skip to content

Commit

Permalink
inline isRegExp
Browse files Browse the repository at this point in the history
  • Loading branch information
hzoo committed Mar 26, 2021
1 parent 140441c commit 952092c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/babel-types/src/converters/valueToNode.ts
@@ -1,5 +1,4 @@
import isPlainObject from "lodash/isPlainObject";
import isRegExp from "lodash/isRegExp";
import isValidIdentifier from "../validators/isValidIdentifier";
import {
identifier,
Expand Down Expand Up @@ -33,6 +32,10 @@ export default valueToNode as {
(value: unknown): t.Expression;
};

function isRegExp(value): boolean {
return Object.prototype.toString.call(value) === "[object RegExp]";
}

function valueToNode(value: unknown): t.Expression {
// undefined
if (value === undefined) {
Expand Down Expand Up @@ -81,7 +84,7 @@ function valueToNode(value: unknown): t.Expression {

// regexes
if (isRegExp(value)) {
const pattern = value.source;
const pattern = (value as RegExp).source;
const flags = value.toString().match(/\/([a-z]+|)$/)[1];
return regExpLiteral(pattern, flags);
}
Expand Down

0 comments on commit 952092c

Please sign in to comment.