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

function HarmonyExportExpressionDependency(originModule, range, rangeStatement) {
	NullDependency.call(this);
	this.originModule = originModule;
	this.range = range;
	this.rangeStatement = rangeStatement;
}
module.exports = HarmonyExportExpressionDependency;

HarmonyExportExpressionDependency.prototype = Object.create(NullDependency.prototype);
HarmonyExportExpressionDependency.prototype.constructor = HarmonyExportExpressionDependency;
HarmonyExportExpressionDependency.prototype.type = "harmony export expression";

HarmonyExportExpressionDependency.prototype.getExports = function() {
	return {
		exports: ["default"]
	};
};

HarmonyExportExpressionDependency.prototype.describeHarmonyExport = function() {
	return {
		exportedName: "default",
		precedence: 1
	};
};

HarmonyExportExpressionDependency.Template = function HarmonyExportDependencyTemplate() {};

HarmonyExportExpressionDependency.Template.prototype.apply = function(dep, source) {
	var used = dep.originModule.isUsed("default");
	var content;
	if(used)
		content = "/* harmony default export */ exports[" + JSON.stringify(used) + "] = ";
	else
		content = "/* unused harmony default export */ var _unused_webpack_default_export = ";
	if(dep.range) {
		source.replace(dep.rangeStatement[0], dep.range[0] - 1, content);
		source.replace(dep.range[1], dep.rangeStatement[1] - 1, ";");
	} else {
		source.replace(dep.rangeStatement[0], dep.rangeStatement[1] - 1, content);
	}
};

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

class HarmonyExportExpressionDependency extends NullDependency {
	constructor(originModule, range, rangeStatement) {
		super();
		this.originModule = originModule;
		this.range = range;
		this.rangeStatement = rangeStatement;
	}

	get type() {
		return "harmony export expression";
	}

	getExports() {
		return {
			exports: ["default"]
		};
	}

	describeHarmonyExport() {
		return {
			exportedName: "default",
			precedence: 1,
		};
	}
}

HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTemplate {
	apply(dep, source) {
		const used = dep.originModule.isUsed("default");
		const content = this.getContent(used);

		if(dep.range) {
			source.replace(dep.rangeStatement[0], dep.range[0] - 1, content);
			source.replace(dep.range[1], dep.rangeStatement[1] - 1, ";");
			return;
		}

		source.replace(dep.rangeStatement[0], dep.rangeStatement[1] - 1, content);
	}

	getContent(used) {
		if(used) {
			return `/* harmony default export */ exports[${JSON.stringify(used)}] = `;
		}
		return "/* unused harmony default export */ var _unused_webpack_default_export = ";
	}
}

module.exports = HarmonyExportExpressionDependency;

refactor harmonyExportExpressionDependency to es6 (#3710)