]>
git.immae.eu Git - github/fretlink/purs-loader.git/blob - lib/utils.js
3 var _createClass = function () { function defineProperties(target
, props
) { for (var i
= 0; i
< props
.length
; i
++) { var descriptor
= props
[i
]; descriptor
.enumerable
= descriptor
.enumerable
|| false; descriptor
.configurable
= true; if ("value" in descriptor
) descriptor
.writable
= true; Object
.defineProperty(target
, descriptor
.key
, descriptor
); } } return function (Constructor
, protoProps
, staticProps
) { if (protoProps
) defineProperties(Constructor
.prototype, protoProps
); if (staticProps
) defineProperties(Constructor
, staticProps
); return Constructor
; }; }();
5 function _toArray(arr
) { return Array
.isArray(arr
) ? arr : Array
.from(arr
); }
7 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
); } }
9 function _classCallCheck(instance
, Constructor
) { if (!(instance
instanceof Constructor
)) { throw new TypeError("Cannot call a class as a function"); } }
11 function _possibleConstructorReturn(self
, call
) { if (!self
) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call
&& (typeof call
=== "object" || typeof call
=== "function") ? call : self
; }
13 function _inherits(subClass
, superClass
) { if (typeof superClass
!== "function" && superClass
!== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass
); } subClass
.prototype = Object
.create(superClass
&& superClass
.prototype, { constructor: { value: subClass
, enumerable: false, writable: true, configurable: true } }); if (superClass
) Object
.setPrototypeOf
? Object
.setPrototypeOf(subClass
, superClass
) : subClass
.__proto__
= superClass
; }
15 var path
= require('path');
17 exports
.PscError = function (_Error
) {
18 _inherits(PscError
, _Error
);
20 function PscError(message
, modules
) {
21 _classCallCheck(this, PscError
);
23 var _this
= _possibleConstructorReturn(this, (PscError
.__proto__
|| Object
.getPrototypeOf(PscError
)).call(this, message
));
25 _this
.modules
= modules
;
26 _this
.isPscError
= true;
30 _createClass(PscError
, null, [{
40 var repeat
= function repeat(value
, times
) {
41 return times
<= 0 ? [] : [value
].concat(_toConsumableArray(repeat(value
, times
- 1)));
43 var diffPursModuleNames
= function diffPursModuleNames(from, target
, parts
) {
44 if (!from.length
) return parts
.concat(target
);
45 if (!target
.length
) return parts
.concat(repeat('..', from.length
));
47 var _from
= _toArray(from),
49 tail_from
= _from
.slice(1);
51 var _target
= _toArray(target
),
52 head_target
= _target
[0],
53 tail_target
= _target
.slice(1);
55 return head_from
=== head_target
? diffPursModuleNames(tail_from
, tail_target
, parts
) : parts
.concat(repeat('..', from.length
), target
);
57 exports
.resolvePursModule = function (_ref
) {
58 var baseModulePath
= _ref
.baseModulePath
,
59 baseModuleName
= _ref
.baseModuleName
,
60 targetModuleName
= _ref
.targetModuleName
;
62 var parts
= diffPursModuleNames(baseModuleName
.split('.'), targetModuleName
.split('.'), []);
63 return parts
.length
? path
.resolve(baseModulePath
, path
.join
.apply(path
, _toConsumableArray(parts
)) + '.purs') : baseModulePath
;