Skip to content

Commit f484ff4

Browse files
committed
Reenabled transforms.
1 parent 52c62d0 commit f484ff4

2 files changed

Lines changed: 36 additions & 59 deletions

File tree

src/compiler/transformer.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,47 @@
11
/// <reference path="visitor.ts" />
2+
/// <reference path="transformers/ts.ts" />
3+
/// <reference path="transformers/jsx.ts" />
4+
/// <reference path="transformers/es7.ts" />
5+
/// <reference path="transformers/es6.ts" />
6+
/// <reference path="transformers/module/module.ts" />
7+
/// <reference path="transformers/module/system.ts" />
8+
/// <reference path="transformers/module/es6.ts" />
29

310
/* @internal */
411
namespace ts {
12+
const moduleTransformerMap: Map<Transformer> = {
13+
[ModuleKind.ES6]: transformES6Module,
14+
[ModuleKind.System]: transformSystemModule,
15+
[ModuleKind.AMD]: transformModule,
16+
[ModuleKind.CommonJS]: transformModule,
17+
[ModuleKind.UMD]: transformModule,
18+
[ModuleKind.None]: transformModule,
19+
};
20+
521
const enum SyntaxKindFeatureFlags {
622
ExpressionSubstitution = 1 << 0,
723
EmitNotifications = 1 << 1,
824
}
925

1026
export function getTransformers(compilerOptions: CompilerOptions) {
27+
const jsx = compilerOptions.jsx;
28+
const languageVersion = getEmitScriptTarget(compilerOptions);
29+
const moduleKind = getEmitModuleKind(compilerOptions);
1130
const transformers: Transformer[] = [];
12-
// TODO(rbuckton): Add transformers
31+
32+
transformers.push(transformTypeScript);
33+
transformers.push(moduleTransformerMap[moduleKind]);
34+
35+
if (jsx === JsxEmit.React) {
36+
transformers.push(transformJsx);
37+
}
38+
39+
transformers.push(transformES7);
40+
41+
if (languageVersion < ScriptTarget.ES6) {
42+
transformers.push(transformES6);
43+
}
44+
1345
return transformers;
1446
}
1547

src/compiler/transformers/ts.ts

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace ts {
77
type SuperContainer = ClassDeclaration | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ConstructorDeclaration;
88

9-
// TODO(rbuckton): TS->ES7 transformer
109
export function transformTypeScript(context: TransformationContext) {
1110
const {
1211
nodeHasGeneratedName,
@@ -38,7 +37,6 @@ namespace ts {
3837
let currentScope: SourceFile | Block | ModuleBlock | CaseBlock;
3938
let currentParent: Node;
4039
let currentNode: Node;
41-
let isRightmostExpression: boolean;
4240
let superContainerStack: SuperContainer[];
4341

4442
return transformSourceFile;
@@ -47,7 +45,6 @@ namespace ts {
4745
currentSourceFile = node;
4846
node = visitEachChild(node, visitor, context);
4947
setNodeEmitFlags(node, NodeEmitFlags.EmitEmitHelpers);
50-
currentSourceFile = undefined;
5148
return node;
5249
}
5350

@@ -61,14 +58,12 @@ namespace ts {
6158
const savedCurrentScope = currentScope;
6259
const savedCurrentParent = currentParent;
6360
const savedCurrentNode = currentNode;
64-
const savedIsRightmostExpression = isRightmostExpression;
6561
onBeforeVisitNode(node);
6662
node = visitor(node);
6763
currentNamespace = savedCurrentNamespace;
6864
currentScope = savedCurrentScope;
6965
currentParent = savedCurrentParent;
7066
currentNode = savedCurrentNode;
71-
isRightmostExpression = savedIsRightmostExpression;
7267
return node;
7368
}
7469

@@ -334,11 +329,6 @@ namespace ts {
334329
currentScope = <SourceFile | CaseBlock | ModuleBlock | Block>node;
335330
break;
336331
}
337-
338-
// Keep track of whether this is the right-most expression of an expression tree.
339-
// This is used to determine whether to parenthesize an `await` expression transformed
340-
// into a `yield` expression.
341-
isRightmostExpression = currentParent && isRightmost(currentParent, currentNode, isRightmostExpression);
342332
}
343333

344334
/**
@@ -567,7 +557,7 @@ namespace ts {
567557
*
568558
* @param node The node to transform.
569559
*/
570-
function visitClassExpression(node: ClassExpression): LeftHandSideExpression {
560+
function visitClassExpression(node: ClassExpression): Expression {
571561
const staticProperties = getInitializedProperties(node, /*isStatic*/ true);
572562
const heritageClauses = visitNodes(node.heritageClauses, visitor, isHeritageClause);
573563
const members = transformClassMembers(node, heritageClauses !== undefined);
@@ -598,7 +588,7 @@ namespace ts {
598588
addNode(expressions, createAssignment(temp, classExpression));
599589
addNodes(expressions, generateInitializedPropertyExpressions(node, staticProperties, temp));
600590
addNode(expressions, temp);
601-
return createParen(inlineExpressions(expressions));
591+
return inlineExpressions(expressions);
602592
}
603593

604594
return classExpression;
@@ -2229,12 +2219,10 @@ namespace ts {
22292219
* @param node The await expression node.
22302220
*/
22312221
function visitAwaitExpression(node: AwaitExpression): Expression {
2232-
const expression = createYield(
2222+
return createYield(
22332223
visitNode(node.expression, visitor, isExpression),
22342224
node
22352225
);
2236-
2237-
return isRightmostExpression ? expression : createParen(expression);
22382226
}
22392227

22402228
/**
@@ -2690,48 +2678,5 @@ namespace ts {
26902678
}
26912679
}
26922680
}
2693-
2694-
function isRightmost(parentNode: Node, node: Node, wasRightmost: boolean) {
2695-
switch (parentNode.kind) {
2696-
case SyntaxKind.VariableDeclaration:
2697-
case SyntaxKind.Parameter:
2698-
case SyntaxKind.BindingElement:
2699-
case SyntaxKind.PropertyDeclaration:
2700-
case SyntaxKind.PropertyAssignment:
2701-
case SyntaxKind.ShorthandPropertyAssignment:
2702-
case SyntaxKind.ExpressionStatement:
2703-
case SyntaxKind.ArrayLiteralExpression:
2704-
case SyntaxKind.ThrowStatement:
2705-
case SyntaxKind.ReturnStatement:
2706-
case SyntaxKind.ForStatement:
2707-
case SyntaxKind.ForOfStatement:
2708-
case SyntaxKind.ForInStatement:
2709-
case SyntaxKind.DoStatement:
2710-
case SyntaxKind.WhileStatement:
2711-
case SyntaxKind.SwitchStatement:
2712-
case SyntaxKind.CaseClause:
2713-
case SyntaxKind.WithStatement:
2714-
case SyntaxKind.Decorator:
2715-
case SyntaxKind.ExpressionWithTypeArguments:
2716-
case SyntaxKind.SpreadElementExpression:
2717-
case SyntaxKind.AsExpression:
2718-
case SyntaxKind.TypeAssertionExpression:
2719-
case SyntaxKind.EnumMember:
2720-
case SyntaxKind.JsxAttribute:
2721-
case SyntaxKind.JsxSpreadAttribute:
2722-
case SyntaxKind.JsxExpression:
2723-
return true;
2724-
case SyntaxKind.TemplateSpan:
2725-
case SyntaxKind.CallExpression:
2726-
case SyntaxKind.NewExpression:
2727-
return node !== (<CallExpression | NewExpression>parentNode).expression;
2728-
case SyntaxKind.BinaryExpression:
2729-
return wasRightmost && node === (<BinaryExpression>parentNode).right;
2730-
case SyntaxKind.ConditionalExpression:
2731-
return wasRightmost && node === (<ConditionalExpression>parentNode).whenTrue;
2732-
default:
2733-
return wasRightmost;
2734-
}
2735-
}
27362681
}
27372682
}

0 commit comments

Comments
 (0)