How to use the StringLiteral function from babel-types

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

10
11
12
13
14
15
16
17
18
19
const source = path.node.source;
if (!t.isImportDefaultSpecifier(specifiers[0]) ) {
  var declarations = specifiers.map((specifier, i) => {
    return t.ImportDeclaration(
      [t.importDefaultSpecifier(specifier.local)],
      t.StringLiteral(`${source.value}/${specifier.local.name}`)
    )
  })
  path.replaceWithMultiple(declarations)
}
fork icon64
star icon68
watch icon2

185
186
187
188
189
190
191
192
193
194
// declare imports for the helpers that are used in the function.
if (hasQuery) {
  imports.push(t.ImportDeclaration([t.ImportDefaultSpecifier(t.Identifier('makeQuery'))], t.StringLiteral('../helpers/makeQuery')))
}
if (hasFormData) {
  imports.push(t.ImportDeclaration([t.ImportDefaultSpecifier(t.Identifier('makeFormData'))], t.StringLiteral('../helpers/makeFormData')))
}
imports.push(t.ImportDeclaration([t.ImportDefaultSpecifier(t.Identifier('AjaxPipe'))], t.StringLiteral('../helpers/AjaxPipe')))

// Create a AST object for `Program` that includes the imports and function
fork icon4
star icon9
watch icon2

+ 119 other calls in file

211
212
213
214
215
216
217
218
219
220
} else if (type === 'number' || val instanceof Number) {
  return t.NumericLiteral(val)
} else if (type === 'boolean' || val instanceof Boolean) {
  return t.BooleanLiteral(val)
} else if (type === 'string' || val instanceof String) {
  return t.StringLiteral(val)
} else if (val instanceof RegExp) {
  return t.RegExpLiteral(val.source, val.flags)
} else if (type === 'function') {
  // anonymouse function expression can not be parsed
fork icon1
star icon3
watch icon2

+ 11 other calls in file

111
112
113
114
115
116
117
118
119
120
  !isString(path.get('arguments')[0])) {
  return;
}
const spliter = isString(path.get('arguments')[0]) ?
  path.node.arguments[0] :
  t.StringLiteral(',');
/** Deal with arrays where template string contains */
const elements = path.get('callee.object.elements');
let element;
if (elements.length === 0) {
fork icon0
star icon1
watch icon2

+ 13 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)