@babel/plugin-proposal-decorators 8.0.0-alpha.1 → 8.0.0-alpha.3

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.
@@ -1,631 +0,0 @@
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";
5
- function incrementId(id, idx = id.length - 1) {
6
- if (idx === -1) {
7
- id.unshift(65);
8
- return;
9
- }
10
- const current = id[idx];
11
- if (current === 90) {
12
- id[idx] = 97;
13
- } else if (current === 122) {
14
- id[idx] = 65;
15
- incrementId(id, idx - 1);
16
- } else {
17
- id[idx] = current + 1;
18
- }
19
- }
20
- function createPrivateUidGeneratorForClass(classPath) {
21
- const currentPrivateId = [];
22
- const privateNames = new Set();
23
- classPath.traverse({
24
- PrivateName(path) {
25
- privateNames.add(path.node.id.name);
26
- }
27
- });
28
- return () => {
29
- let reifiedId;
30
- do {
31
- incrementId(currentPrivateId);
32
- reifiedId = String.fromCharCode(...currentPrivateId);
33
- } while (privateNames.has(reifiedId));
34
- return t.privateName(t.identifier(reifiedId));
35
- };
36
- }
37
- function createLazyPrivateUidGeneratorForClass(classPath) {
38
- let generator;
39
- return () => {
40
- if (!generator) {
41
- generator = createPrivateUidGeneratorForClass(classPath);
42
- }
43
- return generator();
44
- };
45
- }
46
- function replaceClassWithVar(path) {
47
- if (path.type === "ClassDeclaration") {
48
- const varId = path.scope.generateUidIdentifierBasedOnNode(path.node.id);
49
- const classId = t.identifier(path.node.id.name);
50
- path.scope.rename(classId.name, varId.name);
51
- path.insertBefore(t.variableDeclaration("let", [t.variableDeclarator(varId)]));
52
- path.get("id").replaceWith(classId);
53
- return [t.cloneNode(varId), path];
54
- } else {
55
- let className;
56
- let varId;
57
- if (path.node.id) {
58
- className = path.node.id.name;
59
- varId = path.scope.parent.generateDeclaredUidIdentifier(className);
60
- path.scope.rename(className, varId.name);
61
- } else if (path.parentPath.node.type === "VariableDeclarator" && path.parentPath.node.id.type === "Identifier") {
62
- className = path.parentPath.node.id.name;
63
- varId = path.scope.parent.generateDeclaredUidIdentifier(className);
64
- } else {
65
- varId = path.scope.parent.generateDeclaredUidIdentifier("decorated_class");
66
- }
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")];
70
- }
71
- }
72
- function generateClassProperty(key, value, isStatic) {
73
- if (key.type === "PrivateName") {
74
- return t.classPrivateProperty(key, value, undefined, isStatic);
75
- } else {
76
- return t.classProperty(key, value, undefined, undefined, isStatic);
77
- }
78
- }
79
- function addProxyAccessorsFor(className, element, originalKey, targetKey, version, isComputed = false) {
80
- const {
81
- static: isStatic
82
- } = element.node;
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")))]);
86
- let getter, setter;
87
- if (originalKey.type === "PrivateName") {
88
- getter = t.classPrivateMethod("get", t.cloneNode(originalKey), [], getterBody, isStatic);
89
- setter = t.classPrivateMethod("set", t.cloneNode(originalKey), [t.identifier("v")], setterBody, isStatic);
90
- } else {
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);
93
- }
94
- element.insertAfter(setter);
95
- element.insertAfter(getter);
96
- }
97
- function extractProxyAccessorsFor(targetKey, version) {
98
- if (version !== "2023-05" && version !== "2023-01") {
99
- return [template.expression.ast`
100
- function () {
101
- return this.${t.cloneNode(targetKey)};
102
- }
103
- `, template.expression.ast`
104
- function (value) {
105
- this.${t.cloneNode(targetKey)} = value;
106
- }
107
- `];
108
- }
109
- return [template.expression.ast`
110
- o => o.${t.cloneNode(targetKey)}
111
- `, template.expression.ast`
112
- (o, v) => o.${t.cloneNode(targetKey)} = v
113
- `];
114
- }
115
- const FIELD = 0;
116
- const ACCESSOR = 1;
117
- const METHOD = 2;
118
- const GETTER = 3;
119
- const SETTER = 4;
120
- const STATIC_OLD_VERSION = 5;
121
- const STATIC = 8;
122
- const DECORATORS_HAVE_THIS = 16;
123
- function getElementKind(element) {
124
- switch (element.node.type) {
125
- case "ClassProperty":
126
- case "ClassPrivateProperty":
127
- return FIELD;
128
- case "ClassAccessorProperty":
129
- return ACCESSOR;
130
- case "ClassMethod":
131
- case "ClassPrivateMethod":
132
- if (element.node.kind === "get") {
133
- return GETTER;
134
- } else if (element.node.kind === "set") {
135
- return SETTER;
136
- } else {
137
- return METHOD;
138
- }
139
- }
140
- }
141
- function isDecoratorInfo(info) {
142
- return "decorators" in info;
143
- }
144
- function filteredOrderedDecoratorInfo(info) {
145
- const filtered = info.filter(isDecoratorInfo);
146
- return [...filtered.filter(el => el.isStatic && el.kind >= ACCESSOR && el.kind <= SETTER), ...filtered.filter(el => !el.isStatic && el.kind >= ACCESSOR && el.kind <= SETTER), ...filtered.filter(el => el.isStatic && el.kind === FIELD), ...filtered.filter(el => !el.isStatic && el.kind === FIELD)];
147
- }
148
- function generateDecorationList(decorators, decoratorsThis, version) {
149
- const decsCount = decorators.length;
150
- const hasOneThis = decoratorsThis.some(Boolean);
151
- const decs = [];
152
- for (let i = 0; i < decsCount; i++) {
153
- if (version === "2023-05" && hasOneThis) {
154
- decs.push(decoratorsThis[i] || t.unaryExpression("void", t.numericLiteral(0)));
155
- }
156
- decs.push(decorators[i]);
157
- }
158
- return {
159
- hasThis: hasOneThis,
160
- decs
161
- };
162
- }
163
- function generateDecorationExprs(info, version) {
164
- return t.arrayExpression(filteredOrderedDecoratorInfo(info).map(el => {
165
- const {
166
- decs,
167
- hasThis
168
- } = generateDecorationList(el.decorators, el.decoratorsThis, version);
169
- let flag = el.kind;
170
- if (el.isStatic) {
171
- flag += version === "2023-05" ? STATIC : STATIC_OLD_VERSION;
172
- }
173
- if (hasThis) flag += DECORATORS_HAVE_THIS;
174
- return t.arrayExpression([decs.length === 1 ? decs[0] : t.arrayExpression(decs), t.numericLiteral(flag), el.name, ...(el.privateMethods || [])]);
175
- }));
176
- }
177
- function extractElementLocalAssignments(decorationInfo) {
178
- const localIds = [];
179
- for (const el of filteredOrderedDecoratorInfo(decorationInfo)) {
180
- const {
181
- locals
182
- } = el;
183
- if (Array.isArray(locals)) {
184
- localIds.push(...locals);
185
- } else if (locals !== undefined) {
186
- localIds.push(locals);
187
- }
188
- }
189
- return localIds;
190
- }
191
- function addCallAccessorsFor(element, key, getId, setId) {
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")]))])));
194
- }
195
- function isNotTsParameter(node) {
196
- return node.type !== "TSParameterProperty";
197
- }
198
- function movePrivateAccessor(element, key, methodLocalVar, isStatic) {
199
- let params;
200
- let block;
201
- if (element.node.kind === "set") {
202
- params = [t.identifier("v")];
203
- block = [t.expressionStatement(t.callExpression(methodLocalVar, [t.thisExpression(), t.identifier("v")]))];
204
- } else {
205
- params = [];
206
- block = [t.returnStatement(t.callExpression(methodLocalVar, [t.thisExpression()]))];
207
- }
208
- element.replaceWith(t.classPrivateMethod(element.node.kind, t.cloneNode(key), params, t.blockStatement(block), isStatic));
209
- }
210
- function isClassDecoratableElementPath(path) {
211
- const {
212
- type
213
- } = path;
214
- return type !== "TSDeclareMethod" && type !== "TSIndexSignature" && type !== "StaticBlock";
215
- }
216
- function staticBlockToIIFE(block) {
217
- return t.callExpression(t.arrowFunctionExpression([], t.blockStatement(block.body)), []);
218
- }
219
- function maybeSequenceExpression(exprs) {
220
- if (exprs.length === 0) return t.unaryExpression("void", t.numericLiteral(0));
221
- if (exprs.length === 1) return exprs[0];
222
- return t.sequenceExpression(exprs);
223
- }
224
- function transformClass(path, state, constantSuper, version) {
225
- const body = path.get("body.body");
226
- const classDecorators = path.node.decorators;
227
- let hasElementDecorators = false;
228
- const generateClassPrivateUid = createLazyPrivateUidGeneratorForClass(path);
229
- for (const element of body) {
230
- if (!isClassDecoratableElementPath(element)) {
231
- continue;
232
- }
233
- if (element.node.decorators && element.node.decorators.length > 0) {
234
- hasElementDecorators = true;
235
- } else if (element.node.type === "ClassAccessorProperty") {
236
- const {
237
- key,
238
- value,
239
- static: isStatic,
240
- computed
241
- } = element.node;
242
- const newId = generateClassPrivateUid();
243
- const valueNode = value ? t.cloneNode(value) : undefined;
244
- const newField = generateClassProperty(newId, valueNode, isStatic);
245
- const [newPath] = element.replaceWith(newField);
246
- addProxyAccessorsFor(path.node.id, newPath, key, newId, version, computed);
247
- }
248
- }
249
- if (!classDecorators && !hasElementDecorators) return;
250
- const elementDecoratorInfo = [];
251
- let firstFieldPath;
252
- let constructorPath;
253
- let requiresProtoInit = false;
254
- let requiresStaticInit = false;
255
- const decoratedPrivateMethods = new Set();
256
- let protoInitLocal, staticInitLocal, classInitLocal, classIdLocal;
257
- const assignments = [];
258
- const scopeParent = path.scope.parent;
259
- const memoiseExpression = (expression, hint) => {
260
- const localEvaluatedId = scopeParent.generateDeclaredUidIdentifier(hint);
261
- assignments.push(t.assignmentExpression("=", localEvaluatedId, expression));
262
- return t.cloneNode(localEvaluatedId);
263
- };
264
- const decoratorsThis = new Map();
265
- const maybeExtractDecorator = decorator => {
266
- const {
267
- expression
268
- } = decorator;
269
- if (version === "2023-05" && t.isMemberExpression(expression)) {
270
- let object;
271
- if (t.isSuper(expression.object) || t.isThisExpression(expression.object)) {
272
- object = memoiseExpression(t.thisExpression(), "obj");
273
- } else if (!scopeParent.isStatic(expression.object)) {
274
- object = memoiseExpression(expression.object, "obj");
275
- expression.object = object;
276
- } else {
277
- object = expression.object;
278
- }
279
- decoratorsThis.set(decorator, t.cloneNode(object));
280
- }
281
- if (!scopeParent.isStatic(expression)) {
282
- decorator.expression = memoiseExpression(expression, "dec");
283
- }
284
- };
285
- if (classDecorators) {
286
- classInitLocal = scopeParent.generateDeclaredUidIdentifier("initClass");
287
- const [classId, classPath] = replaceClassWithVar(path);
288
- path = classPath;
289
- classIdLocal = classId;
290
- path.node.decorators = null;
291
- for (const classDecorator of classDecorators) {
292
- maybeExtractDecorator(classDecorator);
293
- }
294
- } else {
295
- if (!path.node.id) {
296
- path.node.id = path.scope.generateUidIdentifier("Class");
297
- }
298
- classIdLocal = t.cloneNode(path.node.id);
299
- }
300
- let lastInstancePrivateName;
301
- let needsInstancePrivateBrandCheck = false;
302
- if (hasElementDecorators) {
303
- for (const element of body) {
304
- if (!isClassDecoratableElementPath(element)) {
305
- continue;
306
- }
307
- const {
308
- node
309
- } = element;
310
- const decorators = element.get("decorators");
311
- const hasDecorators = Array.isArray(decorators) && decorators.length > 0;
312
- if (hasDecorators) {
313
- for (const decoratorPath of decorators) {
314
- maybeExtractDecorator(decoratorPath.node);
315
- }
316
- }
317
- const isComputed = "computed" in element.node && element.node.computed === true;
318
- if (isComputed) {
319
- if (!scopeParent.isStatic(node.key)) {
320
- node.key = memoiseExpression(node.key, "computedKey");
321
- }
322
- }
323
- const kind = getElementKind(element);
324
- const {
325
- key
326
- } = node;
327
- const isPrivate = key.type === "PrivateName";
328
- const isStatic = !!element.node.static;
329
- let name = "computedKey";
330
- if (isPrivate) {
331
- name = key.id.name;
332
- } else if (!isComputed && key.type === "Identifier") {
333
- name = key.name;
334
- }
335
- if (isPrivate && !isStatic) {
336
- if (hasDecorators) {
337
- needsInstancePrivateBrandCheck = true;
338
- }
339
- if (t.isClassPrivateProperty(node) || !lastInstancePrivateName) {
340
- lastInstancePrivateName = key;
341
- }
342
- }
343
- if (element.isClassMethod({
344
- kind: "constructor"
345
- })) {
346
- constructorPath = element;
347
- }
348
- if (hasDecorators) {
349
- let locals;
350
- let privateMethods;
351
- if (kind === ACCESSOR) {
352
- const {
353
- value
354
- } = element.node;
355
- const params = [t.thisExpression()];
356
- if (value) {
357
- params.push(t.cloneNode(value));
358
- }
359
- const newId = generateClassPrivateUid();
360
- const newFieldInitId = element.scope.parent.generateDeclaredUidIdentifier(`init_${name}`);
361
- const newValue = t.callExpression(t.cloneNode(newFieldInitId), params);
362
- const newField = generateClassProperty(newId, newValue, isStatic);
363
- const [newPath] = element.replaceWith(newField);
364
- if (isPrivate) {
365
- privateMethods = extractProxyAccessorsFor(newId, version);
366
- const getId = newPath.scope.parent.generateDeclaredUidIdentifier(`get_${name}`);
367
- const setId = newPath.scope.parent.generateDeclaredUidIdentifier(`set_${name}`);
368
- addCallAccessorsFor(newPath, key, getId, setId);
369
- locals = [newFieldInitId, getId, setId];
370
- } else {
371
- addProxyAccessorsFor(path.node.id, newPath, key, newId, version, isComputed);
372
- locals = newFieldInitId;
373
- }
374
- } else if (kind === FIELD) {
375
- const initId = element.scope.parent.generateDeclaredUidIdentifier(`init_${name}`);
376
- const valuePath = element.get("value");
377
- valuePath.replaceWith(t.callExpression(t.cloneNode(initId), [t.thisExpression(), valuePath.node].filter(v => v)));
378
- locals = initId;
379
- if (isPrivate) {
380
- privateMethods = extractProxyAccessorsFor(key, version);
381
- }
382
- } else if (isPrivate) {
383
- locals = element.scope.parent.generateDeclaredUidIdentifier(`call_${name}`);
384
- const replaceSupers = new ReplaceSupers({
385
- constantSuper,
386
- methodPath: element,
387
- objectRef: classIdLocal,
388
- superRef: path.node.superClass,
389
- file: state.file,
390
- refToPreserve: classIdLocal
391
- });
392
- replaceSupers.replace();
393
- const {
394
- params,
395
- body,
396
- async: isAsync
397
- } = element.node;
398
- privateMethods = [t.functionExpression(undefined, params.filter(isNotTsParameter), body, isAsync)];
399
- if (kind === GETTER || kind === SETTER) {
400
- movePrivateAccessor(element, t.cloneNode(key), t.cloneNode(locals), isStatic);
401
- } else {
402
- const node = element.node;
403
- path.node.body.body.unshift(t.classPrivateProperty(key, t.cloneNode(locals), [], node.static));
404
- decoratedPrivateMethods.add(key.id.name);
405
- element.remove();
406
- }
407
- }
408
- let nameExpr;
409
- if (isComputed) {
410
- nameExpr = t.cloneNode(key);
411
- } else if (key.type === "PrivateName") {
412
- nameExpr = t.stringLiteral(key.id.name);
413
- } else if (key.type === "Identifier") {
414
- nameExpr = t.stringLiteral(key.name);
415
- } else {
416
- nameExpr = t.cloneNode(key);
417
- }
418
- elementDecoratorInfo.push({
419
- kind,
420
- decorators: decorators.map(d => d.node.expression),
421
- decoratorsThis: decorators.map(d => decoratorsThis.get(d.node)),
422
- name: nameExpr,
423
- isStatic,
424
- privateMethods,
425
- locals
426
- });
427
- if (kind !== FIELD) {
428
- if (isStatic) {
429
- requiresStaticInit = true;
430
- } else {
431
- requiresProtoInit = true;
432
- }
433
- }
434
- if (element.node) {
435
- element.node.decorators = null;
436
- }
437
- if (!firstFieldPath && !isStatic && (kind === FIELD || kind === ACCESSOR)) {
438
- firstFieldPath = element;
439
- }
440
- }
441
- }
442
- }
443
- const elementDecorations = generateDecorationExprs(elementDecoratorInfo, version);
444
- let classDecorationsFlag = 0;
445
- let classDecorations = [];
446
- if (classDecorators) {
447
- const {
448
- hasThis,
449
- decs
450
- } = generateDecorationList(classDecorators.map(el => el.expression), classDecorators.map(dec => decoratorsThis.get(dec)), version);
451
- classDecorationsFlag = hasThis ? 1 : 0;
452
- classDecorations = decs;
453
- }
454
- const elementLocals = extractElementLocalAssignments(elementDecoratorInfo);
455
- if (requiresProtoInit) {
456
- protoInitLocal = scopeParent.generateDeclaredUidIdentifier("initProto");
457
- elementLocals.push(protoInitLocal);
458
- const protoInitCall = t.callExpression(t.cloneNode(protoInitLocal), [t.thisExpression()]);
459
- if (firstFieldPath) {
460
- const value = firstFieldPath.get("value");
461
- const body = [protoInitCall];
462
- if (value.node) {
463
- body.push(value.node);
464
- }
465
- value.replaceWith(t.sequenceExpression(body));
466
- } else if (constructorPath) {
467
- if (path.node.superClass) {
468
- path.traverse({
469
- CallExpression: {
470
- exit(path) {
471
- if (!path.get("callee").isSuper()) return;
472
- path.replaceWith(t.callExpression(t.cloneNode(protoInitLocal), [path.node]));
473
- path.skip();
474
- }
475
- }
476
- });
477
- } else {
478
- constructorPath.node.body.body.unshift(t.expressionStatement(protoInitCall));
479
- }
480
- } else {
481
- const body = [t.expressionStatement(protoInitCall)];
482
- if (path.node.superClass) {
483
- body.unshift(t.expressionStatement(t.callExpression(t.super(), [t.spreadElement(t.identifier("args"))])));
484
- }
485
- path.node.body.body.unshift(t.classMethod("constructor", t.identifier("constructor"), [t.restElement(t.identifier("args"))], t.blockStatement(body)));
486
- }
487
- }
488
- if (requiresStaticInit) {
489
- staticInitLocal = scopeParent.generateDeclaredUidIdentifier("initStatic");
490
- elementLocals.push(staticInitLocal);
491
- }
492
- if (decoratedPrivateMethods.size > 0) {
493
- path.traverse({
494
- PrivateName(path) {
495
- if (!decoratedPrivateMethods.has(path.node.id.name)) return;
496
- const parentPath = path.parentPath;
497
- const parentParentPath = parentPath.parentPath;
498
- if (parentParentPath.node.type === "AssignmentExpression" && parentParentPath.node.left === parentPath.node || parentParentPath.node.type === "UpdateExpression" || parentParentPath.node.type === "RestElement" || parentParentPath.node.type === "ArrayPattern" || parentParentPath.node.type === "ObjectProperty" && parentParentPath.node.value === parentPath.node && parentParentPath.parentPath.type === "ObjectPattern" || parentParentPath.node.type === "ForOfStatement" && parentParentPath.node.left === parentPath.node) {
499
- throw path.buildCodeFrameError(`Decorated private methods are not updatable, but "#${path.node.id.name}" is updated via this expression.`);
500
- }
501
- }
502
- });
503
- }
504
- const classLocals = [];
505
- let classInitInjected = false;
506
- const classInitCall = classInitLocal && t.callExpression(t.cloneNode(classInitLocal), []);
507
- const originalClass = path.node;
508
- if (classDecorators) {
509
- classLocals.push(classIdLocal, classInitLocal);
510
- const statics = [];
511
- let staticBlocks = [];
512
- path.get("body.body").forEach(element => {
513
- if (element.isStaticBlock()) {
514
- staticBlocks.push(element.node);
515
- element.remove();
516
- return;
517
- }
518
- const isProperty = element.isClassProperty() || element.isClassPrivateProperty();
519
- if ((isProperty || element.isClassPrivateMethod()) && element.node.static) {
520
- if (isProperty && staticBlocks.length > 0) {
521
- const allValues = staticBlocks.map(staticBlockToIIFE);
522
- if (element.node.value) allValues.push(element.node.value);
523
- element.node.value = maybeSequenceExpression(allValues);
524
- staticBlocks = [];
525
- }
526
- element.node.static = false;
527
- statics.push(element.node);
528
- element.remove();
529
- }
530
- });
531
- if (statics.length > 0 || staticBlocks.length > 0) {
532
- const staticsClass = template.expression.ast`
533
- class extends ${state.addHelper("identity")} {}
534
- `;
535
- staticsClass.body.body = [t.staticBlock([t.toStatement(originalClass, true) || t.expressionStatement(originalClass)]), ...statics];
536
- const constructorBody = [];
537
- const newExpr = t.newExpression(staticsClass, []);
538
- if (staticBlocks.length > 0) {
539
- constructorBody.push(...staticBlocks.map(staticBlockToIIFE));
540
- }
541
- if (classInitCall) {
542
- classInitInjected = true;
543
- constructorBody.push(classInitCall);
544
- }
545
- if (constructorBody.length > 0) {
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))])));
548
- } else {
549
- newExpr.arguments.push(t.cloneNode(classIdLocal));
550
- }
551
- path.replaceWith(newExpr);
552
- }
553
- }
554
- if (!classInitInjected && classInitCall) {
555
- path.node.body.body.push(t.staticBlock([t.expressionStatement(classInitCall)]));
556
- }
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)));
559
- path.scope.crawl();
560
- return path;
561
- }
562
- function createLocalsAssignment(elementLocals, classLocals, elementDecorations, classDecorations, classDecorationsFlag, maybePrivateBranName, state, version) {
563
- let lhs, rhs;
564
- const args = [t.thisExpression(), elementDecorations, classDecorations];
565
- ;
566
- if (true) {
567
- if (maybePrivateBranName || classDecorationsFlag.value !== 0) {
568
- args.push(classDecorationsFlag);
569
- }
570
- if (maybePrivateBranName) {
571
- args.push(template.expression.ast`
572
- _ => ${t.cloneNode(maybePrivateBranName)} in _
573
- `);
574
- }
575
- rhs = t.callExpression(state.addHelper("applyDecs2305"), args);
576
- } else if (version === "2023-01") {
577
- if (maybePrivateBranName) {
578
- args.push(template.expression.ast`
579
- _ => ${t.cloneNode(maybePrivateBranName)} in _
580
- `);
581
- }
582
- rhs = t.callExpression(state.addHelper("applyDecs2301"), args);
583
- } else {
584
- rhs = t.callExpression(state.addHelper("applyDecs2203R"), args);
585
- }
586
- if (elementLocals.length > 0) {
587
- if (classLocals.length > 0) {
588
- lhs = t.objectPattern([t.objectProperty(t.identifier("e"), t.arrayPattern(elementLocals)), t.objectProperty(t.identifier("c"), t.arrayPattern(classLocals))]);
589
- } else {
590
- lhs = t.arrayPattern(elementLocals);
591
- rhs = t.memberExpression(rhs, t.identifier("e"), false, false);
592
- }
593
- } else {
594
- lhs = t.arrayPattern(classLocals);
595
- rhs = t.memberExpression(rhs, t.identifier("c"), false, false);
596
- }
597
- return t.assignmentExpression("=", lhs, rhs);
598
- }
599
- export default function ({
600
- assertVersion,
601
- assumption
602
- }, {
603
- loose
604
- }, version) {
605
- {
606
- assertVersion("^7.21.0");
607
- }
608
- const VISITED = new WeakSet();
609
- const constantSuper = assumption("constantSuper") ?? loose;
610
- return {
611
- name: "proposal-decorators",
612
- inherits: syntaxDecorators,
613
- visitor: {
614
- "ExportNamedDeclaration|ExportDefaultDeclaration"(path) {
615
- const {
616
- declaration
617
- } = path.node;
618
- if (declaration?.type === "ClassDeclaration" && declaration.decorators?.length > 0) {
619
- splitExportDeclaration(path);
620
- }
621
- },
622
- Class(path, state) {
623
- if (VISITED.has(path)) return;
624
- const newPath = transformClass(path, state, constantSuper, version);
625
- if (newPath) VISITED.add(newPath);
626
- }
627
- }
628
- };
629
- }
630
-
631
- //# sourceMappingURL=transformer-2023-05.js.map