@babel/plugin-proposal-decorators 7.22.7 → 8.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +780 -27
- package/lib/index.js.map +1 -1
- package/lib/transformer-2023-05.js +100 -120
- package/lib/transformer-2023-05.js.map +1 -1
- package/lib/transformer-legacy.js +30 -40
- package/lib/transformer-legacy.js.map +1 -1
- package/package.json +16 -12
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.default = _default;
|
|
7
|
-
var _core = require("@babel/core");
|
|
8
|
-
var _pluginSyntaxDecorators = require("@babel/plugin-syntax-decorators");
|
|
9
|
-
var _helperReplaceSupers = require("@babel/helper-replace-supers");
|
|
10
|
-
var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
|
|
1
|
+
import { types as t, template } from "@babel/core";
|
|
2
|
+
import syntaxDecorators from "@babel/plugin-syntax-decorators";
|
|
3
|
+
import ReplaceSupers from "@babel/helper-replace-supers";
|
|
4
|
+
import splitExportDeclaration from "@babel/helper-split-export-declaration";
|
|
11
5
|
function incrementId(id, idx = id.length - 1) {
|
|
12
6
|
if (idx === -1) {
|
|
13
7
|
id.unshift(65);
|
|
@@ -37,7 +31,7 @@ function createPrivateUidGeneratorForClass(classPath) {
|
|
|
37
31
|
incrementId(currentPrivateId);
|
|
38
32
|
reifiedId = String.fromCharCode(...currentPrivateId);
|
|
39
33
|
} while (privateNames.has(reifiedId));
|
|
40
|
-
return
|
|
34
|
+
return t.privateName(t.identifier(reifiedId));
|
|
41
35
|
};
|
|
42
36
|
}
|
|
43
37
|
function createLazyPrivateUidGeneratorForClass(classPath) {
|
|
@@ -52,11 +46,11 @@ function createLazyPrivateUidGeneratorForClass(classPath) {
|
|
|
52
46
|
function replaceClassWithVar(path) {
|
|
53
47
|
if (path.type === "ClassDeclaration") {
|
|
54
48
|
const varId = path.scope.generateUidIdentifierBasedOnNode(path.node.id);
|
|
55
|
-
const classId =
|
|
49
|
+
const classId = t.identifier(path.node.id.name);
|
|
56
50
|
path.scope.rename(classId.name, varId.name);
|
|
57
|
-
path.insertBefore(
|
|
51
|
+
path.insertBefore(t.variableDeclaration("let", [t.variableDeclarator(varId)]));
|
|
58
52
|
path.get("id").replaceWith(classId);
|
|
59
|
-
return [
|
|
53
|
+
return [t.cloneNode(varId), path];
|
|
60
54
|
} else {
|
|
61
55
|
let className;
|
|
62
56
|
let varId;
|
|
@@ -70,52 +64,52 @@ function replaceClassWithVar(path) {
|
|
|
70
64
|
} else {
|
|
71
65
|
varId = path.scope.parent.generateDeclaredUidIdentifier("decorated_class");
|
|
72
66
|
}
|
|
73
|
-
const newClassExpr =
|
|
74
|
-
const [newPath] = path.replaceWith(
|
|
75
|
-
return [
|
|
67
|
+
const newClassExpr = t.classExpression(className && t.identifier(className), path.node.superClass, path.node.body);
|
|
68
|
+
const [newPath] = path.replaceWith(t.sequenceExpression([newClassExpr, varId]));
|
|
69
|
+
return [t.cloneNode(varId), newPath.get("expressions.0")];
|
|
76
70
|
}
|
|
77
71
|
}
|
|
78
72
|
function generateClassProperty(key, value, isStatic) {
|
|
79
73
|
if (key.type === "PrivateName") {
|
|
80
|
-
return
|
|
74
|
+
return t.classPrivateProperty(key, value, undefined, isStatic);
|
|
81
75
|
} else {
|
|
82
|
-
return
|
|
76
|
+
return t.classProperty(key, value, undefined, undefined, isStatic);
|
|
83
77
|
}
|
|
84
78
|
}
|
|
85
79
|
function addProxyAccessorsFor(className, element, originalKey, targetKey, version, isComputed = false) {
|
|
86
80
|
const {
|
|
87
81
|
static: isStatic
|
|
88
82
|
} = element.node;
|
|
89
|
-
const thisArg = version === "2023-05" && isStatic ? className :
|
|
90
|
-
const getterBody =
|
|
91
|
-
const setterBody =
|
|
83
|
+
const thisArg = version === "2023-05" && isStatic ? className : t.thisExpression();
|
|
84
|
+
const getterBody = t.blockStatement([t.returnStatement(t.memberExpression(t.cloneNode(thisArg), t.cloneNode(targetKey)))]);
|
|
85
|
+
const setterBody = t.blockStatement([t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.cloneNode(thisArg), t.cloneNode(targetKey)), t.identifier("v")))]);
|
|
92
86
|
let getter, setter;
|
|
93
87
|
if (originalKey.type === "PrivateName") {
|
|
94
|
-
getter =
|
|
95
|
-
setter =
|
|
88
|
+
getter = t.classPrivateMethod("get", t.cloneNode(originalKey), [], getterBody, isStatic);
|
|
89
|
+
setter = t.classPrivateMethod("set", t.cloneNode(originalKey), [t.identifier("v")], setterBody, isStatic);
|
|
96
90
|
} else {
|
|
97
|
-
getter =
|
|
98
|
-
setter =
|
|
91
|
+
getter = t.classMethod("get", t.cloneNode(originalKey), [], getterBody, isComputed, isStatic);
|
|
92
|
+
setter = t.classMethod("set", t.cloneNode(originalKey), [t.identifier("v")], setterBody, isComputed, isStatic);
|
|
99
93
|
}
|
|
100
94
|
element.insertAfter(setter);
|
|
101
95
|
element.insertAfter(getter);
|
|
102
96
|
}
|
|
103
97
|
function extractProxyAccessorsFor(targetKey, version) {
|
|
104
98
|
if (version !== "2023-05" && version !== "2023-01") {
|
|
105
|
-
return [
|
|
99
|
+
return [template.expression.ast`
|
|
106
100
|
function () {
|
|
107
|
-
return this.${
|
|
101
|
+
return this.${t.cloneNode(targetKey)};
|
|
108
102
|
}
|
|
109
|
-
`,
|
|
103
|
+
`, template.expression.ast`
|
|
110
104
|
function (value) {
|
|
111
|
-
this.${
|
|
105
|
+
this.${t.cloneNode(targetKey)} = value;
|
|
112
106
|
}
|
|
113
107
|
`];
|
|
114
108
|
}
|
|
115
|
-
return [
|
|
116
|
-
o => o.${
|
|
117
|
-
`,
|
|
118
|
-
(o, v) => o.${
|
|
109
|
+
return [template.expression.ast`
|
|
110
|
+
o => o.${t.cloneNode(targetKey)}
|
|
111
|
+
`, template.expression.ast`
|
|
112
|
+
(o, v) => o.${t.cloneNode(targetKey)} = v
|
|
119
113
|
`];
|
|
120
114
|
}
|
|
121
115
|
const FIELD = 0;
|
|
@@ -157,7 +151,7 @@ function generateDecorationList(decorators, decoratorsThis, version) {
|
|
|
157
151
|
const decs = [];
|
|
158
152
|
for (let i = 0; i < decsCount; i++) {
|
|
159
153
|
if (version === "2023-05" && hasOneThis) {
|
|
160
|
-
decs.push(decoratorsThis[i] ||
|
|
154
|
+
decs.push(decoratorsThis[i] || t.unaryExpression("void", t.numericLiteral(0)));
|
|
161
155
|
}
|
|
162
156
|
decs.push(decorators[i]);
|
|
163
157
|
}
|
|
@@ -167,7 +161,7 @@ function generateDecorationList(decorators, decoratorsThis, version) {
|
|
|
167
161
|
};
|
|
168
162
|
}
|
|
169
163
|
function generateDecorationExprs(info, version) {
|
|
170
|
-
return
|
|
164
|
+
return t.arrayExpression(filteredOrderedDecoratorInfo(info).map(el => {
|
|
171
165
|
const {
|
|
172
166
|
decs,
|
|
173
167
|
hasThis
|
|
@@ -177,7 +171,7 @@ function generateDecorationExprs(info, version) {
|
|
|
177
171
|
flag += version === "2023-05" ? STATIC : STATIC_OLD_VERSION;
|
|
178
172
|
}
|
|
179
173
|
if (hasThis) flag += DECORATORS_HAVE_THIS;
|
|
180
|
-
return
|
|
174
|
+
return t.arrayExpression([decs.length === 1 ? decs[0] : t.arrayExpression(decs), t.numericLiteral(flag), el.name, ...(el.privateMethods || [])]);
|
|
181
175
|
}));
|
|
182
176
|
}
|
|
183
177
|
function extractElementLocalAssignments(decorationInfo) {
|
|
@@ -195,8 +189,8 @@ function extractElementLocalAssignments(decorationInfo) {
|
|
|
195
189
|
return localIds;
|
|
196
190
|
}
|
|
197
191
|
function addCallAccessorsFor(element, key, getId, setId) {
|
|
198
|
-
element.insertAfter(
|
|
199
|
-
element.insertAfter(
|
|
192
|
+
element.insertAfter(t.classPrivateMethod("get", t.cloneNode(key), [], t.blockStatement([t.returnStatement(t.callExpression(t.cloneNode(getId), [t.thisExpression()]))])));
|
|
193
|
+
element.insertAfter(t.classPrivateMethod("set", t.cloneNode(key), [t.identifier("v")], t.blockStatement([t.expressionStatement(t.callExpression(t.cloneNode(setId), [t.thisExpression(), t.identifier("v")]))])));
|
|
200
194
|
}
|
|
201
195
|
function isNotTsParameter(node) {
|
|
202
196
|
return node.type !== "TSParameterProperty";
|
|
@@ -205,13 +199,13 @@ function movePrivateAccessor(element, key, methodLocalVar, isStatic) {
|
|
|
205
199
|
let params;
|
|
206
200
|
let block;
|
|
207
201
|
if (element.node.kind === "set") {
|
|
208
|
-
params = [
|
|
209
|
-
block = [
|
|
202
|
+
params = [t.identifier("v")];
|
|
203
|
+
block = [t.expressionStatement(t.callExpression(methodLocalVar, [t.thisExpression(), t.identifier("v")]))];
|
|
210
204
|
} else {
|
|
211
205
|
params = [];
|
|
212
|
-
block = [
|
|
206
|
+
block = [t.returnStatement(t.callExpression(methodLocalVar, [t.thisExpression()]))];
|
|
213
207
|
}
|
|
214
|
-
element.replaceWith(
|
|
208
|
+
element.replaceWith(t.classPrivateMethod(element.node.kind, t.cloneNode(key), params, t.blockStatement(block), isStatic));
|
|
215
209
|
}
|
|
216
210
|
function isClassDecoratableElementPath(path) {
|
|
217
211
|
const {
|
|
@@ -220,12 +214,12 @@ function isClassDecoratableElementPath(path) {
|
|
|
220
214
|
return type !== "TSDeclareMethod" && type !== "TSIndexSignature" && type !== "StaticBlock";
|
|
221
215
|
}
|
|
222
216
|
function staticBlockToIIFE(block) {
|
|
223
|
-
return
|
|
217
|
+
return t.callExpression(t.arrowFunctionExpression([], t.blockStatement(block.body)), []);
|
|
224
218
|
}
|
|
225
219
|
function maybeSequenceExpression(exprs) {
|
|
226
|
-
if (exprs.length === 0) return
|
|
220
|
+
if (exprs.length === 0) return t.unaryExpression("void", t.numericLiteral(0));
|
|
227
221
|
if (exprs.length === 1) return exprs[0];
|
|
228
|
-
return
|
|
222
|
+
return t.sequenceExpression(exprs);
|
|
229
223
|
}
|
|
230
224
|
function transformClass(path, state, constantSuper, version) {
|
|
231
225
|
const body = path.get("body.body");
|
|
@@ -246,7 +240,7 @@ function transformClass(path, state, constantSuper, version) {
|
|
|
246
240
|
computed
|
|
247
241
|
} = element.node;
|
|
248
242
|
const newId = generateClassPrivateUid();
|
|
249
|
-
const valueNode = value ?
|
|
243
|
+
const valueNode = value ? t.cloneNode(value) : undefined;
|
|
250
244
|
const newField = generateClassProperty(newId, valueNode, isStatic);
|
|
251
245
|
const [newPath] = element.replaceWith(newField);
|
|
252
246
|
addProxyAccessorsFor(path.node.id, newPath, key, newId, version, computed);
|
|
@@ -264,25 +258,25 @@ function transformClass(path, state, constantSuper, version) {
|
|
|
264
258
|
const scopeParent = path.scope.parent;
|
|
265
259
|
const memoiseExpression = (expression, hint) => {
|
|
266
260
|
const localEvaluatedId = scopeParent.generateDeclaredUidIdentifier(hint);
|
|
267
|
-
assignments.push(
|
|
268
|
-
return
|
|
261
|
+
assignments.push(t.assignmentExpression("=", localEvaluatedId, expression));
|
|
262
|
+
return t.cloneNode(localEvaluatedId);
|
|
269
263
|
};
|
|
270
264
|
const decoratorsThis = new Map();
|
|
271
265
|
const maybeExtractDecorator = decorator => {
|
|
272
266
|
const {
|
|
273
267
|
expression
|
|
274
268
|
} = decorator;
|
|
275
|
-
if (version === "2023-05" &&
|
|
269
|
+
if (version === "2023-05" && t.isMemberExpression(expression)) {
|
|
276
270
|
let object;
|
|
277
|
-
if (
|
|
278
|
-
object = memoiseExpression(
|
|
271
|
+
if (t.isSuper(expression.object) || t.isThisExpression(expression.object)) {
|
|
272
|
+
object = memoiseExpression(t.thisExpression(), "obj");
|
|
279
273
|
} else if (!scopeParent.isStatic(expression.object)) {
|
|
280
274
|
object = memoiseExpression(expression.object, "obj");
|
|
281
275
|
expression.object = object;
|
|
282
276
|
} else {
|
|
283
277
|
object = expression.object;
|
|
284
278
|
}
|
|
285
|
-
decoratorsThis.set(decorator,
|
|
279
|
+
decoratorsThis.set(decorator, t.cloneNode(object));
|
|
286
280
|
}
|
|
287
281
|
if (!scopeParent.isStatic(expression)) {
|
|
288
282
|
decorator.expression = memoiseExpression(expression, "dec");
|
|
@@ -301,7 +295,7 @@ function transformClass(path, state, constantSuper, version) {
|
|
|
301
295
|
if (!path.node.id) {
|
|
302
296
|
path.node.id = path.scope.generateUidIdentifier("Class");
|
|
303
297
|
}
|
|
304
|
-
classIdLocal =
|
|
298
|
+
classIdLocal = t.cloneNode(path.node.id);
|
|
305
299
|
}
|
|
306
300
|
let lastInstancePrivateName;
|
|
307
301
|
let needsInstancePrivateBrandCheck = false;
|
|
@@ -342,7 +336,7 @@ function transformClass(path, state, constantSuper, version) {
|
|
|
342
336
|
if (hasDecorators) {
|
|
343
337
|
needsInstancePrivateBrandCheck = true;
|
|
344
338
|
}
|
|
345
|
-
if (
|
|
339
|
+
if (t.isClassPrivateProperty(node) || !lastInstancePrivateName) {
|
|
346
340
|
lastInstancePrivateName = key;
|
|
347
341
|
}
|
|
348
342
|
}
|
|
@@ -358,13 +352,13 @@ function transformClass(path, state, constantSuper, version) {
|
|
|
358
352
|
const {
|
|
359
353
|
value
|
|
360
354
|
} = element.node;
|
|
361
|
-
const params = [
|
|
355
|
+
const params = [t.thisExpression()];
|
|
362
356
|
if (value) {
|
|
363
|
-
params.push(
|
|
357
|
+
params.push(t.cloneNode(value));
|
|
364
358
|
}
|
|
365
359
|
const newId = generateClassPrivateUid();
|
|
366
360
|
const newFieldInitId = element.scope.parent.generateDeclaredUidIdentifier(`init_${name}`);
|
|
367
|
-
const newValue =
|
|
361
|
+
const newValue = t.callExpression(t.cloneNode(newFieldInitId), params);
|
|
368
362
|
const newField = generateClassProperty(newId, newValue, isStatic);
|
|
369
363
|
const [newPath] = element.replaceWith(newField);
|
|
370
364
|
if (isPrivate) {
|
|
@@ -380,14 +374,14 @@ function transformClass(path, state, constantSuper, version) {
|
|
|
380
374
|
} else if (kind === FIELD) {
|
|
381
375
|
const initId = element.scope.parent.generateDeclaredUidIdentifier(`init_${name}`);
|
|
382
376
|
const valuePath = element.get("value");
|
|
383
|
-
valuePath.replaceWith(
|
|
377
|
+
valuePath.replaceWith(t.callExpression(t.cloneNode(initId), [t.thisExpression(), valuePath.node].filter(v => v)));
|
|
384
378
|
locals = initId;
|
|
385
379
|
if (isPrivate) {
|
|
386
380
|
privateMethods = extractProxyAccessorsFor(key, version);
|
|
387
381
|
}
|
|
388
382
|
} else if (isPrivate) {
|
|
389
383
|
locals = element.scope.parent.generateDeclaredUidIdentifier(`call_${name}`);
|
|
390
|
-
const replaceSupers = new
|
|
384
|
+
const replaceSupers = new ReplaceSupers({
|
|
391
385
|
constantSuper,
|
|
392
386
|
methodPath: element,
|
|
393
387
|
objectRef: classIdLocal,
|
|
@@ -401,25 +395,25 @@ function transformClass(path, state, constantSuper, version) {
|
|
|
401
395
|
body,
|
|
402
396
|
async: isAsync
|
|
403
397
|
} = element.node;
|
|
404
|
-
privateMethods = [
|
|
398
|
+
privateMethods = [t.functionExpression(undefined, params.filter(isNotTsParameter), body, isAsync)];
|
|
405
399
|
if (kind === GETTER || kind === SETTER) {
|
|
406
|
-
movePrivateAccessor(element,
|
|
400
|
+
movePrivateAccessor(element, t.cloneNode(key), t.cloneNode(locals), isStatic);
|
|
407
401
|
} else {
|
|
408
402
|
const node = element.node;
|
|
409
|
-
path.node.body.body.unshift(
|
|
403
|
+
path.node.body.body.unshift(t.classPrivateProperty(key, t.cloneNode(locals), [], node.static));
|
|
410
404
|
decoratedPrivateMethods.add(key.id.name);
|
|
411
405
|
element.remove();
|
|
412
406
|
}
|
|
413
407
|
}
|
|
414
408
|
let nameExpr;
|
|
415
409
|
if (isComputed) {
|
|
416
|
-
nameExpr =
|
|
410
|
+
nameExpr = t.cloneNode(key);
|
|
417
411
|
} else if (key.type === "PrivateName") {
|
|
418
|
-
nameExpr =
|
|
412
|
+
nameExpr = t.stringLiteral(key.id.name);
|
|
419
413
|
} else if (key.type === "Identifier") {
|
|
420
|
-
nameExpr =
|
|
414
|
+
nameExpr = t.stringLiteral(key.name);
|
|
421
415
|
} else {
|
|
422
|
-
nameExpr =
|
|
416
|
+
nameExpr = t.cloneNode(key);
|
|
423
417
|
}
|
|
424
418
|
elementDecoratorInfo.push({
|
|
425
419
|
kind,
|
|
@@ -461,34 +455,34 @@ function transformClass(path, state, constantSuper, version) {
|
|
|
461
455
|
if (requiresProtoInit) {
|
|
462
456
|
protoInitLocal = scopeParent.generateDeclaredUidIdentifier("initProto");
|
|
463
457
|
elementLocals.push(protoInitLocal);
|
|
464
|
-
const protoInitCall =
|
|
458
|
+
const protoInitCall = t.callExpression(t.cloneNode(protoInitLocal), [t.thisExpression()]);
|
|
465
459
|
if (firstFieldPath) {
|
|
466
460
|
const value = firstFieldPath.get("value");
|
|
467
461
|
const body = [protoInitCall];
|
|
468
462
|
if (value.node) {
|
|
469
463
|
body.push(value.node);
|
|
470
464
|
}
|
|
471
|
-
value.replaceWith(
|
|
465
|
+
value.replaceWith(t.sequenceExpression(body));
|
|
472
466
|
} else if (constructorPath) {
|
|
473
467
|
if (path.node.superClass) {
|
|
474
468
|
path.traverse({
|
|
475
469
|
CallExpression: {
|
|
476
470
|
exit(path) {
|
|
477
471
|
if (!path.get("callee").isSuper()) return;
|
|
478
|
-
path.replaceWith(
|
|
472
|
+
path.replaceWith(t.callExpression(t.cloneNode(protoInitLocal), [path.node]));
|
|
479
473
|
path.skip();
|
|
480
474
|
}
|
|
481
475
|
}
|
|
482
476
|
});
|
|
483
477
|
} else {
|
|
484
|
-
constructorPath.node.body.body.unshift(
|
|
478
|
+
constructorPath.node.body.body.unshift(t.expressionStatement(protoInitCall));
|
|
485
479
|
}
|
|
486
480
|
} else {
|
|
487
|
-
const body = [
|
|
481
|
+
const body = [t.expressionStatement(protoInitCall)];
|
|
488
482
|
if (path.node.superClass) {
|
|
489
|
-
body.unshift(
|
|
483
|
+
body.unshift(t.expressionStatement(t.callExpression(t.super(), [t.spreadElement(t.identifier("args"))])));
|
|
490
484
|
}
|
|
491
|
-
path.node.body.body.unshift(
|
|
485
|
+
path.node.body.body.unshift(t.classMethod("constructor", t.identifier("constructor"), [t.restElement(t.identifier("args"))], t.blockStatement(body)));
|
|
492
486
|
}
|
|
493
487
|
}
|
|
494
488
|
if (requiresStaticInit) {
|
|
@@ -509,7 +503,7 @@ function transformClass(path, state, constantSuper, version) {
|
|
|
509
503
|
}
|
|
510
504
|
const classLocals = [];
|
|
511
505
|
let classInitInjected = false;
|
|
512
|
-
const classInitCall = classInitLocal &&
|
|
506
|
+
const classInitCall = classInitLocal && t.callExpression(t.cloneNode(classInitLocal), []);
|
|
513
507
|
const originalClass = path.node;
|
|
514
508
|
if (classDecorators) {
|
|
515
509
|
classLocals.push(classIdLocal, classInitLocal);
|
|
@@ -535,12 +529,12 @@ function transformClass(path, state, constantSuper, version) {
|
|
|
535
529
|
}
|
|
536
530
|
});
|
|
537
531
|
if (statics.length > 0 || staticBlocks.length > 0) {
|
|
538
|
-
const staticsClass =
|
|
532
|
+
const staticsClass = template.expression.ast`
|
|
539
533
|
class extends ${state.addHelper("identity")} {}
|
|
540
534
|
`;
|
|
541
|
-
staticsClass.body.body = [
|
|
535
|
+
staticsClass.body.body = [t.staticBlock([t.toStatement(originalClass, true) || t.expressionStatement(originalClass)]), ...statics];
|
|
542
536
|
const constructorBody = [];
|
|
543
|
-
const newExpr =
|
|
537
|
+
const newExpr = t.newExpression(staticsClass, []);
|
|
544
538
|
if (staticBlocks.length > 0) {
|
|
545
539
|
constructorBody.push(...staticBlocks.map(staticBlockToIIFE));
|
|
546
540
|
}
|
|
@@ -549,94 +543,80 @@ function transformClass(path, state, constantSuper, version) {
|
|
|
549
543
|
constructorBody.push(classInitCall);
|
|
550
544
|
}
|
|
551
545
|
if (constructorBody.length > 0) {
|
|
552
|
-
constructorBody.unshift(
|
|
553
|
-
staticsClass.body.body.push(
|
|
546
|
+
constructorBody.unshift(t.callExpression(t.super(), [t.cloneNode(classIdLocal)]));
|
|
547
|
+
staticsClass.body.body.push(t.classMethod("constructor", t.identifier("constructor"), [], t.blockStatement([t.expressionStatement(t.sequenceExpression(constructorBody))])));
|
|
554
548
|
} else {
|
|
555
|
-
newExpr.arguments.push(
|
|
549
|
+
newExpr.arguments.push(t.cloneNode(classIdLocal));
|
|
556
550
|
}
|
|
557
551
|
path.replaceWith(newExpr);
|
|
558
552
|
}
|
|
559
553
|
}
|
|
560
554
|
if (!classInitInjected && classInitCall) {
|
|
561
|
-
path.node.body.body.push(
|
|
555
|
+
path.node.body.body.push(t.staticBlock([t.expressionStatement(classInitCall)]));
|
|
562
556
|
}
|
|
563
|
-
originalClass.body.body.unshift(
|
|
564
|
-
path.insertBefore(assignments.map(expr =>
|
|
557
|
+
originalClass.body.body.unshift(t.staticBlock([t.expressionStatement(createLocalsAssignment(elementLocals, classLocals, elementDecorations, t.arrayExpression(classDecorations), t.numericLiteral(classDecorationsFlag), needsInstancePrivateBrandCheck ? lastInstancePrivateName : null, state, version)), requiresStaticInit && t.expressionStatement(t.callExpression(t.cloneNode(staticInitLocal), [t.thisExpression()]))].filter(Boolean)));
|
|
558
|
+
path.insertBefore(assignments.map(expr => t.expressionStatement(expr)));
|
|
565
559
|
path.scope.crawl();
|
|
566
560
|
return path;
|
|
567
561
|
}
|
|
568
562
|
function createLocalsAssignment(elementLocals, classLocals, elementDecorations, classDecorations, classDecorationsFlag, maybePrivateBranName, state, version) {
|
|
569
563
|
let lhs, rhs;
|
|
570
|
-
const args = [
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
const lhs = _core.types.arrayPattern([...elementLocals, ...classLocals]);
|
|
574
|
-
const rhs = _core.types.callExpression(state.addHelper(version === "2021-12" ? "applyDecs" : "applyDecs2203"), args);
|
|
575
|
-
return _core.types.assignmentExpression("=", lhs, rhs);
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
if (version === "2023-05") {
|
|
564
|
+
const args = [t.thisExpression(), elementDecorations, classDecorations];
|
|
565
|
+
;
|
|
566
|
+
if (true) {
|
|
579
567
|
if (maybePrivateBranName || classDecorationsFlag.value !== 0) {
|
|
580
568
|
args.push(classDecorationsFlag);
|
|
581
569
|
}
|
|
582
570
|
if (maybePrivateBranName) {
|
|
583
|
-
args.push(
|
|
584
|
-
_ => ${
|
|
571
|
+
args.push(template.expression.ast`
|
|
572
|
+
_ => ${t.cloneNode(maybePrivateBranName)} in _
|
|
585
573
|
`);
|
|
586
574
|
}
|
|
587
|
-
rhs =
|
|
575
|
+
rhs = t.callExpression(state.addHelper("applyDecs2305"), args);
|
|
588
576
|
} else if (version === "2023-01") {
|
|
589
577
|
if (maybePrivateBranName) {
|
|
590
|
-
args.push(
|
|
591
|
-
_ => ${
|
|
578
|
+
args.push(template.expression.ast`
|
|
579
|
+
_ => ${t.cloneNode(maybePrivateBranName)} in _
|
|
592
580
|
`);
|
|
593
581
|
}
|
|
594
|
-
rhs =
|
|
582
|
+
rhs = t.callExpression(state.addHelper("applyDecs2301"), args);
|
|
595
583
|
} else {
|
|
596
|
-
rhs =
|
|
584
|
+
rhs = t.callExpression(state.addHelper("applyDecs2203R"), args);
|
|
597
585
|
}
|
|
598
586
|
if (elementLocals.length > 0) {
|
|
599
587
|
if (classLocals.length > 0) {
|
|
600
|
-
lhs =
|
|
588
|
+
lhs = t.objectPattern([t.objectProperty(t.identifier("e"), t.arrayPattern(elementLocals)), t.objectProperty(t.identifier("c"), t.arrayPattern(classLocals))]);
|
|
601
589
|
} else {
|
|
602
|
-
lhs =
|
|
603
|
-
rhs =
|
|
590
|
+
lhs = t.arrayPattern(elementLocals);
|
|
591
|
+
rhs = t.memberExpression(rhs, t.identifier("e"), false, false);
|
|
604
592
|
}
|
|
605
593
|
} else {
|
|
606
|
-
lhs =
|
|
607
|
-
rhs =
|
|
594
|
+
lhs = t.arrayPattern(classLocals);
|
|
595
|
+
rhs = t.memberExpression(rhs, t.identifier("c"), false, false);
|
|
608
596
|
}
|
|
609
|
-
return
|
|
597
|
+
return t.assignmentExpression("=", lhs, rhs);
|
|
610
598
|
}
|
|
611
|
-
function
|
|
599
|
+
export default function ({
|
|
612
600
|
assertVersion,
|
|
613
601
|
assumption
|
|
614
602
|
}, {
|
|
615
603
|
loose
|
|
616
604
|
}, version) {
|
|
617
|
-
var _assumption;
|
|
618
605
|
{
|
|
619
|
-
|
|
620
|
-
assertVersion("^7.21.0");
|
|
621
|
-
} else if (version === "2021-12") {
|
|
622
|
-
assertVersion("^7.16.0");
|
|
623
|
-
} else {
|
|
624
|
-
assertVersion("^7.19.0");
|
|
625
|
-
}
|
|
606
|
+
assertVersion("^7.21.0");
|
|
626
607
|
}
|
|
627
608
|
const VISITED = new WeakSet();
|
|
628
|
-
const constantSuper =
|
|
609
|
+
const constantSuper = assumption("constantSuper") ?? loose;
|
|
629
610
|
return {
|
|
630
611
|
name: "proposal-decorators",
|
|
631
|
-
inherits:
|
|
612
|
+
inherits: syntaxDecorators,
|
|
632
613
|
visitor: {
|
|
633
614
|
"ExportNamedDeclaration|ExportDefaultDeclaration"(path) {
|
|
634
|
-
var _declaration$decorato;
|
|
635
615
|
const {
|
|
636
616
|
declaration
|
|
637
617
|
} = path.node;
|
|
638
|
-
if (
|
|
639
|
-
(
|
|
618
|
+
if (declaration?.type === "ClassDeclaration" && declaration.decorators?.length > 0) {
|
|
619
|
+
splitExportDeclaration(path);
|
|
640
620
|
}
|
|
641
621
|
},
|
|
642
622
|
Class(path, state) {
|