@@ -3093,32 +3093,24 @@ namespace ts {
3093
3093
3094
3094
function computeCallExpression ( node : CallExpression , subtreeFlags : TransformFlags ) {
3095
3095
let transformFlags = subtreeFlags ;
3096
+ const callee = skipOuterExpressions ( node . expression ) ;
3096
3097
const expression = node . expression ;
3097
3098
3098
3099
if ( node . typeArguments ) {
3099
3100
transformFlags |= TransformFlags . AssertTypeScript ;
3100
3101
}
3101
3102
3102
- if ( subtreeFlags & TransformFlags . ContainsRestOrSpread
3103
- || ( expression . transformFlags & ( TransformFlags . Super | TransformFlags . ContainsSuper ) ) ) {
3103
+ if ( subtreeFlags & TransformFlags . ContainsRestOrSpread || isSuperOrSuperProperty ( callee ) ) {
3104
3104
// If the this node contains a SpreadExpression, or is a super call, then it is an ES6
3105
3105
// node.
3106
3106
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 ) ) {
3110
3108
transformFlags |= TransformFlags . ContainsLexicalThis ;
3111
3109
}
3112
3110
}
3113
3111
3114
3112
if ( expression . kind === SyntaxKind . ImportKeyword ) {
3115
3113
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
- }
3122
3114
}
3123
3115
3124
3116
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
@@ -3191,7 +3183,7 @@ namespace ts {
3191
3183
// If a parameter has an initializer, a binding pattern or a dotDotDot token, then
3192
3184
// it is ES6 syntax and its container must emit default value assignments or parameter destructuring downlevel.
3193
3185
if ( subtreeFlags & TransformFlags . ContainsBindingPattern || initializer || dotDotDotToken ) {
3194
- transformFlags |= TransformFlags . AssertES2015 | TransformFlags . ContainsDefaultValueAssignments ;
3186
+ transformFlags |= TransformFlags . AssertES2015 ;
3195
3187
}
3196
3188
3197
3189
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
@@ -3202,7 +3194,6 @@ namespace ts {
3202
3194
let transformFlags = subtreeFlags ;
3203
3195
const expression = node . expression ;
3204
3196
const expressionKind = expression . kind ;
3205
- const expressionTransformFlags = expression . transformFlags ;
3206
3197
3207
3198
// If the node is synthesized, it means the emitter put the parentheses there,
3208
3199
// not the user. If we didn't want them, the emitter would not have put them
@@ -3212,12 +3203,6 @@ namespace ts {
3212
3203
transformFlags |= TransformFlags . AssertTypeScript ;
3213
3204
}
3214
3205
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
-
3221
3206
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3222
3207
return transformFlags & ~ TransformFlags . OuterExpressionExcludes ;
3223
3208
}
@@ -3241,12 +3226,6 @@ namespace ts {
3241
3226
|| node . typeParameters ) {
3242
3227
transformFlags |= TransformFlags . AssertTypeScript ;
3243
3228
}
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
- }
3250
3229
}
3251
3230
3252
3231
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
@@ -3264,12 +3243,6 @@ namespace ts {
3264
3243
transformFlags |= TransformFlags . AssertTypeScript ;
3265
3244
}
3266
3245
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
-
3273
3246
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3274
3247
return transformFlags & ~ TransformFlags . ClassExcludes ;
3275
3248
}
@@ -3374,7 +3347,7 @@ namespace ts {
3374
3347
}
3375
3348
3376
3349
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3377
- return transformFlags & ~ TransformFlags . MethodOrAccessorExcludes ;
3350
+ return propagatePropertyNameFlags ( node . name , transformFlags & ~ TransformFlags . MethodOrAccessorExcludes ) ;
3378
3351
}
3379
3352
3380
3353
function computeAccessor ( node : AccessorDeclaration , subtreeFlags : TransformFlags ) {
@@ -3396,7 +3369,7 @@ namespace ts {
3396
3369
}
3397
3370
3398
3371
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3399
- return transformFlags & ~ TransformFlags . MethodOrAccessorExcludes ;
3372
+ return propagatePropertyNameFlags ( node . name , transformFlags & ~ TransformFlags . MethodOrAccessorExcludes ) ;
3400
3373
}
3401
3374
3402
3375
function computePropertyDeclaration ( node : PropertyDeclaration , subtreeFlags : TransformFlags ) {
@@ -3410,7 +3383,7 @@ namespace ts {
3410
3383
}
3411
3384
3412
3385
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3413
- return transformFlags & ~ TransformFlags . NodeExcludes ;
3386
+ return propagatePropertyNameFlags ( node . name , transformFlags & ~ TransformFlags . PropertyExcludes ) ;
3414
3387
}
3415
3388
3416
3389
function computeFunctionDeclaration ( node : FunctionDeclaration , subtreeFlags : TransformFlags ) {
@@ -3444,13 +3417,6 @@ namespace ts {
3444
3417
transformFlags |= TransformFlags . AssertES2018 ;
3445
3418
}
3446
3419
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
-
3454
3420
// If a FunctionDeclaration is generator function and is the body of a
3455
3421
// transformed async function, then this node can be transformed to a
3456
3422
// down-level generator.
@@ -3486,14 +3452,6 @@ namespace ts {
3486
3452
transformFlags |= TransformFlags . AssertES2018 ;
3487
3453
}
3488
3454
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
-
3497
3455
// If a FunctionExpression is generator function and is the body of a
3498
3456
// transformed async function, then this node can be transformed to a
3499
3457
// down-level generator.
@@ -3527,11 +3485,6 @@ namespace ts {
3527
3485
transformFlags |= TransformFlags . AssertES2018 ;
3528
3486
}
3529
3487
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
-
3535
3488
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3536
3489
return transformFlags & ~ TransformFlags . ArrowFunctionExcludes ;
3537
3490
}
@@ -3541,11 +3494,10 @@ namespace ts {
3541
3494
3542
3495
// If a PropertyAccessExpression starts with a super keyword, then it is
3543
3496
// ES6 syntax, and requires a lexical `this` binding.
3544
- if ( transformFlags & TransformFlags . Super ) {
3545
- transformFlags ^= TransformFlags . Super ;
3497
+ if ( node . expression . kind === SyntaxKind . SuperKeyword ) {
3546
3498
// super inside of an async function requires hoisting the super access (ES2017).
3547
3499
// 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 ;
3549
3501
}
3550
3502
3551
3503
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
@@ -3554,16 +3506,13 @@ namespace ts {
3554
3506
3555
3507
function computeElementAccess ( node : ElementAccessExpression , subtreeFlags : TransformFlags ) {
3556
3508
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
3559
3509
3560
3510
// If an ElementAccessExpression starts with a super keyword, then it is
3561
3511
// ES6 syntax, and requires a lexical `this` binding.
3562
- if ( expressionFlags & TransformFlags . Super ) {
3563
- transformFlags &= ~ TransformFlags . Super ;
3512
+ if ( node . expression . kind === SyntaxKind . SuperKeyword ) {
3564
3513
// super inside of an async function requires hoisting the super access (ES2017).
3565
3514
// 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 ;
3567
3516
}
3568
3517
3569
3518
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
@@ -3572,7 +3521,7 @@ namespace ts {
3572
3521
3573
3522
function computeVariableDeclaration ( node : VariableDeclaration , subtreeFlags : TransformFlags ) {
3574
3523
let transformFlags = subtreeFlags ;
3575
- transformFlags |= TransformFlags . AssertES2015 | TransformFlags . ContainsBindingPattern ;
3524
+ transformFlags |= TransformFlags . AssertES2015 | TransformFlags . ContainsBindingPattern ; // TODO(rbuckton): Why are these set unconditionally?
3576
3525
3577
3526
// A VariableDeclaration containing ObjectRest is ES2018 syntax
3578
3527
if ( subtreeFlags & TransformFlags . ContainsObjectRestOrSpread ) {
@@ -3634,15 +3583,7 @@ namespace ts {
3634
3583
}
3635
3584
3636
3585
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 ;
3646
3587
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3647
3588
return transformFlags & ~ TransformFlags . NodeExcludes ;
3648
3589
}
@@ -3815,17 +3756,6 @@ namespace ts {
3815
3756
// This is so that they can flow through PropertyName transforms unaffected.
3816
3757
// Instead, we mark the container as ES6, so that it can properly handle the transform.
3817
3758
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
- }
3829
3759
break ;
3830
3760
3831
3761
case SyntaxKind . SpreadElement :
@@ -3838,7 +3768,7 @@ namespace ts {
3838
3768
3839
3769
case SyntaxKind . SuperKeyword :
3840
3770
// This node is ES6 syntax.
3841
- transformFlags |= TransformFlags . AssertES2015 | TransformFlags . Super ;
3771
+ transformFlags |= TransformFlags . AssertES2015 ;
3842
3772
excludeFlags = TransformFlags . OuterExpressionExcludes ; // must be set to persist `Super`
3843
3773
break ;
3844
3774
@@ -3880,12 +3810,6 @@ namespace ts {
3880
3810
transformFlags |= TransformFlags . AssertES2015 ;
3881
3811
}
3882
3812
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
-
3889
3813
if ( subtreeFlags & TransformFlags . ContainsObjectRestOrSpread ) {
3890
3814
// If an ObjectLiteralExpression contains a spread element, then it
3891
3815
// is an ES2018 node.
@@ -3895,14 +3819,7 @@ namespace ts {
3895
3819
break ;
3896
3820
3897
3821
case SyntaxKind . ArrayLiteralExpression :
3898
- case SyntaxKind . NewExpression :
3899
3822
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
-
3906
3823
break ;
3907
3824
3908
3825
case SyntaxKind . DoStatement :
@@ -3917,10 +3834,6 @@ namespace ts {
3917
3834
break ;
3918
3835
3919
3836
case SyntaxKind . SourceFile :
3920
- if ( subtreeFlags & TransformFlags . ContainsCapturedLexicalThis ) {
3921
- transformFlags |= TransformFlags . AssertES2015 ;
3922
- }
3923
-
3924
3837
break ;
3925
3838
3926
3839
case SyntaxKind . ReturnStatement :
@@ -3938,6 +3851,10 @@ namespace ts {
3938
3851
return transformFlags & ~ excludeFlags ;
3939
3852
}
3940
3853
3854
+ function propagatePropertyNameFlags ( node : PropertyName , transformFlags : TransformFlags ) {
3855
+ return transformFlags | ( node . transformFlags & TransformFlags . PropertyNamePropagatingFlags ) ;
3856
+ }
3857
+
3941
3858
/**
3942
3859
* Gets the transform flags to exclude when unioning the transform flags of a subtree.
3943
3860
*
0 commit comments