source: trip-planner-front/node_modules/webpack/lib/dependencies/HarmonyModulesPlugin.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const HarmonyAcceptDependency = require("./HarmonyAcceptDependency");
9const HarmonyAcceptImportDependency = require("./HarmonyAcceptImportDependency");
10const HarmonyCompatibilityDependency = require("./HarmonyCompatibilityDependency");
11const HarmonyExportExpressionDependency = require("./HarmonyExportExpressionDependency");
12const HarmonyExportHeaderDependency = require("./HarmonyExportHeaderDependency");
13const HarmonyExportImportedSpecifierDependency = require("./HarmonyExportImportedSpecifierDependency");
14const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDependency");
15const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
16const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
17
18const HarmonyDetectionParserPlugin = require("./HarmonyDetectionParserPlugin");
19const HarmonyExportDependencyParserPlugin = require("./HarmonyExportDependencyParserPlugin");
20const HarmonyImportDependencyParserPlugin = require("./HarmonyImportDependencyParserPlugin");
21const HarmonyTopLevelThisParserPlugin = require("./HarmonyTopLevelThisParserPlugin");
22
23/** @typedef {import("../Compiler")} Compiler */
24
25class HarmonyModulesPlugin {
26 constructor(options) {
27 this.options = options;
28 }
29
30 /**
31 * Apply the plugin
32 * @param {Compiler} compiler the compiler instance
33 * @returns {void}
34 */
35 apply(compiler) {
36 compiler.hooks.compilation.tap(
37 "HarmonyModulesPlugin",
38 (compilation, { normalModuleFactory }) => {
39 compilation.dependencyTemplates.set(
40 HarmonyCompatibilityDependency,
41 new HarmonyCompatibilityDependency.Template()
42 );
43
44 compilation.dependencyFactories.set(
45 HarmonyImportSideEffectDependency,
46 normalModuleFactory
47 );
48 compilation.dependencyTemplates.set(
49 HarmonyImportSideEffectDependency,
50 new HarmonyImportSideEffectDependency.Template()
51 );
52
53 compilation.dependencyFactories.set(
54 HarmonyImportSpecifierDependency,
55 normalModuleFactory
56 );
57 compilation.dependencyTemplates.set(
58 HarmonyImportSpecifierDependency,
59 new HarmonyImportSpecifierDependency.Template()
60 );
61
62 compilation.dependencyTemplates.set(
63 HarmonyExportHeaderDependency,
64 new HarmonyExportHeaderDependency.Template()
65 );
66
67 compilation.dependencyTemplates.set(
68 HarmonyExportExpressionDependency,
69 new HarmonyExportExpressionDependency.Template()
70 );
71
72 compilation.dependencyTemplates.set(
73 HarmonyExportSpecifierDependency,
74 new HarmonyExportSpecifierDependency.Template()
75 );
76
77 compilation.dependencyFactories.set(
78 HarmonyExportImportedSpecifierDependency,
79 normalModuleFactory
80 );
81 compilation.dependencyTemplates.set(
82 HarmonyExportImportedSpecifierDependency,
83 new HarmonyExportImportedSpecifierDependency.Template()
84 );
85
86 compilation.dependencyTemplates.set(
87 HarmonyAcceptDependency,
88 new HarmonyAcceptDependency.Template()
89 );
90
91 compilation.dependencyFactories.set(
92 HarmonyAcceptImportDependency,
93 normalModuleFactory
94 );
95 compilation.dependencyTemplates.set(
96 HarmonyAcceptImportDependency,
97 new HarmonyAcceptImportDependency.Template()
98 );
99
100 const handler = (parser, parserOptions) => {
101 // TODO webpack 6: rename harmony to esm or module
102 if (parserOptions.harmony !== undefined && !parserOptions.harmony)
103 return;
104
105 new HarmonyDetectionParserPlugin(this.options).apply(parser);
106 new HarmonyImportDependencyParserPlugin(parserOptions).apply(parser);
107 new HarmonyExportDependencyParserPlugin(parserOptions).apply(parser);
108 new HarmonyTopLevelThisParserPlugin().apply(parser);
109 };
110
111 normalModuleFactory.hooks.parser
112 .for("javascript/auto")
113 .tap("HarmonyModulesPlugin", handler);
114 normalModuleFactory.hooks.parser
115 .for("javascript/esm")
116 .tap("HarmonyModulesPlugin", handler);
117 }
118 );
119 }
120}
121module.exports = HarmonyModulesPlugin;
Note: See TracBrowser for help on using the repository browser.