How to use the assertStringLiteral function from @babel/types

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

17
18
19
20
21
22
23
24
25
26
    };
  });
} else if (t.isStringLiteral(arg)) {
  return arg.value;
} else if (t.isLogicalExpression(arg, {operator: '&&'})) {
  t.assertStringLiteral(arg.right);

  return {
    test: extractNode(use, arg.left),
    value: arg.right.value
fork icon18
star icon195
watch icon7

+ 17 other calls in file

102
103
104
105
106
107
108
109

function extractRequiredModule (node) {
  t.assertCallExpression(node);
  t.assertIdentifier(node.callee, { name: 'require' });
  var arg = node.arguments[0];
  t.assertStringLiteral(arg);
  return arg.value;
}
fork icon11
star icon33
watch icon8

+ 13 other calls in file

108
109
110
111
112
113
114
115
116
117

    const nestedString = firstNestedObject.properties[0].value;
    babelTypes.assertStringLiteral(firstNestedObject.properties[0].key, { value: 'bar' });
    babelTypes.assertStringLiteral(nestedString, { value: 'baz' });

    babelTypes.assertStringLiteral(ast.properties[1].key, { value: 'test' });
    babelTypes.assertStringLiteral(ast.properties[1].value, { value: 'value' });

    t.pass();
});
fork icon4
star icon8
watch icon4

+ 23 other calls in file

72
73
74
75
76
77
78
79
80
81
    baz: 1
});

t.is(ast.properties.length, 2);
babelTypes.assertStringLiteral(ast.properties[0].key, { value: 'foo' });
babelTypes.assertStringLiteral(ast.properties[0].value, { value: 'bar' });
babelTypes.assertStringLiteral(ast.properties[1].key, { value: 'baz' });
babelTypes.assertNumericLiteral(ast.properties[1].value, { value: 1 });

t.pass();
fork icon4
star icon0
watch icon1

+ 47 other calls in file

6
7
8
9
10
11
12
13
14
15
/**
 * @type {import('tscm/macro').Macro}
 */
module.exports.yaml = function ({ node, fileName }) {
  const stringLiteral = node.arguments[0];
  t.assertStringLiteral(stringLiteral);
  const ymlFile = fs.readFileSync(
    path.join(path.parse(fileName).dir, stringLiteral.value),
    'utf8'
  );
fork icon0
star icon1
watch icon1

23
24
25
26
27
28
29
30
31
32
/**
 * @type {import('tscm/macro').Macro}
 */
module.exports.json_schema = function json_schema({ node, fileName }) {
  const pathStringLiteral = node.arguments[0];
  t.assertStringLiteral(pathStringLiteral);
  const filePath = pathStringLiteral.value;

  const schemaString = fs.readFileSync(
    path.join(path.parse(fileName).dir, filePath),
fork icon0
star icon1
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)