Skip to content

Commit

Permalink
feat: implement optional chaining/projection
Browse files Browse the repository at this point in the history
  • Loading branch information
kantord committed Oct 24, 2018
1 parent cd6d083 commit 04eeeac
Show file tree
Hide file tree
Showing 11 changed files with 337 additions and 57 deletions.
174 changes: 166 additions & 8 deletions src/__tests__/__snapshots__/interpreter.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ exports[`interpreter correct target code $ 1`] = `"(function(_) { return (functi

exports[`interpreter correct target code $ 2`] = `"(function(_) { return (function(input) { return input})})"`;

exports[`interpreter correct target code $.uno?.dos?.tres 1`] = `"(function(_) { return (function(input) { return _.__opt__(_.__opt__(input.uno, function(x) {return x.dos}), function(x) {return x.tres})})})"`;

exports[`interpreter correct target code $?[3] 1`] = `"(function(_) { return (function(input) { return _.projection(input, [3], true)})})"`;

exports[`interpreter correct target code $?[3] 2`] = `"(function(_) { return (function(input) { return _.projection(input, [3], true)})})"`;

exports[`interpreter correct target code ($x + $foobar | [$, $foobar]) where $x = 3 $foobar = ($x + 1) 1`] = `"(function(_) { return (function(input) { return ((function() {_ = _.assign('x', (3), _); _ = _.assign('foobar', ((_.get('x')+1)), _); return (((function (input) {return [input, _.get('foobar')]})(_.get('x')+_.get('foobar'))))})())})})"`;

exports[`interpreter correct target code ([1, 2] | foo) where $foo = $reverse 1`] = `"(function(_) { return (function(input) { return ((function() {_ = _.assign('foo', (_.get('reverse')), _); return (((function (input) {return _.foo(input)})([1, 2])))})())})})"`;

exports[`interpreter correct target code ([1] | foo 4) where $foo = ($ => $ => 4) 1`] = `"(function(_) { return (function(input) { return ((function() {_ = _.assign('foo', (((function(input) {return (function(input) {return 4})}))), _); return (((function (input) {return _.foo(4)(input)})([1])))})())})})"`;

exports[`interpreter correct target code ([1] | map $foo | $[0]) where $foo = ($ => 4) 1`] = `"(function(_) { return (function(input) { return ((function() {_ = _.assign('foo', (((function(input) {return 4}))), _); return (((function (input) {return (function (input) {return _.projection(input, [0])})(_.map(_.get('foo'))(input))})([1])))})())})})"`;
exports[`interpreter correct target code ([1] | map $foo | $[0]) where $foo = ($ => 4) 1`] = `"(function(_) { return (function(input) { return ((function() {_ = _.assign('foo', (((function(input) {return 4}))), _); return (((function (input) {return (function (input) {return _.projection(input, [0], false)})(_.map(_.get('foo'))(input))})([1])))})())})})"`;

exports[`interpreter correct target code (3 + $foobar | [$, $foobar]) where $foobar = $ 1`] = `"(function(_) { return (function(input) { return ((function() {_ = _.assign('foobar', (input), _); return (((function (input) {return [input, _.get('foobar')]})(3+_.get('foobar'))))})())})})"`;

Expand All @@ -40,19 +46,19 @@ exports[`interpreter correct target code .foo | .bar 1`] = `"(function(_) { retu

exports[`interpreter correct target code [[false], [true, null]] 1`] = `"(function(_) { return (function(input) { return [[false], [true, null]]})})"`;

exports[`interpreter correct target code [0,1,"foo"][1,2][1,1][0] 1`] = `"(function(_) { return (function(input) { return _.projection(_.projection(_.projection([0, 1, \\"foo\\"], [1, 2]), [1, 1]), [0])})})"`;
exports[`interpreter correct target code [0,1,"foo"][1,2][1,1][0] 1`] = `"(function(_) { return (function(input) { return _.projection(_.projection(_.projection([0, 1, \\"foo\\"], [1, 2], false), [1, 1], false), [0], false)})})"`;

exports[`interpreter correct target code [0,1,2][1,2][1,1][0] 1`] = `"(function(_) { return (function(input) { return _.projection(_.projection(_.projection([0, 1, 2], [1, 2]), [1, 1]), [0])})})"`;
exports[`interpreter correct target code [0,1,2][1,2][1,1][0] 1`] = `"(function(_) { return (function(input) { return _.projection(_.projection(_.projection([0, 1, 2], [1, 2], false), [1, 1], false), [0], false)})})"`;

exports[`interpreter correct target code [0.14, true, "true 2"] 1`] = `"(function(_) { return (function(input) { return [0.14, true, \\"true 2\\"]})})"`;

