import { Identifier, ImportDeclaration, NamedImportBindings, NamedImports, NamespaceImport, SourceFile, SyntaxKind } from "typescript"; import { IImportService } from "./i-import-service"; import { IPrinter, ITypescriptASTUtil } from "@wessberg/typescript-ast-util"; import { IFormatter } from "../../formatter/i-formatter-getter"; import { INamedImportsService } from "../named-imports/i-named-imports-service"; import { INamespaceImportService } from "../namespace-import/i-namespace-import-service"; import { IUpdater } from "../../updater/i-updater-getter"; import { NodeService } from "../node/node-service"; import { IDecoratorService } from "../decorator/i-decorator-service"; import { IRemover } from "../../remover/i-remover-base"; import { IJoiner } from "../../joiner/i-joiner-getter"; import { INamedImportExportCtor } from "../../light-ast/ctor/named-import-export/i-named-import-export-ctor"; import { IImportCtor } from "../../light-ast/ctor/import/i-import-ctor"; import { ITypescriptLanguageService } from "@wessberg/typescript-language-service"; import { IPlacement } from "../../placement/i-placement"; import { IModuleUtil } from "@wessberg/moduleutil"; import { IPathUtil } from "@wessberg/pathutil"; import { INodeToDictMapper } from "../../node-to-dict-mapper/i-node-to-dict-mapper-getter"; /** * A class that helps with working with ImportDeclarations through the Typescript ASt */ export declare class ImportService extends NodeService implements IImportService { private readonly namedImportsService; private readonly namespaceImportService; private readonly nodeToDictMapper; private readonly moduleUtil; private readonly formatter; private readonly printer; private readonly pathUtil; /** * The allowed SyntaxKinds when parsing a SourceFile for relevant Expressions * @type {Iterable} */ protected readonly ALLOWED_KINDS: Iterable; constructor(namedImportsService: INamedImportsService, namespaceImportService: INamespaceImportService, nodeToDictMapper: INodeToDictMapper, moduleUtil: IModuleUtil, formatter: IFormatter, printer: IPrinter, pathUtil: IPathUtil, updater: IUpdater, joiner: IJoiner, astUtil: ITypescriptASTUtil, decoratorService: IDecoratorService, languageService: ITypescriptLanguageService, remover: IRemover); /** * Gets the import path of an ImportDeclaration * @param {ImportDeclaration} importDeclaration * @returns {string} */ getPathForImportDeclaration(importDeclaration: ImportDeclaration): string; /** * Gets all ImportDeclarations that refers to the provided path in the provided sourceFile * @param {string} path * @param {SourceFile} sourceFile * @returns {NodeArray} */ getImportsForPath(path: string, sourceFile: SourceFile): ImportDeclaration[]; /** * Gets the ImportDeclarations that refers to the provided path and * has a named import matching the provided one in the provided SourceFile. * If no path is provided, it will look across all ImportDeclarations * @param namedImport * @param {string} path * @param {SourceFile} sourceFile * @returns {ImportDeclaration?} */ getImportWithNamedImport(namedImport: INamedImportExportCtor, sourceFile: SourceFile, path?: string): ImportDeclaration | undefined; /** * Gets the ImportDeclarations that refers to the provided path and has a namespace import with the provided * namespace name. If no path is provided, it will look across all ImportDeclarations * @param {string} namespace * @param {SourceFile} sourceFile * @param {string} path * @returns {ImportDeclaration?} */ getImportWithNamespace(namespace: string, sourceFile: SourceFile, path?: string): ImportDeclaration | undefined; /** * Gets the ImportDeclarations that refers to the provided path and has a default name matching the provided one. * If no path is provided, it will look across all ImportDeclarations * @param {string} name * @param {SourceFile} sourceFile * @param {string} path * @returns {ImportDeclaration?} */ getImportWithName(name: string, sourceFile: SourceFile, path?: string): ImportDeclaration | undefined; /** * Gets the ImportDeclarations that refers to the provided path and has any binding such as a named import, default * name or a namespace matching the provided one. * If no path is provided, it will look across all ImportDeclarations * @param {INamedImportExportCtor | string} binding * @param {SourceFile} sourceFile * @param {string} path * @returns {ImportDeclaration?} */ getImportWithBinding(binding: string, sourceFile: SourceFile, path?: string): ImportDeclaration | undefined; /** * Returns the default binding name for an ImportDeclaration (such as 'import name from "something"' where the identifier for 'name' would be returned) * @param {ImportDeclaration} importDeclaration * @returns {Identifier} */ getNameForImportDeclaration(importDeclaration: ImportDeclaration): Identifier | undefined; /** * Returns true if the provided ImportDeclaration has any named imports (e.g. at least has '{}' brackets) * @param {ImportDeclaration} importDeclaration * @returns {boolean} */ hasNamedImports(importDeclaration: ImportDeclaration): boolean; /** * Returns true if the provided ImportDeclaration already imports the provided named import. * A named import is anything in between "{" and "}" in an import. * @param {INamedImportExportCtor|string} namedImport * @param {ImportDeclaration} importDeclaration * @returns {boolean} */ hasNamedImport(namedImport: string | INamedImportExportCtor, importDeclaration: ImportDeclaration): boolean; /** * Returns true if the provided ImportDeclaration has a namespace import * @param {ts.ImportDeclaration} importDeclaration * @returns {boolean} */ hasNamespaceImport(importDeclaration: ImportDeclaration): boolean; /** * Returns true if the provided ImportDeclaration has a namespace import with the provided name * @param {string} namespaceName * @param {ImportDeclaration} importDeclaration * @returns {boolean} */ hasNamespaceImportWithName(namespaceName: string, importDeclaration: ImportDeclaration): boolean; /** * Returns true if the import declaration has a name (e.g. a default import) * @param {ImportDeclaration} importDeclaration * @returns {boolean} */ hasName(importDeclaration: ImportDeclaration): boolean; /** * Returns true if the import declaration has a name (e.g. a default import) * and it is identical with the provided one * @param {string} name * @param {ts.ImportDeclaration} importDeclaration * @returns {boolean} */ hasSpecificName(name: string, importDeclaration: ImportDeclaration): boolean; /** * Takes all NamedImports for an ImportDeclaration. * This is all named imports that isn't namespace imports (such as 'import {A, B, C} from "something') * @param {ImportDeclaration} importDeclaration * @returns {NamedImports?} */ getNamedImportsForImportDeclaration(importDeclaration: ImportDeclaration): NamedImports | undefined; /** * Takes the namespace import for an ImportDeclaration, if it has any * @param {ImportDeclaration} importDeclaration * @returns {NamespaceImport} */ getNamespaceImportForImportDeclaration(importDeclaration: ImportDeclaration): NamespaceImport | undefined; /** * Takes the named imports or the namespace import for an ImportDeclaration, if it has any * @param {ImportDeclaration} importDeclaration * @returns {NamedImportBindings} */ getNamedImportBindingsForImportDeclaration(importDeclaration: ImportDeclaration): NamedImportBindings | undefined; /** * Creates an ImportDeclaration and adds it to the provided SourceFile * @param {IImportCtor} options * @param {SourceFile} sourceFile * @param {IPlacement} [placement] * @returns {ImportDeclaration} */ createAndAddImportDeclarationToSourceFile(options: IImportCtor, sourceFile: SourceFile, placement?: IPlacement): ImportDeclaration; /** * Removes the given ImportDeclaration from its SourceFile * @param {ImportDeclaration} importDeclaration * @returns {boolean} */ removeImportDeclaration(importDeclaration: ImportDeclaration): boolean; /** * Removes all ImportDeclarations with the given path in the given SourceFile * @param {string} path * @param {SourceFile} sourceFile * @returns {boolean} */ removeImportDeclarationsWithPath(path: string, sourceFile: SourceFile): boolean; /** * Creates a new ImportDeclaration * @param {IImportCtor} options * @returns {ImportDeclaration} */ createImportDeclaration(options: IImportCtor): ImportDeclaration; /** * Changes the path of an ImportDeclaration * @param {string} path * @param {ImportDeclaration} importDeclaration * @returns {ImportDeclaration} */ changePathOfImportDeclaration(path: string, importDeclaration: ImportDeclaration): ImportDeclaration; /** * Adds a specific default name to an ImportDeclaration, unless it has that name already * @param {string} name * @param {ImportDeclaration} importDeclaration * @returns {ImportDeclaration} */ addNameToImportDeclaration(name: string, importDeclaration: ImportDeclaration): ImportDeclaration; /** * Adds a namespace import to an Import Declaration, if it doesn't already include one with the provided name * @param {string} namespaceName * @param {ts.ImportDeclaration} importDeclaration * @returns {ts.ImportDeclaration} */ addNamespaceImportToImportDeclaration(namespaceName: string, importDeclaration: ImportDeclaration): ImportDeclaration; /** * Adds a NamedImport to an ImportDeclaration if it doesn't include it already * @param {INamedImportExportCtor} namedImport * @param {ImportDeclaration} importDeclaration * @returns {ImportDeclaration} */ addNamedImportToImportDeclaration(namedImport: INamedImportExportCtor, importDeclaration: ImportDeclaration): ImportDeclaration; }