How to use the nullLiteral function from babel-types

Find comprehensive JavaScript babel-types.nullLiteral code examples handpicked from public code repositorys.

123
124
125
126
127
128
129
130
131
132
  return node.negative
    ? t.unaryExpression('-', t.identifier('Infinity'))
    : t.identifier('Infinity');
// nil -> null
case l.NullNode:
  return t.nullLiteral();
default:
  throw new Error(
    `Compile error, unknown node type ${node.constructor.name}`
  );
fork icon1
star icon10
watch icon2

+ 9 other calls in file

22
23
24
25
26
27
28
29
30
parentPath.replaceWith(
    t.jSXExpressionContainer(
        t.conditionalExpression(
            test,
            parentPath.node,
            nextElement ? nextElement : t.nullLiteral()
        )
    )
);
fork icon65
star icon2
watch icon2

+ 3 other calls in file

142
143
144
145
146
147
148
149
150
    if (t.isReturnStatement(node)) return node.argument;
    return transformNonNullConsequentOrAlternate(node);
}

function transformAlternate(node) {
    if (node == null) return t.nullLiteral();
    if (t.isReturnStatement(node)) return node.argument;
    return transformNonNullConsequentOrAlternate(node);
}
fork icon3
star icon10
watch icon2

+ 3 other calls in file

39
40
41
42
43
44
45
46
47
48
}
if (Array.isArray(value)) {
  return convertArrayToAstExpression(value)
}
if (value == null) {
  return t.nullLiteral()
}
if (typeof value === 'object') {
  return t.objectExpression(convertObjectToAstExpression(value))
}
fork icon0
star icon0
watch icon2

+ 5 other calls in file

18
19
20
21
22
23
24
25
26
27
 */
const generateLiteral = value => {
  if (_.isString(value)) return t.stringLiteral(value);
  if (_.isBoolean(value)) return t.booleanLiteral(value);
  if (_.isNumber(value)) return t.numericLiteral(value);
  if (_.isNull(value)) return t.nullLiteral();
  if (_.isArray(value)) return t.arrayExpression(value.map(generateLiteral));
  if (_.isObject(value)) {
    const properties = Object.keys(value).map(key =>
      t.objectProperty(t.identifier(key), generateLiteral(value[key]))
fork icon0
star icon0
watch icon4

+ 7 other calls in file

Other functions in babel-types

Sorted by popularity

function icon

babel-types.identifier is the most popular function in babel-types (4076 examples)