vega-interpreter 1.0.3 → 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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015-2018, University of Washington Interactive Data Lab
1
+ Copyright (c) 2015-2023, University of Washington Interactive Data Lab
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
@@ -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,
@@ -176,6 +167,9 @@
176
167
  test: (r, t) => RegExp(r).test(t)
177
168
  };
178
169
 
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);
179
173
  const Visitors = {
180
174
  Literal: ($, n) => n.value,
181
175
  Identifier: ($, n) => {
@@ -184,22 +178,28 @@
184
178
  },
185
179
  MemberExpression: ($, n) => {
186
180
  const d = !n.computed,
187
- o = $(n.object);
181
+ o = $(n.object);
188
182
  if (d) $.memberDepth += 1;
189
183
  const p = $(n.property);
190
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
+ }
191
190
  return o[p];
192
191
  },
193
192
  CallExpression: ($, n) => {
194
193
  const args = n.arguments;
195
- let name = n.callee.name; // handle special internal functions used by encoders
196
- // re-route to corresponding standard function
194
+ let name = n.callee.name;
197
195
 
196
+ // handle special internal functions used by encoders
197
+ // re-route to corresponding standard function
198
198
  if (name.startsWith('_')) {
199
199
  name = name.slice(1);
200
- } // special case "if" due to conditional evaluation of branches
201
-
200
+ }
202
201
 
202
+ // special case "if" due to conditional evaluation of branches
203
203
  return name === 'if' ? $(args[0]) ? $(args[1]) : $(args[2]) : ($.fn[name] || Functions[name]).apply($.fn, args.map($));
204
204
  },
205
205
  ArrayExpression: ($, n) => n.elements.map($),
@@ -211,19 +211,26 @@
211
211
  $.memberDepth += 1;
212
212
  const k = $(p.key);
213
213
  $.memberDepth -= 1;
214
- o[k] = $(p.value);
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
+ }
215
220
  return o;
216
221
  }, {})
217
222
  };
218
223
  function interpret (ast, fn, params, datum, event, item) {
219
224
  const $ = n => Visitors[n.type]($, n);
220
-
221
225
  $.memberDepth = 0;
222
- $.fn = fn;
226
+ $.fn = Object.create(fn);
223
227
  $.params = params;
224
228
  $.datum = datum;
225
229
  $.event = event;
226
230
  $.item = item;
231
+
232
+ // route event functions to annotated vega event context
233
+ EventFunctions.forEach(f => $.fn[f] = (...args) => event.vega[f](...args));
227
234
  return $(ast);
228
235
  }
229
236
 
@@ -233,76 +240,65 @@
233
240
  */
234
241
  operator(ctx, expr) {
235
242
  const ast = expr.ast,
236
- fn = ctx.functions;
243
+ fn = ctx.functions;
237
244
  return _ => interpret(ast, fn, _);
238
245
  },
239
-
240
246
  /**
241
247
  * Parse an expression provided as an operator parameter value.
242
248
  */
243
249
  parameter(ctx, expr) {
244
250
  const ast = expr.ast,
245
- fn = ctx.functions;
251
+ fn = ctx.functions;
246
252
  return (datum, _) => interpret(ast, fn, _, datum);
247
253
  },
248
-
249
254
  /**
250
255
  * Parse an expression applied to an event stream.
251
256
  */
252
257
  event(ctx, expr) {
253
258
  const ast = expr.ast,
254
- fn = ctx.functions;
259
+ fn = ctx.functions;
255
260
  return event => interpret(ast, fn, undefined, undefined, event);
256
261
  },
257
-
258
262
  /**
259
263
  * Parse an expression used to handle an event-driven operator update.
260
264
  */
261
265
  handler(ctx, expr) {
262
266
  const ast = expr.ast,
263
- fn = ctx.functions;
267
+ fn = ctx.functions;
264
268
  return (_, event) => {
265
269
  const datum = event.item && event.item.datum;
266
270
  return interpret(ast, fn, _, datum, event);
267
271
  };
268
272
  },
269
-
270
273
  /**
271
274
  * Parse an expression that performs visual encoding.
272
275
  */