exports[`interpreter correct target code [1, ...$, 3, ...$] 1`] = `"(function(_) { return (function(input) { return [1].concat(input).concat([3]).concat(input)})})"`;

exports[`interpreter correct target code [3, 2][0] : [3, 2][1] 1`] = `"(function(_) { return (function(input) { return [_.projection([3, 2], [0]),_.projection([3, 2], [1])]})})"`;
exports[`interpreter correct target code [3, 2][0] : [3, 2][1] 1`] = `"(function(_) { return (function(input) { return [_.projection([3, 2], [0], false),_.projection([3, 2], [1], false)]})})"`;

exports[`interpreter correct target code [3, 2][0] | [3, 2][1] 1`] = `"(function(_) { return (function(input) { return (function (input) {return _.projection([3, 2], [1])})(_.projection([3, 2], [0]))})})"`;
exports[`interpreter correct target code [3, 2][0] | [3, 2][1] 1`] = `"(function(_) { return (function(input) { return (function (input) {return _.projection([3, 2], [1], false)})(_.projection([3, 2], [0], false))})})"`;

exports[`interpreter correct target code [3, 2][0] 1`] = `"(function(_) { return (function(input) { return _.projection([3, 2], [0])})})"`;
exports[`interpreter correct target code [3, 2][0] 1`] = `"(function(_) { return (function(input) { return _.projection([3, 2], [0], false)})})"`;

