@babel/plugin-proposal-decorators 7.17.0 → 7.17.2
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/transformer-2021-12.js +46 -52
- package/package.json +3 -3
|
@@ -270,16 +270,29 @@ function transformClass(path, state, constantSuper) {
|
|
|
270
270
|
let constructorPath;
|
|
271
271
|
let requiresProtoInit = false;
|
|
272
272
|
let requiresStaticInit = false;
|
|
273
|
-
let hasComputedProps = false;
|
|
274
273
|
const decoratedPrivateMethods = new Set();
|
|
275
274
|
let protoInitLocal, staticInitLocal, classInitLocal, classLocal;
|
|
275
|
+
const assignments = [];
|
|
276
|
+
const scopeParent = path.scope.parent;
|
|
277
|
+
|
|
278
|
+
const memoiseExpression = (expression, hint) => {
|
|
279
|
+
const localEvaluatedId = scopeParent.generateDeclaredUidIdentifier(hint);
|
|
280
|
+
assignments.push(_core.types.assignmentExpression("=", localEvaluatedId, expression));
|
|
281
|
+
return _core.types.cloneNode(localEvaluatedId);
|
|
282
|
+
};
|
|
276
283
|
|
|
277
284
|
if (classDecorators) {
|
|
278
|
-
classInitLocal =
|
|
285
|
+
classInitLocal = scopeParent.generateDeclaredUidIdentifier("initClass");
|
|
279
286
|
const [localId, classPath] = replaceClassWithVar(path);
|
|
280
287
|
path = classPath;
|
|
281
288
|
classLocal = localId;
|
|
282
289
|
path.node.decorators = null;
|
|
290
|
+
|
|
291
|
+
for (const classDecorator of classDecorators) {
|
|
292
|
+
if (!scopeParent.isStatic(classDecorator.expression)) {
|
|
293
|
+
classDecorator.expression = memoiseExpression(classDecorator.expression, "dec");
|
|
294
|
+
}
|
|
295
|
+
}
|
|
283
296
|
} else {
|
|
284
297
|
if (!path.node.id) {
|
|
285
298
|
path.node.id = path.scope.generateUidIdentifier("Class");
|
|
@@ -294,19 +307,39 @@ function transformClass(path, state, constantSuper) {
|
|
|
294
307
|
continue;
|
|
295
308
|
}
|
|
296
309
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
} = element
|
|
300
|
-
const kind = getElementKind(element);
|
|
310
|
+
const {
|
|
311
|
+
node
|
|
312
|
+
} = element;
|
|
301
313
|
const decorators = element.get("decorators");
|
|
302
|
-
const
|
|
314
|
+
const hasDecorators = Array.isArray(decorators) && decorators.length > 0;
|
|
315
|
+
|
|
316
|
+
if (hasDecorators) {
|
|
317
|
+
for (const decoratorPath of decorators) {
|
|
318
|
+
if (!scopeParent.isStatic(decoratorPath.node.expression)) {
|
|
319
|
+
decoratorPath.node.expression = memoiseExpression(decoratorPath.node.expression, "dec");
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
303
324
|
const isComputed = "computed" in element.node && element.node.computed === true;
|
|
325
|
+
|
|
326
|
+
if (isComputed) {
|
|
327
|
+
if (!scopeParent.isStatic(node.key)) {
|
|
328
|
+
node.key = memoiseExpression(node.key, "computedKey");
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const kind = getElementKind(element);
|
|
333
|
+
const {
|
|
334
|
+
key
|
|
335
|
+
} = node;
|
|
336
|
+
const isPrivate = key.type === "PrivateName";
|
|
304
337
|
const isStatic = !!element.node.static;
|
|
305
338
|
let name = "computedKey";
|
|
306
339
|
|
|
307
340
|
if (isPrivate) {
|
|
308
341
|
name = key.id.name;
|
|
309
|
-
} else if (key.type === "Identifier") {
|
|
342
|
+
} else if (!isComputed && key.type === "Identifier") {
|
|
310
343
|
name = key.name;
|
|
311
344
|
}
|
|
312
345
|
|
|
@@ -316,19 +349,7 @@ function transformClass(path, state, constantSuper) {
|
|
|
316
349
|
constructorPath = element;
|
|
317
350
|
}
|
|
318
351
|
|
|
319
|
-
if (
|
|
320
|
-
const keyPath = element.get("key");
|
|
321
|
-
const localComputedNameId = keyPath.scope.parent.generateDeclaredUidIdentifier(name);
|
|
322
|
-
keyPath.replaceWith(localComputedNameId);
|
|
323
|
-
elementDecoratorInfo.push({
|
|
324
|
-
localComputedNameId: _core.types.cloneNode(localComputedNameId),
|
|
325
|
-
keyNode: _core.types.cloneNode(key)
|
|
326
|
-
});
|
|
327
|
-
key = localComputedNameId;
|
|
328
|
-
hasComputedProps = true;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (Array.isArray(decorators) && decorators.length > 0) {
|
|
352
|
+
if (hasDecorators) {
|
|
332
353
|
let locals;
|
|
333
354
|
let privateMethods;
|
|
334
355
|
|
|
@@ -437,43 +458,14 @@ function transformClass(path, state, constantSuper) {
|
|
|
437
458
|
}
|
|
438
459
|
}
|
|
439
460
|
|
|
440
|
-
if (hasComputedProps) {
|
|
441
|
-
const assignments = [];
|
|
442
|
-
|
|
443
|
-
for (const info of elementDecoratorInfo) {
|
|
444
|
-
if (isDecoratorInfo(info)) {
|
|
445
|
-
const {
|
|
446
|
-
decorators
|
|
447
|
-
} = info;
|
|
448
|
-
const newDecorators = [];
|
|
449
|
-
|
|
450
|
-
for (const decorator of decorators) {
|
|
451
|
-
const localComputedNameId = path.scope.parent.generateDeclaredUidIdentifier("dec");
|
|
452
|
-
assignments.push(_core.types.assignmentExpression("=", localComputedNameId, decorator));
|
|
453
|
-
newDecorators.push(_core.types.cloneNode(localComputedNameId));
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
info.decorators = newDecorators;
|
|
457
|
-
} else {
|
|
458
|
-
assignments.push(_core.types.assignmentExpression("=", info.localComputedNameId, info.keyNode));
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
path.insertBefore(assignments);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
461
|
const elementDecorations = generateDecorationExprs(elementDecoratorInfo);
|
|
466
462
|
|
|
467
463
|
const classDecorations = _core.types.arrayExpression((classDecorators || []).map(d => d.expression));
|
|
468
464
|
|
|
469
465
|
const locals = extractElementLocalAssignments(elementDecoratorInfo);
|
|
470
466
|
|
|
471
|
-
if (classDecorators) {
|
|
472
|
-
locals.push(classLocal, classInitLocal);
|
|
473
|
-
}
|
|
474
|
-
|
|
475
467
|
if (requiresProtoInit) {
|
|
476
|
-
protoInitLocal =
|
|
468
|
+
protoInitLocal = scopeParent.generateDeclaredUidIdentifier("initProto");
|
|
477
469
|
locals.push(protoInitLocal);
|
|
478
470
|
|
|
479
471
|
const protoInitCall = _core.types.callExpression(_core.types.cloneNode(protoInitLocal), [_core.types.thisExpression()]);
|
|
@@ -514,7 +506,7 @@ function transformClass(path, state, constantSuper) {
|
|
|
514
506
|
}
|
|
515
507
|
|
|
516
508
|
if (requiresStaticInit) {
|
|
517
|
-
staticInitLocal =
|
|
509
|
+
staticInitLocal = scopeParent.generateDeclaredUidIdentifier("initStatic");
|
|
518
510
|
locals.push(staticInitLocal);
|
|
519
511
|
}
|
|
520
512
|
|
|
@@ -540,6 +532,7 @@ function transformClass(path, state, constantSuper) {
|
|
|
540
532
|
const originalClass = path.node;
|
|
541
533
|
|
|
542
534
|
if (classDecorators) {
|
|
535
|
+
locals.push(classLocal, classInitLocal);
|
|
543
536
|
const statics = [];
|
|
544
537
|
let staticBlocks = [];
|
|
545
538
|
path.get("body.body").forEach(element => {
|
|
@@ -599,6 +592,7 @@ function transformClass(path, state, constantSuper) {
|
|
|
599
592
|
}
|
|
600
593
|
|
|
601
594
|
originalClass.body.body.unshift(_core.types.staticBlock([_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.arrayPattern(locals), _core.types.callExpression(state.addHelper("applyDecs"), [_core.types.thisExpression(), elementDecorations, classDecorations]))), requiresStaticInit && _core.types.expressionStatement(_core.types.callExpression(_core.types.cloneNode(staticInitLocal), [_core.types.thisExpression()]))].filter(Boolean)));
|
|
595
|
+
path.insertBefore(assignments);
|
|
602
596
|
path.scope.crawl();
|
|
603
597
|
return path;
|
|
604
598
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babel/plugin-proposal-decorators",
|
|
3
|
-
"version": "7.17.
|
|
3
|
+
"version": "7.17.2",
|
|
4
4
|
"author": "The Babel Team (https://babel.dev/team)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"decorators"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@babel/helper-create-class-features-plugin": "^7.17.
|
|
23
|
+
"@babel/helper-create-class-features-plugin": "^7.17.1",
|
|
24
24
|
"@babel/helper-plugin-utils": "^7.16.7",
|
|
25
25
|
"@babel/helper-replace-supers": "^7.16.7",
|
|
26
26
|
"@babel/plugin-syntax-decorators": "^7.17.0",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@babel/core": "^7.0.0-0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@babel/core": "^7.17.
|
|
33
|
+
"@babel/core": "^7.17.2",
|
|
34
34
|
"@babel/helper-plugin-test-runner": "^7.16.7",
|
|
35
35
|
"@babel/traverse": "^7.17.0",
|
|
36
36
|
"babel-plugin-polyfill-es-shims": "^0.6.0",
|