How to use the isTemplateLiteral function from @babel/types

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

1
2
3
4
5
6
7
8
9
10
const hasChinese = /[\u4e00-\u9fa5]/;
function isPlusExpression(node) {
  return node.type === 'BinaryExpression' && node.operator === '+';
}
function isLiteral(node) {
  return t.isTemplateLiteral(node) || t.isStringLiteral(node);
}
function needTranslate(node) {
  if (t.isStringLiteral(node)) {
    return hasChinese.test(node.value);
fork icon0
star icon3
watch icon2

+ 3 other calls in file

125
126
127
128
129
130
131
132
133
function compileImportExpressionString(node) {
  return `import('${getPackageName(node)}').then(res => console.log(res));`;
}

function getPackageName(node) {
  return t.isTemplateLiteral(node.arguments[0])
    ? node.arguments[0].quasis[0].value.raw
    : node.arguments[0].value;
}
fork icon80
star icon0
watch icon286

+ 7 other calls in file

91
92
93
94
95
96
97
98
99
100
// module.
state.isCJS = true;

// Check for nested string and template literals.
const isString = t.isStringLiteral(node.arguments[0]);
const isLiteral = t.isTemplateLiteral(node.arguments[0]);

// Normalize the string value, default to the standard string
// literal format of `{ value: "" }`.
let str = null;
fork icon0
star icon1
watch icon1

+ 58 other calls in file

52
53
54
55
56
57
58
59
60
61
    t.isIdentifier(expr.tag, {name: identifierName})
) {
    const {quasi} = expr;

    if (
        t.isTemplateLiteral(quasi) &&
        quasi.expressions &&
        quasi.expressions.length
    ) {
        identifier = quasi.expressions[0];
fork icon0
star icon0
watch icon2

+ 11 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 (20936 examples)