1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | exports.default = function () {
|
8 | var BabelRootImport = function BabelRootImport() {
|
9 | _classCallCheck(this, BabelRootImport);
|
10 |
|
11 | return {
|
12 | 'visitor': {
|
13 | ImportDeclaration: function ImportDeclaration(path, state) {
|
14 | var defaultPath = path.node.source.value;
|
15 |
|
16 | var rootPathSuffix = '';
|
17 | var rootPathPrefix = '';
|
18 |
|
19 | if (state && state.opts) {
|
20 | if (state.opts.rootPathSuffix && typeof state.opts.rootPathSuffix === 'string') {
|
21 | rootPathSuffix = state.opts.rootPathSuffix.replace(/^(\/)|(\/)$/g, '');
|
22 | }
|
23 |
|
24 | if (state.opts.rootPathPrefix && typeof state.opts.rootPathPrefix === 'string') {
|
25 | rootPathPrefix = state.opts.rootPathPrefix;
|
26 | } else {
|
27 | rootPathPrefix = '~';
|
28 | }
|
29 | }
|
30 |
|
31 | if ((0, _helper2.default)().hasRootPathPrefixInString(defaultPath, rootPathPrefix)) {
|
32 | path.node.source.value = (0, _helper2.default)().transformRelativeToRootPath(defaultPath, rootPathSuffix, rootPathPrefix);
|
33 | }
|
34 | }
|
35 | }
|
36 | };
|
37 | };
|
38 |
|
39 | return new BabelRootImport();
|
40 | };
|
41 |
|
42 | var _helper = require('./helper');
|
43 |
|
44 | var _helper2 = _interopRequireDefault(_helper);
|
45 |
|
46 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
47 |
|
48 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
\ | No newline at end of file |