From 198e865259a78e3c7cf9ace96642161d6d74b5d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 20 Feb 2024 15:13:28 -0500 Subject: [PATCH 01/27] enable field-initializers-after-methods-private test --- .../exec.js | 0 .../input.js | 0 .../output.js | 24 +++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) rename packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/{.field-initializers-after-methods-private => field-initializers-after-methods-private}/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/{.field-initializers-after-methods-private => field-initializers-after-methods-private}/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/{.field-initializers-after-methods-private => field-initializers-after-methods-private}/output.js (59%) diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/.field-initializers-after-methods-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/field-initializers-after-methods-private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/.field-initializers-after-methods-private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/field-initializers-after-methods-private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/.field-initializers-after-methods-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/field-initializers-after-methods-private/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/.field-initializers-after-methods-private/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/field-initializers-after-methods-private/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/.field-initializers-after-methods-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/field-initializers-after-methods-private/output.js similarity index 59% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/.field-initializers-after-methods-private/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/field-initializers-after-methods-private/output.js index d97f6d849c01..86d08a4e3d9e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/.field-initializers-after-methods-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/field-initializers-after-methods-private/output.js @@ -1,18 +1,18 @@ -var _dec, _init_foo, _init_extra_foo; +var _fooDecs, _init_foo, _init_extra_foo; var counter = 0; -_dec = (_, { - addInitializer -}) => { - addInitializer(function () { - counter++; - expect(typeof this.method).toBe("function"); - expect(this.#foo).toBe("#foo"); - expect(() => this.#bar).toThrow(); - }); -}; class A { static { - [_init_foo, _init_extra_foo] = babelHelpers.applyDecs2311(this, [[_dec, 0, "foo", o => o.#foo, (o, v) => o.#foo = v]], [], 0, _ => #bar in _).e; + _fooDecs = (_, { + addInitializer + }) => { + addInitializer(function () { + counter++; + expect(typeof this.method).toBe("function"); + expect(this.#foo).toBe("#foo"); + expect(() => this.#bar).toThrow(); + }); + }; + [_init_foo, _init_extra_foo] = babelHelpers.applyDecs2311(this, [[_fooDecs, 0, "foo", o => o.#foo, (o, v) => o.#foo = v]], [], 0, _ => #bar in _).e; } #foo = _init_foo(this, (() => { counter++; From 06aea1a47edfdebfd72be3f4b58a9438aeff5daf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 16 Feb 2024 10:54:59 -0500 Subject: [PATCH 02/27] refactor: extract computed key memoisation --- .../src/decorators.ts | 207 ++++++++++++++---- .../src/misc.ts | 74 ++++--- 2 files changed, 212 insertions(+), 69 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index c14e4652777e..ef9e00894bb4 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -9,6 +9,7 @@ import { privateNameVisitorFactory, type PrivateNameVisitorState, } from "./fields.ts"; +import { memoiseComputedKey } from "./misc.ts"; interface Options { /** @deprecated use `constantSuper` assumption instead. Only supported in 2021-12 version. */ @@ -28,6 +29,11 @@ type ClassElement = | t.TSIndexSignature | t.StaticBlock; +type ClassElementCanHaveComputedKeys = + | t.ClassMethod + | t.ClassProperty + | t.ClassAccessorProperty; + // TODO(Babel 8): Only keep 2023-11 export type DecoratorVersionKind = | "2023-11" @@ -179,11 +185,12 @@ function generateClassProperty( function addProxyAccessorsFor( className: t.Identifier, element: NodePath, - originalKey: t.PrivateName | t.Expression, + getterKey: t.PrivateName | t.Expression, + setterKey: t.PrivateName | t.Expression, targetKey: t.PrivateName, - version: DecoratorVersionKind, isComputed: boolean, isStatic: boolean, + version: DecoratorVersionKind, ): void { const thisArg = (version === "2023-11" || @@ -211,17 +218,11 @@ function addProxyAccessorsFor( let getter: t.ClassMethod | t.ClassPrivateMethod, setter: t.ClassMethod | t.ClassPrivateMethod; - if (originalKey.type === "PrivateName") { - getter = t.classPrivateMethod( - "get", - t.cloneNode(originalKey), - [], - getterBody, - isStatic, - ); + if (getterKey.type === "PrivateName") { + getter = t.classPrivateMethod("get", getterKey, [], getterBody, isStatic); setter = t.classPrivateMethod( "set", - t.cloneNode(originalKey), + setterKey as t.PrivateName, [t.identifier("v")], setterBody, isStatic, @@ -229,7 +230,7 @@ function addProxyAccessorsFor( } else { getter = t.classMethod( "get", - t.cloneNode(originalKey), + getterKey, [], getterBody, isComputed, @@ -237,7 +238,7 @@ function addProxyAccessorsFor( ); setter = t.classMethod( "set", - t.cloneNode(originalKey), + setterKey as t.Expression, [t.identifier("v")], setterBody, isComputed, @@ -277,6 +278,84 @@ function extractProxyAccessorsFor( ]; } +function getComputedKeyCompletion(path: NodePath) { + if (path.isSequenceExpression()) { + const expressions = path.get("expressions"); + return getComputedKeyCompletion(expressions[expressions.length - 1]); + } + return skipTransparentExprWrappers(path); +} + +function getComputedKeyMemoiser(path: NodePath): t.Expression { + const completion = getComputedKeyCompletion(path); + if (completion.isConstantExpression()) { + return t.cloneNode(path.node); + } else if ( + completion.isAssignmentExpression() && + completion.get("left").isIdentifier() + ) { + return t.cloneNode(completion.node.left); + } else { + throw new Error( + "Internal Error: the computed key has not yet been memoised.", + ); + } +} + +function prependExpressionsToComputedKey( + expressions: t.Expression[], + fieldPath: NodePath< + t.ClassMethod | t.ClassProperty | t.ClassAccessorProperty + >, +) { + const key = fieldPath.get("key") as NodePath; + expressions.push(key.node); + key.replaceWith(maybeSequenceExpression(expressions)); +} + +function appendExpressionsToComputedKey( + expressions: t.Expression[], + fieldPath: NodePath< + t.ClassMethod | t.ClassProperty | t.ClassAccessorProperty + >, +) { + const key = fieldPath.get("key") as NodePath; + const completion = getComputedKeyCompletion(key); + if (completion.isConstantExpression()) { + prependExpressionsToComputedKey(expressions, fieldPath); + return; + } else { + const scopeParent = key.scope.parent; + const maybeAssignment = memoiseComputedKey( + completion.node, + scopeParent, + scopeParent.generateUid("computedKey"), + ); + if (maybeAssignment != null) { + const expressionSequence = [ + ...expressions, + // preserve the completion result + t.cloneNode(maybeAssignment.left), + ]; + const completionParent = completion.parentPath; + if (completionParent.isSequenceExpression()) { + completionParent.pushContainer("expressions", expressionSequence); + } else { + completion.replaceWith( + maybeSequenceExpression([ + t.cloneNode(maybeAssignment), + ...expressionSequence, + ]), + ); + } + } else { + // If the computed key is an uid reference, treat it as + // a constant expression + prependExpressionsToComputedKey(expressions, fieldPath); + } + } +} + /** * Prepend expressions to the field initializer. If the initializer is not defined, * this function will wrap the last expression within a `void` unary expression. @@ -851,9 +930,13 @@ function transformClass( const generateClassPrivateUid = createLazyPrivateUidGeneratorForClass(path); - const assignments: t.AssignmentExpression[] = []; + const classAssignments: t.AssignmentExpression[] = []; const scopeParent: Scope = path.scope.parent; - const memoiseExpression = (expression: t.Expression, hint: string) => { + const memoiseExpression = ( + expression: t.Expression, + hint: string, + assignments: t.AssignmentExpression[], + ) => { const localEvaluatedId = scopeParent.generateDeclaredUidIdentifier(hint); assignments.push(t.assignmentExpression("=", localEvaluatedId, expression)); return t.cloneNode(localEvaluatedId); @@ -921,19 +1004,28 @@ function transformClass( const keyPath = element.get("key"); const [newPath] = element.replaceWith(newField); + let getterKey, setterKey; + if (computed && !keyPath.isConstantExpression()) { + getterKey = memoiseComputedKey( + createToPropertyKeyCall(state, key as t.Expression), + scopeParent, + scopeParent.generateUid("computedKey"), + )!; + setterKey = t.cloneNode(getterKey.left as t.Identifier); + } else { + getterKey = t.cloneNode(key); + setterKey = t.cloneNode(key); + } + addProxyAccessorsFor( path.node.id, newPath, - computed && !keyPath.isConstantExpression() - ? memoiseExpression( - createToPropertyKeyCall(state, key as t.Expression), - "computedKey", - ) - : key, + getterKey, + setterKey, newId, - version, computed, isStatic, + version, ); } @@ -943,14 +1035,6 @@ function transformClass( } if (!classDecorators && !hasElementDecorators) { - // If nothing is decorated but we have assignments, it must be the memoised - // computed keys of class accessors - if (assignments.length > 0) { - path.insertBefore(assignments.map(expr => t.expressionStatement(expr))); - - // Recrawl the scope to make sure new identifiers are properly synced - path.scope.crawl(); - } // If nothing is decorated and no assignments inserted, return return; } @@ -1043,6 +1127,7 @@ function transformClass( classDecorationsId = memoiseExpression( t.arrayExpression(classDecorations), "classDecs", + classAssignments, ); } } else { @@ -1055,6 +1140,7 @@ function transformClass( let lastInstancePrivateName: t.PrivateName; let needsInstancePrivateBrandCheck = false; + let computedKeyAssignments: t.AssignmentExpression[] = []; let fieldInitializerExpressions = []; let staticFieldInitializerExpressions: t.Expression[] = []; @@ -1109,16 +1195,25 @@ function transformClass( decoratorsHaveThis = haveThis; decoratorsArray = decs.length === 1 ? decs[0] : t.arrayExpression(decs); if (usesFnContext || (hasSideEffects && willExtractSomeElemDecs)) { - decoratorsArray = memoiseExpression(decoratorsArray, name + "Decs"); + decoratorsArray = memoiseExpression( + decoratorsArray, + name + "Decs", + computedKeyAssignments, + ); } } if (isComputed) { if (!element.get("key").isConstantExpression()) { - node.key = memoiseExpression( - createToPropertyKeyCall(state, node.key as t.Expression), - "computedKey", + const key = node.key as t.Expression; + const maybeAssignment = memoiseComputedKey( + hasDecorators ? createToPropertyKeyCall(state, key) : key, + scopeParent, + scopeParent.generateUid("computedKey"), ); + if (maybeAssignment != null) { + node.key = maybeAssignment; + } } } @@ -1187,11 +1282,14 @@ function transformClass( addProxyAccessorsFor( path.node.id, newPath, - key, + t.cloneNode(key), + t.isAssignmentExpression(key) + ? t.cloneNode(key.left as t.Identifier) + : t.cloneNode(key), newId, - version, isComputed, isStatic, + version, ); locals = [newFieldInitId]; } @@ -1263,7 +1361,9 @@ function transformClass( let nameExpr: t.Expression; if (isComputed) { - nameExpr = t.cloneNode(key as t.Expression); + nameExpr = getComputedKeyMemoiser( + element.get("key") as NodePath, + ); } else if (key.type === "PrivateName") { nameExpr = t.stringLiteral(key.id.name); } else if (key.type === "Identifier") { @@ -1287,6 +1387,14 @@ function transformClass( } } + if (isComputed && computedKeyAssignments.length > 0) { + prependExpressionsToComputedKey( + computedKeyAssignments, + element as NodePath, + ); + computedKeyAssignments = []; + } + if ( fieldInitializerExpressions.length > 0 && !isStatic && @@ -1331,6 +1439,25 @@ function transformClass( } } + if (computedKeyAssignments.length > 0) { + const lastComputedKey = path + .get("body.body") + .findLast( + path => (path.node as ClassElementCanHaveComputedKeys).computed, + ); + if (lastComputedKey != null) { + appendExpressionsToComputedKey( + computedKeyAssignments, + lastComputedKey as NodePath, + ); + computedKeyAssignments = []; + } else { + // todo: handle super usage on computedKeyAssignments + // if there is no computed key, the decorator expressions assignment will + // be injected right before the `applyDecs` call. + } + } + if (fieldInitializerExpressions.length > 0) { const isDerivedClass = !!path.node.superClass; if (constructorPath) { @@ -1496,6 +1623,10 @@ function transformClass( originalClass.body.body.unshift( t.staticBlock( [ + computedKeyAssignments.length > 0 && + t.expressionStatement( + maybeSequenceExpression(computedKeyAssignments), + ), t.expressionStatement( createLocalsAssignment( elementLocals, @@ -1522,7 +1653,7 @@ function transformClass( // When path is a ClassExpression, path.insertBefore will convert `path` // into a SequenceExpression - path.insertBefore(assignments.map(expr => t.expressionStatement(expr))); + path.insertBefore(classAssignments.map(expr => t.expressionStatement(expr))); if (needsDeclaraionForClassBinding) { path.insertBefore( diff --git a/packages/babel-helper-create-class-features-plugin/src/misc.ts b/packages/babel-helper-create-class-features-plugin/src/misc.ts index 67e65a1678c0..7ccf62c346a3 100644 --- a/packages/babel-helper-create-class-features-plugin/src/misc.ts +++ b/packages/babel-helper-create-class-features-plugin/src/misc.ts @@ -120,14 +120,48 @@ export function injectInitialization( } } +type ComputedKeyAssignmentExpression = t.AssignmentExpression & { + left: t.Identifier; +}; +export function memoiseComputedKey( + keyNode: t.Expression, + scope: Scope, + hint: string, +): ComputedKeyAssignmentExpression | undefined { + const isUidReference = t.isIdentifier(keyNode) && scope.hasUid(keyNode.name); + const isMemoiseAssignment = + t.isAssignmentExpression(keyNode, { operator: "=" }) && + t.isIdentifier(keyNode.left) && + scope.hasUid(keyNode.left.name); + if (isUidReference) { + return; + } else if (isMemoiseAssignment) { + return t.cloneNode(keyNode as ComputedKeyAssignmentExpression); + } else { + const ident = t.identifier(hint); + // Declaring in the same block scope + // Ref: https://github.com/babel/babel/pull/10029/files#diff-fbbdd83e7a9c998721c1484529c2ce92 + scope.push({ + id: ident, + kind: "let", + }); + return t.assignmentExpression( + "=", + t.cloneNode(ident), + keyNode, + ) as ComputedKeyAssignmentExpression; + } +} + export function extractComputedKeys( path: NodePath, computedPaths: NodePath[], file: File, ) { + const { scope } = path; const declarations: t.ExpressionStatement[] = []; const state = { - classBinding: path.node.id && path.scope.getBinding(path.node.id.name), + classBinding: path.node.id && scope.getBinding(path.node.id.name), file, }; for (const computedPath of computedPaths) { @@ -142,36 +176,14 @@ export function extractComputedKeys( // Make sure computed property names are only evaluated once (upon class definition) // and in the right order in combination with static properties if (!computedKey.isConstantExpression()) { - const scope = path.scope; - const isUidReference = - t.isIdentifier(computedKey.node) && scope.hasUid(computedKey.node.name); - const isMemoiseAssignment = - computedKey.isAssignmentExpression({ operator: "=" }) && - t.isIdentifier(computedKey.node.left) && - scope.hasUid(computedKey.node.left.name); - if (isUidReference) { - continue; - } else if (isMemoiseAssignment) { - declarations.push(t.expressionStatement(t.cloneNode(computedNode.key))); - computedNode.key = t.cloneNode( - (computedNode.key as t.AssignmentExpression).left as t.Identifier, - ); - } else { - const ident = path.scope.generateUidIdentifierBasedOnNode( - computedNode.key, - ); - // Declaring in the same block scope - // Ref: https://github.com/babel/babel/pull/10029/files#diff-fbbdd83e7a9c998721c1484529c2ce92 - scope.push({ - id: ident, - kind: "let", - }); - declarations.push( - t.expressionStatement( - t.assignmentExpression("=", t.cloneNode(ident), computedNode.key), - ), - ); - computedNode.key = t.cloneNode(ident); + const assignment = memoiseComputedKey( + computedKey.node, + scope, + scope.generateUidBasedOnNode(computedKey.node), + ); + if (assignment) { + declarations.push(t.expressionStatement(assignment)); + computedNode.key = t.cloneNode(assignment.left); } } } From c30a1894c7ea9ad0100e20f04bf7aa6fe057eaae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Thu, 29 Feb 2024 16:32:05 -0500 Subject: [PATCH 03/27] handle computed static field in decorated class --- .../src/decorators.ts | 76 ++++++++++++------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index ef9e00894bb4..c615fd95b39c 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -290,14 +290,19 @@ function getComputedKeyMemoiser(path: NodePath): t.Expression { const completion = getComputedKeyCompletion(path); if (completion.isConstantExpression()) { return t.cloneNode(path.node); + } else if ( + completion.isIdentifier() && + path.scope.hasUid(completion.node.name) + ) { + return t.cloneNode(path.node); } else if ( completion.isAssignmentExpression() && completion.get("left").isIdentifier() ) { - return t.cloneNode(completion.node.left); + return t.cloneNode(completion.node.left as t.Identifier); } else { throw new Error( - "Internal Error: the computed key has not yet been memoised.", + `Internal Error: the computed key ${path.toString()} has not yet been memoised.`, ); } } @@ -1212,7 +1217,15 @@ function transformClass( scopeParent.generateUid("computedKey"), ); if (maybeAssignment != null) { - node.key = maybeAssignment; + // If it is a static computed field within a decorated class, move the computed key into + // computed key assignments which will be then moved into the non-static class, to ensure + // that the evaluation order is correct and the private environment is correct + if (classDecorators && element.isClassProperty({ static: true })) { + node.key = t.cloneNode(maybeAssignment.left); + computedKeyAssignments.push(maybeAssignment); + } else { + node.key = maybeAssignment; + } } } } @@ -1242,6 +1255,20 @@ function transformClass( t.FunctionExpression | t.ArrowFunctionExpression >; + let nameExpr: t.Expression; + + if (isComputed) { + nameExpr = getComputedKeyMemoiser( + element.get("key") as NodePath, + ); + } else if (key.type === "PrivateName") { + nameExpr = t.stringLiteral(key.id.name); + } else if (key.type === "Identifier") { + nameExpr = t.stringLiteral(key.name); + } else { + nameExpr = t.cloneNode(key as t.Expression); + } + if (kind === ACCESSOR) { const { value } = element.node as t.ClassAccessorProperty; @@ -1358,20 +1385,6 @@ function transformClass( } } - let nameExpr: t.Expression; - - if (isComputed) { - nameExpr = getComputedKeyMemoiser( - element.get("key") as NodePath, - ); - } else if (key.type === "PrivateName") { - nameExpr = t.stringLiteral(key.id.name); - } else if (key.type === "Identifier") { - nameExpr = t.stringLiteral(key.name); - } else { - nameExpr = t.cloneNode(key as t.Expression); - } - elementDecoratorInfo.push({ kind, decoratorsArray, @@ -1388,11 +1401,15 @@ function transformClass( } if (isComputed && computedKeyAssignments.length > 0) { - prependExpressionsToComputedKey( - computedKeyAssignments, - element as NodePath, - ); - computedKeyAssignments = []; + if (classDecorators && element.isClassProperty({ static: true })) { + // do nothing + } else { + prependExpressionsToComputedKey( + computedKeyAssignments, + element as NodePath, + ); + computedKeyAssignments = []; + } } if ( @@ -1440,11 +1457,14 @@ function transformClass( } if (computedKeyAssignments.length > 0) { - const lastComputedKey = path - .get("body.body") - .findLast( - path => (path.node as ClassElementCanHaveComputedKeys).computed, - ); + const lastComputedKey = path.get("body.body").findLast(path => { + if ((path.node as ClassElementCanHaveComputedKeys).computed) { + if (classDecorators && path.isClassProperty({ static: true })) { + return false; + } + return true; + } + }); if (lastComputedKey != null) { appendExpressionsToComputedKey( computedKeyAssignments, @@ -1452,7 +1472,7 @@ function transformClass( ); computedKeyAssignments = []; } else { - // todo: handle super usage on computedKeyAssignments + // todo: handle function context e.g. super, this, and arguments in computedKeyAssignments // if there is no computed key, the decorator expressions assignment will // be injected right before the `applyDecs` call. } From 782505c69bf1ee613bb5c644dc79579d74fb50c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Thu, 29 Feb 2024 17:54:02 -0500 Subject: [PATCH 04/27] handle this and super call when moving computed key assignments --- .../src/decorators.ts | 112 +++++++++++++----- 1 file changed, 85 insertions(+), 27 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index c615fd95b39c..ef8c72f01cc2 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -1,7 +1,8 @@ import type { NodePath, Scope, Visitor } from "@babel/traverse"; -import { types as t, template } from "@babel/core"; +import { types as t, template, traverse } from "@babel/core"; import ReplaceSupers from "@babel/helper-replace-supers"; import splitExportDeclaration from "@babel/helper-split-export-declaration"; +import environmentVisitor from "@babel/helper-environment-visitor"; import * as charCodes from "charcodes"; import type { PluginAPI, PluginObject, PluginPass } from "@babel/core"; import { skipTransparentExprWrappers } from "@babel/helper-skip-transparent-expression-wrappers"; @@ -1538,6 +1539,7 @@ function transformClass( const classInitCall = classInitLocal && t.callExpression(t.cloneNode(classInitLocal), []); + let originalClassPath = path; const originalClass = path.node; if (classDecorators) { @@ -1619,6 +1621,15 @@ function transformClass( } path.replaceWith(newExpr); + + path.traverse({ + Class(path) { + if (path.node === originalClass) { + originalClassPath = path; + path.stop(); + } + }, + }); } } if (!classInitInjected && classInitCall) { @@ -1640,35 +1651,82 @@ function transformClass( superClass = id; } } - originalClass.body.body.unshift( - t.staticBlock( - [ - computedKeyAssignments.length > 0 && - t.expressionStatement( - maybeSequenceExpression(computedKeyAssignments), + + originalClass.body.body.unshift(t.staticBlock([])); + const applyDecoratorWrapperPath = originalClassPath + .get("body") + .get("body")[0] as NodePath; + + if (computedKeyAssignments.length > 0) { + applyDecoratorWrapperPath.pushContainer( + "body", + t.expressionStatement(maybeSequenceExpression(computedKeyAssignments)), + ); + + const computedKeysPath = applyDecoratorWrapperPath.get("body")[0]; + + // Capture lexical this and super call, replace their usage in computed key assignments + let outerThis: t.Identifier, outerSuperCall: t.Identifier; + const computedKeysPathVisitor: Visitor = { + ThisExpression(path) { + outerThis ??= scopeParent.generateDeclaredUidIdentifier("outerThis"); + path.replaceWith(t.cloneNode(outerThis)); + }, + CallExpression(path) { + const calleePath = path.get("callee"); + if (calleePath.isSuper()) { + outerSuperCall ??= + scopeParent.generateDeclaredUidIdentifier("outerSuper"); + calleePath.replaceWith(t.cloneNode(outerSuperCall)); + } + }, + }; + computedKeysPath.traverse( + traverse.visitors.merge([computedKeysPathVisitor, environmentVisitor]), + ); + if (outerThis) { + classAssignments.push( + t.assignmentExpression("=", t.cloneNode(outerThis), t.thisExpression()), + ); + } + if (outerSuperCall) { + classAssignments.push( + t.assignmentExpression( + "=", + t.cloneNode(outerSuperCall), + t.arrowFunctionExpression( + [t.restElement(t.identifier("args"))], + t.callExpression(t.super(), [ + t.spreadElement(t.identifier("args")), + ]), ), + ), + ); + } + } + + applyDecoratorWrapperPath.pushContainer( + "body", + [ + t.expressionStatement( + createLocalsAssignment( + elementLocals, + classLocals, + elementDecorations, + classDecorationsId ?? t.arrayExpression(classDecorations), + t.numericLiteral(classDecorationsFlag), + needsInstancePrivateBrandCheck ? lastInstancePrivateName : null, + typeof className === "object" ? className : undefined, + t.cloneNode(superClass), + state, + version, + ), + ), + staticInitLocal && t.expressionStatement( - createLocalsAssignment( - elementLocals, - classLocals, - elementDecorations, - classDecorationsId ?? t.arrayExpression(classDecorations), - t.numericLiteral(classDecorationsFlag), - needsInstancePrivateBrandCheck ? lastInstancePrivateName : null, - typeof className === "object" ? className : undefined, - t.cloneNode(superClass), - state, - version, - ), + t.callExpression(t.cloneNode(staticInitLocal), [t.thisExpression()]), ), - staticInitLocal && - t.expressionStatement( - t.callExpression(t.cloneNode(staticInitLocal), [ - t.thisExpression(), - ]), - ), - ].filter(Boolean), - ), + ].filter(Boolean), ); // When path is a ClassExpression, path.insertBefore will convert `path` From 6dd319862f93df2f0c0575d4d59fb7d78801cf6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 4 Mar 2024 10:35:32 -0500 Subject: [PATCH 05/27] handle other functional context --- .../src/decorators.ts | 101 +++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index ef8c72f01cc2..3df662ae1c23 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -1666,7 +1666,11 @@ function transformClass( const computedKeysPath = applyDecoratorWrapperPath.get("body")[0]; // Capture lexical this and super call, replace their usage in computed key assignments - let outerThis: t.Identifier, outerSuperCall: t.Identifier; + let outerThis: t.Identifier, + outerSuperCall: t.Identifier, + outerSuperProp: t.Identifier, + outerArguments: t.Identifier, + outerNewTarget: t.Identifier; const computedKeysPathVisitor: Visitor = { ThisExpression(path) { outerThis ??= scopeParent.generateDeclaredUidIdentifier("outerThis"); @@ -1680,6 +1684,38 @@ function transformClass( calleePath.replaceWith(t.cloneNode(outerSuperCall)); } }, + MemberExpression(path) { + const objectPath = path.get("object"); + if (objectPath.isSuper()) { + outerSuperProp ??= + scopeParent.generateDeclaredUidIdentifier("outerSuperProp"); + path.replaceWith( + t.memberExpression( + t.callExpression(t.cloneNode(outerSuperProp), [ + path.node.computed + ? (path.node.property as t.Expression) + : t.stringLiteral((path.node.property as t.Identifier).name), + ]), + t.identifier("_"), + ), + ); + } + }, + Identifier(path) { + if (path.node.name === "arguments") { + outerArguments ??= + scopeParent.generateDeclaredUidIdentifier("outerArguments"); + path.replaceWith(t.cloneNode(outerArguments)); + } + }, + MetaProperty(path) { + const object = path.node.meta; + if (object.name === "new") { + outerNewTarget ??= + scopeParent.generateDeclaredUidIdentifier("outerNewTarget"); + path.replaceWith(t.cloneNode(outerNewTarget)); + } + }, }; computedKeysPath.traverse( traverse.visitors.merge([computedKeysPathVisitor, environmentVisitor]), @@ -1703,6 +1739,69 @@ function transformClass( ), ); } + if (outerSuperProp) { + classAssignments.push( + t.assignmentExpression( + "=", + t.cloneNode(outerSuperProp), + t.arrowFunctionExpression( + [t.identifier("prop")], + t.callExpression( + t.memberExpression( + t.identifier("Object"), + t.identifier("defineProperty"), + ), + [ + t.objectExpression([]), + t.stringLiteral("_"), + t.objectExpression([ + t.objectProperty( + t.identifier("get"), + t.arrowFunctionExpression( + [], + t.memberExpression(t.super(), t.identifier("prop"), true), + ), + ), + t.objectProperty( + t.identifier("set"), + t.arrowFunctionExpression( + [t.identifier("v")], + t.assignmentExpression( + "=", + t.memberExpression( + t.super(), + t.identifier("prop"), + true, + ), + t.identifier("v"), + ), + ), + ), + ]), + ], + ), + ), + ), + ); + } + if (outerArguments) { + classAssignments.push( + t.assignmentExpression( + "=", + t.cloneNode(outerArguments), + t.identifier("arguments"), + ), + ); + } + if (outerNewTarget) { + classAssignments.push( + t.assignmentExpression( + "=", + t.cloneNode(outerNewTarget), + t.metaProperty(t.identifier("new"), t.identifier("target")), + ), + ); + } } applyDecoratorWrapperPath.pushContainer( From 2d34eeb216b49f918ed0f34c279b9c65da9d4e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 4 Mar 2024 10:45:58 -0500 Subject: [PATCH 06/27] fix: insert non-static class in the key of the wrapper This change ensures that 1) non static computed key will share the same function context when moved into the non-static class 2) evaluations of decorators and computed keys will always precede static computed keys, given that they have been moved into computed key assignments before --- .../src/decorators.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index 3df662ae1c23..e87d28260ce6 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -1584,12 +1584,18 @@ function transformClass( class extends ${state.addHelper("identity")} {} ` as t.ClassExpression; staticsClass.body.body = [ - t.staticBlock([ - t.toStatement(originalClass, true) || - // If toStatement returns false, originalClass must be an anonymous ClassExpression, - // because `export default @dec ...` has been handled in the export visitor before. - t.expressionStatement(originalClass as t.ClassExpression), - ]), + // Insert the original class to a computed key of the wrapper so that + // 1) they share the same function context with the wrapper class + // 2) the memoisation of static computed field is evaluated before they are referenced + // in the wrapper class keys + t.classProperty( + t.toExpression(originalClass), + undefined, + undefined, + undefined, + /* computed */ true, + /* static */ true, + ), ...statics, ]; From 125a837c4ec5dd003bbb4afcc4f9dba5456b5364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 4 Mar 2024 16:17:02 -0500 Subject: [PATCH 07/27] inject computed keys elements to the last non-comptued elements so that we can still preserve the production params [yield], [await] inherited from the outer scope --- .../src/decorators.ts | 63 ++++++++--- .../decorator-evaluation-yield/exec.js | 102 ++++++++++++++++++ .../decorator-evaluation-yield/options.json | 7 ++ 3 files changed, 160 insertions(+), 12 deletions(-) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield/options.json diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index e87d28260ce6..ea878edd6b78 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -839,12 +839,14 @@ function createPrivateBrandCheckClosure(brandName: t.PrivateName) { // Check if the expression does not reference function-specific // context or the given identifier name. // `true` means "maybe" and `false` means "no". -function usesFunctionContext(expression: t.Node) { +function usesFunctionContextOrYieldAwait(expression: t.Node) { try { t.traverseFast(expression, node => { if ( t.isThisExpression(node) || t.isSuper(node) || + t.isYieldExpression(node) || + t.isAwaitExpression(node) || t.isIdentifier(node, { name: "arguments" }) || (t.isMetaProperty(node) && node.meta.name !== "import") ) { @@ -872,6 +874,14 @@ function usesPrivateField(expression: t.Node) { } } +function convertToComputedKey(path: NodePath) { + const { node } = path; + node.computed = true; + if (t.isIdentifier(node.key)) { + node.key = t.stringLiteral(node.key.name); + } +} + function checkPrivateMethodUpdateError( path: NodePath, decoratedPrivateMethods: Set, @@ -995,8 +1005,9 @@ function transformClass( break; } hasElementDecorators = true; - elemDecsUseFnContext ||= - element.node.decorators.some(usesFunctionContext); + elemDecsUseFnContext ||= element.node.decorators.some( + usesFunctionContextOrYieldAwait, + ); } else if (element.node.type === "ClassAccessorProperty") { // @ts-expect-error todo: propertyVisitor.ClassAccessorProperty should be callable. Improve typings. propertyVisitor.ClassAccessorProperty( @@ -1091,7 +1102,7 @@ function transformClass( } decoratorsThis.push(object); hasSideEffects ||= !scopeParent.isStatic(expression); - usesFnContext ||= usesFunctionContext(expression); + usesFnContext ||= usesFunctionContextOrYieldAwait(expression); } return { hasSideEffects, usesFnContext, decoratorsThis }; } @@ -1407,7 +1418,9 @@ function transformClass( } else { prependExpressionsToComputedKey( computedKeyAssignments, - element as NodePath, + (kind === ACCESSOR + ? element.getNextSibling() // the getter transpiled from the accessor + : element) as NodePath, ); computedKeyAssignments = []; } @@ -1458,24 +1471,24 @@ function transformClass( } if (computedKeyAssignments.length > 0) { - const lastComputedKey = path.get("body.body").findLast(path => { + const elements = path.get("body.body"); + const lastComputedElement = elements.findLast(path => { if ((path.node as ClassElementCanHaveComputedKeys).computed) { if (classDecorators && path.isClassProperty({ static: true })) { return false; } return true; } - }); - if (lastComputedKey != null) { + }) as NodePath; + if (lastComputedElement != null) { appendExpressionsToComputedKey( computedKeyAssignments, - lastComputedKey as NodePath, + lastComputedElement, ); computedKeyAssignments = []; } else { - // todo: handle function context e.g. super, this, and arguments in computedKeyAssignments - // if there is no computed key, the decorator expressions assignment will - // be injected right before the `applyDecs` call. + // if there is no computed key, we will try to convert the last non-computed class element + // into a computed key and insert them there } } @@ -1659,6 +1672,32 @@ function transformClass( } originalClass.body.body.unshift(t.staticBlock([])); + if (computedKeyAssignments.length > 0) { + // todo: the following branch will fail on 2023-05 version + if (version === "2023-11") { + const elements = originalClassPath.get("body.body"); + const lastPublicElement = elements.findLast(path => { + if ( + (path.isClassProperty() || path.isClassMethod()) && + !path.node.computed && + (path.node as t.ClassMethod).kind !== "constructor" + ) { + return true; + } + }) as NodePath; + if (lastPublicElement != null) { + // Convert it to a computed key to host decorator evaluations + convertToComputedKey(lastPublicElement); + prependExpressionsToComputedKey( + computedKeyAssignments, + lastPublicElement as NodePath, + ); + computedKeyAssignments = []; + } + // when there is no public class elements, the decorator expressions + // assignment will be injected right before the `applyDecs` call. + } + } const applyDecoratorWrapperPath = originalClassPath .get("body") .get("body")[0] as NodePath; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield/exec.js new file mode 100644 index 000000000000..28bfbb4bc84b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield/exec.js @@ -0,0 +1,102 @@ +const noop = () => {}; +{ + const log = { + *[Symbol.iterator]() { + + class Foo { + @(yield 1, noop) method() {} + @(yield 2, noop) static method() {} + @(yield 3, noop) field; + @(yield 4, noop) static field; + @(yield 5, noop) get getter() { + return; + } + @(yield 6, noop) static get getter() { + return; + } + @(yield 7, noop) set setter(x) {} + @(yield 8, noop) static set setter(x) {} + @(yield 9, noop) accessor accessor; + @(yield 10, noop) static accessor accessor; + } + }, + }; + expect([...log].join()).toBe("1,2,3,4,5,6,7,8,9,10"); +} +{ + let Foo; + const log = { + *[Symbol.iterator]() { + + Foo = class { + @(yield 0, noop) [(yield 1, "method")]() {} + @(yield 2, noop) static method() {} + @(yield 3, noop) field; + @(yield 4, noop) static field; + @(yield 5, noop) get getter() { + return; + } + @(yield 6, noop) static get getter() { + return; + } + @(yield 7, noop) set setter(x) {} + @(yield 8, noop) static set setter(x) {} + @(yield 9, noop) accessor accessor; + @(yield 10, noop) static accessor accessor; + } + }, + }; + expect([...log].join()).toBe("0,1,2,3,4,5,6,7,8,9,10"); + expect((new Foo())).toHaveProperty("method"); +} +{ + const log = { + *[Symbol.iterator]() { + @(yield 0, noop) + class Foo { + @(yield 1, noop) method() {} + @(yield 2, noop) static method() {} + @(yield 3, noop) field; + @(yield 4, noop) static field; + @(yield 5, noop) get getter() { + return; + } + @(yield 6, noop) static get getter() { + return; + } + @(yield 7, noop) set setter(x) {} + @(yield 8, noop) static set setter(x) {} + @(yield 9, noop) accessor accessor; + @(yield 10, noop) static accessor accessor; + } + }, + }; + expect([...log].join()).toBe("0,1,2,3,4,5,6,7,8,9,10"); +} + +{ + let Foo; + const log = { + *[Symbol.iterator]() { + Foo = @(yield 0, noop) + class { + @(yield 1, noop) method() {} + @(yield 2, noop) static method() {} + @(yield 3, noop) field; + @(yield 4, noop) static field; + @(yield 5, noop) get getter() { + return; + } + @(yield 6, noop) static get getter() { + return; + } + @(yield 7, noop) set setter(x) {} + @(yield 8, noop) static set setter(x) {} + @(yield 9, noop) accessor accessor; + @(yield 10, noop) static accessor [(yield 11, "accessor")]; + } + }, + }; + expect([...log].join()).toBe("0,1,2,3,4,5,6,7,8,9,10,11"); + expect(Foo).toHaveProperty("accessor"); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield/options.json new file mode 100644 index 000000000000..98a9bacf3887 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + ["proposal-decorators", { "version": "2023-11" }], + "transform-class-static-block" + ], + "minNodeVersion": "12.0.0" +} From efbce429f9aa1e73aebd321946347a919bb56ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 4 Mar 2024 18:56:14 -0500 Subject: [PATCH 08/27] reorg complex AST factories --- .../src/decorators.ts | 100 ++++++++++-------- 1 file changed, 56 insertions(+), 44 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index ea878edd6b78..b1bcbf85d18c 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -836,6 +836,58 @@ function createPrivateBrandCheckClosure(brandName: t.PrivateName) { ); } +/** + * create a super() delegate + * (...args) => super(...args) + * + */ +function createSuperCallDelegate() { + return t.arrowFunctionExpression( + [t.restElement(t.identifier("args"))], + t.callExpression(t.super(), [t.spreadElement(t.identifier("args"))]), + ); +} + +/** + * create a super[prop] delegate + * (prop) => Object.defineProperty({}, "_", { + * get: () => super[prop], + * set: (v) => super[prop] = v + * }) + * + */ +function createSuperPropDelegate() { + const getDelegate = t.arrowFunctionExpression( + [], + t.memberExpression(t.super(), t.identifier("prop"), true), + ); + const setDelegate = t.assignmentExpression( + "=", + t.memberExpression(t.super(), t.identifier("prop"), true), + t.identifier("v"), + ); + return t.arrowFunctionExpression( + [t.identifier("prop")], + t.callExpression( + t.memberExpression( + t.identifier("Object"), + t.identifier("defineProperty"), + ), + [ + t.objectExpression([]), + t.stringLiteral("_"), + t.objectExpression([ + t.objectProperty(t.identifier("get"), getDelegate), + t.objectProperty( + t.identifier("set"), + t.arrowFunctionExpression([t.identifier("v")], setDelegate), + ), + ]), + ], + ), + ); +} + // Check if the expression does not reference function-specific // context or the given identifier name. // `true` means "maybe" and `false` means "no". @@ -1710,7 +1762,8 @@ function transformClass( const computedKeysPath = applyDecoratorWrapperPath.get("body")[0]; - // Capture lexical this and super call, replace their usage in computed key assignments + // Capture lexical this, super() and other function contexts, replace their usage + // in computed key assignments let outerThis: t.Identifier, outerSuperCall: t.Identifier, outerSuperProp: t.Identifier, @@ -1775,12 +1828,7 @@ function transformClass( t.assignmentExpression( "=", t.cloneNode(outerSuperCall), - t.arrowFunctionExpression( - [t.restElement(t.identifier("args"))], - t.callExpression(t.super(), [ - t.spreadElement(t.identifier("args")), - ]), - ), + createSuperCallDelegate(), ), ); } @@ -1789,43 +1837,7 @@ function transformClass( t.assignmentExpression( "=", t.cloneNode(outerSuperProp), - t.arrowFunctionExpression( - [t.identifier("prop")], - t.callExpression( - t.memberExpression( - t.identifier("Object"), - t.identifier("defineProperty"), - ), - [ - t.objectExpression([]), - t.stringLiteral("_"), - t.objectExpression([ - t.objectProperty( - t.identifier("get"), - t.arrowFunctionExpression( - [], - t.memberExpression(t.super(), t.identifier("prop"), true), - ), - ), - t.objectProperty( - t.identifier("set"), - t.arrowFunctionExpression( - [t.identifier("v")], - t.assignmentExpression( - "=", - t.memberExpression( - t.super(), - t.identifier("prop"), - true, - ), - t.identifier("v"), - ), - ), - ), - ]), - ], - ), - ), + createSuperPropDelegate(), ), ); } From 7714626bc497a3795d2cf4bfd34069b24fef2516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 4 Mar 2024 18:39:42 -0500 Subject: [PATCH 09/27] add new test cases --- .../exec.js | 33 ++++ .../decorator-evaluation-arguments/exec.js | 54 ++++++ .../options.json | 0 .../decorator-evaluation-new-target/exec.js | 54 ++++++ .../options.json | 7 + .../exec.js | 159 ++++++++++++++++++ .../decorator-evaluation-scope/exec.js | 12 -- .../exec.js | 159 ++++++++++++++++++ .../options.json | 7 + .../exec.js | 148 ++++++++++++++++ .../options.json | 7 + .../decorator-evaluation-this/exec.js | 61 +++++++ .../decorator-evaluation-this/options.json | 7 + .../exec.js | 66 ++++++++ .../options.json | 7 + 15 files changed, 769 insertions(+), 12 deletions(-) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/.decorator-evaluation-yield-super-private-all-private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-arguments/exec.js rename packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/{decorator-evaluation-scope => decorator-evaluation-arguments}/options.json (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-new-target/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-new-target/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-private-environment/exec.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-scope/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-getter-setter/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-getter-setter/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-property/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-property/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-this/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-this/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/options.json diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/.decorator-evaluation-yield-super-private-all-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/.decorator-evaluation-yield-super-private-all-private/exec.js new file mode 100644 index 000000000000..12046fcc0847 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/.decorator-evaluation-yield-super-private-all-private/exec.js @@ -0,0 +1,33 @@ +{ + let B; + + class CaptureFactory { + static *id(fn) { + yield fn; + } + } + + function dummy() {} + + class A extends CaptureFactory { + static #X = "A#X"; + static *[Symbol.iterator] () { + B = @dummy + class B { + static #X = "B#X"; + @(yield* super.id(_ => _.#X), dummy) #method () {} + @(yield* super.id(_ => _.#X), dummy) static #Method () {} + @(yield* super.id(_ => _.#X), dummy) get #getter () {} + @(yield* super.id(_ => _.#X), dummy) static get #Getter () {} + @(yield* super.id(_ => _.#X), dummy) set #setter (v) {} + @(yield* super.id(_ => _.#X), dummy) static set #Setter (v) {} + @(yield* super.id(_ => _.#X), dummy) #property; + @(yield* super.id(_ => _.#X), dummy) static #Property; + @(yield* super.id(_ => _.#X), dummy) accessor #accessor; + @(yield* super.id(_ => _.#X), dummy) static accessor #Accessor; + } + } + } + + expect([...A].map(fn => fn(B)).join(",")).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-arguments/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-arguments/exec.js new file mode 100644 index 000000000000..bb1cd1c259f4 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-arguments/exec.js @@ -0,0 +1,54 @@ +{ + let receivedArguments; + function decFactory(args) { + receivedArguments = args; + return x => x; + } + function B() { + class C { + @decFactory(arguments) #p; + } + } + + B(0); + expect(receivedArguments).toHaveLength(1); + expect(receivedArguments[0]).toBe(0); +} + +{ + function noop() {} + let receivedArguments; + function decFactory(args) { + receivedArguments = args; + return x => x; + } + function B() { + @noop + class C { + @decFactory(arguments) #p; + } + } + + B(0); + expect(receivedArguments).toHaveLength(1); + expect(receivedArguments[0]).toBe(0); +} + +{ + function noop() {} + let receivedArguments; + function decFactory(args) { + receivedArguments = args; + return x => x; + } + function B() { + @noop + class C { + @decFactory(arguments) static #p; + } + } + + B(0); + expect(receivedArguments).toHaveLength(1); + expect(receivedArguments[0]).toBe(0); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-scope/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-arguments/options.json similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-scope/options.json rename to packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-arguments/options.json diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-new-target/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-new-target/exec.js new file mode 100644 index 000000000000..06643188b21c --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-new-target/exec.js @@ -0,0 +1,54 @@ +{ + let receivedNewTarget; + function decFactory(target) { + receivedNewTarget = target; + return x => x; + } + function B() { + class C { + @decFactory(new.target) #p; + } + } + + new B(); + + expect(receivedNewTarget).toBe(B); +} + +{ + function noop() {} + let receivedNewTarget; + function decFactory(target) { + receivedNewTarget = target; + return x => x; + } + function B() { + @noop + class C { + @decFactory(new.target) #p; + } + } + + new B(); + + expect(receivedNewTarget).toBe(B); +} + +{ + function noop() {} + let receivedNewTarget; + function decFactory(target) { + receivedNewTarget = target; + return x => x; + } + function B() { + @noop + class C { + @decFactory(new.target) static #p; + } + } + + new B(); + + expect(receivedNewTarget).toBe(B); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-new-target/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-new-target/options.json new file mode 100644 index 000000000000..98a9bacf3887 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-new-target/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + ["proposal-decorators", { "version": "2023-11" }], + "transform-class-static-block" + ], + "minNodeVersion": "12.0.0" +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-private-environment/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-private-environment/exec.js new file mode 100644 index 000000000000..4ae3da714ae6 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-private-environment/exec.js @@ -0,0 +1,159 @@ +{ + let staticFns = [], fns = [] + let B; + + function capture(staticFn, fn) { + staticFns.push(staticFn); + fns.push(fn); + } + + function dummy() {} + + class A { + static #X = "A#X"; + #x = "a#x"; + constructor () { + B = class B { + static #X = "B#X"; + #x = "b#x"; + @(capture(_ => _.#X, _ => _.#x), dummy) method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) get getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static get getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) set setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) static set setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) property; + @(capture(_ => _.#X, _ => _.#x), dummy) static property; + @(capture(_ => _.#X, _ => _.#x), dummy) accessor accessor; + @(capture(_ => _.#X, _ => _.#x), dummy) static accessor accessor; + } + } + } + + let a = new A(), b = new B(); + + expect(staticFns.map(fn => fn(B)).join()).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); + expect(fns.map(fn => fn(b)).join()).toBe("b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x"); +} + +{ + let staticFns = [], fns = [] + let B; + + function capture(staticFn, fn) { + staticFns.push(staticFn); + fns.push(fn); + } + + function dummy() {} + + class A { + static #X = "A#X"; + #x = "a#x"; + constructor () { + B = class B { + static #X = "B#X"; + #x = "b#x"; + @(capture(_ => _.#X, _ => _.#x), dummy) #method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static #Method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) get #getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static get #Getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) set #setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) static set #Setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) #property; + @(capture(_ => _.#X, _ => _.#x), dummy) static #Property; + @(capture(_ => _.#X, _ => _.#x), dummy) accessor #accessor; + @(capture(_ => _.#X, _ => _.#x), dummy) static accessor #Accessor; + } + } + } + + let a = new A(), b = new B(); + + expect(staticFns.map(fn => fn(B)).join()).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); + expect(fns.map(fn => fn(b)).join()).toBe("b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x"); +} + +{ + let staticFns = [], fns = [] + let B; + + function capture(staticFn, fn) { + staticFns.push(staticFn); + fns.push(fn); + } + + function dummy() {} + + class A { + static #X = "A#X"; + #x = "a#x"; + constructor () { + B = + @(capture(_ => _.#X, _ => _.#x), dummy) + class B { + static #X = "B#X"; + #x = "b#x"; + @(capture(_ => _.#X, _ => _.#x), dummy) method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) get getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static get getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) set setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) static set setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) property; + @(capture(_ => _.#X, _ => _.#x), dummy) static property; + @(capture(_ => _.#X, _ => _.#x), dummy) accessor accessor; + @(capture(_ => _.#X, _ => _.#x), dummy) static accessor accessor; + } + } + } + + let a = new A(), b = new B(); + expect(staticFns.shift()(A)).toBe("A#X"); + expect(fns.shift()(a)).toBe("a#x"); + + expect(staticFns.map(fn => fn(B)).join()).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); + expect(fns.map(fn => fn(b)).join()).toBe("b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x"); +} + +{ + let staticFns = [], fns = [] + let B; + + function capture(staticFn, fn) { + staticFns.push(staticFn); + fns.push(fn); + } + + function dummy() {} + + class A { + static #X = "A#X"; + #x = "a#x"; + constructor () { + B = + @(capture(_ => _.#X, _ => _.#x), dummy) + class B { + static #X = "B#X"; + #x = "b#x"; + @(capture(_ => _.#X, _ => _.#x), dummy) #method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static #Method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) get #getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static get #Getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) set #setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) static set #Setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) #property; + @(capture(_ => _.#X, _ => _.#x), dummy) static #Property; + @(capture(_ => _.#X, _ => _.#x), dummy) accessor #accessor; + @(capture(_ => _.#X, _ => _.#x), dummy) static accessor #Accessor; + } + } + } + + let a = new A(), b = new B(); + expect(staticFns.shift()(A)).toBe("A#X"); + expect(fns.shift()(a)).toBe("a#x"); + + expect(staticFns.map(fn => fn(B)).join()).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); + expect(fns.map(fn => fn(b)).join()).toBe("b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x"); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-scope/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-scope/exec.js deleted file mode 100644 index ec8beb3b8cbf..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-scope/exec.js +++ /dev/null @@ -1,12 +0,0 @@ -let receivedName; -function decFactory(name) { receivedName = name; return x => x } -class B { - static m() { - class C { - @decFactory(this.name) p; - } - } -} - -B.m(); -expect(receivedName).toBe("B"); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-getter-setter/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-getter-setter/exec.js new file mode 100644 index 000000000000..816f371e0268 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-getter-setter/exec.js @@ -0,0 +1,159 @@ +function noop() {} + +function BaseFactory(logs) { + return class A { + static get getter() { + logs.push("getter") + } + static set setter(v) { + logs.push("setter"); + } + } +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + class C { + @(super.setter = super.getter, noop) p; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + class C { + @(super.setter = super.getter, noop) #p; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + class C { + @(super.setter = super.getter, noop) accessor [(noop(), "p")]; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + @noop + class C { + @(super.setter = super.getter, noop) p; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + @noop + class C { + @(super.setter = super.getter, noop) static p; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + @noop + class C { + @(super.setter = super.getter, noop) #p; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + @noop + class C { + @(super.setter = super.getter, noop) [(noop(), "p")]; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + @noop + class C { + @(super.setter = super.getter, noop) static [(noop(), "p")]; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + @noop + class C { + @(super.setter = super.getter, noop) accessor [(noop(), "p")]; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + @noop + class C { + @(super.setter = super.getter, noop) static accessor [(noop(), "p")]; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-getter-setter/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-getter-setter/options.json new file mode 100644 index 000000000000..98a9bacf3887 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-getter-setter/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + ["proposal-decorators", { "version": "2023-11" }], + "transform-class-static-block" + ], + "minNodeVersion": "12.0.0" +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-property/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-property/exec.js new file mode 100644 index 000000000000..2ba4461a451f --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-property/exec.js @@ -0,0 +1,148 @@ +function noop() {} + +{ + let receivedName; + class B extends class A {} { + static m() { + class C { + @(receivedName = super.name, noop) p; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + class C { + @(receivedName = super.name, noop) #p; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + class C { + @(receivedName = super.name, noop) accessor [(noop(), "p")]; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + @noop + class C { + @(receivedName = super.name, noop) p; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + @noop + class C { + @(receivedName = super.name, noop) static p; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + @noop + class C { + @(receivedName = super.name, noop) #p; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + @noop + class C { + @(receivedName = super.name, noop) [(noop(), "p")]; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + @noop + class C { + @(receivedName = super.name, noop) static [(noop(), "p")]; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + @noop + class C { + @(receivedName = super.name, noop) accessor [(noop(), "p")]; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + @noop + class C { + @(receivedName = super.name, noop) static accessor [(noop(), "p")]; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-property/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-property/options.json new file mode 100644 index 000000000000..98a9bacf3887 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-property/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + ["proposal-decorators", { "version": "2023-11" }], + "transform-class-static-block" + ], + "minNodeVersion": "12.0.0" +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-this/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-this/exec.js new file mode 100644 index 000000000000..d424d5679805 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-this/exec.js @@ -0,0 +1,61 @@ +{ + let receivedName; + function decFactory(name) { + receivedName = name; + return x => x; + } + class B { + static m() { + class C { + @decFactory(this.name) #p; + } + } + } + + B.m(); + expect(receivedName).toBe("B"); +} + +{ + let receivedLength; + function decFactory(length) { + receivedLength = length; + return x => x; + } + function noop() {} + class B { + static m() { + @noop + class C { + @decFactory(this.length) #p; + constructor(bar) {} + } + } + constructor(foo, bar) {} + } + + B.m(); + expect(receivedLength).toBe(2); +} + +{ + let receivedLength; + function decFactory(length) { + receivedLength = length; + return x => x; + } + function noop() {} + class B { + static m() { + @noop + class C { + @decFactory(this.length) static #p; + constructor(bar) {} + } + } + constructor(foo, bar) {} + } + + B.m(); + expect(receivedLength).toBe(2); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-this/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-this/options.json new file mode 100644 index 000000000000..98a9bacf3887 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-this/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + ["proposal-decorators", { "version": "2023-11" }], + "transform-class-static-block" + ], + "minNodeVersion": "12.0.0" +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/exec.js new file mode 100644 index 000000000000..8bb4769085bc --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/exec.js @@ -0,0 +1,66 @@ +{ + let B; + + class CaptureFactory { + static *id(fn) { + yield fn; + } + } + + function dummy() {} + + class A extends CaptureFactory { + static #X = "A#X"; + static *[Symbol.iterator] () { + B = class B { + static #X = "B#X"; + @(yield* super.id(_ => _.#X), dummy) method () {} + @(yield* super.id(_ => _.#X), dummy) static method () {} + @(yield* super.id(_ => _.#X), dummy) get getter () {} + @(yield* super.id(_ => _.#X), dummy) static get getter () {} + @(yield* super.id(_ => _.#X), dummy) set setter (v) {} + @(yield* super.id(_ => _.#X), dummy) static set setter (v) {} + @(yield* super.id(_ => _.#X), dummy) property; + @(yield* super.id(_ => _.#X), dummy) static property; + @(yield* super.id(_ => _.#X), dummy) accessor accessor; + @(yield* super.id(_ => _.#X), dummy) static accessor accessor; + } + } + } + + expect([...A].map(fn => fn(B)).join(",")).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); +} + +{ + let B; + + class CaptureFactory { + static *id(fn) { + yield fn; + } + } + + function dummy() {} + + class A extends CaptureFactory { + static #X = "A#X"; + static *[Symbol.iterator] () { + B = @dummy + class B { + static #X = "B#X"; + @(yield* super.id(_ => _.#X), dummy) method () {} + @(yield* super.id(_ => _.#X), dummy) static method () {} + @(yield* super.id(_ => _.#X), dummy) get getter () {} + @(yield* super.id(_ => _.#X), dummy) static get getter () {} + @(yield* super.id(_ => _.#X), dummy) set setter (v) {} + @(yield* super.id(_ => _.#X), dummy) static set setter (v) {} + @(yield* super.id(_ => _.#X), dummy) property; + @(yield* super.id(_ => _.#X), dummy) static property; + @(yield* super.id(_ => _.#X), dummy) accessor accessor; + @(yield* super.id(_ => _.#X), dummy) static accessor accessor; + } + } + } + + expect([...A].map(fn => fn(B)).join(",")).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/options.json new file mode 100644 index 000000000000..98a9bacf3887 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + ["proposal-decorators", { "version": "2023-11" }], + "transform-class-static-block" + ], + "minNodeVersion": "12.0.0" +} From 4ce976cf90b5dc04160dec53c2955c7a0d1641f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 4 Mar 2024 18:43:01 -0500 Subject: [PATCH 10/27] copy test cases to 2023-11-misc--to-es-2015 --- .../decorator-evaluation-arguments/exec.js | 54 ++++++ .../decorator-evaluation-new-target/exec.js | 54 ++++++ .../exec.js | 159 ++++++++++++++++++ .../decorator-evaluation-scope/exec.js | 12 -- .../exec.js | 159 ++++++++++++++++++ .../exec.js | 148 ++++++++++++++++ .../decorator-evaluation-this/exec.js | 61 +++++++ .../exec.js | 66 ++++++++ .../decorator-evaluation-yield/exec.js | 102 +++++++++++ 9 files changed, 803 insertions(+), 12 deletions(-) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-arguments/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-new-target/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-private-environment/exec.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-scope/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-super-getter-setter/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-super-property/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-this/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-yield-private-super-property/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-yield/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-arguments/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-arguments/exec.js new file mode 100644 index 000000000000..bb1cd1c259f4 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-arguments/exec.js @@ -0,0 +1,54 @@ +{ + let receivedArguments; + function decFactory(args) { + receivedArguments = args; + return x => x; + } + function B() { + class C { + @decFactory(arguments) #p; + } + } + + B(0); + expect(receivedArguments).toHaveLength(1); + expect(receivedArguments[0]).toBe(0); +} + +{ + function noop() {} + let receivedArguments; + function decFactory(args) { + receivedArguments = args; + return x => x; + } + function B() { + @noop + class C { + @decFactory(arguments) #p; + } + } + + B(0); + expect(receivedArguments).toHaveLength(1); + expect(receivedArguments[0]).toBe(0); +} + +{ + function noop() {} + let receivedArguments; + function decFactory(args) { + receivedArguments = args; + return x => x; + } + function B() { + @noop + class C { + @decFactory(arguments) static #p; + } + } + + B(0); + expect(receivedArguments).toHaveLength(1); + expect(receivedArguments[0]).toBe(0); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-new-target/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-new-target/exec.js new file mode 100644 index 000000000000..06643188b21c --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-new-target/exec.js @@ -0,0 +1,54 @@ +{ + let receivedNewTarget; + function decFactory(target) { + receivedNewTarget = target; + return x => x; + } + function B() { + class C { + @decFactory(new.target) #p; + } + } + + new B(); + + expect(receivedNewTarget).toBe(B); +} + +{ + function noop() {} + let receivedNewTarget; + function decFactory(target) { + receivedNewTarget = target; + return x => x; + } + function B() { + @noop + class C { + @decFactory(new.target) #p; + } + } + + new B(); + + expect(receivedNewTarget).toBe(B); +} + +{ + function noop() {} + let receivedNewTarget; + function decFactory(target) { + receivedNewTarget = target; + return x => x; + } + function B() { + @noop + class C { + @decFactory(new.target) static #p; + } + } + + new B(); + + expect(receivedNewTarget).toBe(B); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-private-environment/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-private-environment/exec.js new file mode 100644 index 000000000000..4ae3da714ae6 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-private-environment/exec.js @@ -0,0 +1,159 @@ +{ + let staticFns = [], fns = [] + let B; + + function capture(staticFn, fn) { + staticFns.push(staticFn); + fns.push(fn); + } + + function dummy() {} + + class A { + static #X = "A#X"; + #x = "a#x"; + constructor () { + B = class B { + static #X = "B#X"; + #x = "b#x"; + @(capture(_ => _.#X, _ => _.#x), dummy) method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) get getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static get getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) set setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) static set setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) property; + @(capture(_ => _.#X, _ => _.#x), dummy) static property; + @(capture(_ => _.#X, _ => _.#x), dummy) accessor accessor; + @(capture(_ => _.#X, _ => _.#x), dummy) static accessor accessor; + } + } + } + + let a = new A(), b = new B(); + + expect(staticFns.map(fn => fn(B)).join()).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); + expect(fns.map(fn => fn(b)).join()).toBe("b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x"); +} + +{ + let staticFns = [], fns = [] + let B; + + function capture(staticFn, fn) { + staticFns.push(staticFn); + fns.push(fn); + } + + function dummy() {} + + class A { + static #X = "A#X"; + #x = "a#x"; + constructor () { + B = class B { + static #X = "B#X"; + #x = "b#x"; + @(capture(_ => _.#X, _ => _.#x), dummy) #method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static #Method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) get #getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static get #Getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) set #setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) static set #Setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) #property; + @(capture(_ => _.#X, _ => _.#x), dummy) static #Property; + @(capture(_ => _.#X, _ => _.#x), dummy) accessor #accessor; + @(capture(_ => _.#X, _ => _.#x), dummy) static accessor #Accessor; + } + } + } + + let a = new A(), b = new B(); + + expect(staticFns.map(fn => fn(B)).join()).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); + expect(fns.map(fn => fn(b)).join()).toBe("b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x"); +} + +{ + let staticFns = [], fns = [] + let B; + + function capture(staticFn, fn) { + staticFns.push(staticFn); + fns.push(fn); + } + + function dummy() {} + + class A { + static #X = "A#X"; + #x = "a#x"; + constructor () { + B = + @(capture(_ => _.#X, _ => _.#x), dummy) + class B { + static #X = "B#X"; + #x = "b#x"; + @(capture(_ => _.#X, _ => _.#x), dummy) method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) get getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static get getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) set setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) static set setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) property; + @(capture(_ => _.#X, _ => _.#x), dummy) static property; + @(capture(_ => _.#X, _ => _.#x), dummy) accessor accessor; + @(capture(_ => _.#X, _ => _.#x), dummy) static accessor accessor; + } + } + } + + let a = new A(), b = new B(); + expect(staticFns.shift()(A)).toBe("A#X"); + expect(fns.shift()(a)).toBe("a#x"); + + expect(staticFns.map(fn => fn(B)).join()).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); + expect(fns.map(fn => fn(b)).join()).toBe("b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x"); +} + +{ + let staticFns = [], fns = [] + let B; + + function capture(staticFn, fn) { + staticFns.push(staticFn); + fns.push(fn); + } + + function dummy() {} + + class A { + static #X = "A#X"; + #x = "a#x"; + constructor () { + B = + @(capture(_ => _.#X, _ => _.#x), dummy) + class B { + static #X = "B#X"; + #x = "b#x"; + @(capture(_ => _.#X, _ => _.#x), dummy) #method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static #Method () {} + @(capture(_ => _.#X, _ => _.#x), dummy) get #getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) static get #Getter () {} + @(capture(_ => _.#X, _ => _.#x), dummy) set #setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) static set #Setter (v) {} + @(capture(_ => _.#X, _ => _.#x), dummy) #property; + @(capture(_ => _.#X, _ => _.#x), dummy) static #Property; + @(capture(_ => _.#X, _ => _.#x), dummy) accessor #accessor; + @(capture(_ => _.#X, _ => _.#x), dummy) static accessor #Accessor; + } + } + } + + let a = new A(), b = new B(); + expect(staticFns.shift()(A)).toBe("A#X"); + expect(fns.shift()(a)).toBe("a#x"); + + expect(staticFns.map(fn => fn(B)).join()).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); + expect(fns.map(fn => fn(b)).join()).toBe("b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x,b#x"); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-scope/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-scope/exec.js deleted file mode 100644 index ec8beb3b8cbf..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-scope/exec.js +++ /dev/null @@ -1,12 +0,0 @@ -let receivedName; -function decFactory(name) { receivedName = name; return x => x } -class B { - static m() { - class C { - @decFactory(this.name) p; - } - } -} - -B.m(); -expect(receivedName).toBe("B"); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-super-getter-setter/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-super-getter-setter/exec.js new file mode 100644 index 000000000000..816f371e0268 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-super-getter-setter/exec.js @@ -0,0 +1,159 @@ +function noop() {} + +function BaseFactory(logs) { + return class A { + static get getter() { + logs.push("getter") + } + static set setter(v) { + logs.push("setter"); + } + } +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + class C { + @(super.setter = super.getter, noop) p; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + class C { + @(super.setter = super.getter, noop) #p; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + class C { + @(super.setter = super.getter, noop) accessor [(noop(), "p")]; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + @noop + class C { + @(super.setter = super.getter, noop) p; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + @noop + class C { + @(super.setter = super.getter, noop) static p; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + @noop + class C { + @(super.setter = super.getter, noop) #p; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + @noop + class C { + @(super.setter = super.getter, noop) [(noop(), "p")]; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + @noop + class C { + @(super.setter = super.getter, noop) static [(noop(), "p")]; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + @noop + class C { + @(super.setter = super.getter, noop) accessor [(noop(), "p")]; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} + +{ + const logs = []; + class B extends BaseFactory(logs) { + static m() { + @noop + class C { + @(super.setter = super.getter, noop) static accessor [(noop(), "p")]; + } + } + } + + B.m(); + expect(logs.join()).toBe("getter,setter"); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-super-property/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-super-property/exec.js new file mode 100644 index 000000000000..2ba4461a451f --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-super-property/exec.js @@ -0,0 +1,148 @@ +function noop() {} + +{ + let receivedName; + class B extends class A {} { + static m() { + class C { + @(receivedName = super.name, noop) p; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + class C { + @(receivedName = super.name, noop) #p; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + class C { + @(receivedName = super.name, noop) accessor [(noop(), "p")]; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + @noop + class C { + @(receivedName = super.name, noop) p; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + @noop + class C { + @(receivedName = super.name, noop) static p; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + @noop + class C { + @(receivedName = super.name, noop) #p; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + @noop + class C { + @(receivedName = super.name, noop) [(noop(), "p")]; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + @noop + class C { + @(receivedName = super.name, noop) static [(noop(), "p")]; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + @noop + class C { + @(receivedName = super.name, noop) accessor [(noop(), "p")]; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} + +{ + let receivedName; + class B extends class A {} { + static m() { + @noop + class C { + @(receivedName = super.name, noop) static accessor [(noop(), "p")]; + } + } + } + + B.m(); + expect(receivedName).toBe("A"); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-this/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-this/exec.js new file mode 100644 index 000000000000..d424d5679805 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-this/exec.js @@ -0,0 +1,61 @@ +{ + let receivedName; + function decFactory(name) { + receivedName = name; + return x => x; + } + class B { + static m() { + class C { + @decFactory(this.name) #p; + } + } + } + + B.m(); + expect(receivedName).toBe("B"); +} + +{ + let receivedLength; + function decFactory(length) { + receivedLength = length; + return x => x; + } + function noop() {} + class B { + static m() { + @noop + class C { + @decFactory(this.length) #p; + constructor(bar) {} + } + } + constructor(foo, bar) {} + } + + B.m(); + expect(receivedLength).toBe(2); +} + +{ + let receivedLength; + function decFactory(length) { + receivedLength = length; + return x => x; + } + function noop() {} + class B { + static m() { + @noop + class C { + @decFactory(this.length) static #p; + constructor(bar) {} + } + } + constructor(foo, bar) {} + } + + B.m(); + expect(receivedLength).toBe(2); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-yield-private-super-property/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-yield-private-super-property/exec.js new file mode 100644 index 000000000000..8bb4769085bc --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-yield-private-super-property/exec.js @@ -0,0 +1,66 @@ +{ + let B; + + class CaptureFactory { + static *id(fn) { + yield fn; + } + } + + function dummy() {} + + class A extends CaptureFactory { + static #X = "A#X"; + static *[Symbol.iterator] () { + B = class B { + static #X = "B#X"; + @(yield* super.id(_ => _.#X), dummy) method () {} + @(yield* super.id(_ => _.#X), dummy) static method () {} + @(yield* super.id(_ => _.#X), dummy) get getter () {} + @(yield* super.id(_ => _.#X), dummy) static get getter () {} + @(yield* super.id(_ => _.#X), dummy) set setter (v) {} + @(yield* super.id(_ => _.#X), dummy) static set setter (v) {} + @(yield* super.id(_ => _.#X), dummy) property; + @(yield* super.id(_ => _.#X), dummy) static property; + @(yield* super.id(_ => _.#X), dummy) accessor accessor; + @(yield* super.id(_ => _.#X), dummy) static accessor accessor; + } + } + } + + expect([...A].map(fn => fn(B)).join(",")).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); +} + +{ + let B; + + class CaptureFactory { + static *id(fn) { + yield fn; + } + } + + function dummy() {} + + class A extends CaptureFactory { + static #X = "A#X"; + static *[Symbol.iterator] () { + B = @dummy + class B { + static #X = "B#X"; + @(yield* super.id(_ => _.#X), dummy) method () {} + @(yield* super.id(_ => _.#X), dummy) static method () {} + @(yield* super.id(_ => _.#X), dummy) get getter () {} + @(yield* super.id(_ => _.#X), dummy) static get getter () {} + @(yield* super.id(_ => _.#X), dummy) set setter (v) {} + @(yield* super.id(_ => _.#X), dummy) static set setter (v) {} + @(yield* super.id(_ => _.#X), dummy) property; + @(yield* super.id(_ => _.#X), dummy) static property; + @(yield* super.id(_ => _.#X), dummy) accessor accessor; + @(yield* super.id(_ => _.#X), dummy) static accessor accessor; + } + } + } + + expect([...A].map(fn => fn(B)).join(",")).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-yield/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-yield/exec.js new file mode 100644 index 000000000000..28bfbb4bc84b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-yield/exec.js @@ -0,0 +1,102 @@ +const noop = () => {}; +{ + const log = { + *[Symbol.iterator]() { + + class Foo { + @(yield 1, noop) method() {} + @(yield 2, noop) static method() {} + @(yield 3, noop) field; + @(yield 4, noop) static field; + @(yield 5, noop) get getter() { + return; + } + @(yield 6, noop) static get getter() { + return; + } + @(yield 7, noop) set setter(x) {} + @(yield 8, noop) static set setter(x) {} + @(yield 9, noop) accessor accessor; + @(yield 10, noop) static accessor accessor; + } + }, + }; + expect([...log].join()).toBe("1,2,3,4,5,6,7,8,9,10"); +} +{ + let Foo; + const log = { + *[Symbol.iterator]() { + + Foo = class { + @(yield 0, noop) [(yield 1, "method")]() {} + @(yield 2, noop) static method() {} + @(yield 3, noop) field; + @(yield 4, noop) static field; + @(yield 5, noop) get getter() { + return; + } + @(yield 6, noop) static get getter() { + return; + } + @(yield 7, noop) set setter(x) {} + @(yield 8, noop) static set setter(x) {} + @(yield 9, noop) accessor accessor; + @(yield 10, noop) static accessor accessor; + } + }, + }; + expect([...log].join()).toBe("0,1,2,3,4,5,6,7,8,9,10"); + expect((new Foo())).toHaveProperty("method"); +} +{ + const log = { + *[Symbol.iterator]() { + @(yield 0, noop) + class Foo { + @(yield 1, noop) method() {} + @(yield 2, noop) static method() {} + @(yield 3, noop) field; + @(yield 4, noop) static field; + @(yield 5, noop) get getter() { + return; + } + @(yield 6, noop) static get getter() { + return; + } + @(yield 7, noop) set setter(x) {} + @(yield 8, noop) static set setter(x) {} + @(yield 9, noop) accessor accessor; + @(yield 10, noop) static accessor accessor; + } + }, + }; + expect([...log].join()).toBe("0,1,2,3,4,5,6,7,8,9,10"); +} + +{ + let Foo; + const log = { + *[Symbol.iterator]() { + Foo = @(yield 0, noop) + class { + @(yield 1, noop) method() {} + @(yield 2, noop) static method() {} + @(yield 3, noop) field; + @(yield 4, noop) static field; + @(yield 5, noop) get getter() { + return; + } + @(yield 6, noop) static get getter() { + return; + } + @(yield 7, noop) set setter(x) {} + @(yield 8, noop) static set setter(x) {} + @(yield 9, noop) accessor accessor; + @(yield 10, noop) static accessor [(yield 11, "accessor")]; + } + }, + }; + expect([...log].join()).toBe("0,1,2,3,4,5,6,7,8,9,10,11"); + expect(Foo).toHaveProperty("accessor"); +} From 713ad4cd284144081773e669ce6784ef3f69f510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 4 Mar 2024 19:07:55 -0500 Subject: [PATCH 11/27] update test outputs --- .../context-name/output.js | 3 +- .../2021-12-accessors/context-name/output.js | 6 +- .../expressions-static-blocks/output.js | 64 +++------- .../initializers/output.js | 19 +-- .../output.js | 27 ++-- .../replacement-static-this/output.js | 11 +- .../replacement/output.js | 11 +- .../expressions-static-blocks/output.js | 96 ++++++-------- .../2021-12-classes/initializers/output.js | 20 ++- .../output.js | 24 ++-- .../replacement-static-this/output.js | 10 +- .../2021-12-classes/replacement/output.js | 10 +- .../computed-keys-same-ast/output.js | 3 +- .../computed-keys-same-value/output.js | 3 +- .../computed-keys-same-ast/output.js | 9 +- .../computed-keys-same-value/output.js | 9 +- .../member-decorator/output.mjs | 2 +- .../context-name/output.js | 3 +- .../2021-12-fields/context-name/output.js | 6 +- .../context-name/output.js | 3 +- .../2021-12-getters/context-name/output.js | 6 +- .../context-name/output.js | 3 +- .../2021-12-methods/context-name/output.js | 6 +- .../output.js | 6 +- .../valid-expression-formats/output.js | 15 ++- .../2021-12-misc/all-decorators/output.js | 114 ++++++++--------- .../output.js | 4 +- .../output.js | 16 ++- .../valid-expression-formats/output.js | 7 +- .../context-name/output.js | 3 +- .../2021-12-setters/context-name/output.js | 6 +- .../context-name/output.js | 3 +- .../2022-03-accessors/context-name/output.js | 6 +- .../expressions-static-blocks/output.js | 64 +++------- .../initializers/output.js | 19 +-- .../output.js | 27 ++-- .../replacement-static-this/output.js | 11 +- .../replacement/output.js | 11 +- .../expressions-static-blocks/output.js | 96 ++++++-------- .../2022-03-classes/initializers/output.js | 20 ++- .../output.js | 24 ++-- .../replacement-static-this/output.js | 10 +- .../2022-03-classes/replacement/output.js | 10 +- .../computed-keys-same-ast/output.js | 3 +- .../computed-keys-same-value/output.js | 3 +- .../computed-keys-same-ast/output.js | 9 +- .../computed-keys-same-value/output.js | 9 +- .../member-decorator/output.mjs | 2 +- .../context-name/output.js | 3 +- .../2022-03-fields/context-name/output.js | 6 +- .../context-name/output.js | 3 +- .../2022-03-getters/context-name/output.js | 6 +- .../context-name/output.js | 3 +- .../2022-03-methods/context-name/output.js | 6 +- .../output.js | 23 ++-- .../valid-expression-formats/output.js | 21 +-- .../2022-03-misc/all-decorators/output.js | 120 +++++++++--------- .../output.js | 4 +- .../output.js | 16 ++- .../valid-expression-formats/output.js | 7 +- .../context-name/output.js | 3 +- .../2022-03-setters/context-name/output.js | 6 +- .../context-name/output.js | 3 +- .../2023-01-accessors/context-name/output.js | 6 +- .../expressions-static-blocks/output.js | 64 +++------- .../initializers/output.js | 19 +-- .../output.js | 27 ++-- .../replacement-static-this/output.js | 11 +- .../replacement/output.js | 11 +- .../expressions-static-blocks/output.js | 96 ++++++-------- .../2023-01-classes/initializers/output.js | 20 ++- .../output.js | 24 ++-- .../replacement-static-this/output.js | 10 +- .../2023-01-classes/replacement/output.js | 10 +- .../computed-keys-same-ast/output.js | 3 +- .../computed-keys-same-value/output.js | 3 +- .../computed-keys-same-ast/output.js | 9 +- .../computed-keys-same-value/output.js | 9 +- .../member-decorator/output.mjs | 2 +- .../context-name/output.js | 3 +- .../2023-01-fields/context-name/output.js | 6 +- .../context-name/output.js | 3 +- .../2023-01-getters/context-name/output.js | 6 +- .../context-name/output.js | 3 +- .../2023-01-methods/context-name/output.js | 6 +- .../output.js | 23 ++-- .../valid-expression-formats/output.js | 21 +-- .../2023-01-misc/all-decorators/output.js | 88 +++++++------ .../output.js | 4 +- .../output.js | 16 ++- .../valid-expression-formats/output.js | 7 +- .../context-name/output.js | 3 +- .../2023-01-setters/context-name/output.js | 6 +- .../context-name/output.js | 3 +- .../2023-05-accessors/context-name/output.js | 6 +- .../expressions-static-blocks/output.js | 64 +++------- .../initializers/output.js | 19 +-- .../output.js | 27 ++-- .../replacement-static-this/output.js | 11 +- .../replacement/output.js | 11 +- .../expressions-static-blocks/output.js | 96 ++++++-------- .../2023-05-classes/initializers/output.js | 20 ++- .../output.js | 24 ++-- .../replacement-static-this/output.js | 10 +- .../2023-05-classes/replacement/output.js | 10 +- .../computed-keys-same-ast/output.js | 3 +- .../computed-keys-same-value/output.js | 3 +- .../computed-keys-same-ast/output.js | 9 +- .../computed-keys-same-value/output.js | 9 +- .../member-decorator/output.mjs | 2 +- .../context-name/output.js | 3 +- .../2023-05-fields/context-name/output.js | 6 +- .../context-name/output.js | 3 +- .../2023-05-getters/context-name/output.js | 6 +- .../context-name/output.js | 3 +- .../2023-05-methods/context-name/output.js | 6 +- .../output.js | 23 ++-- .../super-in-decorator/output.js | 19 ++- .../2023-05-misc--to-es2015/this/output.js | 13 +- .../valid-expression-formats/output.js | 21 +-- .../2023-05-misc/all-decorators/output.js | 88 +++++++------ .../output.js | 4 +- .../output.js | 16 ++- .../2023-05-misc/super-in-decorator/output.js | 9 +- .../test/fixtures/2023-05-misc/this/output.js | 3 +- .../valid-expression-formats/output.js | 7 +- .../initializers-and-static-blocks/output.js | 84 ++++++------ .../initializers-and-static-blocks/output.js | 76 ++++++----- .../context-name/output.js | 3 +- .../2023-05-setters/context-name/output.js | 6 +- .../context-name/output.js | 3 +- .../2023-11-accessors/context-name/output.js | 6 +- .../expressions-static-blocks/output.js | 64 +++------- .../initializers/output.js | 19 +-- .../output.js | 43 +++---- .../output.js | 27 ++-- .../replacement-static-this/output.js | 11 +- .../replacement/output.js | 11 +- .../expressions-static-blocks/output.js | 96 ++++++-------- .../2023-11-classes/initializers/output.js | 20 ++- .../output.js | 36 +++--- .../output.js | 24 ++-- .../replacement-static-this/output.js | 10 +- .../2023-11-classes/replacement/output.js | 10 +- .../computed-keys-same-ast/output.js | 3 +- .../computed-keys-same-value/output.js | 3 +- .../computed-keys-same-ast/output.js | 9 +- .../computed-keys-same-value/output.js | 9 +- .../context-name/output.js | 3 +- .../2023-11-fields/context-name/output.js | 6 +- .../context-name/output.js | 3 +- .../2023-11-getters/context-name/output.js | 6 +- .../context-name/output.js | 3 +- .../2023-11-methods/context-name/output.js | 6 +- .../output.js | 21 +-- .../private-name-in-class-decorator/output.js | 11 +- .../super-in-decorator/output.js | 5 +- .../valid-expression-formats/output.js | 5 +- .../2023-11-misc/all-decorators/output.js | 94 +++++++------- .../output.js | 15 +-- .../private-name-in-class-decorator/output.js | 10 +- .../2023-11-misc/super-in-decorator/output.js | 3 +- .../valid-expression-formats/output.js | 4 +- .../output.js | 23 ++-- .../context-name/output.js | 3 +- .../2023-11-setters/context-name/output.js | 6 +- .../super-call-in-decorator/output.js | 5 +- .../super-property-in-accessor-key/output.js | 12 +- 168 files changed, 1357 insertions(+), 1618 deletions(-) diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/context-name/output.js index 14951fe8c644..7e916e936855 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7, _Foo; +let _computedKey; +var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/context-name/output.js index 6f69deb83763..21a2442a54ce 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7; +let _computedKey; +var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7, _initStatic] = babelHelpers.applyDecs(this, [[dec, 6, "a"], [dec, 6, "a", function () { @@ -76,7 +76,7 @@ class Foo { this.#H = v; } static #I = _init_computedKey7(this); - static get [_computedKey]() { + static get [_computedKey = babelHelpers.toPropertyKey(f())]() { return this.#I; } static set [_computedKey](v) { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/expressions-static-blocks/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/expressions-static-blocks/output.js index 54e0f1088e53..f0a1d7a3ad44 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/expressions-static-blocks/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/expressions-static-blocks/output.js @@ -1,73 +1,51 @@ -var _initClass, _A, _temp, _initClass2, _C, _temp2, _initClass3, _D, _temp3, _initClass4, _decorated_class, _temp4, _Class2, _initClass5, _G, _temp5, _initClass6, _decorated_class2, _temp6, _Class3, _initClass7, _H, _temp7, _initClass8, _K, _temp8; +let _A2, _C2, _D2, _ref, _G2, _ref2, _H2, _K2; +var _initClass, _A, _Class, _A3, _initClass2, _C, _Class2, _C3, _initClass3, _D, _Class3, _D3, _initClass4, _decorated_class, _Class4, _Class5, _initClass5, _G, _Class6, _G3, _initClass6, _decorated_class2, _Class7, _Class8, _initClass7, _H, _Class9, _H3, _initClass8, _K, _Class10, _K3; const dec = () => {}; -const A = (new (_temp = class extends babelHelpers.identity { +const A = (new (_A2 = (_A3 = class A {}, [_A, _initClass] = babelHelpers.applyDecs(_A3, [], [dec]), _A3), (_Class = class extends babelHelpers.identity { constructor() { super(_A), (() => {})(), _initClass(); } -}, (_A2 => { - class A {} - _A2 = A; - [_A, _initClass] = babelHelpers.applyDecs(_A2, [], [dec]); -})(), _temp)(), _A); -const B = (new (_temp2 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class, _A2, void 0), _Class))(), _A); +const B = (new (_C2 = (_C3 = class C {}, [_C, _initClass2] = babelHelpers.applyDecs(_C3, [], [dec]), _C3), (_Class2 = class extends babelHelpers.identity { constructor() { super(_C), (() => {})(), _initClass2(); } -}, (_C2 => { - class C {} - _C2 = C; - [_C, _initClass2] = babelHelpers.applyDecs(_C2, [], [dec]); -})(), _temp2)(), _C); -const D = (new (_temp3 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class2, _C2, void 0), _Class2))(), _C); +const D = (new (_D2 = (_D3 = class D {}, [_D, _initClass3] = babelHelpers.applyDecs(_D3, [], [dec]), _D3), (_Class3 = class extends babelHelpers.identity { constructor() { super(_D), (() => {})(), _initClass3(); } -}, (_D2 => { - class D {} - _D2 = D; - [_D, _initClass3] = babelHelpers.applyDecs(_D2, [], [dec]); -})(), _temp3)(), _D); -const E = ((new (_temp4 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class3, _D2, void 0), _Class3))(), _D); +const E = ((new (_ref = (_Class5 = class _ref {}, [_decorated_class, _initClass4] = babelHelpers.applyDecs(_Class5, [], [dec]), _Class5), (_Class4 = class extends babelHelpers.identity { constructor() { super(_decorated_class), (() => {})(), _initClass4(); } -}, (_Class2 = class {}, [_decorated_class, _initClass4] = babelHelpers.applyDecs(_Class2, [], [dec])), _temp4)(), _decorated_class), 123); -const F = [(new (_temp5 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class4, _ref, void 0), _Class4))(), _decorated_class), 123); +const F = [(new (_G2 = (_G3 = class G {}, [_G, _initClass5] = babelHelpers.applyDecs(_G3, [], [dec]), _G3), (_Class6 = class extends babelHelpers.identity { constructor() { super(_G), (() => {})(), _initClass5(); } -}, (_G2 => { - class G {} - _G2 = G; - [_G, _initClass5] = babelHelpers.applyDecs(_G2, [], [dec]); -})(), _temp5)(), _G), (new (_temp6 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class6, _G2, void 0), _Class6))(), _G), (new (_ref2 = (_Class8 = class _ref2 {}, [_decorated_class2, _initClass6] = babelHelpers.applyDecs(_Class8, [], [dec]), _Class8), (_Class7 = class extends babelHelpers.identity { constructor() { super(_decorated_class2), (() => {})(), _initClass6(); } -}, (_Class3 = class {}, [_decorated_class2, _initClass6] = babelHelpers.applyDecs(_Class3, [], [dec])), _temp6)(), _decorated_class2)]; -const H = (new (_temp7 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class7, _ref2, void 0), _Class7))(), _decorated_class2)]; +const H = (new (_H2 = (_H3 = class H extends I {}, [_H, _initClass7] = babelHelpers.applyDecs(_H3, [], [dec]), _H3), (_Class9 = class extends babelHelpers.identity { constructor() { super(_H), (() => {})(), _initClass7(); } -}, (_H2 => { - class H extends I {} - _H2 = H; - [_H, _initClass7] = babelHelpers.applyDecs(_H2, [], [dec]); -})(), _temp7)(), _H); -const J = (new (_temp8 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class9, _H2, void 0), _Class9))(), _H); +const J = (new (_K2 = (_K3 = class K extends L {}, [_K, _initClass8] = babelHelpers.applyDecs(_K3, [], [dec]), _K3), (_Class10 = class extends babelHelpers.identity { constructor() { super(_K), (() => {})(), _initClass8(); } -}, (_K2 => { - class K extends L {} - _K2 = K; - [_K, _initClass8] = babelHelpers.applyDecs(_K2, [], [dec]); -})(), _temp8)(), _K); +}, babelHelpers.defineProperty(_Class10, _K2, void 0), _Class10))(), _K); function classFactory() { - var _initClass9, _decorated_class3, _temp9, _Class5; - return new (_temp9 = class extends babelHelpers.identity { + let _ref3; + var _initClass9, _decorated_class3, _Class11, _Class12; + return new (_ref3 = (_Class12 = class _ref3 {}, [_decorated_class3, _initClass9] = babelHelpers.applyDecs(_Class12, [], [dec]), _Class12), (_Class11 = class extends babelHelpers.identity { constructor() { super(_decorated_class3), (() => {})(), _initClass9(); } - }, (_Class5 = class {}, [_decorated_class3, _initClass9] = babelHelpers.applyDecs(_Class5, [], [dec])), _temp9)(), _decorated_class3; + }, babelHelpers.defineProperty(_Class11, _ref3, void 0), _Class11))(), _decorated_class3; } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js index da6d41d72d30..2c414327b3ce 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js @@ -1,24 +1,17 @@ -var _initClass, _temp, _initClass2, _temp2; +let _Foo2, _Bar2; +var _initClass, _Class, _Foo3, _initClass2, _Class2, _Bar3; const dec = () => {}; let _Foo; -new (_temp = class extends babelHelpers.identity { +new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs(_Foo3, [], [dec]), _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "field", 123)), _initClass(); } -}, (_Foo2 => { - class Foo {} - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs(_Foo2, [], [dec]); -})(), _temp)(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); let _Bar; -new (_temp2 = class extends babelHelpers.identity { +new (_Bar2 = (_Bar3 = class Bar extends _Foo {}, [_Bar, _initClass2] = babelHelpers.applyDecs(_Bar3, [], [dec]), _Bar3), (_Class2 = class extends babelHelpers.identity { constructor() { (super(_Bar), babelHelpers.defineProperty(this, "field", ((() => { this.otherField = 456; })(), 123))), _initClass2(); } -}, (_Bar2 => { - class Bar extends _Foo {} - _Bar2 = Bar; - [_Bar, _initClass2] = babelHelpers.applyDecs(_Bar2, [], [dec]); -})(), _temp2)(); +}, babelHelpers.defineProperty(_Class2, _Bar2, void 0), _Class2))(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js index ed917ac13c8a..f4bef9d17933 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js @@ -1,8 +1,17 @@ -var _initClass, _x, _A, _Class_brand, _B, _temp; +let _Foo2; +var _initClass, _Class, _x, _A, _Class_brand, _B, _Foo3; const dec = () => {}; let hasX, hasA, hasM; let _Foo; -new (_x = /*#__PURE__*/new WeakMap(), _A = /*#__PURE__*/new WeakMap(), _Class_brand = /*#__PURE__*/new WeakSet(), _B = /*#__PURE__*/new WeakMap(), (_temp = class extends babelHelpers.identity { +new (_x = /*#__PURE__*/new WeakMap(), _A = /*#__PURE__*/new WeakMap(), _Class_brand = /*#__PURE__*/new WeakSet(), _B = /*#__PURE__*/new WeakMap(), _Foo2 = (_Foo3 = class Foo { + static get a() { + return babelHelpers.classPrivateFieldGet2(_B, this); + } + static set a(v) { + babelHelpers.classPrivateFieldSet2(_B, this, v); + } + static m() {} +}, [_Foo, _initClass] = babelHelpers.applyDecs(_Foo3, [], [dec]), _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.classPrivateMethodInitSpec(this, _Class_brand), babelHelpers.classPrivateFieldInitSpec(this, _x, void 0), babelHelpers.classPrivateFieldInitSpec(this, _A, void 0), babelHelpers.defineProperty(this, "x", void 0), babelHelpers.classPrivateFieldInitSpec(this, _B, void 0), this), (() => { hasX = o => _x.has(babelHelpers.checkInRHS(o)); @@ -10,19 +19,7 @@ new (_x = /*#__PURE__*/new WeakMap(), _A = /*#__PURE__*/new WeakMap(), _Class_br hasM = o => _Class_brand.has(babelHelpers.checkInRHS(o)); })(), _initClass(); } -}, (_Foo2 => { - class Foo { - static get a() { - return babelHelpers.classPrivateFieldGet2(_B, this); - } - static set a(v) { - babelHelpers.classPrivateFieldSet2(_B, this, v); - } - static m() {} - } - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs(_Foo2, [], [dec]); -})(), _temp))(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); function _get_a(_this) { return babelHelpers.classPrivateFieldGet2(_A, _this); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/output.js index 43ad6f8c19b3..14e3049076f3 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/output.js @@ -1,7 +1,8 @@ -var _initClass, _temp; +let _Foo2; +var _initClass, _Class, _Foo3; const dec = () => {}; let _Foo; -new (_temp = class extends babelHelpers.identity { +new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs(_Foo3, [], [dec]), _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "field", ((() => { this; @@ -9,8 +10,4 @@ new (_temp = class extends babelHelpers.identity { this; })(), _initClass(); } -}, (_Foo2 => { - class Foo {} - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs(_Foo2, [], [dec]); -})(), _temp)(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js index e99e938833e0..07c31f214389 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js @@ -1,13 +1,10 @@ -var _initClass, _temp; +let _Foo2; +var _initClass, _Class, _Foo3; const dec = () => {}; let _Foo; -new (_temp = class extends babelHelpers.identity { +new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs(_Foo3, [], [dec]), _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "foo", new _Foo())), _initClass(); } -}, (_Foo2 => { - class Foo {} - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs(_Foo2, [], [dec]); -})(), _temp)(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); const foo = new _Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions-static-blocks/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions-static-blocks/output.js index 78b36106c247..3a212c80a7ab 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions-static-blocks/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions-static-blocks/output.js @@ -1,96 +1,80 @@ var _initClass, _A, _initClass2, _C, _initClass3, _D, _initClass4, _decorated_class, _initClass5, _G, _initClass6, _decorated_class2, _initClass7, _H, _initClass8, _K; const dec = () => {}; const A = (new class extends babelHelpers.identity { - static { - class A { - static { - [_A, _initClass] = babelHelpers.applyDecs(this, [], [dec]); - } + static [class A { + static { + [_A, _initClass] = babelHelpers.applyDecs(this, [], [dec]); } - } + }]; constructor() { super(_A), (() => {})(), _initClass(); } }(), _A); const B = (new class extends babelHelpers.identity { - static { - class C { - static { - [_C, _initClass2] = babelHelpers.applyDecs(this, [], [dec]); - } + static [class C { + static { + [_C, _initClass2] = babelHelpers.applyDecs(this, [], [dec]); } - } + }]; constructor() { super(_C), (() => {})(), _initClass2(); } }(), _C); const D = (new class extends babelHelpers.identity { - static { - class D { - static { - [_D, _initClass3] = babelHelpers.applyDecs(this, [], [dec]); - } + static [class D { + static { + [_D, _initClass3] = babelHelpers.applyDecs(this, [], [dec]); } - } + }]; constructor() { super(_D), (() => {})(), _initClass3(); } }(), _D); const E = ((new class extends babelHelpers.identity { - static { - (class { - static { - [_decorated_class, _initClass4] = babelHelpers.applyDecs(this, [], [dec]); - } - }); - } + static [class { + static { + [_decorated_class, _initClass4] = babelHelpers.applyDecs(this, [], [dec]); + } + }]; constructor() { super(_decorated_class), (() => {})(), _initClass4(); } }(), _decorated_class), 123); const F = [(new class extends babelHelpers.identity { - static { - class G { - static { - [_G, _initClass5] = babelHelpers.applyDecs(this, [], [dec]); - } + static [class G { + static { + [_G, _initClass5] = babelHelpers.applyDecs(this, [], [dec]); } - } + }]; constructor() { super(_G), (() => {})(), _initClass5(); } }(), _G), (new class extends babelHelpers.identity { - static { - (class { - static { - [_decorated_class2, _initClass6] = babelHelpers.applyDecs(this, [], [dec]); - } - }); - } + static [class { + static { + [_decorated_class2, _initClass6] = babelHelpers.applyDecs(this, [], [dec]); + } + }]; constructor() { super(_decorated_class2), (() => {})(), _initClass6(); } }(), _decorated_class2)]; const H = (new class extends babelHelpers.identity { - static { - class H extends I { - static { - [_H, _initClass7] = babelHelpers.applyDecs(this, [], [dec]); - } + static [class H extends I { + static { + [_H, _initClass7] = babelHelpers.applyDecs(this, [], [dec]); } - } + }]; constructor() { super(_H), (() => {})(), _initClass7(); } }(), _H); const J = (new class extends babelHelpers.identity { - static { - class K extends L { - static { - [_K, _initClass8] = babelHelpers.applyDecs(this, [], [dec]); - } + static [class K extends L { + static { + [_K, _initClass8] = babelHelpers.applyDecs(this, [], [dec]); } - } + }]; constructor() { super(_K), (() => {})(), _initClass8(); } @@ -98,13 +82,11 @@ const J = (new class extends babelHelpers.identity { function classFactory() { var _initClass9, _decorated_class3; return new class extends babelHelpers.identity { - static { - (class { - static { - [_decorated_class3, _initClass9] = babelHelpers.applyDecs(this, [], [dec]); - } - }); - } + static [class { + static { + [_decorated_class3, _initClass9] = babelHelpers.applyDecs(this, [], [dec]); + } + }]; constructor() { super(_decorated_class3), (() => {})(), _initClass9(); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js index f38ad2258dd9..a68f64d2dc4c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js @@ -2,13 +2,11 @@ var _initClass, _initClass2; const dec = () => {}; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); - } + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); } - } + }]; field = 123; constructor() { super(_Foo), _initClass(); @@ -16,13 +14,11 @@ new class extends babelHelpers.identity { }(); let _Bar; new class extends babelHelpers.identity { - static { - class Bar extends _Foo { - static { - [_Bar, _initClass2] = babelHelpers.applyDecs(this, [], [dec]); - } + static [class Bar extends _Foo { + static { + [_Bar, _initClass2] = babelHelpers.applyDecs(this, [], [dec]); } - } + }]; field = ((() => { this.otherField = 456; })(), 123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-installed-on-correct-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-installed-on-correct-class/output.js index b16ebb864d77..dabb5776cd9c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-installed-on-correct-class/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-installed-on-correct-class/output.js @@ -3,20 +3,18 @@ const dec = () => {}; let hasX, hasA, hasM; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); - } - static get a() { - return this.#B; - } - static set a(v) { - this.#B = v; - } - static m() {} + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); } - } + static get a() { + return this.#B; + } + static set a(v) { + this.#B = v; + } + static m() {} + }]; #x; #A; get #a() { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-this/output.js index 6be9f640e0c0..148cccaad54a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-this/output.js @@ -2,13 +2,11 @@ var _initClass; const dec = () => {}; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); - } + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); } - } + }]; field = ((() => { this; })(), this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js index a036e5112123..3b1b8b4ff64e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js @@ -2,13 +2,11 @@ var _initClass; const dec = () => {}; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); - } + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); } - } + }]; foo = new _Foo(); constructor() { super(_Foo), _initClass(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-ast/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-ast/output.js index 3e0dc59b4b72..5b7a236b524d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-ast/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-ast/output.js @@ -1,4 +1,5 @@ -var _initProto, _computedKey, _computedKey2, _Foo; +let _computedKey, _computedKey2; +var _initProto, _Foo; const dec = () => {}; _computedKey = babelHelpers.toPropertyKey(getKey()); _computedKey2 = babelHelpers.toPropertyKey(getKey()); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-value/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-value/output.js index 5c6fcc9b509a..b1827ee535aa 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-value/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-value/output.js @@ -1,4 +1,5 @@ -var _initProto, _computedKey, _computedKey2, _Foo; +let _computedKey, _computedKey2; +var _initProto, _Foo; const dec = () => {}; _computedKey = babelHelpers.toPropertyKey(getKeyI()); _computedKey2 = babelHelpers.toPropertyKey(getKeyJ()); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/output.js index 3ab03ded6f83..c2f715c02a75 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/output.js @@ -1,7 +1,6 @@ -var _initProto, _computedKey, _computedKey2; +let _computedKey, _computedKey2; +var _initProto; const dec = () => {}; -_computedKey = babelHelpers.toPropertyKey(getKey()); -_computedKey2 = babelHelpers.toPropertyKey(getKey()); class Foo { static { [_initProto] = babelHelpers.applyDecs(this, [[dec, 2, _computedKey], [dec, 2, _computedKey2]], []); @@ -9,10 +8,10 @@ class Foo { constructor() { _initProto(this); } - [_computedKey]() { + [_computedKey = babelHelpers.toPropertyKey(getKey())]() { return 1; } - [_computedKey2]() { + [_computedKey2 = babelHelpers.toPropertyKey(getKey())]() { return 2; } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/output.js index 024d2419eab8..3230847a90d1 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/output.js @@ -1,7 +1,6 @@ -var _initProto, _computedKey, _computedKey2; +let _computedKey, _computedKey2; +var _initProto; const dec = () => {}; -_computedKey = babelHelpers.toPropertyKey(getKeyI()); -_computedKey2 = babelHelpers.toPropertyKey(getKeyJ()); class Foo { static { [_initProto] = babelHelpers.applyDecs(this, [[dec, 2, _computedKey], [dec, 2, _computedKey2]], []); @@ -9,10 +8,10 @@ class Foo { constructor() { _initProto(this); } - [_computedKey]() { + [_computedKey = babelHelpers.toPropertyKey(getKeyI())]() { return 1; } - [_computedKey2]() { + [_computedKey2 = babelHelpers.toPropertyKey(getKeyJ())]() { return 2; } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-exported/member-decorator/output.mjs b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-exported/member-decorator/output.mjs index 7f95c08c468e..fb2ee3bd4895 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-exported/member-decorator/output.mjs +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-exported/member-decorator/output.mjs @@ -1,7 +1,7 @@ var _xDecs, _init_x; -_xDecs = dec; export class A { static { + _xDecs = dec; [_init_x] = babelHelpers.applyDecs(this, [[_xDecs, 0, "x"]], []); } x = _init_x(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/context-name/output.js index 981c5d83f1a3..836024f1e52f 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7, _Foo; +let _computedKey; +var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/context-name/output.js index 3c280bcd499a..0c69bf628485 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/context-name/output.js @@ -1,4 +1,5 @@ -var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7; +let _computedKey; +var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7] = babelHelpers.applyDecs(this, [[dec, 5, "a"], [dec, 5, "a", function () { @@ -26,6 +26,6 @@ class Foo { static [1] = _init_computedKey4(this); static 2n = _init_computedKey5(this); static [3n] = _init_computedKey6(this); - static [_computedKey] = _init_computedKey7(this); + static [_computedKey = babelHelpers.toPropertyKey(f())] = _init_computedKey7(this); } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/context-name/output.js index 4de670684201..988a0aec1736 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey, _Foo; +let _computedKey; +var _initStatic, _call_a, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/context-name/output.js index f179bd05d42b..fad707ea2c17 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey; +let _computedKey; +var _initStatic, _call_a; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs(this, [[dec, 8, "a"], [dec, 8, "a", function () {}], [dec, 8, "b"], [dec, 8, "c"], [dec, 8, 0], [dec, 8, 1], [dec, 8, 2n], [dec, 8, 3n], [dec, 8, _computedKey]], []); @@ -25,6 +25,6 @@ class Foo { static get [1]() {} static get 2n() {} static get [3n]() {} - static get [_computedKey]() {} + static get [_computedKey = babelHelpers.toPropertyKey(f())]() {} } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/context-name/output.js index 0669b1297661..40a3a79f7efa 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey, _Foo; +let _computedKey; +var _initStatic, _call_a, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/context-name/output.js index 85a6674d0434..116b71fa7f77 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey; +let _computedKey; +var _initStatic, _call_a; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs(this, [[dec, 7, "a"], [dec, 7, "a", function () {}], [dec, 7, "b"], [dec, 7, "c"], [dec, 7, 0], [dec, 7, 1], [dec, 7, 2n], [dec, 7, 3n], [dec, 7, _computedKey]], []); @@ -23,6 +23,6 @@ class Foo { static [1]() {} static 2n() {} static [3n]() {} - static [_computedKey]() {} + static [_computedKey = babelHelpers.toPropertyKey(f())]() {} } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/output.js index 84206743a250..878afee02c0c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/output.js @@ -1,6 +1,5 @@ var _initProto, _methodDecs, _A; const dec = () => {}; -_methodDecs = deco; class A extends B { constructor() { let a = 2; @@ -10,4 +9,7 @@ class A extends B { method() {} } _A = A; -[_initProto] = babelHelpers.applyDecs(_A, [[_methodDecs, 2, "method"]], []); +(() => { + _methodDecs = deco; + [_initProto] = babelHelpers.applyDecs(_A, [[_methodDecs, 2, "method"]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js index 1679c5130c26..70f8fe77d4c3 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js @@ -1,7 +1,6 @@ var _initProto, _initClass, _classDecs, _methodDecs, _Foo2; const dec = () => {}; _classDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; -_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; let _Foo; var _a = /*#__PURE__*/new WeakMap(); class Foo { @@ -10,14 +9,20 @@ class Foo { } method() {} makeClass() { - var _barDecs, _init_bar, _Nested; - return _barDecs = babelHelpers.classPrivateFieldGet2(_a, this), (_Nested = class Nested { + var _barDecs, _init_bar, _outerThis, _Nested; + return _outerThis = this, (_Nested = class Nested { constructor() { babelHelpers.defineProperty(this, "bar", _init_bar(this)); } - }, [_init_bar] = babelHelpers.applyDecs(_Nested, [[_barDecs, 0, "bar"]], []), _Nested); + }, (() => { + _barDecs = babelHelpers.classPrivateFieldGet2(_a, _outerThis); + [_init_bar] = babelHelpers.applyDecs(_Nested, [[_barDecs, 0, "bar"]], []); + })(), _Nested); } } _Foo2 = Foo; -[_initProto, _Foo, _initClass] = babelHelpers.applyDecs(_Foo2, [[_methodDecs, 2, "method"]], _classDecs); +(() => { + _methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; + [_initProto, _Foo, _initClass] = babelHelpers.applyDecs(_Foo2, [[_methodDecs, 2, "method"]], _classDecs); +})(); _initClass(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/all-decorators/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/all-decorators/output.js index 109320ec4a1b..b79064f0c9a4 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/all-decorators/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/all-decorators/output.js @@ -2,65 +2,63 @@ var _initProto, _initStatic, _initClass, _init_a, _init_d, _init_e, _call_f, _ca const dec = () => {}; let _Class; new class extends babelHelpers.identity { - static { - class Class { - static { - [_init_m, _call_o, _call_p, _call_q, _init_r, _get_r, _set_r, _init_d, _call_f, _call_g, _call_g2, _init_h, _get_h, _set_h, _init_i, _init_n, _init_a, _init_e, _initProto, _initStatic, _Class, _initClass] = babelHelpers.applyDecs(this, [[dec, 7, "j"], [dec, 8, "k"], [dec, 9, "l"], [dec, 6, "m"], [dec, 7, "o", function () {}], [dec, 8, "p", function () {}], [dec, 9, "q", function (v) {}], [dec, 6, "r", function () { - return this.#D; - }, function (value) { - this.#D = value; - }], [dec, 2, "b"], [dec, 3, "c"], [dec, 4, "c"], [dec, 1, "d"], [dec, 2, "f", function () {}], [dec, 3, "g", function () {}], [dec, 4, "g", function (v) {}], [dec, 1, "h", function () { - return this.#B; - }, function (value) { - this.#B = value; - }], [dec, 5, "i"], [dec, 5, "n", function () { - return this.#n; - }, function (value) { - this.#n = value; - }], [dec, 0, "a"], [dec, 0, "e", function () { - return this.#e; - }, function (value) { - this.#e = value; - }]], [dec]); - _initStatic(this); - } - #f = _call_f; - a = (_initProto(this), _init_a(this)); - b() {} - get c() {} - set c(v) {} - #A = _init_d(this); - get d() { - return this.#A; - } - set d(v) { - this.#A = v; - } - #e = _init_e(this); - get #g() { - return _call_g(this); - } - set #g(v) { - _call_g2(this, v); - } - #B = _init_h(this); - set #h(v) { - _set_h(this, v); - } - get #h() { - return _get_h(this); - } - static j() {} - static get k() {} - static set l(v) {} - static get m() { - return this.#C; - } - static set m(v) { - this.#C = v; - } + static [class Class { + static { + [_init_m, _call_o, _call_p, _call_q, _init_r, _get_r, _set_r, _init_d, _call_f, _call_g, _call_g2, _init_h, _get_h, _set_h, _init_i, _init_n, _init_a, _init_e, _initProto, _initStatic, _Class, _initClass] = babelHelpers.applyDecs(this, [[dec, 7, "j"], [dec, 8, "k"], [dec, 9, "l"], [dec, 6, "m"], [dec, 7, "o", function () {}], [dec, 8, "p", function () {}], [dec, 9, "q", function (v) {}], [dec, 6, "r", function () { + return this.#D; + }, function (value) { + this.#D = value; + }], [dec, 2, "b"], [dec, 3, "c"], [dec, 4, "c"], [dec, 1, "d"], [dec, 2, "f", function () {}], [dec, 3, "g", function () {}], [dec, 4, "g", function (v) {}], [dec, 1, "h", function () { + return this.#B; + }, function (value) { + this.#B = value; + }], [dec, 5, "i"], [dec, 5, "n", function () { + return this.#n; + }, function (value) { + this.#n = value; + }], [dec, 0, "a"], [dec, 0, "e", function () { + return this.#e; + }, function (value) { + this.#e = value; + }]], [dec]); + _initStatic(this); } - } + #f = _call_f; + a = (_initProto(this), _init_a(this)); + b() {} + get c() {} + set c(v) {} + #A = _init_d(this); + get d() { + return this.#A; + } + set d(v) { + this.#A = v; + } + #e = _init_e(this); + get #g() { + return _call_g(this); + } + set #g(v) { + _call_g2(this, v); + } + #B = _init_h(this); + set #h(v) { + _set_h(this, v); + } + get #h() { + return _get_h(this); + } + static j() {} + static get k() {} + static set l(v) {} + static get m() { + return this.#C; + } + static set m(v) { + this.#C = v; + } + }]; #o = _call_o; i = _init_i(this); #C = _init_m(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js index b5bbfb8c55d5..7810f09be081 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js @@ -1,8 +1,8 @@ var _initProto, _methodDecs, _initProto2, _methodDecs2; const dec = () => {}; -_methodDecs = deco; class A extends B { static { + _methodDecs = deco; [_initProto] = babelHelpers.applyDecs(this, [[_methodDecs, 2, "method"]], []); } constructor() { @@ -14,9 +14,9 @@ class A extends B { } method() {} } -_methodDecs2 = deco; class C extends B { static { + _methodDecs2 = deco; [_initProto2] = babelHelpers.applyDecs(this, [[_methodDecs2, 2, "method"]], []); } constructor() { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js index 9c74491964c6..78f40c2519d7 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js @@ -68,9 +68,9 @@ let log = []; new class Dummy extends B { constructor() { - var _initProto3, _computedKey; + let _computedKey; + var _initProto3; let key; - _computedKey = babelHelpers.toPropertyKey((key = super(5).method(), log.push(key), key)); class A extends B { static { [_initProto3] = babelHelpers.applyDecs(this, [[dec, 2, "method"]], []); @@ -81,7 +81,7 @@ method() { return this.a; } - [_computedKey] = void _initProto3(this); + [_computedKey = (key = super(5).method(), log.push(key), key)] = void _initProto3(this); } new A(); } @@ -94,10 +94,11 @@ const noop = () => fn => fn; new class extends B { constructor() { - var _initProto4, _noopDecs; - _noopDecs = noop(log.push(super(7).method())); + var _initProto4, _noopDecs, _outerSuper; + _outerSuper = (...args) => super(...args); class A extends B { static { + _noopDecs = noop(log.push(_outerSuper(7).method())); [_initProto4] = babelHelpers.applyDecs(this, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []); } constructor() { @@ -147,9 +148,10 @@ [_initProto6] = babelHelpers.applyDecs(this, [[dec, 2, "method"]], []); } constructor() { - var _initProto7, _noopDecs2; - new (_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), class Dummy extends B { + var _initProto7, _noopDecs2, _outerSuper2; + new (_outerSuper2 = (...args) => super(...args), class Dummy extends B { static { + _noopDecs2 = noop(log.push(_initProto6(_outerSuper2(11)).method())); [_initProto7] = babelHelpers.applyDecs(this, [[_noopDecs2, 2, "noop"]], []); } constructor() { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js index 171d52da5533..f15cee18068e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js @@ -1,18 +1,19 @@ var _initProto, _initClass, _classDecs, _methodDecs; const dec = () => {}; _classDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; -_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; let _Foo; class Foo { static { + _methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; [_initProto, _Foo, _initClass] = babelHelpers.applyDecs(this, [[_methodDecs, 2, "method"]], _classDecs); } #a = void _initProto(this); method() {} makeClass() { - var _barDecs, _init_bar; - return _barDecs = this.#a, class Nested { + var _barDecs, _init_bar, _outerThis; + return _outerThis = this, class Nested { static { + _barDecs = _outerThis.#a; [_init_bar] = babelHelpers.applyDecs(this, [[_barDecs, 0, "bar"]], []); } bar = _init_bar(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/context-name/output.js index d8f2ca46bceb..78076f532c2d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey, _Foo; +let _computedKey; +var _initStatic, _call_a, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/context-name/output.js index fa6af9f96250..e7160389c376 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey; +let _computedKey; +var _initStatic, _call_a; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs(this, [[dec, 9, "a"], [dec, 9, "a", function (v) {}], [dec, 9, "b"], [dec, 9, "c"], [dec, 9, 0], [dec, 9, 1], [dec, 9, 2n], [dec, 9, 3n], [dec, 9, _computedKey]], []); @@ -25,6 +25,6 @@ class Foo { static set [1](v) {} static set 2n(v) {} static set [3n](v) {} - static set [_computedKey](v) {} + static set [_computedKey = babelHelpers.toPropertyKey(f())](v) {} } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-accessors--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-accessors--to-es2015/context-name/output.js index f932fe768be6..0d0f0c46aff4 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-accessors--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-accessors--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7, _Foo; +let _computedKey; +var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-accessors/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-accessors/context-name/output.js index b8eb29a26438..ed384e8f8d67 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-accessors/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-accessors/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7; +let _computedKey; +var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7, _initStatic] = babelHelpers.applyDecs2203R(this, [[dec, 6, "a"], [dec, 6, "a", function () { @@ -76,7 +76,7 @@ class Foo { this.#H = v; } static #I = _init_computedKey7(this); - static get [_computedKey]() { + static get [_computedKey = babelHelpers.toPropertyKey(f())]() { return this.#I; } static set [_computedKey](v) { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/expressions-static-blocks/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/expressions-static-blocks/output.js index 40aec4dd1dd4..951153809e0b 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/expressions-static-blocks/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/expressions-static-blocks/output.js @@ -1,73 +1,51 @@ -var _initClass, _A, _temp, _initClass2, _C, _temp2, _initClass3, _D, _temp3, _initClass4, _decorated_class, _temp4, _Class2, _initClass5, _G, _temp5, _initClass6, _decorated_class2, _temp6, _Class3, _initClass7, _H, _temp7, _initClass8, _K, _temp8; +let _A2, _C2, _D2, _ref, _G2, _ref2, _H2, _K2; +var _initClass, _A, _Class, _A3, _initClass2, _C, _Class2, _C3, _initClass3, _D, _Class3, _D3, _initClass4, _decorated_class, _Class4, _Class5, _initClass5, _G, _Class6, _G3, _initClass6, _decorated_class2, _Class7, _Class8, _initClass7, _H, _Class9, _H3, _initClass8, _K, _Class10, _K3; const dec = () => {}; -const A = (new (_temp = class extends babelHelpers.identity { +const A = (new (_A2 = (_A3 = class A {}, [_A, _initClass] = babelHelpers.applyDecs2203R(_A3, [], [dec]).c, _A3), (_Class = class extends babelHelpers.identity { constructor() { super(_A), (() => {})(), _initClass(); } -}, (_A2 => { - class A {} - _A2 = A; - [_A, _initClass] = babelHelpers.applyDecs2203R(_A2, [], [dec]).c; -})(), _temp)(), _A); -const B = (new (_temp2 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class, _A2, void 0), _Class))(), _A); +const B = (new (_C2 = (_C3 = class C {}, [_C, _initClass2] = babelHelpers.applyDecs2203R(_C3, [], [dec]).c, _C3), (_Class2 = class extends babelHelpers.identity { constructor() { super(_C), (() => {})(), _initClass2(); } -}, (_C2 => { - class C {} - _C2 = C; - [_C, _initClass2] = babelHelpers.applyDecs2203R(_C2, [], [dec]).c; -})(), _temp2)(), _C); -const D = (new (_temp3 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class2, _C2, void 0), _Class2))(), _C); +const D = (new (_D2 = (_D3 = class D {}, [_D, _initClass3] = babelHelpers.applyDecs2203R(_D3, [], [dec]).c, _D3), (_Class3 = class extends babelHelpers.identity { constructor() { super(_D), (() => {})(), _initClass3(); } -}, (_D2 => { - class D {} - _D2 = D; - [_D, _initClass3] = babelHelpers.applyDecs2203R(_D2, [], [dec]).c; -})(), _temp3)(), _D); -const E = ((new (_temp4 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class3, _D2, void 0), _Class3))(), _D); +const E = ((new (_ref = (_Class5 = class _ref {}, [_decorated_class, _initClass4] = babelHelpers.applyDecs2203R(_Class5, [], [dec]).c, _Class5), (_Class4 = class extends babelHelpers.identity { constructor() { super(_decorated_class), (() => {})(), _initClass4(); } -}, (_Class2 = class {}, [_decorated_class, _initClass4] = babelHelpers.applyDecs2203R(_Class2, [], [dec]).c), _temp4)(), _decorated_class), 123); -const F = [(new (_temp5 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class4, _ref, void 0), _Class4))(), _decorated_class), 123); +const F = [(new (_G2 = (_G3 = class G {}, [_G, _initClass5] = babelHelpers.applyDecs2203R(_G3, [], [dec]).c, _G3), (_Class6 = class extends babelHelpers.identity { constructor() { super(_G), (() => {})(), _initClass5(); } -}, (_G2 => { - class G {} - _G2 = G; - [_G, _initClass5] = babelHelpers.applyDecs2203R(_G2, [], [dec]).c; -})(), _temp5)(), _G), (new (_temp6 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class6, _G2, void 0), _Class6))(), _G), (new (_ref2 = (_Class8 = class _ref2 {}, [_decorated_class2, _initClass6] = babelHelpers.applyDecs2203R(_Class8, [], [dec]).c, _Class8), (_Class7 = class extends babelHelpers.identity { constructor() { super(_decorated_class2), (() => {})(), _initClass6(); } -}, (_Class3 = class {}, [_decorated_class2, _initClass6] = babelHelpers.applyDecs2203R(_Class3, [], [dec]).c), _temp6)(), _decorated_class2)]; -const H = (new (_temp7 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class7, _ref2, void 0), _Class7))(), _decorated_class2)]; +const H = (new (_H2 = (_H3 = class H extends I {}, [_H, _initClass7] = babelHelpers.applyDecs2203R(_H3, [], [dec]).c, _H3), (_Class9 = class extends babelHelpers.identity { constructor() { super(_H), (() => {})(), _initClass7(); } -}, (_H2 => { - class H extends I {} - _H2 = H; - [_H, _initClass7] = babelHelpers.applyDecs2203R(_H2, [], [dec]).c; -})(), _temp7)(), _H); -const J = (new (_temp8 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class9, _H2, void 0), _Class9))(), _H); +const J = (new (_K2 = (_K3 = class K extends L {}, [_K, _initClass8] = babelHelpers.applyDecs2203R(_K3, [], [dec]).c, _K3), (_Class10 = class extends babelHelpers.identity { constructor() { super(_K), (() => {})(), _initClass8(); } -}, (_K2 => { - class K extends L {} - _K2 = K; - [_K, _initClass8] = babelHelpers.applyDecs2203R(_K2, [], [dec]).c; -})(), _temp8)(), _K); +}, babelHelpers.defineProperty(_Class10, _K2, void 0), _Class10))(), _K); function classFactory() { - var _initClass9, _decorated_class3, _temp9, _Class5; - return new (_temp9 = class extends babelHelpers.identity { + let _ref3; + var _initClass9, _decorated_class3, _Class11, _Class12; + return new (_ref3 = (_Class12 = class _ref3 {}, [_decorated_class3, _initClass9] = babelHelpers.applyDecs2203R(_Class12, [], [dec]).c, _Class12), (_Class11 = class extends babelHelpers.identity { constructor() { super(_decorated_class3), (() => {})(), _initClass9(); } - }, (_Class5 = class {}, [_decorated_class3, _initClass9] = babelHelpers.applyDecs2203R(_Class5, [], [dec]).c), _temp9)(), _decorated_class3; + }, babelHelpers.defineProperty(_Class11, _ref3, void 0), _Class11))(), _decorated_class3; } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/initializers/output.js index a4e0538fbc43..d8d260b559ce 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/initializers/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/initializers/output.js @@ -1,24 +1,17 @@ -var _initClass, _temp, _initClass2, _temp2; +let _Foo2, _Bar2; +var _initClass, _Class, _Foo3, _initClass2, _Class2, _Bar3; const dec = () => {}; let _Foo; -new (_temp = class extends babelHelpers.identity { +new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs2203R(_Foo3, [], [dec]).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "field", 123)), _initClass(); } -}, (_Foo2 => { - class Foo {} - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2203R(_Foo2, [], [dec]).c; -})(), _temp)(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); let _Bar; -new (_temp2 = class extends babelHelpers.identity { +new (_Bar2 = (_Bar3 = class Bar extends _Foo {}, [_Bar, _initClass2] = babelHelpers.applyDecs2203R(_Bar3, [], [dec]).c, _Bar3), (_Class2 = class extends babelHelpers.identity { constructor() { (super(_Bar), babelHelpers.defineProperty(this, "field", ((() => { this.otherField = 456; })(), 123))), _initClass2(); } -}, (_Bar2 => { - class Bar extends _Foo {} - _Bar2 = Bar; - [_Bar, _initClass2] = babelHelpers.applyDecs2203R(_Bar2, [], [dec]).c; -})(), _temp2)(); +}, babelHelpers.defineProperty(_Class2, _Bar2, void 0), _Class2))(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement-static-installed-on-correct-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement-static-installed-on-correct-class/output.js index 7edabe68b815..a3f75a31fb0a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement-static-installed-on-correct-class/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement-static-installed-on-correct-class/output.js @@ -1,8 +1,17 @@ -var _initClass, _x, _A, _Class_brand, _B, _temp; +let _Foo2; +var _initClass, _Class, _x, _A, _Class_brand, _B, _Foo3; const dec = () => {}; let hasX, hasA, hasM; let _Foo; -new (_x = /*#__PURE__*/new WeakMap(), _A = /*#__PURE__*/new WeakMap(), _Class_brand = /*#__PURE__*/new WeakSet(), _B = /*#__PURE__*/new WeakMap(), (_temp = class extends babelHelpers.identity { +new (_x = /*#__PURE__*/new WeakMap(), _A = /*#__PURE__*/new WeakMap(), _Class_brand = /*#__PURE__*/new WeakSet(), _B = /*#__PURE__*/new WeakMap(), _Foo2 = (_Foo3 = class Foo { + static get a() { + return babelHelpers.classPrivateFieldGet2(_B, this); + } + static set a(v) { + babelHelpers.classPrivateFieldSet2(_B, this, v); + } + static m() {} +}, [_Foo, _initClass] = babelHelpers.applyDecs2203R(_Foo3, [], [dec]).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.classPrivateMethodInitSpec(this, _Class_brand), babelHelpers.classPrivateFieldInitSpec(this, _x, void 0), babelHelpers.classPrivateFieldInitSpec(this, _A, void 0), babelHelpers.defineProperty(this, "x", void 0), babelHelpers.classPrivateFieldInitSpec(this, _B, void 0), this), (() => { hasX = o => _x.has(babelHelpers.checkInRHS(o)); @@ -10,19 +19,7 @@ new (_x = /*#__PURE__*/new WeakMap(), _A = /*#__PURE__*/new WeakMap(), _Class_br hasM = o => _Class_brand.has(babelHelpers.checkInRHS(o)); })(), _initClass(); } -}, (_Foo2 => { - class Foo { - static get a() { - return babelHelpers.classPrivateFieldGet2(_B, this); - } - static set a(v) { - babelHelpers.classPrivateFieldSet2(_B, this, v); - } - static m() {} - } - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2203R(_Foo2, [], [dec]).c; -})(), _temp))(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); function _get_a(_this) { return babelHelpers.classPrivateFieldGet2(_A, _this); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement-static-this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement-static-this/output.js index aab7c89d49b2..d355f1c3ab6c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement-static-this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement-static-this/output.js @@ -1,7 +1,8 @@ -var _initClass, _temp; +let _Foo2; +var _initClass, _Class, _Foo3; const dec = () => {}; let _Foo; -new (_temp = class extends babelHelpers.identity { +new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs2203R(_Foo3, [], [dec]).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "field", ((() => { this; @@ -9,8 +10,4 @@ new (_temp = class extends babelHelpers.identity { this; })(), _initClass(); } -}, (_Foo2 => { - class Foo {} - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2203R(_Foo2, [], [dec]).c; -})(), _temp)(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement/output.js index acc6b8d569b7..1ab8558f7494 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement/output.js @@ -1,13 +1,10 @@ -var _initClass, _temp; +let _Foo2; +var _initClass, _Class, _Foo3; const dec = () => {}; let _Foo; -new (_temp = class extends babelHelpers.identity { +new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs2203R(_Foo3, [], [dec]).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "foo", new _Foo())), _initClass(); } -}, (_Foo2 => { - class Foo {} - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2203R(_Foo2, [], [dec]).c; -})(), _temp)(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); const foo = new _Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/expressions-static-blocks/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/expressions-static-blocks/output.js index e04e88b4426d..493fdaabff5a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/expressions-static-blocks/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/expressions-static-blocks/output.js @@ -1,96 +1,80 @@ var _initClass, _A, _initClass2, _C, _initClass3, _D, _initClass4, _decorated_class, _initClass5, _G, _initClass6, _decorated_class2, _initClass7, _H, _initClass8, _K; const dec = () => {}; const A = (new class extends babelHelpers.identity { - static { - class A { - static { - [_A, _initClass] = babelHelpers.applyDecs2203R(this, [], [dec]).c; - } + static [class A { + static { + [_A, _initClass] = babelHelpers.applyDecs2203R(this, [], [dec]).c; } - } + }]; constructor() { super(_A), (() => {})(), _initClass(); } }(), _A); const B = (new class extends babelHelpers.identity { - static { - class C { - static { - [_C, _initClass2] = babelHelpers.applyDecs2203R(this, [], [dec]).c; - } + static [class C { + static { + [_C, _initClass2] = babelHelpers.applyDecs2203R(this, [], [dec]).c; } - } + }]; constructor() { super(_C), (() => {})(), _initClass2(); } }(), _C); const D = (new class extends babelHelpers.identity { - static { - class D { - static { - [_D, _initClass3] = babelHelpers.applyDecs2203R(this, [], [dec]).c; - } + static [class D { + static { + [_D, _initClass3] = babelHelpers.applyDecs2203R(this, [], [dec]).c; } - } + }]; constructor() { super(_D), (() => {})(), _initClass3(); } }(), _D); const E = ((new class extends babelHelpers.identity { - static { - (class { - static { - [_decorated_class, _initClass4] = babelHelpers.applyDecs2203R(this, [], [dec]).c; - } - }); - } + static [class { + static { + [_decorated_class, _initClass4] = babelHelpers.applyDecs2203R(this, [], [dec]).c; + } + }]; constructor() { super(_decorated_class), (() => {})(), _initClass4(); } }(), _decorated_class), 123); const F = [(new class extends babelHelpers.identity { - static { - class G { - static { - [_G, _initClass5] = babelHelpers.applyDecs2203R(this, [], [dec]).c; - } + static [class G { + static { + [_G, _initClass5] = babelHelpers.applyDecs2203R(this, [], [dec]).c; } - } + }]; constructor() { super(_G), (() => {})(), _initClass5(); } }(), _G), (new class extends babelHelpers.identity { - static { - (class { - static { - [_decorated_class2, _initClass6] = babelHelpers.applyDecs2203R(this, [], [dec]).c; - } - }); - } + static [class { + static { + [_decorated_class2, _initClass6] = babelHelpers.applyDecs2203R(this, [], [dec]).c; + } + }]; constructor() { super(_decorated_class2), (() => {})(), _initClass6(); } }(), _decorated_class2)]; const H = (new class extends babelHelpers.identity { - static { - class H extends I { - static { - [_H, _initClass7] = babelHelpers.applyDecs2203R(this, [], [dec]).c; - } + static [class H extends I { + static { + [_H, _initClass7] = babelHelpers.applyDecs2203R(this, [], [dec]).c; } - } + }]; constructor() { super(_H), (() => {})(), _initClass7(); } }(), _H); const J = (new class extends babelHelpers.identity { - static { - class K extends L { - static { - [_K, _initClass8] = babelHelpers.applyDecs2203R(this, [], [dec]).c; - } + static [class K extends L { + static { + [_K, _initClass8] = babelHelpers.applyDecs2203R(this, [], [dec]).c; } - } + }]; constructor() { super(_K), (() => {})(), _initClass8(); } @@ -98,13 +82,11 @@ const J = (new class extends babelHelpers.identity { function classFactory() { var _initClass9, _decorated_class3; return new class extends babelHelpers.identity { - static { - (class { - static { - [_decorated_class3, _initClass9] = babelHelpers.applyDecs2203R(this, [], [dec]).c; - } - }); - } + static [class { + static { + [_decorated_class3, _initClass9] = babelHelpers.applyDecs2203R(this, [], [dec]).c; + } + }]; constructor() { super(_decorated_class3), (() => {})(), _initClass9(); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/initializers/output.js index 4eca9605ad82..b2ffd5d23cc9 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/initializers/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/initializers/output.js @@ -2,13 +2,11 @@ var _initClass, _initClass2; const dec = () => {}; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2203R(this, [], [dec]).c; - } + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2203R(this, [], [dec]).c; } - } + }]; field = 123; constructor() { super(_Foo), _initClass(); @@ -16,13 +14,11 @@ new class extends babelHelpers.identity { }(); let _Bar; new class extends babelHelpers.identity { - static { - class Bar extends _Foo { - static { - [_Bar, _initClass2] = babelHelpers.applyDecs2203R(this, [], [dec]).c; - } + static [class Bar extends _Foo { + static { + [_Bar, _initClass2] = babelHelpers.applyDecs2203R(this, [], [dec]).c; } - } + }]; field = ((() => { this.otherField = 456; })(), 123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/replacement-static-installed-on-correct-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/replacement-static-installed-on-correct-class/output.js index 4953fb3c3150..bfaa11302914 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/replacement-static-installed-on-correct-class/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/replacement-static-installed-on-correct-class/output.js @@ -3,20 +3,18 @@ const dec = () => {}; let hasX, hasA, hasM; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2203R(this, [], [dec]).c; - } - static get a() { - return this.#B; - } - static set a(v) { - this.#B = v; - } - static m() {} + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2203R(this, [], [dec]).c; } - } + static get a() { + return this.#B; + } + static set a(v) { + this.#B = v; + } + static m() {} + }]; #x; #A; get #a() { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/replacement-static-this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/replacement-static-this/output.js index 5f00861b1f21..30996888e725 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/replacement-static-this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/replacement-static-this/output.js @@ -2,13 +2,11 @@ var _initClass; const dec = () => {}; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2203R(this, [], [dec]).c; - } + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2203R(this, [], [dec]).c; } - } + }]; field = ((() => { this; })(), this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/replacement/output.js index a98ff1b05ec1..cb4a658ed6b7 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/replacement/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes/replacement/output.js @@ -2,13 +2,11 @@ var _initClass; const dec = () => {}; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2203R(this, [], [dec]).c; - } + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2203R(this, [], [dec]).c; } - } + }]; foo = new _Foo(); constructor() { super(_Foo), _initClass(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys--to-es2015/computed-keys-same-ast/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys--to-es2015/computed-keys-same-ast/output.js index 49bcb821c40d..135b7599f792 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys--to-es2015/computed-keys-same-ast/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys--to-es2015/computed-keys-same-ast/output.js @@ -1,4 +1,5 @@ -var _initProto, _computedKey, _computedKey2, _Foo; +let _computedKey, _computedKey2; +var _initProto, _Foo; const dec = () => {}; _computedKey = babelHelpers.toPropertyKey(getKey()); _computedKey2 = babelHelpers.toPropertyKey(getKey()); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys--to-es2015/computed-keys-same-value/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys--to-es2015/computed-keys-same-value/output.js index 2606e44a7ac0..3b36b9082fdc 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys--to-es2015/computed-keys-same-value/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys--to-es2015/computed-keys-same-value/output.js @@ -1,4 +1,5 @@ -var _initProto, _computedKey, _computedKey2, _Foo; +let _computedKey, _computedKey2; +var _initProto, _Foo; const dec = () => {}; _computedKey = babelHelpers.toPropertyKey(getKeyI()); _computedKey2 = babelHelpers.toPropertyKey(getKeyJ()); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys/computed-keys-same-ast/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys/computed-keys-same-ast/output.js index 9b3d9ee9c5e4..741b195e9d92 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys/computed-keys-same-ast/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys/computed-keys-same-ast/output.js @@ -1,7 +1,6 @@ -var _initProto, _computedKey, _computedKey2; +let _computedKey, _computedKey2; +var _initProto; const dec = () => {}; -_computedKey = babelHelpers.toPropertyKey(getKey()); -_computedKey2 = babelHelpers.toPropertyKey(getKey()); class Foo { static { [_initProto] = babelHelpers.applyDecs2203R(this, [[dec, 2, _computedKey], [dec, 2, _computedKey2]], []).e; @@ -9,10 +8,10 @@ class Foo { constructor() { _initProto(this); } - [_computedKey]() { + [_computedKey = babelHelpers.toPropertyKey(getKey())]() { return 1; } - [_computedKey2]() { + [_computedKey2 = babelHelpers.toPropertyKey(getKey())]() { return 2; } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys/computed-keys-same-value/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys/computed-keys-same-value/output.js index 1ad51a75c9aa..f182658b7950 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys/computed-keys-same-value/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-duplicated-keys/computed-keys-same-value/output.js @@ -1,7 +1,6 @@ -var _initProto, _computedKey, _computedKey2; +let _computedKey, _computedKey2; +var _initProto; const dec = () => {}; -_computedKey = babelHelpers.toPropertyKey(getKeyI()); -_computedKey2 = babelHelpers.toPropertyKey(getKeyJ()); class Foo { static { [_initProto] = babelHelpers.applyDecs2203R(this, [[dec, 2, _computedKey], [dec, 2, _computedKey2]], []).e; @@ -9,10 +8,10 @@ class Foo { constructor() { _initProto(this); } - [_computedKey]() { + [_computedKey = babelHelpers.toPropertyKey(getKeyI())]() { return 1; } - [_computedKey2]() { + [_computedKey2 = babelHelpers.toPropertyKey(getKeyJ())]() { return 2; } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-exported/member-decorator/output.mjs b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-exported/member-decorator/output.mjs index 124b101ad476..3bb3e16a1b2e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-exported/member-decorator/output.mjs +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-exported/member-decorator/output.mjs @@ -1,7 +1,7 @@ var _xDecs, _init_x; -_xDecs = dec; export class A { static { + _xDecs = dec; [_init_x] = babelHelpers.applyDecs2203R(this, [[_xDecs, 0, "x"]], []).e; } x = _init_x(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-fields--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-fields--to-es2015/context-name/output.js index 612cf49d25a2..be3ce85238ff 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-fields--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-fields--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7, _Foo; +let _computedKey; +var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-fields/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-fields/context-name/output.js index c6f5bf7441d6..63be521691fb 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-fields/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-fields/context-name/output.js @@ -1,4 +1,5 @@ -var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7; +let _computedKey; +var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7] = babelHelpers.applyDecs2203R(this, [[dec, 5, "a"], [dec, 5, "a", function () { @@ -26,6 +26,6 @@ class Foo { static [1] = _init_computedKey4(this); static 2n = _init_computedKey5(this); static [3n] = _init_computedKey6(this); - static [_computedKey] = _init_computedKey7(this); + static [_computedKey = babelHelpers.toPropertyKey(f())] = _init_computedKey7(this); } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-getters--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-getters--to-es2015/context-name/output.js index 449c7a7fc8b9..fd0b433c4530 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-getters--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-getters--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey, _Foo; +let _computedKey; +var _initStatic, _call_a, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-getters/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-getters/context-name/output.js index f16b0e0dc84a..e438f759153d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-getters/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-getters/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey; +let _computedKey; +var _initStatic, _call_a; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs2203R(this, [[dec, 8, "a"], [dec, 8, "a", function () {}], [dec, 8, "b"], [dec, 8, "c"], [dec, 8, 0], [dec, 8, 1], [dec, 8, 2n], [dec, 8, 3n], [dec, 8, _computedKey]], []).e; @@ -25,6 +25,6 @@ class Foo { static get [1]() {} static get 2n() {} static get [3n]() {} - static get [_computedKey]() {} + static get [_computedKey = babelHelpers.toPropertyKey(f())]() {} } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-methods--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-methods--to-es2015/context-name/output.js index fbe1a4aa899e..45c3c03e56e1 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-methods--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-methods--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey, _Foo; +let _computedKey; +var _initStatic, _call_a, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-methods/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-methods/context-name/output.js index ea84299912a5..70e60dfc7a15 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-methods/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-methods/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey; +let _computedKey; +var _initStatic, _call_a; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs2203R(this, [[dec, 7, "a"], [dec, 7, "a", function () {}], [dec, 7, "b"], [dec, 7, "c"], [dec, 7, 0], [dec, 7, 1], [dec, 7, 2n], [dec, 7, 3n], [dec, 7, _computedKey]], []).e; @@ -23,6 +23,6 @@ class Foo { static [1]() {} static 2n() {} static [3n]() {} - static [_computedKey]() {} + static [_computedKey = babelHelpers.toPropertyKey(f())]() {} } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js index 1d2a38b239b1..482931a1a711 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js @@ -66,9 +66,10 @@ let log = []; new class Dummy extends B { constructor() { - var _initProto3, _computedKey, _A3; + let _computedKey; + var _initProto3, _A3; let key; - _computedKey = babelHelpers.toPropertyKey((key = super(5).method(), log.push(key), key)); + _computedKey = (key = super(5).method(), log.push(key), key); class A extends B { constructor() { log.push((super(6), babelHelpers.defineProperty(this, _computedKey, void _initProto3(this))).method()); @@ -90,8 +91,8 @@ const noop = () => fn => fn; new class extends B { constructor() { - var _initProto4, _noopDecs, _A4; - _noopDecs = noop(log.push(super(7).method())); + var _initProto4, _noopDecs, _outerSuper, _A4; + _outerSuper = (...args) => super(...args); class A extends B { constructor() { log.push(_initProto4(super(8)).method()); @@ -102,7 +103,10 @@ noop() {} } _A4 = A; - [_initProto4] = babelHelpers.applyDecs2203R(_A4, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []).e; + (() => { + _noopDecs = noop(log.push(_outerSuper(7).method())); + [_initProto4] = babelHelpers.applyDecs2203R(_A4, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []).e; + })(); new A(); } }(); @@ -138,13 +142,16 @@ const noop = () => fn => fn; class A extends B { constructor() { - var _initProto7, _noopDecs2, _Dummy2; - new (_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), (_Dummy2 = class Dummy extends B { + var _initProto7, _noopDecs2, _outerSuper2, _Dummy2; + new (_outerSuper2 = (...args) => super(...args), (_Dummy2 = class Dummy extends B { constructor() { log.push(_initProto7(super(12)).method()); } noop() {} - }, [_initProto7] = babelHelpers.applyDecs2203R(_Dummy2, [[_noopDecs2, 2, "noop"]], []).e, _Dummy2))(); + }, (() => { + _noopDecs2 = noop(log.push(_initProto6(_outerSuper2(11)).method())); + [_initProto7] = babelHelpers.applyDecs2203R(_Dummy2, [[_noopDecs2, 2, "noop"]], []).e; + })(), _Dummy2))(); } method() { return this.a; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/valid-expression-formats/output.js index 9d199b3e69ab..c4f4d0f3ffbe 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/valid-expression-formats/output.js @@ -1,7 +1,6 @@ var _initProto, _initClass, _classDecs, _methodDecs, _Foo2; const dec = () => {}; _classDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; -_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; let _Foo; var _a = /*#__PURE__*/new WeakMap(); class Foo { @@ -10,17 +9,23 @@ class Foo { } method() {} makeClass() { - var _barDecs, _init_bar, _Nested; - return _barDecs = babelHelpers.classPrivateFieldGet2(_a, this), (_Nested = class Nested { + var _barDecs, _init_bar, _outerThis, _Nested; + return _outerThis = this, (_Nested = class Nested { constructor() { babelHelpers.defineProperty(this, "bar", _init_bar(this)); } - }, [_init_bar] = babelHelpers.applyDecs2203R(_Nested, [[_barDecs, 0, "bar"]], []).e, _Nested); + }, (() => { + _barDecs = babelHelpers.classPrivateFieldGet2(_a, _outerThis); + [_init_bar] = babelHelpers.applyDecs2203R(_Nested, [[_barDecs, 0, "bar"]], []).e; + })(), _Nested); } } _Foo2 = Foo; -({ - e: [_initProto], - c: [_Foo, _initClass] -} = babelHelpers.applyDecs2203R(_Foo2, [[_methodDecs, 2, "method"]], _classDecs)); +(() => { + _methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; + ({ + e: [_initProto], + c: [_Foo, _initClass] + } = babelHelpers.applyDecs2203R(_Foo2, [[_methodDecs, 2, "method"]], _classDecs)); +})(); _initClass(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/all-decorators/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/all-decorators/output.js index d8da8cfefca1..acc01d51a186 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/all-decorators/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/all-decorators/output.js @@ -2,68 +2,66 @@ var _initProto, _initStatic, _initClass, _init_a, _init_d, _init_e, _call_f, _ca const dec = () => {}; let _Class; new class extends babelHelpers.identity { - static { - class Class { - static { - ({ - e: [_init_m, _call_o, _call_p, _call_q, _init_r, _get_r, _set_r, _init_d, _call_f, _call_g, _call_g2, _init_h, _get_h, _set_h, _init_i, _init_n, _init_a, _init_e, _initProto, _initStatic], - c: [_Class, _initClass] - } = babelHelpers.applyDecs2203R(this, [[dec, 7, "j"], [dec, 8, "k"], [dec, 9, "l"], [dec, 6, "m"], [dec, 7, "o", function () {}], [dec, 8, "p", function () {}], [dec, 9, "q", function (v) {}], [dec, 6, "r", function () { - return this.#D; - }, function (value) { - this.#D = value; - }], [dec, 2, "b"], [dec, 3, "c"], [dec, 4, "c"], [dec, 1, "d"], [dec, 2, "f", function () {}], [dec, 3, "g", function () {}], [dec, 4, "g", function (v) {}], [dec, 1, "h", function () { - return this.#B; - }, function (value) { - this.#B = value; - }], [dec, 5, "i"], [dec, 5, "n", function () { - return this.#n; - }, function (value) { - this.#n = value; - }], [dec, 0, "a"], [dec, 0, "e", function () { - return this.#e; - }, function (value) { - this.#e = value; - }]], [dec])); - _initStatic(this); - } - #f = _call_f; - a = (_initProto(this), _init_a(this)); - b() {} - get c() {} - set c(v) {} - #A = _init_d(this); - get d() { - return this.#A; - } - set d(v) { - this.#A = v; - } - #e = _init_e(this); - get #g() { - return _call_g(this); - } - set #g(v) { - _call_g2(this, v); - } - #B = _init_h(this); - set #h(v) { - _set_h(this, v); - } - get #h() { - return _get_h(this); - } - static j() {} - static get k() {} - static set l(v) {} - static get m() { - return this.#C; - } - static set m(v) { - this.#C = v; - } + static [class Class { + static { + ({ + e: [_init_m, _call_o, _call_p, _call_q, _init_r, _get_r, _set_r, _init_d, _call_f, _call_g, _call_g2, _init_h, _get_h, _set_h, _init_i, _init_n, _init_a, _init_e, _initProto, _initStatic], + c: [_Class, _initClass] + } = babelHelpers.applyDecs2203R(this, [[dec, 7, "j"], [dec, 8, "k"], [dec, 9, "l"], [dec, 6, "m"], [dec, 7, "o", function () {}], [dec, 8, "p", function () {}], [dec, 9, "q", function (v) {}], [dec, 6, "r", function () { + return this.#D; + }, function (value) { + this.#D = value; + }], [dec, 2, "b"], [dec, 3, "c"], [dec, 4, "c"], [dec, 1, "d"], [dec, 2, "f", function () {}], [dec, 3, "g", function () {}], [dec, 4, "g", function (v) {}], [dec, 1, "h", function () { + return this.#B; + }, function (value) { + this.#B = value; + }], [dec, 5, "i"], [dec, 5, "n", function () { + return this.#n; + }, function (value) { + this.#n = value; + }], [dec, 0, "a"], [dec, 0, "e", function () { + return this.#e; + }, function (value) { + this.#e = value; + }]], [dec])); + _initStatic(this); } - } + #f = _call_f; + a = (_initProto(this), _init_a(this)); + b() {} + get c() {} + set c(v) {} + #A = _init_d(this); + get d() { + return this.#A; + } + set d(v) { + this.#A = v; + } + #e = _init_e(this); + get #g() { + return _call_g(this); + } + set #g(v) { + _call_g2(this, v); + } + #B = _init_h(this); + set #h(v) { + _set_h(this, v); + } + get #h() { + return _get_h(this); + } + static j() {} + static get k() {} + static set l(v) {} + static get m() { + return this.#C; + } + static set m(v) { + this.#C = v; + } + }]; #o = _call_o; i = _init_i(this); #C = _init_m(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor-multiple-super/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor-multiple-super/output.js index 2c09b82cb035..498be8326084 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor-multiple-super/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor-multiple-super/output.js @@ -1,8 +1,8 @@ var _initProto, _methodDecs, _initProto2, _methodDecs2; const dec = () => {}; -_methodDecs = deco; class A extends B { static { + _methodDecs = deco; [_initProto] = babelHelpers.applyDecs2203R(this, [[_methodDecs, 2, "method"]], []).e; } constructor() { @@ -14,9 +14,9 @@ class A extends B { } method() {} } -_methodDecs2 = deco; class C extends B { static { + _methodDecs2 = deco; [_initProto2] = babelHelpers.applyDecs2203R(this, [[_methodDecs2, 2, "method"]], []).e; } constructor() { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor/output.js index f78bace93bf8..589a7405f4b8 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor/output.js @@ -68,9 +68,9 @@ let log = []; new class Dummy extends B { constructor() { - var _initProto3, _computedKey; + let _computedKey; + var _initProto3; let key; - _computedKey = babelHelpers.toPropertyKey((key = super(5).method(), log.push(key), key)); class A extends B { static { [_initProto3] = babelHelpers.applyDecs2203R(this, [[dec, 2, "method"]], []).e; @@ -81,7 +81,7 @@ method() { return this.a; } - [_computedKey] = void _initProto3(this); + [_computedKey = (key = super(5).method(), log.push(key), key)] = void _initProto3(this); } new A(); } @@ -94,10 +94,11 @@ const noop = () => fn => fn; new class extends B { constructor() { - var _initProto4, _noopDecs; - _noopDecs = noop(log.push(super(7).method())); + var _initProto4, _noopDecs, _outerSuper; + _outerSuper = (...args) => super(...args); class A extends B { static { + _noopDecs = noop(log.push(_outerSuper(7).method())); [_initProto4] = babelHelpers.applyDecs2203R(this, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []).e; } constructor() { @@ -147,9 +148,10 @@ [_initProto6] = babelHelpers.applyDecs2203R(this, [[dec, 2, "method"]], []).e; } constructor() { - var _initProto7, _noopDecs2; - new (_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), class Dummy extends B { + var _initProto7, _noopDecs2, _outerSuper2; + new (_outerSuper2 = (...args) => super(...args), class Dummy extends B { static { + _noopDecs2 = noop(log.push(_initProto6(_outerSuper2(11)).method())); [_initProto7] = babelHelpers.applyDecs2203R(this, [[_noopDecs2, 2, "noop"]], []).e; } constructor() { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/valid-expression-formats/output.js index 9efc481333c1..d5dc3e94e94a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/valid-expression-formats/output.js @@ -1,10 +1,10 @@ var _initProto, _initClass, _classDecs, _methodDecs; const dec = () => {}; _classDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; -_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; let _Foo; class Foo { static { + _methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; ({ e: [_initProto], c: [_Foo, _initClass] @@ -13,9 +13,10 @@ class Foo { #a = void _initProto(this); method() {} makeClass() { - var _barDecs, _init_bar; - return _barDecs = this.#a, class Nested { + var _barDecs, _init_bar, _outerThis; + return _outerThis = this, class Nested { static { + _barDecs = _outerThis.#a; [_init_bar] = babelHelpers.applyDecs2203R(this, [[_barDecs, 0, "bar"]], []).e; } bar = _init_bar(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-setters--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-setters--to-es2015/context-name/output.js index 271b94b5f07f..c6ae83d9792e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-setters--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-setters--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey, _Foo; +let _computedKey; +var _initStatic, _call_a, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-setters/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-setters/context-name/output.js index 37a91073b1cb..86781320b781 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-setters/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-setters/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey; +let _computedKey; +var _initStatic, _call_a; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs2203R(this, [[dec, 9, "a"], [dec, 9, "a", function (v) {}], [dec, 9, "b"], [dec, 9, "c"], [dec, 9, 0], [dec, 9, 1], [dec, 9, 2n], [dec, 9, 3n], [dec, 9, _computedKey]], []).e; @@ -25,6 +25,6 @@ class Foo { static set [1](v) {} static set 2n(v) {} static set [3n](v) {} - static set [_computedKey](v) {} + static set [_computedKey = babelHelpers.toPropertyKey(f())](v) {} } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/context-name/output.js index 2297d6c5bff7..dd5a3f9ce4dd 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7, _Foo; +let _computedKey; +var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors/context-name/output.js index 37a924ceddd5..dd1e1f5a88e0 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7; +let _computedKey; +var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7, _initStatic] = babelHelpers.applyDecs2301(this, [[dec, 6, "a"], [dec, 6, "a", o => o.#B, (o, v) => o.#B = v], [dec, 6, "b"], [dec, 6, "c"], [dec, 6, 0], [dec, 6, 1], [dec, 6, 2n], [dec, 6, 3n], [dec, 6, _computedKey]], []).e; @@ -72,7 +72,7 @@ class Foo { this.#H = v; } static #I = _init_computedKey7(this); - static get [_computedKey]() { + static get [_computedKey = babelHelpers.toPropertyKey(f())]() { return this.#I; } static set [_computedKey](v) { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/expressions-static-blocks/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/expressions-static-blocks/output.js index 094578f69562..81910f6eb7a2 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/expressions-static-blocks/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/expressions-static-blocks/output.js @@ -1,73 +1,51 @@ -var _initClass, _A, _temp, _initClass2, _C, _temp2, _initClass3, _D, _temp3, _initClass4, _decorated_class, _temp4, _Class2, _initClass5, _G, _temp5, _initClass6, _decorated_class2, _temp6, _Class3, _initClass7, _H, _temp7, _initClass8, _K, _temp8; +let _A2, _C2, _D2, _ref, _G2, _ref2, _H2, _K2; +var _initClass, _A, _Class, _A3, _initClass2, _C, _Class2, _C3, _initClass3, _D, _Class3, _D3, _initClass4, _decorated_class, _Class4, _Class5, _initClass5, _G, _Class6, _G3, _initClass6, _decorated_class2, _Class7, _Class8, _initClass7, _H, _Class9, _H3, _initClass8, _K, _Class10, _K3; const dec = () => {}; -const A = (new (_temp = class extends babelHelpers.identity { +const A = (new (_A2 = (_A3 = class A {}, [_A, _initClass] = babelHelpers.applyDecs2301(_A3, [], [dec]).c, _A3), (_Class = class extends babelHelpers.identity { constructor() { super(_A), (() => {})(), _initClass(); } -}, (_A2 => { - class A {} - _A2 = A; - [_A, _initClass] = babelHelpers.applyDecs2301(_A2, [], [dec]).c; -})(), _temp)(), _A); -const B = (new (_temp2 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class, _A2, void 0), _Class))(), _A); +const B = (new (_C2 = (_C3 = class C {}, [_C, _initClass2] = babelHelpers.applyDecs2301(_C3, [], [dec]).c, _C3), (_Class2 = class extends babelHelpers.identity { constructor() { super(_C), (() => {})(), _initClass2(); } -}, (_C2 => { - class C {} - _C2 = C; - [_C, _initClass2] = babelHelpers.applyDecs2301(_C2, [], [dec]).c; -})(), _temp2)(), _C); -const D = (new (_temp3 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class2, _C2, void 0), _Class2))(), _C); +const D = (new (_D2 = (_D3 = class D {}, [_D, _initClass3] = babelHelpers.applyDecs2301(_D3, [], [dec]).c, _D3), (_Class3 = class extends babelHelpers.identity { constructor() { super(_D), (() => {})(), _initClass3(); } -}, (_D2 => { - class D {} - _D2 = D; - [_D, _initClass3] = babelHelpers.applyDecs2301(_D2, [], [dec]).c; -})(), _temp3)(), _D); -const E = ((new (_temp4 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class3, _D2, void 0), _Class3))(), _D); +const E = ((new (_ref = (_Class5 = class _ref {}, [_decorated_class, _initClass4] = babelHelpers.applyDecs2301(_Class5, [], [dec]).c, _Class5), (_Class4 = class extends babelHelpers.identity { constructor() { super(_decorated_class), (() => {})(), _initClass4(); } -}, (_Class2 = class {}, [_decorated_class, _initClass4] = babelHelpers.applyDecs2301(_Class2, [], [dec]).c), _temp4)(), _decorated_class), 123); -const F = [(new (_temp5 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class4, _ref, void 0), _Class4))(), _decorated_class), 123); +const F = [(new (_G2 = (_G3 = class G {}, [_G, _initClass5] = babelHelpers.applyDecs2301(_G3, [], [dec]).c, _G3), (_Class6 = class extends babelHelpers.identity { constructor() { super(_G), (() => {})(), _initClass5(); } -}, (_G2 => { - class G {} - _G2 = G; - [_G, _initClass5] = babelHelpers.applyDecs2301(_G2, [], [dec]).c; -})(), _temp5)(), _G), (new (_temp6 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class6, _G2, void 0), _Class6))(), _G), (new (_ref2 = (_Class8 = class _ref2 {}, [_decorated_class2, _initClass6] = babelHelpers.applyDecs2301(_Class8, [], [dec]).c, _Class8), (_Class7 = class extends babelHelpers.identity { constructor() { super(_decorated_class2), (() => {})(), _initClass6(); } -}, (_Class3 = class {}, [_decorated_class2, _initClass6] = babelHelpers.applyDecs2301(_Class3, [], [dec]).c), _temp6)(), _decorated_class2)]; -const H = (new (_temp7 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class7, _ref2, void 0), _Class7))(), _decorated_class2)]; +const H = (new (_H2 = (_H3 = class H extends I {}, [_H, _initClass7] = babelHelpers.applyDecs2301(_H3, [], [dec]).c, _H3), (_Class9 = class extends babelHelpers.identity { constructor() { super(_H), (() => {})(), _initClass7(); } -}, (_H2 => { - class H extends I {} - _H2 = H; - [_H, _initClass7] = babelHelpers.applyDecs2301(_H2, [], [dec]).c; -})(), _temp7)(), _H); -const J = (new (_temp8 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class9, _H2, void 0), _Class9))(), _H); +const J = (new (_K2 = (_K3 = class K extends L {}, [_K, _initClass8] = babelHelpers.applyDecs2301(_K3, [], [dec]).c, _K3), (_Class10 = class extends babelHelpers.identity { constructor() { super(_K), (() => {})(), _initClass8(); } -}, (_K2 => { - class K extends L {} - _K2 = K; - [_K, _initClass8] = babelHelpers.applyDecs2301(_K2, [], [dec]).c; -})(), _temp8)(), _K); +}, babelHelpers.defineProperty(_Class10, _K2, void 0), _Class10))(), _K); function classFactory() { - var _initClass9, _decorated_class3, _temp9, _Class5; - return new (_temp9 = class extends babelHelpers.identity { + let _ref3; + var _initClass9, _decorated_class3, _Class11, _Class12; + return new (_ref3 = (_Class12 = class _ref3 {}, [_decorated_class3, _initClass9] = babelHelpers.applyDecs2301(_Class12, [], [dec]).c, _Class12), (_Class11 = class extends babelHelpers.identity { constructor() { super(_decorated_class3), (() => {})(), _initClass9(); } - }, (_Class5 = class {}, [_decorated_class3, _initClass9] = babelHelpers.applyDecs2301(_Class5, [], [dec]).c), _temp9)(), _decorated_class3; + }, babelHelpers.defineProperty(_Class11, _ref3, void 0), _Class11))(), _decorated_class3; } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/initializers/output.js index cd3b2f57ab1a..6defa258445e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/initializers/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/initializers/output.js @@ -1,24 +1,17 @@ -var _initClass, _temp, _initClass2, _temp2; +let _Foo2, _Bar2; +var _initClass, _Class, _Foo3, _initClass2, _Class2, _Bar3; const dec = () => {}; let _Foo; -new (_temp = class extends babelHelpers.identity { +new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs2301(_Foo3, [], [dec]).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "field", 123)), _initClass(); } -}, (_Foo2 => { - class Foo {} - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2301(_Foo2, [], [dec]).c; -})(), _temp)(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); let _Bar; -new (_temp2 = class extends babelHelpers.identity { +new (_Bar2 = (_Bar3 = class Bar extends _Foo {}, [_Bar, _initClass2] = babelHelpers.applyDecs2301(_Bar3, [], [dec]).c, _Bar3), (_Class2 = class extends babelHelpers.identity { constructor() { (super(_Bar), babelHelpers.defineProperty(this, "field", ((() => { this.otherField = 456; })(), 123))), _initClass2(); } -}, (_Bar2 => { - class Bar extends _Foo {} - _Bar2 = Bar; - [_Bar, _initClass2] = babelHelpers.applyDecs2301(_Bar2, [], [dec]).c; -})(), _temp2)(); +}, babelHelpers.defineProperty(_Class2, _Bar2, void 0), _Class2))(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/replacement-static-installed-on-correct-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/replacement-static-installed-on-correct-class/output.js index 56cf9658b3bf..c379fdc1c08f 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/replacement-static-installed-on-correct-class/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/replacement-static-installed-on-correct-class/output.js @@ -1,8 +1,17 @@ -var _initClass, _x, _A, _Class_brand, _B, _temp; +let _Foo2; +var _initClass, _Class, _x, _A, _Class_brand, _B, _Foo3; const dec = () => {}; let hasX, hasA, hasM; let _Foo; -new (_x = /*#__PURE__*/new WeakMap(), _A = /*#__PURE__*/new WeakMap(), _Class_brand = /*#__PURE__*/new WeakSet(), _B = /*#__PURE__*/new WeakMap(), (_temp = class extends babelHelpers.identity { +new (_x = /*#__PURE__*/new WeakMap(), _A = /*#__PURE__*/new WeakMap(), _Class_brand = /*#__PURE__*/new WeakSet(), _B = /*#__PURE__*/new WeakMap(), _Foo2 = (_Foo3 = class Foo { + static get a() { + return babelHelpers.classPrivateFieldGet2(_B, this); + } + static set a(v) { + babelHelpers.classPrivateFieldSet2(_B, this, v); + } + static m() {} +}, [_Foo, _initClass] = babelHelpers.applyDecs2301(_Foo3, [], [dec]).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.classPrivateMethodInitSpec(this, _Class_brand), babelHelpers.classPrivateFieldInitSpec(this, _x, void 0), babelHelpers.classPrivateFieldInitSpec(this, _A, void 0), babelHelpers.defineProperty(this, "x", void 0), babelHelpers.classPrivateFieldInitSpec(this, _B, void 0), this), (() => { hasX = o => _x.has(babelHelpers.checkInRHS(o)); @@ -10,19 +19,7 @@ new (_x = /*#__PURE__*/new WeakMap(), _A = /*#__PURE__*/new WeakMap(), _Class_br hasM = o => _Class_brand.has(babelHelpers.checkInRHS(o)); })(), _initClass(); } -}, (_Foo2 => { - class Foo { - static get a() { - return babelHelpers.classPrivateFieldGet2(_B, this); - } - static set a(v) { - babelHelpers.classPrivateFieldSet2(_B, this, v); - } - static m() {} - } - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2301(_Foo2, [], [dec]).c; -})(), _temp))(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); function _get_a(_this) { return babelHelpers.classPrivateFieldGet2(_A, _this); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/replacement-static-this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/replacement-static-this/output.js index e674c50a0598..c915a6f7168a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/replacement-static-this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/replacement-static-this/output.js @@ -1,7 +1,8 @@ -var _initClass, _temp; +let _Foo2; +var _initClass, _Class, _Foo3; const dec = () => {}; let _Foo; -new (_temp = class extends babelHelpers.identity { +new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs2301(_Foo3, [], [dec]).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "field", ((() => { this; @@ -9,8 +10,4 @@ new (_temp = class extends babelHelpers.identity { this; })(), _initClass(); } -}, (_Foo2 => { - class Foo {} - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2301(_Foo2, [], [dec]).c; -})(), _temp)(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/replacement/output.js index 13713b593434..437acdd5e97a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/replacement/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes--to-es2015/replacement/output.js @@ -1,13 +1,10 @@ -var _initClass, _temp; +let _Foo2; +var _initClass, _Class, _Foo3; const dec = () => {}; let _Foo; -new (_temp = class extends babelHelpers.identity { +new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs2301(_Foo3, [], [dec]).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "foo", new _Foo())), _initClass(); } -}, (_Foo2 => { - class Foo {} - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2301(_Foo2, [], [dec]).c; -})(), _temp)(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); const foo = new _Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/expressions-static-blocks/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/expressions-static-blocks/output.js index 0eaacf73aea2..c5fdd742242e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/expressions-static-blocks/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/expressions-static-blocks/output.js @@ -1,96 +1,80 @@ var _initClass, _A, _initClass2, _C, _initClass3, _D, _initClass4, _decorated_class, _initClass5, _G, _initClass6, _decorated_class2, _initClass7, _H, _initClass8, _K; const dec = () => {}; const A = (new class extends babelHelpers.identity { - static { - class A { - static { - [_A, _initClass] = babelHelpers.applyDecs2301(this, [], [dec]).c; - } + static [class A { + static { + [_A, _initClass] = babelHelpers.applyDecs2301(this, [], [dec]).c; } - } + }]; constructor() { super(_A), (() => {})(), _initClass(); } }(), _A); const B = (new class extends babelHelpers.identity { - static { - class C { - static { - [_C, _initClass2] = babelHelpers.applyDecs2301(this, [], [dec]).c; - } + static [class C { + static { + [_C, _initClass2] = babelHelpers.applyDecs2301(this, [], [dec]).c; } - } + }]; constructor() { super(_C), (() => {})(), _initClass2(); } }(), _C); const D = (new class extends babelHelpers.identity { - static { - class D { - static { - [_D, _initClass3] = babelHelpers.applyDecs2301(this, [], [dec]).c; - } + static [class D { + static { + [_D, _initClass3] = babelHelpers.applyDecs2301(this, [], [dec]).c; } - } + }]; constructor() { super(_D), (() => {})(), _initClass3(); } }(), _D); const E = ((new class extends babelHelpers.identity { - static { - (class { - static { - [_decorated_class, _initClass4] = babelHelpers.applyDecs2301(this, [], [dec]).c; - } - }); - } + static [class { + static { + [_decorated_class, _initClass4] = babelHelpers.applyDecs2301(this, [], [dec]).c; + } + }]; constructor() { super(_decorated_class), (() => {})(), _initClass4(); } }(), _decorated_class), 123); const F = [(new class extends babelHelpers.identity { - static { - class G { - static { - [_G, _initClass5] = babelHelpers.applyDecs2301(this, [], [dec]).c; - } + static [class G { + static { + [_G, _initClass5] = babelHelpers.applyDecs2301(this, [], [dec]).c; } - } + }]; constructor() { super(_G), (() => {})(), _initClass5(); } }(), _G), (new class extends babelHelpers.identity { - static { - (class { - static { - [_decorated_class2, _initClass6] = babelHelpers.applyDecs2301(this, [], [dec]).c; - } - }); - } + static [class { + static { + [_decorated_class2, _initClass6] = babelHelpers.applyDecs2301(this, [], [dec]).c; + } + }]; constructor() { super(_decorated_class2), (() => {})(), _initClass6(); } }(), _decorated_class2)]; const H = (new class extends babelHelpers.identity { - static { - class H extends I { - static { - [_H, _initClass7] = babelHelpers.applyDecs2301(this, [], [dec]).c; - } + static [class H extends I { + static { + [_H, _initClass7] = babelHelpers.applyDecs2301(this, [], [dec]).c; } - } + }]; constructor() { super(_H), (() => {})(), _initClass7(); } }(), _H); const J = (new class extends babelHelpers.identity { - static { - class K extends L { - static { - [_K, _initClass8] = babelHelpers.applyDecs2301(this, [], [dec]).c; - } + static [class K extends L { + static { + [_K, _initClass8] = babelHelpers.applyDecs2301(this, [], [dec]).c; } - } + }]; constructor() { super(_K), (() => {})(), _initClass8(); } @@ -98,13 +82,11 @@ const J = (new class extends babelHelpers.identity { function classFactory() { var _initClass9, _decorated_class3; return new class extends babelHelpers.identity { - static { - (class { - static { - [_decorated_class3, _initClass9] = babelHelpers.applyDecs2301(this, [], [dec]).c; - } - }); - } + static [class { + static { + [_decorated_class3, _initClass9] = babelHelpers.applyDecs2301(this, [], [dec]).c; + } + }]; constructor() { super(_decorated_class3), (() => {})(), _initClass9(); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/initializers/output.js index c1faba79db32..13ec64c6d754 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/initializers/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/initializers/output.js @@ -2,13 +2,11 @@ var _initClass, _initClass2; const dec = () => {}; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2301(this, [], [dec]).c; - } + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2301(this, [], [dec]).c; } - } + }]; field = 123; constructor() { super(_Foo), _initClass(); @@ -16,13 +14,11 @@ new class extends babelHelpers.identity { }(); let _Bar; new class extends babelHelpers.identity { - static { - class Bar extends _Foo { - static { - [_Bar, _initClass2] = babelHelpers.applyDecs2301(this, [], [dec]).c; - } + static [class Bar extends _Foo { + static { + [_Bar, _initClass2] = babelHelpers.applyDecs2301(this, [], [dec]).c; } - } + }]; field = ((() => { this.otherField = 456; })(), 123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/replacement-static-installed-on-correct-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/replacement-static-installed-on-correct-class/output.js index bd9e707be02f..ced304f54cf3 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/replacement-static-installed-on-correct-class/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/replacement-static-installed-on-correct-class/output.js @@ -3,20 +3,18 @@ const dec = () => {}; let hasX, hasA, hasM; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2301(this, [], [dec]).c; - } - static get a() { - return this.#B; - } - static set a(v) { - this.#B = v; - } - static m() {} + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2301(this, [], [dec]).c; } - } + static get a() { + return this.#B; + } + static set a(v) { + this.#B = v; + } + static m() {} + }]; #x; #A; get #a() { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/replacement-static-this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/replacement-static-this/output.js index f92f9c39a1b9..1c2dcaec55f1 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/replacement-static-this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/replacement-static-this/output.js @@ -2,13 +2,11 @@ var _initClass; const dec = () => {}; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2301(this, [], [dec]).c; - } + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2301(this, [], [dec]).c; } - } + }]; field = ((() => { this; })(), this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/replacement/output.js index 07f11fb76c4f..ca5dfa8c6d18 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/replacement/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-classes/replacement/output.js @@ -2,13 +2,11 @@ var _initClass; const dec = () => {}; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2301(this, [], [dec]).c; - } + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2301(this, [], [dec]).c; } - } + }]; foo = new _Foo(); constructor() { super(_Foo), _initClass(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys--to-es2015/computed-keys-same-ast/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys--to-es2015/computed-keys-same-ast/output.js index 0a1280bdc166..e1b1a7a9570c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys--to-es2015/computed-keys-same-ast/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys--to-es2015/computed-keys-same-ast/output.js @@ -1,4 +1,5 @@ -var _initProto, _computedKey, _computedKey2, _Foo; +let _computedKey, _computedKey2; +var _initProto, _Foo; const dec = () => {}; _computedKey = babelHelpers.toPropertyKey(getKey()); _computedKey2 = babelHelpers.toPropertyKey(getKey()); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys--to-es2015/computed-keys-same-value/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys--to-es2015/computed-keys-same-value/output.js index 2714d6799d97..286564212033 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys--to-es2015/computed-keys-same-value/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys--to-es2015/computed-keys-same-value/output.js @@ -1,4 +1,5 @@ -var _initProto, _computedKey, _computedKey2, _Foo; +let _computedKey, _computedKey2; +var _initProto, _Foo; const dec = () => {}; _computedKey = babelHelpers.toPropertyKey(getKeyI()); _computedKey2 = babelHelpers.toPropertyKey(getKeyJ()); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys/computed-keys-same-ast/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys/computed-keys-same-ast/output.js index 32feb69e4383..28b05f354c7c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys/computed-keys-same-ast/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys/computed-keys-same-ast/output.js @@ -1,7 +1,6 @@ -var _initProto, _computedKey, _computedKey2; +let _computedKey, _computedKey2; +var _initProto; const dec = () => {}; -_computedKey = babelHelpers.toPropertyKey(getKey()); -_computedKey2 = babelHelpers.toPropertyKey(getKey()); class Foo { static { [_initProto] = babelHelpers.applyDecs2301(this, [[dec, 2, _computedKey], [dec, 2, _computedKey2]], []).e; @@ -9,10 +8,10 @@ class Foo { constructor() { _initProto(this); } - [_computedKey]() { + [_computedKey = babelHelpers.toPropertyKey(getKey())]() { return 1; } - [_computedKey2]() { + [_computedKey2 = babelHelpers.toPropertyKey(getKey())]() { return 2; } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys/computed-keys-same-value/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys/computed-keys-same-value/output.js index 7563353fc572..82e662a6da00 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys/computed-keys-same-value/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-duplicated-keys/computed-keys-same-value/output.js @@ -1,7 +1,6 @@ -var _initProto, _computedKey, _computedKey2; +let _computedKey, _computedKey2; +var _initProto; const dec = () => {}; -_computedKey = babelHelpers.toPropertyKey(getKeyI()); -_computedKey2 = babelHelpers.toPropertyKey(getKeyJ()); class Foo { static { [_initProto] = babelHelpers.applyDecs2301(this, [[dec, 2, _computedKey], [dec, 2, _computedKey2]], []).e; @@ -9,10 +8,10 @@ class Foo { constructor() { _initProto(this); } - [_computedKey]() { + [_computedKey = babelHelpers.toPropertyKey(getKeyI())]() { return 1; } - [_computedKey2]() { + [_computedKey2 = babelHelpers.toPropertyKey(getKeyJ())]() { return 2; } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-exported/member-decorator/output.mjs b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-exported/member-decorator/output.mjs index 5a724bb64030..76d6fda57e6e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-exported/member-decorator/output.mjs +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-exported/member-decorator/output.mjs @@ -1,7 +1,7 @@ var _xDecs, _init_x; -_xDecs = dec; export class A { static { + _xDecs = dec; [_init_x] = babelHelpers.applyDecs2301(this, [[_xDecs, 0, "x"]], []).e; } x = _init_x(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/context-name/output.js index a8ed5cfe9129..b98dc386b101 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7, _Foo; +let _computedKey; +var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields/context-name/output.js index 002e11dc4f0c..dfa1682c71ba 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields/context-name/output.js @@ -1,4 +1,5 @@ -var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7; +let _computedKey; +var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7] = babelHelpers.applyDecs2301(this, [[dec, 5, "a"], [dec, 5, "a", o => o.#a, (o, v) => o.#a = v], [dec, 5, "b"], [dec, 5, "c"], [dec, 5, 0], [dec, 5, 1], [dec, 5, 2n], [dec, 5, 3n], [dec, 5, _computedKey]], []).e; @@ -22,6 +22,6 @@ class Foo { static [1] = _init_computedKey4(this); static 2n = _init_computedKey5(this); static [3n] = _init_computedKey6(this); - static [_computedKey] = _init_computedKey7(this); + static [_computedKey = babelHelpers.toPropertyKey(f())] = _init_computedKey7(this); } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/context-name/output.js index 5ab12f7135b6..8a0b0dc75303 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey, _Foo; +let _computedKey; +var _initStatic, _call_a, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters/context-name/output.js index 0c7f1f296b9a..9d044fa37177 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey; +let _computedKey; +var _initStatic, _call_a; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs2301(this, [[dec, 8, "a"], [dec, 8, "a", function () {}], [dec, 8, "b"], [dec, 8, "c"], [dec, 8, 0], [dec, 8, 1], [dec, 8, 2n], [dec, 8, 3n], [dec, 8, _computedKey]], []).e; @@ -25,6 +25,6 @@ class Foo { static get [1]() {} static get 2n() {} static get [3n]() {} - static get [_computedKey]() {} + static get [_computedKey = babelHelpers.toPropertyKey(f())]() {} } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/context-name/output.js index dbb85cfad6af..9b2164127f53 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey, _Foo; +let _computedKey; +var _initStatic, _call_a, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods/context-name/output.js index cae40ca58080..58e346707b47 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey; +let _computedKey; +var _initStatic, _call_a; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs2301(this, [[dec, 7, "a"], [dec, 7, "a", function () {}], [dec, 7, "b"], [dec, 7, "c"], [dec, 7, 0], [dec, 7, 1], [dec, 7, 2n], [dec, 7, 3n], [dec, 7, _computedKey]], []).e; @@ -23,6 +23,6 @@ class Foo { static [1]() {} static 2n() {} static [3n]() {} - static [_computedKey]() {} + static [_computedKey = babelHelpers.toPropertyKey(f())]() {} } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/initProto-existing-derived-constructor/output.js index be4b92a83737..13bfbddd97cb 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/initProto-existing-derived-constructor/output.js @@ -66,9 +66,10 @@ let log = []; new class Dummy extends B { constructor() { - var _initProto3, _computedKey, _A3; + let _computedKey; + var _initProto3, _A3; let key; - _computedKey = babelHelpers.toPropertyKey((key = super(5).method(), log.push(key), key)); + _computedKey = (key = super(5).method(), log.push(key), key); class A extends B { constructor() { log.push((super(6), babelHelpers.defineProperty(this, _computedKey, void _initProto3(this))).method()); @@ -90,8 +91,8 @@ const noop = () => fn => fn; new class extends B { constructor() { - var _initProto4, _noopDecs, _A4; - _noopDecs = noop(log.push(super(7).method())); + var _initProto4, _noopDecs, _outerSuper, _A4; + _outerSuper = (...args) => super(...args); class A extends B { constructor() { log.push(_initProto4(super(8)).method()); @@ -102,7 +103,10 @@ noop() {} } _A4 = A; - [_initProto4] = babelHelpers.applyDecs2301(_A4, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []).e; + (() => { + _noopDecs = noop(log.push(_outerSuper(7).method())); + [_initProto4] = babelHelpers.applyDecs2301(_A4, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []).e; + })(); new A(); } }(); @@ -138,13 +142,16 @@ const noop = () => fn => fn; class A extends B { constructor() { - var _initProto7, _noopDecs2, _Dummy2; - new (_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), (_Dummy2 = class Dummy extends B { + var _initProto7, _noopDecs2, _outerSuper2, _Dummy2; + new (_outerSuper2 = (...args) => super(...args), (_Dummy2 = class Dummy extends B { constructor() { log.push(_initProto7(super(12)).method()); } noop() {} - }, [_initProto7] = babelHelpers.applyDecs2301(_Dummy2, [[_noopDecs2, 2, "noop"]], []).e, _Dummy2))(); + }, (() => { + _noopDecs2 = noop(log.push(_initProto6(_outerSuper2(11)).method())); + [_initProto7] = babelHelpers.applyDecs2301(_Dummy2, [[_noopDecs2, 2, "noop"]], []).e; + })(), _Dummy2))(); } method() { return this.a; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/valid-expression-formats/output.js index 10771b2f5943..f3fdbfb2d2f5 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/valid-expression-formats/output.js @@ -1,7 +1,6 @@ var _initProto, _initClass, _classDecs, _methodDecs, _Foo2; const dec = () => {}; _classDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; -_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; let _Foo; var _a = /*#__PURE__*/new WeakMap(); class Foo { @@ -10,17 +9,23 @@ class Foo { } method() {} makeClass() { - var _barDecs, _init_bar, _Nested; - return _barDecs = babelHelpers.classPrivateFieldGet2(_a, this), (_Nested = class Nested { + var _barDecs, _init_bar, _outerThis, _Nested; + return _outerThis = this, (_Nested = class Nested { constructor() { babelHelpers.defineProperty(this, "bar", _init_bar(this)); } - }, [_init_bar] = babelHelpers.applyDecs2301(_Nested, [[_barDecs, 0, "bar"]], []).e, _Nested); + }, (() => { + _barDecs = babelHelpers.classPrivateFieldGet2(_a, _outerThis); + [_init_bar] = babelHelpers.applyDecs2301(_Nested, [[_barDecs, 0, "bar"]], []).e; + })(), _Nested); } } _Foo2 = Foo; -({ - e: [_initProto], - c: [_Foo, _initClass] -} = babelHelpers.applyDecs2301(_Foo2, [[_methodDecs, 2, "method"]], _classDecs)); +(() => { + _methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; + ({ + e: [_initProto], + c: [_Foo, _initClass] + } = babelHelpers.applyDecs2301(_Foo2, [[_methodDecs, 2, "method"]], _classDecs)); +})(); _initClass(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/all-decorators/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/all-decorators/output.js index c35c68ccaa54..80b19f50dadc 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/all-decorators/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/all-decorators/output.js @@ -2,52 +2,50 @@ var _initProto, _initStatic, _initClass, _init_a, _init_d, _init_e, _call_f, _ca const dec = () => {}; let _Class; new class extends babelHelpers.identity { - static { - class Class { - static { - ({ - e: [_init_m, _call_o, _call_p, _call_q, _init_r, _get_r, _set_r, _init_d, _call_f, _call_g, _call_g2, _init_h, _get_h, _set_h, _init_i, _init_n, _init_a, _init_e, _initProto, _initStatic], - c: [_Class, _initClass] - } = babelHelpers.applyDecs2301(this, [[dec, 7, "j"], [dec, 8, "k"], [dec, 9, "l"], [dec, 6, "m"], [dec, 7, "o", function () {}], [dec, 8, "p", function () {}], [dec, 9, "q", function (v) {}], [dec, 6, "r", o => o.#D, (o, v) => o.#D = v], [dec, 2, "b"], [dec, 3, "c"], [dec, 4, "c"], [dec, 1, "d"], [dec, 2, "f", function () {}], [dec, 3, "g", function () {}], [dec, 4, "g", function (v) {}], [dec, 1, "h", o => o.#B, (o, v) => o.#B = v], [dec, 5, "i"], [dec, 5, "n", o => o.#n, (o, v) => o.#n = v], [dec, 0, "a"], [dec, 0, "e", o => o.#e, (o, v) => o.#e = v]], [dec], _ => #e in _)); - _initStatic(this); - } - #f = _call_f; - a = (_initProto(this), _init_a(this)); - b() {} - get c() {} - set c(v) {} - #A = _init_d(this); - get d() { - return this.#A; - } - set d(v) { - this.#A = v; - } - #e = _init_e(this); - get #g() { - return _call_g(this); - } - set #g(v) { - _call_g2(this, v); - } - #B = _init_h(this); - set #h(v) { - _set_h(this, v); - } - get #h() { - return _get_h(this); - } - static j() {} - static get k() {} - static set l(v) {} - static get m() { - return this.#C; - } - static set m(v) { - this.#C = v; - } + static [class Class { + static { + ({ + e: [_init_m, _call_o, _call_p, _call_q, _init_r, _get_r, _set_r, _init_d, _call_f, _call_g, _call_g2, _init_h, _get_h, _set_h, _init_i, _init_n, _init_a, _init_e, _initProto, _initStatic], + c: [_Class, _initClass] + } = babelHelpers.applyDecs2301(this, [[dec, 7, "j"], [dec, 8, "k"], [dec, 9, "l"], [dec, 6, "m"], [dec, 7, "o", function () {}], [dec, 8, "p", function () {}], [dec, 9, "q", function (v) {}], [dec, 6, "r", o => o.#D, (o, v) => o.#D = v], [dec, 2, "b"], [dec, 3, "c"], [dec, 4, "c"], [dec, 1, "d"], [dec, 2, "f", function () {}], [dec, 3, "g", function () {}], [dec, 4, "g", function (v) {}], [dec, 1, "h", o => o.#B, (o, v) => o.#B = v], [dec, 5, "i"], [dec, 5, "n", o => o.#n, (o, v) => o.#n = v], [dec, 0, "a"], [dec, 0, "e", o => o.#e, (o, v) => o.#e = v]], [dec], _ => #e in _)); + _initStatic(this); } - } + #f = _call_f; + a = (_initProto(this), _init_a(this)); + b() {} + get c() {} + set c(v) {} + #A = _init_d(this); + get d() { + return this.#A; + } + set d(v) { + this.#A = v; + } + #e = _init_e(this); + get #g() { + return _call_g(this); + } + set #g(v) { + _call_g2(this, v); + } + #B = _init_h(this); + set #h(v) { + _set_h(this, v); + } + get #h() { + return _get_h(this); + } + static j() {} + static get k() {} + static set l(v) {} + static get m() { + return this.#C; + } + static set m(v) { + this.#C = v; + } + }]; #o = _call_o; i = _init_i(this); #C = _init_m(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor-multiple-super/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor-multiple-super/output.js index 782ee9172098..e599954eb6c1 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor-multiple-super/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor-multiple-super/output.js @@ -1,8 +1,8 @@ var _initProto, _methodDecs, _initProto2, _methodDecs2; const dec = () => {}; -_methodDecs = deco; class A extends B { static { + _methodDecs = deco; [_initProto] = babelHelpers.applyDecs2301(this, [[_methodDecs, 2, "method"]], []).e; } constructor() { @@ -14,9 +14,9 @@ class A extends B { } method() {} } -_methodDecs2 = deco; class C extends B { static { + _methodDecs2 = deco; [_initProto2] = babelHelpers.applyDecs2301(this, [[_methodDecs2, 2, "method"]], []).e; } constructor() { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor/output.js index c7fb2688ca6c..3f54829ce781 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor/output.js @@ -68,9 +68,9 @@ let log = []; new class Dummy extends B { constructor() { - var _initProto3, _computedKey; + let _computedKey; + var _initProto3; let key; - _computedKey = babelHelpers.toPropertyKey((key = super(5).method(), log.push(key), key)); class A extends B { static { [_initProto3] = babelHelpers.applyDecs2301(this, [[dec, 2, "method"]], []).e; @@ -81,7 +81,7 @@ method() { return this.a; } - [_computedKey] = void _initProto3(this); + [_computedKey = (key = super(5).method(), log.push(key), key)] = void _initProto3(this); } new A(); } @@ -94,10 +94,11 @@ const noop = () => fn => fn; new class extends B { constructor() { - var _initProto4, _noopDecs; - _noopDecs = noop(log.push(super(7).method())); + var _initProto4, _noopDecs, _outerSuper; + _outerSuper = (...args) => super(...args); class A extends B { static { + _noopDecs = noop(log.push(_outerSuper(7).method())); [_initProto4] = babelHelpers.applyDecs2301(this, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []).e; } constructor() { @@ -147,9 +148,10 @@ [_initProto6] = babelHelpers.applyDecs2301(this, [[dec, 2, "method"]], []).e; } constructor() { - var _initProto7, _noopDecs2; - new (_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), class Dummy extends B { + var _initProto7, _noopDecs2, _outerSuper2; + new (_outerSuper2 = (...args) => super(...args), class Dummy extends B { static { + _noopDecs2 = noop(log.push(_initProto6(_outerSuper2(11)).method())); [_initProto7] = babelHelpers.applyDecs2301(this, [[_noopDecs2, 2, "noop"]], []).e; } constructor() { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/valid-expression-formats/output.js index 8c4c2ef1539e..dadeba29ab56 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/valid-expression-formats/output.js @@ -1,10 +1,10 @@ var _initProto, _initClass, _classDecs, _methodDecs; const dec = () => {}; _classDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; -_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; let _Foo; class Foo { static { + _methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; ({ e: [_initProto], c: [_Foo, _initClass] @@ -13,9 +13,10 @@ class Foo { #a = void _initProto(this); method() {} makeClass() { - var _barDecs, _init_bar; - return _barDecs = this.#a, class Nested { + var _barDecs, _init_bar, _outerThis; + return _outerThis = this, class Nested { static { + _barDecs = _outerThis.#a; [_init_bar] = babelHelpers.applyDecs2301(this, [[_barDecs, 0, "bar"]], []).e; } bar = _init_bar(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/context-name/output.js index a1ce003fc1e2..5b349bf2f06e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey, _Foo; +let _computedKey; +var _initStatic, _call_a, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters/context-name/output.js index f49f74d534e7..906748b8525a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey; +let _computedKey; +var _initStatic, _call_a; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs2301(this, [[dec, 9, "a"], [dec, 9, "a", function (v) {}], [dec, 9, "b"], [dec, 9, "c"], [dec, 9, 0], [dec, 9, 1], [dec, 9, 2n], [dec, 9, 3n], [dec, 9, _computedKey]], []).e; @@ -25,6 +25,6 @@ class Foo { static set [1](v) {} static set 2n(v) {} static set [3n](v) {} - static set [_computedKey](v) {} + static set [_computedKey = babelHelpers.toPropertyKey(f())](v) {} } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-accessors--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-accessors--to-es2015/context-name/output.js index 114d23eab997..18b1d37c0b82 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-accessors--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-accessors--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7, _Foo; +let _computedKey; +var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-accessors/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-accessors/context-name/output.js index f430ae1bb369..ffe94251373b 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-accessors/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-accessors/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7; +let _computedKey; +var _initStatic, _init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7, _initStatic] = babelHelpers.applyDecs2305(this, [[dec, 9, "a"], [dec, 9, "a", o => o.#B, (o, v) => o.#B = v], [dec, 9, "b"], [dec, 9, "c"], [dec, 9, 0], [dec, 9, 1], [dec, 9, 2n], [dec, 9, 3n], [dec, 9, _computedKey]], []).e; @@ -72,7 +72,7 @@ class Foo { Foo.#H = v; } static #I = _init_computedKey7(this); - static get [_computedKey]() { + static get [_computedKey = babelHelpers.toPropertyKey(f())]() { return Foo.#I; } static set [_computedKey](v) { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/expressions-static-blocks/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/expressions-static-blocks/output.js index d6df0f071d05..9b1c374c6d54 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/expressions-static-blocks/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/expressions-static-blocks/output.js @@ -1,73 +1,51 @@ -var _initClass, _A, _temp, _initClass2, _C, _temp2, _initClass3, _D, _temp3, _initClass4, _decorated_class, _temp4, _Class2, _initClass5, _G, _temp5, _initClass6, _decorated_class2, _temp6, _Class3, _initClass7, _H, _I, _temp7, _initClass8, _K, _L, _temp8; +let _A2, _C2, _D2, _ref, _G2, _ref2, _H2, _K2; +var _initClass, _A, _Class, _A3, _initClass2, _C, _Class2, _C3, _initClass3, _D, _Class3, _D3, _initClass4, _decorated_class, _Class4, _Class5, _initClass5, _G, _Class6, _G3, _initClass6, _decorated_class2, _Class7, _Class8, _initClass7, _H, _I, _Class9, _H3, _initClass8, _K, _L, _Class10, _K3; const dec = () => {}; -const A = (new (_temp = class extends babelHelpers.identity { +const A = (new (_A2 = (_A3 = class A {}, [_A, _initClass] = babelHelpers.applyDecs2305(_A3, [], [dec]).c, _A3), (_Class = class extends babelHelpers.identity { constructor() { super(_A), (() => {})(), _initClass(); } -}, (_A2 => { - class A {} - _A2 = A; - [_A, _initClass] = babelHelpers.applyDecs2305(_A2, [], [dec]).c; -})(), _temp)(), _A); -const B = (new (_temp2 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class, _A2, void 0), _Class))(), _A); +const B = (new (_C2 = (_C3 = class C {}, [_C, _initClass2] = babelHelpers.applyDecs2305(_C3, [], [dec]).c, _C3), (_Class2 = class extends babelHelpers.identity { constructor() { super(_C), (() => {})(), _initClass2(); } -}, (_C2 => { - class C {} - _C2 = C; - [_C, _initClass2] = babelHelpers.applyDecs2305(_C2, [], [dec]).c; -})(), _temp2)(), _C); -const D = (new (_temp3 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class2, _C2, void 0), _Class2))(), _C); +const D = (new (_D2 = (_D3 = class D {}, [_D, _initClass3] = babelHelpers.applyDecs2305(_D3, [], [dec]).c, _D3), (_Class3 = class extends babelHelpers.identity { constructor() { super(_D), (() => {})(), _initClass3(); } -}, (_D2 => { - class D {} - _D2 = D; - [_D, _initClass3] = babelHelpers.applyDecs2305(_D2, [], [dec]).c; -})(), _temp3)(), _D); -const E = ((new (_temp4 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class3, _D2, void 0), _Class3))(), _D); +const E = ((new (_ref = (_Class5 = class _ref {}, [_decorated_class, _initClass4] = babelHelpers.applyDecs2305(_Class5, [], [dec]).c, _Class5), (_Class4 = class extends babelHelpers.identity { constructor() { super(_decorated_class), (() => {})(), _initClass4(); } -}, (_Class2 = class {}, [_decorated_class, _initClass4] = babelHelpers.applyDecs2305(_Class2, [], [dec]).c), _temp4)(), _decorated_class), 123); -const F = [(new (_temp5 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class4, _ref, void 0), _Class4))(), _decorated_class), 123); +const F = [(new (_G2 = (_G3 = class G {}, [_G, _initClass5] = babelHelpers.applyDecs2305(_G3, [], [dec]).c, _G3), (_Class6 = class extends babelHelpers.identity { constructor() { super(_G), (() => {})(), _initClass5(); } -}, (_G2 => { - class G {} - _G2 = G; - [_G, _initClass5] = babelHelpers.applyDecs2305(_G2, [], [dec]).c; -})(), _temp5)(), _G), (new (_temp6 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class6, _G2, void 0), _Class6))(), _G), (new (_ref2 = (_Class8 = class _ref2 {}, [_decorated_class2, _initClass6] = babelHelpers.applyDecs2305(_Class8, [], [dec]).c, _Class8), (_Class7 = class extends babelHelpers.identity { constructor() { super(_decorated_class2), (() => {})(), _initClass6(); } -}, (_Class3 = class {}, [_decorated_class2, _initClass6] = babelHelpers.applyDecs2305(_Class3, [], [dec]).c), _temp6)(), _decorated_class2)]; -const H = (new (_temp7 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class7, _ref2, void 0), _Class7))(), _decorated_class2)]; +const H = (new (_H2 = (_H3 = class H extends (_I = I) {}, [_H, _initClass7] = babelHelpers.applyDecs2305(_H3, [], [dec], 0, void 0, _I).c, _H3), (_Class9 = class extends babelHelpers.identity { constructor() { super(_H), (() => {})(), _initClass7(); } -}, (_H2 => { - class H extends (_I = I) {} - _H2 = H; - [_H, _initClass7] = babelHelpers.applyDecs2305(_H2, [], [dec], 0, void 0, _I).c; -})(), _temp7)(), _H); -const J = (new (_temp8 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class9, _H2, void 0), _Class9))(), _H); +const J = (new (_K2 = (_K3 = class K extends (_L = L) {}, [_K, _initClass8] = babelHelpers.applyDecs2305(_K3, [], [dec], 0, void 0, _L).c, _K3), (_Class10 = class extends babelHelpers.identity { constructor() { super(_K), (() => {})(), _initClass8(); } -}, (_K2 => { - class K extends (_L = L) {} - _K2 = K; - [_K, _initClass8] = babelHelpers.applyDecs2305(_K2, [], [dec], 0, void 0, _L).c; -})(), _temp8)(), _K); +}, babelHelpers.defineProperty(_Class10, _K2, void 0), _Class10))(), _K); function classFactory() { - var _initClass9, _decorated_class3, _temp9, _Class5; - return new (_temp9 = class extends babelHelpers.identity { + let _ref3; + var _initClass9, _decorated_class3, _Class11, _Class12; + return new (_ref3 = (_Class12 = class _ref3 {}, [_decorated_class3, _initClass9] = babelHelpers.applyDecs2305(_Class12, [], [dec]).c, _Class12), (_Class11 = class extends babelHelpers.identity { constructor() { super(_decorated_class3), (() => {})(), _initClass9(); } - }, (_Class5 = class {}, [_decorated_class3, _initClass9] = babelHelpers.applyDecs2305(_Class5, [], [dec]).c), _temp9)(), _decorated_class3; + }, babelHelpers.defineProperty(_Class11, _ref3, void 0), _Class11))(), _decorated_class3; } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/initializers/output.js index 210989e0f1c8..f214bd3f782f 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/initializers/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/initializers/output.js @@ -1,24 +1,17 @@ -var _initClass, _temp, _initClass2, _Foo3, _temp2; +let _Foo2, _Bar2; +var _initClass, _Class, _Foo3, _initClass2, _Foo4, _Class2, _Bar3; const dec = () => {}; let _Foo; -new (_temp = class extends babelHelpers.identity { +new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs2305(_Foo3, [], [dec]).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "field", 123)), _initClass(); } -}, (_Foo2 => { - class Foo {} - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2305(_Foo2, [], [dec]).c; -})(), _temp)(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); let _Bar; -new (_temp2 = class extends babelHelpers.identity { +new (_Bar2 = (_Bar3 = class Bar extends (_Foo4 = _Foo) {}, [_Bar, _initClass2] = babelHelpers.applyDecs2305(_Bar3, [], [dec], 0, void 0, _Foo4).c, _Bar3), (_Class2 = class extends babelHelpers.identity { constructor() { (super(_Bar), babelHelpers.defineProperty(this, "field", ((() => { this.otherField = 456; })(), 123))), _initClass2(); } -}, (_Bar2 => { - class Bar extends (_Foo3 = _Foo) {} - _Bar2 = Bar; - [_Bar, _initClass2] = babelHelpers.applyDecs2305(_Bar2, [], [dec], 0, void 0, _Foo3).c; -})(), _temp2)(); +}, babelHelpers.defineProperty(_Class2, _Bar2, void 0), _Class2))(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/replacement-static-installed-on-correct-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/replacement-static-installed-on-correct-class/output.js index 9633788985c9..7846ce831d06 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/replacement-static-installed-on-correct-class/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/replacement-static-installed-on-correct-class/output.js @@ -1,8 +1,17 @@ -var _initClass, _x, _A, _Class_brand, _B, _temp; +let _Foo2; +var _initClass, _Class, _x, _A, _Class_brand, _B, _Foo3; const dec = () => {}; let hasX, hasA, hasM; let _Foo; -new (_x = /*#__PURE__*/new WeakMap(), _A = /*#__PURE__*/new WeakMap(), _Class_brand = /*#__PURE__*/new WeakSet(), _B = /*#__PURE__*/new WeakMap(), (_temp = class extends babelHelpers.identity { +new (_x = /*#__PURE__*/new WeakMap(), _A = /*#__PURE__*/new WeakMap(), _Class_brand = /*#__PURE__*/new WeakSet(), _B = /*#__PURE__*/new WeakMap(), _Foo2 = (_Foo3 = class Foo { + static get a() { + return babelHelpers.classPrivateFieldGet2(_B, _Foo); + } + static set a(v) { + babelHelpers.classPrivateFieldSet2(_B, _Foo, v); + } + static m() {} +}, [_Foo, _initClass] = babelHelpers.applyDecs2305(_Foo3, [], [dec]).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.classPrivateMethodInitSpec(this, _Class_brand), babelHelpers.classPrivateFieldInitSpec(this, _x, void 0), babelHelpers.classPrivateFieldInitSpec(this, _A, void 0), babelHelpers.defineProperty(this, "x", void 0), babelHelpers.classPrivateFieldInitSpec(this, _B, void 0), this), (() => { hasX = o => _x.has(babelHelpers.checkInRHS(o)); @@ -10,19 +19,7 @@ new (_x = /*#__PURE__*/new WeakMap(), _A = /*#__PURE__*/new WeakMap(), _Class_br hasM = o => _Class_brand.has(babelHelpers.checkInRHS(o)); })(), _initClass(); } -}, (_Foo2 => { - class Foo { - static get a() { - return babelHelpers.classPrivateFieldGet2(_B, _Foo); - } - static set a(v) { - babelHelpers.classPrivateFieldSet2(_B, _Foo, v); - } - static m() {} - } - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2305(_Foo2, [], [dec]).c; -})(), _temp))(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); function _get_a(_this) { return babelHelpers.classPrivateFieldGet2(_A, _Foo); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/replacement-static-this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/replacement-static-this/output.js index b873b5d71557..886653dabd20 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/replacement-static-this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/replacement-static-this/output.js @@ -1,7 +1,8 @@ -var _initClass, _temp; +let _Foo2; +var _initClass, _Class, _Foo3; const dec = () => {}; let _Foo; -new (_temp = class extends babelHelpers.identity { +new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs2305(_Foo3, [], [dec]).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "field", ((() => { this; @@ -9,8 +10,4 @@ new (_temp = class extends babelHelpers.identity { this; })(), _initClass(); } -}, (_Foo2 => { - class Foo {} - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2305(_Foo2, [], [dec]).c; -})(), _temp)(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/replacement/output.js index 53a09e92090f..c6ab4adc25a9 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/replacement/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes--to-es2015/replacement/output.js @@ -1,13 +1,10 @@ -var _initClass, _temp; +let _Foo2; +var _initClass, _Class, _Foo3; const dec = () => {}; let _Foo; -new (_temp = class extends babelHelpers.identity { +new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs2305(_Foo3, [], [dec]).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "foo", new _Foo())), _initClass(); } -}, (_Foo2 => { - class Foo {} - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2305(_Foo2, [], [dec]).c; -})(), _temp)(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); const foo = new _Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/expressions-static-blocks/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/expressions-static-blocks/output.js index de1a7937b050..57177c60ba9e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/expressions-static-blocks/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/expressions-static-blocks/output.js @@ -1,96 +1,80 @@ var _initClass, _A, _initClass2, _C, _initClass3, _D, _initClass4, _decorated_class, _initClass5, _G, _initClass6, _decorated_class2, _initClass7, _H, _I, _initClass8, _K, _L; const dec = () => {}; const A = (new class extends babelHelpers.identity { - static { - class A { - static { - [_A, _initClass] = babelHelpers.applyDecs2305(this, [], [dec]).c; - } + static [class A { + static { + [_A, _initClass] = babelHelpers.applyDecs2305(this, [], [dec]).c; } - } + }]; constructor() { super(_A), (() => {})(), _initClass(); } }(), _A); const B = (new class extends babelHelpers.identity { - static { - class C { - static { - [_C, _initClass2] = babelHelpers.applyDecs2305(this, [], [dec]).c; - } + static [class C { + static { + [_C, _initClass2] = babelHelpers.applyDecs2305(this, [], [dec]).c; } - } + }]; constructor() { super(_C), (() => {})(), _initClass2(); } }(), _C); const D = (new class extends babelHelpers.identity { - static { - class D { - static { - [_D, _initClass3] = babelHelpers.applyDecs2305(this, [], [dec]).c; - } + static [class D { + static { + [_D, _initClass3] = babelHelpers.applyDecs2305(this, [], [dec]).c; } - } + }]; constructor() { super(_D), (() => {})(), _initClass3(); } }(), _D); const E = ((new class extends babelHelpers.identity { - static { - (class { - static { - [_decorated_class, _initClass4] = babelHelpers.applyDecs2305(this, [], [dec]).c; - } - }); - } + static [class { + static { + [_decorated_class, _initClass4] = babelHelpers.applyDecs2305(this, [], [dec]).c; + } + }]; constructor() { super(_decorated_class), (() => {})(), _initClass4(); } }(), _decorated_class), 123); const F = [(new class extends babelHelpers.identity { - static { - class G { - static { - [_G, _initClass5] = babelHelpers.applyDecs2305(this, [], [dec]).c; - } + static [class G { + static { + [_G, _initClass5] = babelHelpers.applyDecs2305(this, [], [dec]).c; } - } + }]; constructor() { super(_G), (() => {})(), _initClass5(); } }(), _G), (new class extends babelHelpers.identity { - static { - (class { - static { - [_decorated_class2, _initClass6] = babelHelpers.applyDecs2305(this, [], [dec]).c; - } - }); - } + static [class { + static { + [_decorated_class2, _initClass6] = babelHelpers.applyDecs2305(this, [], [dec]).c; + } + }]; constructor() { super(_decorated_class2), (() => {})(), _initClass6(); } }(), _decorated_class2)]; const H = (new class extends babelHelpers.identity { - static { - class H extends (_I = I) { - static { - [_H, _initClass7] = babelHelpers.applyDecs2305(this, [], [dec], 0, void 0, _I).c; - } + static [class H extends (_I = I) { + static { + [_H, _initClass7] = babelHelpers.applyDecs2305(this, [], [dec], 0, void 0, _I).c; } - } + }]; constructor() { super(_H), (() => {})(), _initClass7(); } }(), _H); const J = (new class extends babelHelpers.identity { - static { - class K extends (_L = L) { - static { - [_K, _initClass8] = babelHelpers.applyDecs2305(this, [], [dec], 0, void 0, _L).c; - } + static [class K extends (_L = L) { + static { + [_K, _initClass8] = babelHelpers.applyDecs2305(this, [], [dec], 0, void 0, _L).c; } - } + }]; constructor() { super(_K), (() => {})(), _initClass8(); } @@ -98,13 +82,11 @@ const J = (new class extends babelHelpers.identity { function classFactory() { var _initClass9, _decorated_class3; return new class extends babelHelpers.identity { - static { - (class { - static { - [_decorated_class3, _initClass9] = babelHelpers.applyDecs2305(this, [], [dec]).c; - } - }); - } + static [class { + static { + [_decorated_class3, _initClass9] = babelHelpers.applyDecs2305(this, [], [dec]).c; + } + }]; constructor() { super(_decorated_class3), (() => {})(), _initClass9(); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/initializers/output.js index 4b735ae09ec3..204dffeb0f66 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/initializers/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/initializers/output.js @@ -2,13 +2,11 @@ var _initClass, _initClass2, _Foo2; const dec = () => {}; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2305(this, [], [dec]).c; - } + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2305(this, [], [dec]).c; } - } + }]; field = 123; constructor() { super(_Foo), _initClass(); @@ -16,13 +14,11 @@ new class extends babelHelpers.identity { }(); let _Bar; new class extends babelHelpers.identity { - static { - class Bar extends (_Foo2 = _Foo) { - static { - [_Bar, _initClass2] = babelHelpers.applyDecs2305(this, [], [dec], 0, void 0, _Foo2).c; - } + static [class Bar extends (_Foo2 = _Foo) { + static { + [_Bar, _initClass2] = babelHelpers.applyDecs2305(this, [], [dec], 0, void 0, _Foo2).c; } - } + }]; field = ((() => { this.otherField = 456; })(), 123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/replacement-static-installed-on-correct-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/replacement-static-installed-on-correct-class/output.js index 93cf1f1b44d4..81ac999011cb 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/replacement-static-installed-on-correct-class/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/replacement-static-installed-on-correct-class/output.js @@ -3,20 +3,18 @@ const dec = () => {}; let hasX, hasA, hasM; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2305(this, [], [dec]).c; - } - static get a() { - return _Foo.#B; - } - static set a(v) { - _Foo.#B = v; - } - static m() {} + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2305(this, [], [dec]).c; } - } + static get a() { + return _Foo.#B; + } + static set a(v) { + _Foo.#B = v; + } + static m() {} + }]; #x; #A; get #a() { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/replacement-static-this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/replacement-static-this/output.js index 66c8ef5979ee..e98c59821b4a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/replacement-static-this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/replacement-static-this/output.js @@ -2,13 +2,11 @@ var _initClass; const dec = () => {}; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2305(this, [], [dec]).c; - } + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2305(this, [], [dec]).c; } - } + }]; field = ((() => { this; })(), this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/replacement/output.js index fdced4d4f3b7..59dba6ecb10a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/replacement/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-classes/replacement/output.js @@ -2,13 +2,11 @@ var _initClass; const dec = () => {}; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2305(this, [], [dec]).c; - } + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2305(this, [], [dec]).c; } - } + }]; foo = new _Foo(); constructor() { super(_Foo), _initClass(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys--to-es2015/computed-keys-same-ast/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys--to-es2015/computed-keys-same-ast/output.js index 5de2df77fe70..032271afe5aa 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys--to-es2015/computed-keys-same-ast/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys--to-es2015/computed-keys-same-ast/output.js @@ -1,4 +1,5 @@ -var _initProto, _computedKey, _computedKey2, _Foo; +let _computedKey, _computedKey2; +var _initProto, _Foo; const dec = () => {}; _computedKey = babelHelpers.toPropertyKey(getKey()); _computedKey2 = babelHelpers.toPropertyKey(getKey()); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys--to-es2015/computed-keys-same-value/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys--to-es2015/computed-keys-same-value/output.js index 93db66c296a6..740f33e27eb3 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys--to-es2015/computed-keys-same-value/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys--to-es2015/computed-keys-same-value/output.js @@ -1,4 +1,5 @@ -var _initProto, _computedKey, _computedKey2, _Foo; +let _computedKey, _computedKey2; +var _initProto, _Foo; const dec = () => {}; _computedKey = babelHelpers.toPropertyKey(getKeyI()); _computedKey2 = babelHelpers.toPropertyKey(getKeyJ()); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys/computed-keys-same-ast/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys/computed-keys-same-ast/output.js index 81e123b36f38..ed8e1050b680 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys/computed-keys-same-ast/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys/computed-keys-same-ast/output.js @@ -1,7 +1,6 @@ -var _initProto, _computedKey, _computedKey2; +let _computedKey, _computedKey2; +var _initProto; const dec = () => {}; -_computedKey = babelHelpers.toPropertyKey(getKey()); -_computedKey2 = babelHelpers.toPropertyKey(getKey()); class Foo { static { [_initProto] = babelHelpers.applyDecs2305(this, [[dec, 2, _computedKey], [dec, 2, _computedKey2]], []).e; @@ -9,10 +8,10 @@ class Foo { constructor() { _initProto(this); } - [_computedKey]() { + [_computedKey = babelHelpers.toPropertyKey(getKey())]() { return 1; } - [_computedKey2]() { + [_computedKey2 = babelHelpers.toPropertyKey(getKey())]() { return 2; } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys/computed-keys-same-value/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys/computed-keys-same-value/output.js index 6e011fafd2a6..c5afcb78e9fb 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys/computed-keys-same-value/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-duplicated-keys/computed-keys-same-value/output.js @@ -1,7 +1,6 @@ -var _initProto, _computedKey, _computedKey2; +let _computedKey, _computedKey2; +var _initProto; const dec = () => {}; -_computedKey = babelHelpers.toPropertyKey(getKeyI()); -_computedKey2 = babelHelpers.toPropertyKey(getKeyJ()); class Foo { static { [_initProto] = babelHelpers.applyDecs2305(this, [[dec, 2, _computedKey], [dec, 2, _computedKey2]], []).e; @@ -9,10 +8,10 @@ class Foo { constructor() { _initProto(this); } - [_computedKey]() { + [_computedKey = babelHelpers.toPropertyKey(getKeyI())]() { return 1; } - [_computedKey2]() { + [_computedKey2 = babelHelpers.toPropertyKey(getKeyJ())]() { return 2; } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-exported/member-decorator/output.mjs b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-exported/member-decorator/output.mjs index 1e29dea47f87..8f7007de68b7 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-exported/member-decorator/output.mjs +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-exported/member-decorator/output.mjs @@ -1,7 +1,7 @@ var _xDecs, _init_x; -_xDecs = dec; export class A { static { + _xDecs = dec; [_init_x] = babelHelpers.applyDecs2305(this, [[_xDecs, 0, "x"]], []).e; } x = _init_x(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-fields--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-fields--to-es2015/context-name/output.js index 5c19dbb6ed66..da9540d5545c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-fields--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-fields--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7, _Foo; +let _computedKey; +var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-fields/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-fields/context-name/output.js index ca6a780610d7..411bf3477db8 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-fields/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-fields/context-name/output.js @@ -1,4 +1,5 @@ -var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _computedKey, _init_computedKey7; +let _computedKey; +var _init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_init_a, _init_a2, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7] = babelHelpers.applyDecs2305(this, [[dec, 8, "a"], [dec, 8, "a", o => o.#a, (o, v) => o.#a = v], [dec, 8, "b"], [dec, 8, "c"], [dec, 8, 0], [dec, 8, 1], [dec, 8, 2n], [dec, 8, 3n], [dec, 8, _computedKey]], []).e; @@ -22,6 +22,6 @@ class Foo { static [1] = _init_computedKey4(this); static 2n = _init_computedKey5(this); static [3n] = _init_computedKey6(this); - static [_computedKey] = _init_computedKey7(this); + static [_computedKey = babelHelpers.toPropertyKey(f())] = _init_computedKey7(this); } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-getters--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-getters--to-es2015/context-name/output.js index 28ef0a183229..62e4e5b67067 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-getters--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-getters--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey, _Foo; +let _computedKey; +var _initStatic, _call_a, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-getters/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-getters/context-name/output.js index 7f9f54d7a508..907a254a7d5e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-getters/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-getters/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey; +let _computedKey; +var _initStatic, _call_a; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs2305(this, [[dec, 11, "a"], [dec, 11, "a", function () {}], [dec, 11, "b"], [dec, 11, "c"], [dec, 11, 0], [dec, 11, 1], [dec, 11, 2n], [dec, 11, 3n], [dec, 11, _computedKey]], []).e; @@ -25,6 +25,6 @@ class Foo { static get [1]() {} static get 2n() {} static get [3n]() {} - static get [_computedKey]() {} + static get [_computedKey = babelHelpers.toPropertyKey(f())]() {} } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-methods--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-methods--to-es2015/context-name/output.js index d0da98725861..33c00c489dfd 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-methods--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-methods--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey, _Foo; +let _computedKey; +var _initStatic, _call_a, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-methods/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-methods/context-name/output.js index da681900829e..783fc6a71d1e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-methods/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-methods/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey; +let _computedKey; +var _initStatic, _call_a; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs2305(this, [[dec, 10, "a"], [dec, 10, "a", function () {}], [dec, 10, "b"], [dec, 10, "c"], [dec, 10, 0], [dec, 10, 1], [dec, 10, 2n], [dec, 10, 3n], [dec, 10, _computedKey]], []).e; @@ -23,6 +23,6 @@ class Foo { static [1]() {} static 2n() {} static [3n]() {} - static [_computedKey]() {} + static [_computedKey = babelHelpers.toPropertyKey(f())]() {} } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/initProto-existing-derived-constructor/output.js index f299c776a4bf..e854c11ca726 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/initProto-existing-derived-constructor/output.js @@ -66,9 +66,10 @@ let log = []; new class Dummy extends B { constructor() { - var _initProto3, _computedKey, _A3; + let _computedKey; + var _initProto3, _A3; let key; - _computedKey = babelHelpers.toPropertyKey((key = super(5).method(), log.push(key), key)); + _computedKey = (key = super(5).method(), log.push(key), key); class A extends B { constructor() { log.push((super(6), babelHelpers.defineProperty(this, _computedKey, void _initProto3(this))).method()); @@ -90,8 +91,8 @@ const noop = () => fn => fn; new class extends B { constructor() { - var _initProto4, _noopDecs, _A4; - _noopDecs = noop(log.push(super(7).method())); + var _initProto4, _noopDecs, _outerSuper, _A4; + _outerSuper = (...args) => super(...args); class A extends B { constructor() { log.push(_initProto4(super(8)).method()); @@ -102,7 +103,10 @@ noop() {} } _A4 = A; - [_initProto4] = babelHelpers.applyDecs2305(_A4, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], [], 0, void 0, B).e; + (() => { + _noopDecs = noop(log.push(_outerSuper(7).method())); + [_initProto4] = babelHelpers.applyDecs2305(_A4, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], [], 0, void 0, B).e; + })(); new A(); } }(); @@ -138,13 +142,16 @@ const noop = () => fn => fn; class A extends B { constructor() { - var _initProto7, _noopDecs2, _Dummy2; - new (_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), (_Dummy2 = class Dummy extends B { + var _initProto7, _noopDecs2, _outerSuper2, _Dummy2; + new (_outerSuper2 = (...args) => super(...args), (_Dummy2 = class Dummy extends B { constructor() { log.push(_initProto7(super(12)).method()); } noop() {} - }, [_initProto7] = babelHelpers.applyDecs2305(_Dummy2, [[_noopDecs2, 2, "noop"]], [], 0, void 0, B).e, _Dummy2))(); + }, (() => { + _noopDecs2 = noop(log.push(_initProto6(_outerSuper2(11)).method())); + [_initProto7] = babelHelpers.applyDecs2305(_Dummy2, [[_noopDecs2, 2, "noop"]], [], 0, void 0, B).e; + })(), _Dummy2))(); } method() { return this.a; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/super-in-decorator/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/super-in-decorator/output.js index b1b503f32cbf..39bd58f0f9bd 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/super-in-decorator/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/super-in-decorator/output.js @@ -1,8 +1,12 @@ class A extends B { m() { - var _initProto, _initClass, _classDecs, _m2Decs, _C2; + var _initProto, _initClass, _classDecs, _m2Decs, _outerThis, _outerSuperProp, _C2; _classDecs = [this, super.dec1]; - _m2Decs = [this, super.dec2]; + _outerThis = this; + _outerSuperProp = prop => Object.defineProperty({}, "_", { + get: () => super[prop], + set: v => super[prop] = v + }); let _C; class C { constructor() { @@ -11,10 +15,13 @@ class A extends B { m2() {} } _C2 = C; - ({ - e: [_initProto], - c: [_C, _initClass] - } = babelHelpers.applyDecs2305(_C2, [[_m2Decs, 18, "m2"]], _classDecs, 1)); + (() => { + _m2Decs = [_outerThis, _outerSuperProp("dec2")._]; + ({ + e: [_initProto], + c: [_C, _initClass] + } = babelHelpers.applyDecs2305(_C2, [[_m2Decs, 18, "m2"]], _classDecs, 1)); + })(); _initClass(); } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/this/output.js index 82e074666e23..55dd372d474a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/this/output.js @@ -1,7 +1,5 @@ var _initClass, _obj, _classDecs, _xDecs, _init_x, _yDecs, _init_y, _A2; _classDecs = [_obj = o1, _obj.dec, void 0, dec, _obj = o2, _obj.dec]; -_xDecs = [_obj = o2, _obj.dec, _obj = o3.o, _obj.dec]; -_yDecs = [_obj = o2, _obj.dec, void 0, dec]; let _A; class A { constructor() { @@ -10,8 +8,11 @@ class A { } } _A2 = A; -({ - e: [_init_x, _init_y], - c: [_A, _initClass] -} = babelHelpers.applyDecs2305(_A2, [[_xDecs, 16, "x"], [_yDecs, 16, "y"]], _classDecs, 1)); +(() => { + _xDecs = [_obj = o2, _obj.dec, _obj = o3.o, _obj.dec], _yDecs = [_obj = o2, _obj.dec, void 0, dec]; + ({ + e: [_init_x, _init_y], + c: [_A, _initClass] + } = babelHelpers.applyDecs2305(_A2, [[_xDecs, 16, "x"], [_yDecs, 16, "y"]], _classDecs, 1)); +})(); _initClass(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/valid-expression-formats/output.js index 5f511be36470..69802959da7d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/valid-expression-formats/output.js @@ -1,7 +1,6 @@ var _initProto, _initClass, _obj, _classDecs, _methodDecs, _Foo2; const dec = () => {}; _classDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]]; -_methodDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]]; let _Foo; var _a = /*#__PURE__*/new WeakMap(); class Foo { @@ -10,17 +9,23 @@ class Foo { } method() {} makeClass() { - var _barDecs, _init_bar, _Nested; - return _barDecs = babelHelpers.classPrivateFieldGet2(_a, this), (_Nested = class Nested { + var _barDecs, _init_bar, _outerThis, _Nested; + return _outerThis = this, (_Nested = class Nested { constructor() { babelHelpers.defineProperty(this, "bar", _init_bar(this)); } - }, [_init_bar] = babelHelpers.applyDecs2305(_Nested, [[_barDecs, 0, "bar"]], []).e, _Nested); + }, (() => { + _barDecs = babelHelpers.classPrivateFieldGet2(_a, _outerThis); + [_init_bar] = babelHelpers.applyDecs2305(_Nested, [[_barDecs, 0, "bar"]], []).e; + })(), _Nested); } } _Foo2 = Foo; -({ - e: [_initProto], - c: [_Foo, _initClass] -} = babelHelpers.applyDecs2305(_Foo2, [[_methodDecs, 18, "method"]], _classDecs, 1)); +(() => { + _methodDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]]; + ({ + e: [_initProto], + c: [_Foo, _initClass] + } = babelHelpers.applyDecs2305(_Foo2, [[_methodDecs, 18, "method"]], _classDecs, 1)); +})(); _initClass(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/all-decorators/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/all-decorators/output.js index 8ca7a3bf1bb0..1218538ba667 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/all-decorators/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/all-decorators/output.js @@ -2,52 +2,50 @@ var _initProto, _initStatic, _initClass, _init_a, _init_d, _init_e, _call_f, _ca const dec = () => {}; let _Class; new class extends babelHelpers.identity { - static { - class Class { - static { - ({ - e: [_init_m, _call_o, _call_p, _call_q, _init_r, _get_r, _set_r, _init_d, _call_f, _call_g, _call_g2, _init_h, _get_h, _set_h, _init_i, _init_n, _init_a, _init_e, _initProto, _initStatic], - c: [_Class, _initClass] - } = babelHelpers.applyDecs2305(this, [[dec, 10, "j"], [dec, 11, "k"], [dec, 12, "l"], [dec, 9, "m"], [dec, 10, "o", function () {}], [dec, 11, "p", function () {}], [dec, 12, "q", function (v) {}], [dec, 9, "r", o => o.#D, (o, v) => o.#D = v], [dec, 2, "b"], [dec, 3, "c"], [dec, 4, "c"], [dec, 1, "d"], [dec, 2, "f", function () {}], [dec, 3, "g", function () {}], [dec, 4, "g", function (v) {}], [dec, 1, "h", o => o.#B, (o, v) => o.#B = v], [dec, 8, "i"], [dec, 8, "n", o => o.#n, (o, v) => o.#n = v], [dec, 0, "a"], [dec, 0, "e", o => o.#e, (o, v) => o.#e = v]], [dec], 0, _ => #e in _)); - _initStatic(this); - } - #f = _call_f; - a = (_initProto(this), _init_a(this)); - b() {} - get c() {} - set c(v) {} - #A = _init_d(this); - get d() { - return this.#A; - } - set d(v) { - this.#A = v; - } - #e = _init_e(this); - get #g() { - return _call_g(this); - } - set #g(v) { - _call_g2(this, v); - } - #B = _init_h(this); - set #h(v) { - _set_h(this, v); - } - get #h() { - return _get_h(this); - } - static j() {} - static get k() {} - static set l(v) {} - static get m() { - return Class.#C; - } - static set m(v) { - Class.#C = v; - } + static [class Class { + static { + ({ + e: [_init_m, _call_o, _call_p, _call_q, _init_r, _get_r, _set_r, _init_d, _call_f, _call_g, _call_g2, _init_h, _get_h, _set_h, _init_i, _init_n, _init_a, _init_e, _initProto, _initStatic], + c: [_Class, _initClass] + } = babelHelpers.applyDecs2305(this, [[dec, 10, "j"], [dec, 11, "k"], [dec, 12, "l"], [dec, 9, "m"], [dec, 10, "o", function () {}], [dec, 11, "p", function () {}], [dec, 12, "q", function (v) {}], [dec, 9, "r", o => o.#D, (o, v) => o.#D = v], [dec, 2, "b"], [dec, 3, "c"], [dec, 4, "c"], [dec, 1, "d"], [dec, 2, "f", function () {}], [dec, 3, "g", function () {}], [dec, 4, "g", function (v) {}], [dec, 1, "h", o => o.#B, (o, v) => o.#B = v], [dec, 8, "i"], [dec, 8, "n", o => o.#n, (o, v) => o.#n = v], [dec, 0, "a"], [dec, 0, "e", o => o.#e, (o, v) => o.#e = v]], [dec], 0, _ => #e in _)); + _initStatic(this); } - } + #f = _call_f; + a = (_initProto(this), _init_a(this)); + b() {} + get c() {} + set c(v) {} + #A = _init_d(this); + get d() { + return this.#A; + } + set d(v) { + this.#A = v; + } + #e = _init_e(this); + get #g() { + return _call_g(this); + } + set #g(v) { + _call_g2(this, v); + } + #B = _init_h(this); + set #h(v) { + _set_h(this, v); + } + get #h() { + return _get_h(this); + } + static j() {} + static get k() {} + static set l(v) {} + static get m() { + return Class.#C; + } + static set m(v) { + Class.#C = v; + } + }]; #o = _call_o; i = _init_i(this); #C = _init_m(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor-multiple-super/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor-multiple-super/output.js index 2b364e8279e5..b3d434c10165 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor-multiple-super/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor-multiple-super/output.js @@ -1,8 +1,8 @@ var _initProto, _methodDecs, _B, _initProto2, _methodDecs2, _B2; const dec = () => {}; -_methodDecs = deco; class A extends (_B = B) { static { + _methodDecs = deco; [_initProto] = babelHelpers.applyDecs2305(this, [[_methodDecs, 2, "method"]], [], 0, void 0, _B).e; } constructor() { @@ -14,9 +14,9 @@ class A extends (_B = B) { } method() {} } -_methodDecs2 = deco; class C extends (_B2 = B) { static { + _methodDecs2 = deco; [_initProto2] = babelHelpers.applyDecs2305(this, [[_methodDecs2, 2, "method"]], [], 0, void 0, _B2).e; } constructor() { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor/output.js index 85d42a3a8d4e..57af0fe87e7f 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor/output.js @@ -68,9 +68,9 @@ let log = []; new class Dummy extends B { constructor() { - var _initProto3, _computedKey; + let _computedKey; + var _initProto3; let key; - _computedKey = babelHelpers.toPropertyKey((key = super(5).method(), log.push(key), key)); class A extends B { static { [_initProto3] = babelHelpers.applyDecs2305(this, [[dec, 2, "method"]], [], 0, void 0, B).e; @@ -81,7 +81,7 @@ method() { return this.a; } - [_computedKey] = void _initProto3(this); + [_computedKey = (key = super(5).method(), log.push(key), key)] = void _initProto3(this); } new A(); } @@ -94,10 +94,11 @@ const noop = () => fn => fn; new class extends B { constructor() { - var _initProto4, _noopDecs; - _noopDecs = noop(log.push(super(7).method())); + var _initProto4, _noopDecs, _outerSuper; + _outerSuper = (...args) => super(...args); class A extends B { static { + _noopDecs = noop(log.push(_outerSuper(7).method())); [_initProto4] = babelHelpers.applyDecs2305(this, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], [], 0, void 0, B).e; } constructor() { @@ -147,9 +148,10 @@ [_initProto6] = babelHelpers.applyDecs2305(this, [[dec, 2, "method"]], [], 0, void 0, B).e; } constructor() { - var _initProto7, _noopDecs2; - new (_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), class Dummy extends B { + var _initProto7, _noopDecs2, _outerSuper2; + new (_outerSuper2 = (...args) => super(...args), class Dummy extends B { static { + _noopDecs2 = noop(log.push(_initProto6(_outerSuper2(11)).method())); [_initProto7] = babelHelpers.applyDecs2305(this, [[_noopDecs2, 2, "noop"]], [], 0, void 0, B).e; } constructor() { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/super-in-decorator/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/super-in-decorator/output.js index 0cc5a28d44b1..9a8e51ad88f7 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/super-in-decorator/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/super-in-decorator/output.js @@ -1,11 +1,16 @@ class A extends B { m() { - var _initProto, _initClass, _classDecs, _m2Decs; + var _initProto, _initClass, _classDecs, _m2Decs, _outerThis, _outerSuperProp; _classDecs = [this, super.dec1]; - _m2Decs = [this, super.dec2]; + _outerThis = this; + _outerSuperProp = prop => Object.defineProperty({}, "_", { + get: () => super[prop], + set: v => super[prop] = v + }); let _C; class C { static { + _m2Decs = [_outerThis, _outerSuperProp("dec2")._]; ({ e: [_initProto], c: [_C, _initClass] diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/this/output.js index dcb99b172e55..1813ca370e61 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/this/output.js @@ -1,10 +1,9 @@ var _initClass, _obj, _classDecs, _xDecs, _init_x, _yDecs, _init_y; _classDecs = [_obj = o1, _obj.dec, void 0, dec, _obj = o2, _obj.dec]; -_xDecs = [_obj = o2, _obj.dec, _obj = o3.o, _obj.dec]; -_yDecs = [_obj = o2, _obj.dec, void 0, dec]; let _A; class A { static { + _xDecs = [_obj = o2, _obj.dec, _obj = o3.o, _obj.dec], _yDecs = [_obj = o2, _obj.dec, void 0, dec]; ({ e: [_init_x, _init_y], c: [_A, _initClass] diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/valid-expression-formats/output.js index 2d0a324851b8..7660e901d752 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/valid-expression-formats/output.js @@ -1,10 +1,10 @@ var _initProto, _initClass, _obj, _classDecs, _methodDecs; const dec = () => {}; _classDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]]; -_methodDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]]; let _Foo; class Foo { static { + _methodDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]]; ({ e: [_initProto], c: [_Foo, _initClass] @@ -13,9 +13,10 @@ class Foo { #a = void _initProto(this); method() {} makeClass() { - var _barDecs, _init_bar; - return _barDecs = [this, this.#a], class Nested { + var _barDecs, _init_bar, _outerThis; + return _outerThis = this, class Nested { static { + _barDecs = [_outerThis, _outerThis.#a]; [_init_bar] = babelHelpers.applyDecs2305(this, [[_barDecs, 16, "bar"]], []).e; } bar = _init_bar(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-ordering--to-es2015/initializers-and-static-blocks/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-ordering--to-es2015/initializers-and-static-blocks/output.js index f5e17f9d94ba..662f428fb6f0 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-ordering--to-es2015/initializers-and-static-blocks/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-ordering--to-es2015/initializers-and-static-blocks/output.js @@ -1,4 +1,5 @@ -var _initProto, _initStatic, _initClass, _init_field, _init_field2, _init_accessor, _init_accessor2, _ref, _B, _temp; +let _Foo2; +var _initProto, _initStatic, _initClass, _init_field, _init_field2, _init_accessor, _init_accessor2, _ref, _Class, _B, _Foo3, _A; const log = []; const classDec1 = (cls, ctxClass) => { log.push("c2"); @@ -144,7 +145,43 @@ const staticAccessorDec2 = (target, ctxStaticAccessor) => { }; log.push("start"); let _Foo; -new (_B = /*#__PURE__*/new WeakMap(), (_temp = class extends babelHelpers.identity { +new (_B = /*#__PURE__*/new WeakMap(), _Foo2 = (_A = /*#__PURE__*/new WeakMap(), (_Foo3 = class Foo extends (_ref = (log.push("extends"), Object)) { + constructor() { + log.push("ctor:start"); + super(); + babelHelpers.defineProperty(this, "field", (_initProto(this), _init_field(this))); + babelHelpers.classPrivateFieldInitSpec(this, _A, _init_accessor(this)); + log.push("ctor:end"); + } + method() {} + static method() {} + get getter() { + return; + } + static get getter() { + return; + } + set setter(x) {} + static set getter(x) {} + get accessor() { + return babelHelpers.classPrivateFieldGet2(_A, this); + } + set accessor(v) { + babelHelpers.classPrivateFieldSet2(_A, this, v); + } + static get accessor() { + return babelHelpers.classPrivateFieldGet2(_B, Foo); + } + static set accessor(v) { + babelHelpers.classPrivateFieldSet2(_B, Foo, v); + } +}, (() => { + ({ + e: [_init_accessor2, _init_accessor, _init_field2, _init_field, _initProto, _initStatic], + c: [_Foo, _initClass] + } = babelHelpers.applyDecs2305(_Foo3, [[[staticMethodDec1, staticMethodDec2], 10, "method"], [[staticGetterDec1, staticGetterDec2], 11, "getter"], [[staticSetterDec1, staticSetterDec2], 12, "getter"], [[staticAccessorDec1, staticAccessorDec2], 9, "accessor"], [[methodDec1, methodDec2], 2, "method"], [[getterDec1, getterDec2], 3, "getter"], [[setterDec1, setterDec2], 4, "setter"], [[accessorDec1, accessorDec2], 1, "accessor"], [[staticFieldDec1, staticFieldDec2], 8, "field"], [[fieldDec1, fieldDec2], 0, "field"]], [classDec1, classDec2], 0, void 0, _ref)); + _initStatic(_Foo3); +})(), _Foo3)), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "field", ((() => { log.push("static:start"); @@ -152,48 +189,7 @@ new (_B = /*#__PURE__*/new WeakMap(), (_temp = class extends babelHelpers.identi log.push("static:end"); })(), _initClass(); } -}, (_Foo2 => { - var _A = /*#__PURE__*/new WeakMap(); - class Foo extends (_ref = (log.push("extends"), Object)) { - constructor() { - log.push("ctor:start"); - super(); - babelHelpers.defineProperty(this, "field", (_initProto(this), _init_field(this))); - babelHelpers.classPrivateFieldInitSpec(this, _A, _init_accessor(this)); - log.push("ctor:end"); - } - method() {} - static method() {} - get getter() { - return; - } - static get getter() { - return; - } - set setter(x) {} - static set getter(x) {} - get accessor() { - return babelHelpers.classPrivateFieldGet2(_A, this); - } - set accessor(v) { - babelHelpers.classPrivateFieldSet2(_A, this, v); - } - static get accessor() { - return babelHelpers.classPrivateFieldGet2(_B, Foo); - } - static set accessor(v) { - babelHelpers.classPrivateFieldSet2(_B, Foo, v); - } - } - _Foo2 = Foo; - (() => { - ({ - e: [_init_accessor2, _init_accessor, _init_field2, _init_field, _initProto, _initStatic], - c: [_Foo, _initClass] - } = babelHelpers.applyDecs2305(_Foo2, [[[staticMethodDec1, staticMethodDec2], 10, "method"], [[staticGetterDec1, staticGetterDec2], 11, "getter"], [[staticSetterDec1, staticSetterDec2], 12, "getter"], [[staticAccessorDec1, staticAccessorDec2], 9, "accessor"], [[methodDec1, methodDec2], 2, "method"], [[getterDec1, getterDec2], 3, "getter"], [[setterDec1, setterDec2], 4, "setter"], [[accessorDec1, accessorDec2], 1, "accessor"], [[staticFieldDec1, staticFieldDec2], 8, "field"], [[fieldDec1, fieldDec2], 0, "field"]], [classDec1, classDec2], 0, void 0, _ref)); - _initStatic(_Foo2); - })(); -})(), _temp))(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); log.push("after"); new _Foo(); log.push("end"); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-ordering/initializers-and-static-blocks/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-ordering/initializers-and-static-blocks/output.js index 8594ae302858..fddd58ef3901 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-ordering/initializers-and-static-blocks/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-ordering/initializers-and-static-blocks/output.js @@ -145,46 +145,44 @@ const staticAccessorDec2 = (target, ctxStaticAccessor) => { log.push("start"); let _Foo; new class extends babelHelpers.identity { - static { - class Foo extends (_ref = (log.push("extends"), Object)) { - static { - ({ - e: [_init_accessor2, _init_accessor, _init_field2, _init_field, _initProto, _initStatic], - c: [_Foo, _initClass] - } = babelHelpers.applyDecs2305(this, [[[staticMethodDec1, staticMethodDec2], 10, "method"], [[staticGetterDec1, staticGetterDec2], 11, "getter"], [[staticSetterDec1, staticSetterDec2], 12, "getter"], [[staticAccessorDec1, staticAccessorDec2], 9, "accessor"], [[methodDec1, methodDec2], 2, "method"], [[getterDec1, getterDec2], 3, "getter"], [[setterDec1, setterDec2], 4, "setter"], [[accessorDec1, accessorDec2], 1, "accessor"], [[staticFieldDec1, staticFieldDec2], 8, "field"], [[fieldDec1, fieldDec2], 0, "field"]], [classDec1, classDec2], 0, void 0, _ref)); - _initStatic(this); - } - constructor() { - log.push("ctor:start"); - super(); - log.push("ctor:end"); - } - method() {} - static method() {} - field = (_initProto(this), _init_field(this)); - get getter() { - return; - } - static get getter() { - return; - } - set setter(x) {} - static set getter(x) {} - #A = _init_accessor(this); - get accessor() { - return this.#A; - } - set accessor(v) { - this.#A = v; - } - static get accessor() { - return Foo.#B; - } - static set accessor(v) { - Foo.#B = v; - } + static [class Foo extends (_ref = (log.push("extends"), Object)) { + static { + ({ + e: [_init_accessor2, _init_accessor, _init_field2, _init_field, _initProto, _initStatic], + c: [_Foo, _initClass] + } = babelHelpers.applyDecs2305(this, [[[staticMethodDec1, staticMethodDec2], 10, "method"], [[staticGetterDec1, staticGetterDec2], 11, "getter"], [[staticSetterDec1, staticSetterDec2], 12, "getter"], [[staticAccessorDec1, staticAccessorDec2], 9, "accessor"], [[methodDec1, methodDec2], 2, "method"], [[getterDec1, getterDec2], 3, "getter"], [[setterDec1, setterDec2], 4, "setter"], [[accessorDec1, accessorDec2], 1, "accessor"], [[staticFieldDec1, staticFieldDec2], 8, "field"], [[fieldDec1, fieldDec2], 0, "field"]], [classDec1, classDec2], 0, void 0, _ref)); + _initStatic(this); } - } + constructor() { + log.push("ctor:start"); + super(); + log.push("ctor:end"); + } + method() {} + static method() {} + field = (_initProto(this), _init_field(this)); + get getter() { + return; + } + static get getter() { + return; + } + set setter(x) {} + static set getter(x) {} + #A = _init_accessor(this); + get accessor() { + return this.#A; + } + set accessor(v) { + this.#A = v; + } + static get accessor() { + return Foo.#B; + } + static set accessor(v) { + Foo.#B = v; + } + }]; field = ((() => { log.push("static:start"); })(), _init_field2(this)); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-setters--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-setters--to-es2015/context-name/output.js index 76e8be570d00..a06e71f6b460 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-setters--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-setters--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey, _Foo; +let _computedKey; +var _initStatic, _call_a, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-setters/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-setters/context-name/output.js index 118536c7ed43..4e176ae972aa 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-setters/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-setters/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey; +let _computedKey; +var _initStatic, _call_a; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs2305(this, [[dec, 12, "a"], [dec, 12, "a", function (v) {}], [dec, 12, "b"], [dec, 12, "c"], [dec, 12, 0], [dec, 12, 1], [dec, 12, 2n], [dec, 12, 3n], [dec, 12, _computedKey]], []).e; @@ -25,6 +25,6 @@ class Foo { static set [1](v) {} static set 2n(v) {} static set [3n](v) {} - static set [_computedKey](v) {} + static set [_computedKey = babelHelpers.toPropertyKey(f())](v) {} } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-accessors--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-accessors--to-es2015/context-name/output.js index e76c6459e292..0a4f4e3b5c03 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-accessors--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-accessors--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _init_a, _init_extra_a, _init_a2, _get_a, _set_a, _init_extra_a2, _init_computedKey, _init_extra_computedKey, _init_computedKey2, _init_extra_computedKey2, _init_computedKey3, _init_extra_computedKey3, _init_computedKey4, _init_extra_computedKey4, _init_computedKey5, _init_extra_computedKey5, _init_computedKey6, _init_extra_computedKey6, _computedKey, _init_computedKey7, _init_extra_computedKey7, _Foo; +let _computedKey; +var _init_a, _init_extra_a, _init_a2, _get_a, _set_a, _init_extra_a2, _init_computedKey, _init_extra_computedKey, _init_computedKey2, _init_extra_computedKey2, _init_computedKey3, _init_extra_computedKey3, _init_computedKey4, _init_extra_computedKey4, _init_computedKey5, _init_extra_computedKey5, _init_computedKey6, _init_extra_computedKey6, _init_computedKey7, _init_extra_computedKey7, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-accessors/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-accessors/context-name/output.js index 44a3c4b976bd..c41d179440fd 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-accessors/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-accessors/context-name/output.js @@ -1,4 +1,5 @@ -var _init_a, _init_extra_a, _init_a2, _get_a, _set_a, _init_extra_a2, _init_computedKey, _init_extra_computedKey, _init_computedKey2, _init_extra_computedKey2, _init_computedKey3, _init_extra_computedKey3, _init_computedKey4, _init_extra_computedKey4, _init_computedKey5, _init_extra_computedKey5, _init_computedKey6, _init_extra_computedKey6, _computedKey, _init_computedKey7, _init_extra_computedKey7; +let _computedKey; +var _init_a, _init_extra_a, _init_a2, _get_a, _set_a, _init_extra_a2, _init_computedKey, _init_extra_computedKey, _init_computedKey2, _init_extra_computedKey2, _init_computedKey3, _init_extra_computedKey3, _init_computedKey4, _init_extra_computedKey4, _init_computedKey5, _init_extra_computedKey5, _init_computedKey6, _init_extra_computedKey6, _init_computedKey7, _init_extra_computedKey7; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_init_a, _init_extra_a, _init_a2, _get_a, _set_a, _init_extra_a2, _init_computedKey, _init_extra_computedKey, _init_computedKey2, _init_extra_computedKey2, _init_computedKey3, _init_extra_computedKey3, _init_computedKey4, _init_extra_computedKey4, _init_computedKey5, _init_extra_computedKey5, _init_computedKey6, _init_extra_computedKey6, _init_computedKey7, _init_extra_computedKey7] = babelHelpers.applyDecs2311(this, [], [[dec, 9, "a"], [dec, 9, "a", o => o.#B, (o, v) => o.#B = v], [dec, 9, "b"], [dec, 9, "c"], [dec, 9, 0], [dec, 9, 1], [dec, 9, 2n], [dec, 9, 3n], [dec, 9, _computedKey]]).e; @@ -71,7 +71,7 @@ class Foo { Foo.#H = v; } static #I = (_init_extra_computedKey6(), _init_computedKey7()); - static get [_computedKey]() { + static get [_computedKey = babelHelpers.toPropertyKey(f())]() { return Foo.#I; } static set [_computedKey](v) { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/expressions-static-blocks/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/expressions-static-blocks/output.js index 040ee8e04539..ddc6cabdcba4 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/expressions-static-blocks/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/expressions-static-blocks/output.js @@ -1,73 +1,51 @@ -var _initClass, _A, _temp, _initClass2, _C, _temp2, _initClass3, _D, _temp3, _initClass4, _decorated_class, _temp4, _Class2, _initClass5, _G, _temp5, _initClass6, _decorated_class2, _temp6, _Class3, _initClass7, _H, _I, _temp7, _initClass8, _K, _L, _temp8; +let _A2, _C2, _D2, _ref, _G2, _ref2, _H2, _K2; +var _initClass, _A, _Class, _A3, _initClass2, _C, _Class2, _C3, _initClass3, _D, _Class3, _D3, _initClass4, _decorated_class, _Class4, _Class5, _initClass5, _G, _Class6, _G3, _initClass6, _decorated_class2, _Class7, _Class8, _initClass7, _H, _I, _Class9, _H3, _initClass8, _K, _L, _Class10, _K3; const dec = () => {}; -const A = (new (_temp = class extends babelHelpers.identity { +const A = (new (_A2 = (_A3 = class A {}, [_A, _initClass] = babelHelpers.applyDecs2311(_A3, [dec], []).c, _A3), (_Class = class extends babelHelpers.identity { constructor() { super(_A), (() => {})(), _initClass(); } -}, (_A2 => { - class A {} - _A2 = A; - [_A, _initClass] = babelHelpers.applyDecs2311(_A2, [dec], []).c; -})(), _temp)(), _A); -const B = (new (_temp2 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class, _A2, void 0), _Class))(), _A); +const B = (new (_C2 = (_C3 = class C {}, [_C, _initClass2] = babelHelpers.applyDecs2311(_C3, [dec], []).c, _C3), (_Class2 = class extends babelHelpers.identity { constructor() { super(_C), (() => {})(), _initClass2(); } -}, (_C2 => { - class C {} - _C2 = C; - [_C, _initClass2] = babelHelpers.applyDecs2311(_C2, [dec], []).c; -})(), _temp2)(), _C); -const D = (new (_temp3 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class2, _C2, void 0), _Class2))(), _C); +const D = (new (_D2 = (_D3 = class D {}, [_D, _initClass3] = babelHelpers.applyDecs2311(_D3, [dec], []).c, _D3), (_Class3 = class extends babelHelpers.identity { constructor() { super(_D), (() => {})(), _initClass3(); } -}, (_D2 => { - class D {} - _D2 = D; - [_D, _initClass3] = babelHelpers.applyDecs2311(_D2, [dec], []).c; -})(), _temp3)(), _D); -const E = ((new (_temp4 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class3, _D2, void 0), _Class3))(), _D); +const E = ((new (_ref = (_Class5 = class _ref {}, [_decorated_class, _initClass4] = babelHelpers.applyDecs2311(_Class5, [dec], []).c, _Class5), (_Class4 = class extends babelHelpers.identity { constructor() { super(_decorated_class), (() => {})(), _initClass4(); } -}, (_Class2 = class {}, [_decorated_class, _initClass4] = babelHelpers.applyDecs2311(_Class2, [dec], []).c), _temp4)(), _decorated_class), 123); -const F = [(new (_temp5 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class4, _ref, void 0), _Class4))(), _decorated_class), 123); +const F = [(new (_G2 = (_G3 = class G {}, [_G, _initClass5] = babelHelpers.applyDecs2311(_G3, [dec], []).c, _G3), (_Class6 = class extends babelHelpers.identity { constructor() { super(_G), (() => {})(), _initClass5(); } -}, (_G2 => { - class G {} - _G2 = G; - [_G, _initClass5] = babelHelpers.applyDecs2311(_G2, [dec], []).c; -})(), _temp5)(), _G), (new (_temp6 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class6, _G2, void 0), _Class6))(), _G), (new (_ref2 = (_Class8 = class _ref2 {}, [_decorated_class2, _initClass6] = babelHelpers.applyDecs2311(_Class8, [dec], []).c, _Class8), (_Class7 = class extends babelHelpers.identity { constructor() { super(_decorated_class2), (() => {})(), _initClass6(); } -}, (_Class3 = class {}, [_decorated_class2, _initClass6] = babelHelpers.applyDecs2311(_Class3, [dec], []).c), _temp6)(), _decorated_class2)]; -const H = (new (_temp7 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class7, _ref2, void 0), _Class7))(), _decorated_class2)]; +const H = (new (_H2 = (_H3 = class H extends (_I = I) {}, [_H, _initClass7] = babelHelpers.applyDecs2311(_H3, [dec], [], 0, void 0, _I).c, _H3), (_Class9 = class extends babelHelpers.identity { constructor() { super(_H), (() => {})(), _initClass7(); } -}, (_H2 => { - class H extends (_I = I) {} - _H2 = H; - [_H, _initClass7] = babelHelpers.applyDecs2311(_H2, [dec], [], 0, void 0, _I).c; -})(), _temp7)(), _H); -const J = (new (_temp8 = class extends babelHelpers.identity { +}, babelHelpers.defineProperty(_Class9, _H2, void 0), _Class9))(), _H); +const J = (new (_K2 = (_K3 = class K extends (_L = L) {}, [_K, _initClass8] = babelHelpers.applyDecs2311(_K3, [dec], [], 0, void 0, _L).c, _K3), (_Class10 = class extends babelHelpers.identity { constructor() { super(_K), (() => {})(), _initClass8(); } -}, (_K2 => { - class K extends (_L = L) {} - _K2 = K; - [_K, _initClass8] = babelHelpers.applyDecs2311(_K2, [dec], [], 0, void 0, _L).c; -})(), _temp8)(), _K); +}, babelHelpers.defineProperty(_Class10, _K2, void 0), _Class10))(), _K); function classFactory() { - var _initClass9, _decorated_class3, _temp9, _Class5; - return new (_temp9 = class extends babelHelpers.identity { + let _ref3; + var _initClass9, _decorated_class3, _Class11, _Class12; + return new (_ref3 = (_Class12 = class _ref3 {}, [_decorated_class3, _initClass9] = babelHelpers.applyDecs2311(_Class12, [dec], []).c, _Class12), (_Class11 = class extends babelHelpers.identity { constructor() { super(_decorated_class3), (() => {})(), _initClass9(); } - }, (_Class5 = class {}, [_decorated_class3, _initClass9] = babelHelpers.applyDecs2311(_Class5, [dec], []).c), _temp9)(), _decorated_class3; + }, babelHelpers.defineProperty(_Class11, _ref3, void 0), _Class11))(), _decorated_class3; } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/initializers/output.js index b747829b3166..a55c3508b845 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/initializers/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/initializers/output.js @@ -1,24 +1,17 @@ -var _initClass, _temp, _initClass2, _Foo3, _temp2; +let _Foo2, _Bar2; +var _initClass, _Class, _Foo3, _initClass2, _Foo4, _Class2, _Bar3; const dec = () => {}; let _Foo; -new (_temp = class extends babelHelpers.identity { +new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs2311(_Foo3, [dec], []).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "field", 123)), _initClass(); } -}, (_Foo2 => { - class Foo {} - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2311(_Foo2, [dec], []).c; -})(), _temp)(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); let _Bar; -new (_temp2 = class extends babelHelpers.identity { +new (_Bar2 = (_Bar3 = class Bar extends (_Foo4 = _Foo) {}, [_Bar, _initClass2] = babelHelpers.applyDecs2311(_Bar3, [dec], [], 0, void 0, _Foo4).c, _Bar3), (_Class2 = class extends babelHelpers.identity { constructor() { (super(_Bar), babelHelpers.defineProperty(this, "field", ((() => { this.otherField = 456; })(), 123))), _initClass2(); } -}, (_Bar2 => { - class Bar extends (_Foo3 = _Foo) {} - _Bar2 = Bar; - [_Bar, _initClass2] = babelHelpers.applyDecs2311(_Bar2, [dec], [], 0, void 0, _Foo3).c; -})(), _temp2)(); +}, babelHelpers.defineProperty(_Class2, _Bar2, void 0), _Class2))(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-decorator-initializer-this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-decorator-initializer-this/output.js index e87ec5b63f86..b9f6b88b5573 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-decorator-initializer-this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-decorator-initializer-this/output.js @@ -1,4 +1,5 @@ -var _initStatic, _initClass, _init_accessor, _init_extra_accessor, _init_property, _init_extra_property, _A, _temp; +let _Foo2; +var _initStatic, _initClass, _init_accessor, _init_extra_accessor, _init_property, _init_extra_property, _Class, _A, _Foo3; let original, replaced, accessorThis, getterThis, setterThis, methodThis, propertyThis, classThis; function dec(Klass, context) { original = Klass; @@ -16,30 +17,26 @@ function captureInitializerThis(callback) { }; } let _Foo; -new (_A = /*#__PURE__*/new WeakMap(), (_temp = class extends babelHelpers.identity { +new (_A = /*#__PURE__*/new WeakMap(), _Foo2 = (_Foo3 = class Foo { + static get accessor() { + return babelHelpers.classPrivateFieldGet2(_A, Foo); + } + static set accessor(v) { + babelHelpers.classPrivateFieldSet2(_A, Foo, v); + } + static get getter() {} + static set setter(_) {} + static method() {} +}, (() => { + ({ + e: [_init_accessor, _init_extra_accessor, _init_property, _init_extra_property, _initStatic], + c: [_Foo, _initClass] + } = babelHelpers.applyDecs2311(_Foo3, [dec], [[captureInitializerThis(v => accessorThis = v), 9, "accessor"], [captureInitializerThis(v => getterThis = v), 11, "getter"], [captureInitializerThis(v => setterThis = v), 12, "setter"], [captureInitializerThis(v => methodThis = v), 10, "method"], [captureInitializerThis(v => propertyThis = v), 8, "property"]])); + _initStatic(_Foo3); +})(), _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.classPrivateFieldInitSpec(this, _A, _init_accessor()), babelHelpers.defineProperty(this, "property", (_init_extra_accessor(), _init_property()))), (() => { _init_extra_property(); })(), _initClass(); } -}, (_Foo2 => { - class Foo { - static get accessor() { - return babelHelpers.classPrivateFieldGet2(_A, Foo); - } - static set accessor(v) { - babelHelpers.classPrivateFieldSet2(_A, Foo, v); - } - static get getter() {} - static set setter(_) {} - static method() {} - } - _Foo2 = Foo; - (() => { - ({ - e: [_init_accessor, _init_extra_accessor, _init_property, _init_extra_property, _initStatic], - c: [_Foo, _initClass] - } = babelHelpers.applyDecs2311(_Foo2, [dec], [[captureInitializerThis(v => accessorThis = v), 9, "accessor"], [captureInitializerThis(v => getterThis = v), 11, "getter"], [captureInitializerThis(v => setterThis = v), 12, "setter"], [captureInitializerThis(v => methodThis = v), 10, "method"], [captureInitializerThis(v => propertyThis = v), 8, "property"]])); - _initStatic(_Foo2); - })(); -})(), _temp))(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-installed-on-correct-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-installed-on-correct-class/output.js index 179431d03af4..8f94b207ff0d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-installed-on-correct-class/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-installed-on-correct-class/output.js @@ -1,8 +1,17 @@ -var _initClass, _x, _A, _Class_brand, _B, _temp; +let _Foo2; +var _initClass, _Class, _x, _A, _Class_brand, _B, _Foo3; const dec = () => {}; let hasX, hasA, hasM; let _Foo; -new (_x = /*#__PURE__*/new WeakMap(), _A = /*#__PURE__*/new WeakMap(), _Class_brand = /*#__PURE__*/new WeakSet(), _B = /*#__PURE__*/new WeakMap(), (_temp = class extends babelHelpers.identity { +new (_x = /*#__PURE__*/new WeakMap(), _A = /*#__PURE__*/new WeakMap(), _Class_brand = /*#__PURE__*/new WeakSet(), _B = /*#__PURE__*/new WeakMap(), _Foo2 = (_Foo3 = class Foo { + static get a() { + return babelHelpers.classPrivateFieldGet2(_B, _Foo); + } + static set a(v) { + babelHelpers.classPrivateFieldSet2(_B, _Foo, v); + } + static m() {} +}, [_Foo, _initClass] = babelHelpers.applyDecs2311(_Foo3, [dec], []).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.classPrivateMethodInitSpec(this, _Class_brand), babelHelpers.classPrivateFieldInitSpec(this, _x, void 0), babelHelpers.classPrivateFieldInitSpec(this, _A, void 0), babelHelpers.defineProperty(this, "x", void 0), babelHelpers.classPrivateFieldInitSpec(this, _B, void 0), this), (() => { hasX = o => _x.has(babelHelpers.checkInRHS(o)); @@ -10,19 +19,7 @@ new (_x = /*#__PURE__*/new WeakMap(), _A = /*#__PURE__*/new WeakMap(), _Class_br hasM = o => _Class_brand.has(babelHelpers.checkInRHS(o)); })(), _initClass(); } -}, (_Foo2 => { - class Foo { - static get a() { - return babelHelpers.classPrivateFieldGet2(_B, _Foo); - } - static set a(v) { - babelHelpers.classPrivateFieldSet2(_B, _Foo, v); - } - static m() {} - } - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2311(_Foo2, [dec], []).c; -})(), _temp))(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); function _get_a(_this) { return babelHelpers.classPrivateFieldGet2(_A, _Foo); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-this/output.js index ffba867c9c4a..bfad32bfbbea 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-this/output.js @@ -1,7 +1,8 @@ -var _initClass, _temp; +let _Foo2; +var _initClass, _Class, _Foo3; const dec = () => {}; let _Foo; -new (_temp = class extends babelHelpers.identity { +new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs2311(_Foo3, [dec], []).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "field", ((() => { this; @@ -9,8 +10,4 @@ new (_temp = class extends babelHelpers.identity { this; })(), _initClass(); } -}, (_Foo2 => { - class Foo {} - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2311(_Foo2, [dec], []).c; -})(), _temp)(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement/output.js index db44675809b1..d997ad19144e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement/output.js @@ -1,13 +1,10 @@ -var _initClass, _temp; +let _Foo2; +var _initClass, _Class, _Foo3; const dec = () => {}; let _Foo; -new (_temp = class extends babelHelpers.identity { +new (_Foo2 = (_Foo3 = class Foo {}, [_Foo, _initClass] = babelHelpers.applyDecs2311(_Foo3, [dec], []).c, _Foo3), (_Class = class extends babelHelpers.identity { constructor() { (super(_Foo), babelHelpers.defineProperty(this, "foo", new _Foo())), _initClass(); } -}, (_Foo2 => { - class Foo {} - _Foo2 = Foo; - [_Foo, _initClass] = babelHelpers.applyDecs2311(_Foo2, [dec], []).c; -})(), _temp)(); +}, babelHelpers.defineProperty(_Class, _Foo2, void 0), _Class))(); const foo = new _Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/expressions-static-blocks/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/expressions-static-blocks/output.js index a7b3c1319f46..fe7662be91a4 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/expressions-static-blocks/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/expressions-static-blocks/output.js @@ -1,96 +1,80 @@ var _initClass, _A, _initClass2, _C, _initClass3, _D, _initClass4, _decorated_class, _initClass5, _G, _initClass6, _decorated_class2, _initClass7, _H, _I, _initClass8, _K, _L; const dec = () => {}; const A = (new class extends babelHelpers.identity { - static { - class A { - static { - [_A, _initClass] = babelHelpers.applyDecs2311(this, [dec], []).c; - } + static [class A { + static { + [_A, _initClass] = babelHelpers.applyDecs2311(this, [dec], []).c; } - } + }]; constructor() { super(_A), (() => {})(), _initClass(); } }(), _A); const B = (new class extends babelHelpers.identity { - static { - class C { - static { - [_C, _initClass2] = babelHelpers.applyDecs2311(this, [dec], []).c; - } + static [class C { + static { + [_C, _initClass2] = babelHelpers.applyDecs2311(this, [dec], []).c; } - } + }]; constructor() { super(_C), (() => {})(), _initClass2(); } }(), _C); const D = (new class extends babelHelpers.identity { - static { - class D { - static { - [_D, _initClass3] = babelHelpers.applyDecs2311(this, [dec], []).c; - } + static [class D { + static { + [_D, _initClass3] = babelHelpers.applyDecs2311(this, [dec], []).c; } - } + }]; constructor() { super(_D), (() => {})(), _initClass3(); } }(), _D); const E = ((new class extends babelHelpers.identity { - static { - (class { - static { - [_decorated_class, _initClass4] = babelHelpers.applyDecs2311(this, [dec], []).c; - } - }); - } + static [class { + static { + [_decorated_class, _initClass4] = babelHelpers.applyDecs2311(this, [dec], []).c; + } + }]; constructor() { super(_decorated_class), (() => {})(), _initClass4(); } }(), _decorated_class), 123); const F = [(new class extends babelHelpers.identity { - static { - class G { - static { - [_G, _initClass5] = babelHelpers.applyDecs2311(this, [dec], []).c; - } + static [class G { + static { + [_G, _initClass5] = babelHelpers.applyDecs2311(this, [dec], []).c; } - } + }]; constructor() { super(_G), (() => {})(), _initClass5(); } }(), _G), (new class extends babelHelpers.identity { - static { - (class { - static { - [_decorated_class2, _initClass6] = babelHelpers.applyDecs2311(this, [dec], []).c; - } - }); - } + static [class { + static { + [_decorated_class2, _initClass6] = babelHelpers.applyDecs2311(this, [dec], []).c; + } + }]; constructor() { super(_decorated_class2), (() => {})(), _initClass6(); } }(), _decorated_class2)]; const H = (new class extends babelHelpers.identity { - static { - class H extends (_I = I) { - static { - [_H, _initClass7] = babelHelpers.applyDecs2311(this, [dec], [], 0, void 0, _I).c; - } + static [class H extends (_I = I) { + static { + [_H, _initClass7] = babelHelpers.applyDecs2311(this, [dec], [], 0, void 0, _I).c; } - } + }]; constructor() { super(_H), (() => {})(), _initClass7(); } }(), _H); const J = (new class extends babelHelpers.identity { - static { - class K extends (_L = L) { - static { - [_K, _initClass8] = babelHelpers.applyDecs2311(this, [dec], [], 0, void 0, _L).c; - } + static [class K extends (_L = L) { + static { + [_K, _initClass8] = babelHelpers.applyDecs2311(this, [dec], [], 0, void 0, _L).c; } - } + }]; constructor() { super(_K), (() => {})(), _initClass8(); } @@ -98,13 +82,11 @@ const J = (new class extends babelHelpers.identity { function classFactory() { var _initClass9, _decorated_class3; return new class extends babelHelpers.identity { - static { - (class { - static { - [_decorated_class3, _initClass9] = babelHelpers.applyDecs2311(this, [dec], []).c; - } - }); - } + static [class { + static { + [_decorated_class3, _initClass9] = babelHelpers.applyDecs2311(this, [dec], []).c; + } + }]; constructor() { super(_decorated_class3), (() => {})(), _initClass9(); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/initializers/output.js index 515698f33242..3dcdb33c2bc5 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/initializers/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/initializers/output.js @@ -2,13 +2,11 @@ var _initClass, _initClass2, _Foo2; const dec = () => {}; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2311(this, [dec], []).c; - } + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2311(this, [dec], []).c; } - } + }]; field = 123; constructor() { super(_Foo), _initClass(); @@ -16,13 +14,11 @@ new class extends babelHelpers.identity { }(); let _Bar; new class extends babelHelpers.identity { - static { - class Bar extends (_Foo2 = _Foo) { - static { - [_Bar, _initClass2] = babelHelpers.applyDecs2311(this, [dec], [], 0, void 0, _Foo2).c; - } + static [class Bar extends (_Foo2 = _Foo) { + static { + [_Bar, _initClass2] = babelHelpers.applyDecs2311(this, [dec], [], 0, void 0, _Foo2).c; } - } + }]; field = ((() => { this.otherField = 456; })(), 123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-decorator-initializer-this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-decorator-initializer-this/output.js index 89e72ac02c2a..c9c5c6ee582e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-decorator-initializer-this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-decorator-initializer-this/output.js @@ -17,26 +17,24 @@ function captureInitializerThis(callback) { } let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - ({ - e: [_init_accessor, _init_extra_accessor, _init_property, _init_extra_property, _initStatic], - c: [_Foo, _initClass] - } = babelHelpers.applyDecs2311(this, [dec], [[captureInitializerThis(v => accessorThis = v), 9, "accessor"], [captureInitializerThis(v => getterThis = v), 11, "getter"], [captureInitializerThis(v => setterThis = v), 12, "setter"], [captureInitializerThis(v => methodThis = v), 10, "method"], [captureInitializerThis(v => propertyThis = v), 8, "property"]])); - _initStatic(this); - } - static get accessor() { - return Foo.#A; - } - static set accessor(v) { - Foo.#A = v; - } - static get getter() {} - static set setter(_) {} - static method() {} + static [class Foo { + static { + ({ + e: [_init_accessor, _init_extra_accessor, _init_property, _init_extra_property, _initStatic], + c: [_Foo, _initClass] + } = babelHelpers.applyDecs2311(this, [dec], [[captureInitializerThis(v => accessorThis = v), 9, "accessor"], [captureInitializerThis(v => getterThis = v), 11, "getter"], [captureInitializerThis(v => setterThis = v), 12, "setter"], [captureInitializerThis(v => methodThis = v), 10, "method"], [captureInitializerThis(v => propertyThis = v), 8, "property"]])); + _initStatic(this); } - } + static get accessor() { + return Foo.#A; + } + static set accessor(v) { + Foo.#A = v; + } + static get getter() {} + static set setter(_) {} + static method() {} + }]; #A = _init_accessor(); property = (_init_extra_accessor(), _init_property()); constructor() { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-installed-on-correct-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-installed-on-correct-class/output.js index 4b76ee31072f..beef1d1d8acc 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-installed-on-correct-class/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-installed-on-correct-class/output.js @@ -3,20 +3,18 @@ const dec = () => {}; let hasX, hasA, hasM; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2311(this, [dec], []).c; - } - static get a() { - return _Foo.#B; - } - static set a(v) { - _Foo.#B = v; - } - static m() {} + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2311(this, [dec], []).c; } - } + static get a() { + return _Foo.#B; + } + static set a(v) { + _Foo.#B = v; + } + static m() {} + }]; #x; #A; get #a() { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-this/output.js index 56493032c6ea..cf4a48fbd5b0 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-this/output.js @@ -2,13 +2,11 @@ var _initClass; const dec = () => {}; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2311(this, [dec], []).c; - } + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2311(this, [dec], []).c; } - } + }]; field = ((() => { this; })(), this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement/output.js index 9ef5852f437c..90bd0cc6e2aa 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement/output.js @@ -2,13 +2,11 @@ var _initClass; const dec = () => {}; let _Foo; new class extends babelHelpers.identity { - static { - class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs2311(this, [dec], []).c; - } + static [class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs2311(this, [dec], []).c; } - } + }]; foo = new _Foo(); constructor() { super(_Foo), _initClass(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys--to-es2015/computed-keys-same-ast/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys--to-es2015/computed-keys-same-ast/output.js index 2114a1271628..0f1b0e0e977c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys--to-es2015/computed-keys-same-ast/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys--to-es2015/computed-keys-same-ast/output.js @@ -1,4 +1,5 @@ -var _initProto, _computedKey, _computedKey2, _Foo; +let _computedKey, _computedKey2; +var _initProto, _Foo; const dec = () => {}; _computedKey = babelHelpers.toPropertyKey(getKey()); _computedKey2 = babelHelpers.toPropertyKey(getKey()); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys--to-es2015/computed-keys-same-value/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys--to-es2015/computed-keys-same-value/output.js index cc737dc4095a..361ba52d351c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys--to-es2015/computed-keys-same-value/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys--to-es2015/computed-keys-same-value/output.js @@ -1,4 +1,5 @@ -var _initProto, _computedKey, _computedKey2, _Foo; +let _computedKey, _computedKey2; +var _initProto, _Foo; const dec = () => {}; _computedKey = babelHelpers.toPropertyKey(getKeyI()); _computedKey2 = babelHelpers.toPropertyKey(getKeyJ()); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys/computed-keys-same-ast/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys/computed-keys-same-ast/output.js index 37a7ee8d7974..943c477b116e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys/computed-keys-same-ast/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys/computed-keys-same-ast/output.js @@ -1,7 +1,6 @@ -var _initProto, _computedKey, _computedKey2; +let _computedKey, _computedKey2; +var _initProto; const dec = () => {}; -_computedKey = babelHelpers.toPropertyKey(getKey()); -_computedKey2 = babelHelpers.toPropertyKey(getKey()); class Foo { static { [_initProto] = babelHelpers.applyDecs2311(this, [], [[dec, 2, _computedKey], [dec, 2, _computedKey2]]).e; @@ -9,10 +8,10 @@ class Foo { constructor() { _initProto(this); } - [_computedKey]() { + [_computedKey = babelHelpers.toPropertyKey(getKey())]() { return 1; } - [_computedKey2]() { + [_computedKey2 = babelHelpers.toPropertyKey(getKey())]() { return 2; } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys/computed-keys-same-value/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys/computed-keys-same-value/output.js index abfbec73ecdc..f42ea8dc86f3 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys/computed-keys-same-value/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-duplicated-keys/computed-keys-same-value/output.js @@ -1,7 +1,6 @@ -var _initProto, _computedKey, _computedKey2; +let _computedKey, _computedKey2; +var _initProto; const dec = () => {}; -_computedKey = babelHelpers.toPropertyKey(getKeyI()); -_computedKey2 = babelHelpers.toPropertyKey(getKeyJ()); class Foo { static { [_initProto] = babelHelpers.applyDecs2311(this, [], [[dec, 2, _computedKey], [dec, 2, _computedKey2]]).e; @@ -9,10 +8,10 @@ class Foo { constructor() { _initProto(this); } - [_computedKey]() { + [_computedKey = babelHelpers.toPropertyKey(getKeyI())]() { return 1; } - [_computedKey2]() { + [_computedKey2 = babelHelpers.toPropertyKey(getKeyJ())]() { return 2; } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-fields--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-fields--to-es2015/context-name/output.js index a70898cd7a30..386332e0bd98 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-fields--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-fields--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _init_a, _init_extra_a, _init_a2, _init_extra_a2, _init_computedKey, _init_extra_computedKey, _init_computedKey2, _init_extra_computedKey2, _init_computedKey3, _init_extra_computedKey3, _init_computedKey4, _init_extra_computedKey4, _init_computedKey5, _init_extra_computedKey5, _init_computedKey6, _init_extra_computedKey6, _computedKey, _init_computedKey7, _init_extra_computedKey7, _Foo; +let _computedKey; +var _init_a, _init_extra_a, _init_a2, _init_extra_a2, _init_computedKey, _init_extra_computedKey, _init_computedKey2, _init_extra_computedKey2, _init_computedKey3, _init_extra_computedKey3, _init_computedKey4, _init_extra_computedKey4, _init_computedKey5, _init_extra_computedKey5, _init_computedKey6, _init_extra_computedKey6, _init_computedKey7, _init_extra_computedKey7, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-fields/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-fields/context-name/output.js index 5c422b4003df..58f66b351de5 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-fields/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-fields/context-name/output.js @@ -1,4 +1,5 @@ -var _init_a, _init_extra_a, _init_a2, _init_extra_a2, _init_computedKey, _init_extra_computedKey, _init_computedKey2, _init_extra_computedKey2, _init_computedKey3, _init_extra_computedKey3, _init_computedKey4, _init_extra_computedKey4, _init_computedKey5, _init_extra_computedKey5, _init_computedKey6, _init_extra_computedKey6, _computedKey, _init_computedKey7, _init_extra_computedKey7; +let _computedKey; +var _init_a, _init_extra_a, _init_a2, _init_extra_a2, _init_computedKey, _init_extra_computedKey, _init_computedKey2, _init_extra_computedKey2, _init_computedKey3, _init_extra_computedKey3, _init_computedKey4, _init_extra_computedKey4, _init_computedKey5, _init_extra_computedKey5, _init_computedKey6, _init_extra_computedKey6, _init_computedKey7, _init_extra_computedKey7; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_init_a, _init_extra_a, _init_a2, _init_extra_a2, _init_computedKey, _init_extra_computedKey, _init_computedKey2, _init_extra_computedKey2, _init_computedKey3, _init_extra_computedKey3, _init_computedKey4, _init_extra_computedKey4, _init_computedKey5, _init_extra_computedKey5, _init_computedKey6, _init_extra_computedKey6, _init_computedKey7, _init_extra_computedKey7] = babelHelpers.applyDecs2311(this, [], [[dec, 8, "a"], [dec, 8, "a", o => o.#a, (o, v) => o.#a = v], [dec, 8, "b"], [dec, 8, "c"], [dec, 8, 0], [dec, 8, 1], [dec, 8, 2n], [dec, 8, 3n], [dec, 8, _computedKey]]).e; @@ -22,7 +22,7 @@ class Foo { static [1] = (_init_extra_computedKey3(), _init_computedKey4()); static 2n = (_init_extra_computedKey4(), _init_computedKey5()); static [3n] = (_init_extra_computedKey5(), _init_computedKey6()); - static [_computedKey] = (_init_extra_computedKey6(), _init_computedKey7()); + static [_computedKey = babelHelpers.toPropertyKey(f())] = (_init_extra_computedKey6(), _init_computedKey7()); static { _init_extra_computedKey7(); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-getters--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-getters--to-es2015/context-name/output.js index 4cbda29af893..82165e802ce6 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-getters--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-getters--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey, _Foo; +let _computedKey; +var _initStatic, _call_a, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-getters/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-getters/context-name/output.js index 004ffb01b827..5fd3b714536e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-getters/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-getters/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey; +let _computedKey; +var _initStatic, _call_a; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs2311(this, [], [[dec, 11, "a"], [dec, 11, "a", function () {}], [dec, 11, "b"], [dec, 11, "c"], [dec, 11, 0], [dec, 11, 1], [dec, 11, 2n], [dec, 11, 3n], [dec, 11, _computedKey]]).e; @@ -25,6 +25,6 @@ class Foo { static get [1]() {} static get 2n() {} static get [3n]() {} - static get [_computedKey]() {} + static get [_computedKey = babelHelpers.toPropertyKey(f())]() {} } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-methods--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-methods--to-es2015/context-name/output.js index 1f09056249bb..d9fde73378a5 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-methods--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-methods--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey, _Foo; +let _computedKey; +var _initStatic, _call_a, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-methods/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-methods/context-name/output.js index e7fe92877e78..813d4ffd84f4 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-methods/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-methods/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey; +let _computedKey; +var _initStatic, _call_a; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs2311(this, [], [[dec, 10, "a"], [dec, 10, "a", function () {}], [dec, 10, "b"], [dec, 10, "c"], [dec, 10, 0], [dec, 10, 1], [dec, 10, 2n], [dec, 10, 3n], [dec, 10, _computedKey]]).e; @@ -23,6 +23,6 @@ class Foo { static [1]() {} static 2n() {} static [3n]() {} - static [_computedKey]() {} + static [_computedKey = babelHelpers.toPropertyKey(f())]() {} } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/initProto-existing-derived-constructor/output.js index 9f44f7bece20..b16536287948 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/initProto-existing-derived-constructor/output.js @@ -66,9 +66,10 @@ let log = []; new class Dummy extends B { constructor() { - var _initProto3, _computedKey, _A3; + let _computedKey; + var _initProto3, _A3; let key; - _computedKey = babelHelpers.toPropertyKey((key = super(5).method(), log.push(key), key)); + _computedKey = (key = super(5).method(), log.push(key), key); class A extends B { constructor() { log.push((super(6), babelHelpers.defineProperty(this, _computedKey, void _initProto3(this))).method()); @@ -90,8 +91,9 @@ const noop = () => fn => fn; new class extends B { constructor() { + let _ref; var _initProto4, _noopDecs, _A4; - _noopDecs = noop(log.push(super(7).method())); + _ref = (_noopDecs = noop(log.push(super(7).method())), "noop"); class A extends B { constructor() { log.push(_initProto4(super(8)).method()); @@ -99,7 +101,7 @@ method() { return this.a; } - noop() {} + [_ref]() {} } _A4 = A; [_initProto4] = babelHelpers.applyDecs2311(_A4, [], [[dec, 2, "method"], [_noopDecs, 2, "noop"]], 0, void 0, B).e; @@ -114,11 +116,11 @@ let log = []; class A extends B { constructor() { - let _ref; + let _ref2; let key; - new (_ref = (key = _initProto5(super(9)).method(), log.push(key), key), class Dummy extends B { + new (_ref2 = (key = _initProto5(super(9)).method(), log.push(key), key), class Dummy extends B { constructor() { - log.push((super(10), babelHelpers.defineProperty(this, _ref, void 0)).method()); + log.push((super(10), babelHelpers.defineProperty(this, _ref2, void 0)).method()); } })(); } @@ -138,12 +140,13 @@ const noop = () => fn => fn; class A extends B { constructor() { + let _ref3; var _initProto7, _noopDecs2, _Dummy2; - new (_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), (_Dummy2 = class Dummy extends B { + new (_ref3 = (_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), "noop"), (_Dummy2 = class Dummy extends B { constructor() { log.push(_initProto7(super(12)).method()); } - noop() {} + [_ref3]() {} }, [_initProto7] = babelHelpers.applyDecs2311(_Dummy2, [], [[_noopDecs2, 2, "noop"]], 0, void 0, B).e, _Dummy2))(); } method() { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/private-name-in-class-decorator/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/private-name-in-class-decorator/output.js index aef2c0c38eec..db4b874f8640 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/private-name-in-class-decorator/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/private-name-in-class-decorator/output.js @@ -1,17 +1,14 @@ let called = false; class A { constructor() { - var _initClass, _Class_brand, _temp; + let _B2; + var _initClass, _Class, _Class_brand, _B3; let _B; - new (_Class_brand = /*#__PURE__*/new WeakSet(), (_temp = class extends babelHelpers.identity { + new (_Class_brand = /*#__PURE__*/new WeakSet(), _B2 = (_B3 = class B extends A {}, [_B, _initClass] = babelHelpers.applyDecs2311(_B3, [_x], [], 0, void 0, A).c, _B3), (_Class = class extends babelHelpers.identity { constructor() { (super(_B), babelHelpers.classPrivateMethodInitSpec(this, _Class_brand), this), _initClass(); } - }, (_B2 => { - class B extends A {} - _B2 = B; - [_B, _initClass] = babelHelpers.applyDecs2311(_B2, [_x], [], 0, void 0, A).c; - })(), _temp))(); + }, babelHelpers.defineProperty(_Class, _B2, void 0), _Class))(); function _x3() { throw new Error("Should not be called"); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/super-in-decorator/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/super-in-decorator/output.js index 739c5dff4e08..12fb90139d8a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/super-in-decorator/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/super-in-decorator/output.js @@ -1,14 +1,15 @@ class A extends B { m() { + let _ref; var _initProto, _initClass, _classDecs, _m2Decs, _C2; _classDecs = [this, super.dec1]; - _m2Decs = [this, super.dec2]; let _C; + _ref = (_m2Decs = [this, super.dec2], "m2"); class C { constructor() { _initProto(this); } - m2() {} + [_ref]() {} } _C2 = C; ({ diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/valid-expression-formats/output.js index 2639bbf1f9aa..6ea7a78fd117 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/valid-expression-formats/output.js @@ -8,10 +8,11 @@ class Foo { } method() {} makeClass() { + let _ref; var _barDecs, _init_bar, _init_extra_bar, _Nested; - return _barDecs = babelHelpers.classPrivateFieldGet2(_a, this), (_Nested = class Nested { + return _ref = (_barDecs = babelHelpers.classPrivateFieldGet2(_a, this), "bar"), (_Nested = class Nested { constructor() { - babelHelpers.defineProperty(this, "bar", _init_bar(this)); + babelHelpers.defineProperty(this, _ref, _init_bar(this)); _init_extra_bar(this); } }, [_init_bar, _init_extra_bar] = babelHelpers.applyDecs2311(_Nested, [], [[_barDecs, 0, "bar"]]).e, _Nested); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/all-decorators/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/all-decorators/output.js index 5a9c61da601d..744127ca3fbe 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/all-decorators/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/all-decorators/output.js @@ -2,55 +2,53 @@ var _initProto, _initStatic, _initClass, _init_a, _init_extra_a, _init_d, _init_ const dec = () => {}; let _Class; new class extends babelHelpers.identity { - static { - class Class { - static { - ({ - e: [_init_m, _init_extra_m, _call_o, _call_p, _call_q, _init_r, _get_r, _set_r, _init_extra_r, _init_d, _init_extra_d, _call_f, _call_g, _call_g2, _init_h, _get_h, _set_h, _init_extra_h, _init_i, _init_extra_i, _init_n, _init_extra_n, _init_a, _init_extra_a, _init_e, _init_extra_e, _initProto, _initStatic], - c: [_Class, _initClass] - } = babelHelpers.applyDecs2311(this, [dec], [[dec, 0, "a"], [dec, 2, "b"], [dec, 3, "c"], [dec, 4, "c"], [dec, 1, "d"], [dec, 0, "e", o => o.#e, (o, v) => o.#e = v], [dec, 2, "f", function () {}], [dec, 3, "g", function () {}], [dec, 4, "g", function (v) {}], [dec, 1, "h", o => o.#B, (o, v) => o.#B = v], [dec, 8, "i"], [dec, 10, "j"], [dec, 11, "k"], [dec, 12, "l"], [dec, 9, "m"], [dec, 8, "n", o => o.#n, (o, v) => o.#n = v], [dec, 10, "o", function () {}], [dec, 11, "p", function () {}], [dec, 12, "q", function (v) {}], [dec, 9, "r", o => o.#D, (o, v) => o.#D = v]], 0, _ => #e in _)); - _initStatic(this); - } - constructor() { - _init_extra_h(this); - } - #f = _call_f; - a = (_initProto(this), _init_a(this)); - b() {} - get c() {} - set c(v) {} - #A = (_init_extra_a(this), _init_d(this)); - get d() { - return this.#A; - } - set d(v) { - this.#A = v; - } - #e = (_init_extra_d(this), _init_e(this)); - get #g() { - return _call_g(this); - } - set #g(v) { - _call_g2(this, v); - } - #B = (_init_extra_e(this), _init_h(this)); - set #h(v) { - _set_h(this, v); - } - get #h() { - return _get_h(this); - } - static j() {} - static get k() {} - static set l(v) {} - static get m() { - return Class.#C; - } - static set m(v) { - Class.#C = v; - } + static [class Class { + static { + ({ + e: [_init_m, _init_extra_m, _call_o, _call_p, _call_q, _init_r, _get_r, _set_r, _init_extra_r, _init_d, _init_extra_d, _call_f, _call_g, _call_g2, _init_h, _get_h, _set_h, _init_extra_h, _init_i, _init_extra_i, _init_n, _init_extra_n, _init_a, _init_extra_a, _init_e, _init_extra_e, _initProto, _initStatic], + c: [_Class, _initClass] + } = babelHelpers.applyDecs2311(this, [dec], [[dec, 0, "a"], [dec, 2, "b"], [dec, 3, "c"], [dec, 4, "c"], [dec, 1, "d"], [dec, 0, "e", o => o.#e, (o, v) => o.#e = v], [dec, 2, "f", function () {}], [dec, 3, "g", function () {}], [dec, 4, "g", function (v) {}], [dec, 1, "h", o => o.#B, (o, v) => o.#B = v], [dec, 8, "i"], [dec, 10, "j"], [dec, 11, "k"], [dec, 12, "l"], [dec, 9, "m"], [dec, 8, "n", o => o.#n, (o, v) => o.#n = v], [dec, 10, "o", function () {}], [dec, 11, "p", function () {}], [dec, 12, "q", function (v) {}], [dec, 9, "r", o => o.#D, (o, v) => o.#D = v]], 0, _ => #e in _)); + _initStatic(this); } - } + constructor() { + _init_extra_h(this); + } + #f = _call_f; + a = (_initProto(this), _init_a(this)); + b() {} + get c() {} + set c(v) {} + #A = (_init_extra_a(this), _init_d(this)); + get d() { + return this.#A; + } + set d(v) { + this.#A = v; + } + #e = (_init_extra_d(this), _init_e(this)); + get #g() { + return _call_g(this); + } + set #g(v) { + _call_g2(this, v); + } + #B = (_init_extra_e(this), _init_h(this)); + set #h(v) { + _set_h(this, v); + } + get #h() { + return _get_h(this); + } + static j() {} + static get k() {} + static set l(v) {} + static get m() { + return Class.#C; + } + static set m(v) { + Class.#C = v; + } + }]; #o = _call_o; i = _init_i(); #C = (_init_extra_i(), _init_m()); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/initProto-existing-derived-constructor/output.js index 7c6303ac8107..6db679229ebe 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/initProto-existing-derived-constructor/output.js @@ -68,9 +68,9 @@ let log = []; new class Dummy extends B { constructor() { - var _initProto3, _computedKey; + let _computedKey; + var _initProto3; let key; - _computedKey = babelHelpers.toPropertyKey((key = super(5).method(), log.push(key), key)); class A extends B { static { [_initProto3] = babelHelpers.applyDecs2311(this, [], [[dec, 2, "method"]], 0, void 0, B).e; @@ -81,7 +81,7 @@ method() { return this.a; } - [_computedKey] = void _initProto3(this); + [_computedKey = (key = super(5).method(), log.push(key), key)] = void _initProto3(this); } new A(); } @@ -95,7 +95,6 @@ new class extends B { constructor() { var _initProto4, _noopDecs; - _noopDecs = noop(log.push(super(7).method())); class A extends B { static { [_initProto4] = babelHelpers.applyDecs2311(this, [], [[dec, 2, "method"], [_noopDecs, 2, "noop"]], 0, void 0, B).e; @@ -106,7 +105,7 @@ method() { return this.a; } - noop() {} + [(_noopDecs = noop(log.push(super(7).method())), "noop")]() {} } new A(); } @@ -148,15 +147,15 @@ } constructor() { var _initProto7, _noopDecs2; - new (_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), class Dummy extends B { + new class Dummy extends B { static { [_initProto7] = babelHelpers.applyDecs2311(this, [], [[_noopDecs2, 2, "noop"]], 0, void 0, B).e; } constructor() { log.push(_initProto7(super(12)).method()); } - noop() {} - })(); + [(_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), "noop")]() {} + }(); } method() { return this.a; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/private-name-in-class-decorator/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/private-name-in-class-decorator/output.js index 7c338b5f8d9d..28900b6cbf94 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/private-name-in-class-decorator/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/private-name-in-class-decorator/output.js @@ -8,13 +8,11 @@ class A { _classDecs = [A, A.#x]; let _B; new class extends babelHelpers.identity { - static { - class B extends A { - static { - [_B, _initClass] = babelHelpers.applyDecs2311(this, _classDecs, [], 1, void 0, A).c; - } + static [class B extends A { + static { + [_B, _initClass] = babelHelpers.applyDecs2311(this, _classDecs, [], 1, void 0, A).c; } - } + }]; #x() { throw new Error("Should not be called"); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/super-in-decorator/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/super-in-decorator/output.js index 353c0958663c..e662cbab84c5 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/super-in-decorator/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/super-in-decorator/output.js @@ -2,7 +2,6 @@ class A extends B { m() { var _initProto, _initClass, _classDecs, _m2Decs; _classDecs = [this, super.dec1]; - _m2Decs = [this, super.dec2]; let _C; class C { static { @@ -14,7 +13,7 @@ class A extends B { constructor() { _initProto(this); } - m2() {} + [(_m2Decs = [this, super.dec2], "m2")]() {} static { _initClass(); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/valid-expression-formats/output.js index 789320a8bb4a..ad07c5f57372 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/valid-expression-formats/output.js @@ -12,14 +12,14 @@ class Foo { method() {} makeClass() { var _barDecs, _init_bar, _init_extra_bar; - return _barDecs = [this, this.#a], class Nested { + return class Nested { static { [_init_bar, _init_extra_bar] = babelHelpers.applyDecs2311(this, [], [[_barDecs, 16, "bar"]]).e; } constructor() { _init_extra_bar(this); } - bar = _init_bar(this); + [(_barDecs = [this, this.#a], "bar")] = _init_bar(this); }; } static { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/field-initializers-after-methods-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/field-initializers-after-methods-private/output.js index 86d08a4e3d9e..4250ce7a9065 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/field-initializers-after-methods-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/field-initializers-after-methods-private/output.js @@ -2,17 +2,7 @@ var _fooDecs, _init_foo, _init_extra_foo; var counter = 0; class A { static { - _fooDecs = (_, { - addInitializer - }) => { - addInitializer(function () { - counter++; - expect(typeof this.method).toBe("function"); - expect(this.#foo).toBe("#foo"); - expect(() => this.#bar).toThrow(); - }); - }; - [_init_foo, _init_extra_foo] = babelHelpers.applyDecs2311(this, [[_fooDecs, 0, "foo", o => o.#foo, (o, v) => o.#foo = v]], [], 0, _ => #bar in _).e; + [_init_foo, _init_extra_foo] = babelHelpers.applyDecs2311(this, [], [[_fooDecs, 0, "foo", o => o.#foo, (o, v) => o.#foo = v]], 0, _ => #bar in _).e; } #foo = _init_foo(this, (() => { counter++; @@ -21,7 +11,16 @@ class A { expect(() => this.#bar).toThrow(); return "#foo"; })()); - method() {} + [(_fooDecs = (_, { + addInitializer + }) => { + addInitializer(function () { + counter++; + expect(typeof this.method).toBe("function"); + expect(this.#foo).toBe("#foo"); + expect(() => this.#bar).toThrow(); + }); + }, "method")]() {} #bar = (_init_extra_foo(this), (() => { counter++; expect(typeof this.method).toBe("function"); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-setters--to-es2015/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-setters--to-es2015/context-name/output.js index 407f1eb4d90b..b8c5ca85876b 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-setters--to-es2015/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-setters--to-es2015/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey, _Foo; +let _computedKey; +var _initStatic, _call_a, _Foo; const logs = []; const dec = (value, context) => { logs.push(context.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-setters/context-name/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-setters/context-name/output.js index 951f772c1a55..39f8838aa38e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-setters/context-name/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-setters/context-name/output.js @@ -1,4 +1,5 @@ -var _initStatic, _call_a, _computedKey; +let _computedKey; +var _initStatic, _call_a; const logs = []; const dec = (value, context) => { logs.push(context.name); @@ -9,7 +10,6 @@ const f = () => { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; }; -_computedKey = babelHelpers.toPropertyKey(f()); class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs2311(this, [], [[dec, 12, "a"], [dec, 12, "a", function (v) {}], [dec, 12, "b"], [dec, 12, "c"], [dec, 12, 0], [dec, 12, 1], [dec, 12, 2n], [dec, 12, 3n], [dec, 12, _computedKey]]).e; @@ -25,6 +25,6 @@ class Foo { static set [1](v) {} static set 2n(v) {} static set [3n](v) {} - static set [_computedKey](v) {} + static set [_computedKey = babelHelpers.toPropertyKey(f())](v) {} } expect(logs).toStrictEqual(["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"]); diff --git a/packages/babel-plugin-transform-class-properties/test/fixtures/nested-class/super-call-in-decorator/output.js b/packages/babel-plugin-transform-class-properties/test/fixtures/nested-class/super-call-in-decorator/output.js index e200a4a08dbb..fae10f791551 100644 --- a/packages/babel-plugin-transform-class-properties/test/fixtures/nested-class/super-call-in-decorator/output.js +++ b/packages/babel-plugin-transform-class-properties/test/fixtures/nested-class/super-call-in-decorator/output.js @@ -7,13 +7,14 @@ let Hello = /*#__PURE__*/babelHelpers.createClass(function Hello() { let Outer = /*#__PURE__*/function (_Hello) { babelHelpers.inherits(Outer, _Hello); function Outer() { + let _ref; var _helloDecs, _init_hello, _init_extra_hello, _Inner; var _this; babelHelpers.classCallCheck(this, Outer); - _helloDecs = _this = babelHelpers.callSuper(this, Outer); + _ref = (_helloDecs = _this = babelHelpers.callSuper(this, Outer), "hello"); let Inner = /*#__PURE__*/babelHelpers.createClass(function Inner() { babelHelpers.classCallCheck(this, Inner); - babelHelpers.defineProperty(this, "hello", _init_hello(this)); + babelHelpers.defineProperty(this, _ref, _init_hello(this)); _init_extra_hello(this); }); _Inner = Inner; diff --git a/packages/babel-plugin-transform-class-properties/test/fixtures/nested-class/super-property-in-accessor-key/output.js b/packages/babel-plugin-transform-class-properties/test/fixtures/nested-class/super-property-in-accessor-key/output.js index c9f5b9e466d3..9e534a51f488 100644 --- a/packages/babel-plugin-transform-class-properties/test/fixtures/nested-class/super-property-in-accessor-key/output.js +++ b/packages/babel-plugin-transform-class-properties/test/fixtures/nested-class/super-property-in-accessor-key/output.js @@ -15,30 +15,30 @@ let Hello = /*#__PURE__*/function () { let Outer = /*#__PURE__*/function (_Hello) { babelHelpers.inherits(Outer, _Hello); function Outer() { - var _computedKey; + let _computedKey; var _thisSuper, _this; babelHelpers.classCallCheck(this, Outer); _this = babelHelpers.callSuper(this, Outer); - _computedKey = babelHelpers.toPropertyKey(babelHelpers.get((_thisSuper = babelHelpers.assertThisInitialized(_this), babelHelpers.getPrototypeOf(Outer.prototype)), "toString", _thisSuper).call(_thisSuper)); var _A = /*#__PURE__*/new WeakMap(); - let Inner = /*#__PURE__*/function () { + _computedKey = babelHelpers.toPropertyKey(babelHelpers.get((_thisSuper = babelHelpers.assertThisInitialized(_this), babelHelpers.getPrototypeOf(Outer.prototype)), "toString", _thisSuper).call(_thisSuper)); + let Inner = /*#__PURE__*/function (_computedKey4, _computedKey5) { function Inner() { babelHelpers.classCallCheck(this, Inner); babelHelpers.classPrivateFieldInitSpec(this, _A, 'hello'); } babelHelpers.createClass(Inner, [{ - key: _computedKey, + key: _computedKey4, get: function () { return babelHelpers.classPrivateFieldGet2(_A, this); } }, { - key: _computedKey, + key: _computedKey5, set: function (v) { babelHelpers.classPrivateFieldSet2(_A, this, v); } }]); return Inner; - }(); + }(_computedKey, _computedKey); return babelHelpers.possibleConstructorReturn(_this, new Inner()); } return babelHelpers.createClass(Outer); From bf86824adde9f3c0a56630963845012bfaf56005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 4 Mar 2024 19:48:08 -0500 Subject: [PATCH 12/27] rewrite findLast usage for legacy node support --- .../src/decorators.ts | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index b1bcbf85d18c..62b78ac8635c 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -1524,14 +1524,18 @@ function transformClass( if (computedKeyAssignments.length > 0) { const elements = path.get("body.body"); - const lastComputedElement = elements.findLast(path => { - if ((path.node as ClassElementCanHaveComputedKeys).computed) { - if (classDecorators && path.isClassProperty({ static: true })) { - return false; + let lastComputedElement: NodePath; + for (let i = elements.length - 1; i >= 0; i--) { + const path = elements[i]; + const node = path.node as ClassElementCanHaveComputedKeys; + if (node.computed) { + if (classDecorators && t.isClassProperty(node, { static: true })) { + continue; } - return true; + lastComputedElement = path as NodePath; + break; } - }) as NodePath; + } if (lastComputedElement != null) { appendExpressionsToComputedKey( computedKeyAssignments, @@ -1728,21 +1732,24 @@ function transformClass( // todo: the following branch will fail on 2023-05 version if (version === "2023-11") { const elements = originalClassPath.get("body.body"); - const lastPublicElement = elements.findLast(path => { + let lastPublicElement: NodePath; + for (let i = elements.length - 1; i >= 0; i--) { + const path = elements[i]; if ( (path.isClassProperty() || path.isClassMethod()) && !path.node.computed && (path.node as t.ClassMethod).kind !== "constructor" ) { - return true; + lastPublicElement = path; + break; } - }) as NodePath; + } if (lastPublicElement != null) { // Convert it to a computed key to host decorator evaluations convertToComputedKey(lastPublicElement); prependExpressionsToComputedKey( computedKeyAssignments, - lastPublicElement as NodePath, + lastPublicElement, ); computedKeyAssignments = []; } From fff405f210cb9ed6d01e25e856f8cffbc1ae0654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 4 Mar 2024 19:58:38 -0500 Subject: [PATCH 13/27] make old node happy --- .../2023-11-misc/decorator-evaluation-arguments/options.json | 2 +- .../2023-11-misc/decorator-evaluation-new-target/options.json | 2 +- .../decorator-evaluation-super-getter-setter/options.json | 2 +- .../decorator-evaluation-super-property/options.json | 2 +- .../2023-11-misc/decorator-evaluation-this/options.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-arguments/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-arguments/options.json index 98a9bacf3887..3ee7a8cee21c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-arguments/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-arguments/options.json @@ -3,5 +3,5 @@ ["proposal-decorators", { "version": "2023-11" }], "transform-class-static-block" ], - "minNodeVersion": "12.0.0" + "minNodeVersion": "16.9.0" } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-new-target/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-new-target/options.json index 98a9bacf3887..3ee7a8cee21c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-new-target/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-new-target/options.json @@ -3,5 +3,5 @@ ["proposal-decorators", { "version": "2023-11" }], "transform-class-static-block" ], - "minNodeVersion": "12.0.0" + "minNodeVersion": "16.9.0" } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-getter-setter/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-getter-setter/options.json index 98a9bacf3887..3ee7a8cee21c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-getter-setter/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-getter-setter/options.json @@ -3,5 +3,5 @@ ["proposal-decorators", { "version": "2023-11" }], "transform-class-static-block" ], - "minNodeVersion": "12.0.0" + "minNodeVersion": "16.9.0" } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-property/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-property/options.json index 98a9bacf3887..3ee7a8cee21c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-property/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-super-property/options.json @@ -3,5 +3,5 @@ ["proposal-decorators", { "version": "2023-11" }], "transform-class-static-block" ], - "minNodeVersion": "12.0.0" + "minNodeVersion": "16.9.0" } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-this/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-this/options.json index 98a9bacf3887..3ee7a8cee21c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-this/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-this/options.json @@ -3,5 +3,5 @@ ["proposal-decorators", { "version": "2023-11" }], "transform-class-static-block" ], - "minNodeVersion": "12.0.0" + "minNodeVersion": "16.9.0" } From f4314e53b0a980a40dee6f3d9332d92d933eea87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 5 Mar 2024 11:08:10 -0500 Subject: [PATCH 14/27] fix: use temp class fields to host decorator expr --- .../src/decorators.ts | 185 +++--------------- .../class-underscore-property/exec.js | 52 +++++ 2 files changed, 76 insertions(+), 161 deletions(-) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/class-underscore-property/exec.js diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index 62b78ac8635c..26cb71cc2d5b 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -1,8 +1,7 @@ import type { NodePath, Scope, Visitor } from "@babel/traverse"; -import { types as t, template, traverse } from "@babel/core"; +import { types as t, template } from "@babel/core"; import ReplaceSupers from "@babel/helper-replace-supers"; import splitExportDeclaration from "@babel/helper-split-export-declaration"; -import environmentVisitor from "@babel/helper-environment-visitor"; import * as charCodes from "charcodes"; import type { PluginAPI, PluginObject, PluginPass } from "@babel/core"; import { skipTransparentExprWrappers } from "@babel/helper-skip-transparent-expression-wrappers"; @@ -836,58 +835,6 @@ function createPrivateBrandCheckClosure(brandName: t.PrivateName) { ); } -/** - * create a super() delegate - * (...args) => super(...args) - * - */ -function createSuperCallDelegate() { - return t.arrowFunctionExpression( - [t.restElement(t.identifier("args"))], - t.callExpression(t.super(), [t.spreadElement(t.identifier("args"))]), - ); -} - -/** - * create a super[prop] delegate - * (prop) => Object.defineProperty({}, "_", { - * get: () => super[prop], - * set: (v) => super[prop] = v - * }) - * - */ -function createSuperPropDelegate() { - const getDelegate = t.arrowFunctionExpression( - [], - t.memberExpression(t.super(), t.identifier("prop"), true), - ); - const setDelegate = t.assignmentExpression( - "=", - t.memberExpression(t.super(), t.identifier("prop"), true), - t.identifier("v"), - ); - return t.arrowFunctionExpression( - [t.identifier("prop")], - t.callExpression( - t.memberExpression( - t.identifier("Object"), - t.identifier("defineProperty"), - ), - [ - t.objectExpression([]), - t.stringLiteral("_"), - t.objectExpression([ - t.objectProperty(t.identifier("get"), getDelegate), - t.objectProperty( - t.identifier("set"), - t.arrowFunctionExpression([t.identifier("v")], setDelegate), - ), - ]), - ], - ), - ); -} - // Check if the expression does not reference function-specific // context or the given identifier name. // `true` means "maybe" and `false` means "no". @@ -1728,9 +1675,12 @@ function transformClass( } originalClass.body.body.unshift(t.staticBlock([])); + const applyDecoratorWrapperPath = originalClassPath + .get("body") + .get("body")[0] as NodePath; if (computedKeyAssignments.length > 0) { // todo: the following branch will fail on 2023-05 version - if (version === "2023-11") { + if (process.env.BABEL_8_BREAKING || version === "2023-11") { const elements = originalClassPath.get("body.body"); let lastPublicElement: NodePath; for (let i = elements.length - 1; i >= 0; i--) { @@ -1753,119 +1703,32 @@ function transformClass( ); computedKeyAssignments = []; } - // when there is no public class elements, the decorator expressions - // assignment will be injected right before the `applyDecs` call. } } - const applyDecoratorWrapperPath = originalClassPath - .get("body") - .get("body")[0] as NodePath; if (computedKeyAssignments.length > 0) { + // when there is no public class elements or decorators version is earlier than 2305, + // we inject a temporary computed field whose key will host the decorator expressions + // assignment. + originalClass.body.body.unshift( + t.classProperty( + t.sequenceExpression([...computedKeyAssignments, t.stringLiteral("_")]), + undefined, + undefined, + undefined, + /* computed */ true, + /* static */ true, + ), + ); applyDecoratorWrapperPath.pushContainer( "body", - t.expressionStatement(maybeSequenceExpression(computedKeyAssignments)), - ); - - const computedKeysPath = applyDecoratorWrapperPath.get("body")[0]; - - // Capture lexical this, super() and other function contexts, replace their usage - // in computed key assignments - let outerThis: t.Identifier, - outerSuperCall: t.Identifier, - outerSuperProp: t.Identifier, - outerArguments: t.Identifier, - outerNewTarget: t.Identifier; - const computedKeysPathVisitor: Visitor = { - ThisExpression(path) { - outerThis ??= scopeParent.generateDeclaredUidIdentifier("outerThis"); - path.replaceWith(t.cloneNode(outerThis)); - }, - CallExpression(path) { - const calleePath = path.get("callee"); - if (calleePath.isSuper()) { - outerSuperCall ??= - scopeParent.generateDeclaredUidIdentifier("outerSuper"); - calleePath.replaceWith(t.cloneNode(outerSuperCall)); - } - }, - MemberExpression(path) { - const objectPath = path.get("object"); - if (objectPath.isSuper()) { - outerSuperProp ??= - scopeParent.generateDeclaredUidIdentifier("outerSuperProp"); - path.replaceWith( - t.memberExpression( - t.callExpression(t.cloneNode(outerSuperProp), [ - path.node.computed - ? (path.node.property as t.Expression) - : t.stringLiteral((path.node.property as t.Identifier).name), - ]), - t.identifier("_"), - ), - ); - } - }, - Identifier(path) { - if (path.node.name === "arguments") { - outerArguments ??= - scopeParent.generateDeclaredUidIdentifier("outerArguments"); - path.replaceWith(t.cloneNode(outerArguments)); - } - }, - MetaProperty(path) { - const object = path.node.meta; - if (object.name === "new") { - outerNewTarget ??= - scopeParent.generateDeclaredUidIdentifier("outerNewTarget"); - path.replaceWith(t.cloneNode(outerNewTarget)); - } - }, - }; - computedKeysPath.traverse( - traverse.visitors.merge([computedKeysPathVisitor, environmentVisitor]), - ); - if (outerThis) { - classAssignments.push( - t.assignmentExpression("=", t.cloneNode(outerThis), t.thisExpression()), - ); - } - if (outerSuperCall) { - classAssignments.push( - t.assignmentExpression( - "=", - t.cloneNode(outerSuperCall), - createSuperCallDelegate(), - ), - ); - } - if (outerSuperProp) { - classAssignments.push( - t.assignmentExpression( - "=", - t.cloneNode(outerSuperProp), - createSuperPropDelegate(), - ), - ); - } - if (outerArguments) { - classAssignments.push( - t.assignmentExpression( - "=", - t.cloneNode(outerArguments), - t.identifier("arguments"), - ), - ); - } - if (outerNewTarget) { - classAssignments.push( - t.assignmentExpression( - "=", - t.cloneNode(outerNewTarget), - t.metaProperty(t.identifier("new"), t.identifier("target")), + t.expressionStatement( + t.unaryExpression( + "delete", + t.memberExpression(t.thisExpression(), t.identifier("_")), ), - ); - } + ), + ); } applyDecoratorWrapperPath.pushContainer( diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/class-underscore-property/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/class-underscore-property/exec.js new file mode 100644 index 000000000000..bc28d94fb7b4 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/class-underscore-property/exec.js @@ -0,0 +1,52 @@ +function noopFactory() { return function noop() {} } + +{ + class B { + @noopFactory() + static _ = "B"; + } + + class C extends B { + @noopFactory() #p; + } + + expect(C._).toBe("B"); +} + +{ + class B { + @noopFactory() + static _ = "B"; + } + + @noopFactory() + class C extends B { + @noopFactory() #p; + } + + expect(C._).toBe("B"); +} + +{ + class C { + @noopFactory() #p; + } + + expect(Reflect.ownKeys(C)).not.toContain("_"); +} + +{ + @noopFactory() + class C {} + + expect(Reflect.ownKeys(C)).not.toContain("_"); +} + +{ + @noopFactory() + class C { + @noopFactory() #p; + } + + expect(Reflect.ownKeys(C)).not.toContain("_"); +} From 2cd5bcc2007b8e9fea907bc96eb5606334f038a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 5 Mar 2024 11:19:15 -0500 Subject: [PATCH 15/27] add class-in-for-loop test --- .../class-in-for-loop/exec.js | 53 +++++++++++++++++++ .../2023-11-misc/class-in-for-loop/exec.js | 53 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/class-in-for-loop/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/class-in-for-loop/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/class-in-for-loop/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/class-in-for-loop/exec.js new file mode 100644 index 000000000000..b2d92bda7b47 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/class-in-for-loop/exec.js @@ -0,0 +1,53 @@ +{ + const logs = []; + const classes = []; + function noop() {} + + for (let i = 0; i < 2; i++) { + classes.push(class C { + @noop [i]; + }) + } + + for (const clazz of classes) { + logs.push(Reflect.ownKeys(new clazz())); + } + + expect(logs.join()).toBe("0,1"); +} + +{ + const logs = []; + const classes = []; + function noop() {} + + for (let i = 0; i < 2; i++) { + classes.push(@noop class C { + [i]; + }) + } + + for (const clazz of classes) { + logs.push(Reflect.ownKeys(new clazz())); + } + + expect(logs.join()).toBe("0,1"); +} + +{ + const logs = []; + const classes = []; + function noop() {} + + for (let i = 0; i < 2; i++) { + classes.push(@noop class C { + @noop [i]; + }) + } + + for (const clazz of classes) { + logs.push(Reflect.ownKeys(new clazz())); + } + + expect(logs.join()).toBe("0,1"); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/class-in-for-loop/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/class-in-for-loop/exec.js new file mode 100644 index 000000000000..b2d92bda7b47 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/class-in-for-loop/exec.js @@ -0,0 +1,53 @@ +{ + const logs = []; + const classes = []; + function noop() {} + + for (let i = 0; i < 2; i++) { + classes.push(class C { + @noop [i]; + }) + } + + for (const clazz of classes) { + logs.push(Reflect.ownKeys(new clazz())); + } + + expect(logs.join()).toBe("0,1"); +} + +{ + const logs = []; + const classes = []; + function noop() {} + + for (let i = 0; i < 2; i++) { + classes.push(@noop class C { + [i]; + }) + } + + for (const clazz of classes) { + logs.push(Reflect.ownKeys(new clazz())); + } + + expect(logs.join()).toBe("0,1"); +} + +{ + const logs = []; + const classes = []; + function noop() {} + + for (let i = 0; i < 2; i++) { + classes.push(@noop class C { + @noop [i]; + }) + } + + for (const clazz of classes) { + logs.push(Reflect.ownKeys(new clazz())); + } + + expect(logs.join()).toBe("0,1"); +} From 707b91ce50f88b8f185d613c456bc1c4d600b287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 5 Mar 2024 12:12:22 -0500 Subject: [PATCH 16/27] fix: skip decorators and key when replacing super within a class method --- .../babel-helper-replace-supers/src/index.ts | 15 +++++++-- .../exec.js | 33 ------------------- .../exec.js | 33 +++++++++++++++++++ 3 files changed, 46 insertions(+), 35 deletions(-) delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/.decorator-evaluation-yield-super-private-all-private/exec.js diff --git a/packages/babel-helper-replace-supers/src/index.ts b/packages/babel-helper-replace-supers/src/index.ts index d30e9e60f989..568bedd76102 100644 --- a/packages/babel-helper-replace-supers/src/index.ts +++ b/packages/babel-helper-replace-supers/src/index.ts @@ -419,16 +419,27 @@ export default class ReplaceSupers { } replace() { + const { methodPath } = this; // https://github.com/babel/babel/issues/11994 if (this.opts.refToPreserve) { - this.methodPath.traverse(unshadowSuperBindingVisitor, { + methodPath.traverse(unshadowSuperBindingVisitor, { refName: this.opts.refToPreserve.name, }); } const handler = this.constantSuper ? looseHandlers : specHandlers; - memberExpressionToFunctions(this.methodPath, visitor, { + // todo: this should have been handled by the environmentVisitor, + // consider add visitSelf support for the path.traverse + visitor.shouldSkip = path => { + if (path.parentPath === methodPath) { + if (path.parentKey === "decorators" || path.parentKey === "key") { + return true; + } + } + }; + + memberExpressionToFunctions(methodPath, visitor, { file: this.file, scope: this.methodPath.scope, isDerivedConstructor: this.isDerivedConstructor, diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/.decorator-evaluation-yield-super-private-all-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/.decorator-evaluation-yield-super-private-all-private/exec.js deleted file mode 100644 index 12046fcc0847..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/.decorator-evaluation-yield-super-private-all-private/exec.js +++ /dev/null @@ -1,33 +0,0 @@ -{ - let B; - - class CaptureFactory { - static *id(fn) { - yield fn; - } - } - - function dummy() {} - - class A extends CaptureFactory { - static #X = "A#X"; - static *[Symbol.iterator] () { - B = @dummy - class B { - static #X = "B#X"; - @(yield* super.id(_ => _.#X), dummy) #method () {} - @(yield* super.id(_ => _.#X), dummy) static #Method () {} - @(yield* super.id(_ => _.#X), dummy) get #getter () {} - @(yield* super.id(_ => _.#X), dummy) static get #Getter () {} - @(yield* super.id(_ => _.#X), dummy) set #setter (v) {} - @(yield* super.id(_ => _.#X), dummy) static set #Setter (v) {} - @(yield* super.id(_ => _.#X), dummy) #property; - @(yield* super.id(_ => _.#X), dummy) static #Property; - @(yield* super.id(_ => _.#X), dummy) accessor #accessor; - @(yield* super.id(_ => _.#X), dummy) static accessor #Accessor; - } - } - } - - expect([...A].map(fn => fn(B)).join(",")).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/exec.js index 8bb4769085bc..4766b6546da4 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/exec.js @@ -64,3 +64,36 @@ expect([...A].map(fn => fn(B)).join(",")).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); } + +{ + let B; + + class CaptureFactory { + static *id(fn) { + yield fn; + } + } + + function dummy() {} + + class A extends CaptureFactory { + static #X = "A#X"; + static *[Symbol.iterator] () { + B = class { + static #X = "B#X"; + @(yield* super.id(_ => _.#X), dummy) #method () {} + @(yield* super.id(_ => _.#X), dummy) static #Method () {} + @(yield* super.id(_ => _.#X), dummy) get #getter () {} + @(yield* super.id(_ => _.#X), dummy) static get #Getter () {} + @(yield* super.id(_ => _.#X), dummy) set #setter (v) {} + @(yield* super.id(_ => _.#X), dummy) static set #Setter (v) {} + @(yield* super.id(_ => _.#X), dummy) #property; + @(yield* super.id(_ => _.#X), dummy) static #Property; + @(yield* super.id(_ => _.#X), dummy) accessor #accessor; + @(yield* super.id(_ => _.#X), dummy) static accessor #Accessor; + } + } + } + + expect([...A].map(fn => fn(B)).join(",")).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); +} From f62c5c2487832b5da831a656fddca4a4d1b6f26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 5 Mar 2024 12:18:01 -0500 Subject: [PATCH 17/27] copy tests to es2015 --- .../class-underscore-property/exec.js | 52 +++++++++++++++++++ .../exec.js | 33 ++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/class-underscore-property/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/class-underscore-property/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/class-underscore-property/exec.js new file mode 100644 index 000000000000..bc28d94fb7b4 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/class-underscore-property/exec.js @@ -0,0 +1,52 @@ +function noopFactory() { return function noop() {} } + +{ + class B { + @noopFactory() + static _ = "B"; + } + + class C extends B { + @noopFactory() #p; + } + + expect(C._).toBe("B"); +} + +{ + class B { + @noopFactory() + static _ = "B"; + } + + @noopFactory() + class C extends B { + @noopFactory() #p; + } + + expect(C._).toBe("B"); +} + +{ + class C { + @noopFactory() #p; + } + + expect(Reflect.ownKeys(C)).not.toContain("_"); +} + +{ + @noopFactory() + class C {} + + expect(Reflect.ownKeys(C)).not.toContain("_"); +} + +{ + @noopFactory() + class C { + @noopFactory() #p; + } + + expect(Reflect.ownKeys(C)).not.toContain("_"); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-yield-private-super-property/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-yield-private-super-property/exec.js index 8bb4769085bc..4766b6546da4 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-yield-private-super-property/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/decorator-evaluation-yield-private-super-property/exec.js @@ -64,3 +64,36 @@ expect([...A].map(fn => fn(B)).join(",")).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); } + +{ + let B; + + class CaptureFactory { + static *id(fn) { + yield fn; + } + } + + function dummy() {} + + class A extends CaptureFactory { + static #X = "A#X"; + static *[Symbol.iterator] () { + B = class { + static #X = "B#X"; + @(yield* super.id(_ => _.#X), dummy) #method () {} + @(yield* super.id(_ => _.#X), dummy) static #Method () {} + @(yield* super.id(_ => _.#X), dummy) get #getter () {} + @(yield* super.id(_ => _.#X), dummy) static get #Getter () {} + @(yield* super.id(_ => _.#X), dummy) set #setter (v) {} + @(yield* super.id(_ => _.#X), dummy) static set #Setter (v) {} + @(yield* super.id(_ => _.#X), dummy) #property; + @(yield* super.id(_ => _.#X), dummy) static #Property; + @(yield* super.id(_ => _.#X), dummy) accessor #accessor; + @(yield* super.id(_ => _.#X), dummy) static accessor #Accessor; + } + } + } + + expect([...A].map(fn => fn(B)).join(",")).toBe("B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X,B#X"); +} From 6969fd41db1aef76a8c0e63e5551ee2bb025d592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 5 Mar 2024 13:52:11 -0500 Subject: [PATCH 18/27] address review comments --- .../src/decorators.ts | 20 ++++++----- .../src/misc.ts | 18 ++++++++-- .../computed-key-ts-as-expression/exec.ts | 17 ++++++++++ .../computed-key-ts-as-expression/input.ts | 17 ++++++++++ .../computed-key-ts-as-expression/output.js | 33 +++++++++++++++++++ .../fixtures/2023-11-typescript/options.json | 5 +++ 6 files changed, 99 insertions(+), 11 deletions(-) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/exec.ts create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/input.ts create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/options.json diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index 26cb71cc2d5b..0e11fa015e2f 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -279,11 +279,12 @@ function extractProxyAccessorsFor( } function getComputedKeyCompletion(path: NodePath) { + path = skipTransparentExprWrappers(path); if (path.isSequenceExpression()) { const expressions = path.get("expressions"); return getComputedKeyCompletion(expressions[expressions.length - 1]); } - return skipTransparentExprWrappers(path); + return path; } function getComputedKeyMemoiser(path: NodePath): t.Expression { @@ -314,7 +315,11 @@ function prependExpressionsToComputedKey( >, ) { const key = fieldPath.get("key") as NodePath; - expressions.push(key.node); + if (key.isSequenceExpression()) { + expressions.push(...key.node.expressions); + } else { + expressions.push(key.node); + } key.replaceWith(maybeSequenceExpression(expressions)); } @@ -328,7 +333,6 @@ function appendExpressionsToComputedKey( const completion = getComputedKeyCompletion(key); if (completion.isConstantExpression()) { prependExpressionsToComputedKey(expressions, fieldPath); - return; } else { const scopeParent = key.scope.parent; const maybeAssignment = memoiseComputedKey( @@ -336,7 +340,11 @@ function appendExpressionsToComputedKey( scopeParent, scopeParent.generateUid("computedKey"), ); - if (maybeAssignment != null) { + if (!maybeAssignment) { + // If the memoiseComputedKey returns undefined, the key is already a uid reference, + // treat it as a constant expression and prepend expressions before it + prependExpressionsToComputedKey(expressions, fieldPath); + } else { const expressionSequence = [ ...expressions, // preserve the completion result @@ -353,10 +361,6 @@ function appendExpressionsToComputedKey( ]), ); } - } else { - // If the computed key is an uid reference, treat it as - // a constant expression - prependExpressionsToComputedKey(expressions, fieldPath); } } } diff --git a/packages/babel-helper-create-class-features-plugin/src/misc.ts b/packages/babel-helper-create-class-features-plugin/src/misc.ts index 7ccf62c346a3..19af4d27f353 100644 --- a/packages/babel-helper-create-class-features-plugin/src/misc.ts +++ b/packages/babel-helper-create-class-features-plugin/src/misc.ts @@ -123,19 +123,31 @@ export function injectInitialization( type ComputedKeyAssignmentExpression = t.AssignmentExpression & { left: t.Identifier; }; + +/** + * Try to memoise a computed key. + * It returns undefined when the computed key is an uid reference, otherwise + * an assignment expression `memoiserId = computed key` + * @export + * @param {t.Expression} keyNode Computed key + * @param {Scope} scope The scope where memoiser id should be registered + * @param {string} hint The memoiser id hint + * @returns {(ComputedKeyAssignmentExpression | undefined)} + */ export function memoiseComputedKey( keyNode: t.Expression, scope: Scope, hint: string, ): ComputedKeyAssignmentExpression | undefined { const isUidReference = t.isIdentifier(keyNode) && scope.hasUid(keyNode.name); + if (isUidReference) { + return; + } const isMemoiseAssignment = t.isAssignmentExpression(keyNode, { operator: "=" }) && t.isIdentifier(keyNode.left) && scope.hasUid(keyNode.left.name); - if (isUidReference) { - return; - } else if (isMemoiseAssignment) { + if (isMemoiseAssignment) { return t.cloneNode(keyNode as ComputedKeyAssignmentExpression); } else { const ident = t.identifier(hint); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/exec.ts b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/exec.ts new file mode 100644 index 000000000000..049723a84e92 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/exec.ts @@ -0,0 +1,17 @@ +function noopFactory() { return function noop() {} } + +{ + class C { + [("a1", "a2") as any]; + @noopFactory(0) #p; + } + expect(new C()).toHaveProperty("a2"); +} + +{ + class C { + [("a1", ("b1", "b2")) as any]; + @noopFactory(1) #p; + } + expect(new C()).toHaveProperty("b2"); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/input.ts b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/input.ts new file mode 100644 index 000000000000..049723a84e92 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/input.ts @@ -0,0 +1,17 @@ +function noopFactory() { return function noop() {} } + +{ + class C { + [("a1", "a2") as any]; + @noopFactory(0) #p; + } + expect(new C()).toHaveProperty("a2"); +} + +{ + class C { + [("a1", ("b1", "b2")) as any]; + @noopFactory(1) #p; + } + expect(new C()).toHaveProperty("b2"); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/output.js new file mode 100644 index 000000000000..4ba71b503b68 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/output.js @@ -0,0 +1,33 @@ +function noopFactory() { + return function noop() {}; +} +{ + var _pDecs, _init_p, _init_extra_p; + let _computedKey; + class C { + static { + [_init_p, _init_extra_p] = babelHelpers.applyDecs2311(this, [], [[_pDecs, 0, "p", o => o.#p, (o, v) => o.#p = v]], 0, _ => #p in _).e; + } + constructor() { + _init_extra_p(this); + } + [(_computedKey = ("a1", "a2"), _pDecs = noopFactory(0), _computedKey)]; + #p = _init_p(this); + } + expect(new C()).toHaveProperty("a2"); +} +{ + var _pDecs2, _init_p2, _init_extra_p2; + let _computedKey3; + class C { + static { + [_init_p2, _init_extra_p2] = babelHelpers.applyDecs2311(this, [], [[_pDecs2, 0, "p", o => o.#p, (o, v) => o.#p = v]], 0, _ => #p in _).e; + } + constructor() { + _init_extra_p2(this); + } + [(_computedKey3 = ("a1", ("b1", "b2")), _pDecs2 = noopFactory(1), _computedKey3)]; + #p = _init_p2(this); + } + expect(new C()).toHaveProperty("b2"); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/options.json new file mode 100644 index 000000000000..c4d1e38dd159 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/options.json @@ -0,0 +1,5 @@ +{ + "minNodeVersion": "16.11.0", + "plugins": [["proposal-decorators", { "version": "2023-11" }]], + "presets": [["typescript", { "allowDeclareFields": true }]] +} From 4c9c493ced42f70e0fbeb776f88ef40e2e615d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 5 Mar 2024 14:11:26 -0500 Subject: [PATCH 19/27] fix ts errors --- packages/babel-helper-replace-supers/src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/babel-helper-replace-supers/src/index.ts b/packages/babel-helper-replace-supers/src/index.ts index 568bedd76102..58f4d24bc2cb 100644 --- a/packages/babel-helper-replace-supers/src/index.ts +++ b/packages/babel-helper-replace-supers/src/index.ts @@ -431,7 +431,9 @@ export default class ReplaceSupers { // todo: this should have been handled by the environmentVisitor, // consider add visitSelf support for the path.traverse - visitor.shouldSkip = path => { + // @ts-expect-error: Refine typings in packages/babel-traverse/src/types.ts + // shouldSkip is accepted in traverseNode + visitor.shouldSkip = (path: NodePath) => { if (path.parentPath === methodPath) { if (path.parentKey === "decorators" || path.parentKey === "key") { return true; From bdee20d1461713f334b87bc53a5374fd05582d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 5 Mar 2024 14:17:41 -0500 Subject: [PATCH 20/27] enable the lastPublicElement insertion point for other decorator versions --- .../src/decorators.ts | 91 +++++++++---------- 1 file changed, 44 insertions(+), 47 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index 0e11fa015e2f..13426c6e54c4 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -1683,56 +1683,53 @@ function transformClass( .get("body") .get("body")[0] as NodePath; if (computedKeyAssignments.length > 0) { - // todo: the following branch will fail on 2023-05 version - if (process.env.BABEL_8_BREAKING || version === "2023-11") { - const elements = originalClassPath.get("body.body"); - let lastPublicElement: NodePath; - for (let i = elements.length - 1; i >= 0; i--) { - const path = elements[i]; - if ( - (path.isClassProperty() || path.isClassMethod()) && - !path.node.computed && - (path.node as t.ClassMethod).kind !== "constructor" - ) { - lastPublicElement = path; - break; - } - } - if (lastPublicElement != null) { - // Convert it to a computed key to host decorator evaluations - convertToComputedKey(lastPublicElement); - prependExpressionsToComputedKey( - computedKeyAssignments, - lastPublicElement, - ); - computedKeyAssignments = []; + const elements = originalClassPath.get("body.body"); + let lastPublicElement: NodePath; + for (let i = elements.length - 1; i >= 0; i--) { + const path = elements[i]; + if ( + (path.isClassProperty() || path.isClassMethod()) && + !path.node.computed && + (path.node as t.ClassMethod).kind !== "constructor" + ) { + lastPublicElement = path; + break; } } - } - - if (computedKeyAssignments.length > 0) { - // when there is no public class elements or decorators version is earlier than 2305, - // we inject a temporary computed field whose key will host the decorator expressions - // assignment. - originalClass.body.body.unshift( - t.classProperty( - t.sequenceExpression([...computedKeyAssignments, t.stringLiteral("_")]), - undefined, - undefined, - undefined, - /* computed */ true, - /* static */ true, - ), - ); - applyDecoratorWrapperPath.pushContainer( - "body", - t.expressionStatement( - t.unaryExpression( - "delete", - t.memberExpression(t.thisExpression(), t.identifier("_")), + if (lastPublicElement != null) { + // Convert it to a computed key to host decorator evaluations + convertToComputedKey(lastPublicElement); + prependExpressionsToComputedKey( + computedKeyAssignments, + lastPublicElement, + ); + } else { + // when there is no public class elements, we inject a temporary computed field + // whose key will host the decorator expressions assignment. + originalClass.body.body.unshift( + t.classProperty( + t.sequenceExpression([ + ...computedKeyAssignments, + t.stringLiteral("_"), + ]), + undefined, + undefined, + undefined, + /* computed */ true, + /* static */ true, ), - ), - ); + ); + applyDecoratorWrapperPath.pushContainer( + "body", + t.expressionStatement( + t.unaryExpression( + "delete", + t.memberExpression(t.thisExpression(), t.identifier("_")), + ), + ), + ); + } + computedKeyAssignments = []; } applyDecoratorWrapperPath.pushContainer( From d33d87b60156a30f4048cfe72c01868aa01fb898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 5 Mar 2024 13:53:32 -0500 Subject: [PATCH 21/27] update test output --- .../member-decorator/output.mjs | 3 +- .../output.js | 9 +++--- .../valid-expression-formats/output.js | 21 ++++++------- .../output.js | 6 ++-- .../output.js | 15 ++++------ .../valid-expression-formats/output.js | 10 +++---- .../member-decorator/output.mjs | 3 +- .../output.js | 30 ++++++++----------- .../valid-expression-formats/output.js | 27 ++++++++--------- .../output.js | 6 ++-- .../output.js | 15 ++++------ .../valid-expression-formats/output.js | 10 +++---- .../member-decorator/output.mjs | 3 +- .../output.js | 30 ++++++++----------- .../valid-expression-formats/output.js | 27 ++++++++--------- .../output.js | 6 ++-- .../output.js | 15 ++++------ .../valid-expression-formats/output.js | 10 +++---- .../member-decorator/output.mjs | 3 +- .../output.js | 30 ++++++++----------- .../super-in-decorator/output.js | 22 +++++--------- .../2023-05-misc--to-es2015/this/output.js | 15 +++++----- .../valid-expression-formats/output.js | 27 ++++++++--------- .../output.js | 6 ++-- .../output.js | 15 ++++------ .../2023-05-misc/super-in-decorator/output.js | 10 ++----- .../test/fixtures/2023-05-misc/this/output.js | 3 +- .../valid-expression-formats/output.js | 10 +++---- 28 files changed, 158 insertions(+), 229 deletions(-) diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-exported/member-decorator/output.mjs b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-exported/member-decorator/output.mjs index fb2ee3bd4895..0cca4d76816f 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-exported/member-decorator/output.mjs +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-exported/member-decorator/output.mjs @@ -1,8 +1,7 @@ var _xDecs, _init_x; export class A { static { - _xDecs = dec; [_init_x] = babelHelpers.applyDecs(this, [[_xDecs, 0, "x"]], []); } - x = _init_x(this); + [(_xDecs = dec, "x")] = _init_x(this); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/output.js index 878afee02c0c..657560c41ad1 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/output.js @@ -1,15 +1,14 @@ +let _ref; var _initProto, _methodDecs, _A; const dec = () => {}; +_ref = (_methodDecs = deco, "method"); class A extends B { constructor() { let a = 2; _initProto(super(a)); foo(); } - method() {} + [_ref]() {} } _A = A; -(() => { - _methodDecs = deco; - [_initProto] = babelHelpers.applyDecs(_A, [[_methodDecs, 2, "method"]], []); -})(); +[_initProto] = babelHelpers.applyDecs(_A, [[_methodDecs, 2, "method"]], []); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js index 70f8fe77d4c3..9ae354702212 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js @@ -1,28 +1,25 @@ +let _ref; var _initProto, _initClass, _classDecs, _methodDecs, _Foo2; const dec = () => {}; _classDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; let _Foo; var _a = /*#__PURE__*/new WeakMap(); +_ref = (_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "makeClass"); class Foo { constructor() { babelHelpers.classPrivateFieldInitSpec(this, _a, void _initProto(this)); } method() {} - makeClass() { - var _barDecs, _init_bar, _outerThis, _Nested; - return _outerThis = this, (_Nested = class Nested { + [_ref]() { + let _ref2; + var _barDecs, _init_bar, _Nested; + return _ref2 = (_barDecs = babelHelpers.classPrivateFieldGet2(_a, this), "bar"), (_Nested = class Nested { constructor() { - babelHelpers.defineProperty(this, "bar", _init_bar(this)); + babelHelpers.defineProperty(this, _ref2, _init_bar(this)); } - }, (() => { - _barDecs = babelHelpers.classPrivateFieldGet2(_a, _outerThis); - [_init_bar] = babelHelpers.applyDecs(_Nested, [[_barDecs, 0, "bar"]], []); - })(), _Nested); + }, [_init_bar] = babelHelpers.applyDecs(_Nested, [[_barDecs, 0, "bar"]], []), _Nested); } } _Foo2 = Foo; -(() => { - _methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; - [_initProto, _Foo, _initClass] = babelHelpers.applyDecs(_Foo2, [[_methodDecs, 2, "method"]], _classDecs); -})(); +[_initProto, _Foo, _initClass] = babelHelpers.applyDecs(_Foo2, [[_methodDecs, 2, "method"]], _classDecs); _initClass(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js index 7810f09be081..4fbbab619ac0 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js @@ -2,7 +2,6 @@ var _initProto, _methodDecs, _initProto2, _methodDecs2; const dec = () => {}; class A extends B { static { - _methodDecs = deco; [_initProto] = babelHelpers.applyDecs(this, [[_methodDecs, 2, "method"]], []); } constructor() { @@ -12,11 +11,10 @@ class A extends B { _initProto(super(false)); } } - method() {} + [(_methodDecs = deco, "method")]() {} } class C extends B { static { - _methodDecs2 = deco; [_initProto2] = babelHelpers.applyDecs(this, [[_methodDecs2, 2, "method"]], []); } constructor() { @@ -24,5 +22,5 @@ class C extends B { _initProto2(super(_initProto2(super()), null.x)); } catch {} } - method() {} + [(_methodDecs2 = deco, "method")]() {} } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js index 78f40c2519d7..f35be43187a9 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js @@ -94,11 +94,9 @@ const noop = () => fn => fn; new class extends B { constructor() { - var _initProto4, _noopDecs, _outerSuper; - _outerSuper = (...args) => super(...args); + var _initProto4, _noopDecs; class A extends B { static { - _noopDecs = noop(log.push(_outerSuper(7).method())); [_initProto4] = babelHelpers.applyDecs(this, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []); } constructor() { @@ -107,7 +105,7 @@ method() { return this.a; } - noop() {} + [(_noopDecs = noop(log.push(super(7).method())), "noop")]() {} } new A(); } @@ -148,17 +146,16 @@ [_initProto6] = babelHelpers.applyDecs(this, [[dec, 2, "method"]], []); } constructor() { - var _initProto7, _noopDecs2, _outerSuper2; - new (_outerSuper2 = (...args) => super(...args), class Dummy extends B { + var _initProto7, _noopDecs2; + new class Dummy extends B { static { - _noopDecs2 = noop(log.push(_initProto6(_outerSuper2(11)).method())); [_initProto7] = babelHelpers.applyDecs(this, [[_noopDecs2, 2, "noop"]], []); } constructor() { log.push(_initProto7(super(12)).method()); } - noop() {} - })(); + [(_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), "noop")]() {} + }(); } method() { return this.a; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js index f15cee18068e..c61d6551756d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js @@ -4,19 +4,17 @@ _classDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; let _Foo; class Foo { static { - _methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; [_initProto, _Foo, _initClass] = babelHelpers.applyDecs(this, [[_methodDecs, 2, "method"]], _classDecs); } #a = void _initProto(this); method() {} - makeClass() { - var _barDecs, _init_bar, _outerThis; - return _outerThis = this, class Nested { + [(_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "makeClass")]() { + var _barDecs, _init_bar; + return class Nested { static { - _barDecs = _outerThis.#a; [_init_bar] = babelHelpers.applyDecs(this, [[_barDecs, 0, "bar"]], []); } - bar = _init_bar(this); + [(_barDecs = this.#a, "bar")] = _init_bar(this); }; } static { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-exported/member-decorator/output.mjs b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-exported/member-decorator/output.mjs index 3bb3e16a1b2e..0d14bbd16ec2 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-exported/member-decorator/output.mjs +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-exported/member-decorator/output.mjs @@ -1,8 +1,7 @@ var _xDecs, _init_x; export class A { static { - _xDecs = dec; [_init_x] = babelHelpers.applyDecs2203R(this, [[_xDecs, 0, "x"]], []).e; } - x = _init_x(this); + [(_xDecs = dec, "x")] = _init_x(this); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js index 482931a1a711..da32b4131a26 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js @@ -91,8 +91,9 @@ const noop = () => fn => fn; new class extends B { constructor() { - var _initProto4, _noopDecs, _outerSuper, _A4; - _outerSuper = (...args) => super(...args); + let _ref; + var _initProto4, _noopDecs, _A4; + _ref = (_noopDecs = noop(log.push(super(7).method())), "noop"); class A extends B { constructor() { log.push(_initProto4(super(8)).method()); @@ -100,13 +101,10 @@ method() { return this.a; } - noop() {} + [_ref]() {} } _A4 = A; - (() => { - _noopDecs = noop(log.push(_outerSuper(7).method())); - [_initProto4] = babelHelpers.applyDecs2203R(_A4, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []).e; - })(); + [_initProto4] = babelHelpers.applyDecs2203R(_A4, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []).e; new A(); } }(); @@ -118,11 +116,11 @@ let log = []; class A extends B { constructor() { - let _ref; + let _ref2; let key; - new (_ref = (key = _initProto5(super(9)).method(), log.push(key), key), class Dummy extends B { + new (_ref2 = (key = _initProto5(super(9)).method(), log.push(key), key), class Dummy extends B { constructor() { - log.push((super(10), babelHelpers.defineProperty(this, _ref, void 0)).method()); + log.push((super(10), babelHelpers.defineProperty(this, _ref2, void 0)).method()); } })(); } @@ -142,16 +140,14 @@ const noop = () => fn => fn; class A extends B { constructor() { - var _initProto7, _noopDecs2, _outerSuper2, _Dummy2; - new (_outerSuper2 = (...args) => super(...args), (_Dummy2 = class Dummy extends B { + let _ref3; + var _initProto7, _noopDecs2, _Dummy2; + new (_ref3 = (_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), "noop"), (_Dummy2 = class Dummy extends B { constructor() { log.push(_initProto7(super(12)).method()); } - noop() {} - }, (() => { - _noopDecs2 = noop(log.push(_initProto6(_outerSuper2(11)).method())); - [_initProto7] = babelHelpers.applyDecs2203R(_Dummy2, [[_noopDecs2, 2, "noop"]], []).e; - })(), _Dummy2))(); + [_ref3]() {} + }, [_initProto7] = babelHelpers.applyDecs2203R(_Dummy2, [[_noopDecs2, 2, "noop"]], []).e, _Dummy2))(); } method() { return this.a; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/valid-expression-formats/output.js index c4f4d0f3ffbe..cd6dbda1a5aa 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/valid-expression-formats/output.js @@ -1,31 +1,28 @@ +let _ref; var _initProto, _initClass, _classDecs, _methodDecs, _Foo2; const dec = () => {}; _classDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; let _Foo; var _a = /*#__PURE__*/new WeakMap(); +_ref = (_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "makeClass"); class Foo { constructor() { babelHelpers.classPrivateFieldInitSpec(this, _a, void _initProto(this)); } method() {} - makeClass() { - var _barDecs, _init_bar, _outerThis, _Nested; - return _outerThis = this, (_Nested = class Nested { + [_ref]() { + let _ref2; + var _barDecs, _init_bar, _Nested; + return _ref2 = (_barDecs = babelHelpers.classPrivateFieldGet2(_a, this), "bar"), (_Nested = class Nested { constructor() { - babelHelpers.defineProperty(this, "bar", _init_bar(this)); + babelHelpers.defineProperty(this, _ref2, _init_bar(this)); } - }, (() => { - _barDecs = babelHelpers.classPrivateFieldGet2(_a, _outerThis); - [_init_bar] = babelHelpers.applyDecs2203R(_Nested, [[_barDecs, 0, "bar"]], []).e; - })(), _Nested); + }, [_init_bar] = babelHelpers.applyDecs2203R(_Nested, [[_barDecs, 0, "bar"]], []).e, _Nested); } } _Foo2 = Foo; -(() => { - _methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; - ({ - e: [_initProto], - c: [_Foo, _initClass] - } = babelHelpers.applyDecs2203R(_Foo2, [[_methodDecs, 2, "method"]], _classDecs)); -})(); +({ + e: [_initProto], + c: [_Foo, _initClass] +} = babelHelpers.applyDecs2203R(_Foo2, [[_methodDecs, 2, "method"]], _classDecs)); _initClass(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor-multiple-super/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor-multiple-super/output.js index 498be8326084..43ea84d5666b 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor-multiple-super/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor-multiple-super/output.js @@ -2,7 +2,6 @@ var _initProto, _methodDecs, _initProto2, _methodDecs2; const dec = () => {}; class A extends B { static { - _methodDecs = deco; [_initProto] = babelHelpers.applyDecs2203R(this, [[_methodDecs, 2, "method"]], []).e; } constructor() { @@ -12,11 +11,10 @@ class A extends B { _initProto(super(false)); } } - method() {} + [(_methodDecs = deco, "method")]() {} } class C extends B { static { - _methodDecs2 = deco; [_initProto2] = babelHelpers.applyDecs2203R(this, [[_methodDecs2, 2, "method"]], []).e; } constructor() { @@ -24,5 +22,5 @@ class C extends B { _initProto2(super(_initProto2(super()), null.x)); } catch {} } - method() {} + [(_methodDecs2 = deco, "method")]() {} } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor/output.js index 589a7405f4b8..2b82f7527e0e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor/output.js @@ -94,11 +94,9 @@ const noop = () => fn => fn; new class extends B { constructor() { - var _initProto4, _noopDecs, _outerSuper; - _outerSuper = (...args) => super(...args); + var _initProto4, _noopDecs; class A extends B { static { - _noopDecs = noop(log.push(_outerSuper(7).method())); [_initProto4] = babelHelpers.applyDecs2203R(this, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []).e; } constructor() { @@ -107,7 +105,7 @@ method() { return this.a; } - noop() {} + [(_noopDecs = noop(log.push(super(7).method())), "noop")]() {} } new A(); } @@ -148,17 +146,16 @@ [_initProto6] = babelHelpers.applyDecs2203R(this, [[dec, 2, "method"]], []).e; } constructor() { - var _initProto7, _noopDecs2, _outerSuper2; - new (_outerSuper2 = (...args) => super(...args), class Dummy extends B { + var _initProto7, _noopDecs2; + new class Dummy extends B { static { - _noopDecs2 = noop(log.push(_initProto6(_outerSuper2(11)).method())); [_initProto7] = babelHelpers.applyDecs2203R(this, [[_noopDecs2, 2, "noop"]], []).e; } constructor() { log.push(_initProto7(super(12)).method()); } - noop() {} - })(); + [(_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), "noop")]() {} + }(); } method() { return this.a; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/valid-expression-formats/output.js index d5dc3e94e94a..62bb307dbe20 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/valid-expression-formats/output.js @@ -4,7 +4,6 @@ _classDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; let _Foo; class Foo { static { - _methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; ({ e: [_initProto], c: [_Foo, _initClass] @@ -12,14 +11,13 @@ class Foo { } #a = void _initProto(this); method() {} - makeClass() { - var _barDecs, _init_bar, _outerThis; - return _outerThis = this, class Nested { + [(_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "makeClass")]() { + var _barDecs, _init_bar; + return class Nested { static { - _barDecs = _outerThis.#a; [_init_bar] = babelHelpers.applyDecs2203R(this, [[_barDecs, 0, "bar"]], []).e; } - bar = _init_bar(this); + [(_barDecs = this.#a, "bar")] = _init_bar(this); }; } static { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-exported/member-decorator/output.mjs b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-exported/member-decorator/output.mjs index 76d6fda57e6e..dbe34c124d1c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-exported/member-decorator/output.mjs +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-exported/member-decorator/output.mjs @@ -1,8 +1,7 @@ var _xDecs, _init_x; export class A { static { - _xDecs = dec; [_init_x] = babelHelpers.applyDecs2301(this, [[_xDecs, 0, "x"]], []).e; } - x = _init_x(this); + [(_xDecs = dec, "x")] = _init_x(this); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/initProto-existing-derived-constructor/output.js index 13bfbddd97cb..1e228bdee2dc 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/initProto-existing-derived-constructor/output.js @@ -91,8 +91,9 @@ const noop = () => fn => fn; new class extends B { constructor() { - var _initProto4, _noopDecs, _outerSuper, _A4; - _outerSuper = (...args) => super(...args); + let _ref; + var _initProto4, _noopDecs, _A4; + _ref = (_noopDecs = noop(log.push(super(7).method())), "noop"); class A extends B { constructor() { log.push(_initProto4(super(8)).method()); @@ -100,13 +101,10 @@ method() { return this.a; } - noop() {} + [_ref]() {} } _A4 = A; - (() => { - _noopDecs = noop(log.push(_outerSuper(7).method())); - [_initProto4] = babelHelpers.applyDecs2301(_A4, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []).e; - })(); + [_initProto4] = babelHelpers.applyDecs2301(_A4, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []).e; new A(); } }(); @@ -118,11 +116,11 @@ let log = []; class A extends B { constructor() { - let _ref; + let _ref2; let key; - new (_ref = (key = _initProto5(super(9)).method(), log.push(key), key), class Dummy extends B { + new (_ref2 = (key = _initProto5(super(9)).method(), log.push(key), key), class Dummy extends B { constructor() { - log.push((super(10), babelHelpers.defineProperty(this, _ref, void 0)).method()); + log.push((super(10), babelHelpers.defineProperty(this, _ref2, void 0)).method()); } })(); } @@ -142,16 +140,14 @@ const noop = () => fn => fn; class A extends B { constructor() { - var _initProto7, _noopDecs2, _outerSuper2, _Dummy2; - new (_outerSuper2 = (...args) => super(...args), (_Dummy2 = class Dummy extends B { + let _ref3; + var _initProto7, _noopDecs2, _Dummy2; + new (_ref3 = (_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), "noop"), (_Dummy2 = class Dummy extends B { constructor() { log.push(_initProto7(super(12)).method()); } - noop() {} - }, (() => { - _noopDecs2 = noop(log.push(_initProto6(_outerSuper2(11)).method())); - [_initProto7] = babelHelpers.applyDecs2301(_Dummy2, [[_noopDecs2, 2, "noop"]], []).e; - })(), _Dummy2))(); + [_ref3]() {} + }, [_initProto7] = babelHelpers.applyDecs2301(_Dummy2, [[_noopDecs2, 2, "noop"]], []).e, _Dummy2))(); } method() { return this.a; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/valid-expression-formats/output.js index f3fdbfb2d2f5..6d999621a662 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/valid-expression-formats/output.js @@ -1,31 +1,28 @@ +let _ref; var _initProto, _initClass, _classDecs, _methodDecs, _Foo2; const dec = () => {}; _classDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; let _Foo; var _a = /*#__PURE__*/new WeakMap(); +_ref = (_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "makeClass"); class Foo { constructor() { babelHelpers.classPrivateFieldInitSpec(this, _a, void _initProto(this)); } method() {} - makeClass() { - var _barDecs, _init_bar, _outerThis, _Nested; - return _outerThis = this, (_Nested = class Nested { + [_ref]() { + let _ref2; + var _barDecs, _init_bar, _Nested; + return _ref2 = (_barDecs = babelHelpers.classPrivateFieldGet2(_a, this), "bar"), (_Nested = class Nested { constructor() { - babelHelpers.defineProperty(this, "bar", _init_bar(this)); + babelHelpers.defineProperty(this, _ref2, _init_bar(this)); } - }, (() => { - _barDecs = babelHelpers.classPrivateFieldGet2(_a, _outerThis); - [_init_bar] = babelHelpers.applyDecs2301(_Nested, [[_barDecs, 0, "bar"]], []).e; - })(), _Nested); + }, [_init_bar] = babelHelpers.applyDecs2301(_Nested, [[_barDecs, 0, "bar"]], []).e, _Nested); } } _Foo2 = Foo; -(() => { - _methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; - ({ - e: [_initProto], - c: [_Foo, _initClass] - } = babelHelpers.applyDecs2301(_Foo2, [[_methodDecs, 2, "method"]], _classDecs)); -})(); +({ + e: [_initProto], + c: [_Foo, _initClass] +} = babelHelpers.applyDecs2301(_Foo2, [[_methodDecs, 2, "method"]], _classDecs)); _initClass(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor-multiple-super/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor-multiple-super/output.js index e599954eb6c1..621147fcb4df 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor-multiple-super/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor-multiple-super/output.js @@ -2,7 +2,6 @@ var _initProto, _methodDecs, _initProto2, _methodDecs2; const dec = () => {}; class A extends B { static { - _methodDecs = deco; [_initProto] = babelHelpers.applyDecs2301(this, [[_methodDecs, 2, "method"]], []).e; } constructor() { @@ -12,11 +11,10 @@ class A extends B { _initProto(super(false)); } } - method() {} + [(_methodDecs = deco, "method")]() {} } class C extends B { static { - _methodDecs2 = deco; [_initProto2] = babelHelpers.applyDecs2301(this, [[_methodDecs2, 2, "method"]], []).e; } constructor() { @@ -24,5 +22,5 @@ class C extends B { _initProto2(super(_initProto2(super()), null.x)); } catch {} } - method() {} + [(_methodDecs2 = deco, "method")]() {} } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor/output.js index 3f54829ce781..aab336396153 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor/output.js @@ -94,11 +94,9 @@ const noop = () => fn => fn; new class extends B { constructor() { - var _initProto4, _noopDecs, _outerSuper; - _outerSuper = (...args) => super(...args); + var _initProto4, _noopDecs; class A extends B { static { - _noopDecs = noop(log.push(_outerSuper(7).method())); [_initProto4] = babelHelpers.applyDecs2301(this, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []).e; } constructor() { @@ -107,7 +105,7 @@ method() { return this.a; } - noop() {} + [(_noopDecs = noop(log.push(super(7).method())), "noop")]() {} } new A(); } @@ -148,17 +146,16 @@ [_initProto6] = babelHelpers.applyDecs2301(this, [[dec, 2, "method"]], []).e; } constructor() { - var _initProto7, _noopDecs2, _outerSuper2; - new (_outerSuper2 = (...args) => super(...args), class Dummy extends B { + var _initProto7, _noopDecs2; + new class Dummy extends B { static { - _noopDecs2 = noop(log.push(_initProto6(_outerSuper2(11)).method())); [_initProto7] = babelHelpers.applyDecs2301(this, [[_noopDecs2, 2, "noop"]], []).e; } constructor() { log.push(_initProto7(super(12)).method()); } - noop() {} - })(); + [(_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), "noop")]() {} + }(); } method() { return this.a; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/valid-expression-formats/output.js index dadeba29ab56..7542e2969f02 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/valid-expression-formats/output.js @@ -4,7 +4,6 @@ _classDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; let _Foo; class Foo { static { - _methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; ({ e: [_initProto], c: [_Foo, _initClass] @@ -12,14 +11,13 @@ class Foo { } #a = void _initProto(this); method() {} - makeClass() { - var _barDecs, _init_bar, _outerThis; - return _outerThis = this, class Nested { + [(_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "makeClass")]() { + var _barDecs, _init_bar; + return class Nested { static { - _barDecs = _outerThis.#a; [_init_bar] = babelHelpers.applyDecs2301(this, [[_barDecs, 0, "bar"]], []).e; } - bar = _init_bar(this); + [(_barDecs = this.#a, "bar")] = _init_bar(this); }; } static { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-exported/member-decorator/output.mjs b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-exported/member-decorator/output.mjs index 8f7007de68b7..d55544d52daf 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-exported/member-decorator/output.mjs +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-exported/member-decorator/output.mjs @@ -1,8 +1,7 @@ var _xDecs, _init_x; export class A { static { - _xDecs = dec; [_init_x] = babelHelpers.applyDecs2305(this, [[_xDecs, 0, "x"]], []).e; } - x = _init_x(this); + [(_xDecs = dec, "x")] = _init_x(this); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/initProto-existing-derived-constructor/output.js index e854c11ca726..3f4ba9e628b8 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/initProto-existing-derived-constructor/output.js @@ -91,8 +91,9 @@ const noop = () => fn => fn; new class extends B { constructor() { - var _initProto4, _noopDecs, _outerSuper, _A4; - _outerSuper = (...args) => super(...args); + let _ref; + var _initProto4, _noopDecs, _A4; + _ref = (_noopDecs = noop(log.push(super(7).method())), "noop"); class A extends B { constructor() { log.push(_initProto4(super(8)).method()); @@ -100,13 +101,10 @@ method() { return this.a; } - noop() {} + [_ref]() {} } _A4 = A; - (() => { - _noopDecs = noop(log.push(_outerSuper(7).method())); - [_initProto4] = babelHelpers.applyDecs2305(_A4, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], [], 0, void 0, B).e; - })(); + [_initProto4] = babelHelpers.applyDecs2305(_A4, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], [], 0, void 0, B).e; new A(); } }(); @@ -118,11 +116,11 @@ let log = []; class A extends B { constructor() { - let _ref; + let _ref2; let key; - new (_ref = (key = _initProto5(super(9)).method(), log.push(key), key), class Dummy extends B { + new (_ref2 = (key = _initProto5(super(9)).method(), log.push(key), key), class Dummy extends B { constructor() { - log.push((super(10), babelHelpers.defineProperty(this, _ref, void 0)).method()); + log.push((super(10), babelHelpers.defineProperty(this, _ref2, void 0)).method()); } })(); } @@ -142,16 +140,14 @@ const noop = () => fn => fn; class A extends B { constructor() { - var _initProto7, _noopDecs2, _outerSuper2, _Dummy2; - new (_outerSuper2 = (...args) => super(...args), (_Dummy2 = class Dummy extends B { + let _ref3; + var _initProto7, _noopDecs2, _Dummy2; + new (_ref3 = (_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), "noop"), (_Dummy2 = class Dummy extends B { constructor() { log.push(_initProto7(super(12)).method()); } - noop() {} - }, (() => { - _noopDecs2 = noop(log.push(_initProto6(_outerSuper2(11)).method())); - [_initProto7] = babelHelpers.applyDecs2305(_Dummy2, [[_noopDecs2, 2, "noop"]], [], 0, void 0, B).e; - })(), _Dummy2))(); + [_ref3]() {} + }, [_initProto7] = babelHelpers.applyDecs2305(_Dummy2, [[_noopDecs2, 2, "noop"]], [], 0, void 0, B).e, _Dummy2))(); } method() { return this.a; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/super-in-decorator/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/super-in-decorator/output.js index 39bd58f0f9bd..9b3371e11cfd 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/super-in-decorator/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/super-in-decorator/output.js @@ -1,27 +1,21 @@ class A extends B { m() { - var _initProto, _initClass, _classDecs, _m2Decs, _outerThis, _outerSuperProp, _C2; + let _ref; + var _initProto, _initClass, _classDecs, _m2Decs, _C2; _classDecs = [this, super.dec1]; - _outerThis = this; - _outerSuperProp = prop => Object.defineProperty({}, "_", { - get: () => super[prop], - set: v => super[prop] = v - }); let _C; + _ref = (_m2Decs = [this, super.dec2], "m2"); class C { constructor() { _initProto(this); } - m2() {} + [_ref]() {} } _C2 = C; - (() => { - _m2Decs = [_outerThis, _outerSuperProp("dec2")._]; - ({ - e: [_initProto], - c: [_C, _initClass] - } = babelHelpers.applyDecs2305(_C2, [[_m2Decs, 18, "m2"]], _classDecs, 1)); - })(); + ({ + e: [_initProto], + c: [_C, _initClass] + } = babelHelpers.applyDecs2305(_C2, [[_m2Decs, 18, "m2"]], _classDecs, 1)); _initClass(); } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/this/output.js index 55dd372d474a..16a2ebc1aea2 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/this/output.js @@ -1,18 +1,17 @@ +let _ref; var _initClass, _obj, _classDecs, _xDecs, _init_x, _yDecs, _init_y, _A2; _classDecs = [_obj = o1, _obj.dec, void 0, dec, _obj = o2, _obj.dec]; let _A; +_ref = (_xDecs = [_obj = o2, _obj.dec, _obj = o3.o, _obj.dec], _yDecs = [_obj = o2, _obj.dec, void 0, dec], "y"); class A { constructor() { babelHelpers.defineProperty(this, "x", _init_x(this)); - babelHelpers.defineProperty(this, "y", _init_y(this)); + babelHelpers.defineProperty(this, _ref, _init_y(this)); } } _A2 = A; -(() => { - _xDecs = [_obj = o2, _obj.dec, _obj = o3.o, _obj.dec], _yDecs = [_obj = o2, _obj.dec, void 0, dec]; - ({ - e: [_init_x, _init_y], - c: [_A, _initClass] - } = babelHelpers.applyDecs2305(_A2, [[_xDecs, 16, "x"], [_yDecs, 16, "y"]], _classDecs, 1)); -})(); +({ + e: [_init_x, _init_y], + c: [_A, _initClass] +} = babelHelpers.applyDecs2305(_A2, [[_xDecs, 16, "x"], [_yDecs, 16, "y"]], _classDecs, 1)); _initClass(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/valid-expression-formats/output.js index 69802959da7d..f920b9a7e7b2 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/valid-expression-formats/output.js @@ -1,31 +1,28 @@ +let _ref; var _initProto, _initClass, _obj, _classDecs, _methodDecs, _Foo2; const dec = () => {}; _classDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]]; let _Foo; var _a = /*#__PURE__*/new WeakMap(); +_ref = (_methodDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]], "makeClass"); class Foo { constructor() { babelHelpers.classPrivateFieldInitSpec(this, _a, void _initProto(this)); } method() {} - makeClass() { - var _barDecs, _init_bar, _outerThis, _Nested; - return _outerThis = this, (_Nested = class Nested { + [_ref]() { + let _ref2; + var _barDecs, _init_bar, _Nested; + return _ref2 = (_barDecs = babelHelpers.classPrivateFieldGet2(_a, this), "bar"), (_Nested = class Nested { constructor() { - babelHelpers.defineProperty(this, "bar", _init_bar(this)); + babelHelpers.defineProperty(this, _ref2, _init_bar(this)); } - }, (() => { - _barDecs = babelHelpers.classPrivateFieldGet2(_a, _outerThis); - [_init_bar] = babelHelpers.applyDecs2305(_Nested, [[_barDecs, 0, "bar"]], []).e; - })(), _Nested); + }, [_init_bar] = babelHelpers.applyDecs2305(_Nested, [[_barDecs, 0, "bar"]], []).e, _Nested); } } _Foo2 = Foo; -(() => { - _methodDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]]; - ({ - e: [_initProto], - c: [_Foo, _initClass] - } = babelHelpers.applyDecs2305(_Foo2, [[_methodDecs, 18, "method"]], _classDecs, 1)); -})(); +({ + e: [_initProto], + c: [_Foo, _initClass] +} = babelHelpers.applyDecs2305(_Foo2, [[_methodDecs, 18, "method"]], _classDecs, 1)); _initClass(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor-multiple-super/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor-multiple-super/output.js index b3d434c10165..63b4395d07c6 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor-multiple-super/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor-multiple-super/output.js @@ -2,7 +2,6 @@ var _initProto, _methodDecs, _B, _initProto2, _methodDecs2, _B2; const dec = () => {}; class A extends (_B = B) { static { - _methodDecs = deco; [_initProto] = babelHelpers.applyDecs2305(this, [[_methodDecs, 2, "method"]], [], 0, void 0, _B).e; } constructor() { @@ -12,11 +11,10 @@ class A extends (_B = B) { _initProto(super(false)); } } - method() {} + [(_methodDecs = deco, "method")]() {} } class C extends (_B2 = B) { static { - _methodDecs2 = deco; [_initProto2] = babelHelpers.applyDecs2305(this, [[_methodDecs2, 2, "method"]], [], 0, void 0, _B2).e; } constructor() { @@ -24,5 +22,5 @@ class C extends (_B2 = B) { _initProto2(super(_initProto2(super()), null.x)); } catch {} } - method() {} + [(_methodDecs2 = deco, "method")]() {} } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor/output.js index 57af0fe87e7f..da91a3dd7008 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor/output.js @@ -94,11 +94,9 @@ const noop = () => fn => fn; new class extends B { constructor() { - var _initProto4, _noopDecs, _outerSuper; - _outerSuper = (...args) => super(...args); + var _initProto4, _noopDecs; class A extends B { static { - _noopDecs = noop(log.push(_outerSuper(7).method())); [_initProto4] = babelHelpers.applyDecs2305(this, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], [], 0, void 0, B).e; } constructor() { @@ -107,7 +105,7 @@ method() { return this.a; } - noop() {} + [(_noopDecs = noop(log.push(super(7).method())), "noop")]() {} } new A(); } @@ -148,17 +146,16 @@ [_initProto6] = babelHelpers.applyDecs2305(this, [[dec, 2, "method"]], [], 0, void 0, B).e; } constructor() { - var _initProto7, _noopDecs2, _outerSuper2; - new (_outerSuper2 = (...args) => super(...args), class Dummy extends B { + var _initProto7, _noopDecs2; + new class Dummy extends B { static { - _noopDecs2 = noop(log.push(_initProto6(_outerSuper2(11)).method())); [_initProto7] = babelHelpers.applyDecs2305(this, [[_noopDecs2, 2, "noop"]], [], 0, void 0, B).e; } constructor() { log.push(_initProto7(super(12)).method()); } - noop() {} - })(); + [(_noopDecs2 = noop(log.push(_initProto6(super(11)).method())), "noop")]() {} + }(); } method() { return this.a; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/super-in-decorator/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/super-in-decorator/output.js index 9a8e51ad88f7..005591fd124c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/super-in-decorator/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/super-in-decorator/output.js @@ -1,16 +1,10 @@ class A extends B { m() { - var _initProto, _initClass, _classDecs, _m2Decs, _outerThis, _outerSuperProp; + var _initProto, _initClass, _classDecs, _m2Decs; _classDecs = [this, super.dec1]; - _outerThis = this; - _outerSuperProp = prop => Object.defineProperty({}, "_", { - get: () => super[prop], - set: v => super[prop] = v - }); let _C; class C { static { - _m2Decs = [_outerThis, _outerSuperProp("dec2")._]; ({ e: [_initProto], c: [_C, _initClass] @@ -19,7 +13,7 @@ class A extends B { constructor() { _initProto(this); } - m2() {} + [(_m2Decs = [this, super.dec2], "m2")]() {} static { _initClass(); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/this/output.js index 1813ca370e61..34d9936c60be 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/this/output.js @@ -3,14 +3,13 @@ _classDecs = [_obj = o1, _obj.dec, void 0, dec, _obj = o2, _obj.dec]; let _A; class A { static { - _xDecs = [_obj = o2, _obj.dec, _obj = o3.o, _obj.dec], _yDecs = [_obj = o2, _obj.dec, void 0, dec]; ({ e: [_init_x, _init_y], c: [_A, _initClass] } = babelHelpers.applyDecs2305(this, [[_xDecs, 16, "x"], [_yDecs, 16, "y"]], _classDecs, 1)); } x = _init_x(this); - y = _init_y(this); + [(_xDecs = [_obj = o2, _obj.dec, _obj = o3.o, _obj.dec], _yDecs = [_obj = o2, _obj.dec, void 0, dec], "y")] = _init_y(this); static { _initClass(); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/valid-expression-formats/output.js index 7660e901d752..2fd62ac4b441 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/valid-expression-formats/output.js @@ -4,7 +4,6 @@ _classDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitra let _Foo; class Foo { static { - _methodDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]]; ({ e: [_initProto], c: [_Foo, _initClass] @@ -12,14 +11,13 @@ class Foo { } #a = void _initProto(this); method() {} - makeClass() { - var _barDecs, _init_bar, _outerThis; - return _outerThis = this, class Nested { + [(_methodDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]], "makeClass")]() { + var _barDecs, _init_bar; + return class Nested { static { - _barDecs = [_outerThis, _outerThis.#a]; [_init_bar] = babelHelpers.applyDecs2305(this, [[_barDecs, 16, "bar"]], []).e; } - bar = _init_bar(this); + [(_barDecs = [this, this.#a], "bar")] = _init_bar(this); }; } static { From 7ad03e3a9e5ddcfafb3d88db0d04551f4b32375b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 5 Mar 2024 14:29:17 -0500 Subject: [PATCH 22/27] ensure typescript test works in both Babel 8 and Babel 7 --- .../computed-key-ts-as-expression/exec.ts | 6 +++--- .../computed-key-ts-as-expression/input.ts | 6 +++--- .../computed-key-ts-as-expression/output.js | 8 +++++--- .../test/fixtures/2023-11-typescript/options.json | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/exec.ts b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/exec.ts index 049723a84e92..e5285d93a38a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/exec.ts +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/exec.ts @@ -1,8 +1,8 @@ -function noopFactory() { return function noop() {} } +function noopFactory() { return function noop(x) { return x } } { class C { - [("a1", "a2") as any]; + [("a1", "a2") as any]() {}; @noopFactory(0) #p; } expect(new C()).toHaveProperty("a2"); @@ -10,7 +10,7 @@ function noopFactory() { return function noop() {} } { class C { - [("a1", ("b1", "b2")) as any]; + [("a1", ("b1", "b2")) as any]() {}; @noopFactory(1) #p; } expect(new C()).toHaveProperty("b2"); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/input.ts b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/input.ts index 049723a84e92..e5285d93a38a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/input.ts +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/input.ts @@ -1,8 +1,8 @@ -function noopFactory() { return function noop() {} } +function noopFactory() { return function noop(x) { return x } } { class C { - [("a1", "a2") as any]; + [("a1", "a2") as any]() {}; @noopFactory(0) #p; } expect(new C()).toHaveProperty("a2"); @@ -10,7 +10,7 @@ function noopFactory() { return function noop() {} } { class C { - [("a1", ("b1", "b2")) as any]; + [("a1", ("b1", "b2")) as any]() {}; @noopFactory(1) #p; } expect(new C()).toHaveProperty("b2"); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/output.js index 4ba71b503b68..8a29f5aeafa7 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/computed-key-ts-as-expression/output.js @@ -1,5 +1,7 @@ function noopFactory() { - return function noop() {}; + return function noop(x) { + return x; + }; } { var _pDecs, _init_p, _init_extra_p; @@ -11,7 +13,7 @@ function noopFactory() { constructor() { _init_extra_p(this); } - [(_computedKey = ("a1", "a2"), _pDecs = noopFactory(0), _computedKey)]; + [(_computedKey = ("a1", "a2"), _pDecs = noopFactory(0), _computedKey)]() {} #p = _init_p(this); } expect(new C()).toHaveProperty("a2"); @@ -26,7 +28,7 @@ function noopFactory() { constructor() { _init_extra_p2(this); } - [(_computedKey3 = ("a1", ("b1", "b2")), _pDecs2 = noopFactory(1), _computedKey3)]; + [(_computedKey3 = ("a1", ("b1", "b2")), _pDecs2 = noopFactory(1), _computedKey3)]() {} #p = _init_p2(this); } expect(new C()).toHaveProperty("b2"); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/options.json index c4d1e38dd159..044273423f51 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-typescript/options.json @@ -1,5 +1,5 @@ { "minNodeVersion": "16.11.0", "plugins": [["proposal-decorators", { "version": "2023-11" }]], - "presets": [["typescript", { "allowDeclareFields": true }]] + "presets": [["typescript"]] } From ccb441a87985f19c2bae8bcd522da7409021474c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 5 Mar 2024 14:35:57 -0500 Subject: [PATCH 23/27] make old node happy --- .../options.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/options.json index 98a9bacf3887..3ee7a8cee21c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/decorator-evaluation-yield-private-super-property/options.json @@ -3,5 +3,5 @@ ["proposal-decorators", { "version": "2023-11" }], "transform-class-static-block" ], - "minNodeVersion": "12.0.0" + "minNodeVersion": "16.9.0" } From 9073384b04f342916eca4cf4a7e6b4291e008419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 5 Mar 2024 17:18:46 -0500 Subject: [PATCH 24/27] workaround pushContainer AST sync issue --- .../src/decorators.ts | 52 +++++++++---------- .../input.js | 10 ++++ .../options.json | 12 +++++ .../output.js | 7 +++ 4 files changed, 54 insertions(+), 27 deletions(-) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/destructuring-transform-integration/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/destructuring-transform-integration/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/destructuring-transform-integration/output.js diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index 13426c6e54c4..cf6284d7301a 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -1678,10 +1678,9 @@ function transformClass( } } - originalClass.body.body.unshift(t.staticBlock([])); - const applyDecoratorWrapperPath = originalClassPath - .get("body") - .get("body")[0] as NodePath; + const applyDecoratorWrapper = t.staticBlock([]); + originalClass.body.body.unshift(applyDecoratorWrapper); + const applyDecsBody = applyDecoratorWrapper.body; if (computedKeyAssignments.length > 0) { const elements = originalClassPath.get("body.body"); let lastPublicElement: NodePath; @@ -1719,8 +1718,7 @@ function transformClass( /* static */ true, ), ); - applyDecoratorWrapperPath.pushContainer( - "body", + applyDecsBody.push( t.expressionStatement( t.unaryExpression( "delete", @@ -1732,29 +1730,29 @@ function transformClass( computedKeyAssignments = []; } - applyDecoratorWrapperPath.pushContainer( - "body", - [ - t.expressionStatement( - createLocalsAssignment( - elementLocals, - classLocals, - elementDecorations, - classDecorationsId ?? t.arrayExpression(classDecorations), - t.numericLiteral(classDecorationsFlag), - needsInstancePrivateBrandCheck ? lastInstancePrivateName : null, - typeof className === "object" ? className : undefined, - t.cloneNode(superClass), - state, - version, - ), + applyDecsBody.push( + t.expressionStatement( + createLocalsAssignment( + elementLocals, + classLocals, + elementDecorations, + classDecorationsId ?? t.arrayExpression(classDecorations), + t.numericLiteral(classDecorationsFlag), + needsInstancePrivateBrandCheck ? lastInstancePrivateName : null, + typeof className === "object" ? className : undefined, + t.cloneNode(superClass), + state, + version, ), - staticInitLocal && - t.expressionStatement( - t.callExpression(t.cloneNode(staticInitLocal), [t.thisExpression()]), - ), - ].filter(Boolean), + ), ); + if (staticInitLocal) { + applyDecsBody.push( + t.expressionStatement( + t.callExpression(t.cloneNode(staticInitLocal), [t.thisExpression()]), + ), + ); + } // When path is a ClassExpression, path.insertBefore will convert `path` // into a SequenceExpression diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/destructuring-transform-integration/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/destructuring-transform-integration/input.js new file mode 100644 index 000000000000..7d71e215df9b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/destructuring-transform-integration/input.js @@ -0,0 +1,10 @@ +// from https://github.com/tc39/test262/blob/9e03c403e73341658d8d485a673798ae61f6f94a/test/language/statements/class/decorator/syntax/class-valid/decorator-member-expr-private-identifier.js +class C { + static #$() {} + static #_() {} + + static { + var D = @C.#$ + @C.#_ class {} + } +}; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/destructuring-transform-integration/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/destructuring-transform-integration/options.json new file mode 100644 index 000000000000..499bfe680fd9 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/destructuring-transform-integration/options.json @@ -0,0 +1,12 @@ +{ + "plugins": [ + ["proposal-decorators", { "version": "2023-11" }], + "transform-class-properties", + "transform-private-methods", + "transform-class-static-block", + "transform-destructuring" + ], + "generatorOpts": { + "comments": false + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/destructuring-transform-integration/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/destructuring-transform-integration/output.js new file mode 100644 index 000000000000..6270a41f708b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/destructuring-transform-integration/output.js @@ -0,0 +1,7 @@ +class C {} +function _$() {} +function _() {} +((_initClass, _D, _D2, _babelHelpers$applyDe) => { + var D = ((_D2 = class D {}, (_babelHelpers$applyDe = babelHelpers.slicedToArray(babelHelpers.applyDecs2311(_D2, [_$, _], []).c, 2), _D = _babelHelpers$applyDe[0], _initClass = _babelHelpers$applyDe[1]), _initClass()), _D); +})(); +; From af8caa67c9c5f8e7a3e4a5dafdb453da29beea15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 5 Mar 2024 20:21:42 -0500 Subject: [PATCH 25/27] small tweaks - rename some routines - improve originalClassPath access, to avoid a full traversal - add more jsdoc coments --- .../src/decorators.ts | 121 +++++++++++++----- 1 file changed, 88 insertions(+), 33 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index cf6284d7301a..437801a62417 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -278,29 +278,47 @@ function extractProxyAccessorsFor( ]; } -function getComputedKeyCompletion(path: NodePath) { +/** + * Get the last element for the given computed key path. + * + * This function unwraps transparent wrappers and gets the last item when + * the key is a SequenceExpression. + * + * @param {NodePath} path The key of a computed class element + * @returns {NodePath} The simple completion result + */ +function getComputedKeyLastElement( + path: NodePath, +): NodePath { path = skipTransparentExprWrappers(path); if (path.isSequenceExpression()) { const expressions = path.get("expressions"); - return getComputedKeyCompletion(expressions[expressions.length - 1]); + return getComputedKeyLastElement(expressions[expressions.length - 1]); } return path; } +/** + * Get a memoiser of the computed key path. + * + * This function does not mutate AST. If the computed key is not a constant + * expression, this function must be called after the key has been memoised. + * + * @param {NodePath} path The key of a computed class element. + * @returns {t.Expression} A clone of key if key is a constant expression, + * otherwise a memoiser identifier. + */ function getComputedKeyMemoiser(path: NodePath): t.Expression { - const completion = getComputedKeyCompletion(path); - if (completion.isConstantExpression()) { + const element = getComputedKeyLastElement(path); + if (element.isConstantExpression()) { return t.cloneNode(path.node); - } else if ( - completion.isIdentifier() && - path.scope.hasUid(completion.node.name) - ) { + } else if (element.isIdentifier() && path.scope.hasUid(element.node.name)) { return t.cloneNode(path.node); } else if ( - completion.isAssignmentExpression() && - completion.get("left").isIdentifier() + element.isAssignmentExpression() && + element.get("left").isIdentifier() ) { - return t.cloneNode(completion.node.left as t.Identifier); + return t.cloneNode(element.node.left as t.Identifier); } else { throw new Error( `Internal Error: the computed key ${path.toString()} has not yet been memoised.`, @@ -308,6 +326,17 @@ function getComputedKeyMemoiser(path: NodePath): t.Expression { } } +/** + * Prepend expressions to the computed key of the given field path. + * + * If the computed key is a sequence expression, this function will unwrap + * the sequence expression for optimal output size. + * + * @param {t.Expression[]} expressions + * @param {(NodePath< + * t.ClassMethod | t.ClassProperty | t.ClassAccessorProperty + * >)} fieldPath + */ function prependExpressionsToComputedKey( expressions: t.Expression[], fieldPath: NodePath< @@ -323,6 +352,18 @@ function prependExpressionsToComputedKey( key.replaceWith(maybeSequenceExpression(expressions)); } +/** + * Append expressions to the computed key of the given field path. + * + * If the computed key is a constant expression or uid reference, it + * will prepend expressions before the comptued key. Otherwise it will + * memoise the computed key to preserve its completion result. + * + * @param {t.Expression[]} expressions + * @param {(NodePath< + * t.ClassMethod | t.ClassProperty | t.ClassAccessorProperty + * >)} fieldPath + */ function appendExpressionsToComputedKey( expressions: t.Expression[], fieldPath: NodePath< @@ -330,7 +371,7 @@ function appendExpressionsToComputedKey( >, ) { const key = fieldPath.get("key") as NodePath; - const completion = getComputedKeyCompletion(key); + const completion = getComputedKeyLastElement(key); if (completion.isConstantExpression()) { prependExpressionsToComputedKey(expressions, fieldPath); } else { @@ -877,6 +918,14 @@ function usesPrivateField(expression: t.Node) { } } +/** + * Convert a non-computed class element to its equivalent computed form. + * + * This function is to provide a decorator evaluation storage from non-computed + * class elements. + * + * @param {(NodePath)} path A non-computed class property or method + */ function convertToComputedKey(path: NodePath) { const { node } = path; node.computed = true; @@ -1232,9 +1281,9 @@ function transformClass( scopeParent.generateUid("computedKey"), ); if (maybeAssignment != null) { - // If it is a static computed field within a decorated class, move the computed key into - // computed key assignments which will be then moved into the non-static class, to ensure - // that the evaluation order is correct and the private environment is correct + // If it is a static computed field within a decorated class, we move the computed key + // into `computedKeyAssignments` which will be then moved into the non-static class, + // to ensure that the evaluation order and private environment are correct if (classDecorators && element.isClassProperty({ static: true })) { node.key = t.cloneNode(maybeAssignment.left); computedKeyAssignments.push(maybeAssignment); @@ -1417,12 +1466,16 @@ function transformClass( if (isComputed && computedKeyAssignments.length > 0) { if (classDecorators && element.isClassProperty({ static: true })) { - // do nothing + // If the class is decorated, we don't insert computedKeyAssignments here + // because any non-static computed elements defined after it will be moved + // into the non-static class, so they will be evaluated before the key of + // this field. At this momemnt, its key must be either a constant expression + // or a uid reference which has been assigned _within_ the non-static class. } else { prependExpressionsToComputedKey( computedKeyAssignments, (kind === ACCESSOR - ? element.getNextSibling() // the getter transpiled from the accessor + ? element.getNextSibling() // the transpiled getter of the accessor property : element) as NodePath, ); computedKeyAssignments = []; @@ -1494,8 +1547,9 @@ function transformClass( ); computedKeyAssignments = []; } else { - // if there is no computed key, we will try to convert the last non-computed class element - // into a computed key and insert them there + // If there is no computed key, we will try to convert the last non-computed + // class element into a computed key and insert assignments there. This will + // be done after we handle the class elements split when the class is decorated. } } @@ -1606,8 +1660,10 @@ function transformClass( staticsClass.body.body = [ // Insert the original class to a computed key of the wrapper so that // 1) they share the same function context with the wrapper class - // 2) the memoisation of static computed field is evaluated before they are referenced - // in the wrapper class keys + // 2) the memoisation of static computed field is evaluated before they + // are referenced in the wrapper class keys + // Note that any static elements of the wrapper class can not be accessed + // in the user land, so we don't have to remove the temporary class field. t.classProperty( t.toExpression(originalClass), undefined, @@ -1646,16 +1702,14 @@ function transformClass( newExpr.arguments.push(t.cloneNode(classIdLocal)); } - path.replaceWith(newExpr); + const [newPath] = path.replaceWith(newExpr); - path.traverse({ - Class(path) { - if (path.node === originalClass) { - originalClassPath = path; - path.stop(); - } - }, - }); + // update originalClassPath according to the new AST + originalClassPath = ( + newPath.get("callee").get("body") as NodePath + ) + .get("body")[0] + .get("key"); } } if (!classInitInjected && classInitCall) { @@ -1696,15 +1750,16 @@ function transformClass( } } if (lastPublicElement != null) { - // Convert it to a computed key to host decorator evaluations + // Convert its key to a computed one to host the decorator evaluations. convertToComputedKey(lastPublicElement); prependExpressionsToComputedKey( computedKeyAssignments, lastPublicElement, ); } else { - // when there is no public class elements, we inject a temporary computed field - // whose key will host the decorator expressions assignment. + // When there is no public class elements, we inject a temporary computed + // field whose key will host the decorator evaluations. The field will be + // deleted immediately after it is defiend. originalClass.body.body.unshift( t.classProperty( t.sequenceExpression([ From e856f3ccae87fbf5da14cdf41c12de34d6ef6910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 5 Mar 2024 20:27:21 -0500 Subject: [PATCH 26/27] output: inject computed key assignments in the first public element --- .../src/decorators.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index 437801a62417..a122c0deed39 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -1547,7 +1547,7 @@ function transformClass( ); computedKeyAssignments = []; } else { - // If there is no computed key, we will try to convert the last non-computed + // If there is no computed key, we will try to convert the first non-computed // class element into a computed key and insert assignments there. This will // be done after we handle the class elements split when the class is decorated. } @@ -1737,24 +1737,22 @@ function transformClass( const applyDecsBody = applyDecoratorWrapper.body; if (computedKeyAssignments.length > 0) { const elements = originalClassPath.get("body.body"); - let lastPublicElement: NodePath; - for (let i = elements.length - 1; i >= 0; i--) { - const path = elements[i]; + let firstPublicElement: NodePath; + for (const path of elements) { if ( (path.isClassProperty() || path.isClassMethod()) && - !path.node.computed && (path.node as t.ClassMethod).kind !== "constructor" ) { - lastPublicElement = path; + firstPublicElement = path; break; } } - if (lastPublicElement != null) { + if (firstPublicElement != null) { // Convert its key to a computed one to host the decorator evaluations. - convertToComputedKey(lastPublicElement); + convertToComputedKey(firstPublicElement); prependExpressionsToComputedKey( computedKeyAssignments, - lastPublicElement, + firstPublicElement, ); } else { // When there is no public class elements, we inject a temporary computed From 20426d6efa59d9abd4d86f208a1ce6bdd721d831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 5 Mar 2024 20:28:24 -0500 Subject: [PATCH 27/27] update test output --- .../valid-expression-formats/output.js | 6 +++--- .../initProto-existing-derived-constructor/output.js | 4 ++-- .../2021-12-misc/valid-expression-formats/output.js | 4 ++-- .../initProto-existing-derived-constructor/output.js | 6 +++--- .../valid-expression-formats/output.js | 6 +++--- .../initProto-existing-derived-constructor/output.js | 4 ++-- .../2022-03-misc/valid-expression-formats/output.js | 4 ++-- .../initProto-existing-derived-constructor/output.js | 6 +++--- .../valid-expression-formats/output.js | 6 +++--- .../initProto-existing-derived-constructor/output.js | 4 ++-- .../2023-01-misc/valid-expression-formats/output.js | 4 ++-- .../initProto-existing-derived-constructor/output.js | 6 +++--- .../test/fixtures/2023-05-misc--to-es2015/this/output.js | 6 +++--- .../valid-expression-formats/output.js | 6 +++--- .../initProto-existing-derived-constructor/output.js | 4 ++-- .../test/fixtures/2023-05-misc/this/output.js | 4 ++-- .../2023-05-misc/valid-expression-formats/output.js | 4 ++-- .../initProto-existing-derived-constructor/output.js | 6 +++--- .../initProto-existing-derived-constructor/output.js | 4 ++-- 19 files changed, 47 insertions(+), 47 deletions(-) diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js index 9ae354702212..d60ee229294a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js @@ -4,13 +4,13 @@ const dec = () => {}; _classDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; let _Foo; var _a = /*#__PURE__*/new WeakMap(); -_ref = (_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "makeClass"); +_ref = (_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "method"); class Foo { constructor() { babelHelpers.classPrivateFieldInitSpec(this, _a, void _initProto(this)); } - method() {} - [_ref]() { + [_ref]() {} + makeClass() { let _ref2; var _barDecs, _init_bar, _Nested; return _ref2 = (_barDecs = babelHelpers.classPrivateFieldGet2(_a, this), "bar"), (_Nested = class Nested { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js index f35be43187a9..10be9ad680a3 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js @@ -102,10 +102,10 @@ constructor() { log.push(_initProto4(super(8)).method()); } - method() { + [(_noopDecs = noop(log.push(super(7).method())), "method")]() { return this.a; } - [(_noopDecs = noop(log.push(super(7).method())), "noop")]() {} + noop() {} } new A(); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js index c61d6551756d..aa688bacbc33 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js @@ -7,8 +7,8 @@ class Foo { [_initProto, _Foo, _initClass] = babelHelpers.applyDecs(this, [[_methodDecs, 2, "method"]], _classDecs); } #a = void _initProto(this); - method() {} - [(_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "makeClass")]() { + [(_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "method")]() {} + makeClass() { var _barDecs, _init_bar; return class Nested { static { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js index da32b4131a26..9c5025fced14 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js @@ -93,15 +93,15 @@ constructor() { let _ref; var _initProto4, _noopDecs, _A4; - _ref = (_noopDecs = noop(log.push(super(7).method())), "noop"); + _ref = (_noopDecs = noop(log.push(super(7).method())), "method"); class A extends B { constructor() { log.push(_initProto4(super(8)).method()); } - method() { + [_ref]() { return this.a; } - [_ref]() {} + noop() {} } _A4 = A; [_initProto4] = babelHelpers.applyDecs2203R(_A4, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []).e; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/valid-expression-formats/output.js index cd6dbda1a5aa..808c255693fb 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc--to-es2015/valid-expression-formats/output.js @@ -4,13 +4,13 @@ const dec = () => {}; _classDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; let _Foo; var _a = /*#__PURE__*/new WeakMap(); -_ref = (_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "makeClass"); +_ref = (_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "method"); class Foo { constructor() { babelHelpers.classPrivateFieldInitSpec(this, _a, void _initProto(this)); } - method() {} - [_ref]() { + [_ref]() {} + makeClass() { let _ref2; var _barDecs, _init_bar, _Nested; return _ref2 = (_barDecs = babelHelpers.classPrivateFieldGet2(_a, this), "bar"), (_Nested = class Nested { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor/output.js index 2b82f7527e0e..5330cb1cbe6a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/initProto-existing-derived-constructor/output.js @@ -102,10 +102,10 @@ constructor() { log.push(_initProto4(super(8)).method()); } - method() { + [(_noopDecs = noop(log.push(super(7).method())), "method")]() { return this.a; } - [(_noopDecs = noop(log.push(super(7).method())), "noop")]() {} + noop() {} } new A(); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/valid-expression-formats/output.js index 62bb307dbe20..3347e22686ba 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-misc/valid-expression-formats/output.js @@ -10,8 +10,8 @@ class Foo { } = babelHelpers.applyDecs2203R(this, [[_methodDecs, 2, "method"]], _classDecs)); } #a = void _initProto(this); - method() {} - [(_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "makeClass")]() { + [(_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "method")]() {} + makeClass() { var _barDecs, _init_bar; return class Nested { static { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/initProto-existing-derived-constructor/output.js index 1e228bdee2dc..989b6bc2820a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/initProto-existing-derived-constructor/output.js @@ -93,15 +93,15 @@ constructor() { let _ref; var _initProto4, _noopDecs, _A4; - _ref = (_noopDecs = noop(log.push(super(7).method())), "noop"); + _ref = (_noopDecs = noop(log.push(super(7).method())), "method"); class A extends B { constructor() { log.push(_initProto4(super(8)).method()); } - method() { + [_ref]() { return this.a; } - [_ref]() {} + noop() {} } _A4 = A; [_initProto4] = babelHelpers.applyDecs2301(_A4, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], []).e; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/valid-expression-formats/output.js index 6d999621a662..ed4321d24604 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc--to-es2015/valid-expression-formats/output.js @@ -4,13 +4,13 @@ const dec = () => {}; _classDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]]; let _Foo; var _a = /*#__PURE__*/new WeakMap(); -_ref = (_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "makeClass"); +_ref = (_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "method"); class Foo { constructor() { babelHelpers.classPrivateFieldInitSpec(this, _a, void _initProto(this)); } - method() {} - [_ref]() { + [_ref]() {} + makeClass() { let _ref2; var _barDecs, _init_bar, _Nested; return _ref2 = (_barDecs = babelHelpers.classPrivateFieldGet2(_a, this), "bar"), (_Nested = class Nested { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor/output.js index aab336396153..eec00a89647f 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/initProto-existing-derived-constructor/output.js @@ -102,10 +102,10 @@ constructor() { log.push(_initProto4(super(8)).method()); } - method() { + [(_noopDecs = noop(log.push(super(7).method())), "method")]() { return this.a; } - [(_noopDecs = noop(log.push(super(7).method())), "noop")]() {} + noop() {} } new A(); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/valid-expression-formats/output.js index 7542e2969f02..89c2c2b99741 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/valid-expression-formats/output.js @@ -10,8 +10,8 @@ class Foo { } = babelHelpers.applyDecs2301(this, [[_methodDecs, 2, "method"]], _classDecs)); } #a = void _initProto(this); - method() {} - [(_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "makeClass")]() { + [(_methodDecs = [dec, call(), chain.expr(), arbitrary + expr, array[expr]], "method")]() {} + makeClass() { var _barDecs, _init_bar; return class Nested { static { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/initProto-existing-derived-constructor/output.js index 3f4ba9e628b8..24ecbc119f5f 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/initProto-existing-derived-constructor/output.js @@ -93,15 +93,15 @@ constructor() { let _ref; var _initProto4, _noopDecs, _A4; - _ref = (_noopDecs = noop(log.push(super(7).method())), "noop"); + _ref = (_noopDecs = noop(log.push(super(7).method())), "method"); class A extends B { constructor() { log.push(_initProto4(super(8)).method()); } - method() { + [_ref]() { return this.a; } - [_ref]() {} + noop() {} } _A4 = A; [_initProto4] = babelHelpers.applyDecs2305(_A4, [[dec, 2, "method"], [_noopDecs, 2, "noop"]], [], 0, void 0, B).e; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/this/output.js index 16a2ebc1aea2..84902a78d7d7 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/this/output.js @@ -2,11 +2,11 @@ let _ref; var _initClass, _obj, _classDecs, _xDecs, _init_x, _yDecs, _init_y, _A2; _classDecs = [_obj = o1, _obj.dec, void 0, dec, _obj = o2, _obj.dec]; let _A; -_ref = (_xDecs = [_obj = o2, _obj.dec, _obj = o3.o, _obj.dec], _yDecs = [_obj = o2, _obj.dec, void 0, dec], "y"); +_ref = (_xDecs = [_obj = o2, _obj.dec, _obj = o3.o, _obj.dec], _yDecs = [_obj = o2, _obj.dec, void 0, dec], "x"); class A { constructor() { - babelHelpers.defineProperty(this, "x", _init_x(this)); - babelHelpers.defineProperty(this, _ref, _init_y(this)); + babelHelpers.defineProperty(this, _ref, _init_x(this)); + babelHelpers.defineProperty(this, "y", _init_y(this)); } } _A2 = A; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/valid-expression-formats/output.js index f920b9a7e7b2..5c790011aa67 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc--to-es2015/valid-expression-formats/output.js @@ -4,13 +4,13 @@ const dec = () => {}; _classDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]]; let _Foo; var _a = /*#__PURE__*/new WeakMap(); -_ref = (_methodDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]], "makeClass"); +_ref = (_methodDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]], "method"); class Foo { constructor() { babelHelpers.classPrivateFieldInitSpec(this, _a, void _initProto(this)); } - method() {} - [_ref]() { + [_ref]() {} + makeClass() { let _ref2; var _barDecs, _init_bar, _Nested; return _ref2 = (_barDecs = babelHelpers.classPrivateFieldGet2(_a, this), "bar"), (_Nested = class Nested { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor/output.js index da91a3dd7008..afcd2ab9c22e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/initProto-existing-derived-constructor/output.js @@ -102,10 +102,10 @@ constructor() { log.push(_initProto4(super(8)).method()); } - method() { + [(_noopDecs = noop(log.push(super(7).method())), "method")]() { return this.a; } - [(_noopDecs = noop(log.push(super(7).method())), "noop")]() {} + noop() {} } new A(); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/this/output.js index 34d9936c60be..0e983263f8ae 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/this/output.js @@ -8,8 +8,8 @@ class A { c: [_A, _initClass] } = babelHelpers.applyDecs2305(this, [[_xDecs, 16, "x"], [_yDecs, 16, "y"]], _classDecs, 1)); } - x = _init_x(this); - [(_xDecs = [_obj = o2, _obj.dec, _obj = o3.o, _obj.dec], _yDecs = [_obj = o2, _obj.dec, void 0, dec], "y")] = _init_y(this); + [(_xDecs = [_obj = o2, _obj.dec, _obj = o3.o, _obj.dec], _yDecs = [_obj = o2, _obj.dec, void 0, dec], "x")] = _init_x(this); + y = _init_y(this); static { _initClass(); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/valid-expression-formats/output.js index 2fd62ac4b441..26ea2431e0ab 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-05-misc/valid-expression-formats/output.js @@ -10,8 +10,8 @@ class Foo { } = babelHelpers.applyDecs2305(this, [[_methodDecs, 18, "method"]], _classDecs, 1)); } #a = void _initProto(this); - method() {} - [(_methodDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]], "makeClass")]() { + [(_methodDecs = [void 0, dec, void 0, call(), void 0, chain.expr(), void 0, arbitrary + expr, _obj = array, _obj[expr]], "method")]() {} + makeClass() { var _barDecs, _init_bar; return class Nested { static { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/initProto-existing-derived-constructor/output.js index b16536287948..f569c91df79e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc--to-es2015/initProto-existing-derived-constructor/output.js @@ -93,15 +93,15 @@ constructor() { let _ref; var _initProto4, _noopDecs, _A4; - _ref = (_noopDecs = noop(log.push(super(7).method())), "noop"); + _ref = (_noopDecs = noop(log.push(super(7).method())), "method"); class A extends B { constructor() { log.push(_initProto4(super(8)).method()); } - method() { + [_ref]() { return this.a; } - [_ref]() {} + noop() {} } _A4 = A; [_initProto4] = babelHelpers.applyDecs2311(_A4, [], [[dec, 2, "method"], [_noopDecs, 2, "noop"]], 0, void 0, B).e; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/initProto-existing-derived-constructor/output.js index 6db679229ebe..83cde95f6da7 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-misc/initProto-existing-derived-constructor/output.js @@ -102,10 +102,10 @@ constructor() { log.push(_initProto4(super(8)).method()); } - method() { + [(_noopDecs = noop(log.push(super(7).method())), "method")]() { return this.a; } - [(_noopDecs = noop(log.push(super(7).method())), "noop")]() {} + noop() {} } new A(); }