273
276
  encode(ctx, encode) {
274
277
  const {
275
- marktype,
276
- channels
277
- } = encode,
278
- fn = ctx.functions,
279
- swap = marktype === 'group' || marktype === 'image' || marktype === 'rect';
278
+ marktype,
279
+ channels
280
+ } = encode,
281
+ fn = ctx.functions,
282
+ swap = marktype === 'group' || marktype === 'image' || marktype === 'rect';
280
283
  return (item, _) => {
281
284
  const datum = item.datum;
282
285
  let m = 0,
283
- v;
284
-
286
+ v;
285
287
  for (const name in channels) {
286
288
  v = interpret(channels[name].ast, fn, _, datum, undefined, item);
287
-
288
289
  if (item[name] !== v) {
289
290
  item[name] = v;
290
291
  m = 1;
291
292
  }
292
293
  }
293
-
294
294
  if (marktype !== 'rule') {
295
295
  adjustSpatial(item, channels, swap);
296
296
  }
297
-
298
297
  return m;
299
298
  };
300
299
  }
301
-
302
300
  };
303
301
 
304
302
  exports.expressionInterpreter = expression;
305
303
 
306
- Object.defineProperty(exports, '__esModule', { value: true });
307
-
308
- })));
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},a={"+":e=>+e,"-":e=>-e,"~":e=>~e,"!":e=>!e};const r=Array.prototype.slice,s=(e,t,n)=>{const a=n?n(t[0]):t[0];return a[e].apply(a,r.call(t,1))};var o={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,a,r,s,o)=>new Date(e,t||0,null!=n?n:1,a||0,r||0,s||0,o||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 s("join",arguments)},indexof:function(){return s("indexOf",arguments)},lastindexof:function(){return s("lastIndexOf",arguments)},slice:function(){return s("slice",arguments)},reverse:e=>e.slice().reverse(),parseFloat:parseFloat,parseInt:parseInt,upper:e=>String(e).toUpperCase(),lower:e=>String(e).toLowerCase(),substring:function(){return s("substring",arguments,String)},split:function(){return s("split",arguments,String)},replace:function(){return s("replace",arguments,String)},trim:e=>String(e).trim(),regexp:RegExp,test:(e,t)=>RegExp(e).test(t)};const i={Literal:(e,t)=>t.value,Identifier:(e,n)=>{const a=n.name;return e.memberDepth>0?a:"datum"===a?e.datum:"event"===a?e.event:"item"===a?e.item:t[a]||e.params["$"+a]},MemberExpression:(e,t)=>{const n=!t.computed,a=e(t.object);n&&(e.memberDepth+=1);const r=e(t.property);return n&&(e.memberDepth-=1),a[r]},CallExpression:(e,t)=>{const n=t.arguments;let a=t.callee.name;return a.startsWith("_")&&(a=a.slice(1)),"if"===a?e(n[0])?e(n[1]):e(n[2]):(e.fn[a]||o[a]).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)=>a[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 a=e(n.key);return e.memberDepth-=1,t[a]=e(n.value),t},{})};function u(e,t,n,a,r,s){const o=e=>i[e.type](o,e);return o.memberDepth=0,o.fn=t,o.params=n,o.datum=a,o.event=r,o.item=s,o(e)}var c={operator(e,t){const n=t.ast,a=e.functions;return e=>u(n,a,e)},parameter(e,t){const n=t.ast,a=e.functions;return(e,t)=>u(n,a,t,e)},event(e,t){const n=t.ast,a=e.functions;return e=>u(n,a,void 0,void 0,e)},handler(e,t){const n=t.ast,a=e.functions;return(e,t)=>{const r=t.item&&t.item.datum;return u(n,a,e,r,t)}},encode(e,t){const{marktype:n,channels:a}=t,r=e.functions,s="group"===n||"image"===n||"rect"===n;return(e,t)=>{const o=e.datum;let i,c=0;for(const n in a)i=u(a[n].ast,r,t,o,void 0,e),e[n]!==i&&(e[n]=i,c=1);return"rule"!==n&&function(e,t,n){let a;t.x2&&(t.x?(n&&e.x>e.x2&&(a=e.x,e.x=e.x2,e.x2=a),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&&(a=e.y,e.y=e.y2,e.y2=a),e.height=e.y2-e.y):e.y=e.y2-(e.height||0)),t.yc&&(e.y=e.yc-(e.height||0)/2)}(e,a,s),c}}};e.expressionInterpreter=c,Object.defineProperty(e,"__esModule",{value:!0})}));
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 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 = fn;\n $.params = params;\n $.datum = datum;\n $.event = event;\n $.item = item;\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":["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","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","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,IAA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","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,IACjBC,KAAYF,KAAKE,KACjBC,MAAYH,KAAKG,MACjBC,OAAYJ,KAAKI,OACjBC,GAAYL,KAAKK,GACjBC,QAAYN,KAAKM,QACjBC,MAAYP,KAAKO,MACjBC,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T3D,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,
@@ -170,6 +161,9 @@ var Functions = {
170
161
  test: (r, t) => RegExp(r).test(t)
171
162
  };
