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