@@ -4,11 +4,13 @@ import {
4
4
Bundle ,
5
5
chainBundle ,
6
6
CompilerOptions ,
7
+ CoreEmitResolver ,
7
8
createEmitHelperFactory ,
8
9
CustomTransformer ,
9
10
CustomTransformerFactory ,
10
11
CustomTransformers ,
11
12
Debug ,
13
+ Diagnostic ,
12
14
DiagnosticWithLocation ,
13
15
disposeEmitNodes ,
14
16
EmitFlags ,
@@ -30,6 +32,7 @@ import {
30
32
getUseDefineForClassFields ,
31
33
Identifier ,
32
34
isBundle ,
35
+ IsolatedTransformationContext ,
33
36
isSourceFile ,
34
37
LexicalEnvironmentFlags ,
35
38
map ,
@@ -40,6 +43,7 @@ import {
40
43
NodeFlags ,
41
44
noop ,
42
45
notImplemented ,
46
+ NullTransformationContext ,
43
47
returnUndefined ,
44
48
ScriptTarget ,
45
49
setEmitFlags ,
@@ -49,6 +53,7 @@ import {
49
53
SyntaxKind ,
50
54
tracing ,
51
55
TransformationContext ,
56
+ TransformationContextKind ,
52
57
TransformationResult ,
53
58
transformClassFields ,
54
59
transformDeclarations ,
@@ -267,6 +272,7 @@ export function transformNodes<T extends Node>(resolver: EmitResolver | undefine
267
272
// The transformation context is provided to each transformer as part of transformer
268
273
// initialization.
269
274
const context : TransformationContext = {
275
+ kind : TransformationContextKind . FullContext ,
270
276
factory,
271
277
getCompilerOptions : ( ) => options ,
272
278
getEmitResolver : ( ) => resolver ! , // TODO: GH#18217
@@ -662,33 +668,51 @@ export function transformNodes<T extends Node>(resolver: EmitResolver | undefine
662
668
}
663
669
}
664
670
}
665
-
666
671
/** @internal */
667
- export const nullTransformationContext : TransformationContext = {
668
- factory : factory , // eslint-disable-line object-shorthand
669
- getCompilerOptions : ( ) => ( { } ) ,
670
- getEmitResolver : notImplemented ,
671
- getEmitHost : notImplemented ,
672
- getEmitHelperFactory : notImplemented ,
673
- startLexicalEnvironment : noop ,
674
- resumeLexicalEnvironment : noop ,
675
- suspendLexicalEnvironment : noop ,
676
- endLexicalEnvironment : returnUndefined ,
677
- setLexicalEnvironmentFlags : noop ,
678
- getLexicalEnvironmentFlags : ( ) => 0 ,
679
- hoistVariableDeclaration : noop ,
680
- hoistFunctionDeclaration : noop ,
681
- addInitializationStatement : noop ,
682
- startBlockScope : noop ,
683
- endBlockScope : returnUndefined ,
684
- addBlockScopedVariable : noop ,
685
- requestEmitHelper : noop ,
686
- readEmitHelpers : notImplemented ,
687
- enableSubstitution : noop ,
688
- enableEmitNotification : noop ,
689
- isSubstitutionEnabled : notImplemented ,
690
- isEmitNotificationEnabled : notImplemented ,
691
- onSubstituteNode : noEmitSubstitution ,
692
- onEmitNode : noEmitNotification ,
693
- addDiagnostic : noop ,
694
- } ;
672
+ export function createTransformationContext ( kind : TransformationContextKind . NullContext ) : NullTransformationContext ;
673
+ /** @internal */
674
+ export function createTransformationContext (
675
+ kind : TransformationContextKind . IsolatedContext ,
676
+ options : CompilerOptions ,
677
+ diagnostics : Diagnostic [ ] ,
678
+ resolver : CoreEmitResolver ,
679
+ ) : IsolatedTransformationContext ;
680
+ export function createTransformationContext (
681
+ kind : TransformationContextKind . IsolatedContext | TransformationContextKind . NullContext ,
682
+ options : CompilerOptions = { } ,
683
+ diagnostics ?: Diagnostic [ ] ,
684
+ resolver ?: EmitResolver | CoreEmitResolver ,
685
+ host ?: EmitHost ,
686
+ ) : NullTransformationContext | IsolatedTransformationContext | TransformationContext {
687
+ return {
688
+ kind,
689
+ factory : factory , // eslint-disable-line object-shorthand
690
+ getCompilerOptions : ( ) => options ,
691
+ getEmitResolver : ! resolver ? notImplemented : ( ) => resolver ,
692
+ getEmitHost : ! host ? notImplemented : ( ) => host ,
693
+ getEmitHelperFactory : notImplemented ,
694
+ startLexicalEnvironment : noop ,
695
+ resumeLexicalEnvironment : noop ,
696
+ suspendLexicalEnvironment : noop ,
697
+ endLexicalEnvironment : returnUndefined ,
698
+ setLexicalEnvironmentFlags : noop ,
699
+ getLexicalEnvironmentFlags : ( ) => 0 ,
700
+ hoistVariableDeclaration : noop ,
701
+ hoistFunctionDeclaration : noop ,
702
+ addInitializationStatement : noop ,
703
+ startBlockScope : noop ,
704
+ endBlockScope : returnUndefined ,
705
+ addBlockScopedVariable : noop ,
706
+ requestEmitHelper : noop ,
707
+ readEmitHelpers : notImplemented ,
708
+ enableSubstitution : noop ,
709
+ enableEmitNotification : noop ,
710
+ isSubstitutionEnabled : notImplemented ,
711
+ isEmitNotificationEnabled : notImplemented ,
712
+ onSubstituteNode : noEmitSubstitution ,
713
+ onEmitNode : noEmitNotification ,
714
+ addDiagnostic : ! diagnostics ? noop : ( diag : Diagnostic ) => diagnostics . push ( diag ) ,
715
+ } ;
716
+ }
717
+ /** @internal */
718
+ export const nullTransformationContext : NullTransformationContext = createTransformationContext ( TransformationContextKind . NullContext ) ;
0 commit comments