@babel/plugin-proposal-decorators 7.17.2 → 7.17.12

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.
@@ -11,6 +11,8 @@ var _pluginSyntaxDecorators = require("@babel/plugin-syntax-decorators");
11
11
 
12
12
  var _helperReplaceSupers = require("@babel/helper-replace-supers");
13
13
 
14
+ var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
15
+
14
16
  function incrementId(id, idx = id.length - 1) {
15
17
  if (idx === -1) {
16
18
  id.unshift(65);
@@ -161,8 +163,13 @@ function isDecoratorInfo(info) {
161
163
  return "decorators" in info;
162
164
  }
163
165
 
166
+ function filteredOrderedDecoratorInfo(info) {
167
+ const filtered = info.filter(isDecoratorInfo);
168
+ 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)];
169
+ }
170
+
164
171
  function generateDecorationExprs(info) {
165
- return _core.types.arrayExpression(info.filter(isDecoratorInfo).map(el => {
172
+ return _core.types.arrayExpression(filteredOrderedDecoratorInfo(info).map(el => {
166
173
  const decs = el.decorators.length > 1 ? _core.types.arrayExpression(el.decorators) : el.decorators[0];
167
174
  const kind = el.isStatic ? el.kind + STATIC : el.kind;
168
175
  const decInfo = [decs, _core.types.numericLiteral(kind), el.name];
@@ -181,23 +188,25 @@ function generateDecorationExprs(info) {
181
188
  }
182
189
 
183
190
  function extractElementLocalAssignments(decorationInfo) {
184
- const locals = [];
191
+ const localIds = [];
185
192
 
186
- for (const el of decorationInfo) {
187
- if ("locals" in el && el.locals) {
188
- if (Array.isArray(el.locals)) {
189
- locals.push(...el.locals);
190
- } else {
191
- locals.push(el.locals);
192
- }
193
+ for (const el of filteredOrderedDecoratorInfo(decorationInfo)) {
194
+ const {
195
+ locals
196
+ } = el;
197
+
198
+ if (Array.isArray(locals)) {
199
+ localIds.push(...locals);
200
+ } else if (locals !== undefined) {
201
+ localIds.push(locals);
193
202
  }
194
203
  }
195
204
 
196
- return locals;
205
+ return localIds;
197
206
  }
198
207
 
199
208
  function addCallAccessorsFor(element, key, getId, setId) {
200
- element.insertAfter(_core.types.classPrivateMethod("get", _core.types.cloneNode(key), [], _core.types.blockStatement([_core.types.expressionStatement(_core.types.callExpression(_core.types.cloneNode(getId), [_core.types.thisExpression()]))])));
209
+ element.insertAfter(_core.types.classPrivateMethod("get", _core.types.cloneNode(key), [], _core.types.blockStatement([_core.types.returnStatement(_core.types.callExpression(_core.types.cloneNode(getId), [_core.types.thisExpression()]))])));
201
210
  element.insertAfter(_core.types.classPrivateMethod("set", _core.types.cloneNode(key), [_core.types.identifier("v")], _core.types.blockStatement([_core.types.expressionStatement(_core.types.callExpression(_core.types.cloneNode(setId), [_core.types.thisExpression(), _core.types.identifier("v")]))])));
202
211
  }
203
212
 
@@ -592,7 +601,7 @@ function transformClass(path, state, constantSuper) {
592
601
  }
593
602
 
594
603
  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);
604
+ path.insertBefore(assignments.map(expr => _core.types.expressionStatement(expr)));
596
605
  path.scope.crawl();
597
606
  return path;
598
607
  }
@@ -612,22 +621,22 @@ function _default({
612
621
  name: "proposal-decorators",
613
622
  inherits: _pluginSyntaxDecorators.default,
614
623
  visitor: {
615
- ClassDeclaration(path, state) {
616
- if (VISITED.has(path)) return;
617
- const newPath = transformClass(path, state, constantSuper);
624
+ "ExportNamedDeclaration|ExportDefaultDeclaration"(path) {
625
+ var _declaration$decorato;
618
626
 
619
- if (newPath) {
620
- VISITED.add(newPath);
627
+ const {
628
+ declaration
629
+ } = path.node;
630
+
631
+ if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0) {
632
+ (0, _helperSplitExportDeclaration.default)(path);
621
633
  }
622
634
  },
623
635
 
624
- ClassExpression(path, state) {
636
+ Class(path, state) {
625
637
  if (VISITED.has(path)) return;
626
638
  const newPath = transformClass(path, state, constantSuper);
627
-
628
- if (newPath) {
629
- VISITED.add(newPath);
630
- }
639
+ if (newPath) VISITED.add(newPath);
631
640
  }
632
641
 
633
642
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/plugin-proposal-decorators",
3
- "version": "7.17.2",
3
+ "version": "7.17.12",
4
4
  "author": "The Babel Team (https://babel.dev/team)",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -20,19 +20,20 @@
20
20
  "decorators"
21
21
  ],
22
22
  "dependencies": {
23
- "@babel/helper-create-class-features-plugin": "^7.17.1",
24
- "@babel/helper-plugin-utils": "^7.16.7",
23
+ "@babel/helper-create-class-features-plugin": "^7.17.12",
24
+ "@babel/helper-plugin-utils": "^7.17.12",
25
25
  "@babel/helper-replace-supers": "^7.16.7",
26
- "@babel/plugin-syntax-decorators": "^7.17.0",
26
+ "@babel/helper-split-export-declaration": "^7.16.7",
27
+ "@babel/plugin-syntax-decorators": "^7.17.12",
27
28
  "charcodes": "^0.2.0"
28
29
  },
29
30
  "peerDependencies": {
30
31
  "@babel/core": "^7.0.0-0"
31
32
  },
32
33
  "devDependencies": {
33
- "@babel/core": "^7.17.2",
34
+ "@babel/core": "^7.17.12",
34
35
  "@babel/helper-plugin-test-runner": "^7.16.7",
35
- "@babel/traverse": "^7.17.0",
36
+ "@babel/traverse": "^7.17.12",
36
37
  "babel-plugin-polyfill-es-shims": "^0.6.0",
37
38
  "object.getownpropertydescriptors": "^2.1.1"
38
39
  },