Skip to content

Commit 1bbaaa3

Browse files
committed
Make TransformationContext.getCompilerOptions public
1 parent 6c59ee4 commit 1bbaaa3

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/compiler/types.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3826,10 +3826,12 @@
38263826
}
38273827

38283828
export interface TransformationContext {
3829-
/*@internal*/ getCompilerOptions(): CompilerOptions;
38303829
/*@internal*/ getEmitResolver(): EmitResolver;
38313830
/*@internal*/ getEmitHost(): EmitHost;
38323831

3832+
/** Gets the compiler options supplied to the transformer. */
3833+
getCompilerOptions(): CompilerOptions;
3834+
38333835
/** Starts a new lexical environment. */
38343836
startLexicalEnvironment(): void;
38353837

@@ -3892,11 +3894,12 @@
38923894
}
38933895

38943896
export interface TransformationResult {
3895-
/**
3896-
* Gets the transformed source files.
3897-
*/
3897+
/** Gets the transformed source files. */
38983898
transformed: SourceFile[];
38993899

3900+
/** Gets diagnostics for the transformation. */
3901+
diagnostics?: Diagnostic[];
3902+
39003903
/**
39013904
* Emits the substitute for a node, if one is available; otherwise, emits the node.
39023905
*

src/services/transform.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
/// <reference path="..\compiler\transformer.ts"/>
22
/// <reference path="transpile.ts"/>
33
namespace ts {
4-
export interface TransformOptions {
5-
newLine?: NewLineKind;
6-
}
7-
84
/**
95
* Transform one or more source files using the supplied transformers.
106
* @param source A `SourceFile` or an array of `SourceFiles`.
117
* @param transformers An array of `Transformer` callbacks used to process the transformation.
128
* @param compilerOptions Optional compiler options.
139
*/
14-
export function transform(source: SourceFile | SourceFile[], transformers: Transformer[], transformOptions?: TransformOptions) {
15-
const compilerOptions = <CompilerOptions>transformOptions || {};
10+
export function transform(source: SourceFile | SourceFile[], transformers: Transformer[], compilerOptions?: CompilerOptions) {
11+
const diagnostics: Diagnostic[] = [];
12+
compilerOptions = fixupCompilerOptions(compilerOptions, diagnostics);
1613
const newLine = getNewLineCharacter(compilerOptions);
1714
const sourceFiles = isArray(source) ? source : [source];
1815
const fileMap = arrayToMap(sourceFiles, sourceFile => sourceFile.fileName);
@@ -29,6 +26,8 @@ namespace ts {
2926
isEmitBlocked: () => false,
3027
writeFile: () => Debug.fail("'writeFile()' is not supported during transformation.")
3128
};
32-
return transformFiles(/*resolver*/ undefined, emitHost, sourceFiles, transformers);
29+
const result = transformFiles(/*resolver*/ undefined, emitHost, sourceFiles, transformers);
30+
result.diagnostics = concatenate(result.diagnostics, diagnostics);
31+
return result;
3332
}
3433
}

0 commit comments

Comments
 (0)