From acdb99ea3f6735b1771982aeced59625cf247108 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Fri, 10 May 2019 16:36:27 +0100 Subject: [PATCH] refactor: remove toplevel property access --- .../side-effects/snapshots/esm2015/index.js | 581 ---------------- .../snapshots/esm2015/operators.js | 581 ---------------- .../side-effects/snapshots/esm5/index.js | 623 +----------------- .../side-effects/snapshots/esm5/operators.js | 623 +----------------- package-lock.json | 116 +--- package.json | 3 +- .../observable/ConnectableObservable.ts | 27 +- src/internal/observable/dom/AjaxObservable.ts | 28 +- src/internal/observable/dom/ajax.ts | 2 +- src/internal/observable/fromEvent.ts | 2 +- src/internal/symbol/observable.ts | 2 +- src/internal/symbol/rxSubscriber.ts | 4 +- src/internal/util/ArgumentOutOfRangeError.ts | 18 +- src/internal/util/EmptyError.ts | 18 +- src/internal/util/ObjectUnsubscribedError.ts | 18 +- src/internal/util/TimeoutError.ts | 18 +- src/internal/util/UnsubscriptionError.ts | 22 +- src/internal/util/isArray.ts | 2 +- tslint.json | 16 +- 19 files changed, 122 insertions(+), 2582 deletions(-) diff --git a/integration/side-effects/snapshots/esm2015/index.js b/integration/side-effects/snapshots/esm2015/index.js index 8437a2e7e38..792fba30c04 100644 --- a/integration/side-effects/snapshots/esm2015/index.js +++ b/integration/side-effects/snapshots/esm2015/index.js @@ -1,584 +1,3 @@ -function isFunction(x) { - return "function" === typeof x; -} - -let _enable_super_gross_mode_that_will_cause_bad_things = false; - -const config = { - Promise: void 0, - set useDeprecatedSynchronousErrorHandling(value) { - _enable_super_gross_mode_that_will_cause_bad_things = value; - }, - get useDeprecatedSynchronousErrorHandling() { - return _enable_super_gross_mode_that_will_cause_bad_things; - } -}; - -function hostReportError(err) { - setTimeout(() => { - throw err; - }, 0); -} - -const empty = { - closed: true, - next(value) {}, - error(err) { - if (config.useDeprecatedSynchronousErrorHandling) throw err; else hostReportError(err); - }, - complete() {} -}; - -const isArray = Array.isArray || (x => x && "number" === typeof x.length); - -function isObject(x) { - return null !== x && "object" === typeof x; -} - -function UnsubscriptionErrorImpl(errors) { - Error.call(this); - this.message = errors ? `${errors.length} errors occurred during unsubscription:\n${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join("\n ")}` : ""; - this.name = "UnsubscriptionError"; - this.errors = errors; - return this; -} - -UnsubscriptionErrorImpl.prototype = Object.create(Error.prototype); - -const UnsubscriptionError = UnsubscriptionErrorImpl; - -const Subscription = function() { - class Subscription { - constructor(unsubscribe) { - this.closed = false; - this._parentOrParents = null; - this._subscriptions = null; - if (unsubscribe) this._unsubscribe = unsubscribe; - } - unsubscribe() { - let errors; - if (this.closed) return; - let {_parentOrParents: _parentOrParents, _unsubscribe: _unsubscribe, _subscriptions: _subscriptions} = this; - this.closed = true; - this._parentOrParents = null; - this._subscriptions = null; - if (_parentOrParents instanceof Subscription) _parentOrParents.remove(this); else if (null !== _parentOrParents) for (let index = 0; index < _parentOrParents.length; ++index) { - const parent = _parentOrParents[index]; - parent.remove(this); - } - if (isFunction(_unsubscribe)) try { - _unsubscribe.call(this); - } catch (e) { - errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [ e ]; - } - if (isArray(_subscriptions)) { - let index = -1; - let len = _subscriptions.length; - while (++index < len) { - const sub = _subscriptions[index]; - if (isObject(sub)) try { - sub.unsubscribe(); - } catch (e) { - errors = errors || []; - if (e instanceof UnsubscriptionError) errors = errors.concat(flattenUnsubscriptionErrors(e.errors)); else errors.push(e); - } - } - } - if (errors) throw new UnsubscriptionError(errors); - } - add(teardown) { - let subscription = teardown; - switch (typeof teardown) { - case "function": - subscription = new Subscription(teardown); - - case "object": - if (subscription === this || subscription.closed || "function" !== typeof subscription.unsubscribe) return subscription; else if (this.closed) { - subscription.unsubscribe(); - return subscription; - } else if (!(subscription instanceof Subscription)) { - const tmp = subscription; - subscription = new Subscription(); - subscription._subscriptions = [ tmp ]; - } - break; - - default: - if (!teardown) return Subscription.EMPTY; - throw new Error("unrecognized teardown " + teardown + " added to Subscription."); - } - let {_parentOrParents: _parentOrParents} = subscription; - if (null === _parentOrParents) subscription._parentOrParents = this; else if (_parentOrParents instanceof Subscription) { - if (_parentOrParents === this) return subscription; - subscription._parentOrParents = [ _parentOrParents, this ]; - } else if (-1 === _parentOrParents.indexOf(this)) _parentOrParents.push(this); else return subscription; - const subscriptions = this._subscriptions; - if (null === subscriptions) this._subscriptions = [ subscription ]; else subscriptions.push(subscription); - return subscription; - } - remove(subscription) { - const subscriptions = this._subscriptions; - if (subscriptions) { - const subscriptionIndex = subscriptions.indexOf(subscription); - if (-1 !== subscriptionIndex) subscriptions.splice(subscriptionIndex, 1); - } - } - } - Subscription.EMPTY = function(empty) { - empty.closed = true; - return empty; - }(new Subscription()); - return Subscription; -}(); - -function flattenUnsubscriptionErrors(errors) { - return errors.reduce((errs, err) => errs.concat(err instanceof UnsubscriptionError ? err.errors : err), []); -} - -const rxSubscriber = "function" === typeof Symbol ? Symbol("rxSubscriber") : "@@rxSubscriber_" + Math.random(); - -class Subscriber extends Subscription { - constructor(destinationOrNext, error, complete) { - super(); - this.syncErrorValue = null; - this.syncErrorThrown = false; - this.syncErrorThrowable = false; - this.isStopped = false; - switch (arguments.length) { - case 0: - this.destination = empty; - break; - - case 1: - if (!destinationOrNext) { - this.destination = empty; - break; - } - if ("object" === typeof destinationOrNext) { - if (destinationOrNext instanceof Subscriber) { - this.syncErrorThrowable = destinationOrNext.syncErrorThrowable; - this.destination = destinationOrNext; - destinationOrNext.add(this); - } else { - this.syncErrorThrowable = true; - this.destination = new SafeSubscriber(this, destinationOrNext); - } - break; - } - - default: - this.syncErrorThrowable = true; - this.destination = new SafeSubscriber(this, destinationOrNext, error, complete); - break; - } - } - [rxSubscriber]() { - return this; - } - static create(next, error, complete) { - const subscriber = new Subscriber(next, error, complete); - subscriber.syncErrorThrowable = false; - return subscriber; - } - next(value) { - if (!this.isStopped) this._next(value); - } - error(err) { - if (!this.isStopped) { - this.isStopped = true; - this._error(err); - } - } - complete() { - if (!this.isStopped) { - this.isStopped = true; - this._complete(); - } - } - unsubscribe() { - if (this.closed) return; - this.isStopped = true; - super.unsubscribe(); - } - _next(value) { - this.destination.next(value); - } - _error(err) { - this.destination.error(err); - this.unsubscribe(); - } - _complete() { - this.destination.complete(); - this.unsubscribe(); - } - _unsubscribeAndRecycle() { - const {_parentOrParents: _parentOrParents} = this; - this._parentOrParents = null; - this.unsubscribe(); - this.closed = false; - this.isStopped = false; - this._parentOrParents = _parentOrParents; - return this; - } -} - -class SafeSubscriber extends Subscriber { - constructor(_parentSubscriber, observerOrNext, error, complete) { - super(); - this._parentSubscriber = _parentSubscriber; - let next; - let context = this; - if (isFunction(observerOrNext)) next = observerOrNext; else if (observerOrNext) { - next = observerOrNext.next; - error = observerOrNext.error; - complete = observerOrNext.complete; - if (observerOrNext !== empty) { - context = Object.create(observerOrNext); - if (isFunction(context.unsubscribe)) this.add(context.unsubscribe.bind(context)); - context.unsubscribe = this.unsubscribe.bind(this); - } - } - this._context = context; - this._next = next; - this._error = error; - this._complete = complete; - } - next(value) { - if (!this.isStopped && this._next) { - const {_parentSubscriber: _parentSubscriber} = this; - if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) this.__tryOrUnsub(this._next, value); else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) this.unsubscribe(); - } - } - error(err) { - if (!this.isStopped) { - const {_parentSubscriber: _parentSubscriber} = this; - const {useDeprecatedSynchronousErrorHandling: useDeprecatedSynchronousErrorHandling} = config; - if (this._error) if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { - this.__tryOrUnsub(this._error, err); - this.unsubscribe(); - } else { - this.__tryOrSetError(_parentSubscriber, this._error, err); - this.unsubscribe(); - } else if (!_parentSubscriber.syncErrorThrowable) { - this.unsubscribe(); - if (useDeprecatedSynchronousErrorHandling) throw err; - hostReportError(err); - } else { - if (useDeprecatedSynchronousErrorHandling) { - _parentSubscriber.syncErrorValue = err; - _parentSubscriber.syncErrorThrown = true; - } else hostReportError(err); - this.unsubscribe(); - } - } - } - complete() { - if (!this.isStopped) { - const {_parentSubscriber: _parentSubscriber} = this; - if (this._complete) { - const wrappedComplete = () => this._complete.call(this._context); - if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { - this.__tryOrUnsub(wrappedComplete); - this.unsubscribe(); - } else { - this.__tryOrSetError(_parentSubscriber, wrappedComplete); - this.unsubscribe(); - } - } else this.unsubscribe(); - } - } - __tryOrUnsub(fn, value) { - try { - fn.call(this._context, value); - } catch (err) { - this.unsubscribe(); - if (config.useDeprecatedSynchronousErrorHandling) throw err; else hostReportError(err); - } - } - __tryOrSetError(parent, fn, value) { - if (!config.useDeprecatedSynchronousErrorHandling) throw new Error("bad call"); - try { - fn.call(this._context, value); - } catch (err) { - if (config.useDeprecatedSynchronousErrorHandling) { - parent.syncErrorValue = err; - parent.syncErrorThrown = true; - return true; - } else { - hostReportError(err); - return true; - } - } - return false; - } - _unsubscribe() { - const {_parentSubscriber: _parentSubscriber} = this; - this._context = null; - this._parentSubscriber = null; - _parentSubscriber.unsubscribe(); - } -} - -function canReportError(observer) { - while (observer) { - const {closed: closed, destination: destination, isStopped: isStopped} = observer; - if (closed || isStopped) return false; else if (destination && destination instanceof Subscriber) observer = destination; else observer = null; - } - return true; -} - -function toSubscriber(nextOrObserver, error, complete) { - if (nextOrObserver) { - if (nextOrObserver instanceof Subscriber) return nextOrObserver; - if (nextOrObserver[rxSubscriber]) return nextOrObserver[rxSubscriber](); - } - if (!nextOrObserver && !error && !complete) return new Subscriber(empty); - return new Subscriber(nextOrObserver, error, complete); -} - -const observable = "function" === typeof Symbol && Symbol.observable || "@@observable"; - -function noop() {} - -function pipeFromArray(fns) { - if (!fns) return noop; - if (1 === fns.length) return fns[0]; - return function piped(input) { - return fns.reduce((prev, fn) => fn(prev), input); - }; -} - -const Observable = function() { - class Observable { - constructor(subscribe) { - this._isScalar = false; - if (subscribe) this._subscribe = subscribe; - } - lift(operator) { - const observable = new Observable(); - observable.source = this; - observable.operator = operator; - return observable; - } - subscribe(observerOrNext, error, complete) { - const {operator: operator} = this; - const sink = toSubscriber(observerOrNext, error, complete); - if (operator) sink.add(operator.call(sink, this.source)); else sink.add(this.source || config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable ? this._subscribe(sink) : this._trySubscribe(sink)); - if (config.useDeprecatedSynchronousErrorHandling) if (sink.syncErrorThrowable) { - sink.syncErrorThrowable = false; - if (sink.syncErrorThrown) throw sink.syncErrorValue; - } - return sink; - } - _trySubscribe(sink) { - try { - return this._subscribe(sink); - } catch (err) { - if (config.useDeprecatedSynchronousErrorHandling) { - sink.syncErrorThrown = true; - sink.syncErrorValue = err; - } - if (canReportError(sink)) sink.error(err); else console.warn(err); - } - } - forEach(next, promiseCtor) { - promiseCtor = getPromiseCtor(promiseCtor); - return new promiseCtor((resolve, reject) => { - let subscription; - subscription = this.subscribe(value => { - try { - next(value); - } catch (err) { - reject(err); - if (subscription) subscription.unsubscribe(); - } - }, reject, resolve); - }); - } - _subscribe(subscriber) { - const {source: source} = this; - return source && source.subscribe(subscriber); - } - [observable]() { - return this; - } - pipe(...operations) { - if (0 === operations.length) return this; - return pipeFromArray(operations)(this); - } - toPromise(promiseCtor) { - promiseCtor = getPromiseCtor(promiseCtor); - return new promiseCtor((resolve, reject) => { - let value; - this.subscribe(x => value = x, err => reject(err), () => resolve(value)); - }); - } - } - Observable.create = (subscribe => { - return new Observable(subscribe); - }); - return Observable; -}(); - -function getPromiseCtor(promiseCtor) { - if (!promiseCtor) promiseCtor = Promise; - if (!promiseCtor) throw new Error("no Promise impl found"); - return promiseCtor; -} - -class SubjectSubscriber extends Subscriber { - constructor(destination) { - super(destination); - this.destination = destination; - } -} - -function refCount() { - return function refCountOperatorFunction(source) { - return source.lift(new RefCountOperator(source)); - }; -} - -class RefCountOperator { - constructor(connectable) { - this.connectable = connectable; - } - call(subscriber, source) { - const {connectable: connectable} = this; - connectable._refCount++; - const refCounter = new RefCountSubscriber(subscriber, connectable); - const subscription = source.subscribe(refCounter); - if (!refCounter.closed) refCounter.connection = connectable.connect(); - return subscription; - } -} - -class RefCountSubscriber extends Subscriber { - constructor(destination, connectable) { - super(destination); - this.connectable = connectable; - } - _unsubscribe() { - const {connectable: connectable} = this; - if (!connectable) { - this.connection = null; - return; - } - this.connectable = null; - const refCount = connectable._refCount; - if (refCount <= 0) { - this.connection = null; - return; - } - connectable._refCount = refCount - 1; - if (refCount > 1) { - this.connection = null; - return; - } - const {connection: connection} = this; - const sharedConnection = connectable._connection; - this.connection = null; - if (sharedConnection && (!connection || sharedConnection === connection)) sharedConnection.unsubscribe(); - } -} - -class ConnectableObservable extends Observable { - constructor(source, subjectFactory) { - super(); - this.source = source; - this.subjectFactory = subjectFactory; - this._refCount = 0; - this._isComplete = false; - } - _subscribe(subscriber) { - return this.getSubject().subscribe(subscriber); - } - getSubject() { - const subject = this._subject; - if (!subject || subject.isStopped) this._subject = this.subjectFactory(); - return this._subject; - } - connect() { - let connection = this._connection; - if (!connection) { - this._isComplete = false; - connection = this._connection = new Subscription(); - connection.add(this.source.subscribe(new ConnectableSubscriber(this.getSubject(), this))); - if (connection.closed) { - this._connection = null; - connection = Subscription.EMPTY; - } - } - return connection; - } - refCount() { - return refCount()(this); - } -} - -const connectableProto = ConnectableObservable.prototype; - -const connectableObservableDescriptor = { - operator: { - value: null - }, - _refCount: { - value: 0, - writable: true - }, - _subject: { - value: null, - writable: true - }, - _connection: { - value: null, - writable: true - }, - _subscribe: { - value: connectableProto._subscribe - }, - _isComplete: { - value: connectableProto._isComplete, - writable: true - }, - getSubject: { - value: connectableProto.getSubject - }, - connect: { - value: connectableProto.connect - }, - refCount: { - value: connectableProto.refCount - } -}; - -class ConnectableSubscriber extends SubjectSubscriber { - constructor(destination, connectable) { - super(destination); - this.connectable = connectable; - } - _error(err) { - this._unsubscribe(); - super._error(err); - } - _complete() { - this.connectable._isComplete = true; - this._unsubscribe(); - super._complete(); - } - _unsubscribe() { - const connectable = this.connectable; - if (connectable) { - this.connectable = null; - const connection = connectable._connection; - connectable._refCount = 0; - connectable._subject = null; - connectable._connection = null; - if (connection) connection.unsubscribe(); - } - } -} - var NotificationKind; (function(NotificationKind) { diff --git a/integration/side-effects/snapshots/esm2015/operators.js b/integration/side-effects/snapshots/esm2015/operators.js index 0242d742cd4..792fba30c04 100644 --- a/integration/side-effects/snapshots/esm2015/operators.js +++ b/integration/side-effects/snapshots/esm2015/operators.js @@ -1,431 +1,3 @@ -function isFunction(x) { - return "function" === typeof x; -} - -let _enable_super_gross_mode_that_will_cause_bad_things = false; - -const config = { - Promise: void 0, - set useDeprecatedSynchronousErrorHandling(value) { - _enable_super_gross_mode_that_will_cause_bad_things = value; - }, - get useDeprecatedSynchronousErrorHandling() { - return _enable_super_gross_mode_that_will_cause_bad_things; - } -}; - -function hostReportError(err) { - setTimeout(() => { - throw err; - }, 0); -} - -const empty = { - closed: true, - next(value) {}, - error(err) { - if (config.useDeprecatedSynchronousErrorHandling) throw err; else hostReportError(err); - }, - complete() {} -}; - -const isArray = Array.isArray || (x => x && "number" === typeof x.length); - -function isObject(x) { - return null !== x && "object" === typeof x; -} - -function UnsubscriptionErrorImpl(errors) { - Error.call(this); - this.message = errors ? `${errors.length} errors occurred during unsubscription:\n${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join("\n ")}` : ""; - this.name = "UnsubscriptionError"; - this.errors = errors; - return this; -} - -UnsubscriptionErrorImpl.prototype = Object.create(Error.prototype); - -const UnsubscriptionError = UnsubscriptionErrorImpl; - -const Subscription = function() { - class Subscription { - constructor(unsubscribe) { - this.closed = false; - this._parentOrParents = null; - this._subscriptions = null; - if (unsubscribe) this._unsubscribe = unsubscribe; - } - unsubscribe() { - let errors; - if (this.closed) return; - let {_parentOrParents: _parentOrParents, _unsubscribe: _unsubscribe, _subscriptions: _subscriptions} = this; - this.closed = true; - this._parentOrParents = null; - this._subscriptions = null; - if (_parentOrParents instanceof Subscription) _parentOrParents.remove(this); else if (null !== _parentOrParents) for (let index = 0; index < _parentOrParents.length; ++index) { - const parent = _parentOrParents[index]; - parent.remove(this); - } - if (isFunction(_unsubscribe)) try { - _unsubscribe.call(this); - } catch (e) { - errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [ e ]; - } - if (isArray(_subscriptions)) { - let index = -1; - let len = _subscriptions.length; - while (++index < len) { - const sub = _subscriptions[index]; - if (isObject(sub)) try { - sub.unsubscribe(); - } catch (e) { - errors = errors || []; - if (e instanceof UnsubscriptionError) errors = errors.concat(flattenUnsubscriptionErrors(e.errors)); else errors.push(e); - } - } - } - if (errors) throw new UnsubscriptionError(errors); - } - add(teardown) { - let subscription = teardown; - switch (typeof teardown) { - case "function": - subscription = new Subscription(teardown); - - case "object": - if (subscription === this || subscription.closed || "function" !== typeof subscription.unsubscribe) return subscription; else if (this.closed) { - subscription.unsubscribe(); - return subscription; - } else if (!(subscription instanceof Subscription)) { - const tmp = subscription; - subscription = new Subscription(); - subscription._subscriptions = [ tmp ]; - } - break; - - default: - if (!teardown) return Subscription.EMPTY; - throw new Error("unrecognized teardown " + teardown + " added to Subscription."); - } - let {_parentOrParents: _parentOrParents} = subscription; - if (null === _parentOrParents) subscription._parentOrParents = this; else if (_parentOrParents instanceof Subscription) { - if (_parentOrParents === this) return subscription; - subscription._parentOrParents = [ _parentOrParents, this ]; - } else if (-1 === _parentOrParents.indexOf(this)) _parentOrParents.push(this); else return subscription; - const subscriptions = this._subscriptions; - if (null === subscriptions) this._subscriptions = [ subscription ]; else subscriptions.push(subscription); - return subscription; - } - remove(subscription) { - const subscriptions = this._subscriptions; - if (subscriptions) { - const subscriptionIndex = subscriptions.indexOf(subscription); - if (-1 !== subscriptionIndex) subscriptions.splice(subscriptionIndex, 1); - } - } - } - Subscription.EMPTY = function(empty) { - empty.closed = true; - return empty; - }(new Subscription()); - return Subscription; -}(); - -function flattenUnsubscriptionErrors(errors) { - return errors.reduce((errs, err) => errs.concat(err instanceof UnsubscriptionError ? err.errors : err), []); -} - -const rxSubscriber = "function" === typeof Symbol ? Symbol("rxSubscriber") : "@@rxSubscriber_" + Math.random(); - -class Subscriber extends Subscription { - constructor(destinationOrNext, error, complete) { - super(); - this.syncErrorValue = null; - this.syncErrorThrown = false; - this.syncErrorThrowable = false; - this.isStopped = false; - switch (arguments.length) { - case 0: - this.destination = empty; - break; - - case 1: - if (!destinationOrNext) { - this.destination = empty; - break; - } - if ("object" === typeof destinationOrNext) { - if (destinationOrNext instanceof Subscriber) { - this.syncErrorThrowable = destinationOrNext.syncErrorThrowable; - this.destination = destinationOrNext; - destinationOrNext.add(this); - } else { - this.syncErrorThrowable = true; - this.destination = new SafeSubscriber(this, destinationOrNext); - } - break; - } - - default: - this.syncErrorThrowable = true; - this.destination = new SafeSubscriber(this, destinationOrNext, error, complete); - break; - } - } - [rxSubscriber]() { - return this; - } - static create(next, error, complete) { - const subscriber = new Subscriber(next, error, complete); - subscriber.syncErrorThrowable = false; - return subscriber; - } - next(value) { - if (!this.isStopped) this._next(value); - } - error(err) { - if (!this.isStopped) { - this.isStopped = true; - this._error(err); - } - } - complete() { - if (!this.isStopped) { - this.isStopped = true; - this._complete(); - } - } - unsubscribe() { - if (this.closed) return; - this.isStopped = true; - super.unsubscribe(); - } - _next(value) { - this.destination.next(value); - } - _error(err) { - this.destination.error(err); - this.unsubscribe(); - } - _complete() { - this.destination.complete(); - this.unsubscribe(); - } - _unsubscribeAndRecycle() { - const {_parentOrParents: _parentOrParents} = this; - this._parentOrParents = null; - this.unsubscribe(); - this.closed = false; - this.isStopped = false; - this._parentOrParents = _parentOrParents; - return this; - } -} - -class SafeSubscriber extends Subscriber { - constructor(_parentSubscriber, observerOrNext, error, complete) { - super(); - this._parentSubscriber = _parentSubscriber; - let next; - let context = this; - if (isFunction(observerOrNext)) next = observerOrNext; else if (observerOrNext) { - next = observerOrNext.next; - error = observerOrNext.error; - complete = observerOrNext.complete; - if (observerOrNext !== empty) { - context = Object.create(observerOrNext); - if (isFunction(context.unsubscribe)) this.add(context.unsubscribe.bind(context)); - context.unsubscribe = this.unsubscribe.bind(this); - } - } - this._context = context; - this._next = next; - this._error = error; - this._complete = complete; - } - next(value) { - if (!this.isStopped && this._next) { - const {_parentSubscriber: _parentSubscriber} = this; - if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) this.__tryOrUnsub(this._next, value); else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) this.unsubscribe(); - } - } - error(err) { - if (!this.isStopped) { - const {_parentSubscriber: _parentSubscriber} = this; - const {useDeprecatedSynchronousErrorHandling: useDeprecatedSynchronousErrorHandling} = config; - if (this._error) if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { - this.__tryOrUnsub(this._error, err); - this.unsubscribe(); - } else { - this.__tryOrSetError(_parentSubscriber, this._error, err); - this.unsubscribe(); - } else if (!_parentSubscriber.syncErrorThrowable) { - this.unsubscribe(); - if (useDeprecatedSynchronousErrorHandling) throw err; - hostReportError(err); - } else { - if (useDeprecatedSynchronousErrorHandling) { - _parentSubscriber.syncErrorValue = err; - _parentSubscriber.syncErrorThrown = true; - } else hostReportError(err); - this.unsubscribe(); - } - } - } - complete() { - if (!this.isStopped) { - const {_parentSubscriber: _parentSubscriber} = this; - if (this._complete) { - const wrappedComplete = () => this._complete.call(this._context); - if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { - this.__tryOrUnsub(wrappedComplete); - this.unsubscribe(); - } else { - this.__tryOrSetError(_parentSubscriber, wrappedComplete); - this.unsubscribe(); - } - } else this.unsubscribe(); - } - } - __tryOrUnsub(fn, value) { - try { - fn.call(this._context, value); - } catch (err) { - this.unsubscribe(); - if (config.useDeprecatedSynchronousErrorHandling) throw err; else hostReportError(err); - } - } - __tryOrSetError(parent, fn, value) { - if (!config.useDeprecatedSynchronousErrorHandling) throw new Error("bad call"); - try { - fn.call(this._context, value); - } catch (err) { - if (config.useDeprecatedSynchronousErrorHandling) { - parent.syncErrorValue = err; - parent.syncErrorThrown = true; - return true; - } else { - hostReportError(err); - return true; - } - } - return false; - } - _unsubscribe() { - const {_parentSubscriber: _parentSubscriber} = this; - this._context = null; - this._parentSubscriber = null; - _parentSubscriber.unsubscribe(); - } -} - -const observable = "function" === typeof Symbol && Symbol.observable || "@@observable"; - -function canReportError(observer) { - while (observer) { - const {closed: closed, destination: destination, isStopped: isStopped} = observer; - if (closed || isStopped) return false; else if (destination && destination instanceof Subscriber) observer = destination; else observer = null; - } - return true; -} - -function toSubscriber(nextOrObserver, error, complete) { - if (nextOrObserver) { - if (nextOrObserver instanceof Subscriber) return nextOrObserver; - if (nextOrObserver[rxSubscriber]) return nextOrObserver[rxSubscriber](); - } - if (!nextOrObserver && !error && !complete) return new Subscriber(empty); - return new Subscriber(nextOrObserver, error, complete); -} - -function noop() {} - -function pipeFromArray(fns) { - if (!fns) return noop; - if (1 === fns.length) return fns[0]; - return function piped(input) { - return fns.reduce((prev, fn) => fn(prev), input); - }; -} - -const Observable = function() { - class Observable { - constructor(subscribe) { - this._isScalar = false; - if (subscribe) this._subscribe = subscribe; - } - lift(operator) { - const observable = new Observable(); - observable.source = this; - observable.operator = operator; - return observable; - } - subscribe(observerOrNext, error, complete) { - const {operator: operator} = this; - const sink = toSubscriber(observerOrNext, error, complete); - if (operator) sink.add(operator.call(sink, this.source)); else sink.add(this.source || config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable ? this._subscribe(sink) : this._trySubscribe(sink)); - if (config.useDeprecatedSynchronousErrorHandling) if (sink.syncErrorThrowable) { - sink.syncErrorThrowable = false; - if (sink.syncErrorThrown) throw sink.syncErrorValue; - } - return sink; - } - _trySubscribe(sink) { - try { - return this._subscribe(sink); - } catch (err) { - if (config.useDeprecatedSynchronousErrorHandling) { - sink.syncErrorThrown = true; - sink.syncErrorValue = err; - } - if (canReportError(sink)) sink.error(err); else console.warn(err); - } - } - forEach(next, promiseCtor) { - promiseCtor = getPromiseCtor(promiseCtor); - return new promiseCtor((resolve, reject) => { - let subscription; - subscription = this.subscribe(value => { - try { - next(value); - } catch (err) { - reject(err); - if (subscription) subscription.unsubscribe(); - } - }, reject, resolve); - }); - } - _subscribe(subscriber) { - const {source: source} = this; - return source && source.subscribe(subscriber); - } - [observable]() { - return this; - } - pipe(...operations) { - if (0 === operations.length) return this; - return pipeFromArray(operations)(this); - } - toPromise(promiseCtor) { - promiseCtor = getPromiseCtor(promiseCtor); - return new promiseCtor((resolve, reject) => { - let value; - this.subscribe(x => value = x, err => reject(err), () => resolve(value)); - }); - } - } - Observable.create = (subscribe => { - return new Observable(subscribe); - }); - return Observable; -}(); - -function getPromiseCtor(promiseCtor) { - if (!promiseCtor) promiseCtor = Promise; - if (!promiseCtor) throw new Error("no Promise impl found"); - return promiseCtor; -} - var NotificationKind; (function(NotificationKind) { @@ -433,156 +5,3 @@ var NotificationKind; NotificationKind["ERROR"] = "E"; NotificationKind["COMPLETE"] = "C"; })(NotificationKind || (NotificationKind = {})); - -class SubjectSubscriber extends Subscriber { - constructor(destination) { - super(destination); - this.destination = destination; - } -} - -function refCount() { - return function refCountOperatorFunction(source) { - return source.lift(new RefCountOperator(source)); - }; -} - -class RefCountOperator { - constructor(connectable) { - this.connectable = connectable; - } - call(subscriber, source) { - const {connectable: connectable} = this; - connectable._refCount++; - const refCounter = new RefCountSubscriber(subscriber, connectable); - const subscription = source.subscribe(refCounter); - if (!refCounter.closed) refCounter.connection = connectable.connect(); - return subscription; - } -} - -class RefCountSubscriber extends Subscriber { - constructor(destination, connectable) { - super(destination); - this.connectable = connectable; - } - _unsubscribe() { - const {connectable: connectable} = this; - if (!connectable) { - this.connection = null; - return; - } - this.connectable = null; - const refCount = connectable._refCount; - if (refCount <= 0) { - this.connection = null; - return; - } - connectable._refCount = refCount - 1; - if (refCount > 1) { - this.connection = null; - return; - } - const {connection: connection} = this; - const sharedConnection = connectable._connection; - this.connection = null; - if (sharedConnection && (!connection || sharedConnection === connection)) sharedConnection.unsubscribe(); - } -} - -class ConnectableObservable extends Observable { - constructor(source, subjectFactory) { - super(); - this.source = source; - this.subjectFactory = subjectFactory; - this._refCount = 0; - this._isComplete = false; - } - _subscribe(subscriber) { - return this.getSubject().subscribe(subscriber); - } - getSubject() { - const subject = this._subject; - if (!subject || subject.isStopped) this._subject = this.subjectFactory(); - return this._subject; - } - connect() { - let connection = this._connection; - if (!connection) { - this._isComplete = false; - connection = this._connection = new Subscription(); - connection.add(this.source.subscribe(new ConnectableSubscriber(this.getSubject(), this))); - if (connection.closed) { - this._connection = null; - connection = Subscription.EMPTY; - } - } - return connection; - } - refCount() { - return refCount()(this); - } -} - -const connectableProto = ConnectableObservable.prototype; - -const connectableObservableDescriptor = { - operator: { - value: null - }, - _refCount: { - value: 0, - writable: true - }, - _subject: { - value: null, - writable: true - }, - _connection: { - value: null, - writable: true - }, - _subscribe: { - value: connectableProto._subscribe - }, - _isComplete: { - value: connectableProto._isComplete, - writable: true - }, - getSubject: { - value: connectableProto.getSubject - }, - connect: { - value: connectableProto.connect - }, - refCount: { - value: connectableProto.refCount - } -}; - -class ConnectableSubscriber extends SubjectSubscriber { - constructor(destination, connectable) { - super(destination); - this.connectable = connectable; - } - _error(err) { - this._unsubscribe(); - super._error(err); - } - _complete() { - this.connectable._isComplete = true; - this._unsubscribe(); - super._complete(); - } - _unsubscribe() { - const connectable = this.connectable; - if (connectable) { - this.connectable = null; - const connection = connectable._connection; - connectable._refCount = 0; - connectable._subject = null; - connectable._connection = null; - if (connection) connection.unsubscribe(); - } - } -} diff --git a/integration/side-effects/snapshots/esm5/index.js b/integration/side-effects/snapshots/esm5/index.js index 25ce2ad1cbd..5d63e0559f6 100644 --- a/integration/side-effects/snapshots/esm5/index.js +++ b/integration/side-effects/snapshots/esm5/index.js @@ -1,622 +1 @@ -import { __extends } from "tslib"; - -function isFunction(x) { - return "function" === typeof x; -} - -var _enable_super_gross_mode_that_will_cause_bad_things = false; - -var config = { - Promise: void 0, - set useDeprecatedSynchronousErrorHandling(value) { - if (value) { - var error = new Error(); - console.warn("DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \n" + error.stack); - } - _enable_super_gross_mode_that_will_cause_bad_things = value; - }, - get useDeprecatedSynchronousErrorHandling() { - return _enable_super_gross_mode_that_will_cause_bad_things; - } -}; - -function hostReportError(err) { - setTimeout(function() { - throw err; - }, 0); -} - -var empty = { - closed: true, - next: function(value) {}, - error: function(err) { - if (config.useDeprecatedSynchronousErrorHandling) throw err; else hostReportError(err); - }, - complete: function() {} -}; - -var isArray = Array.isArray || function(x) { - return x && "number" === typeof x.length; -}; - -function isObject(x) { - return null !== x && "object" === typeof x; -} - -function UnsubscriptionErrorImpl(errors) { - Error.call(this); - this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function(err, i) { - return i + 1 + ") " + err.toString(); - }).join("\n ") : ""; - this.name = "UnsubscriptionError"; - this.errors = errors; - return this; -} - -UnsubscriptionErrorImpl.prototype = Object.create(Error.prototype); - -var UnsubscriptionError = UnsubscriptionErrorImpl; - -var Subscription = function() { - function Subscription(unsubscribe) { - this.closed = false; - this._parentOrParents = null; - this._subscriptions = null; - if (unsubscribe) this._unsubscribe = unsubscribe; - } - Subscription.prototype.unsubscribe = function() { - var errors; - if (this.closed) return; - var _a = this, _parentOrParents = _a._parentOrParents, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions; - this.closed = true; - this._parentOrParents = null; - this._subscriptions = null; - if (_parentOrParents instanceof Subscription) _parentOrParents.remove(this); else if (null !== _parentOrParents) for (var index = 0; index < _parentOrParents.length; ++index) { - var parent_1 = _parentOrParents[index]; - parent_1.remove(this); - } - if (isFunction(_unsubscribe)) try { - _unsubscribe.call(this); - } catch (e) { - errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [ e ]; - } - if (isArray(_subscriptions)) { - var index = -1; - var len = _subscriptions.length; - while (++index < len) { - var sub = _subscriptions[index]; - if (isObject(sub)) try { - sub.unsubscribe(); - } catch (e) { - errors = errors || []; - if (e instanceof UnsubscriptionError) errors = errors.concat(flattenUnsubscriptionErrors(e.errors)); else errors.push(e); - } - } - } - if (errors) throw new UnsubscriptionError(errors); - }; - Subscription.prototype.add = function(teardown) { - var subscription = teardown; - switch (typeof teardown) { - case "function": - subscription = new Subscription(teardown); - - case "object": - if (subscription === this || subscription.closed || "function" !== typeof subscription.unsubscribe) return subscription; else if (this.closed) { - subscription.unsubscribe(); - return subscription; - } else if (!(subscription instanceof Subscription)) { - var tmp = subscription; - subscription = new Subscription(); - subscription._subscriptions = [ tmp ]; - } - break; - - default: - if (!teardown) return Subscription.EMPTY; - throw new Error("unrecognized teardown " + teardown + " added to Subscription."); - } - var _parentOrParents = subscription._parentOrParents; - if (null === _parentOrParents) subscription._parentOrParents = this; else if (_parentOrParents instanceof Subscription) { - if (_parentOrParents === this) return subscription; - subscription._parentOrParents = [ _parentOrParents, this ]; - } else if (-1 === _parentOrParents.indexOf(this)) _parentOrParents.push(this); else return subscription; - var subscriptions = this._subscriptions; - if (null === subscriptions) this._subscriptions = [ subscription ]; else subscriptions.push(subscription); - return subscription; - }; - Subscription.prototype.remove = function(subscription) { - var subscriptions = this._subscriptions; - if (subscriptions) { - var subscriptionIndex = subscriptions.indexOf(subscription); - if (-1 !== subscriptionIndex) subscriptions.splice(subscriptionIndex, 1); - } - }; - Subscription.EMPTY = function(empty) { - empty.closed = true; - return empty; - }(new Subscription()); - return Subscription; -}(); - -function flattenUnsubscriptionErrors(errors) { - return errors.reduce(function(errs, err) { - return errs.concat(err instanceof UnsubscriptionError ? err.errors : err); - }, []); -} - -var rxSubscriber = "function" === typeof Symbol ? Symbol("rxSubscriber") : "@@rxSubscriber_" + Math.random(); - -var Subscriber = function(_super) { - __extends(Subscriber, _super); - function Subscriber(destinationOrNext, error, complete) { - var _this = _super.call(this) || this; - _this.syncErrorValue = null; - _this.syncErrorThrown = false; - _this.syncErrorThrowable = false; - _this.isStopped = false; - switch (arguments.length) { - case 0: - _this.destination = empty; - break; - - case 1: - if (!destinationOrNext) { - _this.destination = empty; - break; - } - if ("object" === typeof destinationOrNext) { - if (destinationOrNext instanceof Subscriber) { - _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable; - _this.destination = destinationOrNext; - destinationOrNext.add(_this); - } else { - _this.syncErrorThrowable = true; - _this.destination = new SafeSubscriber(_this, destinationOrNext); - } - break; - } - - default: - _this.syncErrorThrowable = true; - _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete); - break; - } - return _this; - } - Subscriber.prototype[rxSubscriber] = function() { - return this; - }; - Subscriber.create = function(next, error, complete) { - var subscriber = new Subscriber(next, error, complete); - subscriber.syncErrorThrowable = false; - return subscriber; - }; - Subscriber.prototype.next = function(value) { - if (!this.isStopped) this._next(value); - }; - Subscriber.prototype.error = function(err) { - if (!this.isStopped) { - this.isStopped = true; - this._error(err); - } - }; - Subscriber.prototype.complete = function() { - if (!this.isStopped) { - this.isStopped = true; - this._complete(); - } - }; - Subscriber.prototype.unsubscribe = function() { - if (this.closed) return; - this.isStopped = true; - _super.prototype.unsubscribe.call(this); - }; - Subscriber.prototype._next = function(value) { - this.destination.next(value); - }; - Subscriber.prototype._error = function(err) { - this.destination.error(err); - this.unsubscribe(); - }; - Subscriber.prototype._complete = function() { - this.destination.complete(); - this.unsubscribe(); - }; - Subscriber.prototype._unsubscribeAndRecycle = function() { - var _parentOrParents = this._parentOrParents; - this._parentOrParents = null; - this.unsubscribe(); - this.closed = false; - this.isStopped = false; - this._parentOrParents = _parentOrParents; - return this; - }; - return Subscriber; -}(Subscription); - -var SafeSubscriber = function(_super) { - __extends(SafeSubscriber, _super); - function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) { - var _this = _super.call(this) || this; - _this._parentSubscriber = _parentSubscriber; - var next; - var context = _this; - if (isFunction(observerOrNext)) next = observerOrNext; else if (observerOrNext) { - next = observerOrNext.next; - error = observerOrNext.error; - complete = observerOrNext.complete; - if (observerOrNext !== empty) { - context = Object.create(observerOrNext); - if (isFunction(context.unsubscribe)) _this.add(context.unsubscribe.bind(context)); - context.unsubscribe = _this.unsubscribe.bind(_this); - } - } - _this._context = context; - _this._next = next; - _this._error = error; - _this._complete = complete; - return _this; - } - SafeSubscriber.prototype.next = function(value) { - if (!this.isStopped && this._next) { - var _parentSubscriber = this._parentSubscriber; - if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) this.__tryOrUnsub(this._next, value); else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) this.unsubscribe(); - } - }; - SafeSubscriber.prototype.error = function(err) { - if (!this.isStopped) { - var _parentSubscriber = this._parentSubscriber; - var useDeprecatedSynchronousErrorHandling = config.useDeprecatedSynchronousErrorHandling; - if (this._error) if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { - this.__tryOrUnsub(this._error, err); - this.unsubscribe(); - } else { - this.__tryOrSetError(_parentSubscriber, this._error, err); - this.unsubscribe(); - } else if (!_parentSubscriber.syncErrorThrowable) { - this.unsubscribe(); - if (useDeprecatedSynchronousErrorHandling) throw err; - hostReportError(err); - } else { - if (useDeprecatedSynchronousErrorHandling) { - _parentSubscriber.syncErrorValue = err; - _parentSubscriber.syncErrorThrown = true; - } else hostReportError(err); - this.unsubscribe(); - } - } - }; - SafeSubscriber.prototype.complete = function() { - var _this = this; - if (!this.isStopped) { - var _parentSubscriber = this._parentSubscriber; - if (this._complete) { - var wrappedComplete = function() { - return _this._complete.call(_this._context); - }; - if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { - this.__tryOrUnsub(wrappedComplete); - this.unsubscribe(); - } else { - this.__tryOrSetError(_parentSubscriber, wrappedComplete); - this.unsubscribe(); - } - } else this.unsubscribe(); - } - }; - SafeSubscriber.prototype.__tryOrUnsub = function(fn, value) { - try { - fn.call(this._context, value); - } catch (err) { - this.unsubscribe(); - if (config.useDeprecatedSynchronousErrorHandling) throw err; else hostReportError(err); - } - }; - SafeSubscriber.prototype.__tryOrSetError = function(parent, fn, value) { - if (!config.useDeprecatedSynchronousErrorHandling) throw new Error("bad call"); - try { - fn.call(this._context, value); - } catch (err) { - if (config.useDeprecatedSynchronousErrorHandling) { - parent.syncErrorValue = err; - parent.syncErrorThrown = true; - return true; - } else { - hostReportError(err); - return true; - } - } - return false; - }; - SafeSubscriber.prototype._unsubscribe = function() { - var _parentSubscriber = this._parentSubscriber; - this._context = null; - this._parentSubscriber = null; - _parentSubscriber.unsubscribe(); - }; - return SafeSubscriber; -}(Subscriber); - -function canReportError(observer) { - while (observer) { - var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped; - if (closed_1 || isStopped) return false; else if (destination && destination instanceof Subscriber) observer = destination; else observer = null; - } - return true; -} - -function toSubscriber(nextOrObserver, error, complete) { - if (nextOrObserver) { - if (nextOrObserver instanceof Subscriber) return nextOrObserver; - if (nextOrObserver[rxSubscriber]) return nextOrObserver[rxSubscriber](); - } - if (!nextOrObserver && !error && !complete) return new Subscriber(empty); - return new Subscriber(nextOrObserver, error, complete); -} - -var observable = "function" === typeof Symbol && Symbol.observable || "@@observable"; - -function noop() {} - -function pipeFromArray(fns) { - if (!fns) return noop; - if (1 === fns.length) return fns[0]; - return function piped(input) { - return fns.reduce(function(prev, fn) { - return fn(prev); - }, input); - }; -} - -var Observable = function() { - function Observable(subscribe) { - this._isScalar = false; - if (subscribe) this._subscribe = subscribe; - } - Observable.prototype.lift = function(operator) { - var observable = new Observable(); - observable.source = this; - observable.operator = operator; - return observable; - }; - Observable.prototype.subscribe = function(observerOrNext, error, complete) { - var operator = this.operator; - var sink = toSubscriber(observerOrNext, error, complete); - if (operator) sink.add(operator.call(sink, this.source)); else sink.add(this.source || config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable ? this._subscribe(sink) : this._trySubscribe(sink)); - if (config.useDeprecatedSynchronousErrorHandling) if (sink.syncErrorThrowable) { - sink.syncErrorThrowable = false; - if (sink.syncErrorThrown) throw sink.syncErrorValue; - } - return sink; - }; - Observable.prototype._trySubscribe = function(sink) { - try { - return this._subscribe(sink); - } catch (err) { - if (config.useDeprecatedSynchronousErrorHandling) { - sink.syncErrorThrown = true; - sink.syncErrorValue = err; - } - if (canReportError(sink)) sink.error(err); else console.warn(err); - } - }; - Observable.prototype.forEach = function(next, promiseCtor) { - var _this = this; - promiseCtor = getPromiseCtor(promiseCtor); - return new promiseCtor(function(resolve, reject) { - var subscription; - subscription = _this.subscribe(function(value) { - try { - next(value); - } catch (err) { - reject(err); - if (subscription) subscription.unsubscribe(); - } - }, reject, resolve); - }); - }; - Observable.prototype._subscribe = function(subscriber) { - var source = this.source; - return source && source.subscribe(subscriber); - }; - Observable.prototype[observable] = function() { - return this; - }; - Observable.prototype.pipe = function() { - var operations = []; - for (var _i = 0; _i < arguments.length; _i++) operations[_i] = arguments[_i]; - if (0 === operations.length) return this; - return pipeFromArray(operations)(this); - }; - Observable.prototype.toPromise = function(promiseCtor) { - var _this = this; - promiseCtor = getPromiseCtor(promiseCtor); - return new promiseCtor(function(resolve, reject) { - var value; - _this.subscribe(function(x) { - return value = x; - }, function(err) { - return reject(err); - }, function() { - return resolve(value); - }); - }); - }; - Observable.create = function(subscribe) { - return new Observable(subscribe); - }; - return Observable; -}(); - -function getPromiseCtor(promiseCtor) { - if (!promiseCtor) promiseCtor = Promise; - if (!promiseCtor) throw new Error("no Promise impl found"); - return promiseCtor; -} - -var SubjectSubscriber = function(_super) { - __extends(SubjectSubscriber, _super); - function SubjectSubscriber(destination) { - var _this = _super.call(this, destination) || this; - _this.destination = destination; - return _this; - } - return SubjectSubscriber; -}(Subscriber); - -function refCount() { - return function refCountOperatorFunction(source) { - return source.lift(new RefCountOperator(source)); - }; -} - -var RefCountOperator = function() { - function RefCountOperator(connectable) { - this.connectable = connectable; - } - RefCountOperator.prototype.call = function(subscriber, source) { - var connectable = this.connectable; - connectable._refCount++; - var refCounter = new RefCountSubscriber(subscriber, connectable); - var subscription = source.subscribe(refCounter); - if (!refCounter.closed) refCounter.connection = connectable.connect(); - return subscription; - }; - return RefCountOperator; -}(); - -var RefCountSubscriber = function(_super) { - __extends(RefCountSubscriber, _super); - function RefCountSubscriber(destination, connectable) { - var _this = _super.call(this, destination) || this; - _this.connectable = connectable; - return _this; - } - RefCountSubscriber.prototype._unsubscribe = function() { - var connectable = this.connectable; - if (!connectable) { - this.connection = null; - return; - } - this.connectable = null; - var refCount = connectable._refCount; - if (refCount <= 0) { - this.connection = null; - return; - } - connectable._refCount = refCount - 1; - if (refCount > 1) { - this.connection = null; - return; - } - var connection = this.connection; - var sharedConnection = connectable._connection; - this.connection = null; - if (sharedConnection && (!connection || sharedConnection === connection)) sharedConnection.unsubscribe(); - }; - return RefCountSubscriber; -}(Subscriber); - -var ConnectableObservable = function(_super) { - __extends(ConnectableObservable, _super); - function ConnectableObservable(source, subjectFactory) { - var _this = _super.call(this) || this; - _this.source = source; - _this.subjectFactory = subjectFactory; - _this._refCount = 0; - _this._isComplete = false; - return _this; - } - ConnectableObservable.prototype._subscribe = function(subscriber) { - return this.getSubject().subscribe(subscriber); - }; - ConnectableObservable.prototype.getSubject = function() { - var subject = this._subject; - if (!subject || subject.isStopped) this._subject = this.subjectFactory(); - return this._subject; - }; - ConnectableObservable.prototype.connect = function() { - var connection = this._connection; - if (!connection) { - this._isComplete = false; - connection = this._connection = new Subscription(); - connection.add(this.source.subscribe(new ConnectableSubscriber(this.getSubject(), this))); - if (connection.closed) { - this._connection = null; - connection = Subscription.EMPTY; - } - } - return connection; - }; - ConnectableObservable.prototype.refCount = function() { - return refCount()(this); - }; - return ConnectableObservable; -}(Observable); - -var connectableProto = ConnectableObservable.prototype; - -var connectableObservableDescriptor = { - operator: { - value: null - }, - _refCount: { - value: 0, - writable: true - }, - _subject: { - value: null, - writable: true - }, - _connection: { - value: null, - writable: true - }, - _subscribe: { - value: connectableProto._subscribe - }, - _isComplete: { - value: connectableProto._isComplete, - writable: true - }, - getSubject: { - value: connectableProto.getSubject - }, - connect: { - value: connectableProto.connect - }, - refCount: { - value: connectableProto.refCount - } -}; - -var ConnectableSubscriber = function(_super) { - __extends(ConnectableSubscriber, _super); - function ConnectableSubscriber(destination, connectable) { - var _this = _super.call(this, destination) || this; - _this.connectable = connectable; - return _this; - } - ConnectableSubscriber.prototype._error = function(err) { - this._unsubscribe(); - _super.prototype._error.call(this, err); - }; - ConnectableSubscriber.prototype._complete = function() { - this.connectable._isComplete = true; - this._unsubscribe(); - _super.prototype._complete.call(this); - }; - ConnectableSubscriber.prototype._unsubscribe = function() { - var connectable = this.connectable; - if (connectable) { - this.connectable = null; - var connection = connectable._connection; - connectable._refCount = 0; - connectable._subject = null; - connectable._connection = null; - if (connection) connection.unsubscribe(); - } - }; - return ConnectableSubscriber; -}(SubjectSubscriber); +import "tslib"; diff --git a/integration/side-effects/snapshots/esm5/operators.js b/integration/side-effects/snapshots/esm5/operators.js index 109afa40466..5d63e0559f6 100644 --- a/integration/side-effects/snapshots/esm5/operators.js +++ b/integration/side-effects/snapshots/esm5/operators.js @@ -1,622 +1 @@ -import { __extends } from "tslib"; - -function isFunction(x) { - return "function" === typeof x; -} - -var _enable_super_gross_mode_that_will_cause_bad_things = false; - -var config = { - Promise: void 0, - set useDeprecatedSynchronousErrorHandling(value) { - if (value) { - var error = new Error(); - console.warn("DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \n" + error.stack); - } - _enable_super_gross_mode_that_will_cause_bad_things = value; - }, - get useDeprecatedSynchronousErrorHandling() { - return _enable_super_gross_mode_that_will_cause_bad_things; - } -}; - -function hostReportError(err) { - setTimeout(function() { - throw err; - }, 0); -} - -var empty = { - closed: true, - next: function(value) {}, - error: function(err) { - if (config.useDeprecatedSynchronousErrorHandling) throw err; else hostReportError(err); - }, - complete: function() {} -}; - -var isArray = Array.isArray || function(x) { - return x && "number" === typeof x.length; -}; - -function isObject(x) { - return null !== x && "object" === typeof x; -} - -function UnsubscriptionErrorImpl(errors) { - Error.call(this); - this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function(err, i) { - return i + 1 + ") " + err.toString(); - }).join("\n ") : ""; - this.name = "UnsubscriptionError"; - this.errors = errors; - return this; -} - -UnsubscriptionErrorImpl.prototype = Object.create(Error.prototype); - -var UnsubscriptionError = UnsubscriptionErrorImpl; - -var Subscription = function() { - function Subscription(unsubscribe) { - this.closed = false; - this._parentOrParents = null; - this._subscriptions = null; - if (unsubscribe) this._unsubscribe = unsubscribe; - } - Subscription.prototype.unsubscribe = function() { - var errors; - if (this.closed) return; - var _a = this, _parentOrParents = _a._parentOrParents, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions; - this.closed = true; - this._parentOrParents = null; - this._subscriptions = null; - if (_parentOrParents instanceof Subscription) _parentOrParents.remove(this); else if (null !== _parentOrParents) for (var index = 0; index < _parentOrParents.length; ++index) { - var parent_1 = _parentOrParents[index]; - parent_1.remove(this); - } - if (isFunction(_unsubscribe)) try { - _unsubscribe.call(this); - } catch (e) { - errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [ e ]; - } - if (isArray(_subscriptions)) { - var index = -1; - var len = _subscriptions.length; - while (++index < len) { - var sub = _subscriptions[index]; - if (isObject(sub)) try { - sub.unsubscribe(); - } catch (e) { - errors = errors || []; - if (e instanceof UnsubscriptionError) errors = errors.concat(flattenUnsubscriptionErrors(e.errors)); else errors.push(e); - } - } - } - if (errors) throw new UnsubscriptionError(errors); - }; - Subscription.prototype.add = function(teardown) { - var subscription = teardown; - switch (typeof teardown) { - case "function": - subscription = new Subscription(teardown); - - case "object": - if (subscription === this || subscription.closed || "function" !== typeof subscription.unsubscribe) return subscription; else if (this.closed) { - subscription.unsubscribe(); - return subscription; - } else if (!(subscription instanceof Subscription)) { - var tmp = subscription; - subscription = new Subscription(); - subscription._subscriptions = [ tmp ]; - } - break; - - default: - if (!teardown) return Subscription.EMPTY; - throw new Error("unrecognized teardown " + teardown + " added to Subscription."); - } - var _parentOrParents = subscription._parentOrParents; - if (null === _parentOrParents) subscription._parentOrParents = this; else if (_parentOrParents instanceof Subscription) { - if (_parentOrParents === this) return subscription; - subscription._parentOrParents = [ _parentOrParents, this ]; - } else if (-1 === _parentOrParents.indexOf(this)) _parentOrParents.push(this); else return subscription; - var subscriptions = this._subscriptions; - if (null === subscriptions) this._subscriptions = [ subscription ]; else subscriptions.push(subscription); - return subscription; - }; - Subscription.prototype.remove = function(subscription) { - var subscriptions = this._subscriptions; - if (subscriptions) { - var subscriptionIndex = subscriptions.indexOf(subscription); - if (-1 !== subscriptionIndex) subscriptions.splice(subscriptionIndex, 1); - } - }; - Subscription.EMPTY = function(empty) { - empty.closed = true; - return empty; - }(new Subscription()); - return Subscription; -}(); - -function flattenUnsubscriptionErrors(errors) { - return errors.reduce(function(errs, err) { - return errs.concat(err instanceof UnsubscriptionError ? err.errors : err); - }, []); -} - -var rxSubscriber = "function" === typeof Symbol ? Symbol("rxSubscriber") : "@@rxSubscriber_" + Math.random(); - -var Subscriber = function(_super) { - __extends(Subscriber, _super); - function Subscriber(destinationOrNext, error, complete) { - var _this = _super.call(this) || this; - _this.syncErrorValue = null; - _this.syncErrorThrown = false; - _this.syncErrorThrowable = false; - _this.isStopped = false; - switch (arguments.length) { - case 0: - _this.destination = empty; - break; - - case 1: - if (!destinationOrNext) { - _this.destination = empty; - break; - } - if ("object" === typeof destinationOrNext) { - if (destinationOrNext instanceof Subscriber) { - _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable; - _this.destination = destinationOrNext; - destinationOrNext.add(_this); - } else { - _this.syncErrorThrowable = true; - _this.destination = new SafeSubscriber(_this, destinationOrNext); - } - break; - } - - default: - _this.syncErrorThrowable = true; - _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete); - break; - } - return _this; - } - Subscriber.prototype[rxSubscriber] = function() { - return this; - }; - Subscriber.create = function(next, error, complete) { - var subscriber = new Subscriber(next, error, complete); - subscriber.syncErrorThrowable = false; - return subscriber; - }; - Subscriber.prototype.next = function(value) { - if (!this.isStopped) this._next(value); - }; - Subscriber.prototype.error = function(err) { - if (!this.isStopped) { - this.isStopped = true; - this._error(err); - } - }; - Subscriber.prototype.complete = function() { - if (!this.isStopped) { - this.isStopped = true; - this._complete(); - } - }; - Subscriber.prototype.unsubscribe = function() { - if (this.closed) return; - this.isStopped = true; - _super.prototype.unsubscribe.call(this); - }; - Subscriber.prototype._next = function(value) { - this.destination.next(value); - }; - Subscriber.prototype._error = function(err) { - this.destination.error(err); - this.unsubscribe(); - }; - Subscriber.prototype._complete = function() { - this.destination.complete(); - this.unsubscribe(); - }; - Subscriber.prototype._unsubscribeAndRecycle = function() { - var _parentOrParents = this._parentOrParents; - this._parentOrParents = null; - this.unsubscribe(); - this.closed = false; - this.isStopped = false; - this._parentOrParents = _parentOrParents; - return this; - }; - return Subscriber; -}(Subscription); - -var SafeSubscriber = function(_super) { - __extends(SafeSubscriber, _super); - function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) { - var _this = _super.call(this) || this; - _this._parentSubscriber = _parentSubscriber; - var next; - var context = _this; - if (isFunction(observerOrNext)) next = observerOrNext; else if (observerOrNext) { - next = observerOrNext.next; - error = observerOrNext.error; - complete = observerOrNext.complete; - if (observerOrNext !== empty) { - context = Object.create(observerOrNext); - if (isFunction(context.unsubscribe)) _this.add(context.unsubscribe.bind(context)); - context.unsubscribe = _this.unsubscribe.bind(_this); - } - } - _this._context = context; - _this._next = next; - _this._error = error; - _this._complete = complete; - return _this; - } - SafeSubscriber.prototype.next = function(value) { - if (!this.isStopped && this._next) { - var _parentSubscriber = this._parentSubscriber; - if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) this.__tryOrUnsub(this._next, value); else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) this.unsubscribe(); - } - }; - SafeSubscriber.prototype.error = function(err) { - if (!this.isStopped) { - var _parentSubscriber = this._parentSubscriber; - var useDeprecatedSynchronousErrorHandling = config.useDeprecatedSynchronousErrorHandling; - if (this._error) if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { - this.__tryOrUnsub(this._error, err); - this.unsubscribe(); - } else { - this.__tryOrSetError(_parentSubscriber, this._error, err); - this.unsubscribe(); - } else if (!_parentSubscriber.syncErrorThrowable) { - this.unsubscribe(); - if (useDeprecatedSynchronousErrorHandling) throw err; - hostReportError(err); - } else { - if (useDeprecatedSynchronousErrorHandling) { - _parentSubscriber.syncErrorValue = err; - _parentSubscriber.syncErrorThrown = true; - } else hostReportError(err); - this.unsubscribe(); - } - } - }; - SafeSubscriber.prototype.complete = function() { - var _this = this; - if (!this.isStopped) { - var _parentSubscriber = this._parentSubscriber; - if (this._complete) { - var wrappedComplete = function() { - return _this._complete.call(_this._context); - }; - if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { - this.__tryOrUnsub(wrappedComplete); - this.unsubscribe(); - } else { - this.__tryOrSetError(_parentSubscriber, wrappedComplete); - this.unsubscribe(); - } - } else this.unsubscribe(); - } - }; - SafeSubscriber.prototype.__tryOrUnsub = function(fn, value) { - try { - fn.call(this._context, value); - } catch (err) { - this.unsubscribe(); - if (config.useDeprecatedSynchronousErrorHandling) throw err; else hostReportError(err); - } - }; - SafeSubscriber.prototype.__tryOrSetError = function(parent, fn, value) { - if (!config.useDeprecatedSynchronousErrorHandling) throw new Error("bad call"); - try { - fn.call(this._context, value); - } catch (err) { - if (config.useDeprecatedSynchronousErrorHandling) { - parent.syncErrorValue = err; - parent.syncErrorThrown = true; - return true; - } else { - hostReportError(err); - return true; - } - } - return false; - }; - SafeSubscriber.prototype._unsubscribe = function() { - var _parentSubscriber = this._parentSubscriber; - this._context = null; - this._parentSubscriber = null; - _parentSubscriber.unsubscribe(); - }; - return SafeSubscriber; -}(Subscriber); - -var observable = "function" === typeof Symbol && Symbol.observable || "@@observable"; - -function canReportError(observer) { - while (observer) { - var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped; - if (closed_1 || isStopped) return false; else if (destination && destination instanceof Subscriber) observer = destination; else observer = null; - } - return true; -} - -function toSubscriber(nextOrObserver, error, complete) { - if (nextOrObserver) { - if (nextOrObserver instanceof Subscriber) return nextOrObserver; - if (nextOrObserver[rxSubscriber]) return nextOrObserver[rxSubscriber](); - } - if (!nextOrObserver && !error && !complete) return new Subscriber(empty); - return new Subscriber(nextOrObserver, error, complete); -} - -function noop() {} - -function pipeFromArray(fns) { - if (!fns) return noop; - if (1 === fns.length) return fns[0]; - return function piped(input) { - return fns.reduce(function(prev, fn) { - return fn(prev); - }, input); - }; -} - -var Observable = function() { - function Observable(subscribe) { - this._isScalar = false; - if (subscribe) this._subscribe = subscribe; - } - Observable.prototype.lift = function(operator) { - var observable = new Observable(); - observable.source = this; - observable.operator = operator; - return observable; - }; - Observable.prototype.subscribe = function(observerOrNext, error, complete) { - var operator = this.operator; - var sink = toSubscriber(observerOrNext, error, complete); - if (operator) sink.add(operator.call(sink, this.source)); else sink.add(this.source || config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable ? this._subscribe(sink) : this._trySubscribe(sink)); - if (config.useDeprecatedSynchronousErrorHandling) if (sink.syncErrorThrowable) { - sink.syncErrorThrowable = false; - if (sink.syncErrorThrown) throw sink.syncErrorValue; - } - return sink; - }; - Observable.prototype._trySubscribe = function(sink) { - try { - return this._subscribe(sink); - } catch (err) { - if (config.useDeprecatedSynchronousErrorHandling) { - sink.syncErrorThrown = true; - sink.syncErrorValue = err; - } - if (canReportError(sink)) sink.error(err); else console.warn(err); - } - }; - Observable.prototype.forEach = function(next, promiseCtor) { - var _this = this; - promiseCtor = getPromiseCtor(promiseCtor); - return new promiseCtor(function(resolve, reject) { - var subscription; - subscription = _this.subscribe(function(value) { - try { - next(value); - } catch (err) { - reject(err); - if (subscription) subscription.unsubscribe(); - } - }, reject, resolve); - }); - }; - Observable.prototype._subscribe = function(subscriber) { - var source = this.source; - return source && source.subscribe(subscriber); - }; - Observable.prototype[observable] = function() { - return this; - }; - Observable.prototype.pipe = function() { - var operations = []; - for (var _i = 0; _i < arguments.length; _i++) operations[_i] = arguments[_i]; - if (0 === operations.length) return this; - return pipeFromArray(operations)(this); - }; - Observable.prototype.toPromise = function(promiseCtor) { - var _this = this; - promiseCtor = getPromiseCtor(promiseCtor); - return new promiseCtor(function(resolve, reject) { - var value; - _this.subscribe(function(x) { - return value = x; - }, function(err) { - return reject(err); - }, function() { - return resolve(value); - }); - }); - }; - Observable.create = function(subscribe) { - return new Observable(subscribe); - }; - return Observable; -}(); - -function getPromiseCtor(promiseCtor) { - if (!promiseCtor) promiseCtor = Promise; - if (!promiseCtor) throw new Error("no Promise impl found"); - return promiseCtor; -} - -var SubjectSubscriber = function(_super) { - __extends(SubjectSubscriber, _super); - function SubjectSubscriber(destination) { - var _this = _super.call(this, destination) || this; - _this.destination = destination; - return _this; - } - return SubjectSubscriber; -}(Subscriber); - -function refCount() { - return function refCountOperatorFunction(source) { - return source.lift(new RefCountOperator(source)); - }; -} - -var RefCountOperator = function() { - function RefCountOperator(connectable) { - this.connectable = connectable; - } - RefCountOperator.prototype.call = function(subscriber, source) { - var connectable = this.connectable; - connectable._refCount++; - var refCounter = new RefCountSubscriber(subscriber, connectable); - var subscription = source.subscribe(refCounter); - if (!refCounter.closed) refCounter.connection = connectable.connect(); - return subscription; - }; - return RefCountOperator; -}(); - -var RefCountSubscriber = function(_super) { - __extends(RefCountSubscriber, _super); - function RefCountSubscriber(destination, connectable) { - var _this = _super.call(this, destination) || this; - _this.connectable = connectable; - return _this; - } - RefCountSubscriber.prototype._unsubscribe = function() { - var connectable = this.connectable; - if (!connectable) { - this.connection = null; - return; - } - this.connectable = null; - var refCount = connectable._refCount; - if (refCount <= 0) { - this.connection = null; - return; - } - connectable._refCount = refCount - 1; - if (refCount > 1) { - this.connection = null; - return; - } - var connection = this.connection; - var sharedConnection = connectable._connection; - this.connection = null; - if (sharedConnection && (!connection || sharedConnection === connection)) sharedConnection.unsubscribe(); - }; - return RefCountSubscriber; -}(Subscriber); - -var ConnectableObservable = function(_super) { - __extends(ConnectableObservable, _super); - function ConnectableObservable(source, subjectFactory) { - var _this = _super.call(this) || this; - _this.source = source; - _this.subjectFactory = subjectFactory; - _this._refCount = 0; - _this._isComplete = false; - return _this; - } - ConnectableObservable.prototype._subscribe = function(subscriber) { - return this.getSubject().subscribe(subscriber); - }; - ConnectableObservable.prototype.getSubject = function() { - var subject = this._subject; - if (!subject || subject.isStopped) this._subject = this.subjectFactory(); - return this._subject; - }; - ConnectableObservable.prototype.connect = function() { - var connection = this._connection; - if (!connection) { - this._isComplete = false; - connection = this._connection = new Subscription(); - connection.add(this.source.subscribe(new ConnectableSubscriber(this.getSubject(), this))); - if (connection.closed) { - this._connection = null; - connection = Subscription.EMPTY; - } - } - return connection; - }; - ConnectableObservable.prototype.refCount = function() { - return refCount()(this); - }; - return ConnectableObservable; -}(Observable); - -var connectableProto = ConnectableObservable.prototype; - -var connectableObservableDescriptor = { - operator: { - value: null - }, - _refCount: { - value: 0, - writable: true - }, - _subject: { - value: null, - writable: true - }, - _connection: { - value: null, - writable: true - }, - _subscribe: { - value: connectableProto._subscribe - }, - _isComplete: { - value: connectableProto._isComplete, - writable: true - }, - getSubject: { - value: connectableProto.getSubject - }, - connect: { - value: connectableProto.connect - }, - refCount: { - value: connectableProto.refCount - } -}; - -var ConnectableSubscriber = function(_super) { - __extends(ConnectableSubscriber, _super); - function ConnectableSubscriber(destination, connectable) { - var _this = _super.call(this, destination) || this; - _this.connectable = connectable; - return _this; - } - ConnectableSubscriber.prototype._error = function(err) { - this._unsubscribe(); - _super.prototype._error.call(this, err); - }; - ConnectableSubscriber.prototype._complete = function() { - this.connectable._isComplete = true; - this._unsubscribe(); - _super.prototype._complete.call(this); - }; - ConnectableSubscriber.prototype._unsubscribe = function() { - var connectable = this.connectable; - if (connectable) { - this.connectable = null; - var connection = connectable._connection; - connectable._refCount = 0; - connectable._subject = null; - connectable._connection = null; - if (connection) connection.unsubscribe(); - } - }; - return ConnectableSubscriber; -}(SubjectSubscriber); +import "tslib"; diff --git a/package-lock.json b/package-lock.json index 0a12489437a..e71a20f89e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2313,19 +2313,16 @@ "dev": true }, "check-side-effects": { - "version": "0.0.17", - "resolved": "https://registry.npmjs.org/check-side-effects/-/check-side-effects-0.0.17.tgz", - "integrity": "sha512-btS7893opEL7Y/X+KidPPbGnfjuhs92dZUml8x5RHLxNRDmFZq8iaU72Pl9nU6N9Szr5ilRsdaDaYPf3QBHgtQ==", + "version": "0.0.20", + "resolved": "https://registry.npmjs.org/check-side-effects/-/check-side-effects-0.0.20.tgz", + "integrity": "sha512-tx7dvqAK0z8PM/gTTnfi6oW1Scn9f8EbMSZ1mu//4oIpNWF6ZNW2SFX7Cnsgq9xZjYeoD+YaUVx9CC0fEFizkQ==", "dev": true, "requires": { "@angular-devkit/build-optimizer": "0.14.0-beta.5", "minimist": "~1.2.0", "rollup": "~1.11.3", "rollup-plugin-node-resolve": "~4.2.3", - "rollup-plugin-terser": "~4.0.4", - "tslib": "~1.9.3", - "tslint": "^5.16.0", - "typescript": "^3.4.5" + "rollup-plugin-terser": "~4.0.4" }, "dependencies": { "@angular-devkit/build-optimizer": { @@ -2338,14 +2335,6 @@ "source-map": "0.5.6", "typescript": "3.2.4", "webpack-sources": "1.3.0" - }, - "dependencies": { - "typescript": { - "version": "3.2.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.2.4.tgz", - "integrity": "sha512-0RNDbSdEokBeEAkgNbxJ+BLwSManFy9TeXz8uW+48j/xhEXv1ePME60olyzw2XzUqUBNAYFeJadIqAgNqIACwg==", - "dev": true - } } }, "@types/node": { @@ -2360,15 +2349,6 @@ "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==", "dev": true }, - "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "requires": { - "color-convert": "^1.9.0" - } - }, "big.js": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", @@ -2381,17 +2361,6 @@ "integrity": "sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw==", "dev": true }, - "chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "requires": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - } - }, "json5": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", @@ -2435,66 +2404,16 @@ "resolve": "^1.10.0" } }, - "semver": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", - "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", - "dev": true - }, "source-map": { "version": "0.5.6", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.6.tgz", "integrity": "sha1-dc449SvwczxafwwRjYEzSiu19BI=", "dev": true }, - "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } - }, - "tslib": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", - "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", - "dev": true - }, - "tslint": { - "version": "5.16.0", - "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.16.0.tgz", - "integrity": "sha512-UxG2yNxJ5pgGwmMzPMYh/CCnCnh0HfPgtlVRDs1ykZklufFBL1ZoTlWFRz2NQjcoEiDoRp+JyT0lhBbbH/obyA==", - "dev": true, - "requires": { - "@babel/code-frame": "^7.0.0", - "builtin-modules": "^1.1.1", - "chalk": "^2.3.0", - "commander": "^2.12.1", - "diff": "^3.2.0", - "glob": "^7.1.1", - "js-yaml": "^3.13.0", - "minimatch": "^3.0.4", - "mkdirp": "^0.5.1", - "resolve": "^1.3.2", - "semver": "^5.3.0", - "tslib": "^1.8.0", - "tsutils": "^2.29.0" - }, - "dependencies": { - "builtin-modules": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", - "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", - "dev": true - } - } - }, "typescript": { - "version": "3.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz", - "integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==", + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.2.4.tgz", + "integrity": "sha512-0RNDbSdEokBeEAkgNbxJ+BLwSManFy9TeXz8uW+48j/xhEXv1ePME60olyzw2XzUqUBNAYFeJadIqAgNqIACwg==", "dev": true }, "webpack-sources": { @@ -2781,12 +2700,6 @@ "integrity": "sha1-FopHAXVran9RoSzgyXv6KMCE7WM=", "dev": true }, - "commander": { - "version": "2.20.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", - "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", - "dev": true - }, "commitizen": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/commitizen/-/commitizen-3.1.1.tgz", @@ -11065,6 +10978,12 @@ } } }, + "tslint-no-toplevel-property-access": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/tslint-no-toplevel-property-access/-/tslint-no-toplevel-property-access-0.0.2.tgz", + "integrity": "sha512-Oc+UUurlGLBkgeUSGxMoTpRUpaXsjqzQCEAYrYQyuU8330fi5FKlye5n53y87EJ24AlfdoxMPV7DJfFOADapfg==", + "dev": true + }, "tslint-no-unused-expression-chai": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tslint-no-unused-expression-chai/-/tslint-no-unused-expression-chai-0.0.3.tgz", @@ -11091,15 +11010,6 @@ } } }, - "tsutils": { - "version": "2.29.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", - "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", - "dev": true, - "requires": { - "tslib": "^1.8.1" - } - }, "tty-browserify": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz", diff --git a/package.json b/package.json index 353e2443fd5..9a2a3c7aab3 100644 --- a/package.json +++ b/package.json @@ -167,7 +167,7 @@ "babel-polyfill": "6.26.0", "benchmark": "2.1.0", "chai": "4.1.2", - "check-side-effects": "0.0.17", + "check-side-effects": "0.0.20", "color": "3.0.0", "colors": "1.1.2", "commitizen": "^3.1.1", @@ -213,6 +213,7 @@ "tsconfig-paths": "3.2.0", "tslint": "5.9.1", "tslint-etc": "1.2.6", + "tslint-no-toplevel-property-access": "0.0.2", "tslint-no-unused-expression-chai": "0.0.3", "typescript": "^3.0.1", "validate-commit-msg": "2.14.0", diff --git a/src/internal/observable/ConnectableObservable.ts b/src/internal/observable/ConnectableObservable.ts index 2f578293be4..4e7ffbfb133 100644 --- a/src/internal/observable/ConnectableObservable.ts +++ b/src/internal/observable/ConnectableObservable.ts @@ -55,19 +55,20 @@ export class ConnectableObservable extends Observable { } } -const connectableProto = ConnectableObservable.prototype; - -export const connectableObservableDescriptor: PropertyDescriptorMap = { - operator: { value: null }, - _refCount: { value: 0, writable: true }, - _subject: { value: null, writable: true }, - _connection: { value: null, writable: true }, - _subscribe: { value: connectableProto._subscribe }, - _isComplete: { value: connectableProto._isComplete, writable: true }, - getSubject: { value: connectableProto.getSubject }, - connect: { value: connectableProto.connect }, - refCount: { value: connectableProto.refCount } -}; +export const connectableObservableDescriptor: PropertyDescriptorMap = (() => { + const connectableProto = ConnectableObservable.prototype; + return { + operator: { value: null as null }, + _refCount: { value: 0, writable: true }, + _subject: { value: null as null, writable: true }, + _connection: { value: null as null, writable: true }, + _subscribe: { value: connectableProto._subscribe }, + _isComplete: { value: connectableProto._isComplete, writable: true }, + getSubject: { value: connectableProto.getSubject }, + connect: { value: connectableProto.connect }, + refCount: { value: connectableProto.refCount } + }; +})(); class ConnectableSubscriber extends SubjectSubscriber { constructor(destination: Subject, diff --git a/src/internal/observable/dom/AjaxObservable.ts b/src/internal/observable/dom/AjaxObservable.ts index 662b8e87016..d1f3f91849a 100644 --- a/src/internal/observable/dom/AjaxObservable.ts +++ b/src/internal/observable/dom/AjaxObservable.ts @@ -486,19 +486,21 @@ export interface AjaxErrorCtor { new(message: string, xhr: XMLHttpRequest, request: AjaxRequest): AjaxError; } -function AjaxErrorImpl(this: any, message: string, xhr: XMLHttpRequest, request: AjaxRequest): AjaxError { - Error.call(this); - this.message = message; - this.name = 'AjaxError'; - this.xhr = xhr; - this.request = request; - this.status = xhr.status; - this.responseType = xhr.responseType || request.responseType; - this.response = parseXhrResponse(this.responseType, xhr); - return this; -} - -AjaxErrorImpl.prototype = Object.create(Error.prototype); +const AjaxErrorImpl = (() => { + function AjaxErrorImpl(this: any, message: string, xhr: XMLHttpRequest, request: AjaxRequest): AjaxError { + Error.call(this); + this.message = message; + this.name = 'AjaxError'; + this.xhr = xhr; + this.request = request; + this.status = xhr.status; + this.responseType = xhr.responseType || request.responseType; + this.response = parseXhrResponse(this.responseType, xhr); + return this; + } + AjaxErrorImpl.prototype = Object.create(Error.prototype); + return AjaxErrorImpl; +})(); export const AjaxError: AjaxErrorCtor = AjaxErrorImpl as any; diff --git a/src/internal/observable/dom/ajax.ts b/src/internal/observable/dom/ajax.ts index 059de0ab582..d0885c1db13 100644 --- a/src/internal/observable/dom/ajax.ts +++ b/src/internal/observable/dom/ajax.ts @@ -79,4 +79,4 @@ import { AjaxObservable, AjaxCreationMethod } from './AjaxObservable'; * * ``` */ -export const ajax: AjaxCreationMethod = AjaxObservable.create; +export const ajax: AjaxCreationMethod = (() => AjaxObservable.create)(); diff --git a/src/internal/observable/fromEvent.ts b/src/internal/observable/fromEvent.ts index e69d127f677..015f56ccbb1 100644 --- a/src/internal/observable/fromEvent.ts +++ b/src/internal/observable/fromEvent.ts @@ -4,7 +4,7 @@ import { isFunction } from '../util/isFunction'; import { Subscriber } from '../Subscriber'; import { map } from '../operators/map'; -const toString: Function = Object.prototype.toString; +const toString: Function = (() => Object.prototype.toString)(); export interface NodeStyleEventEmitter { addListener: (eventName: string | symbol, handler: NodeEventHandler) => this; diff --git a/src/internal/symbol/observable.ts b/src/internal/symbol/observable.ts index 02cbaaca3c5..a321d71f683 100644 --- a/src/internal/symbol/observable.ts +++ b/src/internal/symbol/observable.ts @@ -8,4 +8,4 @@ declare global { } /** Symbol.observable or a string "@@observable". Used for interop */ -export const observable = typeof Symbol === 'function' && Symbol.observable || '@@observable'; +export const observable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')(); diff --git a/src/internal/symbol/rxSubscriber.ts b/src/internal/symbol/rxSubscriber.ts index 9a40544bd38..3a558e30b5f 100644 --- a/src/internal/symbol/rxSubscriber.ts +++ b/src/internal/symbol/rxSubscriber.ts @@ -1,8 +1,8 @@ /** @deprecated do not use, this is no longer checked by RxJS internals */ -export const rxSubscriber = +export const rxSubscriber = (() => typeof Symbol === 'function' ? Symbol('rxSubscriber') - : '@@rxSubscriber_' + Math.random(); + : '@@rxSubscriber_' + Math.random())(); /** * @deprecated use rxSubscriber instead diff --git a/src/internal/util/ArgumentOutOfRangeError.ts b/src/internal/util/ArgumentOutOfRangeError.ts index 949bfcc9da4..b9bd72d1d17 100644 --- a/src/internal/util/ArgumentOutOfRangeError.ts +++ b/src/internal/util/ArgumentOutOfRangeError.ts @@ -5,14 +5,18 @@ export interface ArgumentOutOfRangeErrorCtor { new(): ArgumentOutOfRangeError; } -function ArgumentOutOfRangeErrorImpl(this: any) { - Error.call(this); - this.message = 'argument out of range'; - this.name = 'ArgumentOutOfRangeError'; - return this; -} +const ArgumentOutOfRangeErrorImpl = (() => { + function ArgumentOutOfRangeErrorImpl(this: any) { + Error.call(this); + this.message = 'argument out of range'; + this.name = 'ArgumentOutOfRangeError'; + return this; + } + + ArgumentOutOfRangeErrorImpl.prototype = Object.create(Error.prototype); -ArgumentOutOfRangeErrorImpl.prototype = Object.create(Error.prototype); + return ArgumentOutOfRangeErrorImpl; +})(); /** * An error thrown when an element was queried at a certain index of an diff --git a/src/internal/util/EmptyError.ts b/src/internal/util/EmptyError.ts index 6dacfc6aa8a..6eb1d0761d5 100644 --- a/src/internal/util/EmptyError.ts +++ b/src/internal/util/EmptyError.ts @@ -5,14 +5,18 @@ export interface EmptyErrorCtor { new(): EmptyError; } -function EmptyErrorImpl(this: any) { - Error.call(this); - this.message = 'no elements in sequence'; - this.name = 'EmptyError'; - return this; -} +const EmptyErrorImpl = (() => { + function EmptyErrorImpl(this: any) { + Error.call(this); + this.message = 'no elements in sequence'; + this.name = 'EmptyError'; + return this; + } + + EmptyErrorImpl.prototype = Object.create(Error.prototype); -EmptyErrorImpl.prototype = Object.create(Error.prototype); + return EmptyErrorImpl; +})(); /** * An error thrown when an Observable or a sequence was queried but has no diff --git a/src/internal/util/ObjectUnsubscribedError.ts b/src/internal/util/ObjectUnsubscribedError.ts index e068c543472..45d20664453 100644 --- a/src/internal/util/ObjectUnsubscribedError.ts +++ b/src/internal/util/ObjectUnsubscribedError.ts @@ -5,14 +5,18 @@ export interface ObjectUnsubscribedErrorCtor { new(): ObjectUnsubscribedError; } -function ObjectUnsubscribedErrorImpl(this: any) { - Error.call(this); - this.message = 'object unsubscribed'; - this.name = 'ObjectUnsubscribedError'; - return this; -} +const ObjectUnsubscribedErrorImpl = (() => { + function ObjectUnsubscribedErrorImpl(this: any) { + Error.call(this); + this.message = 'object unsubscribed'; + this.name = 'ObjectUnsubscribedError'; + return this; + } + + ObjectUnsubscribedErrorImpl.prototype = Object.create(Error.prototype); -ObjectUnsubscribedErrorImpl.prototype = Object.create(Error.prototype); + return ObjectUnsubscribedErrorImpl; +})(); /** * An error thrown when an action is invalid because the object has been diff --git a/src/internal/util/TimeoutError.ts b/src/internal/util/TimeoutError.ts index 3c654276a37..fd0ae502578 100644 --- a/src/internal/util/TimeoutError.ts +++ b/src/internal/util/TimeoutError.ts @@ -5,14 +5,18 @@ export interface TimeoutErrorCtor { new(): TimeoutError; } -function TimeoutErrorImpl(this: any) { - Error.call(this); - this.message = 'Timeout has occurred'; - this.name = 'TimeoutError'; - return this; -} +const TimeoutErrorImpl = (() => { + function TimeoutErrorImpl(this: any) { + Error.call(this); + this.message = 'Timeout has occurred'; + this.name = 'TimeoutError'; + return this; + } + + TimeoutErrorImpl.prototype = Object.create(Error.prototype); -TimeoutErrorImpl.prototype = Object.create(Error.prototype); + return TimeoutErrorImpl; +})(); /** * An error thrown when duetime elapses. diff --git a/src/internal/util/UnsubscriptionError.ts b/src/internal/util/UnsubscriptionError.ts index 293b9678a90..02f1a0d8ece 100644 --- a/src/internal/util/UnsubscriptionError.ts +++ b/src/internal/util/UnsubscriptionError.ts @@ -6,17 +6,21 @@ export interface UnsubscriptionErrorCtor { new(errors: any[]): UnsubscriptionError; } -function UnsubscriptionErrorImpl(this: any, errors: any[]) { - Error.call(this); - this.message = errors ? - `${errors.length} errors occurred during unsubscription: +const UnsubscriptionErrorImpl = (() => { + function UnsubscriptionErrorImpl(this: any, errors: any[]) { + Error.call(this); + this.message = errors ? + `${errors.length} errors occurred during unsubscription: ${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join('\n ')}` : ''; - this.name = 'UnsubscriptionError'; - this.errors = errors; - return this; -} + this.name = 'UnsubscriptionError'; + this.errors = errors; + return this; + } + + UnsubscriptionErrorImpl.prototype = Object.create(Error.prototype); -UnsubscriptionErrorImpl.prototype = Object.create(Error.prototype); + return UnsubscriptionErrorImpl; +})(); /** * An error thrown when one or more errors have occurred during the diff --git a/src/internal/util/isArray.ts b/src/internal/util/isArray.ts index a6bb48acf7f..092f8a2ad80 100644 --- a/src/internal/util/isArray.ts +++ b/src/internal/util/isArray.ts @@ -1 +1 @@ -export const isArray = Array.isArray || ((x: any): x is T[] => x && typeof x.length === 'number'); +export const isArray = (() => Array.isArray || ((x: any): x is T[] => x && typeof x.length === 'number'))(); diff --git a/tslint.json b/tslint.json index ed853108b78..aafdd71ac8a 100644 --- a/tslint.json +++ b/tslint.json @@ -22,8 +22,6 @@ "no-var-keyword": true, "no-empty": true, "no-unused-expression-chai": true, - "no-unused-variable": true, - "no-use-before-declare": true, "no-var-requires": true, "no-require-imports": true, "one-line": [ @@ -59,9 +57,21 @@ "check-operator", "check-separator", "check-type" + ], + "no-toplevel-property-access": [ + true, + "src/index.ts", + "src/ajax/", + "src/fetch/", + "src/internal/", + "src/internal-compatibility/", + "src/operators/", + "src/testing/", + "src/webSocket/" ] }, "rulesDirectory": [ - "tslint-no-unused-expression-chai" + "tslint-no-unused-expression-chai", + "node_modules/tslint-no-toplevel-property-access/rules" ] } \ No newline at end of file