@@ -3093,32 +3093,24 @@ namespace ts {
30933093
30943094 function computeCallExpression ( node : CallExpression , subtreeFlags : TransformFlags ) {
30953095 let transformFlags = subtreeFlags ;
3096+ const callee = skipOuterExpressions ( node . expression ) ;
30963097 const expression = node . expression ;
30973098
30983099 if ( node . typeArguments ) {
30993100 transformFlags |= TransformFlags . AssertTypeScript ;
31003101 }
31013102
3102- if ( subtreeFlags & TransformFlags . ContainsRestOrSpread
3103- || ( expression . transformFlags & ( TransformFlags . Super | TransformFlags . ContainsSuper ) ) ) {
3103+ if ( subtreeFlags & TransformFlags . ContainsRestOrSpread || isSuperOrSuperProperty ( callee ) ) {
31043104 // If the this node contains a SpreadExpression, or is a super call, then it is an ES6
31053105 // node.
31063106 transformFlags |= TransformFlags . AssertES2015 ;
3107- // super property or element accesses could be inside lambdas, etc, and need a captured `this`,
3108- // while super keyword for super calls (indicated by TransformFlags.Super) does not (since it can only be top-level in a constructor)
3109- if ( expression . transformFlags & TransformFlags . ContainsSuper ) {
3107+ if ( isSuperProperty ( callee ) ) {
31103108 transformFlags |= TransformFlags . ContainsLexicalThis ;
31113109 }
31123110 }
31133111
31143112 if ( expression . kind === SyntaxKind . ImportKeyword ) {
31153113 transformFlags |= TransformFlags . ContainsDynamicImport ;
3116-
3117- // A dynamic 'import()' call that contains a lexical 'this' will
3118- // require a captured 'this' when emitting down-level.
3119- if ( subtreeFlags & TransformFlags . ContainsLexicalThis ) {
3120- transformFlags |= TransformFlags . ContainsCapturedLexicalThis ;
3121- }
31223114 }
31233115
31243116 node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
@@ -3191,7 +3183,7 @@ namespace ts {
31913183 // If a parameter has an initializer, a binding pattern or a dotDotDot token, then
31923184 // it is ES6 syntax and its container must emit default value assignments or parameter destructuring downlevel.
31933185 if ( subtreeFlags & TransformFlags . ContainsBindingPattern || initializer || dotDotDotToken ) {
3194- transformFlags |= TransformFlags . AssertES2015 | TransformFlags . ContainsDefaultValueAssignments ;
3186+ transformFlags |= TransformFlags . AssertES2015 ;
31953187 }
31963188
31973189 node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
@@ -3202,7 +3194,6 @@ namespace ts {
32023194 let transformFlags = subtreeFlags ;
32033195 const expression = node . expression ;
32043196 const expressionKind = expression . kind ;
3205- const expressionTransformFlags = expression . transformFlags ;
32063197
32073198 // If the node is synthesized, it means the emitter put the parentheses there,
32083199 // not the user. If we didn't want them, the emitter would not have put them
@@ -3212,12 +3203,6 @@ namespace ts {
32123203 transformFlags |= TransformFlags . AssertTypeScript ;
32133204 }
32143205
3215- // If the expression of a ParenthesizedExpression is a destructuring assignment,
3216- // then the ParenthesizedExpression is a destructuring assignment.
3217- if ( expressionTransformFlags & TransformFlags . DestructuringAssignment ) {
3218- transformFlags |= TransformFlags . DestructuringAssignment ;
3219- }
3220-
32213206 node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
32223207 return transformFlags & ~ TransformFlags . OuterExpressionExcludes ;
32233208 }
@@ -3241,12 +3226,6 @@ namespace ts {
32413226 || node . typeParameters ) {
32423227 transformFlags |= TransformFlags . AssertTypeScript ;
32433228 }
3244-
3245- if ( subtreeFlags & TransformFlags . ContainsLexicalThisInComputedPropertyName ) {
3246- // A computed property name containing `this` might need to be rewritten,
3247- // so propagate the ContainsLexicalThis flag upward.
3248- transformFlags |= TransformFlags . ContainsLexicalThis ;
3249- }
32503229 }
32513230
32523231 node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
@@ -3264,12 +3243,6 @@ namespace ts {
32643243 transformFlags |= TransformFlags . AssertTypeScript ;
32653244 }
32663245
3267- if ( subtreeFlags & TransformFlags . ContainsLexicalThisInComputedPropertyName ) {
3268- // A computed property name containing `this` might need to be rewritten,
3269- // so propagate the ContainsLexicalThis flag upward.
3270- transformFlags |= TransformFlags . ContainsLexicalThis ;
3271- }
3272-
32733246 node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
32743247 return transformFlags & ~ TransformFlags . ClassExcludes ;
32753248 }
@@ -3374,7 +3347,7 @@ namespace ts {
33743347 }
33753348
33763349 node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3377- return transformFlags & ~ TransformFlags . MethodOrAccessorExcludes ;
3350+ return propagatePropertyNameFlags ( node . name , transformFlags & ~ TransformFlags . MethodOrAccessorExcludes ) ;
33783351 }
33793352
33803353 function computeAccessor ( node : AccessorDeclaration , subtreeFlags : TransformFlags ) {
@@ -3396,7 +3369,7 @@ namespace ts {
33963369 }
33973370
33983371 node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3399- return transformFlags & ~ TransformFlags . MethodOrAccessorExcludes ;
3372+ return propagatePropertyNameFlags ( node . name , transformFlags & ~ TransformFlags . MethodOrAccessorExcludes ) ;
34003373 }
34013374
34023375 function computePropertyDeclaration ( node : PropertyDeclaration , subtreeFlags : TransformFlags ) {
@@ -3410,7 +3383,7 @@ namespace ts {
34103383 }
34113384
34123385 node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3413- return transformFlags & ~ TransformFlags . NodeExcludes ;
3386+ return propagatePropertyNameFlags ( node . name , transformFlags & ~ TransformFlags . PropertyExcludes ) ;
34143387 }
34153388
34163389 function computeFunctionDeclaration ( node : FunctionDeclaration , subtreeFlags : TransformFlags ) {
@@ -3444,13 +3417,6 @@ namespace ts {
34443417 transformFlags |= TransformFlags . AssertES2018 ;
34453418 }
34463419
3447- // If a FunctionDeclaration's subtree has marked the container as needing to capture the
3448- // lexical this, or the function contains parameters with initializers, then this node is
3449- // ES6 syntax.
3450- if ( subtreeFlags & TransformFlags . ES2015FunctionSyntaxMask ) {
3451- transformFlags |= TransformFlags . AssertES2015 ;
3452- }
3453-
34543420 // If a FunctionDeclaration is generator function and is the body of a
34553421 // transformed async function, then this node can be transformed to a
34563422 // down-level generator.
@@ -3486,14 +3452,6 @@ namespace ts {
34863452 transformFlags |= TransformFlags . AssertES2018 ;
34873453 }
34883454
3489-
3490- // If a FunctionExpression's subtree has marked the container as needing to capture the
3491- // lexical this, or the function contains parameters with initializers, then this node is
3492- // ES6 syntax.
3493- if ( subtreeFlags & TransformFlags . ES2015FunctionSyntaxMask ) {
3494- transformFlags |= TransformFlags . AssertES2015 ;
3495- }
3496-
34973455 // If a FunctionExpression is generator function and is the body of a
34983456 // transformed async function, then this node can be transformed to a
34993457 // down-level generator.
@@ -3527,11 +3485,6 @@ namespace ts {
35273485 transformFlags |= TransformFlags . AssertES2018 ;
35283486 }
35293487
3530- // If an ArrowFunction contains a lexical this, its container must capture the lexical this.
3531- if ( subtreeFlags & TransformFlags . ContainsLexicalThis ) {
3532- transformFlags |= TransformFlags . ContainsCapturedLexicalThis ;
3533- }
3534-
35353488 node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
35363489 return transformFlags & ~ TransformFlags . ArrowFunctionExcludes ;
35373490 }
@@ -3541,11 +3494,10 @@ namespace ts {
35413494
35423495 // If a PropertyAccessExpression starts with a super keyword, then it is
35433496 // ES6 syntax, and requires a lexical `this` binding.
3544- if ( transformFlags & TransformFlags . Super ) {
3545- transformFlags ^= TransformFlags . Super ;
3497+ if ( node . expression . kind === SyntaxKind . SuperKeyword ) {
35463498 // super inside of an async function requires hoisting the super access (ES2017).
35473499 // same for super inside of an async generator, which is ES2018.
3548- transformFlags |= TransformFlags . ContainsSuper | TransformFlags . ContainsES2017 | TransformFlags . ContainsES2018 ;
3500+ transformFlags |= TransformFlags . ContainsES2017 | TransformFlags . ContainsES2018 ;
35493501 }
35503502
35513503 node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
@@ -3554,16 +3506,13 @@ namespace ts {
35543506
35553507 function computeElementAccess ( node : ElementAccessExpression , subtreeFlags : TransformFlags ) {
35563508 let transformFlags = subtreeFlags ;
3557- const expression = node . expression ;
3558- const expressionFlags = expression . transformFlags ; // We do not want to aggregate flags from the argument expression for super/this capturing
35593509
35603510 // If an ElementAccessExpression starts with a super keyword, then it is
35613511 // ES6 syntax, and requires a lexical `this` binding.
3562- if ( expressionFlags & TransformFlags . Super ) {
3563- transformFlags &= ~ TransformFlags . Super ;
3512+ if ( node . expression . kind === SyntaxKind . SuperKeyword ) {
35643513 // super inside of an async function requires hoisting the super access (ES2017).
35653514 // same for super inside of an async generator, which is ES2018.
3566- transformFlags |= TransformFlags . ContainsSuper | TransformFlags . ContainsES2017 | TransformFlags . ContainsES2018 ;
3515+ transformFlags |= TransformFlags . ContainsES2017 | TransformFlags . ContainsES2018 ;
35673516 }
35683517
35693518 node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
@@ -3572,7 +3521,7 @@ namespace ts {
35723521
35733522 function computeVariableDeclaration ( node : VariableDeclaration , subtreeFlags : TransformFlags ) {
35743523 let transformFlags = subtreeFlags ;
3575- transformFlags |= TransformFlags . AssertES2015 | TransformFlags . ContainsBindingPattern ;
3524+ transformFlags |= TransformFlags . AssertES2015 | TransformFlags . ContainsBindingPattern ; // TODO(rbuckton): Why are these set unconditionally?
35763525
35773526 // A VariableDeclaration containing ObjectRest is ES2018 syntax
35783527 if ( subtreeFlags & TransformFlags . ContainsObjectRestOrSpread ) {
@@ -3634,15 +3583,7 @@ namespace ts {
36343583 }
36353584
36363585 function computeExpressionStatement ( node : ExpressionStatement , subtreeFlags : TransformFlags ) {
3637- let transformFlags = subtreeFlags ;
3638-
3639- // If the expression of an expression statement is a destructuring assignment,
3640- // then we treat the statement as ES6 so that we can indicate that we do not
3641- // need to hold on to the right-hand side.
3642- if ( node . expression . transformFlags & TransformFlags . DestructuringAssignment ) {
3643- transformFlags |= TransformFlags . AssertES2015 ;
3644- }
3645-
3586+ const transformFlags = subtreeFlags ;
36463587 node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
36473588 return transformFlags & ~ TransformFlags . NodeExcludes ;
36483589 }
@@ -3815,17 +3756,6 @@ namespace ts {
38153756 // This is so that they can flow through PropertyName transforms unaffected.
38163757 // Instead, we mark the container as ES6, so that it can properly handle the transform.
38173758 transformFlags |= TransformFlags . ContainsComputedPropertyName ;
3818- if ( subtreeFlags & TransformFlags . ContainsLexicalThis ) {
3819- // A computed method name like `[this.getName()](x: string) { ... }` needs to
3820- // distinguish itself from the normal case of a method body containing `this`:
3821- // `this` inside a method doesn't need to be rewritten (the method provides `this`),
3822- // whereas `this` inside a computed name *might* need to be rewritten if the class/object
3823- // is inside an arrow function:
3824- // `_this = this; () => class K { [_this.getName()]() { ... } }`
3825- // To make this distinction, use ContainsLexicalThisInComputedPropertyName
3826- // instead of ContainsLexicalThis for computed property names
3827- transformFlags |= TransformFlags . ContainsLexicalThisInComputedPropertyName ;
3828- }
38293759 break ;
38303760
38313761 case SyntaxKind . SpreadElement :
@@ -3838,7 +3768,7 @@ namespace ts {
38383768
38393769 case SyntaxKind . SuperKeyword :
38403770 // This node is ES6 syntax.
3841- transformFlags |= TransformFlags . AssertES2015 | TransformFlags . Super ;
3771+ transformFlags |= TransformFlags . AssertES2015 ;
38423772 excludeFlags = TransformFlags . OuterExpressionExcludes ; // must be set to persist `Super`
38433773 break ;
38443774
@@ -3880,12 +3810,6 @@ namespace ts {
38803810 transformFlags |= TransformFlags . AssertES2015 ;
38813811 }
38823812
3883- if ( subtreeFlags & TransformFlags . ContainsLexicalThisInComputedPropertyName ) {
3884- // A computed property name containing `this` might need to be rewritten,
3885- // so propagate the ContainsLexicalThis flag upward.
3886- transformFlags |= TransformFlags . ContainsLexicalThis ;
3887- }
3888-
38893813 if ( subtreeFlags & TransformFlags . ContainsObjectRestOrSpread ) {
38903814 // If an ObjectLiteralExpression contains a spread element, then it
38913815 // is an ES2018 node.
@@ -3895,14 +3819,7 @@ namespace ts {
38953819 break ;
38963820
38973821 case SyntaxKind . ArrayLiteralExpression :
3898- case SyntaxKind . NewExpression :
38993822 excludeFlags = TransformFlags . ArrayLiteralOrCallOrNewExcludes ;
3900- if ( subtreeFlags & TransformFlags . ContainsRestOrSpread ) {
3901- // If the this node contains a SpreadExpression, then it is an ES6
3902- // node.
3903- transformFlags |= TransformFlags . AssertES2015 ;
3904- }
3905-
39063823 break ;
39073824
39083825 case SyntaxKind . DoStatement :
@@ -3917,10 +3834,6 @@ namespace ts {
39173834 break ;
39183835
39193836 case SyntaxKind . SourceFile :
3920- if ( subtreeFlags & TransformFlags . ContainsCapturedLexicalThis ) {
3921- transformFlags |= TransformFlags . AssertES2015 ;
3922- }
3923-
39243837 break ;
39253838
39263839 case SyntaxKind . ReturnStatement :
@@ -3938,6 +3851,10 @@ namespace ts {
39383851 return transformFlags & ~ excludeFlags ;
39393852 }
39403853
3854+ function propagatePropertyNameFlags ( node : PropertyName , transformFlags : TransformFlags ) {
3855+ return transformFlags | ( node . transformFlags & TransformFlags . PropertyNamePropagatingFlags ) ;
3856+ }
3857+
39413858 /**
39423859 * Gets the transform flags to exclude when unioning the transform flags of a subtree.
39433860 *
0 commit comments