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

26 lines 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CoerceTokenExport = CoerceTokenExport; const ts_morph_1 = require("@rxap/ts-morph"); const ts_morph_2 = require("ts-morph"); function CoerceTokenExport(sourceFile, options) { var _a; const { name, description = name, type, overwrite = false, } = options; const initializer = `new InjectionToken<${(_a = type === null || type === void 0 ? void 0 : type.name) !== null && _a !== void 0 ? _a : 'any'}>('${description}')`; const variableDeclaration = (0, ts_morph_1.CoerceVariableDeclaration)(sourceFile, name, { initializer }, { isExported: true, declarationKind: ts_morph_2.VariableDeclarationKind.Const, }); if (overwrite) { variableDeclaration.setInitializer(initializer); } (0, ts_morph_1.CoerceImports)(sourceFile, { namedImports: ['InjectionToken'], moduleSpecifier: '@angular/core', }); if (type) { (0, ts_morph_1.CoerceImports)(sourceFile, (0, ts_morph_1.TypeImportToImportStructure)(type)); } return variableDeclaration; } //# sourceMappingURL=coerce-token-export.js.map