Sha256: 0118177fe90717572631a470a34f3d81c0ac8d13b1e32cb495552de3664f8291
Contents?: true
Size: 1.2 KB
Versions: 3
Compression:
Stored size: 1.2 KB
Contents
use :node; var Node = module.require('../Node').Node; fn LogicalExpression(left, operator, right) extends Node { this.type = 'LogicalExpression'; this.operator = operator; switch this.operator { case 'and': { this.operator = '&&'; }, case 'or': { this.operator = '||'; } } this.left = left; this.left.parent = this; this.right = right; this.right.parent = this; } LogicalExpression.prototype.codegen = () -> { if !super.codegen() { return; } var enforceBooleanExpression = (o) -> { if o.type == "UnaryExpression" and o.operator == "!" { return o; } return { "type": "UnaryExpression", "operator": "!", "argument": { "type": "UnaryExpression", "operator": "!", "argument": o, "prefix": true }, "prefix": true }; }; this.left = enforceBooleanExpression(this.left.codegen()); this.right = enforceBooleanExpression(this.right.codegen()); return this; }; LogicalExpression.prototype.hasCallExpression = () -> { return this.left?.hasCallExpression() || this.right?.hasCallExpression(); }; exports.LogicalExpression = LogicalExpression;
Version data entries
3 entries across 3 versions & 1 rubygems