exports[`interpreter correct target code {
"foo": [-42, $],
Expand All @@ -63,9 +69,9 @@ exports[`interpreter correct target code {

exports[`interpreter correct target code {"foo": ("bar" | "baz")} 1`] = `"(function(_) { return (function(input) { return (_.objectify([[\\"foo\\",((function (input) {return \\"baz\\"})(\\"bar\\"))]]))})})"`;

exports[`interpreter correct target code {"foo": ("bar" | "baz")}["foo"] 1`] = `"(function(_) { return (function(input) { return _.projection((_.objectify([[\\"foo\\",((function (input) {return \\"baz\\"})(\\"bar\\"))]])), [\\"foo\\"])})})"`;
exports[`interpreter correct target code {"foo": ("bar" | "baz")}["foo"] 1`] = `"(function(_) { return (function(input) { return _.projection((_.objectify([[\\"foo\\",((function (input) {return \\"baz\\"})(\\"bar\\"))]])), [\\"foo\\"], false)})})"`;

exports[`interpreter correct target code {"foo": [{"bar": "baz"}]} | $.foo[0].bar 1`] = `"(function(_) { return (function(input) { return (function (input) {return _.projection(input.foo, [0]).bar})((_.objectify([[\\"foo\\",[(_.objectify([[\\"bar\\",\\"baz\\"]]))]]])))})})"`;
exports[`interpreter correct target code {"foo": [{"bar": "baz"}]} | $.foo[0].bar 1`] = `"(function(_) { return (function(input) { return (function (input) {return _.projection(input.foo, [0], false).bar})((_.objectify([[\\"foo\\",[(_.objectify([[\\"bar\\",\\"baz\\"]]))]]])))})})"`;

exports[`interpreter correct target code {"original": $.foo} | {"new": $} 1`] = `"(function(_) { return (function(input) { return (function (input) {return (_.objectify([[\\"new\\",input]]))})((_.objectify([[\\"original\\",input.foo]])))})})"`;

Expand Down Expand Up @@ -621,6 +627,137 @@ Object {
}
`;

exports[`interpreter correct target tree $.uno?.dos?.tres 1`] = `
Object {
"status": true,
"value": Object {
"name": "valueProp",
"value": Object {
"left": Object {
"name": "valueProp",
"value": Object {
"left": Object {
"name": "valueProp",
"value": Object {
"left": Object {
"name": "variable",
"value": "$",
},
"optional": false,
"right": ".uno",
},
},
"optional": true,
"right": ".dos",
},
},
"optional": true,
"right": ".tres",
},
},
}
`;

exports[`interpreter correct target tree $?[3] 1`] = `
Object {
"status": true,
"value": Object {
"name": "projection",
"value": Object {
"left": Object {
"name": "variable",
"value": "$",
},
"optional": true,
"right": Object {
"end": Object {
"column": 6,
"line": 1,
"offset": 5,
},
"name": "list",
"start": Object {
"column": 3,
"line": 1,
"offset": 2,
},
"value": Array [
Object {
"end": Object {
"column": 5,
"line": 1,
"offset": 4,
},
"name": "simpleList",
"start": Object {
"column": 4,
"line": 1,
"offset": 3,
},
"value": Array [
Object {
"name": "primitive",
"value": "3",
},
],
},
],
},
},
},
}
`;

exports[`interpreter correct target tree $?[3] 2`] = `
Object {
"status": true,
"value": Object {
"name": "projection",
"value": Object {
"left": Object {
"name": "variable",
"value": "$",
},
"optional": true,
"right": Object {
"end": Object {
"column": 6,
"line": 1,
"offset": 5,
},
"name": "list",
"start": Object {
"column": 3,
"line": 1,
"offset": 2,
},
"value": Array [
Object {
"end": Object {
"column": 5,
"line": 1,
"offset": 4,
},
"name": "simpleList",
"start": Object {
"column": 4,
"line": 1,
"offset": 3,
},
"value": Array [
Object {
"name": "primitive",
"value": "3",
},
],
},
],
},
},
},
}
`;

exports[`interpreter correct target tree ($x + $foobar | [$, $foobar]) where $x = 3 $foobar = ($x + 1) 1`] = `
Object {
"status": true,
Expand Down Expand Up @@ -1084,6 +1221,7 @@ Object {
"name": "variable",
"value": "$",
},
"optional": false,
"right": Object {
"end": Object {
"column": 23,
Expand Down Expand Up @@ -1462,6 +1600,7 @@ Object {
"name": "inputProp",
"value": ".apple",
},
"optional": false,
"right": ".pear",
},
},
Expand All @@ -1478,6 +1617,7 @@ Object {
"name": "inputProp",
"value": ".apple",
},
"optional": false,
"right": ".pear.bar",
},
},
Expand Down Expand Up @@ -1703,6 +1843,7 @@ Object {
},
],
},
"optional": false,
"right": Object {
"end": Object {
"column": 17,
Expand Down Expand Up @@ -1743,6 +1884,7 @@ Object {
},
},
},
"optional": false,
"right": Object {
"end": Object {
"column": 22,
Expand Down Expand Up @@ -1783,6 +1925,7 @@ Object {
},
},
},
"optional": false,
"right": Object {
"end": Object {
"column": 25,
Expand Down Expand Up @@ -1876,6 +2019,7 @@ Object {
},
],
},
"optional": false,
"right": Object {
"end": Object {
"column": 13,
Expand Down Expand Up @@ -1916,6 +2060,7 @@ Object {
},
},
},
"optional": false,
"right": Object {
"end": Object {
"column": 18,
Expand Down Expand Up @@ -1956,6 +2101,7 @@ Object {
},
},
},
"optional": false,
"right": Object {
"end": Object {
"column": 21,
Expand Down Expand Up @@ -2183,6 +2329,7 @@ Object {
},
],
},
"optional": false,
"right": Object {
"end": Object {
"column": 10,
Expand Down Expand Up @@ -2260,6 +2407,7 @@ Object {
},
],
},
"optional": false,
"right": Object {
"end": Object {
"column": 22,
Expand Down Expand Up @@ -2348,6 +2496,7 @@ Object {
},
],
},
"optional": false,
"right": Object {
"end": Object {
"column": 10,
Expand Down Expand Up @@ -2425,6 +2574,7 @@ Object {
},
],
},
"optional": false,
"right": Object {
"end": Object {
"column": 22,
Expand Down Expand Up @@ -2510,6 +2660,7 @@ Object {
},
],
},
"optional": false,
"right": Object {
"end": Object {
"column": 10,
Expand Down Expand Up @@ -2811,6 +2962,7 @@ Object {
},
],
},
"optional": false,
"right": Object {
"end": Object {
"column": 32,
Expand Down Expand Up @@ -2981,9 +3133,11 @@ Object {
"name": "variable",
"value": "$",
},
"optional": false,
"right": ".foo",
},
},
"optional": false,
"right": Object {
"end": Object {
"column": 37,
Expand Down Expand Up @@ -3020,6 +3174,7 @@ Object {
},
},
},
"optional": false,
"right": ".bar",
},
},
Expand Down Expand Up @@ -3074,6 +3229,7 @@ Object {
"name": "variable",
"value": "$",
},
"optional": false,
"right": ".foo",
},
},
Expand Down Expand Up @@ -4993,6 +5149,7 @@ Object {
"name": "variable",
"value": "$",
},
"optional": false,
"right": ".foo",
},
},
Expand Down Expand Up @@ -5082,6 +5239,7 @@ Object {
"name": "variable",
"value": "$",
},
"optional": false,
"right": ".foo",
},
},
Expand Down
Loading

0 comments on commit 04eeeac

Please sign in to comment.