|
2 | 2 | MIT License http://www.opensource.org/licenses/mit-license.php |
3 | 3 | Author Tobias Koppers @sokra |
4 | 4 | */ |
5 | | -function FlagDependencyExportsPlugin() { |
| 5 | +"use strict"; |
6 | 6 |
|
7 | | -} |
8 | | -module.exports = FlagDependencyExportsPlugin; |
| 7 | +class FlagDependencyExportsPlugin { |
9 | 8 |
|
10 | | -FlagDependencyExportsPlugin.prototype.apply = function(compiler) { |
11 | | - compiler.plugin("compilation", function(compilation) { |
12 | | - compilation.plugin("finish-modules", function(modules) { |
| 9 | + apply(compiler) { |
| 10 | + compiler.plugin("compilation", (compilation) => { |
| 11 | + compilation.plugin("finish-modules", (modules) => { |
13 | 12 |
|
14 | | - var dependencies = {}; |
| 13 | + const dependencies = Object.create(null); |
15 | 14 |
|
16 | | - var module, moduleWithExports; |
17 | | - var queue = modules.filter(function(m) { |
18 | | - return !m.providedExports; |
19 | | - }); |
20 | | - for(var i = 0; i < queue.length; i++) { |
21 | | - module = queue[i]; |
| 15 | + let module; |
| 16 | + let moduleWithExports; |
| 17 | + const queue = modules.filter((m) => !m.providedExports); |
| 18 | + for(let i = 0; i < queue.length; i++) { |
| 19 | + module = queue[i]; |
22 | 20 |
|
23 | | - if(module.providedExports !== true) { |
24 | | - moduleWithExports = false; |
25 | | - processDependenciesBlock(module); |
26 | | - if(!moduleWithExports) { |
27 | | - module.providedExports = true; |
28 | | - notifyDependencies(); |
| 21 | + if(module.providedExports !== true) { |
| 22 | + moduleWithExports = false; |
| 23 | + processDependenciesBlock(module); |
| 24 | + if(!moduleWithExports) { |
| 25 | + module.providedExports = true; |
| 26 | + notifyDependencies(); |
| 27 | + } |
29 | 28 | } |
30 | 29 | } |
31 | | - } |
32 | 30 |
|
33 | | - function processDependenciesBlock(depBlock) { |
34 | | - depBlock.dependencies.forEach(function(dep) { |
35 | | - processDependency(dep); |
36 | | - }); |
37 | | - depBlock.variables.forEach(function(variable) { |
38 | | - variable.dependencies.forEach(function(dep) { |
39 | | - processDependency(dep); |
40 | | - }); |
41 | | - }); |
42 | | - depBlock.blocks.forEach(function(block) { |
43 | | - processDependenciesBlock(block); |
44 | | - }); |
45 | | - } |
46 | | - |
47 | | - function processDependency(dep, usedExports) { |
48 | | - var exportDesc = dep.getExports && dep.getExports(); |
49 | | - if(!exportDesc) return; |
50 | | - moduleWithExports = true; |
51 | | - var exports = exportDesc.exports; |
52 | | - var exportDeps = exportDesc.dependencies; |
53 | | - if(exportDeps) { |
54 | | - exportDeps.forEach(function(dep) { |
55 | | - var depIdent = dep.identifier(); |
56 | | - var array = dependencies["$" + depIdent]; |
57 | | - if(!array) array = dependencies["$" + depIdent] = []; |
58 | | - if(array.indexOf(module) < 0) |
59 | | - array.push(module); |
| 31 | + function processDependenciesBlock(depBlock) { |
| 32 | + depBlock.dependencies.forEach((dep) => processDependency(dep)); |
| 33 | + depBlock.variables.forEach((variable) => { |
| 34 | + variable.dependencies.forEach((dep) => processDependency(dep)); |
60 | 35 | }); |
| 36 | + depBlock.blocks.forEach(processDependenciesBlock); |
61 | 37 | } |
62 | | - var changed = false; |
63 | | - if(module.providedExports !== true) { |
64 | | - if(exports === true) { |
65 | | - module.providedExports = true; |
66 | | - changed = true; |
67 | | - } else if(Array.isArray(exports)) { |
68 | | - if(Array.isArray(module.providedExports)) { |
69 | | - changed = addToSet(module.providedExports, exports); |
70 | | - } else { |
71 | | - module.providedExports = exports.slice(); |
| 38 | + |
| 39 | + function processDependency(dep, usedExports) { |
| 40 | + const exportDesc = dep.getExports && dep.getExports(); |
| 41 | + if(!exportDesc) return; |
| 42 | + moduleWithExports = true; |
| 43 | + const exports = exportDesc.exports; |
| 44 | + const exportDeps = exportDesc.dependencies; |
| 45 | + if(exportDeps) { |
| 46 | + exportDeps.forEach((dep) => { |
| 47 | + const depIdent = dep.identifier(); |
| 48 | + let array = dependencies[depIdent]; |
| 49 | + if(!array) array = dependencies[depIdent] = []; |
| 50 | + if(array.indexOf(module) < 0) |
| 51 | + array.push(module); |
| 52 | + }); |
| 53 | + } |
| 54 | + let changed = false; |
| 55 | + if(module.providedExports !== true) { |
| 56 | + if(exports === true) { |
| 57 | + module.providedExports = true; |
72 | 58 | changed = true; |
| 59 | + } else if(Array.isArray(exports)) { |
| 60 | + if(Array.isArray(module.providedExports)) { |
| 61 | + changed = addToSet(module.providedExports, exports); |
| 62 | + } else { |
| 63 | + module.providedExports = exports.slice(); |
| 64 | + changed = true; |
| 65 | + } |
73 | 66 | } |
74 | 67 | } |
| 68 | + if(changed) { |
| 69 | + notifyDependencies(); |
| 70 | + } |
75 | 71 | } |
76 | | - if(changed) { |
77 | | - notifyDependencies(); |
78 | | - } |
79 | | - } |
80 | 72 |
|
81 | | - function notifyDependencies() { |
82 | | - var deps = dependencies["$" + module.identifier()]; |
83 | | - if(deps) { |
84 | | - deps.forEach(function(dep) { |
85 | | - queue.push(dep); |
86 | | - }); |
| 73 | + function notifyDependencies() { |
| 74 | + const deps = dependencies[module.identifier()]; |
| 75 | + if(deps) { |
| 76 | + deps.forEach((dep) => queue.push(dep)); |
| 77 | + } |
87 | 78 | } |
| 79 | + }); |
| 80 | + |
| 81 | + function addToSet(a, b) { |
| 82 | + let changed = false; |
| 83 | + b.forEach((item) => { |
| 84 | + if(a.indexOf(item) < 0) { |
| 85 | + a.push(item); |
| 86 | + changed = true; |
| 87 | + } |
| 88 | + }); |
| 89 | + return changed; |
88 | 90 | } |
89 | 91 | }); |
| 92 | + } |
| 93 | +} |
90 | 94 |
|
91 | | - function addToSet(a, b) { |
92 | | - var changed = false; |
93 | | - b.forEach(function(item) { |
94 | | - if(a.indexOf(item) < 0) { |
95 | | - a.push(item); |
96 | | - changed = true; |
97 | | - } |
98 | | - }); |
99 | | - return changed; |
100 | | - } |
101 | | - }); |
102 | | -}; |
| 95 | +module.exports = FlagDependencyExportsPlugin; |
0 commit comments