@swirly/parser-rxjs 0.17.6 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js DELETED
@@ -1,1671 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- /*! *****************************************************************************
6
- Copyright (c) Microsoft Corporation.
7
-
8
- Permission to use, copy, modify, and/or distribute this software for any
9
- purpose with or without fee is hereby granted.
10
-
11
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
- PERFORMANCE OF THIS SOFTWARE.
18
- ***************************************************************************** */
19
- /* global Reflect, Promise */
20
-
21
- var extendStatics = function(d, b) {
22
- extendStatics = Object.setPrototypeOf ||
23
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
24
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
25
- return extendStatics(d, b);
26
- };
27
-
28
- function __extends(d, b) {
29
- extendStatics(d, b);
30
- function __() { this.constructor = d; }
31
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
32
- }
33
-
34
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
35
- function isFunction(x) {
36
- return typeof x === 'function';
37
- }
38
-
39
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
40
- var _enable_super_gross_mode_that_will_cause_bad_things = false;
41
- var config = {
42
- Promise: undefined,
43
- set useDeprecatedSynchronousErrorHandling(value) {
44
- if (value) {
45
- var error = /*@__PURE__*/ new Error();
46
- /*@__PURE__*/ console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \n' + error.stack);
47
- }
48
- _enable_super_gross_mode_that_will_cause_bad_things = value;
49
- },
50
- get useDeprecatedSynchronousErrorHandling() {
51
- return _enable_super_gross_mode_that_will_cause_bad_things;
52
- },
53
- };
54
-
55
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
56
- function hostReportError(err) {
57
- setTimeout(function () { throw err; }, 0);
58
- }
59
-
60
- /** PURE_IMPORTS_START _config,_util_hostReportError PURE_IMPORTS_END */
61
- var empty$1 = {
62
- closed: true,
63
- next: function (value) { },
64
- error: function (err) {
65
- if (config.useDeprecatedSynchronousErrorHandling) {
66
- throw err;
67
- }
68
- else {
69
- hostReportError(err);
70
- }
71
- },
72
- complete: function () { }
73
- };
74
-
75
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
76
- var isArray = /*@__PURE__*/ (function () { return Array.isArray || (function (x) { return x && typeof x.length === 'number'; }); })();
77
-
78
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
79
- function isObject(x) {
80
- return x !== null && typeof x === 'object';
81
- }
82
-
83
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
84
- var UnsubscriptionErrorImpl = /*@__PURE__*/ (function () {
85
- function UnsubscriptionErrorImpl(errors) {
86
- Error.call(this);
87
- this.message = errors ?
88
- errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ') : '';
89
- this.name = 'UnsubscriptionError';
90
- this.errors = errors;
91
- return this;
92
- }
93
- UnsubscriptionErrorImpl.prototype = /*@__PURE__*/ Object.create(Error.prototype);
94
- return UnsubscriptionErrorImpl;
95
- })();
96
- var UnsubscriptionError = UnsubscriptionErrorImpl;
97
-
98
- /** PURE_IMPORTS_START _util_isArray,_util_isObject,_util_isFunction,_util_UnsubscriptionError PURE_IMPORTS_END */
99
- var Subscription = /*@__PURE__*/ (function () {
100
- function Subscription(unsubscribe) {
101
- this.closed = false;
102
- this._parentOrParents = null;
103
- this._subscriptions = null;
104
- if (unsubscribe) {
105
- this._ctorUnsubscribe = true;
106
- this._unsubscribe = unsubscribe;
107
- }
108
- }
109
- Subscription.prototype.unsubscribe = function () {
110
- var errors;
111
- if (this.closed) {
112
- return;
113
- }
114
- var _a = this, _parentOrParents = _a._parentOrParents, _ctorUnsubscribe = _a._ctorUnsubscribe, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions;
115
- this.closed = true;
116
- this._parentOrParents = null;
117
- this._subscriptions = null;
118
- if (_parentOrParents instanceof Subscription) {
119
- _parentOrParents.remove(this);
120
- }
121
- else if (_parentOrParents !== null) {
122
- for (var index = 0; index < _parentOrParents.length; ++index) {
123
- var parent_1 = _parentOrParents[index];
124
- parent_1.remove(this);
125
- }
126
- }
127
- if (isFunction(_unsubscribe)) {
128
- if (_ctorUnsubscribe) {
129
- this._unsubscribe = undefined;
130
- }
131
- try {
132
- _unsubscribe.call(this);
133
- }
134
- catch (e) {
135
- errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e];
136
- }
137
- }
138
- if (isArray(_subscriptions)) {
139
- var index = -1;
140
- var len = _subscriptions.length;
141
- while (++index < len) {
142
- var sub = _subscriptions[index];
143
- if (isObject(sub)) {
144
- try {
145
- sub.unsubscribe();
146
- }
147
- catch (e) {
148
- errors = errors || [];
149
- if (e instanceof UnsubscriptionError) {
150
- errors = errors.concat(flattenUnsubscriptionErrors(e.errors));
151
- }
152
- else {
153
- errors.push(e);
154
- }
155
- }
156
- }
157
- }
158
- }
159
- if (errors) {
160
- throw new UnsubscriptionError(errors);
161
- }
162
- };
163
- Subscription.prototype.add = function (teardown) {
164
- var subscription = teardown;
165
- if (!teardown) {
166
- return Subscription.EMPTY;
167
- }
168
- switch (typeof teardown) {
169
- case 'function':
170
- subscription = new Subscription(teardown);
171
- case 'object':
172
- if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== 'function') {
173
- return subscription;
174
- }
175
- else if (this.closed) {
176
- subscription.unsubscribe();
177
- return subscription;
178
- }
179
- else if (!(subscription instanceof Subscription)) {
180
- var tmp = subscription;
181
- subscription = new Subscription();
182
- subscription._subscriptions = [tmp];
183
- }
184
- break;
185
- default: {
186
- throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');
187
- }
188
- }
189
- var _parentOrParents = subscription._parentOrParents;
190
- if (_parentOrParents === null) {
191
- subscription._parentOrParents = this;
192
- }
193
- else if (_parentOrParents instanceof Subscription) {
194
- if (_parentOrParents === this) {
195
- return subscription;
196
- }
197
- subscription._parentOrParents = [_parentOrParents, this];
198
- }
199
- else if (_parentOrParents.indexOf(this) === -1) {
200
- _parentOrParents.push(this);
201
- }
202
- else {
203
- return subscription;
204
- }
205
- var subscriptions = this._subscriptions;
206
- if (subscriptions === null) {
207
- this._subscriptions = [subscription];
208
- }
209
- else {
210
- subscriptions.push(subscription);
211
- }
212
- return subscription;
213
- };
214
- Subscription.prototype.remove = function (subscription) {
215
- var subscriptions = this._subscriptions;
216
- if (subscriptions) {
217
- var subscriptionIndex = subscriptions.indexOf(subscription);
218
- if (subscriptionIndex !== -1) {
219
- subscriptions.splice(subscriptionIndex, 1);
220
- }
221
- }
222
- };
223
- Subscription.EMPTY = (function (empty) {
224
- empty.closed = true;
225
- return empty;
226
- }(new Subscription()));
227
- return Subscription;
228
- }());
229
- function flattenUnsubscriptionErrors(errors) {
230
- return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError) ? err.errors : err); }, []);
231
- }
232
-
233
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
234
- var rxSubscriber = /*@__PURE__*/ (function () {
235
- return typeof Symbol === 'function'
236
- ? /*@__PURE__*/ Symbol('rxSubscriber')
237
- : '@@rxSubscriber_' + /*@__PURE__*/ Math.random();
238
- })();
239
-
240
- /** PURE_IMPORTS_START tslib,_util_isFunction,_Observer,_Subscription,_internal_symbol_rxSubscriber,_config,_util_hostReportError PURE_IMPORTS_END */
241
- var Subscriber = /*@__PURE__*/ (function (_super) {
242
- __extends(Subscriber, _super);
243
- function Subscriber(destinationOrNext, error, complete) {
244
- var _this = _super.call(this) || this;
245
- _this.syncErrorValue = null;
246
- _this.syncErrorThrown = false;
247
- _this.syncErrorThrowable = false;
248
- _this.isStopped = false;
249
- switch (arguments.length) {
250
- case 0:
251
- _this.destination = empty$1;
252
- break;
253
- case 1:
254
- if (!destinationOrNext) {
255
- _this.destination = empty$1;
256
- break;
257
- }
258
- if (typeof destinationOrNext === 'object') {
259
- if (destinationOrNext instanceof Subscriber) {
260
- _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;
261
- _this.destination = destinationOrNext;
262
- destinationOrNext.add(_this);
263
- }
264
- else {
265
- _this.syncErrorThrowable = true;
266
- _this.destination = new SafeSubscriber(_this, destinationOrNext);
267
- }
268
- break;
269
- }
270
- default:
271
- _this.syncErrorThrowable = true;
272
- _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete);
273
- break;
274
- }
275
- return _this;
276
- }
277
- Subscriber.prototype[rxSubscriber] = function () { return this; };
278
- Subscriber.create = function (next, error, complete) {
279
- var subscriber = new Subscriber(next, error, complete);
280
- subscriber.syncErrorThrowable = false;
281
- return subscriber;
282
- };
283
- Subscriber.prototype.next = function (value) {
284
- if (!this.isStopped) {
285
- this._next(value);
286
- }
287
- };
288
- Subscriber.prototype.error = function (err) {
289
- if (!this.isStopped) {
290
- this.isStopped = true;
291
- this._error(err);
292
- }
293
- };
294
- Subscriber.prototype.complete = function () {
295
- if (!this.isStopped) {
296
- this.isStopped = true;
297
- this._complete();
298
- }
299
- };
300
- Subscriber.prototype.unsubscribe = function () {
301
- if (this.closed) {
302
- return;
303
- }
304
- this.isStopped = true;
305
- _super.prototype.unsubscribe.call(this);
306
- };
307
- Subscriber.prototype._next = function (value) {
308
- this.destination.next(value);
309
- };
310
- Subscriber.prototype._error = function (err) {
311
- this.destination.error(err);
312
- this.unsubscribe();
313
- };
314
- Subscriber.prototype._complete = function () {
315
- this.destination.complete();
316
- this.unsubscribe();
317
- };
318
- Subscriber.prototype._unsubscribeAndRecycle = function () {
319
- var _parentOrParents = this._parentOrParents;
320
- this._parentOrParents = null;
321
- this.unsubscribe();
322
- this.closed = false;
323
- this.isStopped = false;
324
- this._parentOrParents = _parentOrParents;
325
- return this;
326
- };
327
- return Subscriber;
328
- }(Subscription));
329
- var SafeSubscriber = /*@__PURE__*/ (function (_super) {
330
- __extends(SafeSubscriber, _super);
331
- function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) {
332
- var _this = _super.call(this) || this;
333
- _this._parentSubscriber = _parentSubscriber;
334
- var next;
335
- var context = _this;
336
- if (isFunction(observerOrNext)) {
337
- next = observerOrNext;
338
- }
339
- else if (observerOrNext) {
340
- next = observerOrNext.next;
341
- error = observerOrNext.error;
342
- complete = observerOrNext.complete;
343
- if (observerOrNext !== empty$1) {
344
- context = Object.create(observerOrNext);
345
- if (isFunction(context.unsubscribe)) {
346
- _this.add(context.unsubscribe.bind(context));
347
- }
348
- context.unsubscribe = _this.unsubscribe.bind(_this);
349
- }
350
- }
351
- _this._context = context;
352
- _this._next = next;
353
- _this._error = error;
354
- _this._complete = complete;
355
- return _this;
356
- }
357
- SafeSubscriber.prototype.next = function (value) {
358
- if (!this.isStopped && this._next) {
359
- var _parentSubscriber = this._parentSubscriber;
360
- if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
361
- this.__tryOrUnsub(this._next, value);
362
- }
363
- else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {
364
- this.unsubscribe();
365
- }
366
- }
367
- };
368
- SafeSubscriber.prototype.error = function (err) {
369
- if (!this.isStopped) {
370
- var _parentSubscriber = this._parentSubscriber;
371
- var useDeprecatedSynchronousErrorHandling = config.useDeprecatedSynchronousErrorHandling;
372
- if (this._error) {
373
- if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
374
- this.__tryOrUnsub(this._error, err);
375
- this.unsubscribe();
376
- }
377
- else {
378
- this.__tryOrSetError(_parentSubscriber, this._error, err);
379
- this.unsubscribe();
380
- }
381
- }
382
- else if (!_parentSubscriber.syncErrorThrowable) {
383
- this.unsubscribe();
384
- if (useDeprecatedSynchronousErrorHandling) {
385
- throw err;
386
- }
387
- hostReportError(err);
388
- }
389
- else {
390
- if (useDeprecatedSynchronousErrorHandling) {
391
- _parentSubscriber.syncErrorValue = err;
392
- _parentSubscriber.syncErrorThrown = true;
393
- }
394
- else {
395
- hostReportError(err);
396
- }
397
- this.unsubscribe();
398
- }
399
- }
400
- };
401
- SafeSubscriber.prototype.complete = function () {
402
- var _this = this;
403
- if (!this.isStopped) {
404
- var _parentSubscriber = this._parentSubscriber;
405
- if (this._complete) {
406
- var wrappedComplete = function () { return _this._complete.call(_this._context); };
407
- if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
408
- this.__tryOrUnsub(wrappedComplete);
409
- this.unsubscribe();
410
- }
411
- else {
412
- this.__tryOrSetError(_parentSubscriber, wrappedComplete);
413
- this.unsubscribe();
414
- }
415
- }
416
- else {
417
- this.unsubscribe();
418
- }
419
- }
420
- };
421
- SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {
422
- try {
423
- fn.call(this._context, value);
424
- }
425
- catch (err) {
426
- this.unsubscribe();
427
- if (config.useDeprecatedSynchronousErrorHandling) {
428
- throw err;
429
- }
430
- else {
431
- hostReportError(err);
432
- }
433
- }
434
- };
435
- SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) {
436
- if (!config.useDeprecatedSynchronousErrorHandling) {
437
- throw new Error('bad call');
438
- }
439
- try {
440
- fn.call(this._context, value);
441
- }
442
- catch (err) {
443
- if (config.useDeprecatedSynchronousErrorHandling) {
444
- parent.syncErrorValue = err;
445
- parent.syncErrorThrown = true;
446
- return true;
447
- }
448
- else {
449
- hostReportError(err);
450
- return true;
451
- }
452
- }
453
- return false;
454
- };
455
- SafeSubscriber.prototype._unsubscribe = function () {
456
- var _parentSubscriber = this._parentSubscriber;
457
- this._context = null;
458
- this._parentSubscriber = null;
459
- _parentSubscriber.unsubscribe();
460
- };
461
- return SafeSubscriber;
462
- }(Subscriber));
463
-
464
- /** PURE_IMPORTS_START _Subscriber PURE_IMPORTS_END */
465
- function canReportError(observer) {
466
- while (observer) {
467
- var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped;
468
- if (closed_1 || isStopped) {
469
- return false;
470
- }
471
- else if (destination && destination instanceof Subscriber) {
472
- observer = destination;
473
- }
474
- else {
475
- observer = null;
476
- }
477
- }
478
- return true;
479
- }
480
-
481
- /** PURE_IMPORTS_START _Subscriber,_symbol_rxSubscriber,_Observer PURE_IMPORTS_END */
482
- function toSubscriber(nextOrObserver, error, complete) {
483
- if (nextOrObserver) {
484
- if (nextOrObserver instanceof Subscriber) {
485
- return nextOrObserver;
486
- }
487
- if (nextOrObserver[rxSubscriber]) {
488
- return nextOrObserver[rxSubscriber]();
489
- }
490
- }
491
- if (!nextOrObserver && !error && !complete) {
492
- return new Subscriber(empty$1);
493
- }
494
- return new Subscriber(nextOrObserver, error, complete);
495
- }
496
-
497
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
498
- var observable = /*@__PURE__*/ (function () { return typeof Symbol === 'function' && Symbol.observable || '@@observable'; })();
499
-
500
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
501
- function identity(x) {
502
- return x;
503
- }
504
-
505
- /** PURE_IMPORTS_START _identity PURE_IMPORTS_END */
506
- function pipeFromArray(fns) {
507
- if (fns.length === 0) {
508
- return identity;
509
- }
510
- if (fns.length === 1) {
511
- return fns[0];
512
- }
513
- return function piped(input) {
514
- return fns.reduce(function (prev, fn) { return fn(prev); }, input);
515
- };
516
- }
517
-
518
- /** PURE_IMPORTS_START _util_canReportError,_util_toSubscriber,_symbol_observable,_util_pipe,_config PURE_IMPORTS_END */
519
- var Observable = /*@__PURE__*/ (function () {
520
- function Observable(subscribe) {
521
- this._isScalar = false;
522
- if (subscribe) {
523
- this._subscribe = subscribe;
524
- }
525
- }
526
- Observable.prototype.lift = function (operator) {
527
- var observable = new Observable();
528
- observable.source = this;
529
- observable.operator = operator;
530
- return observable;
531
- };
532
- Observable.prototype.subscribe = function (observerOrNext, error, complete) {
533
- var operator = this.operator;
534
- var sink = toSubscriber(observerOrNext, error, complete);
535
- if (operator) {
536
- sink.add(operator.call(sink, this.source));
537
- }
538
- else {
539
- sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?
540
- this._subscribe(sink) :
541
- this._trySubscribe(sink));
542
- }
543
- if (config.useDeprecatedSynchronousErrorHandling) {
544
- if (sink.syncErrorThrowable) {
545
- sink.syncErrorThrowable = false;
546
- if (sink.syncErrorThrown) {
547
- throw sink.syncErrorValue;
548
- }
549
- }
550
- }
551
- return sink;
552
- };
553
- Observable.prototype._trySubscribe = function (sink) {
554
- try {
555
- return this._subscribe(sink);
556
- }
557
- catch (err) {
558
- if (config.useDeprecatedSynchronousErrorHandling) {
559
- sink.syncErrorThrown = true;
560
- sink.syncErrorValue = err;
561
- }
562
- if (canReportError(sink)) {
563
- sink.error(err);
564
- }
565
- else {
566
- console.warn(err);
567
- }
568
- }
569
- };
570
- Observable.prototype.forEach = function (next, promiseCtor) {
571
- var _this = this;
572
- promiseCtor = getPromiseCtor(promiseCtor);
573
- return new promiseCtor(function (resolve, reject) {
574
- var subscription;
575
- subscription = _this.subscribe(function (value) {
576
- try {
577
- next(value);
578
- }
579
- catch (err) {
580
- reject(err);
581
- if (subscription) {
582
- subscription.unsubscribe();
583
- }
584
- }
585
- }, reject, resolve);
586
- });
587
- };
588
- Observable.prototype._subscribe = function (subscriber) {
589
- var source = this.source;
590
- return source && source.subscribe(subscriber);
591
- };
592
- Observable.prototype[observable] = function () {
593
- return this;
594
- };
595
- Observable.prototype.pipe = function () {
596
- var operations = [];
597
- for (var _i = 0; _i < arguments.length; _i++) {
598
- operations[_i] = arguments[_i];
599
- }
600
- if (operations.length === 0) {
601
- return this;
602
- }
603
- return pipeFromArray(operations)(this);
604
- };
605
- Observable.prototype.toPromise = function (promiseCtor) {
606
- var _this = this;
607
- promiseCtor = getPromiseCtor(promiseCtor);
608
- return new promiseCtor(function (resolve, reject) {
609
- var value;
610
- _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); });
611
- });
612
- };
613
- Observable.create = function (subscribe) {
614
- return new Observable(subscribe);
615
- };
616
- return Observable;
617
- }());
618
- function getPromiseCtor(promiseCtor) {
619
- if (!promiseCtor) {
620
- promiseCtor = Promise;
621
- }
622
- if (!promiseCtor) {
623
- throw new Error('no Promise impl found');
624
- }
625
- return promiseCtor;
626
- }
627
-
628
- /** PURE_IMPORTS_START _Observable PURE_IMPORTS_END */
629
- var EMPTY = /*@__PURE__*/ new Observable(function (subscriber) { return subscriber.complete(); });
630
- function empty(scheduler) {
631
- return scheduler ? emptyScheduled(scheduler) : EMPTY;
632
- }
633
- function emptyScheduled(scheduler) {
634
- return new Observable(function (subscriber) { return scheduler.schedule(function () { return subscriber.complete(); }); });
635
- }
636
-
637
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
638
- function isScheduler(value) {
639
- return value && typeof value.schedule === 'function';
640
- }
641
-
642
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
643
- var subscribeToArray = function (array) {
644
- return function (subscriber) {
645
- for (var i = 0, len = array.length; i < len && !subscriber.closed; i++) {
646
- subscriber.next(array[i]);
647
- }
648
- subscriber.complete();
649
- };
650
- };
651
-
652
- /** PURE_IMPORTS_START _Observable,_Subscription PURE_IMPORTS_END */
653
- function scheduleArray(input, scheduler) {
654
- return new Observable(function (subscriber) {
655
- var sub = new Subscription();
656
- var i = 0;
657
- sub.add(scheduler.schedule(function () {
658
- if (i === input.length) {
659
- subscriber.complete();
660
- return;
661
- }
662
- subscriber.next(input[i++]);
663
- if (!subscriber.closed) {
664
- sub.add(this.schedule());
665
- }
666
- }));
667
- return sub;
668
- });
669
- }
670
-
671
- /** PURE_IMPORTS_START _Observable,_util_subscribeToArray,_scheduled_scheduleArray PURE_IMPORTS_END */
672
- function fromArray(input, scheduler) {
673
- if (!scheduler) {
674
- return new Observable(subscribeToArray(input));
675
- }
676
- else {
677
- return scheduleArray(input, scheduler);
678
- }
679
- }
680
-
681
- /** PURE_IMPORTS_START _util_isScheduler,_fromArray,_scheduled_scheduleArray PURE_IMPORTS_END */
682
- function of() {
683
- var args = [];
684
- for (var _i = 0; _i < arguments.length; _i++) {
685
- args[_i] = arguments[_i];
686
- }
687
- var scheduler = args[args.length - 1];
688
- if (isScheduler(scheduler)) {
689
- args.pop();
690
- return scheduleArray(args, scheduler);
691
- }
692
- else {
693
- return fromArray(args);
694
- }
695
- }
696
-
697
- /** PURE_IMPORTS_START _Observable PURE_IMPORTS_END */
698
- function throwError(error, scheduler) {
699
- if (!scheduler) {
700
- return new Observable(function (subscriber) { return subscriber.error(error); });
701
- }
702
- else {
703
- return new Observable(function (subscriber) { return scheduler.schedule(dispatch, 0, { error: error, subscriber: subscriber }); });
704
- }
705
- }
706
- function dispatch(_a) {
707
- var error = _a.error, subscriber = _a.subscriber;
708
- subscriber.error(error);
709
- }
710
-
711
- /** PURE_IMPORTS_START _observable_empty,_observable_of,_observable_throwError PURE_IMPORTS_END */
712
- var Notification = /*@__PURE__*/ (function () {
713
- function Notification(kind, value, error) {
714
- this.kind = kind;
715
- this.value = value;
716
- this.error = error;
717
- this.hasValue = kind === 'N';
718
- }
719
- Notification.prototype.observe = function (observer) {
720
- switch (this.kind) {
721
- case 'N':
722
- return observer.next && observer.next(this.value);
723
- case 'E':
724
- return observer.error && observer.error(this.error);
725
- case 'C':
726
- return observer.complete && observer.complete();
727
- }
728
- };
729
- Notification.prototype.do = function (next, error, complete) {
730
- var kind = this.kind;
731
- switch (kind) {
732
- case 'N':
733
- return next && next(this.value);
734
- case 'E':
735
- return error && error(this.error);
736
- case 'C':
737
- return complete && complete();
738
- }
739
- };
740
- Notification.prototype.accept = function (nextOrObserver, error, complete) {
741
- if (nextOrObserver && typeof nextOrObserver.next === 'function') {
742
- return this.observe(nextOrObserver);
743
- }
744
- else {
745
- return this.do(nextOrObserver, error, complete);
746
- }
747
- };
748
- Notification.prototype.toObservable = function () {
749
- var kind = this.kind;
750
- switch (kind) {
751
- case 'N':
752
- return of(this.value);
753
- case 'E':
754
- return throwError(this.error);
755
- case 'C':
756
- return empty();
757
- }
758
- throw new Error('unexpected notification kind value');
759
- };
760
- Notification.createNext = function (value) {
761
- if (typeof value !== 'undefined') {
762
- return new Notification('N', value);
763
- }
764
- return Notification.undefinedValueNotification;
765
- };
766
- Notification.createError = function (err) {
767
- return new Notification('E', undefined, err);
768
- };
769
- Notification.createComplete = function () {
770
- return Notification.completeNotification;
771
- };
772
- Notification.completeNotification = new Notification('C');
773
- Notification.undefinedValueNotification = new Notification('N', undefined);
774
- return Notification;
775
- }());
776
-
777
- var SubscriptionLog = /*@__PURE__*/ (function () {
778
- function SubscriptionLog(subscribedFrame, unsubscribedFrame) {
779
- if (unsubscribedFrame === void 0) {
780
- unsubscribedFrame = Number.POSITIVE_INFINITY;
781
- }
782
- this.subscribedFrame = subscribedFrame;
783
- this.unsubscribedFrame = unsubscribedFrame;
784
- }
785
- return SubscriptionLog;
786
- }());
787
-
788
- /** PURE_IMPORTS_START tslib,_Observable,_Subscription,_SubscriptionLoggable,_util_applyMixins PURE_IMPORTS_END */
789
- var ColdObservable = /*@__PURE__*/ (function (_super) {
790
- __extends(ColdObservable, _super);
791
- function ColdObservable(messages, scheduler) {
792
- var _this = _super.call(this, function (subscriber) {
793
- var observable = this;
794
- var index = observable.logSubscribedFrame();
795
- var subscription = new Subscription();
796
- subscription.add(new Subscription(function () {
797
- observable.logUnsubscribedFrame(index);
798
- }));
799
- observable.scheduleMessages(subscriber);
800
- return subscription;
801
- }) || this;
802
- _this.messages = messages;
803
- _this.subscriptions = [];
804
- _this.scheduler = scheduler;
805
- return _this;
806
- }
807
- ColdObservable.prototype.scheduleMessages = function (subscriber) {
808
- var messagesLength = this.messages.length;
809
- for (var i = 0; i < messagesLength; i++) {
810
- var message = this.messages[i];
811
- subscriber.add(this.scheduler.schedule(function (_a) {
812
- var message = _a.message, subscriber = _a.subscriber;
813
- message.notification.observe(subscriber);
814
- }, message.frame, { message: message, subscriber: subscriber }));
815
- }
816
- };
817
- return ColdObservable;
818
- }(Observable));
819
-
820
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
821
- var ObjectUnsubscribedErrorImpl = /*@__PURE__*/ (function () {
822
- function ObjectUnsubscribedErrorImpl() {
823
- Error.call(this);
824
- this.message = 'object unsubscribed';
825
- this.name = 'ObjectUnsubscribedError';
826
- return this;
827
- }
828
- ObjectUnsubscribedErrorImpl.prototype = /*@__PURE__*/ Object.create(Error.prototype);
829
- return ObjectUnsubscribedErrorImpl;
830
- })();
831
- var ObjectUnsubscribedError = ObjectUnsubscribedErrorImpl;
832
-
833
- /** PURE_IMPORTS_START tslib,_Subscription PURE_IMPORTS_END */
834
- var SubjectSubscription = /*@__PURE__*/ (function (_super) {
835
- __extends(SubjectSubscription, _super);
836
- function SubjectSubscription(subject, subscriber) {
837
- var _this = _super.call(this) || this;
838
- _this.subject = subject;
839
- _this.subscriber = subscriber;
840
- _this.closed = false;
841
- return _this;
842
- }
843
- SubjectSubscription.prototype.unsubscribe = function () {
844
- if (this.closed) {
845
- return;
846
- }
847
- this.closed = true;
848
- var subject = this.subject;
849
- var observers = subject.observers;
850
- this.subject = null;
851
- if (!observers || observers.length === 0 || subject.isStopped || subject.closed) {
852
- return;
853
- }
854
- var subscriberIndex = observers.indexOf(this.subscriber);
855
- if (subscriberIndex !== -1) {
856
- observers.splice(subscriberIndex, 1);
857
- }
858
- };
859
- return SubjectSubscription;
860
- }(Subscription));
861
-
862
- /** PURE_IMPORTS_START tslib,_Observable,_Subscriber,_Subscription,_util_ObjectUnsubscribedError,_SubjectSubscription,_internal_symbol_rxSubscriber PURE_IMPORTS_END */
863
- var SubjectSubscriber = /*@__PURE__*/ (function (_super) {
864
- __extends(SubjectSubscriber, _super);
865
- function SubjectSubscriber(destination) {
866
- var _this = _super.call(this, destination) || this;
867
- _this.destination = destination;
868
- return _this;
869
- }
870
- return SubjectSubscriber;
871
- }(Subscriber));
872
- var Subject = /*@__PURE__*/ (function (_super) {
873
- __extends(Subject, _super);
874
- function Subject() {
875
- var _this = _super.call(this) || this;
876
- _this.observers = [];
877
- _this.closed = false;
878
- _this.isStopped = false;
879
- _this.hasError = false;
880
- _this.thrownError = null;
881
- return _this;
882
- }
883
- Subject.prototype[rxSubscriber] = function () {
884
- return new SubjectSubscriber(this);
885
- };
886
- Subject.prototype.lift = function (operator) {
887
- var subject = new AnonymousSubject(this, this);
888
- subject.operator = operator;
889
- return subject;
890
- };
891
- Subject.prototype.next = function (value) {
892
- if (this.closed) {
893
- throw new ObjectUnsubscribedError();
894
- }
895
- if (!this.isStopped) {
896
- var observers = this.observers;
897
- var len = observers.length;
898
- var copy = observers.slice();
899
- for (var i = 0; i < len; i++) {
900
- copy[i].next(value);
901
- }
902
- }
903
- };
904
- Subject.prototype.error = function (err) {
905
- if (this.closed) {
906
- throw new ObjectUnsubscribedError();
907
- }
908
- this.hasError = true;
909
- this.thrownError = err;
910
- this.isStopped = true;
911
- var observers = this.observers;
912
- var len = observers.length;
913
- var copy = observers.slice();
914
- for (var i = 0; i < len; i++) {
915
- copy[i].error(err);
916
- }
917
- this.observers.length = 0;
918
- };
919
- Subject.prototype.complete = function () {
920
- if (this.closed) {
921
- throw new ObjectUnsubscribedError();
922
- }
923
- this.isStopped = true;
924
- var observers = this.observers;
925
- var len = observers.length;
926
- var copy = observers.slice();
927
- for (var i = 0; i < len; i++) {
928
- copy[i].complete();
929
- }
930
- this.observers.length = 0;
931
- };
932
- Subject.prototype.unsubscribe = function () {
933
- this.isStopped = true;
934
- this.closed = true;
935
- this.observers = null;
936
- };
937
- Subject.prototype._trySubscribe = function (subscriber) {
938
- if (this.closed) {
939
- throw new ObjectUnsubscribedError();
940
- }
941
- else {
942
- return _super.prototype._trySubscribe.call(this, subscriber);
943
- }
944
- };
945
- Subject.prototype._subscribe = function (subscriber) {
946
- if (this.closed) {
947
- throw new ObjectUnsubscribedError();
948
- }
949
- else if (this.hasError) {
950
- subscriber.error(this.thrownError);
951
- return Subscription.EMPTY;
952
- }
953
- else if (this.isStopped) {
954
- subscriber.complete();
955
- return Subscription.EMPTY;
956
- }
957
- else {
958
- this.observers.push(subscriber);
959
- return new SubjectSubscription(this, subscriber);
960
- }
961
- };
962
- Subject.prototype.asObservable = function () {
963
- var observable = new Observable();
964
- observable.source = this;
965
- return observable;
966
- };
967
- Subject.create = function (destination, source) {
968
- return new AnonymousSubject(destination, source);
969
- };
970
- return Subject;
971
- }(Observable));
972
- var AnonymousSubject = /*@__PURE__*/ (function (_super) {
973
- __extends(AnonymousSubject, _super);
974
- function AnonymousSubject(destination, source) {
975
- var _this = _super.call(this) || this;
976
- _this.destination = destination;
977
- _this.source = source;
978
- return _this;
979
- }
980
- AnonymousSubject.prototype.next = function (value) {
981
- var destination = this.destination;
982
- if (destination && destination.next) {
983
- destination.next(value);
984
- }
985
- };
986
- AnonymousSubject.prototype.error = function (err) {
987
- var destination = this.destination;
988
- if (destination && destination.error) {
989
- this.destination.error(err);
990
- }
991
- };
992
- AnonymousSubject.prototype.complete = function () {
993
- var destination = this.destination;
994
- if (destination && destination.complete) {
995
- this.destination.complete();
996
- }
997
- };
998
- AnonymousSubject.prototype._subscribe = function (subscriber) {
999
- var source = this.source;
1000
- if (source) {
1001
- return this.source.subscribe(subscriber);
1002
- }
1003
- else {
1004
- return Subscription.EMPTY;
1005
- }
1006
- };
1007
- return AnonymousSubject;
1008
- }(Subject));
1009
-
1010
- /** PURE_IMPORTS_START tslib,_Subject,_Subscription,_SubscriptionLoggable,_util_applyMixins PURE_IMPORTS_END */
1011
- var HotObservable = /*@__PURE__*/ (function (_super) {
1012
- __extends(HotObservable, _super);
1013
- function HotObservable(messages, scheduler) {
1014
- var _this = _super.call(this) || this;
1015
- _this.messages = messages;
1016
- _this.subscriptions = [];
1017
- _this.scheduler = scheduler;
1018
- return _this;
1019
- }
1020
- HotObservable.prototype._subscribe = function (subscriber) {
1021
- var subject = this;
1022
- var index = subject.logSubscribedFrame();
1023
- var subscription = new Subscription();
1024
- subscription.add(new Subscription(function () {
1025
- subject.logUnsubscribedFrame(index);
1026
- }));
1027
- subscription.add(_super.prototype._subscribe.call(this, subscriber));
1028
- return subscription;
1029
- };
1030
- HotObservable.prototype.setup = function () {
1031
- var subject = this;
1032
- var messagesLength = subject.messages.length;
1033
- for (var i = 0; i < messagesLength; i++) {
1034
- (function () {
1035
- var message = subject.messages[i];
1036
- subject.scheduler.schedule(function () { message.notification.observe(subject); }, message.frame);
1037
- })();
1038
- }
1039
- };
1040
- return HotObservable;
1041
- }(Subject));
1042
-
1043
- /** PURE_IMPORTS_START tslib,_Subscription PURE_IMPORTS_END */
1044
- var Action = /*@__PURE__*/ (function (_super) {
1045
- __extends(Action, _super);
1046
- function Action(scheduler, work) {
1047
- return _super.call(this) || this;
1048
- }
1049
- Action.prototype.schedule = function (state, delay) {
1050
- return this;
1051
- };
1052
- return Action;
1053
- }(Subscription));
1054
-
1055
- /** PURE_IMPORTS_START tslib,_Action PURE_IMPORTS_END */
1056
- var AsyncAction = /*@__PURE__*/ (function (_super) {
1057
- __extends(AsyncAction, _super);
1058
- function AsyncAction(scheduler, work) {
1059
- var _this = _super.call(this, scheduler, work) || this;
1060
- _this.scheduler = scheduler;
1061
- _this.work = work;
1062
- _this.pending = false;
1063
- return _this;
1064
- }
1065
- AsyncAction.prototype.schedule = function (state, delay) {
1066
- if (delay === void 0) {
1067
- delay = 0;
1068
- }
1069
- if (this.closed) {
1070
- return this;
1071
- }
1072
- this.state = state;
1073
- var id = this.id;
1074
- var scheduler = this.scheduler;
1075
- if (id != null) {
1076
- this.id = this.recycleAsyncId(scheduler, id, delay);
1077
- }
1078
- this.pending = true;
1079
- this.delay = delay;
1080
- this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
1081
- return this;
1082
- };
1083
- AsyncAction.prototype.requestAsyncId = function (scheduler, id, delay) {
1084
- if (delay === void 0) {
1085
- delay = 0;
1086
- }
1087
- return setInterval(scheduler.flush.bind(scheduler, this), delay);
1088
- };
1089
- AsyncAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
1090
- if (delay === void 0) {
1091
- delay = 0;
1092
- }
1093
- if (delay !== null && this.delay === delay && this.pending === false) {
1094
- return id;
1095
- }
1096
- clearInterval(id);
1097
- return undefined;
1098
- };
1099
- AsyncAction.prototype.execute = function (state, delay) {
1100
- if (this.closed) {
1101
- return new Error('executing a cancelled action');
1102
- }
1103
- this.pending = false;
1104
- var error = this._execute(state, delay);
1105
- if (error) {
1106
- return error;
1107
- }
1108
- else if (this.pending === false && this.id != null) {
1109
- this.id = this.recycleAsyncId(this.scheduler, this.id, null);
1110
- }
1111
- };
1112
- AsyncAction.prototype._execute = function (state, delay) {
1113
- var errored = false;
1114
- var errorValue = undefined;
1115
- try {
1116
- this.work(state);
1117
- }
1118
- catch (e) {
1119
- errored = true;
1120
- errorValue = !!e && e || new Error(e);
1121
- }
1122
- if (errored) {
1123
- this.unsubscribe();
1124
- return errorValue;
1125
- }
1126
- };
1127
- AsyncAction.prototype._unsubscribe = function () {
1128
- var id = this.id;
1129
- var scheduler = this.scheduler;
1130
- var actions = scheduler.actions;
1131
- var index = actions.indexOf(this);
1132
- this.work = null;
1133
- this.state = null;
1134
- this.pending = false;
1135
- this.scheduler = null;
1136
- if (index !== -1) {
1137
- actions.splice(index, 1);
1138
- }
1139
- if (id != null) {
1140
- this.id = this.recycleAsyncId(scheduler, id, null);
1141
- }
1142
- this.delay = null;
1143
- };
1144
- return AsyncAction;
1145
- }(Action));
1146
-
1147
- var Scheduler = /*@__PURE__*/ (function () {
1148
- function Scheduler(SchedulerAction, now) {
1149
- if (now === void 0) {
1150
- now = Scheduler.now;
1151
- }
1152
- this.SchedulerAction = SchedulerAction;
1153
- this.now = now;
1154
- }
1155
- Scheduler.prototype.schedule = function (work, delay, state) {
1156
- if (delay === void 0) {
1157
- delay = 0;
1158
- }
1159
- return new this.SchedulerAction(this, work).schedule(state, delay);
1160
- };
1161
- Scheduler.now = function () { return Date.now(); };
1162
- return Scheduler;
1163
- }());
1164
-
1165
- /** PURE_IMPORTS_START tslib,_Scheduler PURE_IMPORTS_END */
1166
- var AsyncScheduler = /*@__PURE__*/ (function (_super) {
1167
- __extends(AsyncScheduler, _super);
1168
- function AsyncScheduler(SchedulerAction, now) {
1169
- if (now === void 0) {
1170
- now = Scheduler.now;
1171
- }
1172
- var _this = _super.call(this, SchedulerAction, function () {
1173
- if (AsyncScheduler.delegate && AsyncScheduler.delegate !== _this) {
1174
- return AsyncScheduler.delegate.now();
1175
- }
1176
- else {
1177
- return now();
1178
- }
1179
- }) || this;
1180
- _this.actions = [];
1181
- _this.active = false;
1182
- _this.scheduled = undefined;
1183
- return _this;
1184
- }
1185
- AsyncScheduler.prototype.schedule = function (work, delay, state) {
1186
- if (delay === void 0) {
1187
- delay = 0;
1188
- }
1189
- if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {
1190
- return AsyncScheduler.delegate.schedule(work, delay, state);
1191
- }
1192
- else {
1193
- return _super.prototype.schedule.call(this, work, delay, state);
1194
- }
1195
- };
1196
- AsyncScheduler.prototype.flush = function (action) {
1197
- var actions = this.actions;
1198
- if (this.active) {
1199
- actions.push(action);
1200
- return;
1201
- }
1202
- var error;
1203
- this.active = true;
1204
- do {
1205
- if (error = action.execute(action.state, action.delay)) {
1206
- break;
1207
- }
1208
- } while (action = actions.shift());
1209
- this.active = false;
1210
- if (error) {
1211
- while (action = actions.shift()) {
1212
- action.unsubscribe();
1213
- }
1214
- throw error;
1215
- }
1216
- };
1217
- return AsyncScheduler;
1218
- }(Scheduler));
1219
-
1220
- /** PURE_IMPORTS_START tslib,_AsyncAction,_AsyncScheduler PURE_IMPORTS_END */
1221
- var VirtualTimeScheduler = /*@__PURE__*/ (function (_super) {
1222
- __extends(VirtualTimeScheduler, _super);
1223
- function VirtualTimeScheduler(SchedulerAction, maxFrames) {
1224
- if (SchedulerAction === void 0) {
1225
- SchedulerAction = VirtualAction;
1226
- }
1227
- if (maxFrames === void 0) {
1228
- maxFrames = Number.POSITIVE_INFINITY;
1229
- }
1230
- var _this = _super.call(this, SchedulerAction, function () { return _this.frame; }) || this;
1231
- _this.maxFrames = maxFrames;
1232
- _this.frame = 0;
1233
- _this.index = -1;
1234
- return _this;
1235
- }
1236
- VirtualTimeScheduler.prototype.flush = function () {
1237
- var _a = this, actions = _a.actions, maxFrames = _a.maxFrames;
1238
- var error, action;
1239
- while ((action = actions[0]) && action.delay <= maxFrames) {
1240
- actions.shift();
1241
- this.frame = action.delay;
1242
- if (error = action.execute(action.state, action.delay)) {
1243
- break;
1244
- }
1245
- }
1246
- if (error) {
1247
- while (action = actions.shift()) {
1248
- action.unsubscribe();
1249
- }
1250
- throw error;
1251
- }
1252
- };
1253
- VirtualTimeScheduler.frameTimeFactor = 10;
1254
- return VirtualTimeScheduler;
1255
- }(AsyncScheduler));
1256
- var VirtualAction = /*@__PURE__*/ (function (_super) {
1257
- __extends(VirtualAction, _super);
1258
- function VirtualAction(scheduler, work, index) {
1259
- if (index === void 0) {
1260
- index = scheduler.index += 1;
1261
- }
1262
- var _this = _super.call(this, scheduler, work) || this;
1263
- _this.scheduler = scheduler;
1264
- _this.work = work;
1265
- _this.index = index;
1266
- _this.active = true;
1267
- _this.index = scheduler.index = index;
1268
- return _this;
1269
- }
1270
- VirtualAction.prototype.schedule = function (state, delay) {
1271
- if (delay === void 0) {
1272
- delay = 0;
1273
- }
1274
- if (!this.id) {
1275
- return _super.prototype.schedule.call(this, state, delay);
1276
- }
1277
- this.active = false;
1278
- var action = new VirtualAction(this.scheduler, this.work);
1279
- this.add(action);
1280
- return action.schedule(state, delay);
1281
- };
1282
- VirtualAction.prototype.requestAsyncId = function (scheduler, id, delay) {
1283
- if (delay === void 0) {
1284
- delay = 0;
1285
- }
1286
- this.delay = scheduler.frame + delay;
1287
- var actions = scheduler.actions;
1288
- actions.push(this);
1289
- actions.sort(VirtualAction.sortActions);
1290
- return true;
1291
- };
1292
- VirtualAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
1293
- return undefined;
1294
- };
1295
- VirtualAction.prototype._execute = function (state, delay) {
1296
- if (this.active === true) {
1297
- return _super.prototype._execute.call(this, state, delay);
1298
- }
1299
- };
1300
- VirtualAction.sortActions = function (a, b) {
1301
- if (a.delay === b.delay) {
1302
- if (a.index === b.index) {
1303
- return 0;
1304
- }
1305
- else if (a.index > b.index) {
1306
- return 1;
1307
- }
1308
- else {
1309
- return -1;
1310
- }
1311
- }
1312
- else if (a.delay > b.delay) {
1313
- return 1;
1314
- }
1315
- else {
1316
- return -1;
1317
- }
1318
- };
1319
- return VirtualAction;
1320
- }(AsyncAction));
1321
-
1322
- /** PURE_IMPORTS_START tslib,_Observable,_Notification,_ColdObservable,_HotObservable,_SubscriptionLog,_scheduler_VirtualTimeScheduler,_scheduler_AsyncScheduler PURE_IMPORTS_END */
1323
- var defaultMaxFrame = 750;
1324
- var TestScheduler = /*@__PURE__*/ (function (_super) {
1325
- __extends(TestScheduler, _super);
1326
- function TestScheduler(assertDeepEqual) {
1327
- var _this = _super.call(this, VirtualAction, defaultMaxFrame) || this;
1328
- _this.assertDeepEqual = assertDeepEqual;
1329
- _this.hotObservables = [];
1330
- _this.coldObservables = [];
1331
- _this.flushTests = [];
1332
- _this.runMode = false;
1333
- return _this;
1334
- }
1335
- TestScheduler.prototype.createTime = function (marbles) {
1336
- var indexOf = marbles.indexOf('|');
1337
- if (indexOf === -1) {
1338
- throw new Error('marble diagram for time should have a completion marker "|"');
1339
- }
1340
- return indexOf * TestScheduler.frameTimeFactor;
1341
- };
1342
- TestScheduler.prototype.createColdObservable = function (marbles, values, error) {
1343
- if (marbles.indexOf('^') !== -1) {
1344
- throw new Error('cold observable cannot have subscription offset "^"');
1345
- }
1346
- if (marbles.indexOf('!') !== -1) {
1347
- throw new Error('cold observable cannot have unsubscription marker "!"');
1348
- }
1349
- var messages = TestScheduler.parseMarbles(marbles, values, error, undefined, this.runMode);
1350
- var cold = new ColdObservable(messages, this);
1351
- this.coldObservables.push(cold);
1352
- return cold;
1353
- };
1354
- TestScheduler.prototype.createHotObservable = function (marbles, values, error) {
1355
- if (marbles.indexOf('!') !== -1) {
1356
- throw new Error('hot observable cannot have unsubscription marker "!"');
1357
- }
1358
- var messages = TestScheduler.parseMarbles(marbles, values, error, undefined, this.runMode);
1359
- var subject = new HotObservable(messages, this);
1360
- this.hotObservables.push(subject);
1361
- return subject;
1362
- };
1363
- TestScheduler.prototype.materializeInnerObservable = function (observable, outerFrame) {
1364
- var _this = this;
1365
- var messages = [];
1366
- observable.subscribe(function (value) {
1367
- messages.push({ frame: _this.frame - outerFrame, notification: Notification.createNext(value) });
1368
- }, function (err) {
1369
- messages.push({ frame: _this.frame - outerFrame, notification: Notification.createError(err) });
1370
- }, function () {
1371
- messages.push({ frame: _this.frame - outerFrame, notification: Notification.createComplete() });
1372
- });
1373
- return messages;
1374
- };
1375
- TestScheduler.prototype.expectObservable = function (observable, subscriptionMarbles) {
1376
- var _this = this;
1377
- if (subscriptionMarbles === void 0) {
1378
- subscriptionMarbles = null;
1379
- }
1380
- var actual = [];
1381
- var flushTest = { actual: actual, ready: false };
1382
- var subscriptionParsed = TestScheduler.parseMarblesAsSubscriptions(subscriptionMarbles, this.runMode);
1383
- var subscriptionFrame = subscriptionParsed.subscribedFrame === Number.POSITIVE_INFINITY ?
1384
- 0 : subscriptionParsed.subscribedFrame;
1385
- var unsubscriptionFrame = subscriptionParsed.unsubscribedFrame;
1386
- var subscription;
1387
- this.schedule(function () {
1388
- subscription = observable.subscribe(function (x) {
1389
- var value = x;
1390
- if (x instanceof Observable) {
1391
- value = _this.materializeInnerObservable(value, _this.frame);
1392
- }
1393
- actual.push({ frame: _this.frame, notification: Notification.createNext(value) });
1394
- }, function (err) {
1395
- actual.push({ frame: _this.frame, notification: Notification.createError(err) });
1396
- }, function () {
1397
- actual.push({ frame: _this.frame, notification: Notification.createComplete() });
1398
- });
1399
- }, subscriptionFrame);
1400
- if (unsubscriptionFrame !== Number.POSITIVE_INFINITY) {
1401
- this.schedule(function () { return subscription.unsubscribe(); }, unsubscriptionFrame);
1402
- }
1403
- this.flushTests.push(flushTest);
1404
- var runMode = this.runMode;
1405
- return {
1406
- toBe: function (marbles, values, errorValue) {
1407
- flushTest.ready = true;
1408
- flushTest.expected = TestScheduler.parseMarbles(marbles, values, errorValue, true, runMode);
1409
- }
1410
- };
1411
- };
1412
- TestScheduler.prototype.expectSubscriptions = function (actualSubscriptionLogs) {
1413
- var flushTest = { actual: actualSubscriptionLogs, ready: false };
1414
- this.flushTests.push(flushTest);
1415
- var runMode = this.runMode;
1416
- return {
1417
- toBe: function (marbles) {
1418
- var marblesArray = (typeof marbles === 'string') ? [marbles] : marbles;
1419
- flushTest.ready = true;
1420
- flushTest.expected = marblesArray.map(function (marbles) {
1421
- return TestScheduler.parseMarblesAsSubscriptions(marbles, runMode);
1422
- });
1423
- }
1424
- };
1425
- };
1426
- TestScheduler.prototype.flush = function () {
1427
- var _this = this;
1428
- var hotObservables = this.hotObservables;
1429
- while (hotObservables.length > 0) {
1430
- hotObservables.shift().setup();
1431
- }
1432
- _super.prototype.flush.call(this);
1433
- this.flushTests = this.flushTests.filter(function (test) {
1434
- if (test.ready) {
1435
- _this.assertDeepEqual(test.actual, test.expected);
1436
- return false;
1437
- }
1438
- return true;
1439
- });
1440
- };
1441
- TestScheduler.parseMarblesAsSubscriptions = function (marbles, runMode) {
1442
- var _this = this;
1443
- if (runMode === void 0) {
1444
- runMode = false;
1445
- }
1446
- if (typeof marbles !== 'string') {
1447
- return new SubscriptionLog(Number.POSITIVE_INFINITY);
1448
- }
1449
- var len = marbles.length;
1450
- var groupStart = -1;
1451
- var subscriptionFrame = Number.POSITIVE_INFINITY;
1452
- var unsubscriptionFrame = Number.POSITIVE_INFINITY;
1453
- var frame = 0;
1454
- var _loop_1 = function (i) {
1455
- var nextFrame = frame;
1456
- var advanceFrameBy = function (count) {
1457
- nextFrame += count * _this.frameTimeFactor;
1458
- };
1459
- var c = marbles[i];
1460
- switch (c) {
1461
- case ' ':
1462
- if (!runMode) {
1463
- advanceFrameBy(1);
1464
- }
1465
- break;
1466
- case '-':
1467
- advanceFrameBy(1);
1468
- break;
1469
- case '(':
1470
- groupStart = frame;
1471
- advanceFrameBy(1);
1472
- break;
1473
- case ')':
1474
- groupStart = -1;
1475
- advanceFrameBy(1);
1476
- break;
1477
- case '^':
1478
- if (subscriptionFrame !== Number.POSITIVE_INFINITY) {
1479
- throw new Error('found a second subscription point \'^\' in a ' +
1480
- 'subscription marble diagram. There can only be one.');
1481
- }
1482
- subscriptionFrame = groupStart > -1 ? groupStart : frame;
1483
- advanceFrameBy(1);
1484
- break;
1485
- case '!':
1486
- if (unsubscriptionFrame !== Number.POSITIVE_INFINITY) {
1487
- throw new Error('found a second subscription point \'^\' in a ' +
1488
- 'subscription marble diagram. There can only be one.');
1489
- }
1490
- unsubscriptionFrame = groupStart > -1 ? groupStart : frame;
1491
- break;
1492
- default:
1493
- if (runMode && c.match(/^[0-9]$/)) {
1494
- if (i === 0 || marbles[i - 1] === ' ') {
1495
- var buffer = marbles.slice(i);
1496
- var match = buffer.match(/^([0-9]+(?:\.[0-9]+)?)(ms|s|m) /);
1497
- if (match) {
1498
- i += match[0].length - 1;
1499
- var duration = parseFloat(match[1]);
1500
- var unit = match[2];
1501
- var durationInMs = void 0;
1502
- switch (unit) {
1503
- case 'ms':
1504
- durationInMs = duration;
1505
- break;
1506
- case 's':
1507
- durationInMs = duration * 1000;
1508
- break;
1509
- case 'm':
1510
- durationInMs = duration * 1000 * 60;
1511
- break;
1512
- }
1513
- advanceFrameBy(durationInMs / this_1.frameTimeFactor);
1514
- break;
1515
- }
1516
- }
1517
- }
1518
- throw new Error('there can only be \'^\' and \'!\' markers in a ' +
1519
- 'subscription marble diagram. Found instead \'' + c + '\'.');
1520
- }
1521
- frame = nextFrame;
1522
- out_i_1 = i;
1523
- };
1524
- var this_1 = this, out_i_1;
1525
- for (var i = 0; i < len; i++) {
1526
- _loop_1(i);
1527
- i = out_i_1;
1528
- }
1529
- if (unsubscriptionFrame < 0) {
1530
- return new SubscriptionLog(subscriptionFrame);
1531
- }
1532
- else {
1533
- return new SubscriptionLog(subscriptionFrame, unsubscriptionFrame);
1534
- }
1535
- };
1536
- TestScheduler.parseMarbles = function (marbles, values, errorValue, materializeInnerObservables, runMode) {
1537
- var _this = this;
1538
- if (materializeInnerObservables === void 0) {
1539
- materializeInnerObservables = false;
1540
- }
1541
- if (runMode === void 0) {
1542
- runMode = false;
1543
- }
1544
- if (marbles.indexOf('!') !== -1) {
1545
- throw new Error('conventional marble diagrams cannot have the ' +
1546
- 'unsubscription marker "!"');
1547
- }
1548
- var len = marbles.length;
1549
- var testMessages = [];
1550
- var subIndex = runMode ? marbles.replace(/^[ ]+/, '').indexOf('^') : marbles.indexOf('^');
1551
- var frame = subIndex === -1 ? 0 : (subIndex * -this.frameTimeFactor);
1552
- var getValue = typeof values !== 'object' ?
1553
- function (x) { return x; } :
1554
- function (x) {
1555
- if (materializeInnerObservables && values[x] instanceof ColdObservable) {
1556
- return values[x].messages;
1557
- }
1558
- return values[x];
1559
- };
1560
- var groupStart = -1;
1561
- var _loop_2 = function (i) {
1562
- var nextFrame = frame;
1563
- var advanceFrameBy = function (count) {
1564
- nextFrame += count * _this.frameTimeFactor;
1565
- };
1566
- var notification = void 0;
1567
- var c = marbles[i];
1568
- switch (c) {
1569
- case ' ':
1570
- if (!runMode) {
1571
- advanceFrameBy(1);
1572
- }
1573
- break;
1574
- case '-':
1575
- advanceFrameBy(1);
1576
- break;
1577
- case '(':
1578
- groupStart = frame;
1579
- advanceFrameBy(1);
1580
- break;
1581
- case ')':
1582
- groupStart = -1;
1583
- advanceFrameBy(1);
1584
- break;
1585
- case '|':
1586
- notification = Notification.createComplete();
1587
- advanceFrameBy(1);
1588
- break;
1589
- case '^':
1590
- advanceFrameBy(1);
1591
- break;
1592
- case '#':
1593
- notification = Notification.createError(errorValue || 'error');
1594
- advanceFrameBy(1);
1595
- break;
1596
- default:
1597
- if (runMode && c.match(/^[0-9]$/)) {
1598
- if (i === 0 || marbles[i - 1] === ' ') {
1599
- var buffer = marbles.slice(i);
1600
- var match = buffer.match(/^([0-9]+(?:\.[0-9]+)?)(ms|s|m) /);
1601
- if (match) {
1602
- i += match[0].length - 1;
1603
- var duration = parseFloat(match[1]);
1604
- var unit = match[2];
1605
- var durationInMs = void 0;
1606
- switch (unit) {
1607
- case 'ms':
1608
- durationInMs = duration;
1609
- break;
1610
- case 's':
1611
- durationInMs = duration * 1000;
1612
- break;
1613
- case 'm':
1614
- durationInMs = duration * 1000 * 60;
1615
- break;
1616
- }
1617
- advanceFrameBy(durationInMs / this_2.frameTimeFactor);
1618
- break;
1619
- }
1620
- }
1621
- }
1622
- notification = Notification.createNext(getValue(c));
1623
- advanceFrameBy(1);
1624
- break;
1625
- }
1626
- if (notification) {
1627
- testMessages.push({ frame: groupStart > -1 ? groupStart : frame, notification: notification });
1628
- }
1629
- frame = nextFrame;
1630
- out_i_2 = i;
1631
- };
1632
- var this_2 = this, out_i_2;
1633
- for (var i = 0; i < len; i++) {
1634
- _loop_2(i);
1635
- i = out_i_2;
1636
- }
1637
- return testMessages;
1638
- };
1639
- TestScheduler.prototype.run = function (callback) {
1640
- var prevFrameTimeFactor = TestScheduler.frameTimeFactor;
1641
- var prevMaxFrames = this.maxFrames;
1642
- TestScheduler.frameTimeFactor = 1;
1643
- this.maxFrames = Number.POSITIVE_INFINITY;
1644
- this.runMode = true;
1645
- AsyncScheduler.delegate = this;
1646
- var helpers = {
1647
- cold: this.createColdObservable.bind(this),
1648
- hot: this.createHotObservable.bind(this),
1649
- flush: this.flush.bind(this),
1650
- expectObservable: this.expectObservable.bind(this),
1651
- expectSubscriptions: this.expectSubscriptions.bind(this),
1652
- };
1653
- try {
1654
- var ret = callback(helpers);
1655
- this.flush();
1656
- return ret;
1657
- }
1658
- finally {
1659
- TestScheduler.frameTimeFactor = prevFrameTimeFactor;
1660
- this.maxFrames = prevMaxFrames;
1661
- this.runMode = false;
1662
- AsyncScheduler.delegate = undefined;
1663
- }
1664
- };
1665
- return TestScheduler;
1666
- }(VirtualTimeScheduler));
1667
-
1668
- const parseMarbles = TestScheduler.parseMarbles.bind(TestScheduler);
1669
-
1670
- exports.parseMarbles = parseMarbles;
1671
- //# sourceMappingURL=index.js.map