From 0f2bbb181faff0ee16bc30b0a81f27b6ac3293b6 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 9 Feb 2016 12:39:46 -0800 Subject: [PATCH] Moved LexicalEnvironment to types.ts, minor fixes --- Jakefile.js | 2 ++ src/compiler/transformer.ts | 21 ++++++++++++--------- src/compiler/types.ts | 19 ++++++++++++++----- src/compiler/visitor.ts | 9 --------- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index a63df27b824..3dd9999aa8a 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -42,6 +42,7 @@ var compilerSources = [ "checker.ts", "factory.ts", "visitor.ts", + "transformer.ts", "sourcemap.ts", "declarationEmitter.ts", "emitter.ts", @@ -64,6 +65,7 @@ var servicesSources = [ "checker.ts", "factory.ts", "visitor.ts", + "transformer.ts", "sourcemap.ts", "declarationEmitter.ts", "emitter.ts", diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index a4a5ae7c91a..d6d3dedd361 100644 --- a/src/compiler/transformer.ts +++ b/src/compiler/transformer.ts @@ -2,12 +2,14 @@ /* @internal */ namespace ts { - export function getTransformers(compilerOptions: CompilerOptions) { - const transformers: Transformer[] = []; - // TODO(rbuckton): Add transformers - return transformers; - } - + /** + * Transforms an array of SourceFiles by passing them through each transformer. + * + * @param resolver The emit resolver provided by the checker. + * @param host The emit host. + * @param sourceFiles An array of source files + * @param transforms An array of Transformers. + */ export function transformFiles(resolver: EmitResolver, host: EmitHost, sourceFiles: SourceFile[], transformers: Transformer[]) { const nodeToGeneratedName: Identifier[] = []; const generatedNameSet: Map = {}; @@ -19,6 +21,8 @@ namespace ts { let hoistedFunctionDeclarations: FunctionDeclaration[]; let currentSourceFile: SourceFile; + // The transformation context is provided to each transformer as part of transformer + // initialization. const context: TransformationContext = { getCompilerOptions: () => host.getCompilerOptions(), getEmitResolver: () => resolver, @@ -42,6 +46,7 @@ namespace ts { /** * Transforms a source file. + * * @param sourceFile The source file to transform. */ function transformSourceFile(sourceFile: SourceFile) { @@ -161,9 +166,7 @@ namespace ts { return generateNameForExportDefault(); case SyntaxKind.ClassExpression: return generateNameForClassExpression(); - case SyntaxKind.ComputedPropertyName: - case SyntaxKind.Parameter: - case SyntaxKind.TaggedTemplateExpression: + default: return createTempVariable(TempVariableKind.Auto); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 23c46a71a58..772c90fb08c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2790,11 +2790,20 @@ namespace ts { /* @internal */ export const enum NodeEmitFlags { - EmitHelpers = 1 << 0, - EmitExportStar = 1 << 1, - UMDDefine = 1 << 2, - NoLexicalEnvironment = 1 << 3, - SingleLine = 1 << 4, + EmitHelpers = 1 << 0, // Any emit helpers should be written to this node. + EmitExportStar = 1 << 1, // The export * helper should be written to this node. + UMDDefine = 1 << 2, // This node should be replaced with the UMD define helper. + NoLexicalEnvironment = 1 << 3, // A new LexicalEnvironment should *not* be introduced when emitting this node. + SingleLine = 1 << 4, // The contents of this node should be emit on a single line. + } + + /** Additional context provided to `visitEachChild` */ + export interface LexicalEnvironment { + /** Starts a new lexical environment. */ + startLexicalEnvironment(): void; + + /** Ends a lexical environment, returning any declarations. */ + endLexicalEnvironment(): Statement[]; } /* @internal */ diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 94faf7b1e10..6e63524a23c 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -2,15 +2,6 @@ /* @internal */ namespace ts { - /** Additional context provided to `visitEachChild` */ - export interface LexicalEnvironment { - /** Starts a new lexical environment. */ - startLexicalEnvironment(): void; - - /** Ends a lexical environment, returning any declarations. */ - endLexicalEnvironment(): Statement[]; - } - /** * Describes an edge of a Node, used when traversing a syntax tree. */