Skip to content

Commit 94e6ca4

Browse files
committed
[Fix] Map/Set: work around core-js bug < v2.5.0
Fixes #9
1 parent 7345a0a commit 94e6ca4

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
4141
else if (indexOf(seen, obj) >= 0) {
4242
return '[Circular]';
4343
}
44-
44+
4545
function inspect (value, from) {
4646
if (from) {
4747
seen = seen.slice();
@@ -154,7 +154,12 @@ function isMap (x) {
154154
}
155155
try {
156156
mapSize.call(x);
157-
return true;
157+
try {
158+
setSize.call(x);
159+
} catch (s) {
160+
return true;
161+
}
162+
return x instanceof Map; // core-js workaround, pre-v2.5.0
158163
} catch (e) {}
159164
return false;
160165
}
@@ -165,7 +170,12 @@ function isSet (x) {
165170
}
166171
try {
167172
setSize.call(x);
168-
return true;
173+
try {
174+
mapSize.call(x);
175+
} catch (m) {
176+
return true;
177+
}
178+
return x instanceof Set; // core-js workaround, pre-v2.5.0
169179
} catch (e) {}
170180
return false;
171181
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
"description": "string representations of objects in node and the browser",
55
"main": "index.js",
66
"devDependencies": {
7+
"core-js": "^2.4.1",
78
"tape": "^4.7.0"
89
},
910
"scripts": {
1011
"test": "npm run tests-only",
12+
"pretests-only": "node test-core-js",
1113
"tests-only": "tape test/*.js"
1214
},
1315
"testling": {

test-core-js.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
require('core-js');
4+
5+
var inspect = require('./');
6+
var test = require('tape');
7+
8+
test('Maps', function (t) {
9+
t.equal(inspect(new Map([[1, 2]])), 'Map (1) {1 => 2}');
10+
t.end();
11+
});
12+
13+
test('Sets', function (t) {
14+
t.equal(inspect(new Set([[1, 2]])), 'Set (1) {[ 1, 2 ]}');
15+
t.end();
16+
});

0 commit comments

Comments
 (0)