lambdajson-js 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/js-compiler.js +16 -2
- package/src/primitives.js +1 -0
package/package.json
CHANGED
package/src/js-compiler.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isObject, isString, map, get, find, mapValues, isArray, every } from 'lodash-es'
|
|
1
|
+
import { isObject, isString, map, get, find, mapValues, isArray, every, has } from 'lodash-es'
|
|
2
2
|
import { primitives } from './primitives.js';
|
|
3
3
|
|
|
4
4
|
export {
|
|
@@ -30,8 +30,12 @@ function compileTree(primitives, tree) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const varsDeclarationKey = '$let';
|
|
33
|
+
const valueDeclarationKey = '$literal';
|
|
33
34
|
|
|
34
35
|
function compilePrimitive(primitives, tree) {
|
|
36
|
+
if (has(tree, valueDeclarationKey)) {
|
|
37
|
+
return _ => tree[valueDeclarationKey];
|
|
38
|
+
}
|
|
35
39
|
const keys = Object.keys(tree);
|
|
36
40
|
const getLocalVars = compileVars(primitives, tree[varsDeclarationKey]);
|
|
37
41
|
const primitiveKey = find(keys, k => k !== varsDeclarationKey);
|
|
@@ -102,10 +106,20 @@ function compileVars(primitives, obj) {
|
|
|
102
106
|
|
|
103
107
|
function compileObject(primitives, obj) {
|
|
104
108
|
const funks = mapValues(obj, n => compileTree(primitives, n));
|
|
105
|
-
return x =>
|
|
109
|
+
return x => {
|
|
110
|
+
const result = {};
|
|
111
|
+
for (const key in funks) {
|
|
112
|
+
const pKey = key.startsWith('\\') ? key.slice(1) : key;
|
|
113
|
+
result[pKey] = funks[key](x);
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
};
|
|
106
117
|
}
|
|
107
118
|
|
|
108
119
|
function compileString(str) {
|
|
120
|
+
if (str.startsWith('\\')) {
|
|
121
|
+
return () => str.slice(1);
|
|
122
|
+
}
|
|
109
123
|
if (str === '#') {
|
|
110
124
|
return ({ input }) => input;
|
|
111
125
|
}
|