forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransform.ts
More file actions
27 lines (26 loc) · 1.13 KB
/
transform.ts
File metadata and controls
27 lines (26 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import {
CompilerOptions,
concatenate,
DiagnosticWithLocation,
factory,
fixupCompilerOptions,
isArray,
Node,
TransformationResult,
TransformerFactory,
transformNodes,
} from "./_namespaces/ts";
/**
* Transform one or more nodes using the supplied transformers.
* @param source A single `Node` or an array of `Node` objects.
* @param transformers An array of `TransformerFactory` callbacks used to process the transformation.
* @param compilerOptions Optional compiler options.
*/
export function transform<T extends Node>(source: T | T[], transformers: TransformerFactory<T>[], compilerOptions?: CompilerOptions): TransformationResult<T> {
const diagnostics: DiagnosticWithLocation[] = [];
compilerOptions = fixupCompilerOptions(compilerOptions!, diagnostics); // TODO: GH#18217
const nodes = isArray(source) ? source : [source];
const result = transformNodes(/*resolver*/ undefined, /*emitHost*/ undefined, factory, compilerOptions, nodes, transformers, /*allowDtsFiles*/ true);
result.diagnostics = concatenate(result.diagnostics, diagnostics);
return result;
}