Make TransformationContext.getCompilerOptions public

This commit is contained in:
Ron Buckton 2017-02-07 15:19:44 -08:00
parent 6c59ee4ce6
commit 1bbaaa3831
2 changed files with 13 additions and 11 deletions

View file

@ -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.
*

View file

@ -1,18 +1,15 @@
/// <reference path="..\compiler\transformer.ts"/>
/// <reference path="transpile.ts"/>
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 = <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;
}
}