|
| 1 | +'use strict'; |
| 2 | +module.exports = class ESXToken { |
| 3 | + // property/ies + interpolations + templates |
| 4 | + static STATIC_TYPE = 1 << 0; // 1 |
| 5 | + static MIXED_TYPE = 1 << 1; // 2 |
| 6 | + static RUNTIME_TYPE = 1 << 2; // 4 |
| 7 | + static TEMPLATE_TYPE = 1 << 3; // 8 |
| 8 | + |
| 9 | + // angle-brackets kind |
| 10 | + static ELEMENT_TYPE = 1 << 6; // 64 |
| 11 | + static FRAGMENT_TYPE = 1 << 7; // 128 |
| 12 | + static COMPONENT_TYPE = 1 << 8; // 256 |
| 13 | + |
| 14 | + // the following utilities DO NOT NEED TO BE AVAILABLE or standardized |
| 15 | + // these are here to simplify, via a namespace, a possible Babel transformer |
| 16 | + |
| 17 | + // child / properties |
| 18 | + static create = (type, value) => ({__proto__: ESXToken.prototype, type, value}); |
| 19 | + |
| 20 | + // specialized cases |
| 21 | + static property = (type, name, value) => ({__proto__: ESXToken.prototype, type, name, value}); |
| 22 | + static template = (id, value) => ({__proto__: ESXToken.prototype, type: ESXToken.TEMPLATE_TYPE, id, value}); |
| 23 | + static chevron = (type, value, properties, children) => ({__proto__: ESXToken.prototype, type, value, properties, children}); |
| 24 | + static fragment = (...children) => ESXToken.chevron(ESXToken.FRAGMENT_TYPE, null, null, children); |
| 25 | + static element = (tag, properties, ...children) => ESXToken.chevron(ESXToken.ELEMENT_TYPE, tag, properties, children); |
| 26 | + static component = (fn, properties, ...children) => ESXToken.chevron(ESXToken.COMPONENT_TYPE, fn, properties, children); |
| 27 | +} |
0 commit comments