How to use the importSpecifier function from babel-types
Find comprehensive JavaScript babel-types.importSpecifier code examples handpicked from public code repositorys.
GitHub: mpvue/mpvue-loader
73 74 75 76 77 78 79 80 81 82
// 将import Vue from 'vue' 替换为 import {Vue, createMP} from 'vue' ImportDeclaration: function (path) { if (path.node.specifiers && path.node.source && path.node.source.value === 'vue') { const specifiersValue = path.node.specifiers[0].local.name path.node.specifiers = [ t.importSpecifier(t.identifier(specifiersValue), t.identifier(specifiersValue)), t.importSpecifier(t.identifier('createMP'), t.identifier('createMP')) ] } },
49
47
12
+ 87 other calls in file
GitHub: alipay/goldfish
7 8 9 10 11 12 13 14 15 16
function getImport(path) { return path.node.specifiers.reduce((result, specifier) => { if (specifier.imported) { result.push( babelTypes.importSpecifier( babelTypes.identifier(specifier.local.name), babelTypes.identifier(specifier.imported.name), ), );
15
76
11
+ 5 other calls in file
51 52 53 54 55 56 57 58 59 60
}; const makeImportStatement = nodeKeys => { return Object.assign( t.importDeclaration( nodeKeys.map(nodeKey => t.importSpecifier(t.identifier(nodeKey), t.identifier(nodeKey))), t.stringLiteral('graphql/language/ast') ), { importKind: 'type' } );
5
52
3
+ 9 other calls in file
50 51 52 53 54 55 56 57 58 59
traverse(AST, { ImportDeclaration: { enter(path) { if (path.get('source').node.value === 'enzyme') { const imports = path.get('specifiers'); const shallowSpec = t.importSpecifier( t.identifier('shallow'), t.identifier('shallow') ); imports[0].insertAfter(shallowSpec);
2
5
3
+ 3 other calls in file
43 44 45 46 47 48 49 50 51 52
if (isDefault) { specifier = types.importDefaultSpecifier(localIdentifier); } else if (isNamespace) { specifier = types.importNamespaceSpecifier(localIdentifier); } else { specifier = types.importSpecifier( localIdentifier, typeof identifier === 'string' ? localIdentifier : types.identifier(identifier[1]) ); }
0
2
1
+ 7 other calls in file
GitHub: secti6n/taro
202 203 204 205 206 207 208 209 210 211
const stylePath = path.resolve(path.dirname(filePath), value) if (styleFiles.indexOf(stylePath) < 0) { styleFiles.push(stylePath) } const importSpecifiers = _.uniqBy(stylesImportedArr, 'originName') .map(item => t.importSpecifier(t.identifier(item.styleName), t.identifier(item.originName))) astPath.replaceWith(t.importDeclaration( importSpecifiers, t.stringLiteral(`${path.dirname(value)}/${basename}_styles`)) )
0
0
4
+ 11 other calls in file
58 59 60 61 62 63 64 65 66 67
* import type {NAMES[0], NAMES[1], ...} from 'MODULE'; */ function importTypes(names: Array<string>, module: string) { const importDeclaration = t.importDeclaration( names.map(name => t.importSpecifier(t.identifier(name), t.identifier(name)), ), t.stringLiteral(module), ); importDeclaration.importKind = 'type';
0
0
2
+ 3 other calls in file
24 25 26 27 28 29 30 31 32
if (file.usingGraphQL) { const graphqlImportDeclaration = t.importDeclaration( [ t.importSpecifier(t.identifier('graphql'), t.identifier('graphql')), t.importSpecifier(t.identifier('compose'), t.identifier('compose')), ], t.stringLiteral('react-apollo') );
0
0
4
+ 27 other calls in file
babel-types.identifier is the most popular function in babel-types (4076 examples)