/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/
"use strict";
var RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
var RequireEnsureDependency = require("./RequireEnsureDependency");
var ConstDependency = require("./ConstDependency");

var NullFactory = require("../NullFactory");

var RequireEnsureDependenciesBlockParserPlugin = require("./RequireEnsureDependenciesBlockParserPlugin");

const ParserHelpers = require("../ParserHelpers");

function RequireEnsurePlugin() {}
module.exports = RequireEnsurePlugin;

RequireEnsurePlugin.prototype.apply = function(compiler) {
	compiler.plugin("compilation", function(compilation, params) {
		var normalModuleFactory = params.normalModuleFactory;

		compilation.dependencyFactories.set(RequireEnsureItemDependency, normalModuleFactory);
		compilation.dependencyTemplates.set(RequireEnsureItemDependency, new RequireEnsureItemDependency.Template());

		compilation.dependencyFactories.set(RequireEnsureDependency, new NullFactory());
		compilation.dependencyTemplates.set(RequireEnsureDependency, new RequireEnsureDependency.Template());

		params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {

			if(typeof parserOptions.requireEnsure !== "undefined" && !parserOptions.requireEnsure)
				return;

			parser.apply(new RequireEnsureDependenciesBlockParserPlugin());
			parser.plugin("evaluate typeof require.ensure", ParserHelpers.evaluateToString("function"));
			parser.plugin("typeof require.ensure", function(expr) {
				var dep = new ConstDependency("'function'", expr.range);
				dep.loc = expr.loc;
				this.state.current.addDependency(dep);
				return true;
			});
		});
	});
};

@@ -107,19 +107,22 @@
 trict%22;%0A
-var
+%0Aconst
  Require
@@ -186,19 +186,21 @@
 ency%22);%0A
-var
+const
  Require
@@ -256,19 +256,21 @@
 ency%22);%0A
-var
+const
  ConstDe
@@ -311,19 +311,21 @@
 ncy%22);%0A%0A
-var
+const
  NullFac
@@ -359,19 +359,21 @@
 ory%22);%0A%0A
-var
+const
  Require
@@ -524,127 +524,43 @@
 );%0A%0A
-function RequireEnsurePlugin() %7B%7D%0Amodule.exports = RequireEnsurePlugin;%0A%0ARequireEnsurePlugin.prototype.apply = function
+class RequireEnsurePlugin %7B%0A%0A%09apply
 (com
@@ -568,16 +568,17 @@
 iler) %7B%0A
+%09
 %09compile
@@ -601,24 +601,16 @@
 ation%22, 
-function
 (compila
@@ -626,16 +626,22 @@
 ams)
+ =%3E
  %7B%0A%09%09
-var
+%09const
  nor
@@ -688,16 +688,17 @@
 ctory;%0A%0A
+%09
 %09%09compil
@@ -778,16 +778,17 @@
 ctory);%0A
+%09
 %09%09compil
@@ -894,16 +894,17 @@
 ());%0A%0A%09%09
+%09
 compilat
@@ -976,16 +976,17 @@
 ory());%0A
+%09
 %09%09compil
@@ -1084,16 +1084,17 @@
 ());%0A%0A%09%09
+%09
 params.n
@@ -1129,24 +1129,16 @@
 arser%22, 
-function
 (parser,
@@ -1152,20 +1152,24 @@
 Options)
+ =%3E
  %7B%0A%0A
+%09
 %09%09%09if(ty
@@ -1250,16 +1250,17 @@
 Ensure)%0A
+%09
 %09%09%09%09retu
@@ -1263,24 +1263,25 @@
 return;%0A%0A%09%09%09
+%09
 parser.apply
@@ -1328,24 +1328,25 @@
 rPlugin());%0A
+%09
 %09%09%09parser.pl
@@ -1432,16 +1432,17 @@
 %22));%0A%09%09%09
+%09
 parser.p
@@ -1476,32 +1476,30 @@
 e%22, 
-function
 (expr)
+ =%3E
  %7B%0A%09%09%09%09
+%09
-var
+const
  dep
@@ -1552,16 +1552,17 @@
 e);%0A%09%09%09%09
+%09
 dep.loc 
@@ -1581,12 +1581,15 @@
 %09%09%09%09
-this
+%09parser
 .sta
@@ -1619,24 +1619,25 @@
 y(dep);%0A%09%09%09%09
+%09
 return true;
@@ -1637,16 +1637,17 @@
 n true;%0A
+%09
 %09%09%09%7D);%0A%09
@@ -1651,16 +1651,58 @@
 ;%0A%09%09
+%09
 %7D);%0A
+%09
 %09%7D);%0A
-%7D
+%09%7D%0A%7D%0Amodule.exports = RequireEnsurePlugin
 ;%0A

upgrade RequireEnsurePlugin to ES6