How to use the templateLiteral function from babel-types

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

13
14
15
16
17
18
19
20
21
22
  })
  references.styled.forEach(styledRef => {
    if (styledRef.parentPath.parentPath.type === 'TaggedTemplateExpression') {
      const quasi = styledRef.parentPath.parentPath.get('quasi')
      const val = quasi.evaluate().value.trim()
      const replacement = t.templateLiteral([t.templateElement(val)], [])
      quasi.replaceWith(replacement)
    }
  })
}
fork icon157
star icon0
watch icon2

+ 11 other calls in file

21
22
23
24
25
26
27
28
29
30
let printed = printAST(exploded) + '\n';

path.replaceWith(
  t.program([
    t.expressionStatement(
      t.templateLiteral([
        t.templateElement({ raw: printed }, true)
      ], [])
    )
  ])
fork icon6
star icon34
watch icon3

+ 11 other calls in file

40
41
42
43
44
45
46
47
48
49
      )
    )
  }
},
Import(path) {
  path.parent.arguments[0] = t.templateLiteral(
    [
      t.templateElement({
        raw: prefix,
        cooked: prefix,
fork icon1
star icon6
watch icon2

+ 19 other calls in file

30
31
32
33
34
35
36
37
38
39
  const quasis = second.quasis.slice(0);
  quasis[0] = t.templateElement({
    raw: first.value + value.raw,
    cooked: first.value + value.cooked,
  });
  return t.templateLiteral(quasis, second.expressions.slice(0));
}
if (t.isTemplateLiteral(first) && t.isStringLiteral(second)) {
  const quasi = first.quasis[first.quasis.length - 1];
  const value = typeof quasi.value === 'string' ?
fork icon0
star icon1
watch icon0

+ 41 other calls in file

217
218
219
220
221
222
223
224
225
226
  expressions = expressionList.map(item => item.value)
  quasis = [ ...templateElementItemList, templateElementLastItem ].map(item => {
    return types.templateElement({ raw: item, cooked: item }, false)
  })
}
const newTemplateLiteral = types.templateLiteral(quasis, expressions)
const objectProperty = types.objectProperty(url, newTemplateLiteral, false, false, null)

// 构造一个CallExpression
let newPoperty
fork icon3
star icon12
watch icon0

308
309
310
311
312
313
314
315
316
317
  expressions = expressionList.map(item => item.value)
  quasis = [...templateElementItemList, templateElementLastItem].map(item => {
    return types.templateElement({ raw: item, cooked: item }, false)
  })
}
const newTemplateLiteral = types.templateLiteral(quasis, expressions) //创建一个 templateLiteral   
const objectProperty = types.objectProperty(url, newTemplateLiteral, false, false, null)
// 构造一个CallExpression   
let newPoperty
if (property.name === 'replace') {
fork icon0
star icon0
watch icon0

Other functions in babel-types

Sorted by popularity

function icon

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