vega-interpreter 1.0.4 → 1.0.5
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/LICENSE +1 -1
- package/build/vega-interpreter.js +33 -40
- package/build/vega-interpreter.min.js +1 -1
- package/build/vega-interpreter.min.js.map +1 -1
- package/build/vega-interpreter.module.js +34 -37
- package/package.json +4 -3
- package/rollup.config.mjs +1 -0
- package/src/interpret.js +20 -2
- package/rollup.config.js +0 -1
package/LICENSE
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vega = global.vega || {}));
|
|
5
|
-
}(this, (function (exports) { 'use strict';
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function adjustSpatial (item, encode, swap) {
|
|
8
8
|
let t;
|
|
9
|
-
|
|
10
9
|
if (encode.x2) {
|
|
11
10
|
if (encode.x) {
|
|
12
11
|
if (swap && item.x > item.x2) {
|
|
@@ -14,17 +13,14 @@
|
|
|
14
13
|
item.x = item.x2;
|
|
15
14
|
item.x2 = t;
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
item.width = item.x2 - item.x;
|
|
19
17
|
} else {
|
|
20
18
|
item.x = item.x2 - (item.width || 0);
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
|
-
|
|
24
21
|
if (encode.xc) {
|
|
25
22
|
item.x = item.xc - (item.width || 0) / 2;
|
|
26
23
|
}
|
|
27
|
-
|
|
28
24
|
if (encode.y2) {
|
|
29
25
|
if (encode.y) {
|
|
30
26
|
if (swap && item.y > item.y2) {
|
|
@@ -32,13 +28,11 @@
|
|
|
32
28
|
item.y = item.y2;
|
|
33
29
|
item.y2 = t;
|
|
34
30
|
}
|
|
35
|
-
|
|
36
31
|
item.height = item.y2 - item.y;
|
|
37
32
|
} else {
|
|
38
33
|
item.y = item.y2 - (item.height || 0);
|
|
39
34
|
}
|
|
40
35
|
}
|
|
41
|
-
|
|
42
36
|
if (encode.yc) {
|
|
43
37
|
item.y = item.yc - (item.height || 0) / 2;
|
|
44
38
|
}
|
|
@@ -88,14 +82,11 @@
|
|
|
88
82
|
};
|
|
89
83
|
|
|
90
84
|
const slice = Array.prototype.slice;
|
|
91
|
-
|
|
92
85
|
const apply = (m, args, cast) => {
|
|
93
86
|
const obj = cast ? cast(args[0]) : args[0];
|
|
94
87
|
return obj[m].apply(obj, slice.call(args, 1));
|
|
95
88
|
};
|
|
96
|
-
|
|
97
89
|
const datetime = (y, m, d, H, M, S, ms) => new Date(y, m || 0, d != null ? d : 1, H || 0, M || 0, S || 0, ms || 0);
|
|
98
|
-
|
|
99
90
|
var Functions = {
|
|
100
91
|
// math functions
|
|
101
92
|
isNaN: Number.isNaN,
|
|
@@ -177,6 +168,8 @@
|
|
|
177
168
|
};
|
|
178
169
|
|
|
179
170
|
const EventFunctions = ['view', 'item', 'group', 'xy', 'x', 'y'];
|
|
171
|
+
const DisallowedMethods = new Set([Function, eval, setTimeout, setInterval]);
|
|
172
|
+
if (typeof setImmediate === 'function') DisallowedMethods.add(setImmediate);
|
|
180
173
|
const Visitors = {
|
|
181
174
|
Literal: ($, n) => n.value,
|
|
182
175
|
Identifier: ($, n) => {
|
|
@@ -185,22 +178,28 @@
|
|
|
185
178
|
},
|
|
186
179
|
MemberExpression: ($, n) => {
|
|
187
180
|
const d = !n.computed,
|
|
188
|
-
|
|
181
|
+
o = $(n.object);
|
|
189
182
|
if (d) $.memberDepth += 1;
|
|
190
183
|
const p = $(n.property);
|
|
191
184
|
if (d) $.memberDepth -= 1;
|
|
185
|
+
if (DisallowedMethods.has(o[p])) {
|
|
186
|
+
// eslint-disable-next-line no-console
|
|
187
|
+
console.error(`Prevented interpretation of member "${p}" which could lead to insecure code execution`);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
192
190
|
return o[p];
|
|
193
191
|
},
|
|
194
192
|
CallExpression: ($, n) => {
|
|
195
193
|
const args = n.arguments;
|
|
196
|
-
let name = n.callee.name;
|
|
197
|
-
// re-route to corresponding standard function
|
|
194
|
+
let name = n.callee.name;
|
|
198
195
|
|
|
196
|
+
// handle special internal functions used by encoders
|
|
197
|
+
// re-route to corresponding standard function
|
|
199
198
|
if (name.startsWith('_')) {
|
|
200
199
|
name = name.slice(1);
|
|
201
|
-
}
|
|
202
|
-
|
|
200
|
+
}
|
|
203
201
|
|
|
202
|
+
// special case "if" due to conditional evaluation of branches
|
|
204
203
|
return name === 'if' ? $(args[0]) ? $(args[1]) : $(args[2]) : ($.fn[name] || Functions[name]).apply($.fn, args.map($));
|
|
205
204
|
},
|
|
206
205
|
ArrayExpression: ($, n) => n.elements.map($),
|
|
@@ -212,20 +211,25 @@
|
|
|
212
211
|
$.memberDepth += 1;
|
|
213
212
|
const k = $(p.key);
|
|
214
213
|
$.memberDepth -= 1;
|
|
215
|
-
|
|
214
|
+
if (DisallowedMethods.has($(p.value))) {
|
|
215
|
+
// eslint-disable-next-line no-console
|
|
216
|
+
console.error(`Prevented interpretation of property "${k}" which could lead to insecure code execution`);
|
|
217
|
+
} else {
|
|
218
|
+
o[k] = $(p.value);
|
|
219
|
+
}
|
|
216
220
|
return o;
|
|
217
221
|
}, {})
|
|
218
222
|
};
|
|
219
223
|
function interpret (ast, fn, params, datum, event, item) {
|
|
220
224
|
const $ = n => Visitors[n.type]($, n);
|
|
221
|
-
|
|
222
225
|
$.memberDepth = 0;
|
|
223
226
|
$.fn = Object.create(fn);
|
|
224
227
|
$.params = params;
|
|
225
228
|
$.datum = datum;
|
|
226
229
|
$.event = event;
|
|
227
|
-
$.item = item;
|
|
230
|
+
$.item = item;
|
|
228
231
|
|
|
232
|
+
// route event functions to annotated vega event context
|
|
229
233
|
EventFunctions.forEach(f => $.fn[f] = (...args) => event.vega[f](...args));
|
|
230
234
|
return $(ast);
|
|
231
235
|
}
|
|
@@ -236,76 +240,65 @@
|
|
|
236
240
|
*/
|
|
237
241
|
operator(ctx, expr) {
|
|
238
242
|
const ast = expr.ast,
|
|
239
|
-
|
|
243
|
+
fn = ctx.functions;
|
|
240
244
|
return _ => interpret(ast, fn, _);
|
|
241
245
|
},
|
|
242
|
-
|
|
243
246
|
/**
|
|
244
247
|
* Parse an expression provided as an operator parameter value.
|
|
245
248
|
*/
|
|
246
249
|
parameter(ctx, expr) {
|
|
247
250
|
const ast = expr.ast,
|
|
248
|
-
|
|
251
|
+
fn = ctx.functions;
|
|
249
252
|
return (datum, _) => interpret(ast, fn, _, datum);
|
|
250
253
|
},
|
|
251
|
-
|
|
252
254
|
/**
|
|
253
255
|
* Parse an expression applied to an event stream.
|
|
254
256
|
*/
|
|
255
257
|
event(ctx, expr) {
|
|
256
258
|
const ast = expr.ast,
|
|
257
|
-
|
|
259
|
+
fn = ctx.functions;
|
|
258
260
|
return event => interpret(ast, fn, undefined, undefined, event);
|
|
259
261
|
},
|
|
260
|
-
|
|
261
262
|
/**
|
|
262
263
|
* Parse an expression used to handle an event-driven operator update.
|
|
263
264
|
*/
|
|
264
265
|
handler(ctx, expr) {
|
|
265
266
|
const ast = expr.ast,
|
|
266
|
-
|
|
267
|
+
fn = ctx.functions;
|
|
267
268
|
return (_, event) => {
|
|
268
269
|
const datum = event.item && event.item.datum;
|
|
269
270
|
return interpret(ast, fn, _, datum, event);
|
|
270
271
|
};
|
|
271
272
|
},
|
|
272
|
-
|
|
273
273
|
/**
|
|
274
274
|
* Parse an expression that performs visual encoding.
|
|
275
275
|
*/
|
|
276
276
|
encode(ctx, encode) {
|
|
277
277
|
const {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
278
|
+
marktype,
|
|
279
|
+
channels
|
|
280
|
+
} = encode,
|
|
281
|
+
fn = ctx.functions,
|
|
282
|
+
swap = marktype === 'group' || marktype === 'image' || marktype === 'rect';
|
|
283
283
|
return (item, _) => {
|
|
284
284
|
const datum = item.datum;
|
|
285
285
|
let m = 0,
|
|
286
|
-
|
|
287
|
-
|
|
286
|
+
v;
|
|
288
287
|
for (const name in channels) {
|
|
289
288
|
v = interpret(channels[name].ast, fn, _, datum, undefined, item);
|
|
290
|
-
|
|
291
289
|
if (item[name] !== v) {
|
|
292
290
|
item[name] = v;
|
|
293
291
|
m = 1;
|
|
294
292
|
}
|
|
295
293
|
}
|
|
296
|
-
|
|
297
294
|
if (marktype !== 'rule') {
|
|
298
295
|
adjustSpatial(item, channels, swap);
|
|
299
296
|
}
|
|
300
|
-
|
|
301
297
|
return m;
|
|
302
298
|
};
|
|
303
299
|
}
|
|
304
|
-
|
|
305
300
|
};
|
|
306
301
|
|
|
307
302
|
exports.expressionInterpreter = expression;
|
|
308
303
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
})));
|
|
304
|
+
}));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).vega=e.vega||{})}(this,(function(e){"use strict";var t={NaN:NaN,E:Math.E,LN2:Math.LN2,LN10:Math.LN10,LOG2E:Math.LOG2E,LOG10E:Math.LOG10E,PI:Math.PI,SQRT1_2:Math.SQRT1_2,SQRT2:Math.SQRT2,MIN_VALUE:Number.MIN_VALUE,MAX_VALUE:Number.MAX_VALUE},n={"*":(e,t)=>e*t,"+":(e,t)=>e+t,"-":(e,t)=>e-t,"/":(e,t)=>e/t,"%":(e,t)=>e%t,">":(e,t)=>e>t,"<":(e,t)=>e<t,"<=":(e,t)=>e<=t,">=":(e,t)=>e>=t,"==":(e,t)=>e==t,"!=":(e,t)=>e!=t,"===":(e,t)=>e===t,"!==":(e,t)=>e!==t,"&":(e,t)=>e&t,"|":(e,t)=>e|t,"^":(e,t)=>e^t,"<<":(e,t)=>e<<t,">>":(e,t)=>e>>t,">>>":(e,t)=>e>>>t},
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).vega=e.vega||{})}(this,(function(e){"use strict";var t={NaN:NaN,E:Math.E,LN2:Math.LN2,LN10:Math.LN10,LOG2E:Math.LOG2E,LOG10E:Math.LOG10E,PI:Math.PI,SQRT1_2:Math.SQRT1_2,SQRT2:Math.SQRT2,MIN_VALUE:Number.MIN_VALUE,MAX_VALUE:Number.MAX_VALUE},n={"*":(e,t)=>e*t,"+":(e,t)=>e+t,"-":(e,t)=>e-t,"/":(e,t)=>e/t,"%":(e,t)=>e%t,">":(e,t)=>e>t,"<":(e,t)=>e<t,"<=":(e,t)=>e<=t,">=":(e,t)=>e>=t,"==":(e,t)=>e==t,"!=":(e,t)=>e!=t,"===":(e,t)=>e===t,"!==":(e,t)=>e!==t,"&":(e,t)=>e&t,"|":(e,t)=>e|t,"^":(e,t)=>e^t,"<<":(e,t)=>e<<t,">>":(e,t)=>e>>t,">>>":(e,t)=>e>>>t},r={"+":e=>+e,"-":e=>-e,"~":e=>~e,"!":e=>!e};const a=Array.prototype.slice,o=(e,t,n)=>{const r=n?n(t[0]):t[0];return r[e].apply(r,a.call(t,1))};var i={isNaN:Number.isNaN,isFinite:Number.isFinite,abs:Math.abs,acos:Math.acos,asin:Math.asin,atan:Math.atan,atan2:Math.atan2,ceil:Math.ceil,cos:Math.cos,exp:Math.exp,floor:Math.floor,log:Math.log,max:Math.max,min:Math.min,pow:Math.pow,random:Math.random,round:Math.round,sin:Math.sin,sqrt:Math.sqrt,tan:Math.tan,clamp:(e,t,n)=>Math.max(t,Math.min(n,e)),now:Date.now,utc:Date.UTC,datetime:(e,t,n,r,a,o,i)=>new Date(e,t||0,null!=n?n:1,r||0,a||0,o||0,i||0),date:e=>new Date(e).getDate(),day:e=>new Date(e).getDay(),year:e=>new Date(e).getFullYear(),month:e=>new Date(e).getMonth(),hours:e=>new Date(e).getHours(),minutes:e=>new Date(e).getMinutes(),seconds:e=>new Date(e).getSeconds(),milliseconds:e=>new Date(e).getMilliseconds(),time:e=>new Date(e).getTime(),timezoneoffset:e=>new Date(e).getTimezoneOffset(),utcdate:e=>new Date(e).getUTCDate(),utcday:e=>new Date(e).getUTCDay(),utcyear:e=>new Date(e).getUTCFullYear(),utcmonth:e=>new Date(e).getUTCMonth(),utchours:e=>new Date(e).getUTCHours(),utcminutes:e=>new Date(e).getUTCMinutes(),utcseconds:e=>new Date(e).getUTCSeconds(),utcmilliseconds:e=>new Date(e).getUTCMilliseconds(),length:e=>e.length,join:function(){return o("join",arguments)},indexof:function(){return o("indexOf",arguments)},lastindexof:function(){return o("lastIndexOf",arguments)},slice:function(){return o("slice",arguments)},reverse:e=>e.slice().reverse(),parseFloat:parseFloat,parseInt:parseInt,upper:e=>String(e).toUpperCase(),lower:e=>String(e).toLowerCase(),substring:function(){return o("substring",arguments,String)},split:function(){return o("split",arguments,String)},replace:function(){return o("replace",arguments,String)},trim:e=>String(e).trim(),regexp:RegExp,test:(e,t)=>RegExp(e).test(t)};const s=["view","item","group","xy","x","y"],c=new Set([Function,eval,setTimeout,setInterval]);"function"==typeof setImmediate&&c.add(setImmediate);const u={Literal:(e,t)=>t.value,Identifier:(e,n)=>{const r=n.name;return e.memberDepth>0?r:"datum"===r?e.datum:"event"===r?e.event:"item"===r?e.item:t[r]||e.params["$"+r]},MemberExpression:(e,t)=>{const n=!t.computed,r=e(t.object);n&&(e.memberDepth+=1);const a=e(t.property);if(n&&(e.memberDepth-=1),!c.has(r[a]))return r[a];console.error(`Prevented interpretation of member "${a}" which could lead to insecure code execution`)},CallExpression:(e,t)=>{const n=t.arguments;let r=t.callee.name;return r.startsWith("_")&&(r=r.slice(1)),"if"===r?e(n[0])?e(n[1]):e(n[2]):(e.fn[r]||i[r]).apply(e.fn,n.map(e))},ArrayExpression:(e,t)=>t.elements.map(e),BinaryExpression:(e,t)=>n[t.operator](e(t.left),e(t.right)),UnaryExpression:(e,t)=>r[t.operator](e(t.argument)),ConditionalExpression:(e,t)=>e(t.test)?e(t.consequent):e(t.alternate),LogicalExpression:(e,t)=>"&&"===t.operator?e(t.left)&&e(t.right):e(t.left)||e(t.right),ObjectExpression:(e,t)=>t.properties.reduce(((t,n)=>{e.memberDepth+=1;const r=e(n.key);return e.memberDepth-=1,c.has(e(n.value))?console.error(`Prevented interpretation of property "${r}" which could lead to insecure code execution`):t[r]=e(n.value),t}),{})};function l(e,t,n,r,a,o){const i=e=>u[e.type](i,e);return i.memberDepth=0,i.fn=Object.create(t),i.params=n,i.datum=r,i.event=a,i.item=o,s.forEach((e=>i.fn[e]=function(){return a.vega[e](...arguments)})),i(e)}var m={operator(e,t){const n=t.ast,r=e.functions;return e=>l(n,r,e)},parameter(e,t){const n=t.ast,r=e.functions;return(e,t)=>l(n,r,t,e)},event(e,t){const n=t.ast,r=e.functions;return e=>l(n,r,void 0,void 0,e)},handler(e,t){const n=t.ast,r=e.functions;return(e,t)=>{const a=t.item&&t.item.datum;return l(n,r,e,a,t)}},encode(e,t){const{marktype:n,channels:r}=t,a=e.functions,o="group"===n||"image"===n||"rect"===n;return(e,t)=>{const i=e.datum;let s,c=0;for(const n in r)s=l(r[n].ast,a,t,i,void 0,e),e[n]!==s&&(e[n]=s,c=1);return"rule"!==n&&function(e,t,n){let r;t.x2&&(t.x?(n&&e.x>e.x2&&(r=e.x,e.x=e.x2,e.x2=r),e.width=e.x2-e.x):e.x=e.x2-(e.width||0)),t.xc&&(e.x=e.xc-(e.width||0)/2),t.y2&&(t.y?(n&&e.y>e.y2&&(r=e.y,e.y=e.y2,e.y2=r),e.height=e.y2-e.y):e.y=e.y2-(e.height||0)),t.yc&&(e.y=e.yc-(e.height||0)/2)}(e,r,o),c}}};e.expressionInterpreter=m}));
|
|
2
2
|
//# sourceMappingURL=vega-interpreter.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vega-interpreter.min.js","sources":["../src/constants.js","../src/ops-binary.js","../src/ops-unary.js","../src/functions.js","../src/interpret.js","../src/expression.js","../src/adjust-spatial.js"],"sourcesContent":["export default {\n NaN: NaN,\n E: Math.E,\n LN2: Math.LN2,\n LN10: Math.LN10,\n LOG2E: Math.LOG2E,\n LOG10E: Math.LOG10E,\n PI: Math.PI,\n SQRT1_2: Math.SQRT1_2,\n SQRT2: Math.SQRT2,\n MIN_VALUE: Number.MIN_VALUE,\n MAX_VALUE: Number.MAX_VALUE\n};\n","export default {\n '*': (a, b) => a * b,\n '+': (a, b) => a + b,\n '-': (a, b) => a - b,\n '/': (a, b) => a / b,\n '%': (a, b) => a % b,\n '>': (a, b) => a > b,\n '<': (a, b) => a < b,\n '<=': (a, b) => a <= b,\n '>=': (a, b) => a >= b,\n '==': (a, b) => a == b,\n '!=': (a, b) => a != b,\n '===': (a, b) => a === b,\n '!==': (a, b) => a !== b,\n '&': (a, b) => a & b,\n '|': (a, b) => a | b,\n '^': (a, b) => a ^ b,\n '<<': (a, b) => a << b,\n '>>': (a, b) => a >> b,\n '>>>': (a, b) => a >>> b\n};\n","export default {\n '+': a => +a,\n '-': a => -a,\n '~': a => ~a,\n '!': a => !a\n};\n","const slice = Array.prototype.slice;\n\nconst apply = (m, args, cast) => {\n const obj = cast ? cast(args[0]) : args[0];\n return obj[m].apply(obj, slice.call(args, 1));\n};\n\nconst datetime = (y, m, d, H, M, S, ms) =>\n new Date(y, m || 0, d != null ? d : 1, H || 0, M || 0, S || 0, ms || 0);\n\nexport default {\n // math functions\n isNaN: Number.isNaN,\n isFinite: Number.isFinite,\n abs: Math.abs,\n acos: Math.acos,\n asin: Math.asin,\n atan: Math.atan,\n atan2: Math.atan2,\n ceil: Math.ceil,\n cos: Math.cos,\n exp: Math.exp,\n floor: Math.floor,\n log: Math.log,\n max: Math.max,\n min: Math.min,\n pow: Math.pow,\n random: Math.random,\n round: Math.round,\n sin: Math.sin,\n sqrt: Math.sqrt,\n tan: Math.tan,\n clamp: (a, b, c) => Math.max(b, Math.min(c, a)),\n\n // date functions\n now: Date.now,\n utc: Date.UTC,\n datetime: datetime,\n date: d => new Date(d).getDate(),\n day: d => new Date(d).getDay(),\n year: d => new Date(d).getFullYear(),\n month: d => new Date(d).getMonth(),\n hours: d => new Date(d).getHours(),\n minutes: d => new Date(d).getMinutes(),\n seconds: d => new Date(d).getSeconds(),\n milliseconds: d => new Date(d).getMilliseconds(),\n time: d => new Date(d).getTime(),\n timezoneoffset: d => new Date(d).getTimezoneOffset(),\n utcdate: d => new Date(d).getUTCDate(),\n utcday: d => new Date(d).getUTCDay(),\n utcyear: d => new Date(d).getUTCFullYear(),\n utcmonth: d => new Date(d).getUTCMonth(),\n utchours: d => new Date(d).getUTCHours(),\n utcminutes: d => new Date(d).getUTCMinutes(),\n utcseconds: d => new Date(d).getUTCSeconds(),\n utcmilliseconds: d => new Date(d).getUTCMilliseconds(),\n\n // sequence functions\n length: x => x.length,\n join: function() { return apply('join', arguments); },\n indexof: function() { return apply('indexOf', arguments); },\n lastindexof: function() { return apply('lastIndexOf', arguments); },\n slice: function() { return apply('slice', arguments); },\n reverse: x => x.slice().reverse(),\n\n // string functions\n parseFloat: parseFloat,\n parseInt: parseInt,\n upper: x => String(x).toUpperCase(),\n lower: x => String(x).toLowerCase(),\n substring: function() { return apply('substring', arguments, String); },\n split: function() { return apply('split', arguments, String); },\n replace: function() { return apply('replace', arguments, String); },\n trim: x => String(x).trim(),\n\n // regexp functions\n regexp: RegExp,\n test: (r, t) => RegExp(r).test(t)\n};\n","import Constants from './constants';\nimport Ops from './ops-binary';\nimport Unary from './ops-unary';\nimport Functions from './functions';\n\nconst EventFunctions = ['view', 'item', 'group', 'xy', 'x', 'y'];\n\nconst Visitors = {\n Literal: ($, n) => n.value,\n\n Identifier: ($, n) => {\n const id = n.name;\n return $.memberDepth > 0 ? id\n : id === 'datum' ? $.datum\n : id === 'event' ? $.event\n : id === 'item' ? $.item\n : Constants[id] || $.params['$' + id];\n },\n\n MemberExpression: ($, n) => {\n const d = !n.computed,\n o = $(n.object);\n if (d) $.memberDepth += 1;\n const p = $(n.property);\n if (d) $.memberDepth -= 1;\n return o[p];\n },\n\n CallExpression: ($, n) => {\n const args = n.arguments;\n let name = n.callee.name;\n\n // handle special internal functions used by encoders\n // re-route to corresponding standard function\n if (name.startsWith('_')) {\n name = name.slice(1);\n }\n\n // special case \"if\" due to conditional evaluation of branches\n return name === 'if'\n ? ($(args[0]) ? $(args[1]) : $(args[2]))\n : ($.fn[name] || Functions[name]).apply($.fn, args.map($));\n },\n\n ArrayExpression: ($, n) => n.elements.map($),\n\n BinaryExpression: ($, n) => Ops[n.operator]($(n.left), $(n.right)),\n\n UnaryExpression: ($, n) => Unary[n.operator]($(n.argument)),\n\n ConditionalExpression: ($, n) => $(n.test)\n ? $(n.consequent)\n : $(n.alternate),\n\n LogicalExpression: ($, n) => n.operator === '&&'\n ? $(n.left) && $(n.right)\n : $(n.left) || $(n.right),\n\n ObjectExpression: ($, n) => n.properties.reduce((o, p) => {\n $.memberDepth += 1;\n const k = $(p.key);\n $.memberDepth -= 1;\n o[k] = $(p.value);\n return o;\n }, {})\n};\n\nexport default function(ast, fn, params, datum, event, item) {\n const $ = n => Visitors[n.type]($, n);\n $.memberDepth = 0;\n $.fn = Object.create(fn);\n $.params = params;\n $.datum = datum;\n $.event = event;\n $.item = item;\n\n // route event functions to annotated vega event context\n EventFunctions.forEach(f => $.fn[f] = (...args) => event.vega[f](...args));\n\n return $(ast);\n}","import adjustSpatial from './adjust-spatial';\nimport interpret from './interpret';\n\nexport default {\n /**\n * Parse an expression used to update an operator value.\n */\n operator(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return _ => interpret(ast, fn, _);\n },\n\n /**\n * Parse an expression provided as an operator parameter value.\n */\n parameter(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return (datum, _) => interpret(ast, fn, _, datum);\n },\n\n /**\n * Parse an expression applied to an event stream.\n */\n event(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return event => interpret(ast, fn, undefined, undefined, event);\n },\n\n /**\n * Parse an expression used to handle an event-driven operator update.\n */\n handler(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return (_, event) => {\n const datum = event.item && event.item.datum;\n return interpret(ast, fn, _, datum, event);\n };\n },\n\n /**\n * Parse an expression that performs visual encoding.\n */\n encode(ctx, encode) {\n const {marktype, channels} = encode,\n fn = ctx.functions,\n swap = marktype === 'group'\n || marktype === 'image'\n || marktype === 'rect';\n\n return (item, _) => {\n const datum = item.datum;\n let m = 0, v;\n\n for (const name in channels) {\n v = interpret(channels[name].ast, fn, _, datum, undefined, item);\n if (item[name] !== v) {\n item[name] = v;\n m = 1;\n }\n }\n\n if (marktype !== 'rule') {\n adjustSpatial(item, channels, swap);\n }\n return m;\n };\n }\n};\n","export default function(item, encode, swap) {\n let t;\n\n if (encode.x2) {\n if (encode.x) {\n if (swap && item.x > item.x2) {\n t = item.x;\n item.x = item.x2;\n item.x2 = t;\n }\n item.width = item.x2 - item.x;\n } else {\n item.x = item.x2 - (item.width || 0);\n }\n }\n\n if (encode.xc) {\n item.x = item.xc - (item.width || 0) / 2;\n }\n\n if (encode.y2) {\n if (encode.y) {\n if (swap && item.y > item.y2) {\n t = item.y;\n item.y = item.y2;\n item.y2 = t;\n }\n item.height = item.y2 - item.y;\n } else {\n item.y = item.y2 - (item.height || 0);\n }\n }\n\n if (encode.yc) {\n item.y = item.yc - (item.height || 0) / 2;\n }\n}\n"],"names":["NaN","E","Math","LN2","LN10","LOG2E","LOG10E","PI","SQRT1_2","SQRT2","MIN_VALUE","Number","MAX_VALUE","a","b","slice","Array","prototype","apply","m","args","cast","obj","call","isNaN","isFinite","abs","acos","asin","atan","atan2","ceil","cos","exp","floor","log","max","min","pow","random","round","sin","sqrt","tan","clamp","c","now","Date","utc","UTC","datetime","y","d","H","M","S","ms","date","getDate","day","getDay","year","getFullYear","month","getMonth","hours","getHours","minutes","getMinutes","seconds","getSeconds","milliseconds","getMilliseconds","time","getTime","timezoneoffset","getTimezoneOffset","utcdate","getUTCDate","utcday","getUTCDay","utcyear","getUTCFullYear","utcmonth","getUTCMonth","utchours","getUTCHours","utcminutes","getUTCMinutes","utcseconds","getUTCSeconds","utcmilliseconds","getUTCMilliseconds","length","x","join","arguments","indexof","lastindexof","reverse","parseFloat","parseInt","upper","String","toUpperCase","lower","toLowerCase","substring","split","replace","trim","regexp","RegExp","test","r","t","EventFunctions","Visitors","Literal","$","n","value","Identifier","id","name","memberDepth","datum","event","item","Constants","params","MemberExpression","computed","o","object","p","property","CallExpression","callee","startsWith","fn","Functions","map","ArrayExpression","elements","BinaryExpression","Ops","operator","left","right","UnaryExpression","Unary","argument","ConditionalExpression","consequent","alternate","LogicalExpression","ObjectExpression","properties","reduce","k","key","ast","type","Object","create","forEach","f","vega","ctx","expr","functions","_","interpret","parameter","undefined","handler","encode","marktype","channels","swap","v","x2","width","xc","y2","height","yc","adjustSpatial"],"mappings":"0PAAe,CACbA,IAAYA,IACZC,EAAYC,KAAKD,EACjBE,IAAYD,KAAKC,IACjBC,KAAYF,KAAKE,KACjBC,MAAYH,KAAKG,MACjBC,OAAYJ,KAAKI,OACjBC,GAAYL,KAAKK,GACjBC,QAAYN,KAAKM,QACjBC,MAAYP,KAAKO,MACjBC,UAAYC,OAAOD,UACnBE,UAAYD,OAAOC,aCXN,KACR,CAACC,EAAGC,IAAMD,EAAIC,MACd,CAACD,EAAGC,IAAMD,EAAIC,MACd,CAACD,EAAGC,IAAMD,EAAIC,MACd,CAACD,EAAGC,IAAMD,EAAIC,MACd,CAACD,EAAGC,IAAMD,EAAIC,MACd,CAACD,EAAGC,IAAMD,EAAIC,MACd,CAACD,EAAGC,IAAMD,EAAIC,OACb,CAACD,EAAGC,IAAMD,GAAKC,OACf,CAACD,EAAGC,IAAMD,GAAKC,OACf,CAACD,EAAGC,IAAMD,GAAKC,OACf,CAACD,EAAGC,IAAMD,GAAKC,Q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EAAK7E,EAAI6E,EAAK2D,IAAM3D,EAAK0D,QAAU,GAAK,GD4BpCE,CAAc5D,EAAMmD,EAAUC,GAEzBjK"}
|
|
1
|
+
{"version":3,"file":"vega-interpreter.min.js","sources":["../src/constants.js","../src/ops-binary.js","../src/ops-unary.js","../src/functions.js","../src/interpret.js","../src/expression.js","../src/adjust-spatial.js"],"sourcesContent":["export default {\n NaN: NaN,\n E: Math.E,\n LN2: Math.LN2,\n LN10: Math.LN10,\n LOG2E: Math.LOG2E,\n LOG10E: Math.LOG10E,\n PI: Math.PI,\n SQRT1_2: Math.SQRT1_2,\n SQRT2: Math.SQRT2,\n MIN_VALUE: Number.MIN_VALUE,\n MAX_VALUE: Number.MAX_VALUE\n};\n","export default {\n '*': (a, b) => a * b,\n '+': (a, b) => a + b,\n '-': (a, b) => a - b,\n '/': (a, b) => a / b,\n '%': (a, b) => a % b,\n '>': (a, b) => a > b,\n '<': (a, b) => a < b,\n '<=': (a, b) => a <= b,\n '>=': (a, b) => a >= b,\n '==': (a, b) => a == b,\n '!=': (a, b) => a != b,\n '===': (a, b) => a === b,\n '!==': (a, b) => a !== b,\n '&': (a, b) => a & b,\n '|': (a, b) => a | b,\n '^': (a, b) => a ^ b,\n '<<': (a, b) => a << b,\n '>>': (a, b) => a >> b,\n '>>>': (a, b) => a >>> b\n};\n","export default {\n '+': a => +a,\n '-': a => -a,\n '~': a => ~a,\n '!': a => !a\n};\n","const slice = Array.prototype.slice;\n\nconst apply = (m, args, cast) => {\n const obj = cast ? cast(args[0]) : args[0];\n return obj[m].apply(obj, slice.call(args, 1));\n};\n\nconst datetime = (y, m, d, H, M, S, ms) =>\n new Date(y, m || 0, d != null ? d : 1, H || 0, M || 0, S || 0, ms || 0);\n\nexport default {\n // math functions\n isNaN: Number.isNaN,\n isFinite: Number.isFinite,\n abs: Math.abs,\n acos: Math.acos,\n asin: Math.asin,\n atan: Math.atan,\n atan2: Math.atan2,\n ceil: Math.ceil,\n cos: Math.cos,\n exp: Math.exp,\n floor: Math.floor,\n log: Math.log,\n max: Math.max,\n min: Math.min,\n pow: Math.pow,\n random: Math.random,\n round: Math.round,\n sin: Math.sin,\n sqrt: Math.sqrt,\n tan: Math.tan,\n clamp: (a, b, c) => Math.max(b, Math.min(c, a)),\n\n // date functions\n now: Date.now,\n utc: Date.UTC,\n datetime: datetime,\n date: d => new Date(d).getDate(),\n day: d => new Date(d).getDay(),\n year: d => new Date(d).getFullYear(),\n month: d => new Date(d).getMonth(),\n hours: d => new Date(d).getHours(),\n minutes: d => new Date(d).getMinutes(),\n seconds: d => new Date(d).getSeconds(),\n milliseconds: d => new Date(d).getMilliseconds(),\n time: d => new Date(d).getTime(),\n timezoneoffset: d => new Date(d).getTimezoneOffset(),\n utcdate: d => new Date(d).getUTCDate(),\n utcday: d => new Date(d).getUTCDay(),\n utcyear: d => new Date(d).getUTCFullYear(),\n utcmonth: d => new Date(d).getUTCMonth(),\n utchours: d => new Date(d).getUTCHours(),\n utcminutes: d => new Date(d).getUTCMinutes(),\n utcseconds: d => new Date(d).getUTCSeconds(),\n utcmilliseconds: d => new Date(d).getUTCMilliseconds(),\n\n // sequence functions\n length: x => x.length,\n join: function() { return apply('join', arguments); },\n indexof: function() { return apply('indexOf', arguments); },\n lastindexof: function() { return apply('lastIndexOf', arguments); },\n slice: function() { return apply('slice', arguments); },\n reverse: x => x.slice().reverse(),\n\n // string functions\n parseFloat: parseFloat,\n parseInt: parseInt,\n upper: x => String(x).toUpperCase(),\n lower: x => String(x).toLowerCase(),\n substring: function() { return apply('substring', arguments, String); },\n split: function() { return apply('split', arguments, String); },\n replace: function() { return apply('replace', arguments, String); },\n trim: x => String(x).trim(),\n\n // regexp functions\n regexp: RegExp,\n test: (r, t) => RegExp(r).test(t)\n};\n","import Constants from './constants';\nimport Ops from './ops-binary';\nimport Unary from './ops-unary';\nimport Functions from './functions';\n\nconst EventFunctions = ['view', 'item', 'group', 'xy', 'x', 'y'];\nconst DisallowedMethods = new Set([\n Function,\n eval,\n setTimeout,\n setInterval\n]);\n\nif (typeof setImmediate === 'function') DisallowedMethods.add(setImmediate);\n\nconst Visitors = {\n Literal: ($, n) => n.value,\n\n Identifier: ($, n) => {\n const id = n.name;\n return $.memberDepth > 0 ? id\n : id === 'datum' ? $.datum\n : id === 'event' ? $.event\n : id === 'item' ? $.item\n : Constants[id] || $.params['$' + id];\n },\n\n MemberExpression: ($, n) => {\n const d = !n.computed,\n o = $(n.object);\n if (d) $.memberDepth += 1;\n const p = $(n.property);\n if (d) $.memberDepth -= 1;\n if (DisallowedMethods.has(o[p])) {\n // eslint-disable-next-line no-console\n console.error(`Prevented interpretation of member \"${p}\" which could lead to insecure code execution`);\n return;\n }\n return o[p];\n },\n\n CallExpression: ($, n) => {\n const args = n.arguments;\n let name = n.callee.name;\n\n // handle special internal functions used by encoders\n // re-route to corresponding standard function\n if (name.startsWith('_')) {\n name = name.slice(1);\n }\n\n // special case \"if\" due to conditional evaluation of branches\n return name === 'if'\n ? ($(args[0]) ? $(args[1]) : $(args[2]))\n : ($.fn[name] || Functions[name]).apply($.fn, args.map($));\n },\n\n ArrayExpression: ($, n) => n.elements.map($),\n\n BinaryExpression: ($, n) => Ops[n.operator]($(n.left), $(n.right)),\n\n UnaryExpression: ($, n) => Unary[n.operator]($(n.argument)),\n\n ConditionalExpression: ($, n) => $(n.test)\n ? $(n.consequent)\n : $(n.alternate),\n\n LogicalExpression: ($, n) => n.operator === '&&'\n ? $(n.left) && $(n.right)\n : $(n.left) || $(n.right),\n\n ObjectExpression: ($, n) => n.properties.reduce((o, p) => {\n $.memberDepth += 1;\n const k = $(p.key);\n $.memberDepth -= 1;\n if (DisallowedMethods.has($(p.value))) {\n // eslint-disable-next-line no-console\n console.error(`Prevented interpretation of property \"${k}\" which could lead to insecure code execution`);\n } else {\n o[k] = $(p.value);\n }\n return o;\n }, {})\n};\n\nexport default function(ast, fn, params, datum, event, item) {\n const $ = n => Visitors[n.type]($, n);\n $.memberDepth = 0;\n $.fn = Object.create(fn);\n $.params = params;\n $.datum = datum;\n $.event = event;\n $.item = item;\n\n // route event functions to annotated vega event context\n EventFunctions.forEach(f => $.fn[f] = (...args) => event.vega[f](...args));\n\n return $(ast);\n}\n","import adjustSpatial from './adjust-spatial';\nimport interpret from './interpret';\n\nexport default {\n /**\n * Parse an expression used to update an operator value.\n */\n operator(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return _ => interpret(ast, fn, _);\n },\n\n /**\n * Parse an expression provided as an operator parameter value.\n */\n parameter(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return (datum, _) => interpret(ast, fn, _, datum);\n },\n\n /**\n * Parse an expression applied to an event stream.\n */\n event(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return event => interpret(ast, fn, undefined, undefined, event);\n },\n\n /**\n * Parse an expression used to handle an event-driven operator update.\n */\n handler(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return (_, event) => {\n const datum = event.item && event.item.datum;\n return interpret(ast, fn, _, datum, event);\n };\n },\n\n /**\n * Parse an expression that performs visual encoding.\n */\n encode(ctx, encode) {\n const {marktype, channels} = encode,\n fn = ctx.functions,\n swap = marktype === 'group'\n || marktype === 'image'\n || marktype === 'rect';\n\n return (item, _) => {\n const datum = item.datum;\n let m = 0, v;\n\n for (const name in channels) {\n v = interpret(channels[name].ast, fn, _, datum, undefined, item);\n if (item[name] !== v) {\n item[name] = v;\n m = 1;\n }\n }\n\n if (marktype !== 'rule') {\n adjustSpatial(item, channels, swap);\n }\n return m;\n };\n }\n};\n","export default function(item, encode, swap) {\n let t;\n\n if (encode.x2) {\n if (encode.x) {\n if (swap && item.x > item.x2) {\n t = item.x;\n item.x = item.x2;\n item.x2 = t;\n }\n item.width = item.x2 - item.x;\n } else {\n item.x = item.x2 - (item.width || 0);\n }\n }\n\n if (encode.xc) {\n item.x = item.xc - (item.width || 0) / 2;\n }\n\n if (encode.y2) {\n if (encode.y) {\n if (swap && item.y > item.y2) {\n t = item.y;\n item.y = item.y2;\n item.y2 = t;\n }\n item.height = item.y2 - item.y;\n } else {\n item.y = item.y2 - (item.height || 0);\n }\n }\n\n if (encode.yc) {\n item.y = item.yc - (item.height || 0) / 2;\n }\n}\n"],"names":["Constants","NaN","E","Math","LN2","LN10","LOG2E","LOG10E","PI","SQRT1_2","SQRT2","MIN_VALUE","Number","MAX_VALUE","Ops","*","a","b","+","-","/","%",">","<","<=",">=","==","!=","===","!==","&","|","^","<<",">>",">>>","Unary","slice","Array","prototype","apply","m","args","cast","obj","call","Functions","isNaN","isFinite","abs","acos","asin","atan","atan2","ceil","cos","exp","floor","log","max","min","pow","random","round","sin","sqrt","tan","clamp","c","now","Date","utc","UTC","datetime","y","d","H","M","S","ms","date","getDate","day","getDay","year","getFullYear","month","getMonth","hours","getHours","minutes","getMinutes","seconds","getSeconds","milliseconds","getMilliseconds","time","getTime","timezoneoffset","getTimezoneOffset","utcdate","getUTCDate","utcday","getUTCDay","utcyear","getUTCFullYear","utcmonth","getUTCMonth","utchours","getUTCHours","utcminutes","getUTCMinutes","utcseconds","getUTCSeconds","utcmilliseconds","getUTCMilliseconds","length","x","join","arguments","indexof","lastindexof","reverse","parseFloat","parseInt","upper","String","toUpperCase","lower","toLowerCase","substring","split","replace","trim","regexp","RegExp","test","r","t","EventFunctions","DisallowedMethods","Set","Function","eval","setTimeout","setInterval","setImmediate","add","Visitors","Literal","$","n","value","Identifier","id","name","memberDepth","datum","event","item","params","MemberExpression","computed","o","object","p","property","has","console","error","CallExpression","callee","startsWith","fn","map","ArrayExpression","elements","BinaryExpression","operator","left","right","UnaryExpression","argument","ConditionalExpression","consequent","alternate","LogicalExpression","ObjectExpression","properties","reduce","k","key","interpret","ast","type","Object","create","forEach","f","vega","expression","ctx","expr","functions","_","parameter","undefined","handler","encode","marktype","channels","swap","v","x2","width","xc","y2","height","yc","adjustSpatial"],"mappings":"oPAAe,IAAAA,EAAA,CACbC,IAAYA,IACZC,EAAYC,KAAKD,EACjBE,IAAYD,KAAKC,I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yD,GAAK9E,GAEZqB,EAAK0D,OAAS1D,EAAKyD,GAAKzD,EAAKrF,GAE7BqF,EAAKrF,EAAIqF,EAAKyD,IAAMzD,EAAK0D,QAAU,IAInCT,EAAOU,KACT3D,EAAKrF,EAAIqF,EAAK2D,IAAM3D,EAAK0D,QAAU,GAAK,EAE5C,CD0BQE,CAAc5D,EAAMmD,EAAUC,GAEzB1K,CAAC,CAEZ"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
function adjustSpatial (item, encode, swap) {
|
|
2
2
|
let t;
|
|
3
|
-
|
|
4
3
|
if (encode.x2) {
|
|
5
4
|
if (encode.x) {
|
|
6
5
|
if (swap && item.x > item.x2) {
|
|
@@ -8,17 +7,14 @@ function adjustSpatial (item, encode, swap) {
|
|
|
8
7
|
item.x = item.x2;
|
|
9
8
|
item.x2 = t;
|
|
10
9
|
}
|
|
11
|
-
|
|
12
10
|
item.width = item.x2 - item.x;
|
|
13
11
|
} else {
|
|
14
12
|
item.x = item.x2 - (item.width || 0);
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
if (encode.xc) {
|
|
19
16
|
item.x = item.xc - (item.width || 0) / 2;
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
if (encode.y2) {
|
|
23
19
|
if (encode.y) {
|
|
24
20
|
if (swap && item.y > item.y2) {
|
|
@@ -26,13 +22,11 @@ function adjustSpatial (item, encode, swap) {
|
|
|
26
22
|
item.y = item.y2;
|
|
27
23
|
item.y2 = t;
|
|
28
24
|
}
|
|
29
|
-
|
|
30
25
|
item.height = item.y2 - item.y;
|
|
31
26
|
} else {
|
|
32
27
|
item.y = item.y2 - (item.height || 0);
|
|
33
28
|
}
|
|
34
29
|
}
|
|
35
|
-
|
|
36
30
|
if (encode.yc) {
|
|
37
31
|
item.y = item.yc - (item.height || 0) / 2;
|
|
38
32
|
}
|
|
@@ -82,14 +76,11 @@ var Unary = {
|
|
|
82
76
|
};
|
|
83
77
|
|
|
84
78
|
const slice = Array.prototype.slice;
|
|
85
|
-
|
|
86
79
|
const apply = (m, args, cast) => {
|
|
87
80
|
const obj = cast ? cast(args[0]) : args[0];
|
|
88
81
|
return obj[m].apply(obj, slice.call(args, 1));
|
|
89
82
|
};
|
|
90
|
-
|
|
91
83
|
const datetime = (y, m, d, H, M, S, ms) => new Date(y, m || 0, d != null ? d : 1, H || 0, M || 0, S || 0, ms || 0);
|
|
92
|
-
|
|
93
84
|
var Functions = {
|
|
94
85
|
// math functions
|
|
95
86
|
isNaN: Number.isNaN,
|
|
@@ -171,6 +162,8 @@ var Functions = {
|
|
|
171
162
|
};
|
|
172
163
|
|
|
173
164
|
const EventFunctions = ['view', 'item', 'group', 'xy', 'x', 'y'];
|
|
165
|
+
const DisallowedMethods = new Set([Function, eval, setTimeout, setInterval]);
|
|
166
|
+
if (typeof setImmediate === 'function') DisallowedMethods.add(setImmediate);
|
|
174
167
|
const Visitors = {
|
|
175
168
|
Literal: ($, n) => n.value,
|
|
176
169
|
Identifier: ($, n) => {
|
|
@@ -179,22 +172,28 @@ const Visitors = {
|
|
|
179
172
|
},
|
|
180
173
|
MemberExpression: ($, n) => {
|
|
181
174
|
const d = !n.computed,
|
|
182
|
-
|
|
175
|
+
o = $(n.object);
|
|
183
176
|
if (d) $.memberDepth += 1;
|
|
184
177
|
const p = $(n.property);
|
|
185
178
|
if (d) $.memberDepth -= 1;
|
|
179
|
+
if (DisallowedMethods.has(o[p])) {
|
|
180
|
+
// eslint-disable-next-line no-console
|
|
181
|
+
console.error(`Prevented interpretation of member "${p}" which could lead to insecure code execution`);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
186
184
|
return o[p];
|
|
187
185
|
},
|
|
188
186
|
CallExpression: ($, n) => {
|
|
189
187
|
const args = n.arguments;
|
|
190
|
-
let name = n.callee.name;
|
|
191
|
-
// re-route to corresponding standard function
|
|
188
|
+
let name = n.callee.name;
|
|
192
189
|
|
|
190
|
+
// handle special internal functions used by encoders
|
|
191
|
+
// re-route to corresponding standard function
|
|
193
192
|
if (name.startsWith('_')) {
|
|
194
193
|
name = name.slice(1);
|
|
195
|
-
}
|
|
196
|
-
|
|
194
|
+
}
|
|
197
195
|
|
|
196
|
+
// special case "if" due to conditional evaluation of branches
|
|
198
197
|
return name === 'if' ? $(args[0]) ? $(args[1]) : $(args[2]) : ($.fn[name] || Functions[name]).apply($.fn, args.map($));
|
|
199
198
|
},
|
|
200
199
|
ArrayExpression: ($, n) => n.elements.map($),
|
|
@@ -206,21 +205,28 @@ const Visitors = {
|
|
|
206
205
|
$.memberDepth += 1;
|
|
207
206
|
const k = $(p.key);
|
|
208
207
|
$.memberDepth -= 1;
|
|
209
|
-
|
|
208
|
+
if (DisallowedMethods.has($(p.value))) {
|
|
209
|
+
// eslint-disable-next-line no-console
|
|
210
|
+
console.error(`Prevented interpretation of property "${k}" which could lead to insecure code execution`);
|
|
211
|
+
} else {
|
|
212
|
+
o[k] = $(p.value);
|
|
213
|
+
}
|
|
210
214
|
return o;
|
|
211
215
|
}, {})
|
|
212
216
|
};
|
|
213
217
|
function interpret (ast, fn, params, datum, event, item) {
|
|
214
218
|
const $ = n => Visitors[n.type]($, n);
|
|
215
|
-
|
|
216
219
|
$.memberDepth = 0;
|
|
217
220
|
$.fn = Object.create(fn);
|
|
218
221
|
$.params = params;
|
|
219
222
|
$.datum = datum;
|
|
220
223
|
$.event = event;
|
|
221
|
-
$.item = item;
|
|
224
|
+
$.item = item;
|
|
222
225
|
|
|
223
|
-
|
|
226
|
+
// route event functions to annotated vega event context
|
|
227
|
+
EventFunctions.forEach(f => $.fn[f] = function () {
|
|
228
|
+
return event.vega[f](...arguments);
|
|
229
|
+
});
|
|
224
230
|
return $(ast);
|
|
225
231
|
}
|
|
226
232
|
|
|
@@ -230,72 +236,63 @@ var expression = {
|
|
|
230
236
|
*/
|
|
231
237
|
operator(ctx, expr) {
|
|
232
238
|
const ast = expr.ast,
|
|
233
|
-
|
|
239
|
+
fn = ctx.functions;
|
|
234
240
|
return _ => interpret(ast, fn, _);
|
|
235
241
|
},
|
|
236
|
-
|
|
237
242
|
/**
|
|
238
243
|
* Parse an expression provided as an operator parameter value.
|
|
239
244
|
*/
|
|
240
245
|
parameter(ctx, expr) {
|
|
241
246
|
const ast = expr.ast,
|
|
242
|
-
|
|
247
|
+
fn = ctx.functions;
|
|
243
248
|
return (datum, _) => interpret(ast, fn, _, datum);
|
|
244
249
|
},
|
|
245
|
-
|
|
246
250
|
/**
|
|
247
251
|
* Parse an expression applied to an event stream.
|
|
248
252
|
*/
|
|
249
253
|
event(ctx, expr) {
|
|
250
254
|
const ast = expr.ast,
|
|
251
|
-
|
|
255
|
+
fn = ctx.functions;
|
|
252
256
|
return event => interpret(ast, fn, undefined, undefined, event);
|
|
253
257
|
},
|
|
254
|
-
|
|
255
258
|
/**
|
|
256
259
|
* Parse an expression used to handle an event-driven operator update.
|
|
257
260
|
*/
|
|
258
261
|
handler(ctx, expr) {
|
|
259
262
|
const ast = expr.ast,
|
|
260
|
-
|
|
263
|
+
fn = ctx.functions;
|
|
261
264
|
return (_, event) => {
|
|
262
265
|
const datum = event.item && event.item.datum;
|
|
263
266
|
return interpret(ast, fn, _, datum, event);
|
|
264
267
|
};
|
|
265
268
|
},
|
|
266
|
-
|
|
267
269
|
/**
|
|
268
270
|
* Parse an expression that performs visual encoding.
|
|
269
271
|
*/
|
|
270
272
|
encode(ctx, encode) {
|
|
271
273
|
const {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
274
|
+
marktype,
|
|
275
|
+
channels
|
|
276
|
+
} = encode,
|
|
277
|
+
fn = ctx.functions,
|
|
278
|
+
swap = marktype === 'group' || marktype === 'image' || marktype === 'rect';
|
|
277
279
|
return (item, _) => {
|
|
278
280
|
const datum = item.datum;
|
|
279
281
|
let m = 0,
|
|
280
|
-
|
|
281
|
-
|
|
282
|
+
v;
|
|
282
283
|
for (const name in channels) {
|
|
283
284
|
v = interpret(channels[name].ast, fn, _, datum, undefined, item);
|
|
284
|
-
|
|
285
285
|
if (item[name] !== v) {
|
|
286
286
|
item[name] = v;
|
|
287
287
|
m = 1;
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
|
-
|
|
291
290
|
if (marktype !== 'rule') {
|
|
292
291
|
adjustSpatial(item, channels, swap);
|
|
293
292
|
}
|
|
294
|
-
|
|
295
293
|
return m;
|
|
296
294
|
};
|
|
297
295
|
}
|
|
298
|
-
|
|
299
296
|
};
|
|
300
297
|
|
|
301
298
|
export { expression as expressionInterpreter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vega-interpreter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "CSP-compliant interpreter for Vega expressions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vega",
|
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
"repository": "vega/vega",
|
|
18
18
|
"scripts": {
|
|
19
19
|
"prebuild": "rimraf build",
|
|
20
|
-
"build": "rollup -c --extend",
|
|
20
|
+
"build": "rollup -c rollup.config.mjs --extend",
|
|
21
21
|
"pretest": "yarn build --config-test",
|
|
22
22
|
"test": "TZ=America/Los_Angeles tape 'test/**/*-test.js'",
|
|
23
23
|
"prepublishOnly": "yarn test && yarn build"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"vega": "*"
|
|
27
|
-
}
|
|
27
|
+
},
|
|
28
|
+
"gitHead": "fb1092f6b931d450f9c210b67ae4752bd3dd461b"
|
|
28
29
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '../../rollup.config.mjs';
|
package/src/interpret.js
CHANGED
|
@@ -4,6 +4,14 @@ import Unary from './ops-unary';
|
|
|
4
4
|
import Functions from './functions';
|
|
5
5
|
|
|
6
6
|
const EventFunctions = ['view', 'item', 'group', 'xy', 'x', 'y'];
|
|
7
|
+
const DisallowedMethods = new Set([
|
|
8
|
+
Function,
|
|
9
|
+
eval,
|
|
10
|
+
setTimeout,
|
|
11
|
+
setInterval
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
if (typeof setImmediate === 'function') DisallowedMethods.add(setImmediate);
|
|
7
15
|
|
|
8
16
|
const Visitors = {
|
|
9
17
|
Literal: ($, n) => n.value,
|
|
@@ -23,6 +31,11 @@ const Visitors = {
|
|
|
23
31
|
if (d) $.memberDepth += 1;
|
|
24
32
|
const p = $(n.property);
|
|
25
33
|
if (d) $.memberDepth -= 1;
|
|
34
|
+
if (DisallowedMethods.has(o[p])) {
|
|
35
|
+
// eslint-disable-next-line no-console
|
|
36
|
+
console.error(`Prevented interpretation of member "${p}" which could lead to insecure code execution`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
26
39
|
return o[p];
|
|
27
40
|
},
|
|
28
41
|
|
|
@@ -60,7 +73,12 @@ const Visitors = {
|
|
|
60
73
|
$.memberDepth += 1;
|
|
61
74
|
const k = $(p.key);
|
|
62
75
|
$.memberDepth -= 1;
|
|
63
|
-
|
|
76
|
+
if (DisallowedMethods.has($(p.value))) {
|
|
77
|
+
// eslint-disable-next-line no-console
|
|
78
|
+
console.error(`Prevented interpretation of property "${k}" which could lead to insecure code execution`);
|
|
79
|
+
} else {
|
|
80
|
+
o[k] = $(p.value);
|
|
81
|
+
}
|
|
64
82
|
return o;
|
|
65
83
|
}, {})
|
|
66
84
|
};
|
|
@@ -78,4 +96,4 @@ export default function(ast, fn, params, datum, event, item) {
|
|
|
78
96
|
EventFunctions.forEach(f => $.fn[f] = (...args) => event.vega[f](...args));
|
|
79
97
|
|
|
80
98
|
return $(ast);
|
|
81
|
-
}
|
|
99
|
+
}
|
package/rollup.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '../../rollup.config';
|