feat: refactoring project
This commit is contained in:
78
node_modules/webpack/lib/css/CssExportsGenerator.js
generated
vendored
78
node_modules/webpack/lib/css/CssExportsGenerator.js
generated
vendored
@@ -8,18 +8,21 @@
|
||||
const { ReplaceSource, RawSource, ConcatSource } = require("webpack-sources");
|
||||
const { UsageState } = require("../ExportsInfo");
|
||||
const Generator = require("../Generator");
|
||||
const { JS_TYPES } = require("../ModuleSourceTypesConstants");
|
||||
const RuntimeGlobals = require("../RuntimeGlobals");
|
||||
const Template = require("../Template");
|
||||
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
|
||||
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
||||
/** @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("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
||||
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
||||
/** @typedef {import("../NormalModule")} NormalModule */
|
||||
/** @typedef {import("../util/Hash")} Hash */
|
||||
|
||||
@@ -28,19 +31,15 @@ const Template = require("../Template");
|
||||
* @typedef {import("../InitFragment")<T>} InitFragment
|
||||
*/
|
||||
|
||||
const TYPES = new Set(["javascript"]);
|
||||
|
||||
class CssExportsGenerator extends Generator {
|
||||
/**
|
||||
* @param {CssGeneratorExportsConvention | undefined} convention the convention of the exports name
|
||||
* @param {CssGeneratorLocalIdentName | undefined} localIdentName css export local ident name
|
||||
* @param {CssGeneratorExportsConvention} convention the convention of the exports name
|
||||
* @param {CssGeneratorLocalIdentName} 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;
|
||||
@@ -68,11 +67,11 @@ class CssExportsGenerator extends Generator {
|
||||
/**
|
||||
* @param {NormalModule} module module for which the code should be generated
|
||||
* @param {GenerateContext} generateContext context for generate
|
||||
* @returns {Source} generated code
|
||||
* @returns {Source | null} generated code
|
||||
*/
|
||||
generate(module, generateContext) {
|
||||
const source = new ReplaceSource(new RawSource(""));
|
||||
/** @type {InitFragment<TODO>[]} */
|
||||
/** @type {InitFragment<GenerateContext>[]} */
|
||||
const initFragments = [];
|
||||
/** @type {CssExportsData} */
|
||||
const cssExportsData = {
|
||||
@@ -82,6 +81,7 @@ class CssExportsGenerator extends Generator {
|
||||
|
||||
generateContext.runtimeRequirements.add(RuntimeGlobals.module);
|
||||
|
||||
/** @type {InitFragment<GenerateContext>[] | undefined} */
|
||||
let chunkInitFragments;
|
||||
const runtimeRequirements = new Set();
|
||||
|
||||
@@ -93,14 +93,18 @@ class CssExportsGenerator extends Generator {
|
||||
chunkGraph: generateContext.chunkGraph,
|
||||
module,
|
||||
runtime: generateContext.runtime,
|
||||
runtimeRequirements: runtimeRequirements,
|
||||
runtimeRequirements,
|
||||
concatenationScope: generateContext.concatenationScope,
|
||||
codeGenerationResults: generateContext.codeGenerationResults,
|
||||
codeGenerationResults:
|
||||
/** @type {CodeGenerationResults} */
|
||||
(generateContext.codeGenerationResults),
|
||||
initFragments,
|
||||
cssExportsData,
|
||||
get chunkInitFragments() {
|
||||
if (!chunkInitFragments) {
|
||||
const data = generateContext.getData();
|
||||
const data =
|
||||
/** @type {NonNullable<GenerateContext["getData"]>} */
|
||||
(generateContext.getData)();
|
||||
chunkInitFragments = data.get("chunkInitFragments");
|
||||
if (!chunkInitFragments) {
|
||||
chunkInitFragments = [];
|
||||
@@ -122,20 +126,23 @@ class CssExportsGenerator extends Generator {
|
||||
const template = generateContext.dependencyTemplates.get(constructor);
|
||||
if (!template) {
|
||||
throw new Error(
|
||||
"No template for dependency: " + dependency.constructor.name
|
||||
`No template for dependency: ${dependency.constructor.name}`
|
||||
);
|
||||
}
|
||||
|
||||
template.apply(dependency, source, templateContext);
|
||||
};
|
||||
module.dependencies.forEach(handleDependency);
|
||||
|
||||
for (const dependency of module.dependencies) {
|
||||
handleDependency(dependency);
|
||||
}
|
||||
|
||||
if (generateContext.concatenationScope) {
|
||||
const source = new ConcatSource();
|
||||
const usedIdentifiers = new Set();
|
||||
for (const [name, v] of cssExportsData.exports) {
|
||||
let identifier = Template.toIdentifier(name);
|
||||
let i = 0;
|
||||
const i = 0;
|
||||
while (usedIdentifiers.has(identifier)) {
|
||||
identifier = Template.toIdentifier(name + i);
|
||||
}
|
||||
@@ -148,36 +155,35 @@ class CssExportsGenerator extends Generator {
|
||||
);
|
||||
}
|
||||
return source;
|
||||
} else {
|
||||
const needNsObj =
|
||||
this.esModule &&
|
||||
generateContext.moduleGraph
|
||||
.getExportsInfo(module)
|
||||
.otherExportsInfo.getUsed(generateContext.runtime) !==
|
||||
UsageState.Unused;
|
||||
if (needNsObj) {
|
||||
generateContext.runtimeRequirements.add(
|
||||
RuntimeGlobals.makeNamespaceObject
|
||||
);
|
||||
}
|
||||
const exports = [];
|
||||
for (let [name, v] of cssExportsData.exports) {
|
||||
exports.push(`\t${JSON.stringify(name)}: ${JSON.stringify(v)}`);
|
||||
}
|
||||
return new RawSource(
|
||||
`${needNsObj ? `${RuntimeGlobals.makeNamespaceObject}(` : ""}${
|
||||
module.moduleArgument
|
||||
}.exports = {\n${exports.join(",\n")}\n}${needNsObj ? ")" : ""};`
|
||||
}
|
||||
const needNsObj =
|
||||
this.esModule &&
|
||||
generateContext.moduleGraph
|
||||
.getExportsInfo(module)
|
||||
.otherExportsInfo.getUsed(generateContext.runtime) !==
|
||||
UsageState.Unused;
|
||||
if (needNsObj) {
|
||||
generateContext.runtimeRequirements.add(
|
||||
RuntimeGlobals.makeNamespaceObject
|
||||
);
|
||||
}
|
||||
const exports = [];
|
||||
for (const [name, v] of cssExportsData.exports) {
|
||||
exports.push(`\t${JSON.stringify(name)}: ${JSON.stringify(v)}`);
|
||||
}
|
||||
return new RawSource(
|
||||
`${needNsObj ? `${RuntimeGlobals.makeNamespaceObject}(` : ""}${
|
||||
module.moduleArgument
|
||||
}.exports = {\n${exports.join(",\n")}\n}${needNsObj ? ")" : ""};`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {NormalModule} module fresh module
|
||||
* @returns {Set<string>} available types (do not mutate)
|
||||
* @returns {SourceTypes} available types (do not mutate)
|
||||
*/
|
||||
getTypes(module) {
|
||||
return TYPES;
|
||||
return JS_TYPES;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user