1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = _default;
|
7 |
|
8 | var _assert = _interopRequireDefault(require("assert"));
|
9 |
|
10 | var _Plugin = _interopRequireDefault(require("./Plugin"));
|
11 |
|
12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13 |
|
14 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
15 |
|
16 | function _default(_ref) {
|
17 | var types = _ref.types;
|
18 | var plugins = null;
|
19 |
|
20 | global.__clearBabelAntdPlugin = function () {
|
21 | plugins = null;
|
22 | };
|
23 |
|
24 | function applyInstance(method, args, context) {
|
25 | var _iteratorNormalCompletion = true;
|
26 | var _didIteratorError = false;
|
27 | var _iteratorError = undefined;
|
28 |
|
29 | try {
|
30 | for (var _iterator = plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
31 | var _plugin = _step.value;
|
32 |
|
33 | if (_plugin[method]) {
|
34 | _plugin[method].apply(_plugin, [].concat(_toConsumableArray(args), [context]));
|
35 | }
|
36 | }
|
37 | } catch (err) {
|
38 | _didIteratorError = true;
|
39 | _iteratorError = err;
|
40 | } finally {
|
41 | try {
|
42 | if (!_iteratorNormalCompletion && _iterator.return != null) {
|
43 | _iterator.return();
|
44 | }
|
45 | } finally {
|
46 | if (_didIteratorError) {
|
47 | throw _iteratorError;
|
48 | }
|
49 | }
|
50 | }
|
51 | }
|
52 |
|
53 | function Program(path, _ref2) {
|
54 | var _ref2$opts = _ref2.opts,
|
55 | opts = _ref2$opts === void 0 ? {} : _ref2$opts;
|
56 |
|
57 |
|
58 | if (!plugins) {
|
59 | if (Array.isArray(opts)) {
|
60 | plugins = opts.map(function (_ref3) {
|
61 | var libraryName = _ref3.libraryName,
|
62 | libraryDirectory = _ref3.libraryDirectory,
|
63 | style = _ref3.style,
|
64 | camel2DashComponentName = _ref3.camel2DashComponentName,
|
65 | camel2UnderlineComponentName = _ref3.camel2UnderlineComponentName,
|
66 | fileName = _ref3.fileName,
|
67 | customName = _ref3.customName;
|
68 | (0, _assert.default)(libraryName, 'libraryName should be provided');
|
69 | return new _Plugin.default(libraryName, libraryDirectory, style, camel2DashComponentName, camel2UnderlineComponentName, fileName, customName, types);
|
70 | });
|
71 | } else {
|
72 | (0, _assert.default)(opts.libraryName, 'libraryName should be provided');
|
73 | plugins = [new _Plugin.default(opts.libraryName, opts.libraryDirectory, opts.style, opts.camel2DashComponentName, opts.camel2UnderlineComponentName, opts.fileName, opts.customName, types)];
|
74 | }
|
75 | }
|
76 |
|
77 | applyInstance('Program', arguments, this);
|
78 | }
|
79 |
|
80 | var methods = ['ImportDeclaration', 'CallExpression', 'MemberExpression', 'Property', 'VariableDeclarator', 'LogicalExpression', 'ConditionalExpression', 'IfStatement', 'ExpressionStatement', 'ReturnStatement', 'ExportDefaultDeclaration', 'BinaryExpression', 'NewExpression'];
|
81 | var ret = {
|
82 | visitor: {
|
83 | Program: Program
|
84 | }
|
85 | };
|
86 |
|
87 | var _loop = function _loop(method) {
|
88 | ret.visitor[method] = function () {
|
89 |
|
90 | applyInstance(method, arguments, ret.visitor);
|
91 | };
|
92 | };
|
93 |
|
94 | for (var _i = 0; _i < methods.length; _i++) {
|
95 | var method = methods[_i];
|
96 |
|
97 | _loop(method);
|
98 | }
|
99 |
|
100 | return ret;
|
101 | } |
\ | No newline at end of file |