vega-interpreter 1.0.4 → 1.1.0
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 +37 -43
- package/build/vega-interpreter.min.js +1 -1
- package/build/vega-interpreter.min.js.map +1 -1
- package/build/vega-interpreter.module.js +37 -37
- package/package.json +7 -3
- package/rollup.config.mjs +1 -0
- package/src/functions.js +3 -0
- package/src/interpret.js +20 -2
- package/rollup.config.js +0 -1
package/LICENSE
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vega = global.vega || {}));
|
|
5
|
-
}(this, (function (exports) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vega-util')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'vega-util'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vega = global.vega || {}, global.vega));
|
|
5
|
+
})(this, (function (exports, vegaUtil) { '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,
|
|
@@ -156,6 +147,7 @@
|
|
|
156
147
|
return apply('slice', arguments);
|
|
157
148
|
},
|
|
158
149
|
reverse: x => x.slice().reverse(),
|
|
150
|
+
sort: x => x.slice().sort(vegaUtil.ascending),
|
|
159
151
|
// string functions
|
|
160
152
|
parseFloat: parseFloat,
|
|
161
153
|
parseInt: parseInt,
|
|
@@ -177,6 +169,8 @@
|
|
|
177
169
|
};
|
|
178
170
|
|
|
179
171
|
const EventFunctions = ['view', 'item', 'group', 'xy', 'x', 'y'];
|
|
172
|
+
const DisallowedMethods = new Set([Function, eval, setTimeout, setInterval]);
|
|
173
|
+
if (typeof setImmediate === 'function') DisallowedMethods.add(setImmediate);
|
|
180
174
|
const Visitors = {
|
|
181
175
|
Literal: ($, n) => n.value,
|
|
182
176
|
Identifier: ($, n) => {
|
|
@@ -185,22 +179,28 @@
|
|
|
185
179
|
},
|
|
186
180
|
MemberExpression: ($, n) => {
|
|
187
181
|
const d = !n.computed,
|
|
188
|
-
|
|
182
|
+
o = $(n.object);
|
|
189
183
|
if (d) $.memberDepth += 1;
|
|
190
184
|
const p = $(n.property);
|
|
191
185
|
if (d) $.memberDepth -= 1;
|
|
186
|
+
if (DisallowedMethods.has(o[p])) {
|
|
187
|
+
// eslint-disable-next-line no-console
|
|
188
|
+
console.error(`Prevented interpretation of member "${p}" which could lead to insecure code execution`);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
192
191
|
return o[p];
|
|
193
192
|
},
|
|
194
193
|
CallExpression: ($, n) => {
|
|
195
194
|
const args = n.arguments;
|
|
196
|
-
let name = n.callee.name;
|
|
197
|
-
// re-route to corresponding standard function
|
|
195
|
+
let name = n.callee.name;
|
|
198
196
|
|
|
197
|
+
// handle special internal functions used by encoders
|
|
198
|
+
// re-route to corresponding standard function
|
|
199
199
|
if (name.startsWith('_')) {
|
|
200
200
|
name = name.slice(1);
|
|
201
|
-
}
|
|
202
|
-
|
|
201
|
+
}
|
|
203
202
|
|
|
203
|
+
// special case "if" due to conditional evaluation of branches
|
|
204
204
|
return name === 'if' ? $(args[0]) ? $(args[1]) : $(args[2]) : ($.fn[name] || Functions[name]).apply($.fn, args.map($));
|
|
205
205
|
},
|
|
206
206
|
ArrayExpression: ($, n) => n.elements.map($),
|
|
@@ -212,20 +212,25 @@
|
|
|
212
212
|
$.memberDepth += 1;
|
|
213
213
|
const k = $(p.key);
|
|
214
214
|
$.memberDepth -= 1;
|
|
215
|
-
|
|
215
|
+
if (DisallowedMethods.has($(p.value))) {
|
|
216
|
+
// eslint-disable-next-line no-console
|
|
217
|
+
console.error(`Prevented interpretation of property "${k}" which could lead to insecure code execution`);
|
|
218
|
+
} else {
|
|
219
|
+
o[k] = $(p.value);
|
|
220
|
+
}
|
|
216
221
|
return o;
|
|
217
222
|
}, {})
|
|
218
223
|
};
|
|
219
224
|
function interpret (ast, fn, params, datum, event, item) {
|
|
220
225
|
const $ = n => Visitors[n.type]($, n);
|
|
221
|
-
|
|
222
226
|
$.memberDepth = 0;
|
|
223
227
|
$.fn = Object.create(fn);
|
|
224
228
|
$.params = params;
|
|
225
229
|
$.datum = datum;
|
|
226
230
|
$.event = event;
|
|
227
|
-
$.item = item;
|
|
231
|
+
$.item = item;
|
|
228
232
|
|
|
233
|
+
// route event functions to annotated vega event context
|
|
229
234
|
EventFunctions.forEach(f => $.fn[f] = (...args) => event.vega[f](...args));
|
|
230
235
|
return $(ast);
|
|
231
236
|
}
|
|
@@ -236,76 +241,65 @@
|
|
|
236
241
|
*/
|
|
237
242
|
operator(ctx, expr) {
|
|
238
243
|
const ast = expr.ast,
|
|
239
|
-
|
|
244
|
+
fn = ctx.functions;
|
|
240
245
|
return _ => interpret(ast, fn, _);
|
|
241
246
|
},
|
|
242
|
-
|
|
243
247
|
/**
|
|
244
248
|
* Parse an expression provided as an operator parameter value.
|
|
245
249
|
*/
|
|
246
250
|
parameter(ctx, expr) {
|
|
247
251
|
const ast = expr.ast,
|
|
248
|
-
|
|
252
|
+
fn = ctx.functions;
|
|
249
253
|
return (datum, _) => interpret(ast, fn, _, datum);
|
|
250
254
|
},
|
|
251
|
-
|
|
252
255
|
/**
|
|
253
256
|
* Parse an expression applied to an event stream.
|
|
254
257
|
*/
|
|
255
258
|
event(ctx, expr) {
|
|
256
259
|
const ast = expr.ast,
|
|
257
|
-
|
|
260
|
+
fn = ctx.functions;
|
|
258
261
|
return event => interpret(ast, fn, undefined, undefined, event);
|
|
259
262
|
},
|
|
260
|
-
|
|
261
263
|
/**
|
|
262
264
|
* Parse an expression used to handle an event-driven operator update.
|
|
263
265
|
*/
|
|
264
266
|
handler(ctx, expr) {
|
|
265
267
|
const ast = expr.ast,
|
|
266
|
-
|
|
268
|
+
fn = ctx.functions;
|
|
267
269
|
return (_, event) => {
|
|
268
270
|
const datum = event.item && event.item.datum;
|
|
269
271
|
return interpret(ast, fn, _, datum, event);
|
|
270
272
|
};
|
|
271
273
|
},
|
|
272
|
-
|
|
273
274
|
/**
|
|
274
275
|
* Parse an expression that performs visual encoding.
|
|
275
276
|
*/
|
|
276
277
|
encode(ctx, encode) {
|
|
277
278
|
const {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
279
|
+
marktype,
|
|
280
|
+
channels
|
|
281
|
+
} = encode,
|
|
282
|
+
fn = ctx.functions,
|
|
283
|
+
swap = marktype === 'group' || marktype === 'image' || marktype === 'rect';
|
|
283
284
|
return (item, _) => {
|
|
284
285
|
const datum = item.datum;
|
|
285
286
|
let m = 0,
|
|
286
|
-
|
|
287
|
-
|
|
287
|
+
v;
|
|
288
288
|
for (const name in channels) {
|
|
289
289
|
v = interpret(channels[name].ast, fn, _, datum, undefined, item);
|
|
290
|
-
|
|
291
290
|
if (item[name] !== v) {
|
|
292
291
|
item[name] = v;
|
|
293
292
|
m = 1;
|
|
294
293
|
}
|
|
295
294
|
}
|
|
296
|
-
|
|
297
295
|
if (marktype !== 'rule') {
|
|
298
296
|
adjustSpatial(item, channels, swap);
|
|
299
297
|
}
|
|
300
|
-
|
|
301
298
|
return m;
|
|
302
299
|
};
|
|
303
300
|
}
|
|
304
|
-
|
|
305
301
|
};
|
|
306
302
|
|
|
307
303
|
exports.expressionInterpreter = expression;
|
|
308
304
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
})));
|
|
305
|
+
}));
|
|
@@ -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
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vega-util")):"function"==typeof define&&define.amd?define(["exports","vega-util"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).vega=e.vega||{},e.vega)}(this,(function(e,t){"use strict";var n={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},r={"*":(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 o=Array.prototype.slice,i=(e,t,n)=>{const r=n?n(t[0]):t[0];return r[e].apply(r,o.call(t,1))};var s={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 i("join",arguments)},indexof:function(){return i("indexOf",arguments)},lastindexof:function(){return i("lastIndexOf",arguments)},slice:function(){return i("slice",arguments)},reverse:e=>e.slice().reverse(),sort:e=>e.slice().sort(t.ascending),parseFloat:parseFloat,parseInt:parseInt,upper:e=>String(e).toUpperCase(),lower:e=>String(e).toLowerCase(),substring:function(){return i("substring",arguments,String)},split:function(){return i("split",arguments,String)},replace:function(){return i("replace",arguments,String)},trim:e=>String(e).trim(),regexp:RegExp,test:(e,t)=>RegExp(e).test(t)};const c=["view","item","group","xy","x","y"],u=new Set([Function,eval,setTimeout,setInterval]);"function"==typeof setImmediate&&u.add(setImmediate);const l={Literal:(e,t)=>t.value,Identifier:(e,t)=>{const r=t.name;return e.memberDepth>0?r:"datum"===r?e.datum:"event"===r?e.event:"item"===r?e.item:n[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),!u.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]||s[r]).apply(e.fn,n.map(e))},ArrayExpression:(e,t)=>t.elements.map(e),BinaryExpression:(e,t)=>r[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 r=e(n.key);return e.memberDepth-=1,u.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 m(e,t,n,r,a,o){const i=e=>l[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,c.forEach((e=>i.fn[e]=function(){return a.vega[e](...arguments)})),i(e)}var p={operator(e,t){const n=t.ast,r=e.functions;return e=>m(n,r,e)},parameter(e,t){const n=t.ast,r=e.functions;return(e,t)=>m(n,r,t,e)},event(e,t){const n=t.ast,r=e.functions;return e=>m(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 m(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=m(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=p}));
|
|
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,QACd,CAACD,EAAGC,IAAM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2D,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","import { ascending } from 'vega-util';\n\nconst 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 sort: x => x.slice().sort(ascending),\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","sort","ascending","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":"8RAAe,IAAAA,EAAA,CACbC,IAAYA,IACZC,EAAY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OQ,KACLR,EAAOxI,GACL2I,GAAQpD,EAAKvF,EAAIuF,EAAKyD,KACxB9E,EAAIqB,EAAKvF,EACTuF,EAAKvF,EAAIuF,EAAKyD,GACdzD,EAAKyD,GAAK9E,GAEZqB,EAAK0D,OAAS1D,EAAKyD,GAAKzD,EAAKvF,GAE7BuF,EAAKvF,EAAIuF,EAAKyD,IAAMzD,EAAK0D,QAAU,IAInCT,EAAOU,KACT3D,EAAKvF,EAAIuF,EAAK2D,IAAM3D,EAAK0D,QAAU,GAAK,EAE5C,CD0BQE,CAAc5D,EAAMmD,EAAUC,GAEzB5K,CAAC,CAEZ"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { ascending } from 'vega-util';
|
|
2
|
+
|
|
1
3
|
function adjustSpatial (item, encode, swap) {
|
|
2
4
|
let t;
|
|
3
|
-
|
|
4
5
|
if (encode.x2) {
|
|
5
6
|
if (encode.x) {
|
|
6
7
|
if (swap && item.x > item.x2) {
|
|
@@ -8,17 +9,14 @@ function adjustSpatial (item, encode, swap) {
|
|
|
8
9
|
item.x = item.x2;
|
|
9
10
|
item.x2 = t;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
12
|
item.width = item.x2 - item.x;
|
|
13
13
|
} else {
|
|
14
14
|
item.x = item.x2 - (item.width || 0);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
|
|
18
17
|
if (encode.xc) {
|
|
19
18
|
item.x = item.xc - (item.width || 0) / 2;
|
|
20
19
|
}
|
|
21
|
-
|
|
22
20
|
if (encode.y2) {
|
|
23
21
|
if (encode.y) {
|
|
24
22
|
if (swap && item.y > item.y2) {
|
|
@@ -26,13 +24,11 @@ function adjustSpatial (item, encode, swap) {
|
|
|
26
24
|
item.y = item.y2;
|
|
27
25
|
item.y2 = t;
|
|
28
26
|
}
|
|
29
|
-
|
|
30
27
|
item.height = item.y2 - item.y;
|
|
31
28
|
} else {
|
|
32
29
|
item.y = item.y2 - (item.height || 0);
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
|
-
|
|
36
32
|
if (encode.yc) {
|
|
37
33
|
item.y = item.yc - (item.height || 0) / 2;
|
|
38
34
|
}
|
|
@@ -82,14 +78,11 @@ var Unary = {
|
|
|
82
78
|
};
|
|
83
79
|
|
|
84
80
|
const slice = Array.prototype.slice;
|
|
85
|
-
|
|
86
81
|
const apply = (m, args, cast) => {
|
|
87
82
|
const obj = cast ? cast(args[0]) : args[0];
|
|
88
83
|
return obj[m].apply(obj, slice.call(args, 1));
|
|
89
84
|
};
|
|
90
|
-
|
|
91
85
|
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
86
|
var Functions = {
|
|
94
87
|
// math functions
|
|
95
88
|
isNaN: Number.isNaN,
|
|
@@ -150,6 +143,7 @@ var Functions = {
|
|
|
150
143
|
return apply('slice', arguments);
|
|
151
144
|
},
|
|
152
145
|
reverse: x => x.slice().reverse(),
|
|
146
|
+
sort: x => x.slice().sort(ascending),
|
|
153
147
|
// string functions
|
|
154
148
|
parseFloat: parseFloat,
|
|
155
149
|
parseInt: parseInt,
|
|
@@ -171,6 +165,8 @@ var Functions = {
|
|
|
171
165
|
};
|
|
172
166
|
|
|
173
167
|
const EventFunctions = ['view', 'item', 'group', 'xy', 'x', 'y'];
|
|
168
|
+
const DisallowedMethods = new Set([Function, eval, setTimeout, setInterval]);
|
|
169
|
+
if (typeof setImmediate === 'function') DisallowedMethods.add(setImmediate);
|
|
174
170
|
const Visitors = {
|
|
175
171
|
Literal: ($, n) => n.value,
|
|
176
172
|
Identifier: ($, n) => {
|
|
@@ -179,22 +175,28 @@ const Visitors = {
|
|
|
179
175
|
},
|
|
180
176
|
MemberExpression: ($, n) => {
|
|
181
177
|
const d = !n.computed,
|
|
182
|
-
|
|
178
|
+
o = $(n.object);
|
|
183
179
|
if (d) $.memberDepth += 1;
|
|
184
180
|
const p = $(n.property);
|
|
185
181
|
if (d) $.memberDepth -= 1;
|
|
182
|
+
if (DisallowedMethods.has(o[p])) {
|
|
183
|
+
// eslint-disable-next-line no-console
|
|
184
|
+
console.error(`Prevented interpretation of member "${p}" which could lead to insecure code execution`);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
186
187
|
return o[p];
|
|
187
188
|
},
|
|
188
189
|
CallExpression: ($, n) => {
|
|
189
190
|
const args = n.arguments;
|
|
190
|
-
let name = n.callee.name;
|
|
191
|
-
// re-route to corresponding standard function
|
|
191
|
+
let name = n.callee.name;
|
|
192
192
|
|
|
193
|
+
// handle special internal functions used by encoders
|
|
194
|
+
// re-route to corresponding standard function
|
|
193
195
|
if (name.startsWith('_')) {
|
|
194
196
|
name = name.slice(1);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
+
}
|
|
197
198
|
|
|
199
|
+
// special case "if" due to conditional evaluation of branches
|
|
198
200
|
return name === 'if' ? $(args[0]) ? $(args[1]) : $(args[2]) : ($.fn[name] || Functions[name]).apply($.fn, args.map($));
|
|
199
201
|
},
|
|
200
202
|
ArrayExpression: ($, n) => n.elements.map($),
|
|
@@ -206,21 +208,28 @@ const Visitors = {
|
|
|
206
208
|
$.memberDepth += 1;
|
|
207
209
|
const k = $(p.key);
|
|
208
210
|
$.memberDepth -= 1;
|
|
209
|
-
|
|
211
|
+
if (DisallowedMethods.has($(p.value))) {
|
|
212
|
+
// eslint-disable-next-line no-console
|
|
213
|
+
console.error(`Prevented interpretation of property "${k}" which could lead to insecure code execution`);
|
|
214
|
+
} else {
|
|
215
|
+
o[k] = $(p.value);
|
|
216
|
+
}
|
|
210
217
|
return o;
|
|
211
218
|
}, {})
|
|
212
219
|
};
|
|
213
220
|
function interpret (ast, fn, params, datum, event, item) {
|
|
214
221
|
const $ = n => Visitors[n.type]($, n);
|
|
215
|
-
|
|
216
222
|
$.memberDepth = 0;
|
|
217
223
|
$.fn = Object.create(fn);
|
|
218
224
|
$.params = params;
|
|
219
225
|
$.datum = datum;
|
|
220
226
|
$.event = event;
|
|
221
|
-
$.item = item;
|
|
227
|
+
$.item = item;
|
|
222
228
|
|
|
223
|
-
|
|
229
|
+
// route event functions to annotated vega event context
|
|
230
|
+
EventFunctions.forEach(f => $.fn[f] = function () {
|
|
231
|
+
return event.vega[f](...arguments);
|
|
232
|
+
});
|
|
224
233
|
return $(ast);
|
|
225
234
|
}
|
|
226
235
|
|
|
@@ -230,72 +239,63 @@ var expression = {
|
|
|
230
239
|
*/
|
|
231
240
|
operator(ctx, expr) {
|
|
232
241
|
const ast = expr.ast,
|
|
233
|
-
|
|
242
|
+
fn = ctx.functions;
|
|
234
243
|
return _ => interpret(ast, fn, _);
|
|
235
244
|
},
|
|
236
|
-
|
|
237
245
|
/**
|
|
238
246
|
* Parse an expression provided as an operator parameter value.
|
|
239
247
|
*/
|
|
240
248
|
parameter(ctx, expr) {
|
|
241
249
|
const ast = expr.ast,
|
|
242
|
-
|
|
250
|
+
fn = ctx.functions;
|
|
243
251
|
return (datum, _) => interpret(ast, fn, _, datum);
|
|
244
252
|
},
|
|
245
|
-
|
|
246
253
|
/**
|
|
247
254
|
* Parse an expression applied to an event stream.
|
|
248
255
|
*/
|
|
249
256
|
event(ctx, expr) {
|
|
250
257
|
const ast = expr.ast,
|
|
251
|
-
|
|
258
|
+
fn = ctx.functions;
|
|
252
259
|
return event => interpret(ast, fn, undefined, undefined, event);
|
|
253
260
|
},
|
|
254
|
-
|
|
255
261
|
/**
|
|
256
262
|
* Parse an expression used to handle an event-driven operator update.
|
|
257
263
|
*/
|
|
258
264
|
handler(ctx, expr) {
|
|
259
265
|
const ast = expr.ast,
|
|
260
|
-
|
|
266
|
+
fn = ctx.functions;
|
|
261
267
|
return (_, event) => {
|
|
262
268
|
const datum = event.item && event.item.datum;
|
|
263
269
|
return interpret(ast, fn, _, datum, event);
|
|
264
270
|
};
|
|
265
271
|
},
|
|
266
|
-
|
|
267
272
|
/**
|
|
268
273
|
* Parse an expression that performs visual encoding.
|
|
269
274
|
*/
|
|
270
275
|
encode(ctx, encode) {
|
|
271
276
|
const {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
+
marktype,
|
|
278
|
+
channels
|
|
279
|
+
} = encode,
|
|
280
|
+
fn = ctx.functions,
|
|
281
|
+
swap = marktype === 'group' || marktype === 'image' || marktype === 'rect';
|
|
277
282
|
return (item, _) => {
|
|
278
283
|
const datum = item.datum;
|
|
279
284
|
let m = 0,
|
|
280
|
-
|
|
281
|
-
|
|
285
|
+
v;
|
|
282
286
|
for (const name in channels) {
|
|
283
287
|
v = interpret(channels[name].ast, fn, _, datum, undefined, item);
|
|
284
|
-
|
|
285
288
|
if (item[name] !== v) {
|
|
286
289
|
item[name] = v;
|
|
287
290
|
m = 1;
|
|
288
291
|
}
|
|
289
292
|
}
|
|
290
|
-
|
|
291
293
|
if (marktype !== 'rule') {
|
|
292
294
|
adjustSpatial(item, channels, swap);
|
|
293
295
|
}
|
|
294
|
-
|
|
295
296
|
return m;
|
|
296
297
|
};
|
|
297
298
|
}
|
|
298
|
-
|
|
299
299
|
};
|
|
300
300
|
|
|
301
301
|
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.1.0",
|
|
4
4
|
"description": "CSP-compliant interpreter for Vega expressions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vega",
|
|
@@ -17,12 +17,16 @@
|
|
|
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
|
+
"dependencies": {
|
|
26
|
+
"vega-util": "^1.17.3"
|
|
27
|
+
},
|
|
25
28
|
"devDependencies": {
|
|
26
29
|
"vega": "*"
|
|
27
|
-
}
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "0e1eb8b091bc83a343bcb23caa87a6d8762abc54"
|
|
28
32
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '../../rollup.config.mjs';
|
package/src/functions.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ascending } from 'vega-util';
|
|
2
|
+
|
|
1
3
|
const slice = Array.prototype.slice;
|
|
2
4
|
|
|
3
5
|
const apply = (m, args, cast) => {
|
|
@@ -62,6 +64,7 @@ export default {
|
|
|
62
64
|
lastindexof: function() { return apply('lastIndexOf', arguments); },
|
|
63
65
|
slice: function() { return apply('slice', arguments); },
|
|
64
66
|
reverse: x => x.slice().reverse(),
|
|
67
|
+
sort: x => x.slice().sort(ascending),
|
|
65
68
|
|
|
66
69
|
// string functions
|
|
67
70
|
parseFloat: parseFloat,
|
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';
|