@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
22 lines (21 loc) • 1.81 kB
TypeScript
import { ImportDeclarationStructure, OptionalKind, SourceFile } from 'ts-morph';
/**
* This function, `CoerceImports`, is used to coerce import declarations in a given source file. It takes two parameters: `sourceFile` and `structures`.
*
* @param {SourceFile} sourceFile - The source file in which the import declarations are to be processed. This is an instance of the `SourceFile` class.
*
* @param {Array<OptionalKind<ImportDeclarationStructure>> | OptionalKind<ImportDeclarationStructure>} structures - An array of import declaration structures or a single import declaration structure. Each structure can be of type `OptionalKind<ImportDeclarationStructure>`, which means it may or may not contain certain properties.
*
* The function iterates over each import declaration structure in `structures`. For each structure, it extracts the following properties: `moduleSpecifier`, `namedImports`, `namespaceImport`, `isTypeOnly`, and `defaultImport`.
*
* If `namedImports` is present, it checks if the named imports are supported using the `isSupportedNamedImports` function. If not, it throws an error. If they are supported, it coerces the named imports using the `coerceNamedImports` function.
*
* If `namespaceImport` is present, it coerces the namespace import using the `coerceNamespaceImport` function.
*
* If `defaultImport` is present, it coerces the default import using the `coerceDefaultImport` function.
*
* The function does not return any value.
*
* Note: This function does not modify the original `sourceFile` or `structures` parameters. It only processes and validates the import declarations.
*/
export declare function CoerceImports(sourceFile: SourceFile, structures: Array<OptionalKind<ImportDeclarationStructure>> | OptionalKind<ImportDeclarationStructure>): void;