How to use the isImportDeclaration function from typescript

Find comprehensive JavaScript typescript.isImportDeclaration code examples handpicked from public code repositorys.

464
465
466
467
468
469
470
471
472
473
// All non-export-statements stay at the root level, the rest is wrapped in `declare global`
const exportStatements = node.statements.filter(s => s.modifiers && s.modifiers.some(m => m.kind === ts.SyntaxKind.ExportKeyword));
const otherStatements = node.statements.filter(s => !exportStatements.includes(s));

const hasExportStatements = exportStatements.length > 0;
const hasImport = otherStatements.some(s => ts.isImportDeclaration(s) || ts.isImportEqualsDeclaration(s));

return ts.updateSourceFileNode(node, [
    ...otherStatements,
    ...(hasExportStatements ? [wrapInDeclareGlobal(exportStatements.map((s) => removeDeclareModifier(s)))] : []),
fork icon116
star icon294
watch icon29

+ 5 other calls in file

156
157
158
159
160
161
162
163
164
165
const sourceFile = program.getSourceFile(filePath);

if (sourceFile) {
  ts.forEachChild(sourceFile, (node) => {
    if (
      ts.isImportDeclaration(node) ||
      ts.isExportDeclaration(node) ||
      ts.isImportEqualsDeclaration(node) ||
      ts.isExportAssignment(node)
    ) {
fork icon0
star icon0
watch icon1

+ 18 other calls in file

28
29
30
31
32
33
34
35
36
37
) {
  return ts.factory.createStringLiteral(marked.parse(node.text));
}

if (
  ts.isImportDeclaration(node) &&
  ts.isStringLiteral(node.moduleSpecifier) &&
  node.importClause.name !== undefined
) {
  /**
fork icon0
star icon0
watch icon1

Other functions in typescript

Sorted by popularity

function icon

typescript.SyntaxKind is the most popular function in typescript (82777 examples)