"use strict"; /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getCallDecoratorImport = exports.getAngularDecorators = void 0; const ts = require("typescript"); const imports_1 = require("./imports"); /** * Gets all decorators which are imported from an Angular package * (e.g. "@angular/core") from a list of decorators. */ function getAngularDecorators(typeChecker, decorators) { return decorators .map(node => ({ node, importData: getCallDecoratorImport(typeChecker, node) })) .filter(({ importData }) => importData && importData.moduleName.startsWith('@angular/')) .map(({ node, importData }) => ({ node: node, name: importData.symbolName, })); } exports.getAngularDecorators = getAngularDecorators; function getCallDecoratorImport(typeChecker, decorator) { if (!ts.isCallExpression(decorator.expression)) { return null; } const valueExpr = decorator.expression.expression; let identifier = null; if (ts.isIdentifier(valueExpr)) { identifier = valueExpr; } else if (ts.isPropertyAccessExpression(valueExpr) && ts.isIdentifier(valueExpr.name)) { identifier = valueExpr.name; } return identifier ? (0, imports_1.getImportOfIdentifier)(identifier, typeChecker) : null; } exports.getCallDecoratorImport = getCallDecoratorImport; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVjb3JhdG9ycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9jZGsvc2NoZW1hdGljcy91cGRhdGUtdG9vbC91dGlscy9kZWNvcmF0b3JzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7O0dBTUc7OztBQUVILGlDQUFpQztBQUVqQyx1Q0FBd0Q7QUFXeEQ7OztHQUdHO0FBQ0gsU0FBZ0Isb0JBQW9CLENBQ2xDLFdBQTJCLEVBQzNCLFVBQW1DO0lBRW5DLE9BQU8sVUFBVTtTQUNkLEdBQUcsQ0FBQyxJQUFJLENBQUMsRUFBRSxDQUFDLENBQUMsRUFBQyxJQUFJLEVBQ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