@schematics/angular
Version:
Schematics specific to Angular
36 lines (35 loc) • 1.57 kB
TypeScript
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import ts from 'typescript';
import { RefactorReporter } from './refactor-reporter';
/**
* A context object that provides access to shared utilities and state
* throughout the transformation process.
*/
export interface RefactorContext {
/** The root ts.SourceFile node of the file being transformed. */
readonly sourceFile: ts.SourceFile;
/** The reporter for logging changes and TODOs. */
readonly reporter: RefactorReporter;
/** The official context from the TypeScript Transformer API. */
readonly tsContext: ts.TransformationContext;
/** A set of Vitest value imports to be added to the file. */
readonly pendingVitestValueImports: Set<string>;
/** A set of Vitest type imports to be added to the file. */
readonly pendingVitestTypeImports: Set<string>;
/**
* Map of module specifier -> names to remove from that import.
* Used when transforming identifiers that become inlined (e.g. flush -> vi.runAllTimersAsync).
*/
readonly pendingImportSpecifierRemovals: Map<string, Set<string>>;
}
/**
* A generic transformer function that operates on a specific type of ts.Node.
* @template T The specific type of AST node this transformer works on (e.g., ts.CallExpression).
*/
export type NodeTransformer<T extends ts.Node> = (node: T, refactorCtx: RefactorContext) => ts.Node | readonly ts.Node[];