How to use the isImportDefaultSpecifier function from babel-types

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

6
7
8
9
10
11
12
13
14
15
// path是捕获路径 state是状态对象 opts是你传给babel插件的选项 {"library": "lodash"}
enter(path, state) {
  let node = path.node
  let specifiers = node.specifiers
  let source = node.source
  if (state.opts.library === source.value && t.isImportDefaultSpecifier(specifiers[0])) {
    let declaration = specifiers.map(specifier => {
      let importDefaultSpecifier = t.importDefaultSpecifier(specifier.local)
      t.importDeclaration([importDefaultSpecifier], t.stringLiteral(`${source.value}/${specifier.imported.name}`))
    })
fork icon3
star icon16
watch icon2

17
18
19
20
21
22
23
24
25
26
let mutated = false

traverse(ast, {
  ImportDeclaration(traversedPath) {
    if (traversedPath.node.specifiers.length === 1 &&
      t.isImportDefaultSpecifier(traversedPath.node.specifiers[0])) {
      // retrieve the name of the variable assigned to the imported css
      const importName = traversedPath.node.specifiers[0].local.name

      // resolve the real import path
fork icon0
star icon13
watch icon3

+ 3 other calls in file

9
10
11
12
13
14
15
16
17
18
const libraryName = source.value;

// 判断是否是需要按需加载的库
const isBelong = state.opts.libraryName === libraryName;
// 判断是否是 默认导入
const isDefault = types.isImportDefaultSpecifier(specifiers[0]);
// 判断是否是 * as 方式导入
const isAll = types.isImportNamespaceSpecifier(specifiers[0]);

if (isBelong && !isDefault && !isAll) {
fork icon0
star icon3
watch icon2

+ 3 other calls in file

486
487
488
489
490
491
492
493
494
495
enter: (astPath) => {
    const node = astPath.node;
    const source = node.source;
    const specifiers = node.specifiers;
    if (source.value === '@tarojs/taro') {
        const specifier = specifiers.find(item => t.isImportDefaultSpecifier(item));
        if (specifier) {
            taroImportDefaultName = astConvert_1.convertAstExpressionToVariable(specifier.local);
        }
        source.value = '@tarojs/taro-h5';
fork icon0
star icon0
watch icon0

+ 35 other calls in file

14
15
16
17
18
19
20
21
22
23
const isImportDeclaration = path => 
  types.isImportDeclaration(path.node) ||
  types.isImportSpecifier(path.parent) ||
  types.isImportDeclaration(path.parent) ||
  types.isImportSpecifier(path.parent) ||
  types.isImportDefaultSpecifier(path.parent);
  
function classname(str) {
  return str.replace(/-/g, ' ').replace(/(?:^\w|[A-Z]|\b\w)/g, function (letter, index) {
    return letter.toUpperCase();
fork icon0
star icon0
watch icon3

Other functions in babel-types

Sorted by popularity

function icon

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