How to use the ImportDeclaration function from babel-types

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

8
9
10
11
12
13
14
15
16
17
ImportDeclaration(path, _ref = {opts:{}}){
  const specifiers = path.node.specifiers;
  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}`)
      )
    })
fork icon64
star icon68
watch icon2

193
194
195
196
197
198
199
200
201
202

// Create a AST object for `Program` that includes the imports and function
// and returns it along with the name of the function so it can be written to
// a file.
typeImports = _.uniq(typeImports).map(function (name) {
  var importStatement = t.ImportDeclaration(
    [t.ImportSpecifier(t.Identifier(name), t.Identifier(name))],
    t.StringLiteral('../types/' + name)
  )
  importStatement.importKind = 'type'
fork icon4
star icon9
watch icon2

+ 29 other calls in file

5
6
7
8
9
10
11
12
13
14
ImportDeclaration(path, _ref = {opts:{}}){
    const specifiers = path.node.specifiers;
    const source = path.node.source;
    if (!t.isImportDefaultSpecifier(specifiers[0]) ) {
        var declarations = specifiers.map((specifier) => {      //遍历  uniq extend flatten cloneDeep
            return t.ImportDeclaration(                         //创建importImportDeclaration节点
                [t.importDefaultSpecifier(specifier.local)],
                t.StringLiteral(`${source.value}/${specifier.local.name}`)
            )
        })
fork icon2
star icon11
watch icon2

8
9
10
11
12
13
14
15
16
17
// if (
//   state.opts.libraryName === source.value &&
//   !types.isImportDefaultSpecifier(specifiers[0])
// ) {
//   const declarations = specifiers.map((specifiers, index) => {
//     return types.ImportDeclaration(
//       [types.importDefaultSpecifier(specifiers.local)],
//       types.stringLiteral(`${source.value}/${specifiers.local.name}`)
//     )
//   })
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)