How to use the isImportSpecifier function from babel-types
Find comprehensive JavaScript babel-types.isImportSpecifier code examples handpicked from public code repositorys.
GitHub: chang-ke/Blog
46 47 48 49 50 51 52 53 54 55
const libraryName = source.value; /** * 第二个判断条件是判断import语句里面有没有使用 import {xxx} 的语法,如果有,就替换 * 不加这个条件的后果就是,死循环 */ if (libraryName === ref.opts.libraryName && specifiers.find(specifier => type.isImportSpecifier(specifier))) { const declarationNodes = []; specifiers.forEach(specifier => { /** 不是默认导入的 * 为什么要这么判断,因为可能会有这种写法,import React, { Component } from 'react';
3
11
2
+ 9 other calls in file
GitHub: MorningBells/taro
120 121 122 123 124 125 126 127 128 129
if (!specifiers.length) { astPath.remove() } } else if (value === PACKAGES['@tarojs/redux']) { const specifier = specifiers.find(item => { return t.isImportSpecifier(item) && item.imported.name === providerComponentName }) if (specifier) { providorImportName = specifier.local.name } else {
0
2
0
GitHub: astrocean/taro-cli-2.0.6
494 495 496 497 498 499 500 501 502 503
} source.value = '@tarojs/taro-h5'; } else if (source.value === '@tarojs/redux') { const specifier = specifiers.find(item => { return t.isImportSpecifier(item) && item.imported.name === constants_2.providerComponentName; }); if (specifier) { providerImportName = specifier.local.name; }
0
0
0
+ 23 other calls in file
290 291 292 293 294 295 296 297 298 299
astPath.remove(); } } else if (value === PACKAGES['@tarojs/redux']) { const specifier = specifiers.find(item => { return t.isImportSpecifier(item) && item.imported.name === providerComponentName; }); if (specifier) { providorImportName = specifier.local.name; }
0
0
0
+ 13 other calls in file
1 2 3 4 5 6 7 8 9 10
module.exports = function () { return { visitor: { ImportDeclaration(path,state={opts}) { console.log(path.node.specifiers, '-----------', t.isImportSpecifier(path.node.specifiers[0])); if (state.opts.library === 'lodash' && t.isImportSpecifier(path.node.specifiers[0])) { const specifiers = path.node.specifiers.map(o => { return t.importDeclaration([t.ImportDefaultSpecifier(o.local)], t.stringLiteral(`${state.opts.library}/${o.local.name}`)) }) console.log(Array.isArray(specifiers), 'arry')
0
0
0
11 12 13 14 15 16 17 18 19 20
const types = require('babel-types'); const generate = require('babel-generator').default; const isImportDeclaration = path => types.isImportDeclaration(path.node) || types.isImportSpecifier(path.parent) || types.isImportDeclaration(path.parent) || types.isImportSpecifier(path.parent) || types.isImportDefaultSpecifier(path.parent);
0
0
3
+ 3 other calls in file
babel-types.identifier is the most popular function in babel-types (4076 examples)