Skip to content

Commit 0f2bbb1

Browse files
committed
Moved LexicalEnvironment to types.ts, minor fixes
1 parent 6fa4002 commit 0f2bbb1

4 files changed

Lines changed: 28 additions & 23 deletions

File tree

Jakefile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var compilerSources = [
4242
"checker.ts",
4343
"factory.ts",
4444
"visitor.ts",
45+
"transformer.ts",
4546
"sourcemap.ts",
4647
"declarationEmitter.ts",
4748
"emitter.ts",
@@ -64,6 +65,7 @@ var servicesSources = [
6465
"checker.ts",
6566
"factory.ts",
6667
"visitor.ts",
68+
"transformer.ts",
6769
"sourcemap.ts",
6870
"declarationEmitter.ts",
6971
"emitter.ts",

src/compiler/transformer.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
/* @internal */
44
namespace ts {
5-
export function getTransformers(compilerOptions: CompilerOptions) {
6-
const transformers: Transformer[] = [];
7-
// TODO(rbuckton): Add transformers
8-
return transformers;
9-
}
10-
5+
/**
6+
* Transforms an array of SourceFiles by passing them through each transformer.
7+
*
8+
* @param resolver The emit resolver provided by the checker.
9+
* @param host The emit host.
10+
* @param sourceFiles An array of source files
11+
* @param transforms An array of Transformers.
12+
*/
1113
export function transformFiles(resolver: EmitResolver, host: EmitHost, sourceFiles: SourceFile[], transformers: Transformer[]) {
1214
const nodeToGeneratedName: Identifier[] = [];
1315
const generatedNameSet: Map<string> = {};
@@ -19,6 +21,8 @@ namespace ts {
1921
let hoistedFunctionDeclarations: FunctionDeclaration[];
2022
let currentSourceFile: SourceFile;
2123

24+
// The transformation context is provided to each transformer as part of transformer
25+
// initialization.
2226
const context: TransformationContext = {
2327
getCompilerOptions: () => host.getCompilerOptions(),
2428
getEmitResolver: () => resolver,
@@ -42,6 +46,7 @@ namespace ts {
4246

4347
/**
4448
* Transforms a source file.
49+
*
4550
* @param sourceFile The source file to transform.
4651
*/
4752
function transformSourceFile(sourceFile: SourceFile) {
@@ -161,9 +166,7 @@ namespace ts {
161166
return generateNameForExportDefault();
162167
case SyntaxKind.ClassExpression:
163168
return generateNameForClassExpression();
164-
case SyntaxKind.ComputedPropertyName:
165-
case SyntaxKind.Parameter:
166-
case SyntaxKind.TaggedTemplateExpression:
169+
default:
167170
return createTempVariable(TempVariableKind.Auto);
168171
}
169172
}

src/compiler/types.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,11 +2790,20 @@ namespace ts {
27902790

27912791
/* @internal */
27922792
export const enum NodeEmitFlags {
2793-
EmitHelpers = 1 << 0,
2794-
EmitExportStar = 1 << 1,
2795-
UMDDefine = 1 << 2,
2796-
NoLexicalEnvironment = 1 << 3,
2797-
SingleLine = 1 << 4,
2793+
EmitHelpers = 1 << 0, // Any emit helpers should be written to this node.
2794+
EmitExportStar = 1 << 1, // The export * helper should be written to this node.
2795+
UMDDefine = 1 << 2, // This node should be replaced with the UMD define helper.
2796+
NoLexicalEnvironment = 1 << 3, // A new LexicalEnvironment should *not* be introduced when emitting this node.
2797+
SingleLine = 1 << 4, // The contents of this node should be emit on a single line.
2798+
}
2799+
2800+
/** Additional context provided to `visitEachChild` */
2801+
export interface LexicalEnvironment {
2802+
/** Starts a new lexical environment. */
2803+
startLexicalEnvironment(): void;
2804+
2805+
/** Ends a lexical environment, returning any declarations. */
2806+
endLexicalEnvironment(): Statement[];
27982807
}
27992808

28002809
/* @internal */

src/compiler/visitor.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22

33
/* @internal */
44
namespace ts {
5-
/** Additional context provided to `visitEachChild` */
6-
export interface LexicalEnvironment {
7-
/** Starts a new lexical environment. */
8-
startLexicalEnvironment(): void;
9-
10-
/** Ends a lexical environment, returning any declarations. */
11-
endLexicalEnvironment(): Statement[];
12-
}
13-
145
/**
156
* Describes an edge of a Node, used when traversing a syntax tree.
167
*/

0 commit comments

Comments
 (0)