Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace lodash 'isRegExp' usage with NodeJS util isRegExp (or a fallback when unavailable) #11856

Closed
wants to merge 18 commits into from
Closed
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/babel-types/src/converters/valueToNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @flow
import isPlainObject from "lodash/isPlainObject";
import isRegExp from "lodash/isRegExp";
import isValidIdentifier from "../validators/isValidIdentifier";
import {
identifier,
Expand All @@ -16,6 +15,18 @@ import {
binaryExpression,
} from "../builders/generated";

let nodeUtilTypes;
try {
const util = require("util");
nodeUtilTypes = util.types || util;
} catch {}

const isRegExp = value => {
return nodeUtilTypes
? nodeUtilTypes.isRegExp(value)
: Object.prototype.toString.call(value) === "[object RegExp]";
};
jayaddison marked this conversation as resolved.
Show resolved Hide resolved

export default function valueToNode(value: any): Object {
// undefined
if (value === undefined) {
Expand Down