"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.EventsHandlingPlugin = void 0;

/* eslint-disable no-use-before-define */
class EventsHandlingPlugin {
  constructor(options) {}

  apply(compiler) {
    // NOTE: we not using this, Reason currently this option is only need for EFC,
    // So it do not needed.
    compiler.hooks.thisCompilation.tap({
      name: 'CustomAttributePlugin',
      stage: 1,
      fn: compilation => {
        compilation.mainTemplate.hooks.requireEnsure.tap('CustomAttributePlugin', source => {
          // const str = attributeSetTemplate(cssAttributes, 'linkTag');
          const sourceStr = source.replace('linkTag.onerror = function(event) {', 'linkTag.onerror = function(event) { linkTag.onerror = linkTag.onload = null;');
          const replacedSourceStr = sourceStr.replace('linkTag.onload = resolve', `linkTag.onload = () =>  { 
          linkTag.onerror = linkTag.onload = null;
          resolve();
        };`);
          return replacedSourceStr;
        });
      }
    });
  }

}

exports.EventsHandlingPlugin = EventsHandlingPlugin;