How to use the isImportDeclaration function from @babel/types

Find comprehensive JavaScript @babel/types.isImportDeclaration code examples handpicked from public code repositorys.

140
141
142
143
144
145
146
147
148
149
    });

    [{node: IMPORT}] = FILE.path.get('body').filter(p => {
        const {node} = p;
        return (
            t.isImportDeclaration(node) &&
            node.source.value === moduleName
        );
    });
}
fork icon15
star icon363
watch icon0

+ 29 other calls in file

163
164
165
166
167
168
169
170
171
172
    nameHint: 'styled',
  });

  [{ node: IMPORT }] = FILE.path.get('body').filter((p) => {
    const { node } = p;
    return t.isImportDeclaration(node) && node.source.value === moduleName;
  });
}

if (imports[name]) return imports[name];
fork icon38
star icon0
watch icon0

+ 3 other calls in file

90
91
92
93
94
95
96
97
98
99

// 覆盖ExportAllDeclaration、ExportNamedDeclaration、ImportDeclaration
if (
  t.isExportAllDeclaration(path.node) ||
  t.isExportNamedDeclaration(path.node) ||
  t.isImportDeclaration(path.node)
) {
  if (
    path.node &&
    path.node.source &&
fork icon1
star icon5
watch icon2

4
5
6
7
8
9
10
11
12
13
const t = require('@babel/types');
const prettierFormat = require('./prettierFormat');

const addImportDeclaration = (node, specifiers, importPath) => {
  const { body } = node;
  const lastImportIndex = _.findLastIndex(body, (item) => t.isImportDeclaration(item));

  const importSpecifiers = (Array.isArray(specifiers) ? specifiers : [specifiers]).map((specifier) => {
    return specifier.imported
      ? t.importSpecifier(t.identifier(specifier.local), t.identifier(specifier.imported))
fork icon3
star icon3
watch icon11

+ 3 other calls in file

20
21
22
23
24
25
26
27
28
29
switch (node == null ? void 0 : node.type) {
  default:
    if (t.isModuleDeclaration(node)) {
      if ((t.isExportAllDeclaration(node) || t.isExportNamedDeclaration(node) || t.isImportDeclaration(node)) && node.source) {
        gatherNodeParts(node.source, parts);
      } else if ((t.isExportNamedDeclaration(node) || t.isImportDeclaration(node)) && node.specifiers && node.specifiers.length) {
        for (const e of node.specifiers) gatherNodeParts(e, parts);
      } else if ((t.isExportDefaultDeclaration(node) || t.isExportNamedDeclaration(node)) && node.declaration) {
        gatherNodeParts(node.declaration, parts);
      }
fork icon0
star icon1
watch icon1

+ 16 other calls in file

28
29
30
31
32
33
34
35
36
37
jsAst = initState(jsAst, store);
templateAst = initTemplate(templateAst, null, new Set());
const { code: jsCode } = generator(
  t.program(
    [
      ...jsAst.program.body.filter((item) => t.isImportDeclaration(item)),
      t.functionDeclaration(
        t.identifier("VueTest"),
        [t.identifier("props")],
        t.blockStatement([
fork icon0
star icon0
watch icon1

+ 213 other calls in file

364
365
366
367
368
369
370
371
372
373
    const declaration = collectTypeDeclaration(seg);
    if (declaration) {
        state.typeDefines.push(declaration);
    }
});
const imports = path.node.body.filter((segment) => t.isImportDeclaration(segment));
for (let i = 0; i < imports.length; i++) {
    const segment = path.node.body[i];
    if (!t.isImportDeclaration(segment)) {
        continue;
fork icon0
star icon0
watch icon1

+ 25 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 (20936 examples)