Code coverage report for src/ast/retif.js

Statements: 94.74% (18 / 19)      Branches: 75% (6 / 8)      Functions: 100% (2 / 2)      Lines: 94.74% (18 / 19)      Ignored: none     

All files » src/ast/ » retif.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46              1 1 1 1                   1 9 9 9 9           1 3 3 3 2 2 2 2             1  
/*!
 * Copyright (C) 2017 Glayzzle (BSD3 License)
 * @authors https://github.com/glayzzle/php-parser/graphs/contributors
 * @url http://glayzzle.com
 */
"use strict";
 
var Statement = require('./statement');
var KIND = 'retif';
var Bin = require('./bin');
var PRECEDENCE = Bin.precedence[KIND];
 
/**
 * Defines a short if statement that returns a value
 * @constructor RetIf
 * @extends {Statement}
 * @property {Expression} test
 * @property {Expression} trueExpr
 * @property {Expression} falseExpr
 */
var RetIf = Statement.extends(function RetIf(test, trueExpr, falseExpr, location) {
  Statement.apply(this, [KIND, location]);
  this.test = test;
  this.trueExpr = trueExpr;
  this.falseExpr = falseExpr;
});
 
/**
 * Handles precedence over items
 */
RetIf.prototype.precedence = function(node) {
  var what = node.kind === 'bin' ? node.type : node.kind;
  var lLevel = Bin.precedence[what];
  if (lLevel && PRECEDENCE < lLevel) {
    Eif (node.kind === 'bin') {
      node.right = this.test;
      this.test = node;
      return this;
    } else {
      throw new Error('@todo ' + node.kind);
    }
  }
};
 
module.exports = RetIf;