UNPKG

@trapi/metadata

Version:

Generate REST-API metadata scheme from TypeScript Decorators.

52 lines 1.66 kB
"use strict"; /* * Copyright (c) 2021-2023. * Author Peter Placzek (tada5hi) * For the full copyright and license information, * view the LICENSE file that was distributed with this source code. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getNodeDecorators = void 0; const typescript_1 = require("typescript"); /** * Get Decorators for a specific node. * * @param node * @param isMatching */ function getNodeDecorators(node, isMatching) { if (!(0, typescript_1.canHaveDecorators)(node)) { return []; } const decorators = (0, typescript_1.getDecorators)(node); if (typeof decorators === 'undefined') { return []; } const items = decorators .map((d) => { const result = { arguments: [], typeArguments: [], }; let x = d.expression; if ((0, typescript_1.isCallExpression)(x)) { if (x.arguments) { result.arguments = x.arguments.map((argument) => { if ((0, typescript_1.isStringLiteral)(argument) || (0, typescript_1.isNumericLiteral)(argument)) { return argument.text; } return argument; }); } if (x.typeArguments) { result.typeArguments = x.typeArguments; } x = x.expression; } result.text = x.text || x.name.text; return result; }); return typeof isMatching === 'undefined' ? items : items.filter(isMatching); } exports.getNodeDecorators = getNodeDecorators; //# sourceMappingURL=module.js.map