@@ -1911,9 +1911,14 @@ namespace ts {
19111911 // Instead, we mark the container as ES6, so that it can properly handle the transform.
19121912 transformFlags = TransformFlags . ContainsComputedPropertyName ;
19131913 if ( subtreeFlags & TransformFlags . ContainsLexicalThis ) {
1914- // A computed method name that contains `this` needs to
1915- // distinguish itself from the normal case of a method body containing `this`.
1916- // So convert ContainsLexicalThis to ContainsLexicalThisInComputedPropertyName
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
19171922 transformFlags |= TransformFlags . ContainsLexicalThisInComputedPropertyName ;
19181923 }
19191924 break ;
@@ -1952,6 +1957,8 @@ namespace ts {
19521957 transformFlags = TransformFlags . AssertES6 ;
19531958 }
19541959 if ( subtreeFlags & TransformFlags . ContainsLexicalThisInComputedPropertyName ) {
1960+ // A computed property name containing `this` might need to be rewritten,
1961+ // so propagate the ContainsLexicalThis flag upward.
19551962 transformFlags |= TransformFlags . ContainsLexicalThis ;
19561963 }
19571964 break ;
@@ -2266,6 +2273,8 @@ namespace ts {
22662273 transformFlags |= TransformFlags . AssertTypeScript ;
22672274 }
22682275 if ( subtreeFlags & TransformFlags . ContainsLexicalThisInComputedPropertyName ) {
2276+ // A computed property name containing `this` might need to be rewritten,
2277+ // so propagate the ContainsLexicalThis flag upward.
22692278 transformFlags |= TransformFlags . ContainsLexicalThis ;
22702279 }
22712280
@@ -2285,6 +2294,8 @@ namespace ts {
22852294 transformFlags |= TransformFlags . AssertTypeScript ;
22862295 }
22872296 if ( subtreeFlags & TransformFlags . ContainsLexicalThisInComputedPropertyName ) {
2297+ // A computed property name containing `this` might need to be rewritten,
2298+ // so propagate the ContainsLexicalThis flag upward.
22882299 transformFlags |= TransformFlags . ContainsLexicalThis ;
22892300 }
22902301
0 commit comments