HarmonyModulesPlugin.js
3.63 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const HarmonyImportDependency = require("./HarmonyImportDependency");
const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
const HarmonyCompatiblilityDependency = require("./HarmonyCompatibilityDependency");
const HarmonyExportHeaderDependency = require("./HarmonyExportHeaderDependency");
const HarmonyExportExpressionDependency = require("./HarmonyExportExpressionDependency");
const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDependency");
const HarmonyExportImportedSpecifierDependency = require("./HarmonyExportImportedSpecifierDependency");
const HarmonyAcceptDependency = require("./HarmonyAcceptDependency");
const HarmonyAcceptImportDependency = require("./HarmonyAcceptImportDependency");
const NullFactory = require("../NullFactory");
const HarmonyDetectionParserPlugin = require("./HarmonyDetectionParserPlugin");
const HarmonyImportDependencyParserPlugin = require("./HarmonyImportDependencyParserPlugin");
const HarmonyExportDependencyParserPlugin = require("./HarmonyExportDependencyParserPlugin");
class HarmonyModulesPlugin {
constructor(options) {
this.options = options;
}
apply(compiler) {
compiler.plugin("compilation", (compilation, params) => {
const normalModuleFactory = params.normalModuleFactory;
compilation.dependencyFactories.set(HarmonyImportDependency, normalModuleFactory);
compilation.dependencyTemplates.set(HarmonyImportDependency, new HarmonyImportDependency.Template());
compilation.dependencyFactories.set(HarmonyImportSpecifierDependency, new NullFactory());
compilation.dependencyTemplates.set(HarmonyImportSpecifierDependency, new HarmonyImportSpecifierDependency.Template());
compilation.dependencyFactories.set(HarmonyCompatiblilityDependency, new NullFactory());
compilation.dependencyTemplates.set(HarmonyCompatiblilityDependency, new HarmonyCompatiblilityDependency.Template());
compilation.dependencyFactories.set(HarmonyExportHeaderDependency, new NullFactory());
compilation.dependencyTemplates.set(HarmonyExportHeaderDependency, new HarmonyExportHeaderDependency.Template());
compilation.dependencyFactories.set(HarmonyExportExpressionDependency, new NullFactory());
compilation.dependencyTemplates.set(HarmonyExportExpressionDependency, new HarmonyExportExpressionDependency.Template());
compilation.dependencyFactories.set(HarmonyExportSpecifierDependency, new NullFactory());
compilation.dependencyTemplates.set(HarmonyExportSpecifierDependency, new HarmonyExportSpecifierDependency.Template());
compilation.dependencyFactories.set(HarmonyExportImportedSpecifierDependency, new NullFactory());
compilation.dependencyTemplates.set(HarmonyExportImportedSpecifierDependency, new HarmonyExportImportedSpecifierDependency.Template());
compilation.dependencyFactories.set(HarmonyAcceptDependency, new NullFactory());
compilation.dependencyTemplates.set(HarmonyAcceptDependency, new HarmonyAcceptDependency.Template());
compilation.dependencyFactories.set(HarmonyAcceptImportDependency, normalModuleFactory);
compilation.dependencyTemplates.set(HarmonyAcceptImportDependency, new HarmonyAcceptImportDependency.Template());
params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
if(typeof parserOptions.harmony !== "undefined" && !parserOptions.harmony)
return;
parser.apply(
new HarmonyDetectionParserPlugin(),
new HarmonyImportDependencyParserPlugin(this.options),
new HarmonyExportDependencyParserPlugin()
);
});
});
}
}
module.exports = HarmonyModulesPlugin;