Skip to content

Commit 1299a7c

Browse files
committed
Merge pull request immutable-js#391 from wmertens/jsonstringkeys
toString(): Print keys in JSON
2 parents 6b60746 + a102ada commit 1299a7c

File tree

4 files changed

+59
-40
lines changed

4 files changed

+59
-40
lines changed

__tests__/Conversion.ts

+18-11
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,30 @@ describe('Conversion', () => {
9898
});
9999

100100
var immutableOrderedDataString = 'OrderedMap { ' +
101-
'deepList: List [ '+
101+
'"deepList": List [ '+
102102
'OrderedMap { '+
103-
'position: "first"'+
103+
'"position": "first"'+
104104
' }, ' +
105105
'OrderedMap { '+
106-
'position: "second"'+
106+
'"position": "second"'+
107107
' }, '+
108108
'OrderedMap { '+
109-
'position: "third"'+
109+
'"position": "third"'+
110110
' }' +
111111
' ], '+
112-
'deepMap: OrderedMap { '+
113-
'a: "A", '+
114-
'b: "B"'+
112+
'"deepMap": OrderedMap { '+
113+
'"a": "A", '+
114+
'"b": "B"'+
115115
' }, '+
116-
'emptyMap: OrderedMap {}, ' +
117-
'point: Point { x: 10, y: 20 }, '+
118-
'string: "Hello", '+
119-
'list: List [ 1, 2, 3 ]'+
116+
'"emptyMap": OrderedMap {}, ' +
117+
'"point": Point { "x": 10, "y": 20 }, '+
118+
'"string": "Hello", '+
119+
'"list": List [ 1, 2, 3 ]'+
120120
' }';
121121

122+
var nonStringKeyMap = OrderedMap().set(1, true).set(false, "foo");
123+
var nonStringKeyMapString = 'OrderedMap { 1: true, false: "foo" }';
124+
122125
it('Converts deep JS to deep immutable sequences', () => {
123126
expect(Immutable.fromJS(js)).is(immutableData);
124127
});
@@ -134,6 +137,10 @@ describe('Conversion', () => {
134137
expect(seq.toString()).is(immutableOrderedDataString);
135138
});
136139

140+
it('Prints keys as JSON values', () => {
141+
expect(nonStringKeyMap.toString()).is(nonStringKeyMapString);
142+
});
143+
137144
it('Converts deep sequences to JSON', () => {
138145
var json = immutableData.toJS();
139146
expect(json).not.is(js); // raw JS is not immutable.

dist/immutable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4600,7 +4600,7 @@
46004600
KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
46014601
KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
46024602
KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
4603-
KeyedIterablePrototype.__toStringMapper = function(v, k) {return k + ': ' + quoteString(v)};
4603+
KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
46044604

46054605

46064606

0 commit comments

Comments
 (0)