@@ -3099,21 +3099,14 @@ namespace ts {
3099
3099
// If the this node contains a SpreadExpression, or is a super call, then it is an ES6
3100
3100
// node.
3101
3101
transformFlags |= TransformFlags . AssertES2015 ;
3102
- // super property or element accesses could be inside lambdas, etc, and need a captured `this`,
3103
- // while super keyword for super calls (indicated by TransformFlags.Super) does not (since it can only be top-level in a constructor)
3102
+
3104
3103
if ( expression . transformFlags & TransformFlags . ContainsSuper ) {
3105
3104
transformFlags |= TransformFlags . ContainsLexicalThis ;
3106
3105
}
3107
3106
}
3108
3107
3109
3108
if ( expression . kind === SyntaxKind . ImportKeyword ) {
3110
3109
transformFlags |= TransformFlags . ContainsDynamicImport ;
3111
-
3112
- // A dynamic 'import()' call that contains a lexical 'this' will
3113
- // require a captured 'this' when emitting down-level.
3114
- if ( subtreeFlags & TransformFlags . ContainsLexicalThis ) {
3115
- transformFlags |= TransformFlags . ContainsCapturedLexicalThis ;
3116
- }
3117
3110
}
3118
3111
3119
3112
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
@@ -3236,12 +3229,6 @@ namespace ts {
3236
3229
|| node . typeParameters ) {
3237
3230
transformFlags |= TransformFlags . AssertTypeScript ;
3238
3231
}
3239
-
3240
- if ( subtreeFlags & TransformFlags . ContainsLexicalThisInComputedPropertyName ) {
3241
- // A computed property name containing `this` might need to be rewritten,
3242
- // so propagate the ContainsLexicalThis flag upward.
3243
- transformFlags |= TransformFlags . ContainsLexicalThis ;
3244
- }
3245
3232
}
3246
3233
3247
3234
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
@@ -3259,12 +3246,6 @@ namespace ts {
3259
3246
transformFlags |= TransformFlags . AssertTypeScript ;
3260
3247
}
3261
3248
3262
- if ( subtreeFlags & TransformFlags . ContainsLexicalThisInComputedPropertyName ) {
3263
- // A computed property name containing `this` might need to be rewritten,
3264
- // so propagate the ContainsLexicalThis flag upward.
3265
- transformFlags |= TransformFlags . ContainsLexicalThis ;
3266
- }
3267
-
3268
3249
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3269
3250
return transformFlags & ~ TransformFlags . ClassExcludes ;
3270
3251
}
@@ -3369,7 +3350,7 @@ namespace ts {
3369
3350
}
3370
3351
3371
3352
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3372
- return transformFlags & ~ TransformFlags . MethodOrAccessorExcludes ;
3353
+ return propagatePropertyNameFlags ( node . name , transformFlags & ~ TransformFlags . MethodOrAccessorExcludes ) ;
3373
3354
}
3374
3355
3375
3356
function computeAccessor ( node : AccessorDeclaration , subtreeFlags : TransformFlags ) {
@@ -3391,7 +3372,7 @@ namespace ts {
3391
3372
}
3392
3373
3393
3374
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3394
- return transformFlags & ~ TransformFlags . MethodOrAccessorExcludes ;
3375
+ return propagatePropertyNameFlags ( node . name , transformFlags & ~ TransformFlags . MethodOrAccessorExcludes ) ;
3395
3376
}
3396
3377
3397
3378
function computePropertyDeclaration ( node : PropertyDeclaration , subtreeFlags : TransformFlags ) {
@@ -3405,7 +3386,7 @@ namespace ts {
3405
3386
}
3406
3387
3407
3388
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3408
- return transformFlags & ~ TransformFlags . NodeExcludes ;
3389
+ return propagatePropertyNameFlags ( node . name , transformFlags & ~ TransformFlags . PropertyExcludes ) ;
3409
3390
}
3410
3391
3411
3392
function computeFunctionDeclaration ( node : FunctionDeclaration , subtreeFlags : TransformFlags ) {
@@ -3439,13 +3420,6 @@ namespace ts {
3439
3420
transformFlags |= TransformFlags . AssertES2018 ;
3440
3421
}
3441
3422
3442
- // If a FunctionDeclaration's subtree has marked the container as needing to capture the
3443
- // lexical this, or the function contains parameters with initializers, then this node is
3444
- // ES6 syntax.
3445
- if ( subtreeFlags & TransformFlags . ContainsCapturedLexicalThis ) {
3446
- transformFlags |= TransformFlags . AssertES2015 ;
3447
- }
3448
-
3449
3423
// If a FunctionDeclaration is generator function and is the body of a
3450
3424
// transformed async function, then this node can be transformed to a
3451
3425
// down-level generator.
@@ -3481,14 +3455,6 @@ namespace ts {
3481
3455
transformFlags |= TransformFlags . AssertES2018 ;
3482
3456
}
3483
3457
3484
-
3485
- // If a FunctionExpression's subtree has marked the container as needing to capture the
3486
- // lexical this, or the function contains parameters with initializers, then this node is
3487
- // ES6 syntax.
3488
- if ( subtreeFlags & TransformFlags . ContainsCapturedLexicalThis ) {
3489
- transformFlags |= TransformFlags . AssertES2015 ;
3490
- }
3491
-
3492
3458
// If a FunctionExpression is generator function and is the body of a
3493
3459
// transformed async function, then this node can be transformed to a
3494
3460
// down-level generator.
@@ -3522,11 +3488,6 @@ namespace ts {
3522
3488
transformFlags |= TransformFlags . AssertES2018 ;
3523
3489
}
3524
3490
3525
- // If an ArrowFunction contains a lexical this, its container must capture the lexical this.
3526
- if ( subtreeFlags & TransformFlags . ContainsLexicalThis ) {
3527
- transformFlags |= TransformFlags . ContainsCapturedLexicalThis ;
3528
- }
3529
-
3530
3491
node . transformFlags = transformFlags | TransformFlags . HasComputedFlags ;
3531
3492
return transformFlags & ~ TransformFlags . ArrowFunctionExcludes ;
3532
3493
}
@@ -3810,17 +3771,6 @@ namespace ts {
3810
3771
// This is so that they can flow through PropertyName transforms unaffected.
3811
3772
// Instead, we mark the container as ES6, so that it can properly handle the transform.
3812
3773
transformFlags |= TransformFlags . ContainsComputedPropertyName ;
3813
- if ( subtreeFlags & TransformFlags . ContainsLexicalThis ) {
3814
- // A computed method name like `[this.getName()](x: string) { ... }` needs to
3815
- // distinguish itself from the normal case of a method body containing `this`:
3816
- // `this` inside a method doesn't need to be rewritten (the method provides `this`),
3817
- // whereas `this` inside a computed name *might* need to be rewritten if the class/object
3818
- // is inside an arrow function:
3819
- // `_this = this; () => class K { [_this.getName()]() { ... } }`
3820
- // To make this distinction, use ContainsLexicalThisInComputedPropertyName
3821
- // instead of ContainsLexicalThis for computed property names
3822
- transformFlags |= TransformFlags . ContainsLexicalThisInComputedPropertyName ;
3823
- }
3824
3774
break ;
3825
3775
3826
3776
case SyntaxKind . SpreadElement :
@@ -3839,7 +3789,6 @@ namespace ts {
3839
3789
3840
3790
case SyntaxKind . ThisKeyword :
3841
3791
// Mark this node and its ancestors as containing a lexical `this` keyword.
3842
- transformFlags |= TransformFlags . AssertES2015 ;
3843
3792
transformFlags |= TransformFlags . ContainsLexicalThis ;
3844
3793
break ;
3845
3794
@@ -3876,12 +3825,6 @@ namespace ts {
3876
3825
transformFlags |= TransformFlags . AssertES2015 ;
3877
3826
}
3878
3827
3879
- if ( subtreeFlags & TransformFlags . ContainsLexicalThisInComputedPropertyName ) {
3880
- // A computed property name containing `this` might need to be rewritten,
3881
- // so propagate the ContainsLexicalThis flag upward.
3882
- transformFlags |= TransformFlags . ContainsLexicalThis ;
3883
- }
3884
-
3885
3828
if ( subtreeFlags & TransformFlags . ContainsObjectRestOrSpread ) {
3886
3829
// If an ObjectLiteralExpression contains a spread element, then it
3887
3830
// is an ES2018 node.
@@ -3906,10 +3849,6 @@ namespace ts {
3906
3849
break ;
3907
3850
3908
3851
case SyntaxKind . SourceFile :
3909
- if ( subtreeFlags & TransformFlags . ContainsCapturedLexicalThis ) {
3910
- transformFlags |= TransformFlags . AssertES2015 ;
3911
- }
3912
-
3913
3852
break ;
3914
3853
3915
3854
case SyntaxKind . ReturnStatement :
@@ -3927,6 +3866,10 @@ namespace ts {
3927
3866
return transformFlags & ~ excludeFlags ;
3928
3867
}
3929
3868
3869
+ function propagatePropertyNameFlags ( node : PropertyName , transformFlags : TransformFlags ) {
3870
+ return transformFlags | ( node . transformFlags & TransformFlags . PropertyNamePropagatingFlags ) ;
3871
+ }
3872
+
3930
3873
/**
3931
3874
* Gets the transform flags to exclude when unioning the transform flags of a subtree.
3932
3875
*
0 commit comments