All files / dist/helpers decorators.js

32% Statements 8/25
14.29% Branches 2/14
25% Functions 1/4
32% Lines 8/25
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 47 48 49 50 51 52 53    1x     1x   1x   1x 1x     1x   1x 1x                                                                        
"use strict";
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getDecoratorClassInfo = getDecoratorClassInfo;
 
require("source-map-support/register");
 
const classInfoValueTags = ['alias', 'name', 'namespace', 'metadata', 'renderer'];
const classInfoBoolTags = ['nonUI5'];
 
function getDecoratorClassInfo(node) {
  const decorators = node.decorators;
 
  Eif (!decorators || !decorators.length) {
    return null;
  }
 
  const decoratorsByName = groupByName(decorators);
  const info = {};
 
  for (const tagName of classInfoValueTags) {
    const value = getDecoratorValue(decoratorsByName[tagName.toLowerCase()]);
 
    if (value) {
      info[tagName] = value;
    }
  }
 
  for (const tagName of classInfoBoolTags) {
    const value = !!decoratorsByName[tagName.toLowerCase()];
 
    if (value) {
      info[tagName] = value;
    }
  }
 
  return info;
}
 
function groupByName(decorators) {
  return decorators.reduce((accumulator, decorator) => {
    const expression = decorator.expression;
    const name = expression.name || expression.callee && expression.callee.name;
    accumulator[name.toLowerCase()] = decorator;
    return accumulator;
  }, {});
}
 
function getDecoratorValue(decorator) {
  return (decorator && decorator.expression.arguments[0] || {}).value;
}