66namespace 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