@babel/plugin-proposal-decorators 7.3.0 → 7.7.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 +7 -31
- package/lib/transformer-legacy.js +41 -34
- package/package.json +5 -4
package/lib/index.js
CHANGED
|
@@ -5,41 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
const data = require("@babel/helper-plugin-utils");
|
|
8
|
+
var _helperPluginUtils = require("@babel/helper-plugin-utils");
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
10
|
+
var _pluginSyntaxDecorators = _interopRequireDefault(require("@babel/plugin-syntax-decorators"));
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _pluginSyntaxDecorators() {
|
|
19
|
-
const data = _interopRequireDefault(require("@babel/plugin-syntax-decorators"));
|
|
20
|
-
|
|
21
|
-
_pluginSyntaxDecorators = function () {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _helperCreateClassFeaturesPlugin() {
|
|
29
|
-
const data = require("@babel/helper-create-class-features-plugin");
|
|
30
|
-
|
|
31
|
-
_helperCreateClassFeaturesPlugin = function () {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
12
|
+
var _helperCreateClassFeaturesPlugin = require("@babel/helper-create-class-features-plugin");
|
|
37
13
|
|
|
38
14
|
var _transformerLegacy = _interopRequireDefault(require("./transformer-legacy"));
|
|
39
15
|
|
|
40
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
41
17
|
|
|
42
|
-
var _default = (0, _helperPluginUtils
|
|
18
|
+
var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
|
43
19
|
api.assertVersion(7);
|
|
44
20
|
const {
|
|
45
21
|
legacy = false
|
|
@@ -70,7 +46,7 @@ var _default = (0, _helperPluginUtils().declare)((api, options) => {
|
|
|
70
46
|
if (legacy) {
|
|
71
47
|
return {
|
|
72
48
|
name: "proposal-decorators",
|
|
73
|
-
inherits: _pluginSyntaxDecorators
|
|
49
|
+
inherits: _pluginSyntaxDecorators.default,
|
|
74
50
|
|
|
75
51
|
manipulateOptions({
|
|
76
52
|
generatorOpts
|
|
@@ -82,9 +58,9 @@ var _default = (0, _helperPluginUtils().declare)((api, options) => {
|
|
|
82
58
|
};
|
|
83
59
|
}
|
|
84
60
|
|
|
85
|
-
return (0, _helperCreateClassFeaturesPlugin
|
|
61
|
+
return (0, _helperCreateClassFeaturesPlugin.createClassFeaturePlugin)({
|
|
86
62
|
name: "proposal-decorators",
|
|
87
|
-
feature: _helperCreateClassFeaturesPlugin
|
|
63
|
+
feature: _helperCreateClassFeaturesPlugin.FEATURES.decorators,
|
|
88
64
|
|
|
89
65
|
manipulateOptions({
|
|
90
66
|
generatorOpts,
|
|
@@ -5,26 +5,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
const data = require("@babel/core");
|
|
8
|
+
var _core = require("@babel/core");
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const buildClassDecorator = (0, _core().template)(`
|
|
10
|
+
const buildClassDecorator = (0, _core.template)(`
|
|
19
11
|
DECORATOR(CLASS_REF = INNER) || CLASS_REF;
|
|
20
12
|
`);
|
|
21
|
-
const buildClassPrototype = (0, _core
|
|
13
|
+
const buildClassPrototype = (0, _core.template)(`
|
|
22
14
|
CLASS_REF.prototype;
|
|
23
15
|
`);
|
|
24
|
-
const buildGetDescriptor = (0, _core
|
|
16
|
+
const buildGetDescriptor = (0, _core.template)(`
|
|
25
17
|
Object.getOwnPropertyDescriptor(TARGET, PROPERTY);
|
|
26
18
|
`);
|
|
27
|
-
const buildGetObjectInitializer = (0, _core
|
|
19
|
+
const buildGetObjectInitializer = (0, _core.template)(`
|
|
28
20
|
(TEMP = Object.getOwnPropertyDescriptor(TARGET, PROPERTY), (TEMP = TEMP ? TEMP.value : undefined), {
|
|
29
21
|
enumerable: true,
|
|
30
22
|
configurable: true,
|
|
@@ -38,12 +30,12 @@ const WARNING_CALLS = new WeakSet();
|
|
|
38
30
|
|
|
39
31
|
function applyEnsureOrdering(path) {
|
|
40
32
|
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
|
|
33
|
+
const identDecorators = decorators.filter(decorator => !_core.types.isIdentifier(decorator.expression));
|
|
42
34
|
if (identDecorators.length === 0) return;
|
|
43
|
-
return _core
|
|
35
|
+
return _core.types.sequenceExpression(identDecorators.map(decorator => {
|
|
44
36
|
const expression = decorator.expression;
|
|
45
37
|
const id = decorator.expression = path.scope.generateDeclaredUidIdentifier("dec");
|
|
46
|
-
return _core
|
|
38
|
+
return _core.types.assignmentExpression("=", id, expression);
|
|
47
39
|
}).concat([path.node]));
|
|
48
40
|
}
|
|
49
41
|
|
|
@@ -54,8 +46,8 @@ function applyClassDecorators(classPath) {
|
|
|
54
46
|
const name = classPath.scope.generateDeclaredUidIdentifier("class");
|
|
55
47
|
return decorators.map(dec => dec.expression).reverse().reduce(function (acc, decorator) {
|
|
56
48
|
return buildClassDecorator({
|
|
57
|
-
CLASS_REF: _core
|
|
58
|
-
DECORATOR: _core
|
|
49
|
+
CLASS_REF: _core.types.cloneNode(name),
|
|
50
|
+
DECORATOR: _core.types.cloneNode(decorator),
|
|
59
51
|
INNER: acc
|
|
60
52
|
}).expression;
|
|
61
53
|
}, classPath.node);
|
|
@@ -90,35 +82,35 @@ function applyTargetDecorators(path, state, decoratedProps) {
|
|
|
90
82
|
throw path.buildCodeFrameError("Computed method/property decorators are not yet supported.");
|
|
91
83
|
}
|
|
92
84
|
|
|
93
|
-
const property = _core
|
|
85
|
+
const property = _core.types.isLiteral(node.key) ? node.key : _core.types.stringLiteral(node.key.name);
|
|
94
86
|
const target = path.isClass() && !node.static ? buildClassPrototype({
|
|
95
87
|
CLASS_REF: name
|
|
96
88
|
}).expression : name;
|
|
97
89
|
|
|
98
|
-
if (_core
|
|
90
|
+
if (_core.types.isClassProperty(node, {
|
|
99
91
|
static: false
|
|
100
92
|
})) {
|
|
101
93
|
const descriptor = path.scope.generateDeclaredUidIdentifier("descriptor");
|
|
102
|
-
const initializer = node.value ? _core
|
|
103
|
-
node.value = _core
|
|
94
|
+
const initializer = node.value ? _core.types.functionExpression(null, [], _core.types.blockStatement([_core.types.returnStatement(node.value)])) : _core.types.nullLiteral();
|
|
95
|
+
node.value = _core.types.callExpression(state.addHelper("initializerWarningHelper"), [descriptor, _core.types.thisExpression()]);
|
|
104
96
|
WARNING_CALLS.add(node.value);
|
|
105
|
-
acc = acc.concat([_core
|
|
97
|
+
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.expression))), _core.types.objectExpression([_core.types.objectProperty(_core.types.identifier("configurable"), _core.types.booleanLiteral(true)), _core.types.objectProperty(_core.types.identifier("enumerable"), _core.types.booleanLiteral(true)), _core.types.objectProperty(_core.types.identifier("writable"), _core.types.booleanLiteral(true)), _core.types.objectProperty(_core.types.identifier("initializer"), initializer)])]))]);
|
|
106
98
|
} else {
|
|
107
|
-
acc = acc.concat(_core
|
|
99
|
+
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.expression))), _core.types.isObjectProperty(node) || _core.types.isClassProperty(node, {
|
|
108
100
|
static: true
|
|
109
101
|
}) ? buildGetObjectInitializer({
|
|
110
102
|
TEMP: path.scope.generateDeclaredUidIdentifier("init"),
|
|
111
|
-
TARGET: _core
|
|
112
|
-
PROPERTY: _core
|
|
103
|
+
TARGET: _core.types.cloneNode(target),
|
|
104
|
+
PROPERTY: _core.types.cloneNode(property)
|
|
113
105
|
}).expression : buildGetDescriptor({
|
|
114
|
-
TARGET: _core
|
|
115
|
-
PROPERTY: _core
|
|
116
|
-
}).expression, _core
|
|
106
|
+
TARGET: _core.types.cloneNode(target),
|
|
107
|
+
PROPERTY: _core.types.cloneNode(property)
|
|
108
|
+
}).expression, _core.types.cloneNode(target)]));
|
|
117
109
|
}
|
|
118
110
|
|
|
119
111
|
return acc;
|
|
120
112
|
}, []);
|
|
121
|
-
return _core
|
|
113
|
+
return _core.types.sequenceExpression([_core.types.assignmentExpression("=", _core.types.cloneNode(name), path.node), _core.types.sequenceExpression(exprs), _core.types.cloneNode(name)]);
|
|
122
114
|
}
|
|
123
115
|
|
|
124
116
|
function decoratedClassToExpression({
|
|
@@ -129,8 +121,8 @@ function decoratedClassToExpression({
|
|
|
129
121
|
return;
|
|
130
122
|
}
|
|
131
123
|
|
|
132
|
-
const ref = node.id ? _core
|
|
133
|
-
return _core
|
|
124
|
+
const ref = node.id ? _core.types.cloneNode(node.id) : scope.generateUidIdentifier("class");
|
|
125
|
+
return _core.types.variableDeclaration("let", [_core.types.variableDeclarator(ref, _core.types.toExpression(node))]);
|
|
134
126
|
}
|
|
135
127
|
|
|
136
128
|
var _default = {
|
|
@@ -140,7 +132,11 @@ var _default = {
|
|
|
140
132
|
const replacement = decoratedClassToExpression(decl);
|
|
141
133
|
|
|
142
134
|
if (replacement) {
|
|
143
|
-
path.replaceWithMultiple([replacement, _core
|
|
135
|
+
const [varDeclPath] = path.replaceWithMultiple([replacement, _core.types.exportNamedDeclaration(null, [_core.types.exportSpecifier(_core.types.cloneNode(replacement.declarations[0].id), _core.types.identifier("default"))])]);
|
|
136
|
+
|
|
137
|
+
if (!decl.node.id) {
|
|
138
|
+
path.scope.registerDeclaration(varDeclPath);
|
|
139
|
+
}
|
|
144
140
|
}
|
|
145
141
|
},
|
|
146
142
|
|
|
@@ -164,7 +160,18 @@ var _default = {
|
|
|
164
160
|
|
|
165
161
|
AssignmentExpression(path, state) {
|
|
166
162
|
if (!WARNING_CALLS.has(path.node.right)) return;
|
|
167
|
-
path.replaceWith(_core
|
|
163
|
+
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 || path.get("left.property").node.value), _core.types.cloneNode(path.get("right.arguments")[0].node), _core.types.cloneNode(path.get("right.arguments")[1].node)]));
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
CallExpression(path, state) {
|
|
167
|
+
if (path.node.arguments.length !== 3) return;
|
|
168
|
+
if (!WARNING_CALLS.has(path.node.arguments[2])) return;
|
|
169
|
+
|
|
170
|
+
if (path.node.callee.name !== state.addHelper("defineProperty").name) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
path.replaceWith(_core.types.callExpression(state.addHelper("initializerDefineProperty"), [_core.types.cloneNode(path.get("arguments")[0].node), _core.types.cloneNode(path.get("arguments")[1].node), _core.types.cloneNode(path.get("arguments.2.arguments")[0].node), _core.types.cloneNode(path.get("arguments.2.arguments")[1].node)]));
|
|
168
175
|
}
|
|
169
176
|
|
|
170
177
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babel/plugin-proposal-decorators",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.7.0",
|
|
4
4
|
"author": "Logan Smyth <loganfsmyth@gmail.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"decorators"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@babel/helper-create-class-features-plugin": "^7.
|
|
18
|
+
"@babel/helper-create-class-features-plugin": "^7.7.0",
|
|
19
19
|
"@babel/helper-plugin-utils": "^7.0.0",
|
|
20
20
|
"@babel/plugin-syntax-decorators": "^7.2.0"
|
|
21
21
|
},
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"@babel/core": "^7.0.0-0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@babel/core": "^7.
|
|
26
|
+
"@babel/core": "^7.7.0",
|
|
27
27
|
"@babel/helper-plugin-test-runner": "^7.0.0"
|
|
28
|
-
}
|
|
28
|
+
},
|
|
29
|
+
"gitHead": "97faa83953cb87e332554fa559a4956d202343ea"
|
|
29
30
|
}
|