ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
178 lines (177 loc) • 7.47 kB
TypeScript
import * as ts from "typescript";
import * as compiler from "./compiler";
import { SourceFileStructure } from "./structures";
import { FileSystemHost } from "./FileSystemHost";
import { ManipulationSettings, ManipulationSettingsContainer } from "./ManipulationSettings";
export interface Options {
/** Compiler options */
compilerOptions?: ts.CompilerOptions;
/** File path to the tsconfig.json file */
tsConfigFilePath?: string;
/** Manipulation settings */
manipulationSettings?: Partial<ManipulationSettings>;
}
/**
* Compiler wrapper.
*/
export declare class TsSimpleAst {
private fileSystem;
/**
* Initializes a new instance.
* @param options - Optional options.
* @param fileSystem - Optional file system host. Useful for mocking access to the file system.
*/
constructor(options?: Options, fileSystem?: FileSystemHost);
/** Gets the manipulation settings. */
readonly manipulationSettings: ManipulationSettingsContainer;
/**
* Add source files based on file globs.
* @param fileGlobs - File globs to add files based on.
*/
addSourceFiles(...fileGlobs: string[]): void;
/**
* Gets or adds a source file from a file path.
* @param filePath - File path to create the file from.
*/
getOrAddSourceFileFromFilePath(filePath: string): compiler.SourceFile;
/**
* Adds a source file from text.
* @param filePath - File path for the source file.
* @param sourceFileText - Source file text.
* @throws - InvalidOperationError if a source file already exists at the provided file path.
*/
addSourceFileFromText(filePath: string, sourceFileText: string): compiler.SourceFile;
/**
* Adds a source file from a structure.
* @param filePath - File path for the source file.
* @param structure - Structure that represents the source file.
* @throws - InvalidOperationError if a source file already exists at the provided file path.
*/
addSourceFileFromStructure(filePath: string, structure: SourceFileStructure): compiler.SourceFile;
/**
* Removes a source file from the AST.
* @param sourceFile - Source file to remove.
* @returns True if removed.
*/
removeSourceFile(sourceFile: compiler.SourceFile): boolean;
/**
* Gets a source file by a file name or file path. Throws an error if it doesn't exist.
* @param fileNameOrPath - File name or path that the path could end with or equal.
*/
getSourceFileOrThrow(fileNameOrPath: string): compiler.SourceFile;
/**
* Gets a source file by a search function. Throws an erorr if it doesn't exist.
* @param searchFunction - Search function.
*/
getSourceFileOrThrow(searchFunction: (file: compiler.SourceFile) => boolean): compiler.SourceFile;
/**
* Gets a source file by a file name or file path. Returns undefined if none exists.
* @param fileNameOrPath - File name or path that the path could end with or equal.
*/
getSourceFile(fileNameOrPath: string): compiler.SourceFile | undefined;
/**
* Gets a source file by a search function. Returns undefined if none exists.
* @param searchFunction - Search function.
*/
getSourceFile(searchFunction: (file: compiler.SourceFile) => boolean): compiler.SourceFile | undefined;
/**
* Gets all the source files contained in the compiler wrapper.
*/
getSourceFiles(): compiler.SourceFile[];
/**
* Saves all the unsaved source files.
*/
saveUnsavedSourceFiles(): Promise<void[]>;
/**
* Saves all the unsaved source files synchronously.
*
* Remarks: This might be very slow compared to the asynchronous version if there are a lot of files.
*/
saveUnsavedSourceFilesSync(): void;
private getUnsavedSourceFiles();
/**
* Gets the compiler diagnostics.
*/
getDiagnostics(): compiler.Diagnostic[];
/**
* Gets a language service.
*/
getLanguageService(): compiler.LanguageService;
/**
* Emits all the source files.
* @param emitOptions - Optional emit options.
*/
emit(emitOptions?: compiler.EmitOptions): compiler.EmitResult;
/**
* Gets the compiler options.
*/
getCompilerOptions(): {
[option: string]: string | number | boolean | string[] | (string | number)[] | ts.JsonSourceFile | ts.MapLike<string[]> | ts.PluginImport[] | undefined;
allowJs?: boolean | undefined;
allowSyntheticDefaultImports?: boolean | undefined;
allowUnreachableCode?: boolean | undefined;
allowUnusedLabels?: boolean | undefined;
alwaysStrict?: boolean | undefined;
baseUrl?: string | undefined;
charset?: string | undefined;
checkJs?: boolean | undefined;
declaration?: boolean | undefined;
declarationDir?: string | undefined;
disableSizeLimit?: boolean | undefined;
downlevelIteration?: boolean | undefined;
emitBOM?: boolean | undefined;
emitDecoratorMetadata?: boolean | undefined;
experimentalDecorators?: boolean | undefined;
forceConsistentCasingInFileNames?: boolean | undefined;
importHelpers?: boolean | undefined;
inlineSourceMap?: boolean | undefined;
inlineSources?: boolean | undefined;
isolatedModules?: boolean | undefined;
jsx?: ts.JsxEmit | undefined;
lib?: string[] | undefined;
locale?: string | undefined;
mapRoot?: string | undefined;
maxNodeModuleJsDepth?: number | undefined;
module?: ts.ModuleKind | undefined;
moduleResolution?: ts.ModuleResolutionKind | undefined;
newLine?: ts.NewLineKind | undefined;
noEmit?: boolean | undefined;
noEmitHelpers?: boolean | undefined;
noEmitOnError?: boolean | undefined;
noErrorTruncation?: boolean | undefined;
noFallthroughCasesInSwitch?: boolean | undefined;
noImplicitAny?: boolean | undefined;
noImplicitReturns?: boolean | undefined;
noImplicitThis?: boolean | undefined;
noStrictGenericChecks?: boolean | undefined;
noUnusedLocals?: boolean | undefined;
noUnusedParameters?: boolean | undefined;
noImplicitUseStrict?: boolean | undefined;
noLib?: boolean | undefined;
noResolve?: boolean | undefined;
out?: string | undefined;
outDir?: string | undefined;
outFile?: string | undefined;
paths?: ts.MapLike<string[]> | undefined;
preserveConstEnums?: boolean | undefined;
preserveSymlinks?: boolean | undefined;
project?: string | undefined;
reactNamespace?: string | undefined;
jsxFactory?: string | undefined;
removeComments?: boolean | undefined;
rootDir?: string | undefined;
rootDirs?: string[] | undefined;
skipLibCheck?: boolean | undefined;
skipDefaultLibCheck?: boolean | undefined;
sourceMap?: boolean | undefined;
sourceRoot?: string | undefined;
strict?: boolean | undefined;
strictNullChecks?: boolean | undefined;
suppressExcessPropertyErrors?: boolean | undefined;
suppressImplicitAnyIndexErrors?: boolean | undefined;
target?: ts.ScriptTarget | undefined;
traceResolution?: boolean | undefined;
types?: string[] | undefined;
typeRoots?: string[] | undefined;
};
}