Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2238,9 +2238,8 @@ function shouldTransformClass(node: t.Class) {
return isDecorated(node) || node.body.body.some(shouldTransformElement);
}

// Todo: unify name references logic with helper-function-name
function NamedEvaluationVisitoryFactory(
isAnonymous: (path: NodePath) => boolean,
export function buildNamedEvaluationVisitor(
needsName: (path: NodePath) => boolean,
visitor: (
path: NodePath,
state: PluginPass,
Expand Down Expand Up @@ -2288,7 +2287,7 @@ function NamedEvaluationVisitoryFactory(
const id = path.node.id;
if (id.type === "Identifier") {
const initializer = skipTransparentExprWrappers(path.get("init"));
if (isAnonymous(initializer)) {
if (needsName(initializer)) {
const name = id.name;
visitor(initializer, state, name);
}
Expand All @@ -2298,7 +2297,7 @@ function NamedEvaluationVisitoryFactory(
const id = path.node.left;
if (id.type === "Identifier") {
const initializer = skipTransparentExprWrappers(path.get("right"));
if (isAnonymous(initializer)) {
if (needsName(initializer)) {
switch (path.node.operator) {
case "=":
case "&&=":
Expand All @@ -2313,7 +2312,7 @@ function NamedEvaluationVisitoryFactory(
const id = path.node.left;
if (id.type === "Identifier") {
const initializer = skipTransparentExprWrappers(path.get("right"));
if (isAnonymous(initializer)) {
if (needsName(initializer)) {
const name = id.name;
visitor(initializer, state, name);
}
Expand All @@ -2329,7 +2328,7 @@ function NamedEvaluationVisitoryFactory(
const initializer = skipTransparentExprWrappers(
propertyPath.get("value") as NodePath<t.Expression>,
);
if (isAnonymous(initializer)) {
if (needsName(initializer)) {
if (!node.computed) {
// 13.2.5.5 RS: PropertyDefinitionEvaluation
if (!isProtoKey(id as t.StringLiteral | t.Identifier)) {
Expand Down Expand Up @@ -2358,7 +2357,7 @@ function NamedEvaluationVisitoryFactory(
ClassPrivateProperty(path, state) {
const { node } = path;
const initializer = skipTransparentExprWrappers(path.get("value"));
if (isAnonymous(initializer)) {
if (needsName(initializer)) {
const className = t.stringLiteral("#" + node.key.id.name);
visitor(initializer, state, className);
}
Expand All @@ -2367,7 +2366,7 @@ function NamedEvaluationVisitoryFactory(
const { node } = path;
const id = node.key;
const initializer = skipTransparentExprWrappers(path.get("value"));
if (isAnonymous(initializer)) {
if (needsName(initializer)) {
if (!node.computed) {
if (id.type === "Identifier") {
visitor(initializer, state, id.name);
Expand Down Expand Up @@ -2396,7 +2395,7 @@ function NamedEvaluationVisitoryFactory(
const { node } = path;
const id = node.key;
const initializer = skipTransparentExprWrappers(path.get("value"));
if (isAnonymous(initializer)) {
if (needsName(initializer)) {
if (!node.computed) {
if (id.type === "Identifier") {
visitor(initializer, state, id.name);
Expand Down Expand Up @@ -2455,7 +2454,7 @@ export default function (
const ignoreFunctionLength = assumption("ignoreFunctionLength") ?? loose;

const namedEvaluationVisitor: Visitor<PluginPass> =
NamedEvaluationVisitoryFactory(
buildNamedEvaluationVisitor(
isDecoratedAnonymousClassExpression,
visitClass,
);
Expand Down
13 changes: 11 additions & 2 deletions packages/babel-helper-create-class-features-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
buildCheckInRHS,
} from "./fields.ts";
import type { PropPath } from "./fields.ts";
import createDecoratorTransform, { hasDecorators } from "./decorators.ts";
import createDecoratorTransform, {
hasDecorators,
buildNamedEvaluationVisitor,
} from "./decorators.ts";
import type { DecoratorVersionKind } from "./decorators.ts";
import { buildDecoratedClass } from "./decorators-2018-09.ts" with { if: "!process.env.BABEL_8_BREAKING" };
import { injectInitialization, extractComputedKeys } from "./misc.ts";
Expand All @@ -23,7 +26,13 @@ import {
} from "./features.ts";
import { assertFieldTransformed } from "./typescript.ts";

export { FEATURES, enableFeature, injectInitialization, buildCheckInRHS };
export {
FEATURES,
enableFeature,
injectInitialization,
buildCheckInRHS,
buildNamedEvaluationVisitor,
};

const versionKey = "@babel/plugin-class-features/version";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
var _staticBlock;
let _computedKeyDecs, _computedKey, _init_computedKey, _init_extra_computedKey;
"class binding in plain class, decorated field, and computed keys";
const errs = [];
Expand All @@ -19,12 +20,13 @@
capture(() => K);
assertUninitialized(() => K);
class K {
static #_ = [_init_computedKey, _init_extra_computedKey] = babelHelpers.applyDecs2311(this, [], [[_computedKeyDecs, 0, _computedKey]]).e;
constructor() {
_init_extra_computedKey(this);
}
[(_computedKeyDecs = [capture(() => K), assertUninitialized(() => K)], _computedKey = babelHelpers.toPropertyKey((capture(() => K), assertUninitialized(() => K))))] = _init_computedKey(this);
static #_ = _staticBlock = () => [_init_computedKey, _init_extra_computedKey] = babelHelpers.applyDecs2311(this, [], [[_computedKeyDecs, 0, _computedKey]]).e;
}
_staticBlock();
const E = ReferenceError;
expect(errs.map(e => e.constructor)).toEqual([E, E, E]);
const C = K;
Expand Down Expand Up @@ -53,19 +55,20 @@
_classDecs = [capture(() => _K), assertUninitialized(() => _K)];
let _K, _t_K;
{
var _staticBlock2;
let _K;
class K {
static #_ = {
e: [_init_computedKey2, _init_extra_computedKey2],
c: [_K, _initClass]
} = babelHelpers.applyDecs2311(this, _classDecs, [[_computedKeyDecs2, 0, _computedKey2]]);
constructor() {
_init_extra_computedKey2(this);
}
//todo: add the assertUninitialized decorator when we properly implement class tdz
[(_computedKeyDecs2 = capture(() => _K), _computedKey2 = babelHelpers.toPropertyKey(capture(() => _K)))] = _init_computedKey2(this);
static #_2 = _initClass();
static #_ = _staticBlock2 = () => ({
e: [_init_computedKey2, _init_extra_computedKey2],
c: [_K, _initClass]
} = babelHelpers.applyDecs2311(this, _classDecs, [[_computedKeyDecs2, 0, _computedKey2]]), _initClass());
}
_staticBlock2();
_t_K = _K;
}
_K = _t_K;
Expand Down Expand Up @@ -97,18 +100,19 @@
_classDecs2 = [capture(() => _K2), assertUninitialized(() => _K2)];
let _K2, _t_K2;
{
var _staticBlock3;
let _K2;
new class extends babelHelpers.identity {
static [class K {
static [(_computedKeyDecs3 = capture(() => _K2), _computedKey3 = babelHelpers.toPropertyKey(capture(() => _K2)), "_")];
static #_ = (() => {
static [(class K {
static [(_computedKeyDecs3 = capture(() => _K2), _computedKey3 = babelHelpers.toPropertyKey(capture(() => _K2)), "_")] = void (_staticBlock3 = () => {
delete this._;
({
e: [_init_computedKey3, _init_extra_computedKey3],
c: [_K2, _initClass2]
} = babelHelpers.applyDecs2311(this, _classDecs2, [[_computedKeyDecs3, 8, _computedKey3]]));
})();
}];
return this;
});
}, _staticBlock3())];
//todo: add the assertUninitialized decorator when we properly implement class tdz
[_computedKey3] = _init_computedKey3();
constructor() {
Expand Down Expand Up @@ -150,19 +154,20 @@
_classDecs3 = [capture(await (() => _K3)), assertUninitialized(await (() => _K3))];
let _K3, _t_K3;
{
var _staticBlock4;
let _K3;
class K {
static #_ = (() => {
//todo: add the assertUninitialized decorator when we properly implement class tdz
static [(_computedKeyDecs4 = capture(await (() => _K3)), _computedKey4 = babelHelpers.toPropertyKey(capture(await (() => _K3))))]() {}
static #_ = _staticBlock4 = () => ((() => {
({
e: [_initStatic],
c: [_K3, _initClass3]
} = babelHelpers.applyDecs2311(this, _classDecs3, [[_computedKeyDecs4, 10, _computedKey4]]));
_initStatic(this);
})();
//todo: add the assertUninitialized decorator when we properly implement class tdz
static [(_computedKeyDecs4 = capture(await (() => _K3)), _computedKey4 = babelHelpers.toPropertyKey(capture(await (() => _K3))))]() {}
static #_2 = _initClass3();
})(), _initClass3());
}
_staticBlock4();
_t_K3 = _K3;
}
_K3 = _t_K3;
Expand Down
Loading
Loading