]>
Commit | Line | Data |
---|---|---|
d3f40b6f CS |
1 | 'use strict'; |
2 | ||
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; }; }(); | |
4 | ||
5 | function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); } | |
6 | ||
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); } } | |
8 | ||
9 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
10 | ||
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; } | |
12 | ||
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; } | |
14 | ||
15 | var path = require('path'); | |
16 | ||
17 | exports.PscError = function (_Error) { | |
18 | _inherits(PscError, _Error); | |
19 | ||
20 | function PscError(message, modules) { | |
21 | _classCallCheck(this, PscError); | |
22 | ||
23 | var _this = _possibleConstructorReturn(this, (PscError.__proto__ || Object.getPrototypeOf(PscError)).call(this, message)); | |
24 | ||
25 | _this.modules = modules; | |
e4e6f894 | 26 | _this.isPscError = true; |
d3f40b6f CS |
27 | return _this; |
28 | } | |
29 | ||
30 | _createClass(PscError, null, [{ | |
31 | key: 'name', | |
32 | get: function get() { | |
33 | return 'PscError'; | |
34 | } | |
35 | }]); | |
36 | ||
37 | return PscError; | |
38 | }(Error); | |
39 | ||
40 | var repeat = function repeat(value, times) { | |
41 | return times <= 0 ? [] : [value].concat(_toConsumableArray(repeat(value, times - 1))); | |
42 | }; | |
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)); | |
46 | ||
47 | var _from = _toArray(from), | |
48 | head_from = _from[0], | |
49 | tail_from = _from.slice(1); | |
50 | ||
51 | var _target = _toArray(target), | |
52 | head_target = _target[0], | |
53 | tail_target = _target.slice(1); | |
54 | ||
55 | return head_from === head_target ? diffPursModuleNames(tail_from, tail_target, parts) : parts.concat(repeat('..', from.length), target); | |
56 | }; | |
57 | exports.resolvePursModule = function (_ref) { | |
58 | var baseModulePath = _ref.baseModulePath, | |
59 | baseModuleName = _ref.baseModuleName, | |
60 | targetModuleName = _ref.targetModuleName; | |
61 | ||
62 | var parts = diffPursModuleNames(baseModuleName.split('.'), targetModuleName.split('.'), []); | |
63 | return parts.length ? path.resolve(baseModulePath, path.join.apply(path, _toConsumableArray(parts)) + '.purs') : baseModulePath; | |
64 | }; |