Code coverage report for harmonizer/transform/arrow-functions.js

Statements: 100% (21 / 21)      Branches: 100% (2 / 2)      Functions: 100% (3 / 3)      Lines: 100% (21 / 21)      Ignored: none     

All files » harmonizer/transform/ » arrow-functions.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  1 1 1 1 1 1 1 1 10       10 10 10 10 10 7   3   10   10 89 89     1
'use strict';
var objectPatternB = require('nodes');
var nodes = objectPatternB.nodes;
var syntax = require('nodes/syntax.json');
var objectPatternA = require('../util/self');
var getSelfId = objectPatternA.getSelfId;
var objectPattern = require('../util/arguments');
var getArgumentsId = objectPattern.getArgumentsId;
function arrowify(program) {
  var q = [
      '#ArrowFunctionExpression => #ThisExpression',
      '#ArrowFunctionExpression => #Identifier:reference[name=arguments]'
    ];
  program.search(q).forEach(function (expression) {
    var arrowFunction = expression.scope();
    var arrowScope = arrowFunction.scope('[type!=ArrowFunctionExpression]');
    var id;
    if (expression.type === syntax.ThisExpression) {
      id = getSelfId(arrowScope);
    } else {
      id = getArgumentsId(arrowScope);
    }
    expression.parentNode.replaceChild(expression, id.clone());
  });
  program.search('#ArrowFunctionExpression').forEach(function (node) {
    var shallow = new nodes.FunctionExpression(node);
    node.parentNode.replaceChild(node, shallow);
  });
}
exports.transform = arrowify;