All files / dist/helpers templates.js

81.36% Statements 48/59
30% Branches 6/20
66.67% Functions 2/3
97.92% Lines 47/48
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155    1x     1x 1x   1x   1x   1x   1x   1x   1x 1x 1x 1x     1x 1x         1x 1x         1x 1x         1x 1x     1x 1x               1x                     1x                         1x 1x     1x 1x     1x 1x     1x 1x       1x 1x                                     1x 1x     1x 1x     1x 1x       1x 1x                 1x 1x               1x 1x         1x
"use strict";
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.buildNamedExport = buildNamedExport;
exports.buildInheritingConstructor = exports.buildInheritingFunction = exports.buildThisAssignment = exports.buildExtendAssign = exports.buildNamedImportDestructor = exports.buildConstDeclaration = exports.buildDynamicImportHelper = exports.buildDefaultImportDestructor = exports.buildDefaultImportInterop = exports.buildReturn = exports.buildAllExport = exports.buildAllExportHelper = exports.buildReturnExports = exports.buildTempExport = exports.buildDeclareExports = exports.buildDefineGlobal = exports.buildDefine = exports.buildAssign = exports.exportsIdentifier = void 0;
 
require("source-map-support/register");
 
var t = _interopRequireWildcard(require("@babel/types"));
 
var _template = _interopRequireDefault(require("@babel/template"));
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
function _interopRequireWildcard(obj) { Eif (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
 
const exportName = '__exports';
const exportsIdentifier = t.identifier(exportName);
exports.exportsIdentifier = exportsIdentifier;
const buildAssign = (0, _template.default)(`
  OBJECT.NAME = VALUE;
`);
exports.buildAssign = buildAssign;
const buildDefine = (0, _template.default)(`
  sap.ui.define(SOURCES, function (PARAMS) {
    BODY;
  });
`);
exports.buildDefine = buildDefine;
const buildDefineGlobal = (0, _template.default)(`
  sap.ui.define(SOURCES, function (PARAMS) {
    BODY;
  }, true);
`);
exports.buildDefineGlobal = buildDefineGlobal;
const buildDeclareExports = (0, _template.default)(`
  const ${exportName} = {
    __esModule: true
  };
`);
exports.buildDeclareExports = buildDeclareExports;
const buildTempExport = (0, _template.default)(`
  const ${exportName} = VALUE;
`);
exports.buildTempExport = buildTempExport;
const buildReturnExports = (0, _template.default)(`
  return ${exportName};
`); // export const buildExportsModuleDeclaration = template(`
//   Object.defineProperty(${exportString}, "__esModule", {
//     value: true
//   });
// `)
 
exports.buildReturnExports = buildReturnExports;
 
function buildNamedExport(obj) {
  // console.log(obj);
  return buildAssign({
    OBJECT: exportsIdentifier,
    NAME: obj.key,
    VALUE: obj.value
  });
}
 
const buildAllExportHelper = (0, _template.default)(`
  function extendExports(exports, obj) {
    Object.keys(obj).forEach(function (key) {
      if (key === "default" || key === "__esModule") return;
      Object.defineProperty(exports, key, {
        enumerable: true,
        get: function get() {
          return obj[key];
        }
      });
    });
  }
`);
exports.buildAllExportHelper = buildAllExportHelper;
const buildAllExport = (0, _template.default)(`
  extendExports(${exportName}, LOCAL);
`);
exports.buildAllExport = buildAllExport;
const buildReturn = (0, _template.default)(`
  return ID;
`);
exports.buildReturn = buildReturn;
const buildDefaultImportInterop = (0, _template.default)(`
  function _interopRequireDefault(obj) { return (obj && obj.__esModule && typeof obj.default !== "undefined") ? obj.default : obj; }
`);
exports.buildDefaultImportInterop = buildDefaultImportInterop;
const buildDefaultImportDestructor = (0, _template.default)(`
  const LOCAL = _interopRequireDefault(MODULE);
`); // TODO: inject __extends instead of Object.assign unless useBuiltIns in set
 
exports.buildDefaultImportDestructor = buildDefaultImportDestructor;
const buildDynamicImportHelper = (0, _template.default)(`
  function __ui5_require_async(path) {
    return new Promise((resolve, reject) => {
      sap.ui.require([path], (module) => {
        if (!module) { 
          return reject("No module returned from " + path); 
        } else if (module.__esModule) { 
          return resolve(module); 
        } else if (module.default) {
          return reject(new Error(path + " module includes a 'default' property but not __esModule. Cannot use as dynamic import"));
        } else {
          module.default = typeof module === "object" ? Object.assign({}, module) : module;
          module.__esModule = true;
          resolve(module);
        }
      })
    })
  }
`);
exports.buildDynamicImportHelper = buildDynamicImportHelper;
const buildConstDeclaration = (0, _template.default)(`
  const NAME = VALUE;
`);
exports.buildConstDeclaration = buildConstDeclaration;
const buildNamedImportDestructor = (0, _template.default)(`
  const LOCAL = MODULE[IMPORTED];
`);
exports.buildNamedImportDestructor = buildNamedImportDestructor;
const buildExtendAssign = (0, _template.default)(`
  const NAME = SUPERNAME.extend(FQN, OBJECT);
`); // TODO: get this one to use buildAssign
 
exports.buildExtendAssign = buildExtendAssign;
const buildThisAssignment = (0, _template.default)(`
  this.NAME = VALUE;
`); // export const buildDefaultConstructorFunction = template(`
//   function constructor() {
//     SUPER.prototype.constructor.apply(this, arguments);
//   }
// `)
// This is use when there is not already the function, so always propagate arguments.
 
exports.buildThisAssignment = buildThisAssignment;
const buildInheritingFunction = (0, _template.default)(`
  function NAME() {
    if (typeof SUPER.prototype.NAME === 'function') {
      SUPER.prototype.NAME.apply(this, arguments);
    }
  }
`); // This is use when there is not already the function, so always propagate arguments.
 
exports.buildInheritingFunction = buildInheritingFunction;
const buildInheritingConstructor = (0, _template.default)(`
  function constructor() {
    SUPER.prototype.constructor.apply(this, arguments);
  }
`);
exports.buildInheritingConstructor = buildInheritingConstructor;