parse-imports-ts
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -32,2 +32,3 @@ "use strict"; | ||
exports.parse = void 0; | ||
/* eslint-disable @typescript-eslint/no-use-before-define */ | ||
var typescript_1 = __importDefault(require("typescript")); | ||
@@ -72,16 +73,20 @@ var types_1 = require("./types"); | ||
var result = []; | ||
var index = 0; | ||
var children = []; | ||
typescript_1.default.forEachChild(importDeclaration, function (child) { | ||
if (index === 0 && !typescript_1.default.isImportClause(child)) { | ||
return; | ||
} | ||
var type = types_1.ImportedPackageType.NormalImport; | ||
if (index === 1 && typescript_1.default.isStringLiteral(child)) { | ||
children.push(child); | ||
}); | ||
if (children.length === 2) { | ||
if (typescript_1.default.isImportClause(children[0]) && typescript_1.default.isStringLiteral(children[1])) { | ||
result.push({ | ||
name: (0, get_package_name_1.getPackageName)(child.text), | ||
type: type, | ||
name: (0, get_package_name_1.getPackageName)(children[1].text), | ||
type: types_1.ImportedPackageType.NormalImport, | ||
}); | ||
} | ||
index += 1; | ||
}); | ||
else { | ||
children.forEach(function (child) { return result.push.apply(result, __spreadArray([], __read(parseTsNode(child)), false)); }); | ||
} | ||
} | ||
else { | ||
children.forEach(function (child) { return result.push.apply(result, __spreadArray([], __read(parseTsNode(child)), false)); }); | ||
} | ||
return result; | ||
@@ -92,38 +97,50 @@ } | ||
var result = []; | ||
var index = 0; | ||
var isDynamicImport = function (child) { return child.kind === typescript_1.default.SyntaxKind.ImportKeyword; }; | ||
var isRequire = function (child) { return typescript_1.default.isIdentifier(child) && child.getText() === 'require'; }; | ||
var isImport = function (child) { return isDynamicImport(child) || isRequire(child); }; | ||
var children = []; | ||
typescript_1.default.forEachChild(callExpression, function (child) { | ||
if (index === 0 && !isImport(child)) { | ||
return; | ||
} | ||
if (index === 1 && typescript_1.default.isStringLiteral(child)) { | ||
children.push(child); | ||
}); | ||
if (children.length === 2) { | ||
if (isImport(children[0]) && typescript_1.default.isStringLiteral(children[1])) { | ||
result.push({ | ||
name: (0, get_package_name_1.getPackageName)(child.text), | ||
name: (0, get_package_name_1.getPackageName)(children[1].text), | ||
type: type, | ||
}); | ||
} | ||
index += 1; | ||
}); | ||
else { | ||
children.forEach(function (child) { return result.push.apply(result, __spreadArray([], __read(parseTsNode(child)), false)); }); | ||
} | ||
} | ||
else { | ||
children.forEach(function (child) { return result.push.apply(result, __spreadArray([], __read(parseTsNode(child)), false)); }); | ||
} | ||
return result; | ||
} | ||
function parseTsNode(node) { | ||
var result = []; | ||
if (typescript_1.default.isExportDeclaration(node)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsExportDeclaration(node)), false)); | ||
} | ||
else if (typescript_1.default.isImportDeclaration(node)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsImportDeclaration(node)), false)); | ||
} | ||
else if (typescript_1.default.isImportEqualsDeclaration(node)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsEqualsDeclaration(node)), false)); | ||
} | ||
else if (typescript_1.default.isCallExpression(node)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsCallExpression(node)), false)); | ||
} | ||
else { | ||
typescript_1.default.forEachChild(node, function (child) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsNode(child)), false)); | ||
}); | ||
} | ||
return result; | ||
} | ||
function parseTsSourceFile(node) { | ||
var result = []; | ||
typescript_1.default.forEachChild(node, function (child) { | ||
if (typescript_1.default.isExportDeclaration(child)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsExportDeclaration(child)), false)); | ||
} | ||
else if (typescript_1.default.isImportDeclaration(child)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsImportDeclaration(child)), false)); | ||
} | ||
else if (typescript_1.default.isImportEqualsDeclaration(child)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsEqualsDeclaration(child)), false)); | ||
} | ||
else if (typescript_1.default.isCallExpression(child)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsCallExpression(child)), false)); | ||
} | ||
else { | ||
result.push.apply(result, __spreadArray([], __read(parseTsSourceFile(child)), false)); | ||
} | ||
result.push.apply(result, __spreadArray([], __read(parseTsNode(child)), false)); | ||
}); | ||
@@ -130,0 +147,0 @@ return result; |
@@ -26,2 +26,3 @@ var __read = (this && this.__read) || function (o, n) { | ||
}; | ||
/* eslint-disable @typescript-eslint/no-use-before-define */ | ||
import ts from 'typescript'; | ||
@@ -66,16 +67,20 @@ import { ImportedPackageType } from './types'; | ||
var result = []; | ||
var index = 0; | ||
var children = []; | ||
ts.forEachChild(importDeclaration, function (child) { | ||
if (index === 0 && !ts.isImportClause(child)) { | ||
return; | ||
} | ||
var type = ImportedPackageType.NormalImport; | ||
if (index === 1 && ts.isStringLiteral(child)) { | ||
children.push(child); | ||
}); | ||
if (children.length === 2) { | ||
if (ts.isImportClause(children[0]) && ts.isStringLiteral(children[1])) { | ||
result.push({ | ||
name: getPackageName(child.text), | ||
type: type, | ||
name: getPackageName(children[1].text), | ||
type: ImportedPackageType.NormalImport, | ||
}); | ||
} | ||
index += 1; | ||
}); | ||
else { | ||
children.forEach(function (child) { return result.push.apply(result, __spreadArray([], __read(parseTsNode(child)), false)); }); | ||
} | ||
} | ||
else { | ||
children.forEach(function (child) { return result.push.apply(result, __spreadArray([], __read(parseTsNode(child)), false)); }); | ||
} | ||
return result; | ||
@@ -86,38 +91,50 @@ } | ||
var result = []; | ||
var index = 0; | ||
var isDynamicImport = function (child) { return child.kind === ts.SyntaxKind.ImportKeyword; }; | ||
var isRequire = function (child) { return ts.isIdentifier(child) && child.getText() === 'require'; }; | ||
var isImport = function (child) { return isDynamicImport(child) || isRequire(child); }; | ||
var children = []; | ||
ts.forEachChild(callExpression, function (child) { | ||
if (index === 0 && !isImport(child)) { | ||
return; | ||
} | ||
if (index === 1 && ts.isStringLiteral(child)) { | ||
children.push(child); | ||
}); | ||
if (children.length === 2) { | ||
if (isImport(children[0]) && ts.isStringLiteral(children[1])) { | ||
result.push({ | ||
name: getPackageName(child.text), | ||
name: getPackageName(children[1].text), | ||
type: type, | ||
}); | ||
} | ||
index += 1; | ||
}); | ||
else { | ||
children.forEach(function (child) { return result.push.apply(result, __spreadArray([], __read(parseTsNode(child)), false)); }); | ||
} | ||
} | ||
else { | ||
children.forEach(function (child) { return result.push.apply(result, __spreadArray([], __read(parseTsNode(child)), false)); }); | ||
} | ||
return result; | ||
} | ||
function parseTsNode(node) { | ||
var result = []; | ||
if (ts.isExportDeclaration(node)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsExportDeclaration(node)), false)); | ||
} | ||
else if (ts.isImportDeclaration(node)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsImportDeclaration(node)), false)); | ||
} | ||
else if (ts.isImportEqualsDeclaration(node)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsEqualsDeclaration(node)), false)); | ||
} | ||
else if (ts.isCallExpression(node)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsCallExpression(node)), false)); | ||
} | ||
else { | ||
ts.forEachChild(node, function (child) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsNode(child)), false)); | ||
}); | ||
} | ||
return result; | ||
} | ||
function parseTsSourceFile(node) { | ||
var result = []; | ||
ts.forEachChild(node, function (child) { | ||
if (ts.isExportDeclaration(child)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsExportDeclaration(child)), false)); | ||
} | ||
else if (ts.isImportDeclaration(child)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsImportDeclaration(child)), false)); | ||
} | ||
else if (ts.isImportEqualsDeclaration(child)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsEqualsDeclaration(child)), false)); | ||
} | ||
else if (ts.isCallExpression(child)) { | ||
result.push.apply(result, __spreadArray([], __read(parseTsCallExpression(child)), false)); | ||
} | ||
else { | ||
result.push.apply(result, __spreadArray([], __read(parseTsSourceFile(child)), false)); | ||
} | ||
result.push.apply(result, __spreadArray([], __read(parseTsNode(child)), false)); | ||
}); | ||
@@ -124,0 +141,0 @@ return result; |
{ | ||
"name": "parse-imports-ts", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable @typescript-eslint/no-use-before-define */ | ||
import ts from 'typescript'; | ||
@@ -49,16 +50,18 @@ import { ImportedPackage, ImportedPackageType } from './types'; | ||
const result: ImportedPackage[] = []; | ||
let index = 0; | ||
const children: ts.Node[] = []; | ||
ts.forEachChild(importDeclaration, (child: ts.Node) => { | ||
if (index === 0 && !ts.isImportClause(child)) { | ||
return; | ||
} | ||
const type = ImportedPackageType.NormalImport; | ||
if (index === 1 && ts.isStringLiteral(child)) { | ||
children.push(child); | ||
}); | ||
if (children.length === 2) { | ||
if (ts.isImportClause(children[0]) && ts.isStringLiteral(children[1])) { | ||
result.push({ | ||
name: getPackageName(child.text), | ||
type, | ||
name: getPackageName(children[1].text), | ||
type: ImportedPackageType.NormalImport, | ||
}); | ||
} else { | ||
children.forEach((child) => result.push(...parseTsNode(child))); | ||
} | ||
index += 1; | ||
}); | ||
} else { | ||
children.forEach((child) => result.push(...parseTsNode(child))); | ||
} | ||
return result; | ||
@@ -70,35 +73,46 @@ } | ||
const result: ImportedPackage[] = []; | ||
let index = 0; | ||
const isDynamicImport = (child: ts.Node) => child.kind === ts.SyntaxKind.ImportKeyword; | ||
const isRequire = (child: ts.Node) => ts.isIdentifier(child) && child.getText() === 'require'; | ||
const isImport = (child: ts.Node) => isDynamicImport(child) || isRequire(child); | ||
const children: ts.Node[] = []; | ||
ts.forEachChild(callExpression, (child: ts.Node) => { | ||
if (index === 0 && !isImport(child)) { | ||
return; | ||
} | ||
if (index === 1 && ts.isStringLiteral(child)) { | ||
children.push(child); | ||
}); | ||
if (children.length === 2) { | ||
if (isImport(children[0]) && ts.isStringLiteral(children[1])) { | ||
result.push({ | ||
name: getPackageName(child.text), | ||
name: getPackageName(children[1].text), | ||
type, | ||
}); | ||
} else { | ||
children.forEach((child) => result.push(...parseTsNode(child))); | ||
} | ||
index += 1; | ||
}); | ||
} else { | ||
children.forEach((child) => result.push(...parseTsNode(child))); | ||
} | ||
return result; | ||
} | ||
function parseTsNode(node: ts.Node): ImportedPackage[] { | ||
const result: ImportedPackage[] = []; | ||
if (ts.isExportDeclaration(node)) { | ||
result.push(...parseTsExportDeclaration(node)); | ||
} else if (ts.isImportDeclaration(node)) { | ||
result.push(...parseTsImportDeclaration(node)); | ||
} else if (ts.isImportEqualsDeclaration(node)) { | ||
result.push(...parseTsEqualsDeclaration(node)); | ||
} else if (ts.isCallExpression(node)) { | ||
result.push(...parseTsCallExpression(node)); | ||
} else { | ||
ts.forEachChild(node, (child: ts.Node) => { | ||
result.push(...parseTsNode(child)); | ||
}); | ||
} | ||
return result; | ||
} | ||
function parseTsSourceFile(node: ts.Node): ImportedPackage[] { | ||
const result: ImportedPackage[] = []; | ||
ts.forEachChild(node, (child: ts.Node) => { | ||
if (ts.isExportDeclaration(child)) { | ||
result.push(...parseTsExportDeclaration(child)); | ||
} else if (ts.isImportDeclaration(child)) { | ||
result.push(...parseTsImportDeclaration(child)); | ||
} else if (ts.isImportEqualsDeclaration(child)) { | ||
result.push(...parseTsEqualsDeclaration(child)); | ||
} else if (ts.isCallExpression(child)) { | ||
result.push(...parseTsCallExpression(child)); | ||
} else { | ||
result.push(...parseTsSourceFile(child)); | ||
} | ||
result.push(...parseTsNode(child)); | ||
}); | ||
@@ -105,0 +119,0 @@ return result; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44930
44
706