summaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/css/CssGenerator.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2024-08-30 17:21:18 +0800
committerlittleblack111 <littleblack11111@gmail.com>2024-08-30 17:21:18 +0800
commitefbc2ffe6a1ee5ec38a4396305561d6515d0943e (patch)
tree2b4c94f18f2c792dfda813050755d5c0273fae22 /node_modules/webpack/lib/css/CssGenerator.js
parent43acceb75957c880a5ba5a31aae221394a36d5f6 (diff)
node fixes, updates
Diffstat (limited to 'node_modules/webpack/lib/css/CssGenerator.js')
-rw-r--r--node_modules/webpack/lib/css/CssGenerator.js151
1 files changed, 151 insertions, 0 deletions
diff --git a/node_modules/webpack/lib/css/CssGenerator.js b/node_modules/webpack/lib/css/CssGenerator.js
new file mode 100644
index 00000000..16f6ff16
--- /dev/null
+++ b/node_modules/webpack/lib/css/CssGenerator.js
@@ -0,0 +1,151 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Sergey Melyukov @smelukov
+*/
+
+"use strict";
+
+const { ReplaceSource } = require("webpack-sources");
+const Generator = require("../Generator");
+const InitFragment = require("../InitFragment");
+const RuntimeGlobals = require("../RuntimeGlobals");
+
+/** @typedef {import("webpack-sources").Source} Source */
+/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
+/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
+/** @typedef {import("../Dependency")} Dependency */
+/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
+/** @typedef {import("../DependencyTemplate").CssExportsData} CssExportsData */
+/** @typedef {import("../Generator").GenerateContext} GenerateContext */
+/** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
+/** @typedef {import("../NormalModule")} NormalModule */
+/** @typedef {import("../util/Hash")} Hash */
+
+const TYPES = new Set(["css"]);
+
+class CssGenerator extends Generator {
+ /**
+ * @param {CssGeneratorExportsConvention | undefined} convention the convention of the exports name
+ * @param {CssGeneratorLocalIdentName | undefined} localIdentName css export local ident name
+ * @param {boolean} esModule whether to use ES modules syntax
+ */
+ constructor(convention, localIdentName, esModule) {
+ super();
+ /** @type {CssGeneratorExportsConvention | undefined} */
+ this.convention = convention;
+ /** @type {CssGeneratorLocalIdentName | undefined} */
+ this.localIdentName = localIdentName;
+ /** @type {boolean} */
+ this.esModule = esModule;
+ }
+
+ /**
+ * @param {NormalModule} module module for which the code should be generated
+ * @param {GenerateContext} generateContext context for generate
+ * @returns {Source} generated code
+ */
+ generate(module, generateContext) {
+ const originalSource = /** @type {Source} */ (module.originalSource());
+ const source = new ReplaceSource(originalSource);
+ /** @type {InitFragment[]} */
+ const initFragments = [];
+ /** @type {CssExportsData} */
+ const cssExportsData = {
+ esModule: this.esModule,
+ exports: new Map()
+ };
+
+ generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
+
+ let chunkInitFragments;
+ /** @type {DependencyTemplateContext} */
+ const templateContext = {
+ runtimeTemplate: generateContext.runtimeTemplate,
+ dependencyTemplates: generateContext.dependencyTemplates,
+ moduleGraph: generateContext.moduleGraph,
+ chunkGraph: generateContext.chunkGraph,
+ module,
+ runtime: generateContext.runtime,
+ runtimeRequirements: generateContext.runtimeRequirements,
+ concatenationScope: generateContext.concatenationScope,
+ codeGenerationResults: generateContext.codeGenerationResults,
+ initFragments,
+ cssExportsData,
+ get chunkInitFragments() {
+ if (!chunkInitFragments) {
+ const data = generateContext.getData();
+ chunkInitFragments = data.get("chunkInitFragments");
+ if (!chunkInitFragments) {
+ chunkInitFragments = [];
+ data.set("chunkInitFragments", chunkInitFragments);
+ }
+ }
+
+ return chunkInitFragments;
+ }
+ };
+
+ /**
+ * @param {Dependency} dependency dependency
+ */
+ const handleDependency = dependency => {
+ const constructor = /** @type {new (...args: any[]) => Dependency} */ (
+ dependency.constructor
+ );
+ const template = generateContext.dependencyTemplates.get(constructor);
+ if (!template) {
+ throw new Error(
+ `No template for dependency: ${dependency.constructor.name}`
+ );
+ }
+
+ template.apply(dependency, source, templateContext);
+ };
+ for (const dependency of module.dependencies) {
+ handleDependency(dependency);
+ }
+ if (module.presentationalDependencies !== undefined) {
+ for (const dependency of module.presentationalDependencies) {
+ handleDependency(dependency);
+ }
+ }
+
+ const data = generateContext.getData();
+ data.set("css-exports", cssExportsData);
+
+ return InitFragment.addToSource(source, initFragments, generateContext);
+ }
+
+ /**
+ * @param {NormalModule} module fresh module
+ * @returns {Set<string>} available types (do not mutate)
+ */
+ getTypes(module) {
+ return TYPES;
+ }
+
+ /**
+ * @param {NormalModule} module the module
+ * @param {string=} type source type
+ * @returns {number} estimate size of the module
+ */
+ getSize(module, type) {
+ const originalSource = module.originalSource();
+
+ if (!originalSource) {
+ return 0;
+ }
+
+ return originalSource.size();
+ }
+
+ /**
+ * @param {Hash} hash hash that will be modified
+ * @param {UpdateHashContext} updateHashContext context for updating hash
+ */
+ updateHash(hash, { module }) {
+ hash.update(this.esModule.toString());
+ }
+}
+
+module.exports = CssGenerator;