@@ -1910,6 +1910,17 @@ namespace ts {
19101910 // This is so that they can flow through PropertyName transforms unaffected.
19111911 // Instead, we mark the container as ES6, so that it can properly handle the transform.
19121912 transformFlags = TransformFlags . ContainsComputedPropertyName ;
1913+ if ( subtreeFlags & TransformFlags . ContainsLexicalThis ) {
1914+ // A computed method name like `[this.getName()](x: string) { ... }` needs to
1915+ // distinguish itself from the normal case of a method body containing `this`:
1916+ // `this` inside a method doesn't need to be rewritten (the method provides `this`),
1917+ // whereas `this` inside a computed name *might* need to be rewritten if the class/object
1918+ // is inside an arrow function:
1919+ // `_this = this; () => class K { [_this.getName()]() { ... } }`
1920+ // To make this distinction, use ContainsLexicalThisInComputedPropertyName
1921+ // instead of ContainsLexicalThis for computed property names
1922+ transformFlags |= TransformFlags . ContainsLexicalThisInComputedPropertyName ;
1923+ }
19131924 break ;
19141925
19151926 case SyntaxKind . SpreadElementExpression :
@@ -1945,6 +1956,11 @@ namespace ts {
19451956 // is an ES6 node.
19461957 transformFlags = TransformFlags . AssertES6 ;
19471958 }
1959+ if ( subtreeFlags & TransformFlags . ContainsLexicalThisInComputedPropertyName ) {
1960+ // A computed property name containing `this` might need to be rewritten,
1961+ // so propagate the ContainsLexicalThis flag upward.
1962+ transformFlags |= TransformFlags . ContainsLexicalThis ;
1963+ }
19481964 break ;
19491965
19501966 case SyntaxKind . CallExpression :
@@ -2256,6 +2272,11 @@ namespace ts {
22562272 || hasModifier ( node , ModifierFlags . Export ) ) {
22572273 transformFlags |= TransformFlags . AssertTypeScript ;
22582274 }
2275+ if ( subtreeFlags & TransformFlags . ContainsLexicalThisInComputedPropertyName ) {
2276+ // A computed property name containing `this` might need to be rewritten,
2277+ // so propagate the ContainsLexicalThis flag upward.
2278+ transformFlags |= TransformFlags . ContainsLexicalThis ;
2279+ }
22592280
22602281 return updateTransformFlags ( node , subtreeFlags , transformFlags , TransformFlags . ClassExcludes ) ;
22612282 }
@@ -2272,6 +2293,11 @@ namespace ts {
22722293 | TransformFlags . ContainsDecorators ) ) {
22732294 transformFlags |= TransformFlags . AssertTypeScript ;
22742295 }
2296+ if ( subtreeFlags & TransformFlags . ContainsLexicalThisInComputedPropertyName ) {
2297+ // A computed property name containing `this` might need to be rewritten,
2298+ // so propagate the ContainsLexicalThis flag upward.
2299+ transformFlags |= TransformFlags . ContainsLexicalThis ;
2300+ }
22752301
22762302 return updateTransformFlags ( node , subtreeFlags , transformFlags , TransformFlags . ClassExcludes ) ;
22772303 }
0 commit comments