UNPKG

@rxap/ts-morph

Version:

Provides utilities for manipulating TypeScript code using the ts-morph library. It offers a fluent API to add, modify, and remove code elements such as classes, decorators, imports, and properties in both Angular and NestJS projects. This package simplifi

43 lines 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetArrayLiteralFromObjectLiteral = GetArrayLiteralFromObjectLiteral; exports.GetCoerceArrayLiteralFromObjectLiteral = GetCoerceArrayLiteralFromObjectLiteral; const ts_morph_1 = require("ts-morph"); function GetArrayLiteralFromObjectLiteral(objectLiteral, propertyKey) { const arrayLiteralAssignment = objectLiteral.getProperty(propertyKey); if (!arrayLiteralAssignment) { return null; } if (!(arrayLiteralAssignment.isKind(ts_morph_1.SyntaxKind.PropertyAssignment))) { throw new Error('The imports property is not type of Property Assignment!'); } const arrayLiteral = arrayLiteralAssignment.getInitializer(); if (!arrayLiteral) { throw new Error('The imports property a not a initializer'); } if (!(arrayLiteral.isKind(ts_morph_1.SyntaxKind.ArrayLiteralExpression))) { throw new Error('The imports property initializer is not an array'); } return arrayLiteral; } function GetCoerceArrayLiteralFromObjectLiteral(objectLiteral, propertyKey) { let arrayLiteralAssignment = objectLiteral.getProperty(propertyKey); if (!arrayLiteralAssignment) { arrayLiteralAssignment = objectLiteral.addPropertyAssignment({ name: propertyKey, initializer: '[]', }); } if (!(arrayLiteralAssignment.isKind(ts_morph_1.SyntaxKind.PropertyAssignment))) { throw new Error('The imports property is not type of Property Assignment!'); } const arrayLiteral = arrayLiteralAssignment.getInitializer(); if (!arrayLiteral) { throw new Error('The imports property a not a initializer'); } if (!(arrayLiteral.isKind(ts_morph_1.SyntaxKind.ArrayLiteralExpression))) { throw new Error('The imports property initializer is not an array'); } return arrayLiteral; } //# sourceMappingURL=get-coerce-array-literal-form-object-literal.js.map