1 | void (function(){var _ion_browser_require_ = function(module,exports,require){var modules, normalize, require, resolve;
|
2 |
|
3 | if (this.global == null) {
|
4 | this.global = (function() {
|
5 | return this;
|
6 | })();
|
7 | }
|
8 |
|
9 | if (this.require != null) {
|
10 | return;
|
11 | }
|
12 |
|
13 | require = function(path) {
|
14 | var i, m, object, originalPath, steps;
|
15 | if (path === 'ion/browser/require') {
|
16 | return require;
|
17 | }
|
18 | originalPath = path;
|
19 | m = modules[path];
|
20 | if (!m) {
|
21 | if (path[path.length - 1] !== '/') {
|
22 | path += '/';
|
23 | }
|
24 | path += "index";
|
25 | m = modules[path];
|
26 | }
|
27 | if (!m) {
|
28 | steps = path.replace(/\/index$/, "").split(/\//);
|
29 | object = this;
|
30 | i = 0;
|
31 | while ((object != null) && i < steps.length) {
|
32 | object = object[steps[i]];
|
33 | i++;
|
34 | }
|
35 | if (object != null) {
|
36 | m = modules[originalPath] = {
|
37 | exports: object
|
38 | };
|
39 | }
|
40 | }
|
41 | if (!m) {
|
42 | throw new Error("Couldn't find module for: " + path);
|
43 | }
|
44 | if (!m.exports) {
|
45 | m.exports = {};
|
46 | m.id = path;
|
47 | m.call(this, m, m.exports, resolve(path));
|
48 | }
|
49 | return m.exports;
|
50 | };
|
51 |
|
52 | modules = {};
|
53 |
|
54 | normalize = require.normalize = function(curr, path) {
|
55 | var i, seg, segs;
|
56 | segs = curr.split("/");
|
57 | seg = void 0;
|
58 | if (path[0] !== ".") {
|
59 | return path;
|
60 | }
|
61 | segs.pop();
|
62 | path = path.split("/");
|
63 | i = 0;
|
64 | while (i < path.length) {
|
65 | seg = path[i];
|
66 | if (seg === "..") {
|
67 | segs.pop();
|
68 | } else {
|
69 | if (seg !== ".") {
|
70 | segs.push(seg);
|
71 | }
|
72 | }
|
73 | ++i;
|
74 | }
|
75 | return segs.join("/");
|
76 | };
|
77 |
|
78 | resolve = function(path) {
|
79 | return function(p) {
|
80 | return require(normalize(path, p));
|
81 | };
|
82 | };
|
83 |
|
84 | require.register = function(path, fn) {
|
85 | return modules[path] = fn;
|
86 | };
|
87 |
|
88 | require.loadAll = function() {
|
89 | var id, _results;
|
90 | _results = [];
|
91 | for (id in modules) {
|
92 | _results.push(require(id));
|
93 | }
|
94 | return _results;
|
95 | };
|
96 |
|
97 | require.getModuleIds = function() {
|
98 | return Object.keys(modules);
|
99 | };
|
100 |
|
101 | require.runTests = function(callback) {
|
102 | var fn;
|
103 | fn = function() {
|
104 | return require("ion/browser/tester").runTests(require.getModuleIds(), callback);
|
105 | };
|
106 | if (global.setTimeout != null) {
|
107 | return setTimeout(fn, 0);
|
108 | } else {
|
109 | return fn();
|
110 | }
|
111 | };
|
112 |
|
113 | require.compileScripts = function() {
|
114 | var compiledWrapper, compiler, ion, removeLastResult, result, scriptElement, template, _i, _len, _ref, _results;
|
115 | ion = require('ion');
|
116 | compiler = require('ion/compiler');
|
117 | _ref = document.querySelectorAll("script[type=ion]");
|
118 | _results = [];
|
119 | for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
120 | scriptElement = _ref[_i];
|
121 | compiledWrapper = eval("(function(){ " + (compiler.compile(scriptElement.innerHTML)) + " })");
|
122 | result = compiledWrapper.call(scriptElement);
|
123 | if (result != null) {
|
124 | if (typeof result.template) {
|
125 | template = result.call(scriptElement);
|
126 | removeLastResult = null;
|
127 | _results.push(template.watchValue(function(templateResult) {
|
128 | if (typeof removeLastResult === "function") {
|
129 | removeLastResult();
|
130 | }
|
131 | removeLastResult = null;
|
132 | if (templateResult != null) {
|
133 | return removeLastResult = ion.add(scriptElement.parentElement, templateResult);
|
134 | }
|
135 | }));
|
136 | } else {
|
137 | _results.push(ion.add(scriptElement.parentElement, result));
|
138 | }
|
139 | } else {
|
140 | _results.push(void 0);
|
141 | }
|
142 | }
|
143 | return _results;
|
144 | };
|
145 |
|
146 | if (typeof module === "undefined") {
|
147 | this.require = require;
|
148 | } else {
|
149 | module.exports = require;
|
150 | }
|
151 |
|
152 | if (global.window != null) {
|
153 | window.addEventListener((global.Polymer ? 'polymer-ready' : 'load'), function(e) {
|
154 | return require.compileScripts();
|
155 | });
|
156 | }
|
157 |
|
158 | }
|
159 | if (typeof require === 'function') {
|
160 | if (require.register)
|
161 | require.register('ion/browser/require',_ion_browser_require_);
|
162 | else
|
163 | _ion_browser_require_.call(this, module, exports, require);
|
164 | }
|
165 | else {
|
166 | _ion_browser_require_.call(this);
|
167 | }
|
168 | }).call(this)
|
169 | void (function(){var _ion_Object_ = function(module,exports,require){'use strict';
|
170 | var ion = require('./');
|
171 | var typeKey = '$';
|
172 | var _ref2 = {};
|
173 | {
|
174 | _ref2[typeKey] = ion.patch(_ref2[typeKey], {
|
175 | visible: false,
|
176 | type: 'string'
|
177 | });
|
178 | _ref2.toJSON = function () {
|
179 | var properties = {};
|
180 | if (this.constructor.id != null) {
|
181 | properties[this.constructor.typeKey] = this.constructor.id;
|
182 | }
|
183 | {
|
184 | var _ref = this;
|
185 | for (var key in _ref) {
|
186 | var value = _ref[key];
|
187 | if (this.hasOwnProperty(key)) {
|
188 | properties[key] = value;
|
189 | }
|
190 | }
|
191 | }
|
192 | return properties;
|
193 | };
|
194 | }
|
195 | var Object = ion.defineClass({
|
196 | name: 'Object',
|
197 | constructor: function Object(properties) {
|
198 | if (properties != null) {
|
199 | for (var key in properties) {
|
200 | var value = properties[key];
|
201 | var value = properties[key];
|
202 | this[key] = value;
|
203 | }
|
204 | }
|
205 | },
|
206 | typeKey: typeKey,
|
207 | is: function (object) {
|
208 | return object != null ? object.constructor.types != null ? object.constructor.types.has != null ? object.constructor.types.has(this) : void 0 : void 0 : void 0;
|
209 | },
|
210 | properties: _ref2,
|
211 | test: function () {
|
212 | var object = new Object();
|
213 | if (!Object.is(object))
|
214 | throw new Error('Assertion Failed: (Object.is(object))');
|
215 | }
|
216 | }, null);
|
217 | module.exports = exports = Object;
|
218 | }
|
219 | if (typeof require === 'function') {
|
220 | if (require.register)
|
221 | require.register('ion/Object',_ion_Object_);
|
222 | else
|
223 | _ion_Object_.call(this, module, exports, require);
|
224 | }
|
225 | else {
|
226 | _ion_Object_.call(this);
|
227 | }
|
228 | }).call(this)
|
229 |
|
230 | void (function(){var _ion_browser_element_ = function(module,exports,require){'use strict';
|
231 | var ion = require('../');
|
232 | var changeHandler = function change() {
|
233 | ion.checkForChanges();
|
234 | };
|
235 | var changeElements = {
|
236 | input: true,
|
237 | select: true,
|
238 | textarea: true
|
239 | };
|
240 | var elements = [
|
241 | 'div',
|
242 | 'span',
|
243 | 'input',
|
244 | 'textarea',
|
245 | 'a',
|
246 | 'br',
|
247 | 'img',
|
248 | 'p',
|
249 | 'button',
|
250 | 'caption',
|
251 | 'fieldset',
|
252 | 'form',
|
253 | 'frame',
|
254 | 'frameset',
|
255 | 'h1',
|
256 | 'h2',
|
257 | 'h3',
|
258 | 'h4',
|
259 | 'h5',
|
260 | 'h6',
|
261 | 'hr',
|
262 | 'legend',
|
263 | 'menu',
|
264 | 'option',
|
265 | 'select',
|
266 | 'script',
|
267 | 'pre',
|
268 | 'table',
|
269 | 'tbody',
|
270 | 'td',
|
271 | 'tr',
|
272 | 'thead',
|
273 | 'canvas',
|
274 | 'head',
|
275 | 'meta',
|
276 | 'body',
|
277 | 'script',
|
278 | 'section',
|
279 | 'header',
|
280 | 'footer',
|
281 | 'article',
|
282 | 'ul',
|
283 | 'ol',
|
284 | 'li',
|
285 | 'label',
|
286 | 'strong'
|
287 | ];
|
288 | var elementFactory = function (name, attributes, change) {
|
289 | var element = document.createElement(name);
|
290 | if (change) {
|
291 | ion.add(element, changeHandler);
|
292 | }
|
293 | if (attributes != null) {
|
294 | for (var key in attributes) {
|
295 | var value = attributes[key];
|
296 | element.setAttribute(key, value);
|
297 | }
|
298 | }
|
299 | return element;
|
300 | };
|
301 | var _ref = elementFactory;
|
302 | for (var _i = 0; _i < elements.length; _i++) {
|
303 | var name = elements[_i];
|
304 | _ref[name] = function (name) {
|
305 | return function (attributes) {
|
306 | return elementFactory(name, attributes, changeElements[name]);
|
307 | };
|
308 | }(name);
|
309 | }
|
310 | module.exports = exports = _ref;
|
311 | }
|
312 | if (typeof require === 'function') {
|
313 | if (require.register)
|
314 | require.register('ion/browser/element',_ion_browser_element_);
|
315 | else
|
316 | _ion_browser_element_.call(this, module, exports, require);
|
317 | }
|
318 | else {
|
319 | _ion_browser_element_.call(this);
|
320 | }
|
321 | }).call(this)
|
322 |
|
323 | void (function(){var _ion_browser_index_ = function(module,exports,require){Object.defineProperty(exports, 'element', {get:function(){ return require('./element') }, enumerable: true})
|
324 | Object.defineProperty(exports, 'require', {get:function(){ return require('./require') }, enumerable: true})
|
325 | Object.defineProperty(exports, 'tester', {get:function(){ return require('./tester') }, enumerable: true})
|
326 | }
|
327 | if (typeof require === 'function') {
|
328 | if (require.register)
|
329 | require.register('ion/browser/index',_ion_browser_index_);
|
330 | else
|
331 | _ion_browser_index_.call(this, module, exports, require);
|
332 | }
|
333 | else {
|
334 | _ion_browser_index_.call(this);
|
335 | }
|
336 | }).call(this)
|
337 | void (function(){var _ion_browser_tester_ = function(module,exports,require){var args, file, manifest, manifestFile, moduleId, modules, np, runTest, runTests, spawnTests, utility, _i, _len, _ref;
|
338 |
|
339 | runTest = function(name, test, callback) {
|
340 | var e, expectedCallbacks, key, result, value;
|
341 | expectedCallbacks = [];
|
342 | if (typeof test === 'object') {
|
343 | for (key in test) {
|
344 | value = test[key];
|
345 | expectedCallbacks = expectedCallbacks.concat(runTest(name + ' ' + key, value, callback));
|
346 | }
|
347 | } else if (typeof test === 'function') {
|
348 | if (/^\s*function\s*[a-zA-Z_0-9]*\s*\(\s*(done)?\s*\)/.test(test.toString())) {
|
349 | expectedCallbacks.push(name);
|
350 | try {
|
351 | if (test.length === 1) {
|
352 | test(function(error, warning) {
|
353 | return callback(name, error, warning);
|
354 | });
|
355 | } else {
|
356 | result = test();
|
357 | callback(name, null, result);
|
358 | }
|
359 | } catch (_error) {
|
360 | e = _error;
|
361 | callback(name, e, null);
|
362 | }
|
363 | }
|
364 | }
|
365 | return expectedCallbacks;
|
366 | };
|
367 |
|
368 | exports.spawnTests = spawnTests = function(manifestFile) {
|
369 | var command;
|
370 | command = "node" + (process.platform === 'win32' ? '.cmd' : '') + " " + __filename + " " + manifestFile;
|
371 | require('../builder/utility').spawn(command);
|
372 | };
|
373 |
|
374 | exports.runTests = runTests = function(moduleIds, callback) {
|
375 | var array, duration, e, error, expectedCallbacks, getIncompleteCallbacks, handler, inc, key, module, moduleId, name, timeout, waitingForFinishTimeout, warning, _i, _len;
|
376 | if (!moduleIds) {
|
377 | throw new Error("moduleIds is required");
|
378 | }
|
379 | if (callback == null) {
|
380 | callback = exports.createCallback();
|
381 | }
|
382 | expectedCallbacks = {};
|
383 | waitingForFinishTimeout = null;
|
384 | handler = function(name, error, warning) {
|
385 | var inc;
|
386 | expectedCallbacks[name] = true;
|
387 | callback(name, error, warning);
|
388 | if (waitingForFinishTimeout != null) {
|
389 | inc = getIncompleteCallbacks();
|
390 | if (inc.length === 0) {
|
391 | clearTimeout(waitingForFinishTimeout);
|
392 | return callback();
|
393 | }
|
394 | }
|
395 | };
|
396 | for (key in moduleIds) {
|
397 | moduleId = moduleIds[key];
|
398 | try {
|
399 | module = require(moduleId);
|
400 | name = Array.isArray(moduleIds) ? moduleId : key;
|
401 | array = runTest(name, module.test, handler);
|
402 | for (_i = 0, _len = array.length; _i < _len; _i++) {
|
403 | name = array[_i];
|
404 | if (expectedCallbacks[name] == null) {
|
405 | expectedCallbacks[name] = false;
|
406 | }
|
407 | }
|
408 | } catch (_error) {
|
409 | e = _error;
|
410 | handler(moduleId, e, null);
|
411 | }
|
412 | }
|
413 | getIncompleteCallbacks = function() {
|
414 | var value;
|
415 | return (function() {
|
416 | var _results;
|
417 | _results = [];
|
418 | for (name in expectedCallbacks) {
|
419 | value = expectedCallbacks[name];
|
420 | if (!value) {
|
421 | _results.push(name);
|
422 | }
|
423 | }
|
424 | return _results;
|
425 | })();
|
426 | };
|
427 | inc = getIncompleteCallbacks();
|
428 | if (inc.length === 0) {
|
429 | return callback();
|
430 | } else {
|
431 | duration = 1000;
|
432 | error = "Timed out after " + duration + " ms";
|
433 | warning = void 0;
|
434 | timeout = (function(_this) {
|
435 | return function() {
|
436 | var _j, _len1;
|
437 | inc = getIncompleteCallbacks();
|
438 | for (_j = 0, _len1 = inc.length; _j < _len1; _j++) {
|
439 | name = inc[_j];
|
440 | callback(name, error, warning);
|
441 | }
|
442 | return callback();
|
443 | };
|
444 | })(this);
|
445 | if (global.setTimeout != null) {
|
446 | return waitingForFinishTimeout = setTimeout(timeout, duration);
|
447 | } else {
|
448 | error = void 0;
|
449 | warning = "Platform missing setTimeout";
|
450 | return timeout();
|
451 | }
|
452 | }
|
453 | };
|
454 |
|
455 | exports.createCallback = function(options, html) {
|
456 | var beep, blue, endColor, endLine, fails, green, log, plain, red, start, tests, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
|
457 | if (html == null) {
|
458 | html = global.window != null;
|
459 | }
|
460 | if (options == null) {
|
461 | options = html ? {
|
462 | red: '<span style="color:red;white-space:pre">',
|
463 | green: '<span style="color:green;white-space:pre">',
|
464 | blue: '<span style="color:blue;white-space:pre">',
|
465 | plain: '<span>',
|
466 | endColor: '</span>',
|
467 | log: function(x) {
|
468 | return document.body.innerHTML += x;
|
469 | },
|
470 | beep: '',
|
471 | endLine: '<br>'
|
472 | } : {};
|
473 | }
|
474 | red = (_ref = options.red) != null ? _ref : '\u001b[31m';
|
475 | green = (_ref1 = options.green) != null ? _ref1 : '\u001b[32m';
|
476 | blue = (_ref2 = options.blue) != null ? _ref2 : '\u001b[36m';
|
477 | endColor = (_ref3 = options.endColor) != null ? _ref3 : '\u001b[0m';
|
478 | plain = (_ref4 = options.plain) != null ? _ref4 : '';
|
479 | beep = (_ref5 = options.beep) != null ? _ref5 : '\u0007';
|
480 | log = (_ref6 = options.log) != null ? _ref6 : function(x) {
|
481 | return console.log(x);
|
482 | };
|
483 | endLine = (_ref7 = options.endLine) != null ? _ref7 : '';
|
484 | tests = 0;
|
485 | fails = 0;
|
486 | start = null;
|
487 | return function(name, error, result) {
|
488 | var color, finish, passed, time, title, _ref10, _ref8, _ref9;
|
489 | if (start == null) {
|
490 | start = new Date().getTime();
|
491 | }
|
492 | if (name != null) {
|
493 | tests++;
|
494 | if (error != null) {
|
495 | fails++;
|
496 | }
|
497 | color = error != null ? red : result != null ? blue : plain;
|
498 | return log(color + name + ": " + ((_ref8 = (_ref9 = (_ref10 = error != null ? error.stack : void 0) != null ? _ref10 : error) != null ? _ref9 : result) != null ? _ref8 : "") + endColor + endLine);
|
499 | } else {
|
500 | finish = new Date().getTime();
|
501 | time = finish - start;
|
502 | passed = tests - fails;
|
503 | log(endLine);
|
504 | color = passed === tests ? green : red + beep;
|
505 | log(color + (title = "" + passed + "/" + tests + " Passed (" + time + " ms).") + endColor + endLine);
|
506 | if (global.document) {
|
507 | document.title = title;
|
508 | }
|
509 | return log(endLine);
|
510 | }
|
511 | };
|
512 | };
|
513 |
|
514 | exports.test = function() {
|
515 | var assert, tests;
|
516 | assert = {
|
517 | equal: function(a, b) {
|
518 | if (!a == b) {
|
519 | throw new Error("" + a + " != " + b);
|
520 | }
|
521 | }
|
522 | };
|
523 | tests = {
|
524 | alpha: function() {
|
525 | throw "Failure";
|
526 | },
|
527 | beta: function() {},
|
528 | charlie: function() {
|
529 | return "Return value";
|
530 | }
|
531 | };
|
532 | runTest('fail', (function() {
|
533 | throw 'Failure';
|
534 | }), function(name, error, result) {
|
535 | assert.equal(name, 'fail');
|
536 | assert.equal(error, 'Failure');
|
537 | return assert.equal(result, null);
|
538 | });
|
539 | runTest('pass', (function() {}), function(name, error, result) {
|
540 | assert.equal(name, 'pass');
|
541 | assert.equal(error, null);
|
542 | return assert.equal(result, null);
|
543 | });
|
544 | runTest('warn', (function() {
|
545 | return 'warning';
|
546 | }), function(name, error, result) {
|
547 | assert.equal(name, 'warn');
|
548 | assert.equal(error, null);
|
549 | return assert.equal(result, 'warning');
|
550 | });
|
551 | };
|
552 |
|
553 | if (require.main === module) {
|
554 | np = require('path');
|
555 | args = process.argv.slice(2).map(function(x) {
|
556 | return x.replace(/\\/g, '\/');
|
557 | });
|
558 | if (args.length < 1) {
|
559 | console.log("Usage: tester manifestFile");
|
560 | return;
|
561 | }
|
562 | manifestFile = args[0];
|
563 | utility = require('../builder/utility');
|
564 | manifest = JSON.parse(utility.read(manifestFile));
|
565 | modules = {};
|
566 | _ref = manifest.files;
|
567 | for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
568 | file = _ref[_i];
|
569 | moduleId = np.join(process.cwd(), np.dirname(manifestFile), file);
|
570 | modules[file] = moduleId;
|
571 | }
|
572 | console.log("------------------------------------------------------");
|
573 | runTests(modules);
|
574 | }
|
575 |
|
576 | }
|
577 | if (typeof require === 'function') {
|
578 | if (require.register)
|
579 | require.register('ion/browser/tester',_ion_browser_tester_);
|
580 | else
|
581 | _ion_browser_tester_.call(this, module, exports, require);
|
582 | }
|
583 | else {
|
584 | _ion_browser_tester_.call(this);
|
585 | }
|
586 | }).call(this)
|
587 |
|
588 |
|
589 |
|
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 | void (function(){var _ion_es6_Array_ = function(module,exports,require){'use strict';
|
609 | if (!(Array.prototype.add != null)) {
|
610 | Object.defineProperty(Array.prototype, 'add', { value: Array.prototype.push });
|
611 | }
|
612 | if (!(Array.prototype.remove != null)) {
|
613 | Object.defineProperty(Array.prototype, 'remove', {
|
614 | value: function () {
|
615 | for (var _i = 0; _i < arguments.length; _i++) {
|
616 | var item = arguments[_i];
|
617 | var index = this.lastIndexOf(item);
|
618 | if (index >= 0) {
|
619 | this.splice(index, 1);
|
620 | }
|
621 | }
|
622 | }
|
623 | });
|
624 | }
|
625 | if (!(Array.prototype.contains != null)) {
|
626 | Object.defineProperty(Array.prototype, 'contains', {
|
627 | value: function (item) {
|
628 | return this.indexOf(item) >= 0;
|
629 | }
|
630 | });
|
631 | }
|
632 | }
|
633 | if (typeof require === 'function') {
|
634 | if (require.register)
|
635 | require.register('ion/es6/Array',_ion_es6_Array_);
|
636 | else
|
637 | _ion_es6_Array_.call(this, module, exports, require);
|
638 | }
|
639 | else {
|
640 | _ion_es6_Array_.call(this);
|
641 | }
|
642 | }).call(this)
|
643 |
|
644 | void (function(){var _ion_es6_Function_ = function(module,exports,require){
|
645 |
|
646 | if (!(function f() {}).name) {
|
647 | Object.defineProperty(Function.prototype, 'name', {
|
648 | get: function() {
|
649 | var name = this.toString().match(/^\s*function\s*(\S*)\s*\(/)[1]
|
650 | Object.defineProperty(this, 'name', {value:name})
|
651 | return name
|
652 | }
|
653 | });
|
654 | }
|
655 |
|
656 | }
|
657 | if (typeof require === 'function') {
|
658 | if (require.register)
|
659 | require.register('ion/es6/Function',_ion_es6_Function_);
|
660 | else
|
661 | _ion_es6_Function_.call(this, module, exports, require);
|
662 | }
|
663 | else {
|
664 | _ion_es6_Function_.call(this);
|
665 | }
|
666 | }).call(this)
|
667 | void (function(){var _ion_es6_Map_ = function(module,exports,require){'use strict';
|
668 | var ion = null;
|
669 | var uniqueCounter = 0;
|
670 | var idName = '_Map_id_';
|
671 | var getId = function (key) {
|
672 | if (!(key != null)) {
|
673 | return String(key);
|
674 | }
|
675 | if (typeof key === 'string' || typeof key === 'number' || typeof key === 'boolean') {
|
676 | return '_' + key;
|
677 | }
|
678 | var id = key[idName];
|
679 | if (!(id != null)) {
|
680 | var def = Object.getOwnPropertyDescriptor(key, idName);
|
681 | if (def != null) {
|
682 | id = def.value;
|
683 | } else {
|
684 | id = ++uniqueCounter;
|
685 | Object.defineProperty(key, idName, { value: id });
|
686 | }
|
687 | }
|
688 | return id;
|
689 | };
|
690 | function MapShim(pairs) {
|
691 | if (pairs != null) {
|
692 | throw new Error('Don\'t add items in the constructor, IE implementation of Set breaks this');
|
693 | }
|
694 | var lookup = {};
|
695 | var keys = [];
|
696 | var methods = {
|
697 | get: function (key) {
|
698 | return lookup[getId(key)];
|
699 | },
|
700 | set: function (key, value) {
|
701 | var id = getId(key);
|
702 | if (!lookup.hasOwnProperty(id)) {
|
703 | keys.push(key);
|
704 | }
|
705 | lookup[id] = value;
|
706 | return value;
|
707 | },
|
708 | has: function (key) {
|
709 | var id = getId(key);
|
710 | return lookup.hasOwnProperty(id);
|
711 | },
|
712 | delete: function (key) {
|
713 | var id = getId(key);
|
714 | keys.remove(key);
|
715 | delete lookup[id];
|
716 | },
|
717 | clear: function () {
|
718 | lookup = {};
|
719 | keys = [];
|
720 | },
|
721 | forEach: function (callback, thisArg) {
|
722 | for (var _i = 0; _i < keys.length; _i++) {
|
723 | var key = keys[_i];
|
724 | var value = this.get(key);
|
725 | callback.call(thisArg, value, key, this);
|
726 | }
|
727 | }
|
728 | };
|
729 | for (var key in methods) {
|
730 | var value = methods[key];
|
731 | Object.defineProperty(this, key, { value: value });
|
732 | }
|
733 | }
|
734 | if (!((global.Map != null ? global.Map.prototype.forEach : void 0) != null)) {
|
735 | if (global.window) {
|
736 | console.warn('Shimming Map');
|
737 | }
|
738 | global.Map = MapShim;
|
739 | }
|
740 | var test = exports.test = function () {
|
741 | var Map = global.Map;
|
742 | var map = new Map();
|
743 | map.set('a', 1);
|
744 | map.set('b', 2);
|
745 | if (!(Object.keys(map).length === 0))
|
746 | throw new Error('Assertion Failed: (Object.keys(map).length is 0)');
|
747 | if (!map.has('a'))
|
748 | throw new Error('Assertion Failed: (map.has(\'a\'))');
|
749 | if (!!map.has('c'))
|
750 | throw new Error('Assertion Failed: (not map.has(\'c\'))');
|
751 | if (!(map.get('a') === 1))
|
752 | throw new Error('Assertion Failed: (map.get(\'a\') is 1)');
|
753 | if (!(map.get('b') === 2))
|
754 | throw new Error('Assertion Failed: (map.get(\'b\') is 2)');
|
755 | if (!(map.get('c') === void 0))
|
756 | throw new Error('Assertion Failed: (map.get(\'c\') is undefined)');
|
757 | var mykey1 = {};
|
758 | map.set(mykey1, 'one');
|
759 | if (!(Object.keys(mykey1).length === 0))
|
760 | throw new Error('Assertion Failed: (Object.keys(mykey1).length is 0)');
|
761 | if (!(map.get(mykey1) === 'one'))
|
762 | throw new Error('Assertion Failed: (map.get(mykey1) is "one")');
|
763 | };
|
764 | }
|
765 | if (typeof require === 'function') {
|
766 | if (require.register)
|
767 | require.register('ion/es6/Map',_ion_es6_Map_);
|
768 | else
|
769 | _ion_es6_Map_.call(this, module, exports, require);
|
770 | }
|
771 | else {
|
772 | _ion_es6_Map_.call(this);
|
773 | }
|
774 | }).call(this)
|
775 |
|
776 | void (function(){var _ion_es6_Object_ = function(module,exports,require){'use strict';
|
777 | if (!(Object.is != null)) {
|
778 | Object.defineProperty(Object, 'is', {
|
779 | value: function (a, b) {
|
780 | if (a === b) {
|
781 | if (a === 0) {
|
782 | return 1 / a === 1 / b;
|
783 | }
|
784 | return true;
|
785 | }
|
786 | return a !== a && b !== b;
|
787 | }
|
788 | });
|
789 | }
|
790 | }
|
791 | if (typeof require === 'function') {
|
792 | if (require.register)
|
793 | require.register('ion/es6/Object',_ion_es6_Object_);
|
794 | else
|
795 | _ion_es6_Object_.call(this, module, exports, require);
|
796 | }
|
797 | else {
|
798 | _ion_es6_Object_.call(this);
|
799 | }
|
800 | }).call(this)
|
801 |
|
802 | void (function(){var _ion_es6_Object_observe_ = function(module,exports,require){'use strict';
|
803 | var clone = function (object, properties) {
|
804 | if (properties != null) {
|
805 | var _ref3 = {};
|
806 | for (var key in properties) {
|
807 | _ref3[key] = object[key];
|
808 | }
|
809 | return _ref3;
|
810 | } else {
|
811 | var _ref4 = {};
|
812 | for (var key in object) {
|
813 | var value = object[key];
|
814 | _ref4[key] = value;
|
815 | }
|
816 | return _ref4;
|
817 | }
|
818 | };
|
819 | var createShim = exports.createShim = function () {
|
820 | var map = new Map();
|
821 | var observe = function (object, callback, property) {
|
822 | var meta = map.get(object);
|
823 | if (!(meta != null)) {
|
824 | var _ref5 = {};
|
825 | _ref5[property] = 0;
|
826 | meta = {
|
827 | object: object,
|
828 | properties: {},
|
829 | all: 0,
|
830 | clone: clone(object, property ? _ref5 : null),
|
831 | callbacks: []
|
832 | };
|
833 | map.set(object, meta);
|
834 | }
|
835 | if (property != null) {
|
836 | meta.properties[property] = meta.properties[property] != null ? meta.properties[property] : 0;
|
837 | meta.properties[property]++;
|
838 | } else {
|
839 | meta.all++;
|
840 | }
|
841 | meta.callbacks.push(callback);
|
842 | };
|
843 | var unobserve = function (object, callback, property) {
|
844 | var meta = map.get(object);
|
845 | if (meta != null) {
|
846 | meta.callbacks.remove(callback);
|
847 | if (meta.callbacks.length === 0) {
|
848 | map.delete(object);
|
849 | }
|
850 | if (property != null) {
|
851 | meta.properties[property]--;
|
852 | if (meta.properties[property] === 0) {
|
853 | delete meta.properties[property];
|
854 | }
|
855 | } else {
|
856 | meta.all--;
|
857 | }
|
858 | }
|
859 | };
|
860 | var getChanges = function (oldValue, newValue, properties) {
|
861 | var changes = null;
|
862 | var change = function (type, name, oldValue, object) {
|
863 | changes = changes != null ? changes : [];
|
864 | changes.push({
|
865 | type: type,
|
866 | name: name,
|
867 | oldValue: oldValue,
|
868 | object: object
|
869 | });
|
870 | };
|
871 | var checkForChange = function (property) {
|
872 | if (newValue.constructor === Object) {
|
873 | if (oldValue.hasOwnProperty(name)) {
|
874 | var oldPropertyValue = oldValue[name];
|
875 | if (!newValue.hasOwnProperty(name)) {
|
876 | if (oldPropertyValue !== void 0) {
|
877 | change('delete', name, oldPropertyValue, newValue);
|
878 | }
|
879 | } else {
|
880 | var newPropertyValue = newValue[name];
|
881 | if (!Object.is(newPropertyValue, oldPropertyValue)) {
|
882 | change('update', name, oldPropertyValue, newValue);
|
883 | }
|
884 | }
|
885 | } else if (newValue.hasOwnProperty(name)) {
|
886 | change('add', name, void 0, newValue);
|
887 | }
|
888 | } else {
|
889 | var oldPropertyValue = oldValue[name];
|
890 | var newPropertyValue = newValue[name];
|
891 | if (!Object.is(newPropertyValue, oldPropertyValue)) {
|
892 | change('update', name, oldPropertyValue, newValue);
|
893 | }
|
894 | }
|
895 | };
|
896 | if (properties != null) {
|
897 | for (var name in properties) {
|
898 | checkForChange(name);
|
899 | }
|
900 | } else {
|
901 | for (var name in oldValue) {
|
902 | checkForChange(name);
|
903 | }
|
904 | for (var name in newValue) {
|
905 | if (!oldValue.hasOwnProperty(name)) {
|
906 | checkForChange(name);
|
907 | }
|
908 | }
|
909 | }
|
910 | return changes;
|
911 | };
|
912 | observe.checkForChanges = function () {
|
913 | var maxCycles = 10;
|
914 | for (var i = 0; i < maxCycles; i++) {
|
915 | var totalChanges = 0;
|
916 | var pendingChanges = [];
|
917 | map.forEach(function (meta, key) {
|
918 | var properties = meta.all > 0 ? null : meta.properties;
|
919 | var changes = getChanges(meta.clone, meta.object, properties);
|
920 | if (changes != null) {
|
921 | totalChanges++;
|
922 | meta.clone = clone(meta.object, properties);
|
923 | pendingChanges.push([
|
924 | changes,
|
925 | meta.callbacks.slice(0),
|
926 | meta
|
927 | ]);
|
928 | }
|
929 | });
|
930 | if (totalChanges === 0) {
|
931 | return;
|
932 | }
|
933 | for (var _i = 0; _i < pendingChanges.length; _i++) {
|
934 | var _ref6 = pendingChanges[_i];
|
935 | var changes = _ref6[0];
|
936 | var callbacks = _ref6[1];
|
937 | for (var _i2 = 0; _i2 < callbacks.length; _i2++) {
|
938 | var callback = callbacks[_i2];
|
939 | callback(changes);
|
940 | }
|
941 | }
|
942 | }
|
943 | throw new Error('Circular Object.observe dependency');
|
944 | };
|
945 | return {
|
946 | observe: observe,
|
947 | unobserve: unobserve
|
948 | };
|
949 | };
|
950 | var test = exports.test = function () {
|
951 | var _ref = createShim();
|
952 | var observe = _ref.observe;
|
953 | var unobserve = _ref.unobserve;
|
954 | var object = {
|
955 | a: 1,
|
956 | b: {
|
957 | c: 2,
|
958 | d: 3
|
959 | }
|
960 | };
|
961 | var changes;
|
962 | var handler = function (c) {
|
963 | changes = c;
|
964 | };
|
965 | observe(object, handler);
|
966 | object.a = 2;
|
967 | delete object.b;
|
968 | object.c = 5;
|
969 | observe.checkForChanges();
|
970 | if (!(JSON.stringify(changes) === JSON.stringify([
|
971 | {
|
972 | 'type': 'update',
|
973 | 'name': 'a',
|
974 | 'oldValue': 1,
|
975 | 'object': {
|
976 | 'a': 2,
|
977 | 'c': 5
|
978 | }
|
979 | },
|
980 | {
|
981 | 'type': 'delete',
|
982 | 'name': 'b',
|
983 | 'oldValue': {
|
984 | 'c': 2,
|
985 | 'd': 3
|
986 | },
|
987 | 'object': {
|
988 | 'a': 2,
|
989 | 'c': 5
|
990 | }
|
991 | },
|
992 | {
|
993 | 'type': 'add',
|
994 | 'name': 'c',
|
995 | 'object': {
|
996 | 'a': 2,
|
997 | 'c': 5
|
998 | }
|
999 | }
|
1000 | ])))
|
1001 | throw new Error('Assertion Failed: (JSON.stringify(changes) is JSON.stringify([{"type":"update","name":"a","oldValue":1,"object":{"a":2,"c":5}},{"type":"delete","name":"b","oldValue":{"c":2,"d":3},"object":{"a":2,"c":5}},{"type":"add","name":"c","object":{"a":2,"c":5}}]))');
|
1002 | unobserve(object, handler);
|
1003 | };
|
1004 | if (!(Object.observe != null) && global.Map != null) {
|
1005 | console.warn('Shimming Object.observe');
|
1006 | {
|
1007 | var _ref2 = createShim();
|
1008 | for (var key in _ref2) {
|
1009 | var value = _ref2[key];
|
1010 | Object[key] = value;
|
1011 | }
|
1012 | }
|
1013 | }
|
1014 | }
|
1015 | if (typeof require === 'function') {
|
1016 | if (require.register)
|
1017 | require.register('ion/es6/Object.observe',_ion_es6_Object_observe_);
|
1018 | else
|
1019 | _ion_es6_Object_observe_.call(this, module, exports, require);
|
1020 | }
|
1021 | else {
|
1022 | _ion_es6_Object_observe_.call(this);
|
1023 | }
|
1024 | }).call(this)
|
1025 |
|
1026 | void (function(){var _ion_es6_Set_ = function(module,exports,require){'use strict';
|
1027 | var ion = require('../');
|
1028 | require('./Map');
|
1029 | function SetShim(items) {
|
1030 | if (items != null) {
|
1031 | throw new Error('Don\'t add items in the constructor, IE implementation of Set breaks this');
|
1032 | }
|
1033 | var map = new Map();
|
1034 | var methods = {
|
1035 | has: function (key) {
|
1036 | return map.has(key);
|
1037 | },
|
1038 | delete: function (key) {
|
1039 | return map.delete(key);
|
1040 | },
|
1041 | add: function (key) {
|
1042 | return map.set(key, true);
|
1043 | },
|
1044 | forEach: function (callback, thisArg) {
|
1045 | map.forEach(ion.bind(function (value, key) {
|
1046 | callback.call(thisArg, key, this);
|
1047 | }, this));
|
1048 | }
|
1049 | };
|
1050 | for (var key in methods) {
|
1051 | var value = methods[key];
|
1052 | Object.defineProperty(this, key, { value: value });
|
1053 | }
|
1054 | }
|
1055 | if (!(global.Set != null) || !(Set.prototype.forEach != null)) {
|
1056 | if (global.window) {
|
1057 | console.warn('Shimming Set');
|
1058 | }
|
1059 | global.Set = SetShim;
|
1060 | }
|
1061 | var test = exports.test = function () {
|
1062 | var Set = global.Set;
|
1063 | var a = {};
|
1064 | var b = function () {
|
1065 | };
|
1066 | var set = new Set();
|
1067 | set.add(a);
|
1068 | set.add(b);
|
1069 | if (!set.has(a))
|
1070 | throw new Error('Assertion Failed: (set.has(a))');
|
1071 | if (!set.has(b))
|
1072 | throw new Error('Assertion Failed: (set.has(b))');
|
1073 | set.delete(b);
|
1074 | if (!!set.has(b))
|
1075 | throw new Error('Assertion Failed: (not set.has(b))');
|
1076 | set.add(b);
|
1077 | if (!set.has(b))
|
1078 | throw new Error('Assertion Failed: (set.has(b))');
|
1079 | };
|
1080 | }
|
1081 | if (typeof require === 'function') {
|
1082 | if (require.register)
|
1083 | require.register('ion/es6/Set',_ion_es6_Set_);
|
1084 | else
|
1085 | _ion_es6_Set_.call(this, module, exports, require);
|
1086 | }
|
1087 | else {
|
1088 | _ion_es6_Set_.call(this);
|
1089 | }
|
1090 | }).call(this)
|
1091 |
|
1092 | void (function(){var _ion_es6_String_ = function(module,exports,require){if (!String.prototype.endsWith) {
|
1093 | Object.defineProperty(String.prototype, 'endsWith', {
|
1094 | enumerable: false,
|
1095 | configurable: false,
|
1096 | writable: false,
|
1097 | value: function (searchString, position) {
|
1098 | position = position || this.length;
|
1099 | position = position - searchString.length;
|
1100 | var lastIndex = this.lastIndexOf(searchString);
|
1101 | return lastIndex !== -1 && lastIndex === position;
|
1102 | }
|
1103 | });
|
1104 | }
|
1105 |
|
1106 | if (!String.prototype.startsWith) {
|
1107 | Object.defineProperty(String.prototype, 'startsWith', {
|
1108 | enumerable: false,
|
1109 | configurable: false,
|
1110 | writable: false,
|
1111 | value: function (searchString, position) {
|
1112 | position = position || 0;
|
1113 | return this.indexOf(searchString, position) === position;
|
1114 | }
|
1115 | });
|
1116 | }
|
1117 |
|
1118 | if (!String.prototype.contains ) {
|
1119 | String.prototype.contains = function() {
|
1120 | return this.indexOf(arguments) !== -1;
|
1121 | };
|
1122 | }
|
1123 | }
|
1124 | if (typeof require === 'function') {
|
1125 | if (require.register)
|
1126 | require.register('ion/es6/String',_ion_es6_String_);
|
1127 | else
|
1128 | _ion_es6_String_.call(this, module, exports, require);
|
1129 | }
|
1130 | else {
|
1131 | _ion_es6_String_.call(this);
|
1132 | }
|
1133 | }).call(this)
|
1134 | void (function(){var _ion_es6_index_ = function(module,exports,require){'use strict';
|
1135 | require('./String');
|
1136 | require('./Map');
|
1137 | require('./Set');
|
1138 | require('./Object');
|
1139 | require('./Object.observe');
|
1140 | require('./Function');
|
1141 | require('./Array');
|
1142 | }
|
1143 | if (typeof require === 'function') {
|
1144 | if (require.register)
|
1145 | require.register('ion/es6/index',_ion_es6_index_);
|
1146 | else
|
1147 | _ion_es6_index_.call(this, module, exports, require);
|
1148 | }
|
1149 | else {
|
1150 | _ion_es6_index_.call(this);
|
1151 | }
|
1152 | }).call(this)
|
1153 |
|
1154 | void (function(){var _ion_index_ = function(module,exports,require){'use strict';
|
1155 | var ion = null;
|
1156 | require('./es6');
|
1157 | global.DEBUG = global.DEBUG != null ? global.DEBUG : true;
|
1158 | var primitive = {
|
1159 | string: true,
|
1160 | number: true,
|
1161 | boolean: true,
|
1162 | function: true
|
1163 | }, isPrimitive = function (object) {
|
1164 | return !(object != null) || primitive[typeof object] || false;
|
1165 | }, normalizeProperty = function (property, name) {
|
1166 | if (typeof property === 'function') {
|
1167 | property = {
|
1168 | writable: false,
|
1169 | value: property
|
1170 | };
|
1171 | } else if (isPrimitive(property) || Array.isArray(property)) {
|
1172 | property = { value: property };
|
1173 | }
|
1174 | if (!(property.get != null) && !(property.set != null) && !property.hasOwnProperty('value')) {
|
1175 | property.value = void 0;
|
1176 | }
|
1177 | if (property.hasOwnProperty('value')) {
|
1178 | property.writable = property.writable != null ? property.writable : true;
|
1179 | }
|
1180 | property.name = name;
|
1181 | return property;
|
1182 | }, normalizeProperties = function (properties) {
|
1183 | if (properties == null)
|
1184 | properties = {};
|
1185 | for (var name in properties) {
|
1186 | var property = properties[name];
|
1187 | properties[name] = normalizeProperty(property, name);
|
1188 | }
|
1189 | return properties;
|
1190 | }, variableArgConstructs = [
|
1191 | function (type, a) {
|
1192 | return new type();
|
1193 | },
|
1194 | function (type, a) {
|
1195 | return new type(a[0]);
|
1196 | },
|
1197 | function (type, a) {
|
1198 | return new type(a[0], a[1]);
|
1199 | },
|
1200 | function (type, a) {
|
1201 | return new type(a[0], a[1], a[2]);
|
1202 | },
|
1203 | function (type, a) {
|
1204 | return new type(a[0], a[1], a[2], a[3]);
|
1205 | },
|
1206 | function (type, a) {
|
1207 | return new type(a[0], a[1], a[2], a[3], a[4]);
|
1208 | },
|
1209 | function (type, a) {
|
1210 | return new type(a[0], a[1], a[2], a[3], a[4], a[5]);
|
1211 | },
|
1212 | function (type, a) {
|
1213 | return new type(a[0], a[1], a[2], a[3], a[4], a[5], a[6]);
|
1214 | },
|
1215 | function (type, a) {
|
1216 | return new type(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
|
1217 | },
|
1218 | function (type, a) {
|
1219 | return new type(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
|
1220 | },
|
1221 | function (type, a) {
|
1222 | return new type(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]);
|
1223 | }
|
1224 | ], nodeObserveShim = (Object.observe != null ? Object.observe.checkForChanges : void 0) ? Object : require('./es6/Object.observe').createShim(), isObjectObservable = function () {
|
1225 | var Node = global.Node != null ? global.Node : function () {
|
1226 | };
|
1227 | var NodeList = global.NodeList != null ? global.NodeList : function () {
|
1228 | };
|
1229 | return function (a) {
|
1230 | if (a instanceof Node || a instanceof NodeList) {
|
1231 | return false;
|
1232 | }
|
1233 | return true;
|
1234 | };
|
1235 | }();
|
1236 | var patch = exports.patch = function () {
|
1237 | var mergePatch = require('./mergePatch');
|
1238 | var patch = function (object, patch) {
|
1239 | return mergePatch.merge(object, patch);
|
1240 | };
|
1241 | for (var key in mergePatch) {
|
1242 | var value = mergePatch[key];
|
1243 | patch[key] = value;
|
1244 | }
|
1245 | return patch;
|
1246 | }(), create = exports.create = function (type, args) {
|
1247 | return variableArgConstructs[args.length](type, args);
|
1248 | }, setImmediate = exports.setImmediate = function () {
|
1249 | if (global.setImmediate != null) {
|
1250 | return global.setImmediate;
|
1251 | }
|
1252 | if (global.document != null) {
|
1253 | return function () {
|
1254 | var hiddenDiv = document.createElement('div');
|
1255 | var callbacks = [];
|
1256 | new MutationObserver(function (records) {
|
1257 | var cbList = callbacks;
|
1258 | callbacks = [];
|
1259 | for (var _i = 0; _i < cbList.length; _i++) {
|
1260 | var callback = cbList[_i];
|
1261 | callback();
|
1262 | }
|
1263 | }).observe(hiddenDiv, { attributes: true });
|
1264 | }();
|
1265 | return function setImmediate(callback) {
|
1266 | if (callbacks.length === 0) {
|
1267 | hiddenDiv.setAttribute('yes', 'no');
|
1268 | }
|
1269 | callbacks.push(callback);
|
1270 | };
|
1271 | }
|
1272 | return function (fn) {
|
1273 | setTimeout(fn, 0);
|
1274 | };
|
1275 | }(), template = exports.template = function (fn, template) {
|
1276 | fn.template = template != null ? template : true;
|
1277 | return fn;
|
1278 | }, createRuntime = exports.createRuntime = function (ast, args, parent) {
|
1279 | var Context = require('./runtime/Context');
|
1280 | var context = new Context(parent);
|
1281 | if (args != null) {
|
1282 | for (var name in args) {
|
1283 | var value = args[name];
|
1284 | context.setVariableLiteral(name, value);
|
1285 | }
|
1286 | }
|
1287 | return context.createRuntime(ast);
|
1288 | }, nextTick = exports.nextTick = (this.process != null ? this.process.nextTick : void 0) != null ? this.process.nextTick : function (fn) {
|
1289 | return setTimeout(fn, 0);
|
1290 | }, clone = exports.clone = function (object, deep) {
|
1291 | if (deep == null)
|
1292 | deep = false;
|
1293 | if (Array.isArray(object)) {
|
1294 | var _ref = [];
|
1295 | for (var _i2 = 0; _i2 < object.length; _i2++) {
|
1296 | var item = object[_i2];
|
1297 | _ref.push(deep ? clone(item, deep) : item);
|
1298 | }
|
1299 | return _ref;
|
1300 | } else if ((object != null ? object.constructor : void 0) === Object) {
|
1301 | var _ref3 = {};
|
1302 | for (var key in object) {
|
1303 | var value = object[key];
|
1304 | _ref3[key] = deep ? clone(value, deep) : value;
|
1305 | }
|
1306 | return _ref3;
|
1307 | } else {
|
1308 | return object;
|
1309 | }
|
1310 | }, observe = exports.observe = function (object, observer, property) {
|
1311 | if (object === global || object === console) {
|
1312 | return;
|
1313 | }
|
1314 | if (!isObjectObservable(object)) {
|
1315 | if (!(property != null)) {
|
1316 | return;
|
1317 | }
|
1318 | nodeObserveShim.observe(object, observer, property);
|
1319 | } else if (object != null && observer != null && Object.observe != null && typeof object === 'object') {
|
1320 | if (DEBUG) {
|
1321 | observer.tryWrapper = observer.tryWrapper != null ? observer.tryWrapper : function (changes) {
|
1322 | try {
|
1323 | observer(changes);
|
1324 | } catch (error) {
|
1325 | console.error('Exception in Object.observe callback', error);
|
1326 | }
|
1327 | };
|
1328 | }
|
1329 | Object.observe(object, observer.tryWrapper != null ? observer.tryWrapper : observer);
|
1330 | object.addEventListener != null ? object.addEventListener('change', observer) : void 0;
|
1331 | }
|
1332 | object != null ? object.onObserved != null ? object.onObserved(observer, property) : void 0 : void 0;
|
1333 | }, unobserve = exports.unobserve = function (object, observer, property) {
|
1334 | if (!isObjectObservable(object)) {
|
1335 | if (!(property != null)) {
|
1336 | return;
|
1337 | }
|
1338 | nodeObserveShim.unobserve(object, observer, property);
|
1339 | } else if (object != null && observer != null && Object.unobserve != null && typeof object === 'object') {
|
1340 | Object.unobserve(object, observer.tryWrapper != null ? observer.tryWrapper : observer);
|
1341 | object.removeEventListener != null ? object.removeEventListener('change', observer) : void 0;
|
1342 | }
|
1343 | object != null ? object.unObserved != null ? object.unObserved(observer, property) : void 0 : void 0;
|
1344 | }, checkForChanges = exports.checkForChanges = function () {
|
1345 | if (Object.observe.checkForChanges != null) {
|
1346 | Object.observe.checkForChanges();
|
1347 | } else {
|
1348 | nodeObserveShim.observe.checkForChanges();
|
1349 | }
|
1350 | }, bind = exports.bind = function (fn, thisArg) {
|
1351 | var newFn = fn.bind(thisArg);
|
1352 | if ((fn.name != null ? fn.name.length : void 0) > 0) {
|
1353 | newFn.id = fn.id != null ? fn.id : fn.name;
|
1354 | }
|
1355 | return newFn;
|
1356 | }, add = exports.add = function (container, item) {
|
1357 | var remove;
|
1358 | if (typeof item === 'function' && ((item.name != null ? item.name.length : void 0) > 0 || item.id != null) && typeof container.addEventListener === 'function') {
|
1359 | var name = item.id != null ? item.id : item.name;
|
1360 | var capture = false;
|
1361 | var captureSuffix = '_capture';
|
1362 | if (name.endsWith(captureSuffix)) {
|
1363 | capture = true;
|
1364 | name = name.substring(0, name.length - captureSuffix.length);
|
1365 | }
|
1366 | if ((Object.observe != null ? Object.observe.checkForChanges : void 0) != null) {
|
1367 | var originalItem = item;
|
1368 | item = function () {
|
1369 | originalItem.apply(this, arguments);
|
1370 | Object.observe.checkForChanges();
|
1371 | };
|
1372 | }
|
1373 | container.addEventListener(name, item, capture);
|
1374 | remove = function () {
|
1375 | container.removeEventListener(name, item);
|
1376 | };
|
1377 | } else if (container.nodeType === 1) {
|
1378 | if (typeof item !== 'string' && !((item != null ? item.nodeType : void 0) != null)) {
|
1379 | item = JSON.stringify(item);
|
1380 | }
|
1381 | if (typeof item === 'string') {
|
1382 | item = document.createTextNode(item);
|
1383 | }
|
1384 | container.appendChild(item);
|
1385 | remove = function () {
|
1386 | if (item.parentNode === container) {
|
1387 | container.removeChild(item);
|
1388 | }
|
1389 | };
|
1390 | } else {
|
1391 | if (container.push != null) {
|
1392 | container.push(item);
|
1393 | } else {
|
1394 | container.add(item);
|
1395 | }
|
1396 | remove = function () {
|
1397 | if (container.lastIndexOf != null && container.removeAt != null) {
|
1398 | var index = container.lastIndexOf(item);
|
1399 | if (index >= 0) {
|
1400 | container.removeAt(index);
|
1401 | }
|
1402 | } else if (typeof container.remove === 'function') {
|
1403 | container.remove(item);
|
1404 | } else if (Array.isArray(container)) {
|
1405 | var index = container.lastIndexOf(item);
|
1406 | if (index >= 0) {
|
1407 | container.splice(index, 1);
|
1408 | }
|
1409 | }
|
1410 | };
|
1411 | }
|
1412 | item != null ? item.onAdded != null ? item.onAdded(container) : void 0 : void 0;
|
1413 | return function () {
|
1414 | remove();
|
1415 | item != null ? item.onRemoved != null ? item.onRemoved(container) : void 0 : void 0;
|
1416 | };
|
1417 | }, defineProperties = exports.defineProperties = function (object, properties) {
|
1418 | return Object.defineProperties(object, normalizeProperties(properties));
|
1419 | }, defineClass = exports.defineClass = function (___definitions) {
|
1420 | var definitions = Array.prototype.slice.call(arguments, 0);
|
1421 | var classDefinition = definitions[0];
|
1422 | if (definitions[1] === void 0) {
|
1423 | definitions[1] = require('./Object');
|
1424 | }
|
1425 | classDefinition.super = definitions[1];
|
1426 | var name = classDefinition.name != null ? classDefinition.name : classDefinition.id != null ? classDefinition.id.match(/([a-z_0-9\$]+)(\.js)?$/i) != null ? classDefinition.id.match(/([a-z_0-9\$]+)(\.js)?$/i)[1] : void 0 : void 0;
|
1427 | if (!(name != null)) {
|
1428 | throw new Error('missing name property');
|
1429 | }
|
1430 | var classFunction;
|
1431 | if (classDefinition.hasOwnProperty('constructor')) {
|
1432 | classFunction = classDefinition.constructor;
|
1433 | } else if (classDefinition.super != null) {
|
1434 | classFunction = eval('(function ' + name + '() { ' + name + '.super.apply(this, arguments); })');
|
1435 | } else {
|
1436 | classFunction = eval('(function ' + name + '() {})');
|
1437 | }
|
1438 | var canSetClassProperty = function (key) {
|
1439 | if (key === 'name') {
|
1440 | return false;
|
1441 | }
|
1442 | var descriptor = Object.getOwnPropertyDescriptor(classFunction, key);
|
1443 | return !(descriptor != null) || descriptor.writable || !(descriptor.get != null);
|
1444 | };
|
1445 | var types = new Set();
|
1446 | types.add(classFunction);
|
1447 | for (var i = definitions.length - 1; i >= 0; i--) {
|
1448 | var definition = definitions[i];
|
1449 | if (definition != null) {
|
1450 | types.add(definition);
|
1451 | for (var key in definition) {
|
1452 | var value = definition[key];
|
1453 | if (key !== 'test' || i === 0) {
|
1454 | if (canSetClassProperty(key)) {
|
1455 | classFunction[key] = patch(classFunction[key], value);
|
1456 | }
|
1457 | }
|
1458 | }
|
1459 | }
|
1460 | }
|
1461 | classFunction.types = types;
|
1462 | if (classFunction.properties != null) {
|
1463 | defineProperties(classFunction.prototype, classFunction.properties);
|
1464 | }
|
1465 | return classFunction;
|
1466 | }, is = exports.is = function (instance, type) {
|
1467 | if (!(instance != null)) {
|
1468 | return false;
|
1469 | }
|
1470 | if (!(type != null)) {
|
1471 | return true;
|
1472 | }
|
1473 | if (typeof type === 'function') {
|
1474 | if (typeof instance.is === 'function') {
|
1475 | return instance.is(type);
|
1476 | }
|
1477 | return instance instanceof type;
|
1478 | } else {
|
1479 | return instance === type;
|
1480 | }
|
1481 | }, makeReactive = exports.makeReactive = function (object, activate) {
|
1482 | var observeCount = 0;
|
1483 | var deactivate = null;
|
1484 | return Object.defineProperties(object, {
|
1485 | onObserved: {
|
1486 | value: function () {
|
1487 | observeCount++;
|
1488 | if (observeCount === 1) {
|
1489 | deactivate = activate.call(object);
|
1490 | }
|
1491 | }
|
1492 | },
|
1493 | unObserved: {
|
1494 | value: function () {
|
1495 | observeCount--;
|
1496 | if (observeCount === 0) {
|
1497 | deactivate != null ? deactivate() : void 0;
|
1498 | }
|
1499 | }
|
1500 | }
|
1501 | });
|
1502 | }, serialize = exports.serialize = function (object) {
|
1503 | return JSON.stringify(object);
|
1504 | }, deserialize = exports.deserialize = function () {
|
1505 | var extractType = function (object) {
|
1506 | var typeKey = require('ion/Object').typeKey;
|
1507 | var typeName = object[typeKey];
|
1508 | if (!(typeName != null)) {
|
1509 | return Object;
|
1510 | }
|
1511 | var type = require(typeName);
|
1512 | if (!type.serializable) {
|
1513 | throw new Error('Type is not serializable: ' + typeName);
|
1514 | }
|
1515 | delete object[typeKey];
|
1516 | return type;
|
1517 | };
|
1518 | var deserialize = function (object) {
|
1519 | if (typeof object === 'string') {
|
1520 | object = JSON.parse(object);
|
1521 | }
|
1522 | var typeKey = require('ion/Object').typeKey;
|
1523 | var typeName = object[typeKey];
|
1524 | if (typeName != null) {
|
1525 | var type = require(typeName);
|
1526 | if (!type.serializable) {
|
1527 | throw new Error('Type is not serializable: ' + typeName);
|
1528 | }
|
1529 | var typedObject = new type();
|
1530 | for (var key in object) {
|
1531 | var value = object[key];
|
1532 | if (key !== typeKey) {
|
1533 | typedObject[key] = object[key];
|
1534 | }
|
1535 | }
|
1536 | return typedObject;
|
1537 | } else {
|
1538 | return object;
|
1539 | }
|
1540 | };
|
1541 | deserialize.extractType = extractType;
|
1542 | return deserialize;
|
1543 | }(), test = exports.test = {
|
1544 | defineClass: function () {
|
1545 | var Foo = defineClass({
|
1546 | id: 'Foo',
|
1547 | constructor: function (number) {
|
1548 | this.number = number;
|
1549 | },
|
1550 | properties: {
|
1551 | getValue: function () {
|
1552 | return this.number;
|
1553 | }
|
1554 | }
|
1555 | });
|
1556 | if (!(new Foo(2).getValue() === 2))
|
1557 | throw new Error('Assertion Failed: (new Foo(2).getValue() is 2)');
|
1558 | },
|
1559 | defineProperties: {
|
1560 | 'should allow primitive values': function () {
|
1561 | var object = {};
|
1562 | var result = defineProperties(object, {
|
1563 | f: function () {
|
1564 | return 'function';
|
1565 | },
|
1566 | i: 2,
|
1567 | b: true,
|
1568 | a: [],
|
1569 | s: 'hello'
|
1570 | });
|
1571 | if (!(object === result))
|
1572 | throw new Error('Assertion Failed: (object is result)');
|
1573 | if (!(typeof object.f === 'function'))
|
1574 | throw new Error('Assertion Failed: (typeof object.f is \'function\')');
|
1575 | if (!(object.f() === 'function'))
|
1576 | throw new Error('Assertion Failed: (object.f() is \'function\')');
|
1577 | if (!(object.i === 2))
|
1578 | throw new Error('Assertion Failed: (object.i is 2)');
|
1579 | if (!(object.b === true))
|
1580 | throw new Error('Assertion Failed: (object.b is true)');
|
1581 | if (!Array.isArray(object.a))
|
1582 | throw new Error('Assertion Failed: (Array.isArray(object.a))');
|
1583 | if (!(object.s === 'hello'))
|
1584 | throw new Error('Assertion Failed: (object.s is \'hello\')');
|
1585 | }
|
1586 | }
|
1587 | };
|
1588 | {
|
1589 | var _ref2 = [
|
1590 | 'runtime',
|
1591 | 'compiler',
|
1592 | 'builder',
|
1593 | 'browser'
|
1594 | ];
|
1595 | for (var _i3 = 0; _i3 < _ref2.length; _i3++) {
|
1596 | var name = _ref2[_i3];
|
1597 | (function (name) {
|
1598 | Object.defineProperty(exports, name, {
|
1599 | enumerable: true,
|
1600 | get: function () {
|
1601 | return require('./' + name);
|
1602 | }
|
1603 | });
|
1604 | }(name));
|
1605 | }
|
1606 | }
|
1607 | if (global.window != null) {
|
1608 | global.window.addEventListener('resize', checkForChanges);
|
1609 | }
|
1610 | }
|
1611 | if (typeof require === 'function') {
|
1612 | if (require.register)
|
1613 | require.register('ion/index',_ion_index_);
|
1614 | else
|
1615 | _ion_index_.call(this, module, exports, require);
|
1616 | }
|
1617 | else {
|
1618 | _ion_index_.call(this);
|
1619 | }
|
1620 | }).call(this)
|
1621 |
|
1622 | void (function(){var _ion_mergePatch_ = function(module,exports,require){'use strict';
|
1623 | var ion = require('./'), isObject = function (a) {
|
1624 | var type = typeof a;
|
1625 | return a != null && type === 'object' || type === 'function';
|
1626 | }, deleteValue = null;
|
1627 | var canSetProperty = exports.canSetProperty = function (object, key) {
|
1628 | return !(typeof object === 'function' && key === 'name');
|
1629 | }, merge = exports.merge = function (target, values, options) {
|
1630 | var deleteNull = (options != null ? options.deleteNull : void 0) != null ? options.deleteNull : true;
|
1631 | if ((values != null ? values.constructor : void 0) !== Object) {
|
1632 | return values;
|
1633 | }
|
1634 | if (!isObject(target)) {
|
1635 | if ((options != null ? options.factory : void 0) != null) {
|
1636 | target = options.factory(values);
|
1637 | } else {
|
1638 | target = {};
|
1639 | }
|
1640 | }
|
1641 | for (var key in values) {
|
1642 | var value = values[key];
|
1643 | if (deleteNull && value === deleteValue) {
|
1644 | delete target[key];
|
1645 | } else {
|
1646 | var newValue = merge(target[key], value, options);
|
1647 | if (canSetProperty(target, key)) {
|
1648 | target[key] = newValue;
|
1649 | }
|
1650 | }
|
1651 | }
|
1652 | return target;
|
1653 | }, combine = exports.combine = function (patch1, patch2) {
|
1654 | return merge(patch1, patch2, { deleteNull: false });
|
1655 | }, watch = exports.watch = function (object, handler, callInitial) {
|
1656 | if (callInitial == null)
|
1657 | callInitial = true;
|
1658 | if (!isObject(object)) {
|
1659 | throw new Error('Cannot watch: #{object}');
|
1660 | }
|
1661 | var subWatchers = {};
|
1662 | var pendingPatch = null;
|
1663 | var processPatch = function (patchValues) {
|
1664 | for (var name in patchValues) {
|
1665 | subWatchers[name] != null ? subWatchers[name]() : void 0;
|
1666 | var value = object[name];
|
1667 | if (isObject(value)) {
|
1668 | (function (name) {
|
1669 | var subHandler = function (patch) {
|
1670 | var basePatch = {};
|
1671 | basePatch[name] = patch;
|
1672 | queuePatch(basePatch);
|
1673 | };
|
1674 | subWatchers[name] = watch(value, subHandler, false);
|
1675 | }(name));
|
1676 | }
|
1677 | }
|
1678 | };
|
1679 | var pendingTimeout = null;
|
1680 | var queuePatch = function (patch) {
|
1681 | if (!callInitial) {
|
1682 | handler(patch);
|
1683 | } else {
|
1684 | pendingPatch = combine(pendingPatch, patch);
|
1685 | processPatch(pendingPatch);
|
1686 | pendingTimeout = pendingTimeout != null ? pendingTimeout : setTimeout(function () {
|
1687 | handler(pendingPatch);
|
1688 | pendingPatch = null;
|
1689 | pendingTimeout = null;
|
1690 | }, 0);
|
1691 | }
|
1692 | };
|
1693 | var watcher = function (changes) {
|
1694 | var patch = {};
|
1695 | for (var _i = 0; _i < changes.length; _i++) {
|
1696 | var change = changes[_i];
|
1697 | if (change.name[0] !== '_') {
|
1698 | patch = patch != null ? patch : {};
|
1699 | patch[change.name] = object[change.name] != null ? object[change.name] : deleteValue;
|
1700 | }
|
1701 | }
|
1702 | if (patch != null) {
|
1703 | queuePatch(patch);
|
1704 | }
|
1705 | };
|
1706 | if (DEBUG) {
|
1707 | var innerWatcher = watcher;
|
1708 | watcher = function (changes) {
|
1709 | try {
|
1710 | innerWatcher(changes);
|
1711 | } catch (e) {
|
1712 | console.error(e);
|
1713 | }
|
1714 | };
|
1715 | }
|
1716 | processPatch(object);
|
1717 | ion.observe(object, watcher);
|
1718 | return function () {
|
1719 | ion.unobserve(object, watcher);
|
1720 | for (var key in subWatchers) {
|
1721 | var value = subWatchers[key];
|
1722 | value();
|
1723 | }
|
1724 | };
|
1725 | }, diff = exports.diff = function (oldValue, newValue) {
|
1726 | if (oldValue === newValue) {
|
1727 | return void 0;
|
1728 | }
|
1729 | if (!(oldValue != null && newValue != null && typeof newValue === 'object' && typeof oldValue === 'object')) {
|
1730 | return newValue != null ? newValue : null;
|
1731 | }
|
1732 | var patch = void 0;
|
1733 | for (var name in oldValue) {
|
1734 | if (oldValue.hasOwnProperty(name)) {
|
1735 | var propertyDiff = diff(oldValue[name], newValue[name]);
|
1736 | if (propertyDiff !== void 0) {
|
1737 | patch = patch != null ? patch : {};
|
1738 | patch[name] = propertyDiff;
|
1739 | }
|
1740 | }
|
1741 | }
|
1742 | for (var name in newValue) {
|
1743 | if (newValue.hasOwnProperty(name) && !oldValue.hasOwnProperty(name)) {
|
1744 | patch = patch != null ? patch : {};
|
1745 | patch[name] = newValue[name];
|
1746 | }
|
1747 | }
|
1748 | return patch;
|
1749 | }, isChange = exports.isChange = function (oldValue, newValue) {
|
1750 | if (oldValue === newValue) {
|
1751 | return false;
|
1752 | }
|
1753 | if (!(oldValue != null && newValue != null && typeof newValue === 'object' && typeof oldValue === 'object')) {
|
1754 | return true;
|
1755 | }
|
1756 | for (var name in newValue) {
|
1757 | if (newValue[name] === null && !oldValue.hasOwnProperty(name)) {
|
1758 | continue;
|
1759 | }
|
1760 | if (isChange(oldValue[name], newValue[name])) {
|
1761 | return true;
|
1762 | }
|
1763 | }
|
1764 | return false;
|
1765 | }, test = exports.test = function () {
|
1766 | var equal = function (a, b) {
|
1767 | return !isChange(a, b) && !isChange(b, a);
|
1768 | };
|
1769 | return {
|
1770 | merge: function () {
|
1771 | if (!equal({
|
1772 | a: {
|
1773 | b: 2,
|
1774 | c: 3
|
1775 | },
|
1776 | d: 4
|
1777 | }, merge({ a: { b: 2 } }, {
|
1778 | a: { c: 3 },
|
1779 | d: 4
|
1780 | })))
|
1781 | throw new Error('Assertion Failed: (equal({a:{b:2,c:3},d:4}, merge({a:{b:2}}, {a:{c:3},d:4})))');
|
1782 | if (!equal({ b: 2 }, merge(null, { b: 2 })))
|
1783 | throw new Error('Assertion Failed: (equal({b:2}, merge(null, {b:2})))');
|
1784 | if (!equal({
|
1785 | a: 1,
|
1786 | b: 2
|
1787 | }, merge({
|
1788 | a: 1,
|
1789 | b: 2,
|
1790 | c: 3
|
1791 | }, { c: void 0 })))
|
1792 | throw new Error('Assertion Failed: (equal({a:1,b:2}, merge({a:1,b:2,c:3}, {c:undefined})))');
|
1793 | var double = function (x) {
|
1794 | return x * 2;
|
1795 | };
|
1796 | if (!equal({ a: double }, merge({}, { a: double })))
|
1797 | throw new Error('Assertion Failed: (equal({a:double}, merge({},{a:double})))');
|
1798 | },
|
1799 | isChange: function () {
|
1800 | if (!isChange({ a: 1 }, null))
|
1801 | throw new Error('Assertion Failed: (isChange({a:1}, null))');
|
1802 | if (!!isChange(null, null))
|
1803 | throw new Error('Assertion Failed: (not isChange(null, null))');
|
1804 | if (!isChange(void 0, null))
|
1805 | throw new Error('Assertion Failed: (isChange(undefined, null))');
|
1806 | if (!isChange(null, void 0))
|
1807 | throw new Error('Assertion Failed: (isChange(null, undefined))');
|
1808 | if (!!isChange({ a: 1 }, { a: 1 }))
|
1809 | throw new Error('Assertion Failed: (not isChange({a:1}, {a:1}))');
|
1810 | if (!!isChange({
|
1811 | a: {
|
1812 | b: 2,
|
1813 | c: 3
|
1814 | }
|
1815 | }, { a: { b: 2 } }))
|
1816 | throw new Error('Assertion Failed: (not isChange({a:{b:2,c:3}}, {a:{b:2}}))');
|
1817 | if (!isChange({ a: { b: 2 } }, { a: { b: 3 } }))
|
1818 | throw new Error('Assertion Failed: (isChange({a:{b:2}}, {a:{b:3}}))');
|
1819 | if (!!isChange({ a: 1 }, { b: null }))
|
1820 | throw new Error('Assertion Failed: (not isChange({a:1}, {b:null}))');
|
1821 | },
|
1822 | diff: function () {
|
1823 | if (!equal({ b: 2 }, diff({ a: 1 }, {
|
1824 | a: 1,
|
1825 | b: 2
|
1826 | })))
|
1827 | throw new Error('Assertion Failed: (equal({b:2}, diff({a:1}, {a:1,b:2})))');
|
1828 | if (!equal({
|
1829 | a: {
|
1830 | b: 3,
|
1831 | c: null
|
1832 | }
|
1833 | }, diff({
|
1834 | a: {
|
1835 | b: 2,
|
1836 | c: 4
|
1837 | }
|
1838 | }, { a: { b: 3 } })))
|
1839 | throw new Error('Assertion Failed: (equal({a:{b:3,c:null}}, diff({a:{b:2,c:4}}, {a:{b:3}})))');
|
1840 | if (!equal({ a: 1 }, diff(null, { a: 1 })))
|
1841 | throw new Error('Assertion Failed: (equal({a:1}, diff(null, {a:1})))');
|
1842 | if (!equal({ c: { d: { f: 4 } } }, diff({
|
1843 | a: 1,
|
1844 | b: 2,
|
1845 | c: {
|
1846 | d: {
|
1847 | e: 1,
|
1848 | f: 2
|
1849 | }
|
1850 | }
|
1851 | }, {
|
1852 | a: 1,
|
1853 | b: 2,
|
1854 | c: {
|
1855 | d: {
|
1856 | e: 1,
|
1857 | f: 4
|
1858 | }
|
1859 | }
|
1860 | })))
|
1861 | throw new Error('Assertion Failed: (equal({c:{d:{f:4}}}, diff({a:1,b:2,c:{d:{e:1,f:2}}}, {a:1,b:2,c:{d:{e:1,f:4}}})))');
|
1862 | if (!equal(null, diff({ a: 1 }, void 0)))
|
1863 | throw new Error('Assertion Failed: (equal(null, diff({a:1}, undefined)))');
|
1864 | if (!equal(null, diff({ a: 1 }, null)))
|
1865 | throw new Error('Assertion Failed: (equal(null, diff({a:1}, null)))');
|
1866 | if (!equal(void 0, diff({ a: { b: 2 } }, { a: { b: 2 } })))
|
1867 | throw new Error('Assertion Failed: (equal(undefined, diff({a:{b:2}}, {a:{b:2}})))');
|
1868 | },
|
1869 | observe: function (done) {
|
1870 | if (!(Object.observe != null)) {
|
1871 | return done(null, 'Object.observe missing.');
|
1872 | }
|
1873 | var source = {
|
1874 | name: 'Kris',
|
1875 | age: 41,
|
1876 | children: {
|
1877 | Sadera: {
|
1878 | grandchildren: {
|
1879 | One: 1,
|
1880 | Two: 2
|
1881 | }
|
1882 | },
|
1883 | Orion: {},
|
1884 | Third: {}
|
1885 | }
|
1886 | };
|
1887 | var target = ion.clone(source, true);
|
1888 | var unwatch = watch(source, function (patch) {
|
1889 | target = merge(target, patch);
|
1890 | if (equal(source, target)) {
|
1891 | done();
|
1892 | unwatch();
|
1893 | }
|
1894 | });
|
1895 | {
|
1896 | source.name = 'Fred';
|
1897 | source.children = ion.patch(source.children, {
|
1898 | Orion: {
|
1899 | a: 1,
|
1900 | b: 2,
|
1901 | c: 12
|
1902 | },
|
1903 | Sadera: { grandchildren: { three: 3 } }
|
1904 | });
|
1905 | }
|
1906 | delete source.children.Third;
|
1907 | ion.checkForChanges();
|
1908 | }
|
1909 | };
|
1910 | }();
|
1911 | }
|
1912 | if (typeof require === 'function') {
|
1913 | if (require.register)
|
1914 | require.register('ion/mergePatch',_ion_mergePatch_);
|
1915 | else
|
1916 | _ion_mergePatch_.call(this, module, exports, require);
|
1917 | }
|
1918 | else {
|
1919 | _ion_mergePatch_.call(this);
|
1920 | }
|
1921 | }).call(this)
|
1922 |
|
1923 | void (function(){var _ion_runtime_ArrayExpression_ = function(module,exports,require){'use strict';
|
1924 | var ion = require('../'), DynamicExpression = require('./DynamicExpression');
|
1925 | var ArrayExpression = ion.defineClass({
|
1926 | name: 'ArrayExpression',
|
1927 | constructor: function ArrayExpression() {
|
1928 | ArrayExpression.super.apply(this, arguments);
|
1929 | if (!(this.elements != null)) {
|
1930 | throw new Error('elements is required');
|
1931 | }
|
1932 | if (!(this.context != null)) {
|
1933 | throw new Error('context is required');
|
1934 | }
|
1935 | },
|
1936 | properties: {
|
1937 | observeElements: false,
|
1938 | notifyIfActive: function () {
|
1939 | if (this.isActive) {
|
1940 | this.notify();
|
1941 | }
|
1942 | },
|
1943 | setArgumentValue: function (key, value) {
|
1944 | if (this.argumentValues[key] !== value) {
|
1945 | if (this.observeElements) {
|
1946 | ion.unobserve(this.argumentValues[key], this.itemObserver);
|
1947 | }
|
1948 | this.argumentValues[key] = value;
|
1949 | if (this.observeElements) {
|
1950 | ion.observe(value, this.itemObserver = this.itemObserver != null ? this.itemObserver : ion.bind(function () {
|
1951 | this.notifyIfActive();
|
1952 | }, this));
|
1953 | }
|
1954 | this.notifyIfActive();
|
1955 | }
|
1956 | },
|
1957 | activate: function () {
|
1958 | if (!(this.argumentValues != null)) {
|
1959 | var _ref = [];
|
1960 | {
|
1961 | var _ref2 = this.elements;
|
1962 | for (var _i = 0; _i < _ref2.length; _i++) {
|
1963 | var item = _ref2[_i];
|
1964 | _ref.push(this.context.createRuntime(item));
|
1965 | }
|
1966 | }
|
1967 | this.expressions = _ref;
|
1968 | this.argumentValues = [];
|
1969 | this.expressionWatchers = [];
|
1970 | for (var key = 0; key < this.expressions.length; key++) {
|
1971 | this.expressionWatchers[key] = this.setArgumentValue.bind(this, key);
|
1972 | }
|
1973 | }
|
1974 | {
|
1975 | var _ref3 = this.expressions;
|
1976 | for (var _i2 = 0; _i2 < _ref3.length; _i2++) {
|
1977 | var key = _i2;
|
1978 | var expression = _ref3[_i2];
|
1979 | expression.watchValue(this.expressionWatchers[key]);
|
1980 | }
|
1981 | }
|
1982 | ArrayExpression.super.prototype.activate.apply(this, arguments);
|
1983 | this.setValue(this.argumentValues);
|
1984 | },
|
1985 | deactivate: function () {
|
1986 | {
|
1987 | var _ref4 = this.expressions;
|
1988 | for (var _i3 = 0; _i3 < _ref4.length; _i3++) {
|
1989 | var key = _i3;
|
1990 | var expression = _ref4[_i3];
|
1991 | expression.unwatchValue(this.expressionWatchers[key]);
|
1992 | }
|
1993 | }
|
1994 | ArrayExpression.super.prototype.deactivate.apply(this, arguments);
|
1995 | }
|
1996 | },
|
1997 | test: function () {
|
1998 | var Context = require('./Context');
|
1999 | var e = new ArrayExpression({
|
2000 | context: new Context(),
|
2001 | elements: [
|
2002 | {
|
2003 | type: 'Literal',
|
2004 | value: 1
|
2005 | },
|
2006 | {
|
2007 | type: 'Literal',
|
2008 | value: 2
|
2009 | }
|
2010 | ]
|
2011 | });
|
2012 | var result = void 0;
|
2013 | function watcher(value) {
|
2014 | result = value;
|
2015 | }
|
2016 | e.watchValue(watcher);
|
2017 | if (!(JSON.stringify(result) === '[1,2]'))
|
2018 | throw new Error('Assertion Failed: (JSON.stringify(result) is "[1,2]")');
|
2019 | e.unwatchValue(watcher);
|
2020 | }
|
2021 | }, DynamicExpression);
|
2022 | module.exports = exports = ArrayExpression;
|
2023 | }
|
2024 | if (typeof require === 'function') {
|
2025 | if (require.register)
|
2026 | require.register('ion/runtime/ArrayExpression',_ion_runtime_ArrayExpression_);
|
2027 | else
|
2028 | _ion_runtime_ArrayExpression_.call(this, module, exports, require);
|
2029 | }
|
2030 | else {
|
2031 | _ion_runtime_ArrayExpression_.call(this);
|
2032 | }
|
2033 | }).call(this)
|
2034 |
|
2035 | void (function(){var _ion_runtime_BlockStatement_ = function(module,exports,require){'use strict';
|
2036 | var ion = require('../'), Statement = require('./Statement');
|
2037 | var BlockStatement = ion.defineClass({
|
2038 | name: 'BlockStatement',
|
2039 | properties: {
|
2040 | activate: function () {
|
2041 | BlockStatement.super.prototype.activate.apply(this, arguments);
|
2042 | if (!(this.statements != null)) {
|
2043 | var _ref = [];
|
2044 | {
|
2045 | var _ref2 = this.body;
|
2046 | for (var _i = 0; _i < _ref2.length; _i++) {
|
2047 | var s = _ref2[_i];
|
2048 | _ref.push(this.context.createRuntime(s));
|
2049 | }
|
2050 | }
|
2051 | this.statements = _ref;
|
2052 | }
|
2053 | {
|
2054 | var _ref3 = this.statements;
|
2055 | for (var _i2 = 0; _i2 < _ref3.length; _i2++) {
|
2056 | var statement = _ref3[_i2];
|
2057 | statement.activate();
|
2058 | }
|
2059 | }
|
2060 | },
|
2061 | deactivate: function () {
|
2062 | BlockStatement.super.prototype.deactivate.apply(this, arguments);
|
2063 | for (var i = this.statements.length - 1; i >= 0; i--) {
|
2064 | var statement = this.statements[i];
|
2065 | statement.deactivate();
|
2066 | }
|
2067 | }
|
2068 | }
|
2069 | }, Statement);
|
2070 | module.exports = exports = BlockStatement;
|
2071 | }
|
2072 | if (typeof require === 'function') {
|
2073 | if (require.register)
|
2074 | require.register('ion/runtime/BlockStatement',_ion_runtime_BlockStatement_);
|
2075 | else
|
2076 | _ion_runtime_BlockStatement_.call(this, module, exports, require);
|
2077 | }
|
2078 | else {
|
2079 | _ion_runtime_BlockStatement_.call(this);
|
2080 | }
|
2081 | }).call(this)
|
2082 |
|
2083 | void (function(){var _ion_runtime_CallExpression_ = function(module,exports,require){'use strict';
|
2084 | var ion = require('../'), _ref = require('./');
|
2085 | var DynamicExpression = _ref.DynamicExpression;
|
2086 | var ArrayExpression = _ref.ArrayExpression;
|
2087 | var Factory = _ref.Factory;
|
2088 | var _ref2 = {};
|
2089 | {
|
2090 | _ref2.args = null;
|
2091 | _ref2.activate = function () {
|
2092 | CallExpression.super.prototype.activate.apply(this, arguments);
|
2093 | this.calleeExpression = this.calleeExpression != null ? this.calleeExpression : this.context.createRuntime(this.callee);
|
2094 | this.calleeExpression.watchValue(this.calleeWatcher = this.calleeWatcher != null ? this.calleeWatcher : ion.bind(function (value) {
|
2095 | if (this.isActive && !(value != null) && !this.existential && (this.loc != null ? this.loc.start.source : void 0) != null) {
|
2096 | console.warn('Function is ' + value + ' (' + Factory.toCode(this.callee) + ') (' + this.loc.start.source + ':' + this.loc.start.line + ':' + (this.loc.start.column + 1) + ')');
|
2097 | }
|
2098 | this.calleeValue = value;
|
2099 | var thisArg = this.calleeExpression.objectExpression != null ? this.calleeExpression.objectExpression.value : void 0;
|
2100 | if (thisArg !== this.thisArg) {
|
2101 | ion.unobserve(this.thisarg, this.thisObserver);
|
2102 | this.unwatch != null ? this.unwatch() : void 0;
|
2103 | this.thisArg = thisArg;
|
2104 | if (!(this.calleeValue != null ? this.calleeValue.template : void 0)) {
|
2105 | var deep = Array.isArray(thisArg);
|
2106 | if (deep) {
|
2107 | this.unwatch = ion.patch.watch(thisArg, this.thisObserver = this.thisObserver != null ? this.thisObserver : ion.bind(function (patch) {
|
2108 | this.evaluate();
|
2109 | }, this));
|
2110 | } else {
|
2111 | ion.observe(thisArg, this.thisObserver = this.thisObserver != null ? this.thisObserver : ion.bind(function () {
|
2112 | this.evaluate();
|
2113 | }, this));
|
2114 | }
|
2115 | }
|
2116 | }
|
2117 | this.evaluate();
|
2118 | }, this));
|
2119 | this.argumentExpressions = this.argumentExpressions != null ? this.argumentExpressions : this.context.createRuntime({
|
2120 | type: 'ArrayExpression',
|
2121 | elements: this.arguments,
|
2122 | observeElements: !(this.calleeValue != null ? this.calleeValue.template : void 0)
|
2123 | });
|
2124 | this.argumentExpressions.watchValue(this.argumentWatcher = this.argumentWatcher != null ? this.argumentWatcher : ion.bind(function (value) {
|
2125 | this.argumentsValue = value;
|
2126 | this.evaluate();
|
2127 | }, this));
|
2128 | };
|
2129 | _ref2.deactivate = function () {
|
2130 | CallExpression.super.prototype.deactivate.apply(this, arguments);
|
2131 | this.calleeExpression.unwatchValue(this.calleeWatcher);
|
2132 | this.argumentExpressions.unwatchValue(this.argumentWatcher);
|
2133 | if (this.template != null) {
|
2134 | this.template.unwatchValue(this.templateWatcher);
|
2135 | delete this.template;
|
2136 | }
|
2137 | };
|
2138 | _ref2._evaluateInternal = function () {
|
2139 | if (!(this.isActive && this.calleeValue != null && this.argumentsValue != null)) {
|
2140 | return;
|
2141 | }
|
2142 | var value = void 0;
|
2143 | if (this.calleeValue.template) {
|
2144 | if (this.template != null) {
|
2145 | this.template.unwatchValue(this.templateWatcher);
|
2146 | }
|
2147 | this.template = this.calleeValue.apply(this.thisArg, this.argumentsValue);
|
2148 | this.template.watchValue(this.templateWatcher = this.templateWatcher != null ? this.templateWatcher : this.setValue.bind(this));
|
2149 | } else {
|
2150 | if (this.type === 'NewExpression') {
|
2151 | value = ion.create(this.calleeValue, this.argumentsValue);
|
2152 | } else {
|
2153 | value = this.calleeValue.apply(this.thisArg, this.argumentsValue);
|
2154 | }
|
2155 | this.setValue(value);
|
2156 | }
|
2157 | };
|
2158 | if (DEBUG) {
|
2159 | _ref2.evaluate = function () {
|
2160 | try {
|
2161 | this._evaluateInternal();
|
2162 | } catch (e) {
|
2163 | console.error(e.stack != null ? e.stack : e);
|
2164 | }
|
2165 | };
|
2166 | } else {
|
2167 | _ref2.evaluate = function () {
|
2168 | return this._evaluateInternal();
|
2169 | };
|
2170 | }
|
2171 | }
|
2172 | var CallExpression = ion.defineClass({
|
2173 | name: 'CallExpression',
|
2174 | properties: _ref2
|
2175 | }, DynamicExpression);
|
2176 | module.exports = CallExpression;
|
2177 | }
|
2178 | if (typeof require === 'function') {
|
2179 | if (require.register)
|
2180 | require.register('ion/runtime/CallExpression',_ion_runtime_CallExpression_);
|
2181 | else
|
2182 | _ion_runtime_CallExpression_.call(this, module, exports, require);
|
2183 | }
|
2184 | else {
|
2185 | _ion_runtime_CallExpression_.call(this);
|
2186 | }
|
2187 | }).call(this)
|
2188 |
|
2189 | void (function(){var _ion_runtime_ConditionalExpression_ = function(module,exports,require){'use strict';
|
2190 | var ion = require('../'), DynamicExpression = require('./DynamicExpression');
|
2191 | var ConditionalExpression = ion.defineClass({
|
2192 | name: 'ConditionalExpression',
|
2193 | properties: {
|
2194 | activate: function () {
|
2195 | ConditionalExpression.super.prototype.activate.apply(this, arguments);
|
2196 | this.testExpression = this.testExpression != null ? this.testExpression : this.context.createRuntime(this.test);
|
2197 | this.testExpression.watchValue(this.testWatcher = this.testWatcher != null ? this.testWatcher : ion.bind(function (value) {
|
2198 | if (!this.hasOwnProperty('testValue') || Boolean(value) !== Boolean(this.testValue)) {
|
2199 | this.testValue = value;
|
2200 | if (value) {
|
2201 | this.alternateExpression != null ? this.alternateExpression.unwatchValue(this.alternateWatcher) : void 0;
|
2202 | this.alternateExpression = null;
|
2203 | this.consequentExpression = this.consequentExpression != null ? this.consequentExpression : this.context.createRuntime(this.consequent);
|
2204 | this.consequentExpression.watchValue(this.consequentWatcher = this.consequentWatcher != null ? this.consequentWatcher : ion.bind(function (value) {
|
2205 | if (this.testValue) {
|
2206 | this.setValue(value);
|
2207 | }
|
2208 | }, this));
|
2209 | } else {
|
2210 | this.consequentExpression != null ? this.consequentExpression.unwatchValue(this.consequentWatcher) : void 0;
|
2211 | this.consequentExpression = null;
|
2212 | this.alternateExpression = this.alternateExpression != null ? this.alternateExpression : this.context.createRuntime(this.alternate);
|
2213 | this.alternateExpression.watchValue(this.alternateWatcher = this.alternateWatcher != null ? this.alternateWatcher : ion.bind(function (value) {
|
2214 | if (!this.testValue) {
|
2215 | this.setValue(value);
|
2216 | }
|
2217 | }, this));
|
2218 | }
|
2219 | }
|
2220 | }, this));
|
2221 | },
|
2222 | deactivate: function () {
|
2223 | ConditionalExpression.super.prototype.deactivate.apply(this, arguments);
|
2224 | this.testExpression.unwatchValue(this.testWatcher);
|
2225 | this.consequentExpression != null ? this.consequentExpression.unwatchValue(this.consequentWatcher) : void 0;
|
2226 | this.alternateExpression != null ? this.alternateExpression.unwatchValue(this.alternateWatcher) : void 0;
|
2227 | }
|
2228 | }
|
2229 | }, DynamicExpression);
|
2230 | module.exports = ConditionalExpression;
|
2231 | }
|
2232 | if (typeof require === 'function') {
|
2233 | if (require.register)
|
2234 | require.register('ion/runtime/ConditionalExpression',_ion_runtime_ConditionalExpression_);
|
2235 | else
|
2236 | _ion_runtime_ConditionalExpression_.call(this, module, exports, require);
|
2237 | }
|
2238 | else {
|
2239 | _ion_runtime_ConditionalExpression_.call(this);
|
2240 | }
|
2241 | }).call(this)
|
2242 |
|
2243 | void (function(){var _ion_runtime_Context_ = function(module,exports,require){'use strict';
|
2244 | var ion = require('../'), Factory = require('./Factory'), Literal = require('./Literal'), noop = function () {
|
2245 | };
|
2246 | var Context = ion.defineClass({
|
2247 | name: 'Context',
|
2248 | constructor: function Context(parent, output) {
|
2249 | this.output = output;
|
2250 | this.parent = parent;
|
2251 | this.variables = {};
|
2252 | this.root = (this.parent != null ? this.parent.root : void 0) != null ? this.parent.root : this;
|
2253 | this._watched = {};
|
2254 | this._runtimes = {};
|
2255 | },
|
2256 | properties: {
|
2257 | newContext: function (output) {
|
2258 | if (output == null)
|
2259 | output = this.output;
|
2260 | return new Context(this, output);
|
2261 | },
|
2262 | createRuntime: function (node) {
|
2263 | return Factory.createRuntime(this, node);
|
2264 | },
|
2265 | get: function (name) {
|
2266 | var variable = this.getVariable(name);
|
2267 | if (!(variable != null)) {
|
2268 | throw new Error('Variable not found: \'' + name + '\'');
|
2269 | }
|
2270 | return variable.value;
|
2271 | },
|
2272 | getVariable: function (name) {
|
2273 | var context = this, value;
|
2274 | while (context != null) {
|
2275 | var variable = context.variables[name];
|
2276 | if (variable != null) {
|
2277 | return variable;
|
2278 | }
|
2279 | context = context.parent;
|
2280 | }
|
2281 | value = global[name];
|
2282 | if (value === void 0) {
|
2283 | throw new Error('Variable not found: \'' + name + '\'');
|
2284 | }
|
2285 | var cachedGlobals = this.root.globals = this.root.globals != null ? this.root.globals : {};
|
2286 | return cachedGlobals[name] = cachedGlobals[name] != null ? cachedGlobals[name] : new Literal({ value: value });
|
2287 | },
|
2288 | setVariableFromAst: function (name, node) {
|
2289 | if (name != null) {
|
2290 | this.setVariableExpression(name, this.createRuntime(node));
|
2291 | }
|
2292 | },
|
2293 | setVariableLiteral: function (name, value) {
|
2294 | if (name != null) {
|
2295 | this.setVariableExpression(name, new Literal({ value: value }));
|
2296 | }
|
2297 | },
|
2298 | setVariableExpression: function (name, expression) {
|
2299 | if (name != null) {
|
2300 | expression.watchValue(noop);
|
2301 | return this.variables[name] = expression;
|
2302 | }
|
2303 | }
|
2304 | }
|
2305 | });
|
2306 | module.exports = exports = Context;
|
2307 | }
|
2308 | if (typeof require === 'function') {
|
2309 | if (require.register)
|
2310 | require.register('ion/runtime/Context',_ion_runtime_Context_);
|
2311 | else
|
2312 | _ion_runtime_Context_.call(this, module, exports, require);
|
2313 | }
|
2314 | else {
|
2315 | _ion_runtime_Context_.call(this);
|
2316 | }
|
2317 | }).call(this)
|
2318 |
|
2319 | void (function(){var _ion_runtime_DynamicExpression_ = function(module,exports,require){'use strict';
|
2320 | var ion = require('../');
|
2321 | var DynamicExpression = ion.defineClass({
|
2322 | name: 'DynamicExpression',
|
2323 | properties: {
|
2324 | isActive: false,
|
2325 | activate: function () {
|
2326 | this.isActive = true;
|
2327 | },
|
2328 | deactivate: function () {
|
2329 | this.isActive = false;
|
2330 | },
|
2331 | watchValue: function (watcher) {
|
2332 | var watchers = this._watchers = this._watchers != null ? this._watchers : [];
|
2333 | if (watchers.length === 0) {
|
2334 | this.activate();
|
2335 | }
|
2336 | watchers.push(watcher);
|
2337 | if (this.hasValue()) {
|
2338 | var value = this.getValue();
|
2339 | this._notifyWatcher(watcher, value);
|
2340 | }
|
2341 | },
|
2342 | unwatchValue: function (watcher) {
|
2343 | this._watchers.remove(watcher);
|
2344 | if (this.hasValue()) {
|
2345 | this._notifyWatcher(watcher, void 0);
|
2346 | }
|
2347 | if (this._watchers.length === 0) {
|
2348 | this.deactivate();
|
2349 | }
|
2350 | },
|
2351 | _notifyWatcher: function (watcher, value) {
|
2352 | return watcher.call(this, value);
|
2353 | },
|
2354 | notify: function () {
|
2355 | if (this._watchers != null) {
|
2356 | var value = this.getValue();
|
2357 | {
|
2358 | var _ref = this._watchers;
|
2359 | for (var _i = 0; _i < _ref.length; _i++) {
|
2360 | var watcher = _ref[_i];
|
2361 | this._notifyWatcher(watcher, value);
|
2362 | }
|
2363 | }
|
2364 | }
|
2365 | return;
|
2366 | },
|
2367 | hasValue: function () {
|
2368 | return this.hasOwnProperty('value');
|
2369 | },
|
2370 | getValue: function () {
|
2371 | return this.value;
|
2372 | },
|
2373 | setValue: function (value) {
|
2374 | if (value !== this.value || !this.hasValue()) {
|
2375 | this.value = value;
|
2376 | this.notify();
|
2377 | }
|
2378 | return;
|
2379 | }
|
2380 | },
|
2381 | test: function () {
|
2382 | var d = new DynamicExpression();
|
2383 | if (d.getValue() !== void 0) {
|
2384 | throw 'd.getValue() != undefined';
|
2385 | }
|
2386 | var total = 10;
|
2387 | var watcher = function (value) {
|
2388 | if (value !== void 0) {
|
2389 | total += value;
|
2390 | }
|
2391 | };
|
2392 | d.watchValue(watcher);
|
2393 | if (!(total === 10))
|
2394 | throw new Error('Assertion Failed: (total is 10)');
|
2395 | d.setValue(10);
|
2396 | if (!(d.getValue() === 10))
|
2397 | throw new Error('Assertion Failed: (d.getValue() is 10)');
|
2398 | if (!(total === 20))
|
2399 | throw new Error('Assertion Failed: (total is 20)');
|
2400 | d.setValue(20);
|
2401 | if (!(total === 40))
|
2402 | throw new Error('Assertion Failed: (total is 40)');
|
2403 | d.unwatchValue(watcher);
|
2404 | if (!(total === 40))
|
2405 | throw new Error('Assertion Failed: (total is 40)');
|
2406 | d.setValue(50);
|
2407 | if (!(total === 40))
|
2408 | throw new Error('Assertion Failed: (total is 40)');
|
2409 | }
|
2410 | }, require('./Expression'));
|
2411 | module.exports = exports = DynamicExpression;
|
2412 | }
|
2413 | if (typeof require === 'function') {
|
2414 | if (require.register)
|
2415 | require.register('ion/runtime/DynamicExpression',_ion_runtime_DynamicExpression_);
|
2416 | else
|
2417 | _ion_runtime_DynamicExpression_.call(this, module, exports, require);
|
2418 | }
|
2419 | else {
|
2420 | _ion_runtime_DynamicExpression_.call(this);
|
2421 | }
|
2422 | }).call(this)
|
2423 |
|
2424 | void (function(){var _ion_runtime_Expression_ = function(module,exports,require){'use strict';
|
2425 | var ion = require('../');
|
2426 | var Expression = ion.defineClass({
|
2427 | name: 'Expression',
|
2428 | properties: {
|
2429 | watchValue: function (watcher) {
|
2430 | return this.watch(watcher);
|
2431 | },
|
2432 | unwatchValue: function (watcher) {
|
2433 | return this.unwatch(watcher);
|
2434 | }
|
2435 | }
|
2436 | }, require('./Node'));
|
2437 | module.exports = exports = Expression;
|
2438 | }
|
2439 | if (typeof require === 'function') {
|
2440 | if (require.register)
|
2441 | require.register('ion/runtime/Expression',_ion_runtime_Expression_);
|
2442 | else
|
2443 | _ion_runtime_Expression_.call(this, module, exports, require);
|
2444 | }
|
2445 | else {
|
2446 | _ion_runtime_Expression_.call(this);
|
2447 | }
|
2448 | }).call(this)
|
2449 |
|
2450 | void (function(){var _ion_runtime_ExpressionStatement_ = function(module,exports,require){'use strict';
|
2451 | var ion = require('../'), Statement = require('./Statement');
|
2452 | var ExpressionStatement = ion.defineClass({
|
2453 | name: 'ExpressionStatement',
|
2454 | properties: {
|
2455 | activate: function () {
|
2456 | ExpressionStatement.super.prototype.activate.apply(this, arguments);
|
2457 | this.runtimeExpression = this.runtimeExpression != null ? this.runtimeExpression : this.context.createRuntime(this.expression);
|
2458 | this.runtimeExpression.watchValue(this.runtimeExpressionWatcher = this.runtimeExpressionWatcher != null ? this.runtimeExpressionWatcher : ion.bind(function (value) {
|
2459 | if (this.expressionValue !== value) {
|
2460 | this.expressionValue = value;
|
2461 | this._remove != null ? this._remove() : void 0;
|
2462 | this._remove = null;
|
2463 | if (this.context.output != null && value !== void 0) {
|
2464 | this._remove = ion.add(this.context.output, value);
|
2465 | }
|
2466 | }
|
2467 | }, this));
|
2468 | },
|
2469 | deactivate: function () {
|
2470 | ExpressionStatement.super.prototype.deactivate.apply(this, arguments);
|
2471 | this.runtimeExpression.unwatchValue(this.runtimeExpressionWatcher);
|
2472 | }
|
2473 | }
|
2474 | }, Statement);
|
2475 | module.exports = exports = ExpressionStatement;
|
2476 | }
|
2477 | if (typeof require === 'function') {
|
2478 | if (require.register)
|
2479 | require.register('ion/runtime/ExpressionStatement',_ion_runtime_ExpressionStatement_);
|
2480 | else
|
2481 | _ion_runtime_ExpressionStatement_.call(this, module, exports, require);
|
2482 | }
|
2483 | else {
|
2484 | _ion_runtime_ExpressionStatement_.call(this);
|
2485 | }
|
2486 | }).call(this)
|
2487 |
|
2488 | void (function(){var _ion_runtime_Factory_ = function(module,exports,require){'use strict';
|
2489 | var ion = require('../');
|
2490 | var Literal = require('./Literal');
|
2491 | var Expression = require('./Expression');
|
2492 | var Factory = ion.defineClass({
|
2493 | name: 'Factory',
|
2494 | properties: {
|
2495 | runtime: './OperationExpression',
|
2496 | createRuntime: {
|
2497 | writable: true,
|
2498 | value: function (context, ast) {
|
2499 | var properties = ion.clone(ast);
|
2500 | properties.context = context;
|
2501 | properties.factory = this;
|
2502 | var type = require(this.runtime);
|
2503 | return new type(properties);
|
2504 | }
|
2505 | },
|
2506 | canCache: {
|
2507 | writable: true,
|
2508 | value: function (ast) {
|
2509 | return false;
|
2510 | }
|
2511 | },
|
2512 | toCode: {
|
2513 | writable: true,
|
2514 | value: function (ast) {
|
2515 | if (ast.type === 'BinaryExpression') {
|
2516 | return toCode(ast.left) + ast.operator + toCode(ast.right);
|
2517 | }
|
2518 | return '(' + JSON.stringify(ast) + ')';
|
2519 | }
|
2520 | }
|
2521 | }
|
2522 | });
|
2523 | Factory;
|
2524 | var lookup = {
|
2525 | type: {
|
2526 | VariableDeclaration: ion.patch(new Factory(), { runtime: './VariableDeclaration' }),
|
2527 | ThisExpression: ion.patch(new Factory(), {
|
2528 | createRuntime: function (context, ast) {
|
2529 | return context.getVariable('this');
|
2530 | },
|
2531 | toCode: function (ast) {
|
2532 | return 'this';
|
2533 | }
|
2534 | }),
|
2535 | Identifier: ion.patch(new Factory(), {
|
2536 | createRuntime: function (context, ast) {
|
2537 | return context.getVariable(ast.name);
|
2538 | },
|
2539 | canCache: function (ast) {
|
2540 | return true;
|
2541 | },
|
2542 | toCode: function (ast) {
|
2543 | return ast.name;
|
2544 | }
|
2545 | }),
|
2546 | Function: ion.patch(new Factory(), {
|
2547 | createRuntime: function (context, ast) {
|
2548 | var value = ast.value;
|
2549 | if (ast.context) {
|
2550 | value = value(context);
|
2551 | }
|
2552 | return new Literal({ value: value });
|
2553 | }
|
2554 | }),
|
2555 | Template: ion.patch(new Factory(), { runtime: './Template' }),
|
2556 | Literal: ion.patch(new Factory(), {
|
2557 | runtime: './Literal',
|
2558 | canCache: function (ast) {
|
2559 | return true;
|
2560 | },
|
2561 | toCode: function (ast) {
|
2562 | return JSON.stringify(ast.value);
|
2563 | }
|
2564 | }),
|
2565 | Property: ion.patch(new Factory(), { runtime: './Property' }),
|
2566 | IfStatement: ion.patch(new Factory(), { runtime: './IfStatement' }),
|
2567 | BlockStatement: ion.patch(new Factory(), { runtime: './BlockStatement' }),
|
2568 | ReturnStatement: ion.patch(new Factory(), { runtime: './ReturnStatement' }),
|
2569 | ObjectExpression: ion.patch(new Factory(), { runtime: './ObjectExpression' }),
|
2570 | ArrayExpression: ion.patch(new Factory(), { runtime: './ArrayExpression' }),
|
2571 | ExpressionStatement: ion.patch(new Factory(), { runtime: './ExpressionStatement' }),
|
2572 | ForOfStatement: ion.patch(new Factory(), { runtime: './ForInOfStatement' }),
|
2573 | ForInStatement: ion.patch(new Factory(), { runtime: './ForInOfStatement' }),
|
2574 | MemberExpression: ion.patch(new Factory(), {
|
2575 | runtime: './MemberExpression',
|
2576 | canCache: function (ast) {
|
2577 | return canCache(ast.object) && canCache(ast.property);
|
2578 | },
|
2579 | toCode: function (ast) {
|
2580 | if (ast.computed) {
|
2581 | return '' + toCode(ast.object) + '[' + toCode(ast.property) + ']';
|
2582 | } else {
|
2583 | return '' + toCode(ast.object) + '.' + toCode(ast.property);
|
2584 | }
|
2585 | }
|
2586 | }),
|
2587 | CallExpression: ion.patch(new Factory(), { runtime: './CallExpression' }),
|
2588 | NewExpression: ion.patch(new Factory(), { runtime: './CallExpression' }),
|
2589 | UnaryExpression: {
|
2590 | operator: {
|
2591 | '!': ion.patch(new Factory(), {
|
2592 | evaluate: function (a) {
|
2593 | return !a;
|
2594 | }
|
2595 | }),
|
2596 | 'typeof': ion.patch(new Factory(), {
|
2597 | evaluate: function (a) {
|
2598 | return typeof a;
|
2599 | }
|
2600 | }),
|
2601 | 'void': ion.patch(new Factory(), {
|
2602 | evaluate: function (a) {
|
2603 | return void a;
|
2604 | }
|
2605 | }),
|
2606 | '-': ion.patch(new Factory(), {
|
2607 | evaluate: function (a) {
|
2608 | return -a;
|
2609 | }
|
2610 | }),
|
2611 | '+': ion.patch(new Factory(), {
|
2612 | evaluate: function (a) {
|
2613 | return +a;
|
2614 | }
|
2615 | }),
|
2616 | '~': ion.patch(new Factory(), {
|
2617 | evaluate: function (a) {
|
2618 | return ~a;
|
2619 | }
|
2620 | }),
|
2621 | '?': ion.patch(new Factory(), {
|
2622 | evaluate: function (a) {
|
2623 | return a != null;
|
2624 | }
|
2625 | })
|
2626 | }
|
2627 | },
|
2628 | ConditionalExpression: ion.patch(new Factory(), { runtime: './ConditionalExpression' }),
|
2629 | BinaryExpression: {
|
2630 | operator: {
|
2631 | '*': ion.patch(new Factory(), {
|
2632 | evaluate: function (left, right) {
|
2633 | return left * right;
|
2634 | }
|
2635 | }),
|
2636 | '/': ion.patch(new Factory(), {
|
2637 | evaluate: function (left, right) {
|
2638 | return left / right;
|
2639 | }
|
2640 | }),
|
2641 | '%': ion.patch(new Factory(), {
|
2642 | evaluate: function (left, right) {
|
2643 | return left % right;
|
2644 | }
|
2645 | }),
|
2646 | '+': ion.patch(new Factory(), {
|
2647 | evaluate: function (left, right) {
|
2648 | return left + right;
|
2649 | }
|
2650 | }),
|
2651 | '-': ion.patch(new Factory(), {
|
2652 | evaluate: function (left, right) {
|
2653 | return left - right;
|
2654 | }
|
2655 | }),
|
2656 | '&&': ion.patch(new Factory(), {
|
2657 | evaluate: function (left, right) {
|
2658 | return left && right;
|
2659 | }
|
2660 | }),
|
2661 | '||': ion.patch(new Factory(), {
|
2662 | evaluate: function (left, right) {
|
2663 | return left || right;
|
2664 | }
|
2665 | }),
|
2666 | '&': ion.patch(new Factory(), {
|
2667 | evaluate: function (left, right) {
|
2668 | return left & right;
|
2669 | }
|
2670 | }),
|
2671 | '|': ion.patch(new Factory(), {
|
2672 | evaluate: function (left, right) {
|
2673 | return left | right;
|
2674 | }
|
2675 | }),
|
2676 | '==': ion.patch(new Factory(), {
|
2677 | evaluate: function (left, right) {
|
2678 | return left == right;
|
2679 | }
|
2680 | }),
|
2681 | '!=': ion.patch(new Factory(), {
|
2682 | evaluate: function (left, right) {
|
2683 | return left != right;
|
2684 | }
|
2685 | }),
|
2686 | '===': ion.patch(new Factory(), {
|
2687 | evaluate: function (left, right) {
|
2688 | return left === right;
|
2689 | }
|
2690 | }),
|
2691 | '!==': ion.patch(new Factory(), {
|
2692 | evaluate: function (left, right) {
|
2693 | return left !== right;
|
2694 | }
|
2695 | }),
|
2696 | '<': ion.patch(new Factory(), {
|
2697 | evaluate: function (left, right) {
|
2698 | return left < right;
|
2699 | }
|
2700 | }),
|
2701 | '>': ion.patch(new Factory(), {
|
2702 | evaluate: function (left, right) {
|
2703 | return left > right;
|
2704 | }
|
2705 | }),
|
2706 | '<=': ion.patch(new Factory(), {
|
2707 | evaluate: function (left, right) {
|
2708 | return left <= right;
|
2709 | }
|
2710 | }),
|
2711 | '>=': ion.patch(new Factory(), {
|
2712 | evaluate: function (left, right) {
|
2713 | return left >= right;
|
2714 | }
|
2715 | })
|
2716 | }
|
2717 | }
|
2718 | }
|
2719 | };
|
2720 | function getFactory(ast, step) {
|
2721 | if (step == null)
|
2722 | step = lookup;
|
2723 | for (var key in step) {
|
2724 | var values = step[key];
|
2725 | var nodeValue = ast[key];
|
2726 | var next = values[nodeValue];
|
2727 | if (next != null) {
|
2728 | if (next.constructor === Factory) {
|
2729 | return next;
|
2730 | }
|
2731 | return getFactory(ast, next);
|
2732 | }
|
2733 | }
|
2734 | return null;
|
2735 | }
|
2736 | var canCache = exports.canCache = function (ast) {
|
2737 | if (ast != null) {
|
2738 | var factory = getFactory(ast);
|
2739 | if (factory != null) {
|
2740 | return factory.canCache(ast);
|
2741 | }
|
2742 | }
|
2743 | return false;
|
2744 | }, toCode = exports.toCode = function (ast) {
|
2745 | if (ast != null) {
|
2746 | var code = ast._toCode;
|
2747 | if (!(code != null)) {
|
2748 | var factory = getFactory(ast);
|
2749 | if (factory != null) {
|
2750 | code = factory.toCode(ast);
|
2751 | }
|
2752 | if (code != null && typeof ast === 'object') {
|
2753 | Object.defineProperty(ast, '_toCode', { value: code });
|
2754 | }
|
2755 | }
|
2756 | return code;
|
2757 | }
|
2758 | return JSON.stringify(ast);
|
2759 | }, createRuntime = exports.createRuntime = function (context, ast) {
|
2760 | if (typeof (ast != null ? ast.type : void 0) !== 'string') {
|
2761 | ast = {
|
2762 | type: 'Literal',
|
2763 | value: ast
|
2764 | };
|
2765 | }
|
2766 | var factory = getFactory(ast);
|
2767 | if (!(factory != null)) {
|
2768 | throw new Error('Factory not found for ast:\n' + JSON.stringify(ast, null, ' '));
|
2769 | }
|
2770 | return factory.createRuntime(context, ast);
|
2771 | }, test = exports.test = function () {
|
2772 | var factory = getFactory({
|
2773 | type: 'BinaryExpression',
|
2774 | operator: '>',
|
2775 | left: {
|
2776 | type: 'Literal',
|
2777 | value: 1
|
2778 | },
|
2779 | right: {
|
2780 | type: 'Literal',
|
2781 | value: 2
|
2782 | }
|
2783 | });
|
2784 | if (!(factory === lookup.type.BinaryExpression.operator['>']))
|
2785 | throw new Error('Assertion Failed: (factory is lookup.type.BinaryExpression.operator[">"])');
|
2786 | if (!(lookup.type.BinaryExpression.operator['>'] != null))
|
2787 | throw new Error('Assertion Failed: (lookup.type.BinaryExpression.operator[">"]?)');
|
2788 | };
|
2789 | }
|
2790 | if (typeof require === 'function') {
|
2791 | if (require.register)
|
2792 | require.register('ion/runtime/Factory',_ion_runtime_Factory_);
|
2793 | else
|
2794 | _ion_runtime_Factory_.call(this, module, exports, require);
|
2795 | }
|
2796 | else {
|
2797 | _ion_runtime_Factory_.call(this);
|
2798 | }
|
2799 | }).call(this)
|
2800 |
|
2801 | void (function(){var _ion_runtime_ForInOfStatement_ = function(module,exports,require){'use strict';
|
2802 | var ion = require('../'), Statement = require('./Statement'), DynamicExpression = require('./DynamicExpression');
|
2803 | var ForInOfStatement = ion.defineClass({
|
2804 | name: 'ForInOfStatement',
|
2805 | properties: {
|
2806 | toKey: function (name) {
|
2807 | if (this.type === 'ForOfStatement') {
|
2808 | return parseInt(name);
|
2809 | } else {
|
2810 | return name;
|
2811 | }
|
2812 | },
|
2813 | forEach: function (collection, callback) {
|
2814 | if (this.type === 'ForOfStatement') {
|
2815 | for (var key = 0; key < collection.length; key++) {
|
2816 | var value = collection[key];
|
2817 | callback(key, value);
|
2818 | }
|
2819 | } else {
|
2820 | for (var key in collection) {
|
2821 | var value = collection[key];
|
2822 | callback(key, value);
|
2823 | }
|
2824 | }
|
2825 | },
|
2826 | activate: function () {
|
2827 | ForInOfStatement.super.prototype.activate.apply(this, arguments);
|
2828 | if (!(this.statements != null)) {
|
2829 | this.statements = {};
|
2830 | this.valueName = this.left.declarations[this.type === 'ForOfStatement' ? 0 : 1] != null ? this.left.declarations[this.type === 'ForOfStatement' ? 0 : 1].id.name : void 0;
|
2831 | this.keyName = this.left.declarations[this.type === 'ForOfStatement' ? 1 : 0] != null ? this.left.declarations[this.type === 'ForOfStatement' ? 1 : 0].id.name : void 0;
|
2832 | }
|
2833 | this.collectionExpression = this.collectionExpression != null ? this.collectionExpression : this.context.createRuntime(this.right);
|
2834 | this.collectionExpression.watchValue(this.collectionWatcher = this.collectionWatcher != null ? this.collectionWatcher : ion.bind(function (collection) {
|
2835 | if (this.collection !== collection) {
|
2836 | if (this.collection != null) {
|
2837 | this.forEach(this.collection, ion.bind(function (key, value) {
|
2838 | this.removeItem(key, value);
|
2839 | }, this));
|
2840 | ion.unobserve(this.collection, this.collectionObserver);
|
2841 | }
|
2842 | this.collection = collection;
|
2843 | if (this.collection != null) {
|
2844 | this.forEach(this.collection, ion.bind(function (key, value) {
|
2845 | this.addItem(key, value);
|
2846 | }, this));
|
2847 | ion.observe(this.collection, this.collectionObserver = this.collectionObserver != null ? this.collectionObserver : this.applyChanges.bind(this));
|
2848 | }
|
2849 | }
|
2850 | }, this));
|
2851 | },
|
2852 | deactivate: function () {
|
2853 | ForInOfStatement.super.prototype.deactivate.apply(this, arguments);
|
2854 | this.collectionExpression.unwatchValue(this.collectionWatcher);
|
2855 | },
|
2856 | addItem: function (key, value, activate) {
|
2857 | if (activate == null)
|
2858 | activate = true;
|
2859 | if (value !== void 0) {
|
2860 | var newContext = this.context.newContext();
|
2861 | if (this.valueName != null) {
|
2862 | newContext.setVariableExpression(this.valueName, new DynamicExpression({ value: value }));
|
2863 | }
|
2864 | if (this.keyName != null) {
|
2865 | newContext.setVariableExpression(this.keyName, new DynamicExpression({ value: key }));
|
2866 | }
|
2867 | var statement = newContext.createRuntime(this.body);
|
2868 | this.statements[key] = statement;
|
2869 | if (activate) {
|
2870 | statement.activate();
|
2871 | }
|
2872 | return statement;
|
2873 | }
|
2874 | },
|
2875 | removeItem: function (key, value) {
|
2876 | var statement = this.statements[key];
|
2877 | if (statement != null) {
|
2878 | this.disposeStatement(statement);
|
2879 | }
|
2880 | delete this.statements[key];
|
2881 | return statement;
|
2882 | },
|
2883 | disposeStatement: function (statement) {
|
2884 | if (this.remove != null) {
|
2885 | var removeStatement = statement.context.createRuntime(this.remove);
|
2886 | removeStatement.activate();
|
2887 | }
|
2888 | statement.deactivate();
|
2889 | },
|
2890 | summarize: function (changes) {
|
2891 | var ignoreProperty = ion.bind(function (name) {
|
2892 | if (!(name != null)) {
|
2893 | return true;
|
2894 | }
|
2895 | if (name[0] === '_') {
|
2896 | return true;
|
2897 | }
|
2898 | if (name === 'length' && this.type === 'ForOfStatement') {
|
2899 | return true;
|
2900 | }
|
2901 | return false;
|
2902 | }, this);
|
2903 | var map = new Map();
|
2904 | for (var _i = 0; _i < changes.length; _i++) {
|
2905 | var _ref = changes[_i];
|
2906 | var type = _ref.type;
|
2907 | var object = _ref.object;
|
2908 | var name = _ref.name;
|
2909 | var oldValue = _ref.oldValue;
|
2910 | if (!ignoreProperty(name)) {
|
2911 | if (!map.has(name)) {
|
2912 | map.set(name, {
|
2913 | type: type,
|
2914 | object: object,
|
2915 | name: name,
|
2916 | oldValue: oldValue
|
2917 | });
|
2918 | } else {
|
2919 | var change = map.get(name);
|
2920 | change.type = type;
|
2921 | }
|
2922 | }
|
2923 | }
|
2924 | var array = [];
|
2925 | map.forEach(function (change, name, object) {
|
2926 | var newValue = change.object[name];
|
2927 | if (newValue !== change.oldValue) {
|
2928 | delete change.object;
|
2929 | array.push(change);
|
2930 | }
|
2931 | });
|
2932 | return array;
|
2933 | },
|
2934 | applyChanges: function (changes) {
|
2935 | changes = this.summarize(changes);
|
2936 | if (changes.length === 0) {
|
2937 | return;
|
2938 | }
|
2939 | var recyclableStatements = new Map();
|
2940 | var getRecycleKey = ion.bind(function (key, value) {
|
2941 | return this.type === 'ForOfStatement' ? value : key;
|
2942 | }, this);
|
2943 | var activateStatements = [];
|
2944 | for (var _i2 = 0; _i2 < changes.length; _i2++) {
|
2945 | var _ref2 = changes[_i2];
|
2946 | var name = _ref2.name;
|
2947 | var oldValue = _ref2.oldValue;
|
2948 | var key = this.toKey(name);
|
2949 | if (oldValue !== void 0) {
|
2950 | var rkey = getRecycleKey(key, oldValue);
|
2951 | var statement = this.statements[key];
|
2952 | if (statement != null) {
|
2953 | delete this.statements[key];
|
2954 | recyclableStatements.set(rkey, statement);
|
2955 | }
|
2956 | }
|
2957 | }
|
2958 | for (var _i3 = 0; _i3 < changes.length; _i3++) {
|
2959 | var _ref3 = changes[_i3];
|
2960 | var name = _ref3.name;
|
2961 | var oldValue = _ref3.oldValue;
|
2962 | var newValue = this.collection[name];
|
2963 | var key = this.toKey(name);
|
2964 | if (newValue !== void 0) {
|
2965 | var rkey = getRecycleKey(key, newValue);
|
2966 | var statement = recyclableStatements.get(rkey);
|
2967 | if (statement != null) {
|
2968 | if (this.type === 'ForOfStatement') {
|
2969 | if (this.keyName != null) {
|
2970 | statement.context.variables[this.keyName].setValue(key);
|
2971 | }
|
2972 | } else {
|
2973 | if (this.valueName != null) {
|
2974 | statement.context.variables[this.valueName].setValue(newValue);
|
2975 | }
|
2976 | }
|
2977 | this.statements[key] = statement;
|
2978 | recyclableStatements.delete(rkey);
|
2979 | } else {
|
2980 | statement = this.addItem(key, newValue, false);
|
2981 | if (statement != null) {
|
2982 | activateStatements.push(statement);
|
2983 | }
|
2984 | }
|
2985 | }
|
2986 | }
|
2987 | recyclableStatements.forEach(ion.bind(function (statement) {
|
2988 | this.disposeStatement(statement);
|
2989 | }, this));
|
2990 | for (var _i4 = 0; _i4 < activateStatements.length; _i4++) {
|
2991 | var statement = activateStatements[_i4];
|
2992 | statement.activate();
|
2993 | }
|
2994 | }
|
2995 | }
|
2996 | }, Statement);
|
2997 | module.exports = exports = ForInOfStatement;
|
2998 | }
|
2999 | if (typeof require === 'function') {
|
3000 | if (require.register)
|
3001 | require.register('ion/runtime/ForInOfStatement',_ion_runtime_ForInOfStatement_);
|
3002 | else
|
3003 | _ion_runtime_ForInOfStatement_.call(this, module, exports, require);
|
3004 | }
|
3005 | else {
|
3006 | _ion_runtime_ForInOfStatement_.call(this);
|
3007 | }
|
3008 | }).call(this)
|
3009 |
|
3010 | void (function(){var _ion_runtime_IfStatement_ = function(module,exports,require){'use strict';
|
3011 | var ion = require('../'), Statement = require('./Statement');
|
3012 | var IfStatement = ion.defineClass({
|
3013 | name: 'IfStatement',
|
3014 | properties: {
|
3015 | activate: function () {
|
3016 | IfStatement.super.prototype.activate.apply(this, arguments);
|
3017 | this.testExpression = this.testExpression != null ? this.testExpression : this.context.createRuntime(this.test);
|
3018 | this.testExpression.watchValue(this.testExpressionWatcher = this.testExpressionWatcher != null ? this.testExpressionWatcher : ion.bind(function (value) {
|
3019 | if (value) {
|
3020 | if (this.alternateStatement != null ? this.alternateStatement.isActive : void 0) {
|
3021 | this.alternateStatement != null ? this.alternateStatement.deactivate() : void 0;
|
3022 | delete this.alternateStatement;
|
3023 | }
|
3024 | this.consequentStatement = this.consequentStatement != null ? this.consequentStatement : this.context.createRuntime(this.consequent);
|
3025 | this.consequentStatement.activate();
|
3026 | } else {
|
3027 | if (this.consequentStatement != null ? this.consequentStatement.isActive : void 0) {
|
3028 | this.consequentStatement != null ? this.consequentStatement.deactivate() : void 0;
|
3029 | delete this.consequentStatement;
|
3030 | }
|
3031 | if (this.alternate != null) {
|
3032 | this.alternateStatement = this.alternateStatement != null ? this.alternateStatement : this.context.createRuntime(this.alternate);
|
3033 | this.alternateStatement.activate();
|
3034 | }
|
3035 | }
|
3036 | }, this));
|
3037 | },
|
3038 | deactivate: function () {
|
3039 | IfStatement.super.prototype.deactivate.apply(this, arguments);
|
3040 | this.testExpression.unwatchValue(this.testExpressionWatcher);
|
3041 | if (this.alternateStatement != null ? this.alternateStatement.isActive : void 0) {
|
3042 | this.alternateStatement != null ? this.alternateStatement.deactivate() : void 0;
|
3043 | }
|
3044 | if (this.consequentStatement != null ? this.consequentStatement.isActive : void 0) {
|
3045 | this.consequentStatement != null ? this.consequentStatement.deactivate() : void 0;
|
3046 | }
|
3047 | }
|
3048 | }
|
3049 | }, Statement);
|
3050 | module.exports = exports = IfStatement;
|
3051 | }
|
3052 | if (typeof require === 'function') {
|
3053 | if (require.register)
|
3054 | require.register('ion/runtime/IfStatement',_ion_runtime_IfStatement_);
|
3055 | else
|
3056 | _ion_runtime_IfStatement_.call(this, module, exports, require);
|
3057 | }
|
3058 | else {
|
3059 | _ion_runtime_IfStatement_.call(this);
|
3060 | }
|
3061 | }).call(this)
|
3062 |
|
3063 | void (function(){var _ion_runtime_Literal_ = function(module,exports,require){'use strict';
|
3064 | var ion = require('../');
|
3065 | var Literal = ion.defineClass({
|
3066 | name: 'Literal',
|
3067 | properties: {
|
3068 | watchValue: function (watcher) {
|
3069 | watcher(this.value);
|
3070 | },
|
3071 | unwatchValue: function (watcher) {
|
3072 | watcher(void 0);
|
3073 | }
|
3074 | }
|
3075 | }, require('./Expression'));
|
3076 | module.exports = exports = Literal;
|
3077 | }
|
3078 | if (typeof require === 'function') {
|
3079 | if (require.register)
|
3080 | require.register('ion/runtime/Literal',_ion_runtime_Literal_);
|
3081 | else
|
3082 | _ion_runtime_Literal_.call(this, module, exports, require);
|
3083 | }
|
3084 | else {
|
3085 | _ion_runtime_Literal_.call(this);
|
3086 | }
|
3087 | }).call(this)
|
3088 |
|
3089 | void (function(){var _ion_runtime_MemberExpression_ = function(module,exports,require){'use strict';
|
3090 | var ion = require('../'), _ref = require('./');
|
3091 | var DynamicExpression = _ref.DynamicExpression;
|
3092 | var Factory = _ref.Factory;
|
3093 | var MemberExpression = ion.defineClass({
|
3094 | name: 'MemberExpression',
|
3095 | properties: {
|
3096 | activate: function () {
|
3097 | MemberExpression.super.prototype.activate.apply(this, arguments);
|
3098 | this.objectExpression = this.objectExpression != null ? this.objectExpression : this.context.createRuntime(this.object);
|
3099 | this.propertyExpression = this.propertyExpression != null ? this.propertyExpression : this.context.createRuntime(this.computed ? this.property : this.property.name);
|
3100 | this.objectExpression.watchValue(this.objectWatcher = this.objectWatcher != null ? this.objectWatcher : ion.bind(function (objectValue) {
|
3101 | this.objectValue = objectValue;
|
3102 | this.updateValue();
|
3103 | }, this));
|
3104 | this.propertyExpression.watchValue(this.propertyWatcher = this.propertyWatcher != null ? this.propertyWatcher : ion.bind(function (propertyValue) {
|
3105 | this.propertyValue = propertyValue;
|
3106 | this.updateValue();
|
3107 | }, this));
|
3108 | },
|
3109 | deactivate: function () {
|
3110 | MemberExpression.super.prototype.deactivate.apply(this, arguments);
|
3111 | this.objectExpression.unwatchValue(this.objectWatcher);
|
3112 | this.propertyExpression.unwatchValue(this.propertyWatcher);
|
3113 | },
|
3114 | updateValue: function () {
|
3115 | var value = void 0;
|
3116 | if (this.objectValue != null) {
|
3117 | if (this.propertyValue != null) {
|
3118 | value = this.objectValue[this.propertyValue];
|
3119 | }
|
3120 | } else if (this.isActive && !this.existential && (this.loc != null ? this.loc.start != null ? this.loc.start.source : void 0 : void 0) != null && this.hasOwnProperty('objectValue') && this.hasOwnProperty('propertyValue')) {
|
3121 | console.warn('Cannot read ' + Factory.toCode(this.property) + ' property of ' + this.objectValue + ' (' + Factory.toCode(this.object) + ') (' + this.loc.start.source + ':' + this.loc.start.line + ':' + (this.loc.start.column + 1) + ')');
|
3122 | }
|
3123 | this.setValue(value);
|
3124 | if (this.observedObject !== this.objectValue || this.observedProperty !== this.propertyValue) {
|
3125 | this.observedObject = this.objectValue;
|
3126 | this.observedProperty = this.propertyValue;
|
3127 | this.objectObserver != null ? this.objectObserver() : void 0;
|
3128 | if (this.objectValue != null) {
|
3129 | this.objectObserver = ion.observe(this.objectValue, ion.bind(function (changes) {
|
3130 | this.updateValue();
|
3131 | }, this), this.propertyValue);
|
3132 | }
|
3133 | }
|
3134 | },
|
3135 | setMemberValue: function (value) {
|
3136 | if (this.objectValue != null && this.propertyValue != null) {
|
3137 | this.objectValue[this.propertyValue] = value;
|
3138 | }
|
3139 | }
|
3140 | },
|
3141 | test: function () {
|
3142 | }
|
3143 | }, DynamicExpression);
|
3144 | module.exports = exports = MemberExpression;
|
3145 | }
|
3146 | if (typeof require === 'function') {
|
3147 | if (require.register)
|
3148 | require.register('ion/runtime/MemberExpression',_ion_runtime_MemberExpression_);
|
3149 | else
|
3150 | _ion_runtime_MemberExpression_.call(this, module, exports, require);
|
3151 | }
|
3152 | else {
|
3153 | _ion_runtime_MemberExpression_.call(this);
|
3154 | }
|
3155 | }).call(this)
|
3156 |
|
3157 | void (function(){var _ion_runtime_Node_ = function(module,exports,require){'use strict';
|
3158 | var ion = require('../');
|
3159 | var Node = ion.defineClass({ name: 'Node' });
|
3160 | module.exports = exports = Node;
|
3161 | }
|
3162 | if (typeof require === 'function') {
|
3163 | if (require.register)
|
3164 | require.register('ion/runtime/Node',_ion_runtime_Node_);
|
3165 | else
|
3166 | _ion_runtime_Node_.call(this, module, exports, require);
|
3167 | }
|
3168 | else {
|
3169 | _ion_runtime_Node_.call(this);
|
3170 | }
|
3171 | }).call(this)
|
3172 |
|
3173 | void (function(){var _ion_runtime_ObjectExpression_ = function(module,exports,require){'use strict';
|
3174 | var ion = require('../'), DynamicExpression = require('./DynamicExpression');
|
3175 | var ObjectExpression = ion.defineClass({
|
3176 | name: 'ObjectExpression',
|
3177 | properties: {
|
3178 | setLeftValue: function (value) {
|
3179 | this.value = value;
|
3180 | },
|
3181 | activate: function () {
|
3182 | ObjectExpression.super.prototype.activate.apply(this, arguments);
|
3183 | this.typeExpression = this.typeExpression != null ? this.typeExpression : this.context.createRuntime(this.objectType != null ? this.objectType : null);
|
3184 | this.typeExpression.watchValue(this.typeWatcher = this.typeWatcher != null ? this.typeWatcher : ion.bind(function (type) {
|
3185 | var value;
|
3186 | if (!ion.is(this.value, type)) {
|
3187 | this.statements != null ? this.statements.deactivate() : void 0;
|
3188 | this.statements = null;
|
3189 | value = type != null ? type : {};
|
3190 | } else {
|
3191 | value = this.value;
|
3192 | }
|
3193 | if (value != null && !(this.statements != null)) {
|
3194 | var newContext = this.context.newContext(value);
|
3195 | this.statements = newContext.createRuntime({
|
3196 | type: 'BlockStatement',
|
3197 | body: this.properties
|
3198 | });
|
3199 | this.statements.activate();
|
3200 | }
|
3201 | this.setValue(value);
|
3202 | }, this));
|
3203 | },
|
3204 | deactivate: function () {
|
3205 | ObjectExpression.super.prototype.deactivate.apply(this, arguments);
|
3206 | this.typeExpression.unwatchValue(this.typeWatcher);
|
3207 | }
|
3208 | }
|
3209 | }, DynamicExpression);
|
3210 | module.exports = exports = ObjectExpression;
|
3211 | }
|
3212 | if (typeof require === 'function') {
|
3213 | if (require.register)
|
3214 | require.register('ion/runtime/ObjectExpression',_ion_runtime_ObjectExpression_);
|
3215 | else
|
3216 | _ion_runtime_ObjectExpression_.call(this, module, exports, require);
|
3217 | }
|
3218 | else {
|
3219 | _ion_runtime_ObjectExpression_.call(this);
|
3220 | }
|
3221 | }).call(this)
|
3222 |
|
3223 | void (function(){var _ion_runtime_OperationExpression_ = function(module,exports,require){'use strict';
|
3224 | var ion = require('../'), DynamicExpression = require('./DynamicExpression');
|
3225 | var OperationExpression = ion.defineClass({
|
3226 | name: 'OperationExpression',
|
3227 | constructor: function OperationExpression(properties) {
|
3228 | OperationExpression.super.apply(this, arguments);
|
3229 | if (!(this.args != null)) {
|
3230 | if (this.type === 'BinaryExpression') {
|
3231 | this.args = [
|
3232 | this.left,
|
3233 | this.right
|
3234 | ];
|
3235 | } else if (this.type === 'UnaryExpression') {
|
3236 | this.args = [this.argument];
|
3237 | } else if (this.type === 'ConditionalExpression') {
|
3238 | this.args = [
|
3239 | this.test,
|
3240 | this.consequent,
|
3241 | this.alternate
|
3242 | ];
|
3243 | }
|
3244 | }
|
3245 | },
|
3246 | properties: {
|
3247 | args: null,
|
3248 | activate: function () {
|
3249 | OperationExpression.super.prototype.activate.apply(this, arguments);
|
3250 | this.argumentExpressions = this.argumentExpressions != null ? this.argumentExpressions : this.context.createRuntime({
|
3251 | type: 'ArrayExpression',
|
3252 | elements: this.args,
|
3253 | observeElements: this.factory.observe
|
3254 | });
|
3255 | this.argumentExpressions.watchValue(this.watcher = this.watcher != null ? this.watcher : ion.bind(function (value) {
|
3256 | this.argumentValues = value;
|
3257 | this.evaluate();
|
3258 | }, this));
|
3259 | },
|
3260 | deactivate: function () {
|
3261 | OperationExpression.super.prototype.deactivate.apply(this, arguments);
|
3262 | this.argumentExpressions.unwatchValue(this.watcher);
|
3263 | },
|
3264 | evaluate: function () {
|
3265 | if (!(this.factory.evaluate != null)) {
|
3266 | throw new Error('evaluate method not defined for operation: ' + this.factory);
|
3267 | }
|
3268 | var value = this.factory.evaluate.apply(this.context, this.argumentValues);
|
3269 | this.setValue(value);
|
3270 | }
|
3271 | }
|
3272 | }, DynamicExpression);
|
3273 | module.exports = OperationExpression;
|
3274 | }
|
3275 | if (typeof require === 'function') {
|
3276 | if (require.register)
|
3277 | require.register('ion/runtime/OperationExpression',_ion_runtime_OperationExpression_);
|
3278 | else
|
3279 | _ion_runtime_OperationExpression_.call(this, module, exports, require);
|
3280 | }
|
3281 | else {
|
3282 | _ion_runtime_OperationExpression_.call(this);
|
3283 | }
|
3284 | }).call(this)
|
3285 |
|
3286 | void (function(){var _ion_runtime_Property_ = function(module,exports,require){'use strict';
|
3287 | var ion = require('../'), Statement = require('./Statement');
|
3288 | var Property = ion.defineClass({
|
3289 | name: 'Property',
|
3290 | properties: {
|
3291 | activate: function () {
|
3292 | Property.super.prototype.activate.apply(this, arguments);
|
3293 | this.keyExpression = this.keyExpression != null ? this.keyExpression : this.context.createRuntime(this.computed ? this.key : this.key.name != null ? this.key.name : this.key.value);
|
3294 | this.valueExpression = this.valueExpression != null ? this.valueExpression : this.context.createRuntime(this.value);
|
3295 | this.keyExpression.watchValue(this.keyWatcher = this.keyWatcher != null ? this.keyWatcher : ion.bind(function (key) {
|
3296 | if (key != null && this.valueExpression.setLeftValue != null) {
|
3297 | var currentValue = this.context.output ? this.context.output != null ? this.context.output[key] : void 0 : this.context.get(key);
|
3298 | if (currentValue != null) {
|
3299 | this.valueExpression.setLeftValue(currentValue);
|
3300 | }
|
3301 | }
|
3302 | this.keyValue = key;
|
3303 | this.setProperty();
|
3304 | }, this));
|
3305 | this.valueExpression.watchValue(this.valueWatcher = this.valueWatcher != null ? this.valueWatcher : ion.bind(function (value) {
|
3306 | this.valueValue = value;
|
3307 | this.setProperty();
|
3308 | }, this));
|
3309 | },
|
3310 | deactivate: function () {
|
3311 | Property.super.prototype.deactivate.apply(this, arguments);
|
3312 | ion.unobserve(this.context.output, this.contextObserver, this.leftValue);
|
3313 | this.keyExpression.unwatchValue(this.keyWatcher);
|
3314 | this.valueExpression.unwatchValue(this.valueWatcher);
|
3315 | },
|
3316 | setProperty: function (key, value) {
|
3317 | if (key == null)
|
3318 | key = this.keyValue;
|
3319 | if (value == null)
|
3320 | value = this.valueValue;
|
3321 | if (this.hasOwnProperty('keyValue') && this.hasOwnProperty('valueValue')) {
|
3322 | if (key != null && this.context.output != null) {
|
3323 | var currentValue = this.context.output[key];
|
3324 | if (currentValue !== value) {
|
3325 | this.context.output[key] = value;
|
3326 | }
|
3327 | }
|
3328 | }
|
3329 | }
|
3330 | }
|
3331 | }, Statement);
|
3332 | module.exports = exports = Property;
|
3333 | }
|
3334 | if (typeof require === 'function') {
|
3335 | if (require.register)
|
3336 | require.register('ion/runtime/Property',_ion_runtime_Property_);
|
3337 | else
|
3338 | _ion_runtime_Property_.call(this, module, exports, require);
|
3339 | }
|
3340 | else {
|
3341 | _ion_runtime_Property_.call(this);
|
3342 | }
|
3343 | }).call(this)
|
3344 |
|
3345 | void (function(){var _ion_runtime_ReturnStatement_ = function(module,exports,require){'use strict';
|
3346 | var ion = require('../'), Statement = require('./Statement');
|
3347 | var ReturnStatement = ion.defineClass({
|
3348 | name: 'ReturnStatement',
|
3349 | properties: {
|
3350 | activate: function () {
|
3351 | ReturnStatement.super.prototype.activate.apply(this, arguments);
|
3352 | this.argumentExpression = this.argumentExpression != null ? this.argumentExpression : this.context.createRuntime(this.argument);
|
3353 | this.argumentExpression.watchValue(this.argumentWatcher = this.argumentWatcher != null ? this.argumentWatcher : ion.bind(function (value) {
|
3354 | return this.context.returnExpression.setValue(value);
|
3355 | }, this));
|
3356 | },
|
3357 | deactivate: function () {
|
3358 | ReturnStatement.super.prototype.deactivate.apply(this, arguments);
|
3359 | this.argumentExpression.unwatchValue(this.argumentWatcher);
|
3360 | }
|
3361 | }
|
3362 | }, Statement);
|
3363 | module.exports = exports = ReturnStatement;
|
3364 | }
|
3365 | if (typeof require === 'function') {
|
3366 | if (require.register)
|
3367 | require.register('ion/runtime/ReturnStatement',_ion_runtime_ReturnStatement_);
|
3368 | else
|
3369 | _ion_runtime_ReturnStatement_.call(this, module, exports, require);
|
3370 | }
|
3371 | else {
|
3372 | _ion_runtime_ReturnStatement_.call(this);
|
3373 | }
|
3374 | }).call(this)
|
3375 |
|
3376 | void (function(){var _ion_runtime_Statement_ = function(module,exports,require){'use strict';
|
3377 | var ion = require('../');
|
3378 | var Statement = ion.defineClass({
|
3379 | name: 'Statement',
|
3380 | properties: {
|
3381 | isActive: false,
|
3382 | activate: function () {
|
3383 | this.isActive = true;
|
3384 | },
|
3385 | deactivate: function () {
|
3386 | this.isActive = false;
|
3387 | }
|
3388 | }
|
3389 | }, require('./Node'));
|
3390 | module.exports = exports = Statement;
|
3391 | }
|
3392 | if (typeof require === 'function') {
|
3393 | if (require.register)
|
3394 | require.register('ion/runtime/Statement',_ion_runtime_Statement_);
|
3395 | else
|
3396 | _ion_runtime_Statement_.call(this, module, exports, require);
|
3397 | }
|
3398 | else {
|
3399 | _ion_runtime_Statement_.call(this);
|
3400 | }
|
3401 | }).call(this)
|
3402 |
|
3403 | void (function(){var _ion_runtime_Template_ = function(module,exports,require){'use strict';
|
3404 | var ion = require('../'), BlockStatement = require('./BlockStatement'), DynamicExpression = require('./DynamicExpression'), noop = function () {
|
3405 | };
|
3406 | var Template = ion.defineClass({
|
3407 | name: 'Template',
|
3408 | constructor: function Template() {
|
3409 | Template.super.apply(this, arguments);
|
3410 | this.context.returnExpression = new DynamicExpression();
|
3411 | },
|
3412 | properties: {
|
3413 | watchValue: function (watcher) {
|
3414 | if (watcher == null)
|
3415 | watcher = noop;
|
3416 | if (!this.isActive) {
|
3417 | this.activate();
|
3418 | }
|
3419 | this.context.returnExpression.watchValue(watcher);
|
3420 | },
|
3421 | unwatchValue: function (watcher) {
|
3422 | this.context.returnExpression.unwatchValue(watcher);
|
3423 | if (!this.context.returnExpression.isActive) {
|
3424 | this.deactivate();
|
3425 | }
|
3426 | }
|
3427 | }
|
3428 | }, BlockStatement);
|
3429 | module.exports = exports = Template;
|
3430 | }
|
3431 | if (typeof require === 'function') {
|
3432 | if (require.register)
|
3433 | require.register('ion/runtime/Template',_ion_runtime_Template_);
|
3434 | else
|
3435 | _ion_runtime_Template_.call(this, module, exports, require);
|
3436 | }
|
3437 | else {
|
3438 | _ion_runtime_Template_.call(this);
|
3439 | }
|
3440 | }).call(this)
|
3441 |
|
3442 | void (function(){var _ion_runtime_VariableDeclaration_ = function(module,exports,require){'use strict';
|
3443 | var ion = require('../');
|
3444 | var Statement = require('./Statement');
|
3445 | var VariableDeclaration = ion.defineClass({
|
3446 | name: 'VariableDeclaration',
|
3447 | constructor: function VariableDeclaration() {
|
3448 | VariableDeclaration.super.apply(this, arguments);
|
3449 | {
|
3450 | var _ref = this.declarations;
|
3451 | for (var _i = 0; _i < _ref.length; _i++) {
|
3452 | var _ref2 = _ref[_i];
|
3453 | var name = _ref2.id.name;
|
3454 | var init = _ref2.init;
|
3455 | this.context.setVariableFromAst(name, init);
|
3456 | }
|
3457 | }
|
3458 | }
|
3459 | }, Statement);
|
3460 | module.exports = exports = VariableDeclaration;
|
3461 | }
|
3462 | if (typeof require === 'function') {
|
3463 | if (require.register)
|
3464 | require.register('ion/runtime/VariableDeclaration',_ion_runtime_VariableDeclaration_);
|
3465 | else
|
3466 | _ion_runtime_VariableDeclaration_.call(this, module, exports, require);
|
3467 | }
|
3468 | else {
|
3469 | _ion_runtime_VariableDeclaration_.call(this);
|
3470 | }
|
3471 | }).call(this)
|
3472 |
|
3473 | void (function(){var _ion_runtime_index_ = function(module,exports,require){Object.defineProperty(exports, 'ArrayExpression', {get:function(){ return require('./ArrayExpression') }, enumerable: true})
|
3474 | Object.defineProperty(exports, 'BlockStatement', {get:function(){ return require('./BlockStatement') }, enumerable: true})
|
3475 | Object.defineProperty(exports, 'CallExpression', {get:function(){ return require('./CallExpression') }, enumerable: true})
|
3476 | Object.defineProperty(exports, 'ConditionalExpression', {get:function(){ return require('./ConditionalExpression') }, enumerable: true})
|
3477 | Object.defineProperty(exports, 'Context', {get:function(){ return require('./Context') }, enumerable: true})
|
3478 | Object.defineProperty(exports, 'DynamicExpression', {get:function(){ return require('./DynamicExpression') }, enumerable: true})
|
3479 | Object.defineProperty(exports, 'Expression', {get:function(){ return require('./Expression') }, enumerable: true})
|
3480 | Object.defineProperty(exports, 'ExpressionStatement', {get:function(){ return require('./ExpressionStatement') }, enumerable: true})
|
3481 | Object.defineProperty(exports, 'Factory', {get:function(){ return require('./Factory') }, enumerable: true})
|
3482 | Object.defineProperty(exports, 'ForInOfStatement', {get:function(){ return require('./ForInOfStatement') }, enumerable: true})
|
3483 | Object.defineProperty(exports, 'IfStatement', {get:function(){ return require('./IfStatement') }, enumerable: true})
|
3484 | Object.defineProperty(exports, 'Literal', {get:function(){ return require('./Literal') }, enumerable: true})
|
3485 | Object.defineProperty(exports, 'MemberExpression', {get:function(){ return require('./MemberExpression') }, enumerable: true})
|
3486 | Object.defineProperty(exports, 'Node', {get:function(){ return require('./Node') }, enumerable: true})
|
3487 | Object.defineProperty(exports, 'ObjectExpression', {get:function(){ return require('./ObjectExpression') }, enumerable: true})
|
3488 | Object.defineProperty(exports, 'OperationExpression', {get:function(){ return require('./OperationExpression') }, enumerable: true})
|
3489 | Object.defineProperty(exports, 'Property', {get:function(){ return require('./Property') }, enumerable: true})
|
3490 | Object.defineProperty(exports, 'ReturnStatement', {get:function(){ return require('./ReturnStatement') }, enumerable: true})
|
3491 | Object.defineProperty(exports, 'Statement', {get:function(){ return require('./Statement') }, enumerable: true})
|
3492 | Object.defineProperty(exports, 'Template', {get:function(){ return require('./Template') }, enumerable: true})
|
3493 | Object.defineProperty(exports, 'VariableDeclaration', {get:function(){ return require('./VariableDeclaration') }, enumerable: true})
|
3494 | }
|
3495 | if (typeof require === 'function') {
|
3496 | if (require.register)
|
3497 | require.register('ion/runtime/index',_ion_runtime_index_);
|
3498 | else
|
3499 | _ion_runtime_index_.call(this, module, exports, require);
|
3500 | }
|
3501 | else {
|
3502 | _ion_runtime_index_.call(this);
|
3503 | }
|
3504 | }).call(this)
|
3505 |
|
3506 |
|
3507 |
|
3508 |
|
3509 |
|