@@ -2740,6 +2740,9 @@ namespace ts {
2740
2740
case SyntaxKind . PropertyAccessExpression :
2741
2741
return computePropertyAccess ( < PropertyAccessExpression > node , subtreeFlags ) ;
2742
2742
2743
+ case SyntaxKind . ElementAccessExpression :
2744
+ return computeElementAccess ( < ElementAccessExpression > node , subtreeFlags ) ;
2745
+
2743
2746
default :
2744
2747
return computeOther ( node , kind , subtreeFlags ) ;
2745
2748
}
@@ -2748,17 +2751,21 @@ namespace ts {
2748
2751
function computeCallExpression ( node : CallExpression , subtreeFlags : TransformFlags ) {
2749
2752
let transformFlags = subtreeFlags ;
2750
2753
const expression = node . expression ;
2751
- const expressionKind = expression . kind ;
2752
2754
2753
2755
if ( node . typeArguments ) {
2754
2756
transformFlags |= TransformFlags . AssertTypeScript ;
2755
2757
}
2756
2758
2757
2759
if ( subtreeFlags & TransformFlags . ContainsSpread
2758
- || isSuperOrSuperProperty ( expression , expressionKind ) ) {
2760
+ || ( expression . transformFlags & ( TransformFlags . Super | TransformFlags . ContainsSuper ) ) ) {
2759
2761
// If the this node contains a SpreadExpression, or is a super call, then it is an ES6
2760
2762
// node.
2761
2763
transformFlags |= TransformFlags . AssertES2015 ;
2764
+ // super property or element accesses could be inside lambdas, etc, and need a captured `this`,
2765
+ // while super keyword for super calls (indicated by TransformFlags.Super) does not (since it can only be top-level in a constructor)
2766
+ if ( expression . transformFlags & TransformFlags . ContainsSuper ) {
2767
+ transformFlags |= TransformFlags . ContainsLexicalThis ;
2768
+ }
2762
2769
}
2763
2770
2764
2771
if ( expression . kind === SyntaxKind . ImportKeyword ) {
@@ -2775,21 +2782,6 @@ namespace ts {
2775
2782
return transformFlags & ~ TransformFlags . ArrayLiteralOrCallOrNewExcludes ;
2776
2783
}
2777
2784
2778
- function isSuperOrSuperProperty ( node : Node , kind : SyntaxKind ) {
2779
- switch ( kind ) {
2780
- case SyntaxKind . SuperKeyword :
2781
- return true ;
2782
-
2783
- case SyntaxKind . PropertyAccessExpression :
2784
- case SyntaxKind . ElementAccessExpression :
2785
- const expression = ( < PropertyAccessExpression | ElementAccessExpression > node ) . expression ;
2786
- const expressionKind = expression . kind ;
2787
- return expressionKind === SyntaxKind . SuperKeyword ;
2788
- }
2789
-
2790
- return false ;
2791
- }
2792
-
2793
2785
function computeNewExpression ( node : NewExpression , subtreeFlags : TransformFlags ) {
2794
2786
let transformFlags = subtreeFlags ;
2795
2787
if ( node . typeArguments ) {
@@ -2884,7 +2876,7 @@ namespace ts {
2884
2876
}
2885
2877
2886
2878
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
2887
- return transformFlags & ~ TransformFlags . NodeExcludes ;
2879
+ return transformFlags & ~ TransformFlags . OuterExpressionExcludes ;
2888
2880
}
2889
2881
2890
2882
function computeClassDeclaration ( node : ClassDeclaration , subtreeFlags : TransformFlags ) {
@@ -3203,17 +3195,32 @@ namespace ts {
3203
3195
3204
3196
function computePropertyAccess ( node : PropertyAccessExpression , subtreeFlags : TransformFlags ) {
3205
3197
let transformFlags = subtreeFlags ;
3206
- const expression = node . expression ;
3207
- const expressionKind = expression . kind ;
3208
3198
3209
3199
// If a PropertyAccessExpression starts with a super keyword, then it is
3210
3200
// ES6 syntax, and requires a lexical `this` binding.
3211
- if ( expressionKind === SyntaxKind . SuperKeyword ) {
3212
- transformFlags |= TransformFlags . ContainsLexicalThis ;
3201
+ if ( transformFlags & TransformFlags . Super ) {
3202
+ transformFlags ^= TransformFlags . Super ;
3203
+ transformFlags |= TransformFlags . ContainsSuper ;
3213
3204
}
3214
3205
3215
3206
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3216
- return transformFlags & ~ TransformFlags . NodeExcludes ;
3207
+ return transformFlags & ~ TransformFlags . PropertyAccessExcludes ;
3208
+ }
3209
+
3210
+ function computeElementAccess ( node : ElementAccessExpression , subtreeFlags : TransformFlags ) {
3211
+ let transformFlags = subtreeFlags ;
3212
+ const expression = node . expression ;
3213
+ const expressionFlags = expression . transformFlags ; // We do not want to aggregate flags from the argument expression for super/this capturing
3214
+
3215
+ // If an ElementAccessExpression starts with a super keyword, then it is
3216
+ // ES6 syntax, and requires a lexical `this` binding.
3217
+ if ( expressionFlags & TransformFlags . Super ) {
3218
+ transformFlags &= ~ TransformFlags . Super ;
3219
+ transformFlags |= TransformFlags . ContainsSuper ;
3220
+ }
3221
+
3222
+ node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3223
+ return transformFlags & ~ TransformFlags . PropertyAccessExcludes ;
3217
3224
}
3218
3225
3219
3226
function computeVariableDeclaration ( node : VariableDeclaration , subtreeFlags : TransformFlags ) {
@@ -3333,6 +3340,13 @@ namespace ts {
3333
3340
transformFlags |= TransformFlags . AssertESNext | TransformFlags . AssertES2017 ;
3334
3341
break ;
3335
3342
3343
+ case SyntaxKind . TypeAssertionExpression :
3344
+ case SyntaxKind . AsExpression :
3345
+ case SyntaxKind . PartiallyEmittedExpression :
3346
+ // These nodes are TypeScript syntax.
3347
+ transformFlags |= TransformFlags . AssertTypeScript ;
3348
+ excludeFlags = TransformFlags . OuterExpressionExcludes ;
3349
+ break ;
3336
3350
case SyntaxKind . PublicKeyword :
3337
3351
case SyntaxKind . PrivateKeyword :
3338
3352
case SyntaxKind . ProtectedKeyword :
@@ -3341,8 +3355,6 @@ namespace ts {
3341
3355
case SyntaxKind . ConstKeyword :
3342
3356
case SyntaxKind . EnumDeclaration :
3343
3357
case SyntaxKind . EnumMember :
3344
- case SyntaxKind . TypeAssertionExpression :
3345
- case SyntaxKind . AsExpression :
3346
3358
case SyntaxKind . NonNullExpression :
3347
3359
case SyntaxKind . ReadonlyKeyword :
3348
3360
// These nodes are TypeScript syntax.
@@ -3470,7 +3482,8 @@ namespace ts {
3470
3482
3471
3483
case SyntaxKind . SuperKeyword :
3472
3484
// This node is ES6 syntax.
3473
- transformFlags |= TransformFlags . AssertES2015 ;
3485
+ transformFlags |= TransformFlags . AssertES2015 | TransformFlags . Super ;
3486
+ excludeFlags = TransformFlags . OuterExpressionExcludes ; // must be set to persist `Super`
3474
3487
break ;
3475
3488
3476
3489
case SyntaxKind . ThisKeyword :
@@ -3627,6 +3640,15 @@ namespace ts {
3627
3640
case SyntaxKind . ObjectBindingPattern :
3628
3641
case SyntaxKind . ArrayBindingPattern :
3629
3642
return TransformFlags . BindingPatternExcludes ;
3643
+ case SyntaxKind . TypeAssertionExpression :
3644
+ case SyntaxKind . AsExpression :
3645
+ case SyntaxKind . PartiallyEmittedExpression :
3646
+ case SyntaxKind . ParenthesizedExpression :
3647
+ case SyntaxKind . SuperKeyword :
3648
+ return TransformFlags . OuterExpressionExcludes ;
3649
+ case SyntaxKind . PropertyAccessExpression :
3650
+ case SyntaxKind . ElementAccessExpression :
3651
+ return TransformFlags . PropertyAccessExcludes ;
3630
3652
default :
3631
3653
return TransformFlags . NodeExcludes ;
3632
3654
}
0 commit comments