@@ -2734,6 +2734,9 @@ namespace ts {
2734
2734
case SyntaxKind . PropertyAccessExpression :
2735
2735
return computePropertyAccess ( < PropertyAccessExpression > node , subtreeFlags ) ;
2736
2736
2737
+ case SyntaxKind . ElementAccessExpression :
2738
+ return computeElementAccess ( < ElementAccessExpression > node , subtreeFlags ) ;
2739
+
2737
2740
default :
2738
2741
return computeOther ( node , kind , subtreeFlags ) ;
2739
2742
}
@@ -2748,10 +2751,15 @@ namespace ts {
2748
2751
}
2749
2752
2750
2753
if ( subtreeFlags & TransformFlags . ContainsSpread
2751
- || isSuperOrSuperProperty ( expression ) ) {
2754
+ || ( expression . transformFlags & ( TransformFlags . Super | TransformFlags . ContainsSuper ) ) ) {
2752
2755
// If the this node contains a SpreadExpression, or is a super call, then it is an ES6
2753
2756
// node.
2754
2757
transformFlags |= TransformFlags . AssertES2015 ;
2758
+ // super property or element accesses could be inside lambdas, etc, and need a captured `this`,
2759
+ // while super keyword for super calls (indicated by TransformFlags.Super) does not (since it can only be top-level in a constructor)
2760
+ if ( expression . transformFlags & TransformFlags . ContainsSuper ) {
2761
+ transformFlags |= TransformFlags . ContainsLexicalThis ;
2762
+ }
2755
2763
}
2756
2764
2757
2765
if ( expression . kind === SyntaxKind . ImportKeyword ) {
@@ -2768,22 +2776,6 @@ namespace ts {
2768
2776
return transformFlags & ~ TransformFlags . ArrayLiteralOrCallOrNewExcludes ;
2769
2777
}
2770
2778
2771
- function isSuperOrSuperProperty ( node : Node ) {
2772
- node = skipOuterExpressions ( node ) ;
2773
- switch ( node . kind ) {
2774
- case SyntaxKind . SuperKeyword :
2775
- return true ;
2776
-
2777
- case SyntaxKind . PropertyAccessExpression :
2778
- case SyntaxKind . ElementAccessExpression :
2779
- const expression = ( < PropertyAccessExpression | ElementAccessExpression > node ) . expression ;
2780
- const expressionKind = expression . kind ;
2781
- return expressionKind === SyntaxKind . SuperKeyword ;
2782
- }
2783
-
2784
- return false ;
2785
- }
2786
-
2787
2779
function computeNewExpression ( node : NewExpression , subtreeFlags : TransformFlags ) {
2788
2780
let transformFlags = subtreeFlags ;
2789
2781
if ( node . typeArguments ) {
@@ -2878,7 +2870,7 @@ namespace ts {
2878
2870
}
2879
2871
2880
2872
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
2881
- return transformFlags & ~ TransformFlags . NodeExcludes ;
2873
+ return transformFlags & ~ TransformFlags . OuterExpressionExcludes ;
2882
2874
}
2883
2875
2884
2876
function computeClassDeclaration ( node : ClassDeclaration , subtreeFlags : TransformFlags ) {
@@ -3197,17 +3189,32 @@ namespace ts {
3197
3189
3198
3190
function computePropertyAccess ( node : PropertyAccessExpression , subtreeFlags : TransformFlags ) {
3199
3191
let transformFlags = subtreeFlags ;
3200
- const expression = node . expression ;
3201
- const expressionKind = expression . kind ;
3202
3192
3203
3193
// If a PropertyAccessExpression starts with a super keyword, then it is
3204
3194
// ES6 syntax, and requires a lexical `this` binding.
3205
- if ( expressionKind === SyntaxKind . SuperKeyword ) {
3206
- transformFlags |= TransformFlags . ContainsLexicalThis ;
3195
+ if ( transformFlags & TransformFlags . Super ) {
3196
+ transformFlags ^= TransformFlags . Super ;
3197
+ transformFlags |= TransformFlags . ContainsSuper ;
3207
3198
}
3208
3199
3209
3200
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3210
- return transformFlags & ~ TransformFlags . NodeExcludes ;
3201
+ return transformFlags & ~ TransformFlags . PropertyAccessExcludes ;
3202
+ }
3203
+
3204
+ function computeElementAccess ( node : ElementAccessExpression , subtreeFlags : TransformFlags ) {
3205
+ let transformFlags = subtreeFlags ;
3206
+ const expression = node . expression ;
3207
+ const expressionFlags = expression . transformFlags ; // We do not want to aggregate flags from the argument expression for super/this capturing
3208
+
3209
+ // If an ElementAccessExpression starts with a super keyword, then it is
3210
+ // ES6 syntax, and requires a lexical `this` binding.
3211
+ if ( expressionFlags & TransformFlags . Super ) {
3212
+ transformFlags &= ~ TransformFlags . Super ;
3213
+ transformFlags |= TransformFlags . ContainsSuper ;
3214
+ }
3215
+
3216
+ node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3217
+ return transformFlags & ~ TransformFlags . PropertyAccessExcludes ;
3211
3218
}
3212
3219
3213
3220
function computeVariableDeclaration ( node : VariableDeclaration , subtreeFlags : TransformFlags ) {
@@ -3327,6 +3334,11 @@ namespace ts {
3327
3334
transformFlags |= TransformFlags . AssertESNext | TransformFlags . AssertES2017 ;
3328
3335
break ;
3329
3336
3337
+ case SyntaxKind . TypeAssertionExpression :
3338
+ case SyntaxKind . AsExpression :
3339
+ case SyntaxKind . PartiallyEmittedExpression :
3340
+ excludeFlags = TransformFlags . OuterExpressionExcludes ;
3341
+ // fallthrough
3330
3342
case SyntaxKind . PublicKeyword :
3331
3343
case SyntaxKind . PrivateKeyword :
3332
3344
case SyntaxKind . ProtectedKeyword :
@@ -3335,8 +3347,6 @@ namespace ts {
3335
3347
case SyntaxKind . ConstKeyword :
3336
3348
case SyntaxKind . EnumDeclaration :
3337
3349
case SyntaxKind . EnumMember :
3338
- case SyntaxKind . TypeAssertionExpression :
3339
- case SyntaxKind . AsExpression :
3340
3350
case SyntaxKind . NonNullExpression :
3341
3351
case SyntaxKind . ReadonlyKeyword :
3342
3352
// These nodes are TypeScript syntax.
@@ -3464,7 +3474,8 @@ namespace ts {
3464
3474
3465
3475
case SyntaxKind . SuperKeyword :
3466
3476
// This node is ES6 syntax.
3467
- transformFlags |= TransformFlags . AssertES2015 ;
3477
+ transformFlags |= TransformFlags . AssertES2015 | TransformFlags . Super ;
3478
+ excludeFlags = TransformFlags . OuterExpressionExcludes ; // must be set to persist `Super`
3468
3479
break ;
3469
3480
3470
3481
case SyntaxKind . ThisKeyword :
@@ -3621,6 +3632,15 @@ namespace ts {
3621
3632
case SyntaxKind . ObjectBindingPattern :
3622
3633
case SyntaxKind . ArrayBindingPattern :
3623
3634
return TransformFlags . BindingPatternExcludes ;
3635
+ case SyntaxKind . TypeAssertionExpression :
3636
+ case SyntaxKind . AsExpression :
3637
+ case SyntaxKind . PartiallyEmittedExpression :
3638
+ case SyntaxKind . ParenthesizedExpression :
3639
+ case SyntaxKind . SuperKeyword :
3640
+ return TransformFlags . OuterExpressionExcludes ;
3641
+ case SyntaxKind . PropertyAccessExpression :
3642
+ case SyntaxKind . ElementAccessExpression :
3643
+ return TransformFlags . PropertyAccessExcludes ;
3624
3644
default :
3625
3645
return TransformFlags . NodeExcludes ;
3626
3646
}
0 commit comments