Skip to content

Commit 1d3852f

Browse files
authored
Merge pull request #407 from vans163/bugfix_map_to_object
bugfix map_to_object
2 parents 1c64205 + 33ee0a4 commit 1d3852f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/javascript/lib/core/functions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ function object_to_map(object, options = []) {
130130
key2 = Symbol.for(key);
131131
}
132132

133-
if (value.constructor === Object || (value instanceof Array && opt_recurse_array)) {
133+
if (value !== null && (value.constructor === Object || (value instanceof Array && opt_recurse_array))) {
134134
value = object_to_map(value, options);
135135
}
136136
map.set(key2, value);
137137
});
138138
return map;
139139
} else if (object instanceof Array && opt_recurse_array) {
140140
return object.map((ele) => {
141-
if (ele.constructor === Object || ele instanceof Array) {
141+
if (ele !== null && (ele.constructor === Object || ele instanceof Array)) {
142142
return object_to_map(ele, options);
143143
}
144144
return ele;

src/javascript/tests/core/functions.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ test('object_to_map/1', (t) => {
4646
let result = Functions.object_to_map(obj);
4747
t.deepEqual(result, new Map());
4848

49-
obj = { key: 'value' };
49+
obj = { key: 'value', key2: null };
5050
result = Functions.object_to_map(obj);
51-
t.deepEqual(result, new Map([['key', 'value']]));
51+
t.deepEqual(result, new Map([['key', 'value'], ['key2', null]]));
5252

5353
obj = {};
5454
obj[Symbol.for('key')] = 'value';

0 commit comments

Comments
 (0)