Skip to content

Commit 290c2a0

Browse files
committed
Add support for .[0] syntax
1 parent ed61309 commit 290c2a0

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@
4646
"node": ">=8"
4747
},
4848
"dependencies": {
49-
"@medv/blessed": "^2.0.0",
49+
"@medv/blessed": "^2.0.1",
5050
"chalk": "^3.0.0",
5151
"indent-string": "^4.0.0",
5252
"lossless-json": "^1.0.3",
5353
"string-width": "^4.2.0"
5454
},
5555
"devDependencies": {
5656
"ava": "^2.4.0",
57-
"pkg": "^4.4.1",
57+
"pkg": "^4.4.2",
5858
"release-it": "^12.4.3"
5959
}
6060
}

reduce.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
'use strict'
22

33
function reduce(json, code) {
4-
if (/^\./.test(code)) {
5-
const fx = eval(`function fn() {
6-
return ${code === '.' ? 'this' : 'this' + code}
7-
}; fn`)
8-
return fx.call(json)
4+
if ('.' === code) {
5+
return json
96
}
107

118
if ('?' === code) {
129
return Object.keys(json)
1310
}
1411

15-
const fx = eval(`function fn() {
12+
if (/^\.\[/.test(code)) {
13+
return eval(`function fn() {
14+
return this${code.substring(1)}
15+
}; fn`).call(json)
16+
}
17+
18+
if (/^\./.test(code)) {
19+
return eval(`function fn() {
20+
return this${code}
21+
}; fn`).call(json)
22+
}
23+
24+
const fn = eval(`function fn() {
1625
return ${code}
17-
}; fn`)
26+
}; fn`).call(json)
1827

19-
const fn = fx.call(json)
2028
if (typeof fn === 'function') {
2129
return fn(json)
2230
}

0 commit comments

Comments
 (0)