172
163
 
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);
173
167
  const Visitors = {
174
168
  Literal: ($, n) => n.value,
175
169
  Identifier: ($, n) => {
@@ -178,22 +172,28 @@ const Visitors = {
178
172
  },
179
173
  MemberExpression: ($, n) => {
180
174
  const d = !n.computed,
181
- o = $(n.object);
175
+ o = $(n.object);
182
176
  if (d) $.memberDepth += 1;
183
177
  const p = $(n.property);
184
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
+ }
185
184
  return o[p];
186
185
  },
187
186
  CallExpression: ($, n) => {
188
187
  const args = n.arguments;
189
- let name = n.callee.name; // handle special internal functions used by encoders
190
- // re-route to corresponding standard function
188
+ let name = n.callee.name;
191
189
 
190
+ // handle special internal functions used by encoders
191
+ // re-route to corresponding standard function
192
192
  if (name.startsWith('_')) {
193
193
  name = name.slice(1);
194
- } // special case "if" due to conditional evaluation of branches
195
-
194
+ }
196
195
 
196
+ // special case "if" due to conditional evaluation of branches
197
197
  return name === 'if' ? $(args[0]) ? $(args[1]) : $(args[2]) : ($.fn[name] || Functions[name]).apply($.fn, args.map($));
198
198
  },
199
199
  ArrayExpression: ($, n) => n.elements.map($),
@@ -205,19 +205,28 @@ const Visitors = {
205
205
  $.memberDepth += 1;
206
206
  const k = $(p.key);
207
207
  $.memberDepth -= 1;
208
- o[k] = $(p.value);
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
+ }
209
214
  return o;
210
215
  }, {})
211
216
  };
212
217
  function interpret (ast, fn, params, datum, event, item) {
213
218
  const $ = n => Visitors[n.type]($, n);
214
-
215
219
  $.memberDepth = 0;
216
- $.fn = fn;
220
+ $.fn = Object.create(fn);
217
221
  $.params = params;
218
222
  $.datum = datum;
219
223
  $.event = event;
220
224
  $.item = item;
225
+
226
+ // route event functions to annotated vega event context
227
+ EventFunctions.forEach(f => $.fn[f] = function () {
228
+ return event.vega[f](...arguments);
229
+ });
221
230
  return $(ast);
222
231
  }
223
232
 
