HarmonyExportExpressionDependency.js
1.29 KB
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
/*
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"]
};
}
}
HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTemplate {
apply(dep, source) {
const used = dep.originModule.isUsed("default");
const content = this.getContent(dep.originModule, 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(module, used) {
const exportsName = module.exportsArgument || "exports";
if(used) {
return `/* harmony default export */ ${exportsName}[${JSON.stringify(used)}] = `;
}
return "/* unused harmony default export */ var _unused_webpack_default_export = ";
}
};
module.exports = HarmonyExportExpressionDependency;