Skip to content

Commit f3af629

Browse files
author
Nikolaus Piccolotto
committed
🚧 save wip
1 parent 01277e5 commit f3af629

9 files changed

Lines changed: 354 additions & 329 deletions

File tree

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
],
55
"plugins": [
66
"transform-es2015-spread",
7-
"transform-object-entries"
7+
"transform-object-entries",
8+
"transform-object-rest-spread"
89
]
910
}

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"node": true
55
},
66
"extends": "eslint:recommended",
7+
"parser": "babel-eslint",
78
"parserOptions": {
89
"sourceType": "module"
910
},

lib/regex.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ function catDeriv(regex, x) {
7474
})
7575
)
7676
);
77-
} else {
7877
}
7978

8079
return palt({
@@ -119,14 +118,16 @@ export function deriv(regex, x) {
119118
case cat:
120119
return catDeriv(regex, x);
121120
}
122-
throw new Error(`Cannot derive unknown operation "${symbolToString(op)}"`);
121+
throw new Error(
122+
`Cannot derive unknown operation "${symbolToString(regex.op)}"`
123+
);
123124
}
124125

125126
function getReturn(regex) {
126127
switch (regex.op) {
127128
case cat:
128129
const catProcessed = regex.ret.reduce(
129-
(agg, val) => Object.assign(agg, val),
130+
(agg, val) => ({ ...agg, ...val }),
130131
{}
131132
);
132133
// unprocessed values
@@ -305,10 +306,14 @@ function palt(opts = {}) {
305306
ks,
306307
ret
307308
};
309+
console.log(JSON.stringify(ps, null, 2));
308310
// if any of the alternatives is accepted, return that
309311
const acceptIdx = ps.findIndex(p => accepted(p));
310312
if (acceptIdx !== -1) {
311313
if (ks[acceptIdx]) {
314+
console.log(acceptIdx, {
315+
[ks[acceptIdx]]: ps[acceptIdx].ret
316+
});
312317
return accept({
313318
[ks[acceptIdx]]: ps[acceptIdx].ret
314319
});
@@ -370,7 +375,7 @@ export function maybeImpl(name, predicate) {
370375
throw new Error(`Must provide a predicate to maybe.`);
371376
}
372377
return palt({
373-
ps: [predicate, p.nil],
378+
ps: [p.nil, predicate],
374379
ks: [name, name]
375380
});
376381
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@
2828
"devDependencies": {
2929
"babel-cli": "^6.18.0",
3030
"babel-core": "^6.18.2",
31+
"babel-eslint": "7",
3132
"babel-istanbul": "^0.11.0",
3233
"babel-loader": "^6.2.7",
3334
"babel-plugin-transform-es2015-spread": "^6.8.0",
3435
"babel-plugin-transform-object-entries": "^1.0.0",
36+
"babel-plugin-transform-object-rest-spread": "^6.23.0",
3537
"babel-preset-es2015": "^6.18.0",
3638
"babel-register": "^6.18.0",
3739
"chai": "^3.5.0",
3840
"coveralls": "^2.11.14",
39-
"eslint": "^4.4.1",
41+
"eslint": "3.x",
4042
"eslint-plugin-prettier": "^2.1.2",
4143
"mocha": "^3.1.2",
4244
"nodemon": "^1.11.0",

test/regex/alt.test.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,21 @@ describe("alt", () => {
8484

8585
it("works with null/undefined", () => {
8686
// expect not nullable spec to be invalid for nil
87-
expect(conform(ingredient_part, [])).to.deep.equal(invalid)
88-
expect(conform(ingredient_part)).to.deep.equal(invalid)
87+
expect(conform(ingredient_part, [])).to.deep.equal(invalid);
88+
expect(conform(ingredient_part)).to.deep.equal(invalid);
8989

9090
// expect nullable spec to be valid for nil
91-
const nullable_alt = alt("value", p.number, "no value", p.nil)
91+
const nullable_alt = alt("value", p.number, "no value", p.nil);
9292
expect(conform(nullable_alt, null)).to.deep.equal({
9393
"no value": null
94-
})
94+
});
9595
expect(conform(nullable_alt)).to.deep.equal({
9696
"no value": null
97-
})
97+
});
9898
expect(conform(nullable_alt, 5)).to.deep.equal({
99-
"value": 5
100-
})
101-
102-
103-
})
99+
value: 5
100+
});
101+
});
104102

105103
it("works in happy nested case", () => {
106104
expect(

0 commit comments

Comments
 (0)