UNPKG

28.3 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
7var lodash = require('lodash');
8var fs = _interopDefault(require('fs'));
9var path = _interopDefault(require('path'));
10
11var fails = function (exec) {
12 try {
13 return !!exec();
14 } catch (error) {
15 return true;
16 }
17};
18
19var toString = {}.toString;
20
21var classofRaw = function (it) {
22 return toString.call(it).slice(8, -1);
23};
24
25// fallback for non-array-like ES3 and non-enumerable old V8 strings
26
27
28var split = ''.split;
29
30var indexedObject = fails(function () {
31 // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
32 // eslint-disable-next-line no-prototype-builtins
33 return !Object('z').propertyIsEnumerable(0);
34}) ? function (it) {
35 return classofRaw(it) == 'String' ? split.call(it, '') : Object(it);
36} : Object;
37
38// `RequireObjectCoercible` abstract operation
39// https://tc39.github.io/ecma262/#sec-requireobjectcoercible
40var requireObjectCoercible = function (it) {
41 if (it == undefined) throw TypeError("Can't call method on " + it);
42 return it;
43};
44
45// toObject with fallback for non-array-like ES3 strings
46
47
48
49var toIndexedObject = function (it) {
50 return indexedObject(requireObjectCoercible(it));
51};
52
53function createCommonjsModule(fn, module) {
54 return module = { exports: {} }, fn(module, module.exports), module.exports;
55}
56
57// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
58var global = typeof window == 'object' && window && window.Math == Math ? window
59 : typeof self == 'object' && self && self.Math == Math ? self
60 // eslint-disable-next-line no-new-func
61 : Function('return this')();
62
63// Thank's IE8 for his funny defineProperty
64var descriptors = !fails(function () {
65 return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7;
66});
67
68var isObject = function (it) {
69 return typeof it === 'object' ? it !== null : typeof it === 'function';
70};
71
72var document = global.document;
73// typeof document.createElement is 'object' in old IE
74var exist = isObject(document) && isObject(document.createElement);
75
76var documentCreateElement = function (it) {
77 return exist ? document.createElement(it) : {};
78};
79
80// Thank's IE8 for his funny defineProperty
81var ie8DomDefine = !descriptors && !fails(function () {
82 return Object.defineProperty(documentCreateElement('div'), 'a', {
83 get: function () { return 7; }
84 }).a != 7;
85});
86
87var anObject = function (it) {
88 if (!isObject(it)) {
89 throw TypeError(String(it) + ' is not an object');
90 } return it;
91};
92
93// 7.1.1 ToPrimitive(input [, PreferredType])
94
95// instead of the ES6 spec version, we didn't implement @@toPrimitive case
96// and the second argument - flag - preferred type is a string
97var toPrimitive = function (it, S) {
98 if (!isObject(it)) return it;
99 var fn, val;
100 if (S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it))) return val;
101 if (typeof (fn = it.valueOf) == 'function' && !isObject(val = fn.call(it))) return val;
102 if (!S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it))) return val;
103 throw TypeError("Can't convert object to primitive value");
104};
105
106var nativeDefineProperty = Object.defineProperty;
107
108var f = descriptors ? nativeDefineProperty : function defineProperty(O, P, Attributes) {
109 anObject(O);
110 P = toPrimitive(P, true);
111 anObject(Attributes);
112 if (ie8DomDefine) try {
113 return nativeDefineProperty(O, P, Attributes);
114 } catch (error) { /* empty */ }
115 if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported');
116 if ('value' in Attributes) O[P] = Attributes.value;
117 return O;
118};
119
120var objectDefineProperty = {
121 f: f
122};
123
124var createPropertyDescriptor = function (bitmap, value) {
125 return {
126 enumerable: !(bitmap & 1),
127 configurable: !(bitmap & 2),
128 writable: !(bitmap & 4),
129 value: value
130 };
131};
132
133var hide = descriptors ? function (object, key, value) {
134 return objectDefineProperty.f(object, key, createPropertyDescriptor(1, value));
135} : function (object, key, value) {
136 object[key] = value;
137 return object;
138};
139
140var setGlobal = function (key, value) {
141 try {
142 hide(global, key, value);
143 } catch (error) {
144 global[key] = value;
145 } return value;
146};
147
148var shared = createCommonjsModule(function (module) {
149var SHARED = '__core-js_shared__';
150var store = global[SHARED] || setGlobal(SHARED, {});
151
152(module.exports = function (key, value) {
153 return store[key] || (store[key] = value !== undefined ? value : {});
154})('versions', []).push({
155 version: '3.0.1',
156 mode: 'global',
157 copyright: '© 2019 Denis Pushkarev (zloirock.ru)'
158});
159});
160
161var id = 0;
162var postfix = Math.random();
163
164var uid = function (key) {
165 return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + postfix).toString(36));
166};
167
168// Chrome 38 Symbol has incorrect toString conversion
169var nativeSymbol = !fails(function () {
170 // eslint-disable-next-line no-undef
171 return !String(Symbol());
172});
173
174var store = shared('wks');
175
176var Symbol$1 = global.Symbol;
177
178
179var wellKnownSymbol = function (name) {
180 return store[name] || (store[name] = nativeSymbol && Symbol$1[name]
181 || (nativeSymbol ? Symbol$1 : uid)('Symbol.' + name));
182};
183
184var hasOwnProperty = {}.hasOwnProperty;
185
186var has = function (it, key) {
187 return hasOwnProperty.call(it, key);
188};
189
190var ceil = Math.ceil;
191var floor = Math.floor;
192
193// `ToInteger` abstract operation
194// https://tc39.github.io/ecma262/#sec-tointeger
195var toInteger = function (argument) {
196 return isNaN(argument = +argument) ? 0 : (argument > 0 ? floor : ceil)(argument);
197};
198
199var min = Math.min;
200
201// `ToLength` abstract operation
202// https://tc39.github.io/ecma262/#sec-tolength
203var toLength = function (argument) {
204 return argument > 0 ? min(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
205};
206
207var max = Math.max;
208var min$1 = Math.min;
209
210// Helper for a popular repeating case of the spec:
211// Let integer be ? ToInteger(index).
212// If integer < 0, let result be max((length + integer), 0); else let result be min(length, length).
213var toAbsoluteIndex = function (index, length) {
214 var integer = toInteger(index);
215 return integer < 0 ? max(integer + length, 0) : min$1(integer, length);
216};
217
218// `Array.prototype.{ indexOf, includes }` methods implementation
219// false -> Array#indexOf
220// https://tc39.github.io/ecma262/#sec-array.prototype.indexof
221// true -> Array#includes
222// https://tc39.github.io/ecma262/#sec-array.prototype.includes
223var arrayIncludes = function (IS_INCLUDES) {
224 return function ($this, el, fromIndex) {
225 var O = toIndexedObject($this);
226 var length = toLength(O.length);
227 var index = toAbsoluteIndex(fromIndex, length);
228 var value;
229 // Array#includes uses SameValueZero equality algorithm
230 // eslint-disable-next-line no-self-compare
231 if (IS_INCLUDES && el != el) while (length > index) {
232 value = O[index++];
233 // eslint-disable-next-line no-self-compare
234 if (value != value) return true;
235 // Array#indexOf ignores holes, Array#includes - not
236 } else for (;length > index; index++) if (IS_INCLUDES || index in O) {
237 if (O[index] === el) return IS_INCLUDES || index || 0;
238 } return !IS_INCLUDES && -1;
239 };
240};
241
242var hiddenKeys = {};
243
244var arrayIndexOf = arrayIncludes(false);
245
246
247var objectKeysInternal = function (object, names) {
248 var O = toIndexedObject(object);
249 var i = 0;
250 var result = [];
251 var key;
252 for (key in O) !has(hiddenKeys, key) && has(O, key) && result.push(key);
253 // Don't enum bug & hidden keys
254 while (names.length > i) if (has(O, key = names[i++])) {
255 ~arrayIndexOf(result, key) || result.push(key);
256 }
257 return result;
258};
259
260// IE8- don't enum bug keys
261var enumBugKeys = [
262 'constructor',
263 'hasOwnProperty',
264 'isPrototypeOf',
265 'propertyIsEnumerable',
266 'toLocaleString',
267 'toString',
268 'valueOf'
269];
270
271// 19.1.2.14 / 15.2.3.14 Object.keys(O)
272
273
274
275var objectKeys = Object.keys || function keys(O) {
276 return objectKeysInternal(O, enumBugKeys);
277};
278
279var objectDefineProperties = descriptors ? Object.defineProperties : function defineProperties(O, Properties) {
280 anObject(O);
281 var keys = objectKeys(Properties);
282 var length = keys.length;
283 var i = 0;
284 var key;
285 while (length > i) objectDefineProperty.f(O, key = keys[i++], Properties[key]);
286 return O;
287};
288
289var document$1 = global.document;
290
291var html = document$1 && document$1.documentElement;
292
293var shared$1 = shared('keys');
294
295
296var sharedKey = function (key) {
297 return shared$1[key] || (shared$1[key] = uid(key));
298};
299
300// 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties])
301
302
303
304
305
306var IE_PROTO = sharedKey('IE_PROTO');
307var PROTOTYPE = 'prototype';
308var Empty = function () { /* empty */ };
309
310// Create object with fake `null` prototype: use iframe Object with cleared prototype
311var createDict = function () {
312 // Thrash, waste and sodomy: IE GC bug
313 var iframe = documentCreateElement('iframe');
314 var length = enumBugKeys.length;
315 var lt = '<';
316 var script = 'script';
317 var gt = '>';
318 var js = 'java' + script + ':';
319 var iframeDocument;
320 iframe.style.display = 'none';
321 html.appendChild(iframe);
322 iframe.src = String(js);
323 iframeDocument = iframe.contentWindow.document;
324 iframeDocument.open();
325 iframeDocument.write(lt + script + gt + 'document.F=Object' + lt + '/' + script + gt);
326 iframeDocument.close();
327 createDict = iframeDocument.F;
328 while (length--) delete createDict[PROTOTYPE][enumBugKeys[length]];
329 return createDict();
330};
331
332var objectCreate = Object.create || function create(O, Properties) {
333 var result;
334 if (O !== null) {
335 Empty[PROTOTYPE] = anObject(O);
336 result = new Empty();
337 Empty[PROTOTYPE] = null;
338 // add "__proto__" for Object.getPrototypeOf polyfill
339 result[IE_PROTO] = O;
340 } else result = createDict();
341 return Properties === undefined ? result : objectDefineProperties(result, Properties);
342};
343
344hiddenKeys[IE_PROTO] = true;
345
346var UNSCOPABLES = wellKnownSymbol('unscopables');
347
348
349var ArrayPrototype = Array.prototype;
350
351// Array.prototype[@@unscopables]
352// https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
353if (ArrayPrototype[UNSCOPABLES] == undefined) {
354 hide(ArrayPrototype, UNSCOPABLES, objectCreate(null));
355}
356
357// add a key to Array.prototype[@@unscopables]
358var addToUnscopables = function (key) {
359 ArrayPrototype[UNSCOPABLES][key] = true;
360};
361
362var functionToString = shared('native-function-to-string', Function.toString);
363
364var WeakMap = global.WeakMap;
365
366var nativeWeakMap = typeof WeakMap === 'function' && /native code/.test(functionToString.call(WeakMap));
367
368var WeakMap$1 = global.WeakMap;
369var set, get, has$1;
370
371var enforce = function (it) {
372 return has$1(it) ? get(it) : set(it, {});
373};
374
375var getterFor = function (TYPE) {
376 return function (it) {
377 var state;
378 if (!isObject(it) || (state = get(it)).type !== TYPE) {
379 throw TypeError('Incompatible receiver, ' + TYPE + ' required');
380 } return state;
381 };
382};
383
384if (nativeWeakMap) {
385 var store$1 = new WeakMap$1();
386 var wmget = store$1.get;
387 var wmhas = store$1.has;
388 var wmset = store$1.set;
389 set = function (it, metadata) {
390 wmset.call(store$1, it, metadata);
391 return metadata;
392 };
393 get = function (it) {
394 return wmget.call(store$1, it) || {};
395 };
396 has$1 = function (it) {
397 return wmhas.call(store$1, it);
398 };
399} else {
400 var STATE = sharedKey('state');
401 hiddenKeys[STATE] = true;
402 set = function (it, metadata) {
403 hide(it, STATE, metadata);
404 return metadata;
405 };
406 get = function (it) {
407 return has(it, STATE) ? it[STATE] : {};
408 };
409 has$1 = function (it) {
410 return has(it, STATE);
411 };
412}
413
414var internalState = {
415 set: set,
416 get: get,
417 has: has$1,
418 enforce: enforce,
419 getterFor: getterFor
420};
421
422var nativePropertyIsEnumerable = {}.propertyIsEnumerable;
423var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
424
425// Nashorn ~ JDK8 bug
426var NASHORN_BUG = nativeGetOwnPropertyDescriptor && !nativePropertyIsEnumerable.call({ 1: 2 }, 1);
427
428var f$1 = NASHORN_BUG ? function propertyIsEnumerable(V) {
429 var descriptor = nativeGetOwnPropertyDescriptor(this, V);
430 return !!descriptor && descriptor.enumerable;
431} : nativePropertyIsEnumerable;
432
433var objectPropertyIsEnumerable = {
434 f: f$1
435};
436
437var nativeGetOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor;
438
439var f$2 = descriptors ? nativeGetOwnPropertyDescriptor$1 : function getOwnPropertyDescriptor(O, P) {
440 O = toIndexedObject(O);
441 P = toPrimitive(P, true);
442 if (ie8DomDefine) try {
443 return nativeGetOwnPropertyDescriptor$1(O, P);
444 } catch (error) { /* empty */ }
445 if (has(O, P)) return createPropertyDescriptor(!objectPropertyIsEnumerable.f.call(O, P), O[P]);
446};
447
448var objectGetOwnPropertyDescriptor = {
449 f: f$2
450};
451
452var redefine = createCommonjsModule(function (module) {
453var getInternalState = internalState.get;
454var enforceInternalState = internalState.enforce;
455var TEMPLATE = String(functionToString).split('toString');
456
457shared('inspectSource', function (it) {
458 return functionToString.call(it);
459});
460
461(module.exports = function (O, key, value, options) {
462 var unsafe = options ? !!options.unsafe : false;
463 var simple = options ? !!options.enumerable : false;
464 var noTargetGet = options ? !!options.noTargetGet : false;
465 if (typeof value == 'function') {
466 if (typeof key == 'string' && !has(value, 'name')) hide(value, 'name', key);
467 enforceInternalState(value).source = TEMPLATE.join(typeof key == 'string' ? key : '');
468 }
469 if (O === global) {
470 if (simple) O[key] = value;
471 else setGlobal(key, value);
472 return;
473 } else if (!unsafe) {
474 delete O[key];
475 } else if (!noTargetGet && O[key]) {
476 simple = true;
477 }
478 if (simple) O[key] = value;
479 else hide(O, key, value);
480// add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
481})(Function.prototype, 'toString', function toString() {
482 return typeof this == 'function' && getInternalState(this).source || functionToString.call(this);
483});
484});
485
486// 19.1.2.7 / 15.2.3.4 Object.getOwnPropertyNames(O)
487
488var hiddenKeys$1 = enumBugKeys.concat('length', 'prototype');
489
490var f$3 = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
491 return objectKeysInternal(O, hiddenKeys$1);
492};
493
494var objectGetOwnPropertyNames = {
495 f: f$3
496};
497
498var f$4 = Object.getOwnPropertySymbols;
499
500var objectGetOwnPropertySymbols = {
501 f: f$4
502};
503
504var Reflect = global.Reflect;
505
506// all object keys, includes non-enumerable and symbols
507var ownKeys = Reflect && Reflect.ownKeys || function ownKeys(it) {
508 var keys = objectGetOwnPropertyNames.f(anObject(it));
509 var getOwnPropertySymbols = objectGetOwnPropertySymbols.f;
510 return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys;
511};
512
513var copyConstructorProperties = function (target, source) {
514 var keys = ownKeys(source);
515 var defineProperty = objectDefineProperty.f;
516 var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
517 for (var i = 0; i < keys.length; i++) {
518 var key = keys[i];
519 if (!has(target, key)) defineProperty(target, key, getOwnPropertyDescriptor(source, key));
520 }
521};
522
523var replacement = /#|\.prototype\./;
524
525var isForced = function (feature, detection) {
526 var value = data[normalize(feature)];
527 return value == POLYFILL ? true
528 : value == NATIVE ? false
529 : typeof detection == 'function' ? fails(detection)
530 : !!detection;
531};
532
533var normalize = isForced.normalize = function (string) {
534 return String(string).replace(replacement, '.').toLowerCase();
535};
536
537var data = isForced.data = {};
538var NATIVE = isForced.NATIVE = 'N';
539var POLYFILL = isForced.POLYFILL = 'P';
540
541var isForced_1 = isForced;
542
543var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
544
545
546
547
548
549
550/*
551 options.target - name of the target object
552 options.global - target is the global object
553 options.stat - export as static methods of target
554 options.proto - export as prototype methods of target
555 options.real - real prototype method for the `pure` version
556 options.forced - export even if the native feature is available
557 options.bind - bind methods to the target, required for the `pure` version
558 options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
559 options.unsafe - use the simple assignment of property instead of delete + defineProperty
560 options.sham - add a flag to not completely full polyfills
561 options.enumerable - export as enumerable property
562 options.noTargetGet - prevent calling a getter on target
563*/
564var _export = function (options, source) {
565 var TARGET = options.target;
566 var GLOBAL = options.global;
567 var STATIC = options.stat;
568 var FORCED, target, key, targetProperty, sourceProperty, descriptor;
569 if (GLOBAL) {
570 target = global;
571 } else if (STATIC) {
572 target = global[TARGET] || setGlobal(TARGET, {});
573 } else {
574 target = (global[TARGET] || {}).prototype;
575 }
576 if (target) for (key in source) {
577 sourceProperty = source[key];
578 if (options.noTargetGet) {
579 descriptor = getOwnPropertyDescriptor(target, key);
580 targetProperty = descriptor && descriptor.value;
581 } else targetProperty = target[key];
582 FORCED = isForced_1(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
583 // contained in target
584 if (!FORCED && targetProperty !== undefined) {
585 if (typeof sourceProperty === typeof targetProperty) continue;
586 copyConstructorProperties(sourceProperty, targetProperty);
587 }
588 // add a flag to not completely full polyfills
589 if (options.sham || (targetProperty && targetProperty.sham)) {
590 hide(sourceProperty, 'sham', true);
591 }
592 // extend global
593 redefine(target, key, sourceProperty, options);
594 }
595};
596
597// `ToObject` abstract operation
598// https://tc39.github.io/ecma262/#sec-toobject
599var toObject = function (argument) {
600 return Object(requireObjectCoercible(argument));
601};
602
603var correctPrototypeGetter = !fails(function () {
604 function F() { /* empty */ }
605 F.prototype.constructor = null;
606 return Object.getPrototypeOf(new F()) !== F.prototype;
607});
608
609// 19.1.2.9 / 15.2.3.2 Object.getPrototypeOf(O)
610
611
612var IE_PROTO$1 = sharedKey('IE_PROTO');
613
614var ObjectPrototype = Object.prototype;
615
616var objectGetPrototypeOf = correctPrototypeGetter ? Object.getPrototypeOf : function (O) {
617 O = toObject(O);
618 if (has(O, IE_PROTO$1)) return O[IE_PROTO$1];
619 if (typeof O.constructor == 'function' && O instanceof O.constructor) {
620 return O.constructor.prototype;
621 } return O instanceof Object ? ObjectPrototype : null;
622};
623
624var ITERATOR = wellKnownSymbol('iterator');
625var BUGGY_SAFARI_ITERATORS = false;
626
627var returnThis = function () { return this; };
628
629// `%IteratorPrototype%` object
630// https://tc39.github.io/ecma262/#sec-%iteratorprototype%-object
631var IteratorPrototype, PrototypeOfArrayIteratorPrototype, arrayIterator;
632
633if ([].keys) {
634 arrayIterator = [].keys();
635 // Safari 8 has buggy iterators w/o `next`
636 if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS = true;
637 else {
638 PrototypeOfArrayIteratorPrototype = objectGetPrototypeOf(objectGetPrototypeOf(arrayIterator));
639 if (PrototypeOfArrayIteratorPrototype !== Object.prototype) IteratorPrototype = PrototypeOfArrayIteratorPrototype;
640 }
641}
642
643if (IteratorPrototype == undefined) IteratorPrototype = {};
644
645// 25.1.2.1.1 %IteratorPrototype%[@@iterator]()
646if (!has(IteratorPrototype, ITERATOR)) hide(IteratorPrototype, ITERATOR, returnThis);
647
648var iteratorsCore = {
649 IteratorPrototype: IteratorPrototype,
650 BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS
651};
652
653var defineProperty = objectDefineProperty.f;
654
655var TO_STRING_TAG = wellKnownSymbol('toStringTag');
656
657var setToStringTag = function (it, TAG, STATIC) {
658 if (it && !has(it = STATIC ? it : it.prototype, TO_STRING_TAG)) {
659 defineProperty(it, TO_STRING_TAG, { configurable: true, value: TAG });
660 }
661};
662
663var IteratorPrototype$1 = iteratorsCore.IteratorPrototype;
664
665var createIteratorConstructor = function (IteratorConstructor, NAME, next) {
666 var TO_STRING_TAG = NAME + ' Iterator';
667 IteratorConstructor.prototype = objectCreate(IteratorPrototype$1, { next: createPropertyDescriptor(1, next) });
668 setToStringTag(IteratorConstructor, TO_STRING_TAG, false, true);
669 return IteratorConstructor;
670};
671
672var validateSetPrototypeOfArguments = function (O, proto) {
673 anObject(O);
674 if (!isObject(proto) && proto !== null) {
675 throw TypeError("Can't set " + String(proto) + ' as a prototype');
676 }
677};
678
679// Works with __proto__ only. Old v8 can't work with null proto objects.
680/* eslint-disable no-proto */
681
682
683var objectSetPrototypeOf = Object.setPrototypeOf || ('__proto__' in {} ? function () {
684 var correctSetter = false;
685 var test = {};
686 var setter;
687 try {
688 setter = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set;
689 setter.call(test, []);
690 correctSetter = test instanceof Array;
691 } catch (error) { /* empty */ }
692 return function setPrototypeOf(O, proto) {
693 validateSetPrototypeOfArguments(O, proto);
694 if (correctSetter) setter.call(O, proto);
695 else O.__proto__ = proto;
696 return O;
697 };
698}() : undefined);
699
700var ITERATOR$1 = wellKnownSymbol('iterator');
701
702
703var IteratorPrototype$2 = iteratorsCore.IteratorPrototype;
704var BUGGY_SAFARI_ITERATORS$1 = iteratorsCore.BUGGY_SAFARI_ITERATORS;
705var KEYS = 'keys';
706var VALUES = 'values';
707var ENTRIES = 'entries';
708
709var returnThis$1 = function () { return this; };
710
711var defineIterator = function (Iterable, NAME, IteratorConstructor, next, DEFAULT, IS_SET, FORCED) {
712 createIteratorConstructor(IteratorConstructor, NAME, next);
713
714 var getIterationMethod = function (KIND) {
715 if (KIND === DEFAULT && defaultIterator) return defaultIterator;
716 if (!BUGGY_SAFARI_ITERATORS$1 && KIND in IterablePrototype) return IterablePrototype[KIND];
717 switch (KIND) {
718 case KEYS: return function keys() { return new IteratorConstructor(this, KIND); };
719 case VALUES: return function values() { return new IteratorConstructor(this, KIND); };
720 case ENTRIES: return function entries() { return new IteratorConstructor(this, KIND); };
721 } return function () { return new IteratorConstructor(this); };
722 };
723
724 var TO_STRING_TAG = NAME + ' Iterator';
725 var INCORRECT_VALUES_NAME = false;
726 var IterablePrototype = Iterable.prototype;
727 var nativeIterator = IterablePrototype[ITERATOR$1]
728 || IterablePrototype['@@iterator']
729 || DEFAULT && IterablePrototype[DEFAULT];
730 var defaultIterator = !BUGGY_SAFARI_ITERATORS$1 && nativeIterator || getIterationMethod(DEFAULT);
731 var anyNativeIterator = NAME == 'Array' ? IterablePrototype.entries || nativeIterator : nativeIterator;
732 var CurrentIteratorPrototype, methods, KEY;
733
734 // fix native
735 if (anyNativeIterator) {
736 CurrentIteratorPrototype = objectGetPrototypeOf(anyNativeIterator.call(new Iterable()));
737 if (IteratorPrototype$2 !== Object.prototype && CurrentIteratorPrototype.next) {
738 if (objectGetPrototypeOf(CurrentIteratorPrototype) !== IteratorPrototype$2) {
739 if (objectSetPrototypeOf) {
740 objectSetPrototypeOf(CurrentIteratorPrototype, IteratorPrototype$2);
741 } else if (typeof CurrentIteratorPrototype[ITERATOR$1] != 'function') {
742 hide(CurrentIteratorPrototype, ITERATOR$1, returnThis$1);
743 }
744 }
745 // Set @@toStringTag to native iterators
746 setToStringTag(CurrentIteratorPrototype, TO_STRING_TAG, true, true);
747 }
748 }
749
750 // fix Array#{values, @@iterator}.name in V8 / FF
751 if (DEFAULT == VALUES && nativeIterator && nativeIterator.name !== VALUES) {
752 INCORRECT_VALUES_NAME = true;
753 defaultIterator = function values() { return nativeIterator.call(this); };
754 }
755
756 // define iterator
757 if (IterablePrototype[ITERATOR$1] !== defaultIterator) {
758 hide(IterablePrototype, ITERATOR$1, defaultIterator);
759 }
760
761 // export additional methods
762 if (DEFAULT) {
763 methods = {
764 values: getIterationMethod(VALUES),
765 keys: IS_SET ? defaultIterator : getIterationMethod(KEYS),
766 entries: getIterationMethod(ENTRIES)
767 };
768 if (FORCED) for (KEY in methods) {
769 if (BUGGY_SAFARI_ITERATORS$1 || INCORRECT_VALUES_NAME || !(KEY in IterablePrototype)) {
770 redefine(IterablePrototype, KEY, methods[KEY]);
771 }
772 } else _export({ target: NAME, proto: true, forced: BUGGY_SAFARI_ITERATORS$1 || INCORRECT_VALUES_NAME }, methods);
773 }
774
775 return methods;
776};
777
778var ARRAY_ITERATOR = 'Array Iterator';
779var setInternalState = internalState.set;
780var getInternalState = internalState.getterFor(ARRAY_ITERATOR);
781
782// `Array.prototype.entries` method
783// https://tc39.github.io/ecma262/#sec-array.prototype.entries
784// `Array.prototype.keys` method
785// https://tc39.github.io/ecma262/#sec-array.prototype.keys
786// `Array.prototype.values` method
787// https://tc39.github.io/ecma262/#sec-array.prototype.values
788// `Array.prototype[@@iterator]` method
789// https://tc39.github.io/ecma262/#sec-array.prototype-@@iterator
790// `CreateArrayIterator` internal method
791// https://tc39.github.io/ecma262/#sec-createarrayiterator
792var es_array_iterator = defineIterator(Array, 'Array', function (iterated, kind) {
793 setInternalState(this, {
794 type: ARRAY_ITERATOR,
795 target: toIndexedObject(iterated), // target
796 index: 0, // next index
797 kind: kind // kind
798 });
799// `%ArrayIteratorPrototype%.next` method
800// https://tc39.github.io/ecma262/#sec-%arrayiteratorprototype%.next
801}, function () {
802 var state = getInternalState(this);
803 var target = state.target;
804 var kind = state.kind;
805 var index = state.index++;
806 if (!target || index >= target.length) {
807 state.target = undefined;
808 return { value: undefined, done: true };
809 }
810 if (kind == 'keys') return { value: index, done: false };
811 if (kind == 'values') return { value: target[index], done: false };
812 return { value: [index, target[index]], done: false };
813}, 'values');
814
815// https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
816addToUnscopables('keys');
817addToUnscopables('values');
818addToUnscopables('entries');
819
820function doTsCheck(tsPath, filePaths) {
821 // eslint-disable-next-line import/no-dynamic-require, global-require
822 const ts = require(tsPath);
823
824 const configPaths = lodash.groupBy(filePaths, filePath => ts.findConfigFile(filePath, ts.sys.fileExists));
825 const filesWithoutProject = configPaths.undefined || [];
826 const filesNotIncludedInProject = [];
827 const diagnostics = [];
828 Object.entries(configPaths).forEach(([configPath, files]) => {
829 const program = createTsProgram(ts, configPath);
830 files.forEach(f => {
831 if (!program.getSourceFile(f)) {
832 filesNotIncludedInProject.push(f);
833 }
834 });
835 diagnostics.push(...ts.getPreEmitDiagnostics(program));
836 });
837 return {
838 filesWithoutProject,
839 filesNotIncludedInProject,
840 errors: diagnostics.map(d => ({
841 filename: d.file ? d.file.fileName : 'Other TypeScript errors',
842 message: typeof d.messageText === 'string' ? d.messageText : d.messageText.messageText
843 }))
844 };
845}
846
847// This is taken from the TSLint source:
848// https://github.com/palantir/tslint/blob/2ca2f1990868d7bfdf0d92216a42b98dca9ddab7/src/linter.ts#L55-L100
849function createTsProgram(ts, configPath) {
850 const config = ts.readConfigFile(configPath, ts.sys.readFile);
851
852 if (config.error !== undefined) {
853 throw ts.formatDiagnostics([config.error], {
854 getCanonicalFileName: f => f,
855 getCurrentDirectory: process.cwd,
856 getNewLine: () => '\n'
857 });
858 }
859
860 const parseConfigHost = {
861 fileExists: fs.existsSync,
862 readDirectory: ts.sys.readDirectory,
863 readFile: file => fs.readFileSync(file, 'utf8'),
864 useCaseSensitiveFileNames: true
865 };
866 const parsed = ts.parseJsonConfigFileContent(config.config, parseConfigHost, path.resolve(path.dirname(configPath)), {
867 noEmit: true
868 });
869
870 if (parsed.errors !== undefined) {
871 // ignore warnings and 'TS18003: No inputs were found in config file ...'
872 const errors = parsed.errors.filter(d => d.category === ts.DiagnosticCategory.Error && d.code !== 18003);
873
874 if (errors.length !== 0) {
875 throw ts.formatDiagnostics(errors, {
876 getCanonicalFileName: f => f,
877 getCurrentDirectory: process.cwd,
878 getNewLine: () => '\n'
879 });
880 }
881 }
882
883 const host = ts.createCompilerHost(parsed.options, true);
884 const program = ts.createProgram(parsed.fileNames, parsed.options, host);
885 return program;
886}
887
888exports.doTsCheck = doTsCheck;