1 | const NullDependency = require('webpack/lib/dependencies/NullDependency');
|
2 |
|
3 | class ClosureHarmonyExportDependency extends NullDependency {
|
4 | constructor(declaration, rangeStatement, module, name, id) {
|
5 | super();
|
6 | this.declaration = declaration;
|
7 | this.rangeStatement = rangeStatement;
|
8 | this.originModule = module;
|
9 | this.name = name;
|
10 | this.id = id;
|
11 | }
|
12 |
|
13 | get type() {
|
14 | return 'harmony export';
|
15 | }
|
16 |
|
17 | getExports() {
|
18 | return {
|
19 | exports: [this.id],
|
20 | dependencies: undefined,
|
21 | };
|
22 | }
|
23 |
|
24 | updateHash(hash) {
|
25 | hash.update(this.rangeStatement + '');
|
26 | hash.update(this.declaration + '');
|
27 | hash.update('ClosureHarmonyExportDependency');
|
28 | }
|
29 | }
|
30 |
|
31 | ClosureHarmonyExportDependency.Template = class ClosureHarmonyExportDependencyTemplate {
|
32 | apply(dep, source) {
|
33 | const used = dep.originModule.isUsed(dep.name);
|
34 | if (!used) {
|
35 | const replaceUntil =
|
36 | dep.declaration && dep.declaration.range
|
37 | ? dep.declaration.range[0] - 1
|
38 | : dep.rangeStatement[1] - 1;
|
39 | source.replace(dep.rangeStatement[0], replaceUntil, '');
|
40 | }
|
41 | }
|
42 | };
|
43 |
|
44 | module.exports = ClosureHarmonyExportDependency;
|