Skip to content

Commit 75af3b7

Browse files
author
Joseph Watts
committed
Move class property transformation into ESNext transformer
Signed-off-by: Joseph Watts <[email protected]>
1 parent 221111e commit 75af3b7

File tree

4 files changed

+677
-362
lines changed

4 files changed

+677
-362
lines changed

src/compiler/binder.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,8 +3189,7 @@ namespace ts {
31893189
// A ClassDeclaration is ES6 syntax.
31903190
transformFlags = subtreeFlags | TransformFlags.AssertES2015;
31913191

3192-
// A class with a parameter property assignment, property initializer, computed property name, or decorator is
3193-
// TypeScript syntax.
3192+
// A class with a parameter property assignment or decorator is TypeScript syntax.
31943193
// An exported declaration may be TypeScript syntax, but is handled by the visitor
31953194
// for a namespace declaration.
31963195
if ((subtreeFlags & TransformFlags.ContainsTypeScriptClassSyntax)
@@ -3213,8 +3212,7 @@ namespace ts {
32133212
// A ClassExpression is ES6 syntax.
32143213
let transformFlags = subtreeFlags | TransformFlags.AssertES2015;
32153214

3216-
// A class with a parameter property assignment, property initializer, or decorator is
3217-
// TypeScript syntax.
3215+
// A class with a parameter property assignment or decorator is TypeScript syntax.
32183216
if (subtreeFlags & TransformFlags.ContainsTypeScriptClassSyntax
32193217
|| node.typeParameters) {
32203218
transformFlags |= TransformFlags.AssertTypeScript;
@@ -3310,7 +3308,6 @@ namespace ts {
33103308
|| hasModifier(node, ModifierFlags.TypeScriptModifier)
33113309
|| node.typeParameters
33123310
|| node.type
3313-
|| (node.name && isComputedPropertyName(node.name)) // While computed method names aren't typescript, the TS transform must visit them to emit property declarations correctly
33143311
|| !node.body) {
33153312
transformFlags |= TransformFlags.AssertTypeScript;
33163313
}
@@ -3341,7 +3338,6 @@ namespace ts {
33413338
if (node.decorators
33423339
|| hasModifier(node, ModifierFlags.TypeScriptModifier)
33433340
|| node.type
3344-
|| (node.name && isComputedPropertyName(node.name)) // While computed accessor names aren't typescript, the TS transform must visit them to emit property declarations correctly
33453341
|| !node.body) {
33463342
transformFlags |= TransformFlags.AssertTypeScript;
33473343
}
@@ -3356,12 +3352,16 @@ namespace ts {
33563352
}
33573353

33583354
function computePropertyDeclaration(node: PropertyDeclaration, subtreeFlags: TransformFlags) {
3359-
// A PropertyDeclaration is TypeScript syntax.
3360-
let transformFlags = subtreeFlags | TransformFlags.AssertTypeScript;
3355+
// A PropertyDeclaration is ESnext syntax.
3356+
let transformFlags = subtreeFlags | TransformFlags.AssertESNext;
33613357

3362-
// If the PropertyDeclaration has an initializer or a computed name, we need to inform its ancestor
3363-
// so that it handle the transformation.
3364-
if (node.initializer || isComputedPropertyName(node.name)) {
3358+
// Decorators, TypeScript-specific modifiers, and type annotations are TypeScript syntax.
3359+
if (some(node.decorators) || hasModifier(node, ModifierFlags.TypeScriptModifier) || node.type) {
3360+
transformFlags |= TransformFlags.AssertTypeScript;
3361+
}
3362+
3363+
// Hoisted variables related to class properties should live within the TypeScript class wrapper.
3364+
if (isComputedPropertyName(node.name) || (hasStaticModifier(node) && node.initializer)) {
33653365
transformFlags |= TransformFlags.ContainsTypeScriptClassSyntax;
33663366
}
33673367

@@ -3762,6 +3762,8 @@ namespace ts {
37623762
break;
37633763

37643764
case SyntaxKind.ComputedPropertyName:
3765+
// Computed property names are transformed by the ESNext transformer.
3766+
transformFlags |= TransformFlags.AssertESNext;
37653767
// Even though computed property names are ES6, we don't treat them as such.
37663768
// This is so that they can flow through PropertyName transforms unaffected.
37673769
// Instead, we mark the container as ES6, so that it can properly handle the transform.

0 commit comments

Comments
 (0)