archunit
Version:
ArchUnit TypeScript is an architecture testing library, to specify and assert architecture rules in your TypeScript app
94 lines • 3.29 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.countDeclarations = exports.isAbstractMethodDeclaration = exports.isAbstractClassDeclaration = void 0;
const ts = __importStar(require("typescript"));
/**
* Checks if a given node is an abstract class declaration
*/
function isAbstractClassDeclaration(node) {
return (ts.isClassDeclaration(node) &&
node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AbstractKeyword) === true);
}
exports.isAbstractClassDeclaration = isAbstractClassDeclaration;
/**
* Checks if a given node is an abstract method declaration
*/
function isAbstractMethodDeclaration(node) {
return (ts.isMethodDeclaration(node) &&
node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AbstractKeyword) === true);
}
exports.isAbstractMethodDeclaration = isAbstractMethodDeclaration;
/**
* Counts the number of declarations in a source file
*/
function countDeclarations(sourceFile) {
let total = 0;
let interfaces = 0;
let abstractClasses = 0;
let abstractMethods = 0;
let concreteClasses = 0;
let functions = 0;
let variables = 0;
function visit(node) {
if (ts.isInterfaceDeclaration(node)) {
interfaces++;
total++;
}
else if (isAbstractClassDeclaration(node)) {
abstractClasses++;
total++;
}
else if (ts.isClassDeclaration(node)) {
concreteClasses++;
total++;
}
else if (isAbstractMethodDeclaration(node)) {
abstractMethods++;
total++;
}
else if (ts.isFunctionDeclaration(node)) {
functions++;
total++;
}
else if (ts.isVariableStatement(node)) {
variables += node.declarationList.declarations.length;
total += node.declarationList.declarations.length;
}
ts.forEachChild(node, visit);
}
visit(sourceFile);
return {
total,
interfaces,
abstractClasses,
abstractMethods,
concreteClasses,
functions,
variables,
};
}
exports.countDeclarations = countDeclarations;
//# sourceMappingURL=declaration-detector.js.map
;