@@ -227,72 +236,63 @@ var expression = {
227
236
  */
228
237
  operator(ctx, expr) {
229
238
  const ast = expr.ast,
230
- fn = ctx.functions;
239
+ fn = ctx.functions;
231
240
  return _ => interpret(ast, fn, _);
232
241
  },
233
-
234
242
  /**
235
243
  * Parse an expression provided as an operator parameter value.
236
244
  */
237
245
  parameter(ctx, expr) {
238
246
  const ast = expr.ast,
239
- fn = ctx.functions;
247
+ fn = ctx.functions;
240
248
  return (datum, _) => interpret(ast, fn, _, datum);
241
249
  },
242
-
243
250
  /**
244
251
  * Parse an expression applied to an event stream.
245
252
  */
246
253
  event(ctx, expr) {
247
254
  const ast = expr.ast,
248
- fn = ctx.functions;
255
+ fn = ctx.functions;
249
256
  return event => interpret(ast, fn, undefined, undefined, event);
250
257
  },
251
-
252
258
  /**
253
259
  * Parse an expression used to handle an event-driven operator update.
254
260
  */
255
261
  handler(ctx, expr) {
256
262
  const ast = expr.ast,
257
- fn = ctx.functions;
263
+ fn = ctx.functions;
258
264
  return (_, event) => {
259
265
  const datum = event.item && event.item.datum;
260
266
  return interpret(ast, fn, _, datum, event);
261
267
  };
262
268
  },
263
-
264
269
  /**
265
270
  * Parse an expression that performs visual encoding.
266
271
  */
267
272
  encode(ctx, encode) {
268
273
  const {
269
- marktype,
270
- channels
271
- } = encode,
272
- fn = ctx.functions,
273
- swap = marktype === 'group' || marktype === 'image' || marktype === 'rect';
274
+ marktype,
275
+ channels
276
+ } = encode,
277
+ fn = ctx.functions,
278
+ swap = marktype === 'group' || marktype === 'image' || marktype === 'rect';
274
279
  return (item, _) => {
275
280
  const datum = item.datum;
276
281
  let m = 0,
277
- v;
278
-
282
+ v;
279
283
  for (const name in channels) {
280
284
  v = interpret(channels[name].ast, fn, _, datum, undefined, item);
281
-
282
285
  if (item[name] !== v) {
283
286
  item[name] = v;
284
287
  m = 1;
285
288
  }
286
289
  }
287
-
288
290
  if (marktype !== 'rule') {
289
291
  adjustSpatial(item, channels, swap);
290
292
  }
291
-
292
293
  return m;
293
294
  };
294
295
  }
295
-
296
296
  };
297
297
 
298
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",
3
+ "version": "1.0.5",
4
4
  "description": "CSP-compliant interpreter for Vega expressions.",
5
5
  "keywords": [
6
6
  "vega",
@@ -17,7 +17,7 @@
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"
@@ -25,5 +25,5 @@
25
25
  "devDependencies": {
26
26
  "vega": "*"
27
27
  },
28
- "gitHead": "1d7db81379c538f8a8ee081a87702d8e4fdce30c"
28
+ "gitHead": "fb1092f6b931d450f9c210b67ae4752bd3dd461b"
29
29
  }
@@ -0,0 +1 @@
1
+ export { default } from '../../rollup.config.mjs';
package/src/interpret.js CHANGED
@@ -3,6 +3,16 @@ import Ops from './ops-binary';
3
3
  import Unary from './ops-unary';
4
4
  import Functions from './functions';
5
5
 
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);
15
+
6
16
  const Visitors = {
7
17
  Literal: ($, n) => n.value,
8
18
 
@@ -21,6 +31,11 @@ const Visitors = {
21
31
  if (d) $.memberDepth += 1;
22
32
  const p = $(n.property);
23
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
+ }
24
39
  return o[p];
25
40
  },
26
41
 
@@ -58,7 +73,12 @@ const Visitors = {
58
73
  $.memberDepth += 1;
59
74
  const k = $(p.key);
60
75
  $.memberDepth -= 1;
61
- o[k] = $(p.value);
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
+ }
62
82
  return o;
63
83
  }, {})
64
84
  };
@@ -66,10 +86,14 @@ const Visitors = {
66
86
  export default function(ast, fn, params, datum, event, item) {
67
87
  const $ = n => Visitors[n.type]($, n);
68
88
  $.memberDepth = 0;
69
- $.fn = fn;
89
+ $.fn = Object.create(fn);
70
90
  $.params = params;
71
91
  $.datum = datum;
72
92
  $.event = event;
73
93
  $.item = item;
94
+
95
+ // route event functions to annotated vega event context
96
+ EventFunctions.forEach(f => $.fn[f] = (...args) => event.vega[f](...args));
97
+
74
98
  return $(ast);
75
99
  }
package/rollup.config.js DELETED
@@ -1 +0,0 @@
1
- export { default } from '../../rollup.config';