diff --git a/src/compiler/types.ts b/src/compiler/types.ts
index c0da1329b0..3c859694b4 100644
--- a/src/compiler/types.ts
+++ b/src/compiler/types.ts
@@ -3826,10 +3826,12 @@
}
export interface TransformationContext {
- /*@internal*/ getCompilerOptions(): CompilerOptions;
/*@internal*/ getEmitResolver(): EmitResolver;
/*@internal*/ getEmitHost(): EmitHost;
+ /** Gets the compiler options supplied to the transformer. */
+ getCompilerOptions(): CompilerOptions;
+
/** Starts a new lexical environment. */
startLexicalEnvironment(): void;
@@ -3892,11 +3894,12 @@
}
export interface TransformationResult {
- /**
- * Gets the transformed source files.
- */
+ /** Gets the transformed source files. */
transformed: SourceFile[];
+ /** Gets diagnostics for the transformation. */
+ diagnostics?: Diagnostic[];
+
/**
* Emits the substitute for a node, if one is available; otherwise, emits the node.
*
diff --git a/src/services/transform.ts b/src/services/transform.ts
index 724075e4cf..426e4280fd 100644
--- a/src/services/transform.ts
+++ b/src/services/transform.ts
@@ -1,18 +1,15 @@
///
///
namespace ts {
- export interface TransformOptions {
- newLine?: NewLineKind;
- }
-
/**
* 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.
* @param compilerOptions Optional compiler options.
*/
- export function transform(source: SourceFile | SourceFile[], transformers: Transformer[], transformOptions?: TransformOptions) {
- const compilerOptions = transformOptions || {};
+ export function transform(source: SourceFile | SourceFile[], transformers: Transformer[], compilerOptions?: CompilerOptions) {
+ const diagnostics: Diagnostic[] = [];
+ compilerOptions = fixupCompilerOptions(compilerOptions, diagnostics);
const newLine = getNewLineCharacter(compilerOptions);
const sourceFiles = isArray(source) ? source : [source];
const fileMap = arrayToMap(sourceFiles, sourceFile => sourceFile.fileName);
@@ -29,6 +26,8 @@ namespace ts {
isEmitBlocked: () => false,
writeFile: () => Debug.fail("'writeFile()' is not supported during transformation.")
};
- return transformFiles(/*resolver*/ undefined, emitHost, sourceFiles, transformers);
+ const result = transformFiles(/*resolver*/ undefined, emitHost, sourceFiles, transformers);
+ result.diagnostics = concatenate(result.diagnostics, diagnostics);
+ return result;
}
}
\ No newline at end of file