@ng-doc/builder
Version:
<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>
43 lines • 2.14 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInputName = getInputName;
const ts_morph_1 = require("ts-morph");
const is_input_1 = require("./is-input");
/**
* Returns the name of the component input.
* @param property - The property declaration
*/
function getInputName(property) {
if ((0, is_input_1.isInputDecorator)(property)) {
const inputArgument = property.getDecorator('Input')?.getArguments()[0];
if (ts_morph_1.Node.isStringLiteral(inputArgument)) {
return inputArgument.getLiteralText().replace(/^["']|['"]$/g, '');
}
if (ts_morph_1.Node.isObjectLiteralExpression(inputArgument)) {
const inputAliasProperty = inputArgument.getProperty('alias');
if (ts_morph_1.Node.isPropertyAssignment(inputAliasProperty)) {
return inputAliasProperty
.getInitializerIfKindOrThrow(ts_morph_1.SyntaxKind.StringLiteral)
.getLiteralText();
}
}
}
if ((0, is_input_1.isInputSignal)(property)) {
const typeDeclaration = property.getType().getSymbol()?.getDeclarations()[0];
if (ts_morph_1.Node.isInterfaceDeclaration(typeDeclaration) && ts_morph_1.Node.isPropertyDeclaration(property)) {
const inputInitializer = property.getInitializerIfKind(ts_morph_1.SyntaxKind.CallExpression);
const argumentsIndex = inputInitializer?.getExpression().getText() === 'input.required' ? 0 : 1;
const objectExpression = inputInitializer?.getArguments()[argumentsIndex];
if (ts_morph_1.Node.isObjectLiteralExpression(objectExpression)) {
const inputAliasProperty = objectExpression.getProperty('alias');
if (ts_morph_1.Node.isPropertyAssignment(inputAliasProperty)) {
return inputAliasProperty
.getInitializerIfKindOrThrow(ts_morph_1.SyntaxKind.StringLiteral)
.getLiteralText();
}
}
}
}
return property.getName();
}
//# sourceMappingURL=get-input-name.js.map
;