3 Object.defineProperty(exports, '__esModule', {
6 exports.test = exports.serialize = undefined;
8 var _collections = require('../collections');
10 // SENTINEL constants are from https://github.com/facebook/immutable-js
12 * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
14 * This source code is licensed under the MIT license found in the
15 * LICENSE file in the root directory of this source tree.
20 const IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
21 const IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
22 const IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
23 const IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
24 const IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
25 const IS_RECORD_SENTINEL = '@@__IMMUTABLE_RECORD__@@'; // immutable v4
26 const IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
27 const IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
28 const IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
30 const getImmutableName = name => 'Immutable.' + name;
31 const printAsLeaf = name => '[' + name + ']';
33 const LAZY = '…'; // Seq is lazy if it calls a method like filter
35 const printImmutableEntries = (
44 ++depth > config.maxDepth
45 ? printAsLeaf(getImmutableName(type))
46 : getImmutableName(type) +
49 (0, _collections.printIteratorEntries)(
59 // Record has an entries method because it is a collection in immutable v3.
60 // Return an iterator for Immutable Record from version v3 or v4.
61 const getRecordEntries = val => {
65 if (i < val._keys.length) {
66 const key = val._keys[i++];
67 return {done: false, value: [key, val.get(key)]};
74 const printImmutableRecord = (
82 // _name property is defined only for an Immutable Record instance
83 // which was constructed with a second optional descriptive name arg
84 const name = getImmutableName(val._name || 'Record');
85 return ++depth > config.maxDepth
90 (0, _collections.printIteratorEntries)(
91 getRecordEntries(val),
101 const printImmutableSeq = (val, config, indentation, depth, refs, printer) => {
102 const name = getImmutableName('Seq');
104 if (++depth > config.maxDepth) {
105 return printAsLeaf(name);
108 if (val[IS_KEYED_SENTINEL]) {
113 // from Immutable collection of entries or from ECMAScript object
114 (val._iter || val._object
115 ? (0, _collections.printIteratorEntries)(
132 (val._iter || // from Immutable collection of values
133 val._array || // from ECMAScript array
134 val._collection || // from ECMAScript collection in immutable v4
135 val._iterable // from ECMAScript collection in immutable v3
136 ? (0, _collections.printIteratorValues)(
149 const printImmutableValues = (
158 ++depth > config.maxDepth
159 ? printAsLeaf(getImmutableName(type))
160 : getImmutableName(type) +
163 (0, _collections.printIteratorValues)(
173 const serialize = (exports.serialize = (
181 if (val[IS_MAP_SENTINEL]) {
182 return printImmutableEntries(
189 val[IS_ORDERED_SENTINEL] ? 'OrderedMap' : 'Map'
193 if (val[IS_LIST_SENTINEL]) {
194 return printImmutableValues(
204 if (val[IS_SET_SENTINEL]) {
205 return printImmutableValues(
212 val[IS_ORDERED_SENTINEL] ? 'OrderedSet' : 'Set'
215 if (val[IS_STACK_SENTINEL]) {
216 return printImmutableValues(
227 if (val[IS_SEQ_SENTINEL]) {
228 return printImmutableSeq(val, config, indentation, depth, refs, printer);
231 // For compatibility with immutable v3 and v4, let record be the default.
232 return printImmutableRecord(val, config, indentation, depth, refs, printer);
235 // Explicitly comparing sentinel properties to true avoids false positive
236 // when mock identity-obj-proxy returns the key as the value for any key.
237 const test = (exports.test = val =>
239 (val[IS_ITERABLE_SENTINEL] === true || val[IS_RECORD_SENTINEL] === true));
241 exports.default = {serialize: serialize, test: test};