Skip to content

Commit 737cb45

Browse files
authored
Merge pull request #31807 from microsoft/revert-30467-move-class-property-transform
Revert "Move class property transformation into new transformer file"
2 parents 4ae3a54 + 53467ae commit 737cb45

11 files changed

+434
-807
lines changed

src/compiler/binder.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -3229,7 +3229,8 @@ namespace ts {
32293229
// A ClassDeclaration is ES6 syntax.
32303230
transformFlags = subtreeFlags | TransformFlags.AssertES2015;
32313231

3232-
// A class with a parameter property assignment or decorator is TypeScript syntax.
3232+
// A class with a parameter property assignment, property initializer, computed property name, or decorator is
3233+
// TypeScript syntax.
32333234
// An exported declaration may be TypeScript syntax, but is handled by the visitor
32343235
// for a namespace declaration.
32353236
if ((subtreeFlags & TransformFlags.ContainsTypeScriptClassSyntax)
@@ -3246,7 +3247,8 @@ namespace ts {
32463247
// A ClassExpression is ES6 syntax.
32473248
let transformFlags = subtreeFlags | TransformFlags.AssertES2015;
32483249

3249-
// A class with a parameter property assignment or decorator is TypeScript syntax.
3250+
// A class with a parameter property assignment, property initializer, or decorator is
3251+
// TypeScript syntax.
32503252
if (subtreeFlags & TransformFlags.ContainsTypeScriptClassSyntax
32513253
|| node.typeParameters) {
32523254
transformFlags |= TransformFlags.AssertTypeScript;
@@ -3336,6 +3338,7 @@ namespace ts {
33363338
|| hasModifier(node, ModifierFlags.TypeScriptModifier)
33373339
|| node.typeParameters
33383340
|| node.type
3341+
|| (node.name && isComputedPropertyName(node.name)) // While computed method names aren't typescript, the TS transform must visit them to emit property declarations correctly
33393342
|| !node.body) {
33403343
transformFlags |= TransformFlags.AssertTypeScript;
33413344
}
@@ -3366,6 +3369,7 @@ namespace ts {
33663369
if (node.decorators
33673370
|| hasModifier(node, ModifierFlags.TypeScriptModifier)
33683371
|| node.type
3372+
|| (node.name && isComputedPropertyName(node.name)) // While computed accessor names aren't typescript, the TS transform must visit them to emit property declarations correctly
33693373
|| !node.body) {
33703374
transformFlags |= TransformFlags.AssertTypeScript;
33713375
}
@@ -3380,15 +3384,12 @@ namespace ts {
33803384
}
33813385

33823386
function computePropertyDeclaration(node: PropertyDeclaration, subtreeFlags: TransformFlags) {
3383-
let transformFlags = subtreeFlags | TransformFlags.ContainsClassFields;
3384-
3385-
// Decorators, TypeScript-specific modifiers, and type annotations are TypeScript syntax.
3386-
if (some(node.decorators) || hasModifier(node, ModifierFlags.TypeScriptModifier) || node.type) {
3387-
transformFlags |= TransformFlags.AssertTypeScript;
3388-
}
3387+
// A PropertyDeclaration is TypeScript syntax.
3388+
let transformFlags = subtreeFlags | TransformFlags.AssertTypeScript;
33893389

3390-
// Hoisted variables related to class properties should live within the TypeScript class wrapper.
3391-
if (isComputedPropertyName(node.name) || (hasStaticModifier(node) && node.initializer)) {
3390+
// If the PropertyDeclaration has an initializer or a computed name, we need to inform its ancestor
3391+
// so that it handle the transformation.
3392+
if (node.initializer || isComputedPropertyName(node.name)) {
33923393
transformFlags |= TransformFlags.ContainsTypeScriptClassSyntax;
33933394
}
33943395

src/compiler/transformer.ts

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ namespace ts {
4444
addRange(transformers, customTransformers && map(customTransformers.before, wrapScriptTransformerFactory));
4545

4646
transformers.push(transformTypeScript);
47-
transformers.push(transformClassFields);
4847

4948
if (jsx === JsxEmit.React) {
5049
transformers.push(transformJsx);

src/compiler/transformers/classFields.ts

-491
This file was deleted.

src/compiler/transformers/ts.ts

+347-146
Large diffs are not rendered by default.

src/compiler/transformers/utilities.ts

-80
Original file line numberDiff line numberDiff line change
@@ -240,47 +240,6 @@ namespace ts {
240240
isIdentifier(expression);
241241
}
242242

243-
/**
244-
* A simple inlinable expression is an expression which can be copied into multiple locations
245-
* without risk of repeating any sideeffects and whose value could not possibly change between
246-
* any such locations
247-
*/
248-
export function isSimpleInlineableExpression(expression: Expression) {
249-
return !isIdentifier(expression) && isSimpleCopiableExpression(expression) ||
250-
isWellKnownSymbolSyntactically(expression);
251-
}
252-
253-
/**
254-
* Adds super call and preceding prologue directives into the list of statements.
255-
*
256-
* @param ctor The constructor node.
257-
* @param result The list of statements.
258-
* @param visitor The visitor to apply to each node added to the result array.
259-
* @returns index of the statement that follows super call
260-
*/
261-
export function addPrologueDirectivesAndInitialSuperCall(ctor: ConstructorDeclaration, result: Statement[], visitor: Visitor): number {
262-
if (ctor.body) {
263-
const statements = ctor.body.statements;
264-
// add prologue directives to the list (if any)
265-
const index = addPrologue(result, statements, /*ensureUseStrict*/ false, visitor);
266-
if (index === statements.length) {
267-
// list contains nothing but prologue directives (or empty) - exit
268-
return index;
269-
}
270-
271-
const statement = statements[index];
272-
if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCall((<ExpressionStatement>statement).expression)) {
273-
result.push(visitNode(statement, visitor, isStatement));
274-
return index + 1;
275-
}
276-
277-
return index;
278-
}
279-
280-
return 0;
281-
}
282-
283-
284243
/**
285244
* @param input Template string input strings
286245
* @param args Names which need to be made file-level unique
@@ -296,43 +255,4 @@ namespace ts {
296255
return result;
297256
};
298257
}
299-
300-
/**
301-
* Gets all property declarations with initializers on either the static or instance side of a class.
302-
*
303-
* @param node The class node.
304-
* @param isStatic A value indicating whether to get properties from the static or instance side of the class.
305-
*/
306-
export function getInitializedProperties(node: ClassExpression | ClassDeclaration, isStatic: boolean): ReadonlyArray<PropertyDeclaration> {
307-
return filter(node.members, isStatic ? isStaticInitializedProperty : isInstanceInitializedProperty);
308-
}
309-
310-
/**
311-
* Gets a value indicating whether a class element is a static property declaration with an initializer.
312-
*
313-
* @param member The class element node.
314-
*/
315-
export function isStaticInitializedProperty(member: ClassElement): member is PropertyDeclaration & { initializer: Expression; } {
316-
return isInitializedProperty(member) && hasStaticModifier(member);
317-
}
318-
319-
/**
320-
* Gets a value indicating whether a class element is an instance property declaration with an initializer.
321-
*
322-
* @param member The class element node.
323-
*/
324-
export function isInstanceInitializedProperty(member: ClassElement): member is PropertyDeclaration & { initializer: Expression; } {
325-
return isInitializedProperty(member) && !hasStaticModifier(member);
326-
}
327-
328-
/**
329-
* Gets a value indicating whether a class element is either a static or an instance property declaration with an initializer.
330-
*
331-
* @param member The class element node.
332-
* @param isStatic A value indicating whether the member should be a static or instance member.
333-
*/
334-
export function isInitializedProperty(member: ClassElement): member is PropertyDeclaration & { initializer: Expression; } {
335-
return member.kind === SyntaxKind.PropertyDeclaration
336-
&& (<PropertyDeclaration>member).initializer !== undefined;
337-
}
338258
}

src/compiler/tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"transformers/utilities.ts",
3131
"transformers/destructuring.ts",
3232
"transformers/ts.ts",
33-
"transformers/classFields.ts",
3433
"transformers/es2017.ts",
3534
"transformers/es2018.ts",
3635
"transformers/es2019.ts",

src/compiler/types.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5197,7 +5197,6 @@ namespace ts {
51975197
ContainsYield = 1 << 17,
51985198
ContainsHoistedDeclarationOrCompletion = 1 << 18,
51995199
ContainsDynamicImport = 1 << 19,
5200-
ContainsClassFields = 1 << 20,
52015200

52025201
// Please leave this as 1 << 29.
52035202
// It is the maximum bit we can set before we outgrow the size of a v8 small integer (SMI) on an x86 system.

tests/baselines/reference/declarationEmitPrivateSymbolCausesVarDeclarationEmit2.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ var C = /** @class */ (function () {
3434
}
3535
return C;
3636
}());
37-
exports.C = C;
3837
_a = a_1.x;
38+
exports.C = C;
3939
//// [c.js]
4040
"use strict";
4141
var __extends = (this && this.__extends) || (function () {
@@ -64,8 +64,8 @@ var D = /** @class */ (function (_super) {
6464
}
6565
return D;
6666
}(b_1.C));
67-
exports.D = D;
6867
_a = a_1.x;
68+
exports.D = D;
6969

7070

7171
//// [a.d.ts]

0 commit comments

Comments
 (0)