How to use the regExpLiteral function from @babel/types

Find comprehensive JavaScript @babel/types.regExpLiteral code examples handpicked from public code repositorys.

128
129
130
131
132
133
134
135
136
137
}
if (typeof value == "string") {
  return types.stringLiteral(value);
}
if (qx.lang.Type.isRegExp(value)) {
  return types.regExpLiteral(value.toString());
}
if (qx.lang.Type.isDate(value)) {
  return types.stringLiteral(value.toString());
}
fork icon257
star icon758
watch icon0

+ 21 other calls in file

84
85
86
87
88
89
90
91
92
93
case 'string': return t.stringLiteral(v);
case 'boolean': return t.booleanLiteral(v);
case 'number': return t.numericLiteral(v);
case 'object':
  if (v === null) return t.nullLiteral();
  if (v instanceof RegExp) return t.regExpLiteral(v.source, v.flags);
  if (v instanceof Date) return template('new Date(TIME)')({ TIME: t.numericLiteral(v.getTime()) });
  if (v instanceof Function) return template(v.toString())();
  return obj2Expression(v, parent);
default: return t.identifier('undefined');
fork icon3
star icon6
watch icon1

+ 8 other calls in file

158
159
160
161
162
163
164
165
166
167
        t.memberExpression(
            t.identifier(value),
            t.identifier('replace')
        ),
        [
            t.regExpLiteral('<[^>]+>', 'g'),
            t.stringLiteral('')
        ]
    )
)
fork icon65
star icon1
watch icon1

+ 3 other calls in file

19
20
21
22
23
24
25
26
27
28
  URLToString = URL.prototype.toString,
  URLSearchParamsToString = URLSearchParams.prototype.toString;

module.exports = {
  serializeRegex(regex, record) {
    const node = t.regExpLiteral(regexSourceGetter.call(regex), regexFlagsGetter.call(regex));
    return this.wrapWithProperties(
      regex, record, node, RegExp.prototype,
      [{name: 'lastIndex', value: 0, writable: true, enumerable: false, configurable: false}]
    );
fork icon0
star icon23
watch icon2

8
9
10
11
12
13
14
15
16
17

const buildLiteral = R.cond([
    [ R.is(Number), types.numericLiteral ],
    [ R.is(String), types.stringLiteral ],
    [ R.is(Boolean), types.booleanLiteral ],
    [ R.is(RegExp), (re) => types.regExpLiteral(re.source, re.flags) ],
    [ R.is(Array), buildArrayLiteral ],
    [ R.is(Object), buildObjectLiteral ],
    [ R.T, nullary(types.nullLiteral) ]
]);
fork icon4
star icon0
watch icon1

Other functions in @babel/types

Sorted by popularity

function icon

@babel/types.identifier is the most popular function in @babel/types (20936 examples)