@babel/plugin-proposal-decorators 7.0.0-beta.46 → 7.0.0-beta.47

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 CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
 
8
8
  function _helperPluginUtils() {
9
- var data = require("@babel/helper-plugin-utils");
9
+ const data = require("@babel/helper-plugin-utils");
10
10
 
11
11
  _helperPluginUtils = function _helperPluginUtils() {
12
12
  return data;
@@ -16,7 +16,7 @@ function _helperPluginUtils() {
16
16
  }
17
17
 
18
18
  function _pluginSyntaxDecorators() {
19
- var data = _interopRequireDefault(require("@babel/plugin-syntax-decorators"));
19
+ const data = _interopRequireDefault(require("@babel/plugin-syntax-decorators"));
20
20
 
21
21
  _pluginSyntaxDecorators = function _pluginSyntaxDecorators() {
22
22
  return data;
@@ -31,10 +31,10 @@ var _transformerLegacy = _interopRequireDefault(require("./transformer-legacy"))
31
31
 
32
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
33
 
34
- var _default = (0, _helperPluginUtils().declare)(function (api, options) {
34
+ var _default = (0, _helperPluginUtils().declare)((api, options) => {
35
35
  api.assertVersion(7);
36
- var _options$legacy = options.legacy,
37
- legacy = _options$legacy === void 0 ? false : _options$legacy;
36
+ const _options$legacy = options.legacy,
37
+ legacy = _options$legacy === void 0 ? false : _options$legacy;
38
38
 
39
39
  if (typeof legacy !== "boolean") {
40
40
  throw new Error("'legacy' must be a boolean.");
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
 
8
8
  function _core() {
9
- var data = require("@babel/core");
9
+ const data = require("@babel/core");
10
10
 
11
11
  _core = function _core() {
12
12
  return data;
@@ -15,35 +15,44 @@ function _core() {
15
15
  return data;
16
16
  }
17
17
 
18
- var buildClassDecorator = (0, _core().template)("\n DECORATOR(CLASS_REF = INNER) || CLASS_REF;\n");
19
- var buildClassPrototype = (0, _core().template)("\n CLASS_REF.prototype;\n");
20
- var buildGetDescriptor = (0, _core().template)("\n Object.getOwnPropertyDescriptor(TARGET, PROPERTY);\n");
21
- var buildGetObjectInitializer = (0, _core().template)("\n (TEMP = Object.getOwnPropertyDescriptor(TARGET, PROPERTY), (TEMP = TEMP ? TEMP.value : undefined), {\n enumerable: true,\n configurable: true,\n writable: true,\n initializer: function(){\n return TEMP;\n }\n })\n");
22
- var WARNING_CALLS = new WeakSet();
18
+ const buildClassDecorator = (0, _core().template)(`
19
+ DECORATOR(CLASS_REF = INNER) || CLASS_REF;
20
+ `);
21
+ const buildClassPrototype = (0, _core().template)(`
22
+ CLASS_REF.prototype;
23
+ `);
24
+ const buildGetDescriptor = (0, _core().template)(`
25
+ Object.getOwnPropertyDescriptor(TARGET, PROPERTY);
26
+ `);
27
+ const buildGetObjectInitializer = (0, _core().template)(`
28
+ (TEMP = Object.getOwnPropertyDescriptor(TARGET, PROPERTY), (TEMP = TEMP ? TEMP.value : undefined), {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ initializer: function(){
33
+ return TEMP;
34
+ }
35
+ })
36
+ `);
37
+ const WARNING_CALLS = new WeakSet();
23
38
 
24
39
  function applyEnsureOrdering(path) {
25
- var decorators = (path.isClass() ? [path].concat(path.get("body.body")) : path.get("properties")).reduce(function (acc, prop) {
26
- return acc.concat(prop.node.decorators || []);
27
- }, []);
28
- var identDecorators = decorators.filter(function (decorator) {
29
- return !_core().types.isIdentifier(decorator.callee);
30
- });
40
+ const decorators = (path.isClass() ? [path].concat(path.get("body.body")) : path.get("properties")).reduce((acc, prop) => acc.concat(prop.node.decorators || []), []);
41
+ const identDecorators = decorators.filter(decorator => !_core().types.isIdentifier(decorator.callee));
31
42
  if (identDecorators.length === 0) return;
32
- return _core().types.sequenceExpression(identDecorators.map(function (decorator) {
33
- var callee = decorator.callee;
34
- var id = decorator.callee = path.scope.generateDeclaredUidIdentifier("dec");
43
+ return _core().types.sequenceExpression(identDecorators.map(decorator => {
44
+ const callee = decorator.callee;
45
+ const id = decorator.callee = path.scope.generateDeclaredUidIdentifier("dec");
35
46
  return _core().types.assignmentExpression("=", id, callee);
36
47
  }).concat([path.node]));
37
48
  }
38
49
 
39
50
  function applyClassDecorators(classPath) {
40
51
  if (!hasClassDecorators(classPath.node)) return;
41
- var decorators = classPath.node.decorators || [];
52
+ const decorators = classPath.node.decorators || [];
42
53
  classPath.node.decorators = null;
43
- var name = classPath.scope.generateDeclaredUidIdentifier("class");
44
- return decorators.map(function (dec) {
45
- return dec.callee;
46
- }).reverse().reduce(function (acc, decorator) {
54
+ const name = classPath.scope.generateDeclaredUidIdentifier("class");
55
+ return decorators.map(dec => dec.callee).reverse().reduce(function (acc, decorator) {
47
56
  return buildClassDecorator({
48
57
  CLASS_REF: _core().types.cloneNode(name),
49
58
  DECORATOR: _core().types.cloneNode(decorator),
@@ -62,9 +71,7 @@ function applyMethodDecorators(path, state) {
62
71
  }
63
72
 
64
73
  function hasMethodDecorators(body) {
65
- return body.some(function (node) {
66
- return node.decorators && node.decorators.length;
67
- });
74
+ return body.some(node => node.decorators && node.decorators.length);
68
75
  }
69
76
 
70
77
  function applyObjectDecorators(path, state) {
@@ -73,9 +80,9 @@ function applyObjectDecorators(path, state) {
73
80
  }
74
81
 
75
82
  function applyTargetDecorators(path, state, decoratedProps) {
76
- var name = path.scope.generateDeclaredUidIdentifier(path.isClass() ? "class" : "obj");
77
- var exprs = decoratedProps.reduce(function (acc, node) {
78
- var decorators = node.decorators || [];
83
+ const name = path.scope.generateDeclaredUidIdentifier(path.isClass() ? "class" : "obj");
84
+ const exprs = decoratedProps.reduce(function (acc, node) {
85
+ const decorators = node.decorators || [];
79
86
  node.decorators = null;
80
87
  if (decorators.length === 0) return acc;
81
88
 
@@ -83,25 +90,21 @@ function applyTargetDecorators(path, state, decoratedProps) {
83
90
  throw path.buildCodeFrameError("Computed method/property decorators are not yet supported.");
84
91
  }
85
92
 
86
- var property = _core().types.isLiteral(node.key) ? node.key : _core().types.stringLiteral(node.key.name);
87
- var target = path.isClass() && !node.static ? buildClassPrototype({
93
+ const property = _core().types.isLiteral(node.key) ? node.key : _core().types.stringLiteral(node.key.name);
94
+ const target = path.isClass() && !node.static ? buildClassPrototype({
88
95
  CLASS_REF: name
89
96
  }).expression : name;
90
97
 
91
98
  if (_core().types.isClassProperty(node, {
92
99
  static: false
93
100
  })) {
94
- var descriptor = path.scope.generateDeclaredUidIdentifier("descriptor");
95
- var initializer = node.value ? _core().types.functionExpression(null, [], _core().types.blockStatement([_core().types.returnStatement(node.value)])) : _core().types.nullLiteral();
101
+ const descriptor = path.scope.generateDeclaredUidIdentifier("descriptor");
102
+ const initializer = node.value ? _core().types.functionExpression(null, [], _core().types.blockStatement([_core().types.returnStatement(node.value)])) : _core().types.nullLiteral();
96
103
  node.value = _core().types.callExpression(state.addHelper("initializerWarningHelper"), [descriptor, _core().types.thisExpression()]);
97
104
  WARNING_CALLS.add(node.value);
98
- acc = acc.concat([_core().types.assignmentExpression("=", descriptor, _core().types.callExpression(state.addHelper("applyDecoratedDescriptor"), [_core().types.cloneNode(target), _core().types.cloneNode(property), _core().types.arrayExpression(decorators.map(function (dec) {
99
- return _core().types.cloneNode(dec.callee);
100
- })), _core().types.objectExpression([_core().types.objectProperty(_core().types.identifier("enumerable"), _core().types.booleanLiteral(true)), _core().types.objectProperty(_core().types.identifier("initializer"), initializer)])]))]);
105
+ acc = acc.concat([_core().types.assignmentExpression("=", descriptor, _core().types.callExpression(state.addHelper("applyDecoratedDescriptor"), [_core().types.cloneNode(target), _core().types.cloneNode(property), _core().types.arrayExpression(decorators.map(dec => _core().types.cloneNode(dec.callee))), _core().types.objectExpression([_core().types.objectProperty(_core().types.identifier("enumerable"), _core().types.booleanLiteral(true)), _core().types.objectProperty(_core().types.identifier("initializer"), initializer)])]))]);
101
106
  } else {
102
- acc = acc.concat(_core().types.callExpression(state.addHelper("applyDecoratedDescriptor"), [_core().types.cloneNode(target), _core().types.cloneNode(property), _core().types.arrayExpression(decorators.map(function (dec) {
103
- return _core().types.cloneNode(dec.callee);
104
- })), _core().types.isObjectProperty(node) || _core().types.isClassProperty(node, {
107
+ acc = acc.concat(_core().types.callExpression(state.addHelper("applyDecoratedDescriptor"), [_core().types.cloneNode(target), _core().types.cloneNode(property), _core().types.arrayExpression(decorators.map(dec => _core().types.cloneNode(dec.callee))), _core().types.isObjectProperty(node) || _core().types.isClassProperty(node, {
105
108
  static: true
106
109
  }) ? buildGetObjectInitializer({
107
110
  TEMP: path.scope.generateDeclaredUidIdentifier("init"),
@@ -119,16 +122,16 @@ function applyTargetDecorators(path, state, decoratedProps) {
119
122
  }
120
123
 
121
124
  var _default = {
122
- ClassDeclaration: function ClassDeclaration(path) {
123
- var node = path.node;
125
+ ClassDeclaration(path) {
126
+ const node = path.node;
124
127
 
125
128
  if (!hasClassDecorators(node) && !hasMethodDecorators(node.body.body)) {
126
129
  return;
127
130
  }
128
131
 
129
- var ref = node.id ? _core().types.cloneNode(node.id) : path.scope.generateUidIdentifier("class");
132
+ const ref = node.id ? _core().types.cloneNode(node.id) : path.scope.generateUidIdentifier("class");
130
133
 
131
- var letDeclaration = _core().types.variableDeclaration("let", [_core().types.variableDeclarator(ref, _core().types.toExpression(node))]);
134
+ const letDeclaration = _core().types.variableDeclaration("let", [_core().types.variableDeclarator(ref, _core().types.toExpression(node))]);
132
135
 
133
136
  if (path.parentPath.isExportDefaultDeclaration()) {
134
137
  path.parentPath.replaceWithMultiple([letDeclaration, _core().types.exportNamedDeclaration(null, [_core().types.exportSpecifier(_core().types.cloneNode(ref), _core().types.identifier("default"))])]);
@@ -136,17 +139,21 @@ var _default = {
136
139
  path.replaceWith(letDeclaration);
137
140
  }
138
141
  },
139
- ClassExpression: function ClassExpression(path, state) {
140
- var decoratedClass = applyEnsureOrdering(path) || applyClassDecorators(path, state) || applyMethodDecorators(path, state);
142
+
143
+ ClassExpression(path, state) {
144
+ const decoratedClass = applyEnsureOrdering(path) || applyClassDecorators(path, state) || applyMethodDecorators(path, state);
141
145
  if (decoratedClass) path.replaceWith(decoratedClass);
142
146
  },
143
- ObjectExpression: function ObjectExpression(path, state) {
144
- var decoratedObject = applyEnsureOrdering(path) || applyObjectDecorators(path, state);
147
+
148
+ ObjectExpression(path, state) {
149
+ const decoratedObject = applyEnsureOrdering(path) || applyObjectDecorators(path, state);
145
150
  if (decoratedObject) path.replaceWith(decoratedObject);
146
151
  },
147
- AssignmentExpression: function AssignmentExpression(path, state) {
152
+
153
+ AssignmentExpression(path, state) {
148
154
  if (!WARNING_CALLS.has(path.node.right)) return;
149
155
  path.replaceWith(_core().types.callExpression(state.addHelper("initializerDefineProperty"), [_core().types.cloneNode(path.get("left.object").node), _core().types.stringLiteral(path.get("left.property").node.name), _core().types.cloneNode(path.get("right.arguments")[0].node), _core().types.cloneNode(path.get("right.arguments")[1].node)]));
150
156
  }
157
+
151
158
  };
152
159
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/plugin-proposal-decorators",
3
- "version": "7.0.0-beta.46",
3
+ "version": "7.0.0-beta.47",
4
4
  "author": "Logan Smyth <loganfsmyth@gmail.com>",
5
5
  "license": "MIT",
6
6
  "description": "Compile class and object decorators to ES5",
@@ -12,14 +12,14 @@
12
12
  "decorators"
13
13
  ],
14
14
  "dependencies": {
15
- "@babel/helper-plugin-utils": "7.0.0-beta.46",
16
- "@babel/plugin-syntax-decorators": "7.0.0-beta.46"
15
+ "@babel/helper-plugin-utils": "7.0.0-beta.47",
16
+ "@babel/plugin-syntax-decorators": "7.0.0-beta.47"
17
17
  },
18
18
  "peerDependencies": {
19
- "@babel/core": "7.0.0-beta.46"
19
+ "@babel/core": "7.0.0-beta.47"
20
20
  },
21
21
  "devDependencies": {
22
- "@babel/core": "7.0.0-beta.46",
23
- "@babel/helper-plugin-test-runner": "7.0.0-beta.46"
22
+ "@babel/core": "7.0.0-beta.47",
23
+ "@babel/helper-plugin-test-runner": "7.0.0-beta.47"
24
24
  }
25
25
  }