forked from babel/babel
/
plugin.js
54 lines (48 loc) 路 1.6 KB
/
plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use strict";
// https://github.com/benderTheCrime/babel-plugin-transform-function-parameter-decorators/
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.default = function(_ref) {
var types = _ref.types;
return {
visitor: {
Function: function parseFunctionPath(path) {
(path.get("params") || [])
.slice()
.reverse()
.forEach(function(param) {
var name = param.node.name;
var paramUidName = path.scope.generateUidIdentifier(name).name;
var resultantDecorator = void 0;
(param.node.decorators || [])
.slice()
.reverse()
.forEach(function(decorator) {
resultantDecorator = types.callExpression(
decorator.expression,
[resultantDecorator || types.identifier(paramUidName)]
);
});
if (resultantDecorator) {
var decoratedParamUidName = path.scope.generateUidIdentifier(name)
.name;
path.scope.rename(name, decoratedParamUidName);
param.parentPath
.get("body")
.unshiftContainer(
"body",
types.variableDeclaration("var", [
types.variableDeclarator(
types.identifier(decoratedParamUidName),
resultantDecorator
),
])
);
param.replaceWith(types.identifier(paramUidName));
}
});
},
},
};
};