@hadss/hmrouter-plugin
Version:
HMRouter Compiler Plugin
52 lines (51 loc) • 2.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComponentAnalyzer = void 0;
const AbstractAnnotationAnalyzer_1 = require("./interface/AbstractAnnotationAnalyzer");
const DecoratorParser_1 = require("./utils/DecoratorParser");
const constants_1 = require("../constants");
class ComponentAnalyzer extends AbstractAnnotationAnalyzer_1.AbstractAnnotationAnalyzer {
constructor(constantResolver) {
super(constantResolver);
this.name = 'ComponentAnalyzer';
}
analyze(sourceFile, filePath, context) {
const results = [];
sourceFile.getClasses().forEach((cls) => {
this.analyzeClassDecorators(cls, filePath, sourceFile, results);
this.analyzeMethodDecorators(cls, filePath, sourceFile, results);
});
context.addAnalyzeResults(results);
}
analyzeClassDecorators(cls, filePath, sourceFile, results) {
cls.getDecorators().forEach((decorator) => {
if ([
constants_1.AnnotationConstants.INTERCEPTOR_ANNOTATION,
constants_1.AnnotationConstants.LIFECYCLE_ANNOTATION,
constants_1.AnnotationConstants.ANIMATOR_ANNOTATION,
constants_1.AnnotationConstants.SERVICE_PROVIDE_ANNOTATION,
].includes(decorator.getName())) {
const result = this.addToResultSet(decorator, cls.getName(), filePath, sourceFile);
results.push(result);
}
});
}
analyzeMethodDecorators(cls, filePath, sourceFile, results) {
cls.getMethods().forEach((method) => {
method.getDecorators().forEach((decorator) => {
if (decorator.getName() === constants_1.AnnotationConstants.SERVICE_ANNOTATION) {
const serviceResult = this.addToResultSet(decorator, cls.getName(), filePath, sourceFile);
serviceResult.functionName = method.getName();
results.push(serviceResult);
}
});
});
}
addToResultSet(decorator, componentName, filePath, sourceFile) {
const decoratorResult = DecoratorParser_1.DecoratorParser.parseDecorator(decorator, this.constantResolver, sourceFile, filePath);
decoratorResult.name = componentName;
decoratorResult.sourceFilePath = filePath;
return decoratorResult;
}
}
exports.ComponentAnalyzer = ComponentAnalyzer;