Skip to content

Commit c45ffaf

Browse files
Addressed code review.
Signed-off-by: Titian Cernicova-Dragomir <[email protected]>
1 parent 97161e0 commit c45ffaf

File tree

3 files changed

+30
-55
lines changed

3 files changed

+30
-55
lines changed

src/compiler/transformer.ts

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import {
44
Bundle,
55
chainBundle,
66
CompilerOptions,
7-
CoreEmitResolver,
87
createEmitHelperFactory,
98
CustomTransformer,
109
CustomTransformerFactory,
1110
CustomTransformers,
1211
Debug,
13-
Diagnostic,
1412
DiagnosticWithLocation,
1513
disposeEmitNodes,
1614
EmitFlags,
@@ -32,7 +30,6 @@ import {
3230
getUseDefineForClassFields,
3331
Identifier,
3432
isBundle,
35-
IsolatedTransformationContext,
3633
isSourceFile,
3734
LexicalEnvironmentFlags,
3835
map,
@@ -42,7 +39,6 @@ import {
4239
NodeFactory,
4340
NodeFlags,
4441
noop,
45-
notImplemented,
4642
NullTransformationContext,
4743
returnUndefined,
4844
ScriptTarget,
@@ -668,51 +664,22 @@ export function transformNodes<T extends Node>(resolver: EmitResolver | undefine
668664
}
669665
}
670666
}
667+
671668
/** @internal */
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);
669+
export const nullTransformationContext: NullTransformationContext = {
670+
kind: TransformationContextKind.NullContext,
671+
factory: factory, // eslint-disable-line object-shorthand
672+
getCompilerOptions: () => ({}),
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+
};

src/compiler/transformers/declarations/transpileDeclaration.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
createPrinter,
88
createSourceMapGenerator,
99
createTextWriter,
10-
createTransformationContext,
1110
Debug,
1211
Diagnostic,
1312
EmitHost,
@@ -20,8 +19,10 @@ import {
2019
getRelativePathToDirectoryOrUrl,
2120
getRootLength,
2221
getSourceFilePathInNewDir,
22+
IsolatedTransformationContext,
2323
normalizePath,
2424
normalizeSlashes,
25+
nullTransformationContext,
2526
PrinterOptions,
2627
SourceFile,
2728
SourceMapGenerator,
@@ -47,7 +48,13 @@ export function transpileDeclaration(sourceFile: SourceFile, transpileOptions: T
4748
};
4849
const emitResolver = createEmitDeclarationResolver(sourceFile);
4950
const diagnostics: Diagnostic[] = [];
50-
const transformationContext = createTransformationContext(TransformationContextKind.IsolatedContext, compilerOptions, diagnostics, emitResolver);
51+
const transformationContext: IsolatedTransformationContext = {
52+
...nullTransformationContext,
53+
kind: TransformationContextKind.IsolatedContext,
54+
getCompilerOptions: () => compilerOptions,
55+
addDiagnostic: diag => diagnostics.push(diag),
56+
getEmitResolver: () => emitResolver,
57+
};
5158
const transformer = transformDeclarations(transformationContext);
5259
const result = transformer(sourceFile);
5360

src/compiler/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5696,7 +5696,7 @@ export interface CoreEmitResolver {
56965696
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): string | number | undefined;
56975697
getAllAccessorDeclarations(declaration: AccessorDeclaration): AllAccessorDeclarations;
56985698
tryFindAmbientModule(moduleReferenceExpression: Expression): Symbol | undefined;
5699-
getPropertiesOfContainerFunction(node: FunctionDeclaration | VariableDeclaration): Symbol[]
5699+
getPropertiesOfContainerFunction(node: FunctionDeclaration | VariableDeclaration): Symbol[];
57005700
}
57015701
/** @internal */
57025702
export interface EmitResolver extends CoreEmitResolver {
@@ -9167,6 +9167,7 @@ export const enum LexicalEnvironmentFlags {
91679167
VariablesHoistedInParameters = 1 << 1, // a temp variable was hoisted while visiting a parameter list
91689168
}
91699169

9170+
/** @internal */
91709171
export const enum TransformationContextKind {
91719172
FullContext = 0,
91729173
IsolatedContext = 1,
@@ -9216,7 +9217,7 @@ export interface CoreTransformationContext {
92169217
}
92179218

92189219
export interface TransformationContext extends CoreTransformationContext {
9219-
kind: TransformationContextKind.FullContext;
9220+
/** @internal */ kind: TransformationContextKind.FullContext;
92209221
/** @internal */ getEmitResolver(): EmitResolver;
92219222
/** @internal */ getEmitHost(): EmitHost;
92229223
/** @internal */ getEmitHelperFactory(): EmitHelperFactory;

0 commit comments

Comments
 (0)