All files OpenUI5DefineDependency.js

91.67% Statements 33/36
70.59% Branches 12/17
85.71% Functions 6/7
91.43% Lines 32/35
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 931x       7x 7x 7x 7x 7x               1x   7x                                             7x 7x 7x 7x 7x       14x       7x 7x 7x 7x       7x 7x         7x 3x     7x   7x   7x 7x 4x 4x     7x 7x   7x               1x  
const NullDependency = require('webpack/lib/dependencies/NullDependency');
 
class OpenUI5DefineDependency extends NullDependency {
  constructor(range, arrayRange, functionRange, namedModule) {
    super();
    this.range = range;
    this.arrayRange = arrayRange;
    this.functionRange = functionRange;
    this.namedModule = namedModule;
  }
 
  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__))`,
      ],
      lf: [
        'var XXX, XXXmodule;',
        '!(XXXmodule = { id: YYY, exports: {}, loaded: false }, XXX = #.call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule), XXXmodule.loaded = true, XXX === undefined && (XXX = XXXmodule.exports))',
      ],
      laf: [
        'var __WEBPACK_UI5_DEFINE_ARRAY__, XXX;',
        '!(__WEBPACK_UI5_DEFINE_ARRAY__ = #, XXX = (#.apply(exports, __WEBPACK_UI5_DEFINE_ARRAY__)))',
      ],
    };
  }
 
  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);
  }
 
  localModuleVar(dependency) {
    return dependency.localModule && dependency.localModule.used && dependency.localModule.variableName();
  }
 
  branch(dependency) {
    const localModuleVar = this.localModuleVar(dependency) ? 'l' : '';
    const arrayRange = dependency.arrayRange ? 'a' : '';
    const functionRange = dependency.functionRange ? 'f' : '';
    return localModuleVar + arrayRange + functionRange;
  }
 
  replace(dependency, source, definition, text) {
    const localModuleVar = this.localModuleVar(dependency);
    Iif (localModuleVar) {
      text = text.replace(/XXX/g, localModuleVar.replace(/\$/g, '$$$$'));
      definition = definition.replace(/XXX/g, localModuleVar.replace(/\$/g, '$$$$'));
    }
 
    if (dependency.namedModule) {
      text = text.replace(/YYY/g, JSON.stringify(dependency.namedModule));
    }
 
    const texts = text.split('#');
 
    Eif (definition) source.insert(0, definition);
 
    let current = dependency.range[0];
    if (dependency.arrayRange) {
      source.replace(current, dependency.arrayRange[0] - 1, texts.shift());
      current = dependency.arrayRange[1];
    }
 
    source.replace(current, dependency.functionRange[0] - 1, texts.shift());
    current = dependency.functionRange[1];
 
    source.replace(current, dependency.range[1] - 1, texts.shift());
    /* istanbul ignore next */
    if (texts.length > 0) {
      throw new Error('Implementation error');
    }
  }
};
 
module.exports = OpenUI5DefineDependency;