diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 63c3726fc10..fd2b0314dda 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -587,7 +587,7 @@ namespace ts { } if (visited) { if (isArray(visited)) { - for (let visitedNode of visited) { + for (const visitedNode of visited) { Debug.assertNode(visitedNode, test); aggregateTransformFlags(visitedNode); updated.push(visitedNode); diff --git a/src/services/transform.ts b/src/services/transform.ts new file mode 100644 index 00000000000..c9107eea853 --- /dev/null +++ b/src/services/transform.ts @@ -0,0 +1,29 @@ +/// +/// +namespace ts { + /** + * Transform one or more source files using the supplied transformers. + * @param source A `SourceFile` or an array of `SourceFiles`. + * @param transformers An array of `Transformer` callbacks used to process the transformation. + */ + export function transform(source: SourceFile | SourceFile[], transformers: Transformer[]) { + const diagnostics: Diagnostic[] = []; + const compilerOptions: CompilerOptions = {}; + const sourceFiles = isArray(source) ? source : [source]; + const fileMap = arrayToMap(sourceFiles, sourceFile => sourceFile.fileName); + const emitHost: EmitHost = { + getCompilerOptions: () => compilerOptions, + getCanonicalFileName: fileName => fileName, + getCommonSourceDirectory: () => "", + getCurrentDirectory: () => "", + getNewLine: () => "\n", + getSourceFile: fileName => fileMap.get(fileName), + getSourceFileByPath: fileName => fileMap.get(fileName), + getSourceFiles: () => sourceFiles, + isSourceFileFromExternalLibrary: () => false, + isEmitBlocked: () => false, + writeFile: () => Debug.fail("'writeFile()' is not supported during transformation.") + }; + return transformFiles(/*resolver*/ undefined, emitHost, sourceFiles, transformers); + } +} \ No newline at end of file