expression-language
Version:
Javascript implementation of symfony/expression-language
62 lines (61 loc) • 2.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _Node = _interopRequireDefault(require("./Node"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
class ConstantNode extends _Node.default {
constructor(_value, isIdentifier = false, isNullSafe = false) {
super({}, {
value: _value
});
_defineProperty(this, "compile", compiler => {
compiler.repr(this.attributes.value, this.isIdentifier);
});
_defineProperty(this, "evaluate", (functions, values) => {
return this.attributes.value;
});
_defineProperty(this, "toArray", () => {
let array = [],
value = this.attributes.value;
if (this.isIdentifier) {
array.push(value);
} else if (true === value) {
array.push('true');
} else if (false === value) {
array.push('false');
} else if (null === value) {
array.push('null');
} else if (typeof value === "number") {
array.push(value);
} else if (typeof value === "string") {
array.push(this.dumpString(value));
} else if (Array.isArray(value)) {
for (let v of value) {
array.push(',');
array.push(new ConstantNode(v));
}
array[0] = '[';
array.push(']');
} else if (this.isHash(value)) {
for (let k of Object.keys(value)) {
array.push(', ');
array.push(new ConstantNode(k));
array.push(': ');
array.push(new ConstantNode(value[k]));
}
array[0] = '{';
array.push('}');
}
return array;
});
this.isIdentifier = isIdentifier;
this.isNullSafe = isNullSafe;
this.name = 'ConstantNode';
}
}
exports.default = ConstantNode;