All files OpenUI5DefineDependency.js

93.33% Statements 28/30
50% Branches 6/12
83.33% Functions 5/6
96.43% Lines 27/28
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    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';
 
const NullDependency = require('webpack/lib/dependencies/NullDependency');
 
class OpenUI5DefineDependency extends NullDependency {
  constructor(range, arrayRange, functionRange) {
    super();
    this.range = range;
    this.arrayRange = arrayRange;
    this.functionRange = functionRange;
  }
 
  get type() {
    return 'openui5 define';
  }
}
 
OpenUI5DefineDependency.Template = class UI5DefineDependencyTemplate {
  get definitions() {
    return {
      f: [
        'var __WEBPACK_UI5_DEFINE_RESULT__;',
        `!(__WEBPACK_UI5_DEFINE_RESULT__ = #.call(exports, __webpack_require__, exports, module),
				__WEBPACK_UI5_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_UI5_DEFINE_RESULT__))`,
      ],
      af: [
        'var __WEBPACK_UI5_DEFINE_ARRAY__, __WEBPACK_UI5_DEFINE_RESULT__;',
        `!(__WEBPACK_UI5_DEFINE_ARRAY__ = #, __WEBPACK_UI5_DEFINE_RESULT__ = #.apply(exports, __WEBPACK_UI5_DEFINE_ARRAY__),
				__WEBPACK_UI5_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_UI5_DEFINE_RESULT__))`,
      ],
    };
  }
 
  apply(dependency, source) {
    const branch = this.branch(dependency);
    const defAndText = this.definitions[branch];
    const definitions = defAndText[0];
    const text = defAndText[1];
    this.replace(dependency, source, definitions, text);
  }
 
  branch(dependency) {
    const arrayRange = dependency.arrayRange ? 'a' : '';
    const functionRange = dependency.functionRange ? 'f' : '';
    return arrayRange + functionRange;
  }
 
  replace(dependency, source, definition, text) {
    const texts = text.split('#');
 
    Eif (definition) source.insert(0, definition);
 
    let current = dependency.range[0];
    Eif (dependency.arrayRange) {
      source.replace(current, dependency.arrayRange[0] - 1, texts.shift());
      current = dependency.arrayRange[1];
    }
 
    Eif (dependency.functionRange) {
      source.replace(current, dependency.functionRange[0] - 1, texts.shift());
      current = dependency.functionRange[1];
    }
    source.replace(current, dependency.range[1] - 1, texts.shift());
    Iif (texts.length > 0) { throw new Error('Implementation error'); }
  }
};
 
module.exports = OpenUI5DefineDependency;