Fix code quality violations and enhance ROUTE-EXISTS-01 rule
Implement JQHTML function cache ID system and fix bundle compilation Implement underscore prefix for system tables Fix JS syntax linter to support decorators and grant exception to Task system SPA: Update planning docs and wishlists with remaining features SPA: Document Navigation API abandonment and future enhancements Implement SPA browser integration with History API (Phase 1) Convert contacts view page to SPA action Convert clients pages to SPA actions and document conversion procedure SPA: Merge GET parameters and update documentation Implement SPA route URL generation in JavaScript and PHP Implement SPA bootstrap controller architecture Add SPA routing manual page (rsx:man spa) Add SPA routing documentation to CLAUDE.md Phase 4 Complete: Client-side SPA routing implementation Update get_routes() consumers for unified route structure Complete SPA Phase 3: PHP-side route type detection and is_spa flag Restore unified routes structure and Manifest_Query class Refactor route indexing and add SPA infrastructure Phase 3 Complete: SPA route registration in manifest Implement SPA Phase 2: Extract router code and test decorators Rename Jqhtml_Component to Component and complete SPA foundation setup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
0
node_modules/webpack/lib/dependencies/AMDDefineDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDDefineDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDDefineDependencyParserPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDDefineDependencyParserPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDRequireArrayDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDRequireArrayDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDRequireContextDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDRequireContextDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDRequireDependenciesBlock.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDRequireDependenciesBlock.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDRequireDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDRequireDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDRequireItemDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDRequireItemDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDRuntimeModules.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/AMDRuntimeModules.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CachedConstDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CachedConstDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CommonJsDependencyHelpers.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CommonJsDependencyHelpers.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CommonJsExportRequireDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CommonJsExportRequireDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CommonJsExportsDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CommonJsExportsDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CommonJsExportsParserPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CommonJsExportsParserPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CommonJsFullRequireDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CommonJsFullRequireDependency.js
generated
vendored
Executable file → Normal file
9
node_modules/webpack/lib/dependencies/CommonJsImportsParserPlugin.js
generated
vendored
Executable file → Normal file
9
node_modules/webpack/lib/dependencies/CommonJsImportsParserPlugin.js
generated
vendored
Executable file → Normal file
@@ -126,15 +126,6 @@ class CommonJsImportsParserPlugin {
|
||||
});
|
||||
|
||||
// #region Unsupported
|
||||
parser.hooks.expression
|
||||
.for("require.main")
|
||||
.tap(
|
||||
PLUGIN_NAME,
|
||||
expressionIsUnsupported(
|
||||
parser,
|
||||
"require.main is not supported by webpack."
|
||||
)
|
||||
);
|
||||
parser.hooks.call
|
||||
.for("require.main.require")
|
||||
.tap(
|
||||
|
||||
12
node_modules/webpack/lib/dependencies/CommonJsPlugin.js
generated
vendored
Executable file → Normal file
12
node_modules/webpack/lib/dependencies/CommonJsPlugin.js
generated
vendored
Executable file → Normal file
@@ -15,6 +15,7 @@ const SelfModuleFactory = require("../SelfModuleFactory");
|
||||
const Template = require("../Template");
|
||||
const {
|
||||
evaluateToIdentifier,
|
||||
expressionIsUnsupported,
|
||||
toConstantDependency
|
||||
} = require("../javascript/JavascriptParserHelpers");
|
||||
const CommonJsExportRequireDependency = require("./CommonJsExportRequireDependency");
|
||||
@@ -198,6 +199,17 @@ class CommonJsPlugin {
|
||||
[RuntimeGlobals.moduleCache, RuntimeGlobals.entryModuleId]
|
||||
)
|
||||
);
|
||||
|
||||
parser.hooks.expression
|
||||
.for("require.extensions")
|
||||
.tap(
|
||||
PLUGIN_NAME,
|
||||
expressionIsUnsupported(
|
||||
parser,
|
||||
"require.extensions is not supported by webpack. Use a loader instead."
|
||||
)
|
||||
);
|
||||
|
||||
parser.hooks.expression
|
||||
.for(RuntimeGlobals.moduleLoaded)
|
||||
.tap(PLUGIN_NAME, (expr) => {
|
||||
|
||||
0
node_modules/webpack/lib/dependencies/CommonJsRequireContextDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CommonJsRequireContextDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CommonJsRequireDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CommonJsRequireDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CommonJsSelfReferenceDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CommonJsSelfReferenceDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ConstDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ConstDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ContextDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ContextDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ContextDependencyHelpers.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ContextDependencyHelpers.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ContextDependencyTemplateAsId.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ContextDependencyTemplateAsId.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ContextDependencyTemplateAsRequireCall.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ContextDependencyTemplateAsRequireCall.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ContextElementDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ContextElementDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CreateScriptUrlDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CreateScriptUrlDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CriticalDependencyWarning.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CriticalDependencyWarning.js
generated
vendored
Executable file → Normal file
255
node_modules/webpack/lib/dependencies/CssIcssExportDependency.js
generated
vendored
Executable file → Normal file
255
node_modules/webpack/lib/dependencies/CssIcssExportDependency.js
generated
vendored
Executable file → Normal file
@@ -6,11 +6,18 @@
|
||||
"use strict";
|
||||
|
||||
const { cssExportConvention } = require("../util/conventions");
|
||||
const createHash = require("../util/createHash");
|
||||
const { makePathsRelative } = require("../util/identifier");
|
||||
const makeSerializable = require("../util/makeSerializable");
|
||||
const memoize = require("../util/memoize");
|
||||
const CssIcssImportDependency = require("./CssIcssImportDependency");
|
||||
const NullDependency = require("./NullDependency");
|
||||
|
||||
const getCssParser = memoize(() => require("../css/CssParser"));
|
||||
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
|
||||
/** @typedef {import("../CssModule")} CssModule */
|
||||
/** @typedef {import("../Dependency")} Dependency */
|
||||
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
||||
@@ -21,16 +28,82 @@ const NullDependency = require("./NullDependency");
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
||||
/** @typedef {import("../util/Hash")} Hash */
|
||||
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
||||
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
||||
/** @typedef {import("../css/CssParser").Range} Range */
|
||||
|
||||
/**
|
||||
* @param {string} local css local
|
||||
* @param {CssModule} module module
|
||||
* @param {ChunkGraph} chunkGraph chunk graph
|
||||
* @param {RuntimeTemplate} runtimeTemplate runtime template
|
||||
* @returns {string} local ident
|
||||
*/
|
||||
const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
|
||||
const generator = /** @type {CssGenerator} */ (module.generator);
|
||||
const localIdentName =
|
||||
/** @type {CssGeneratorLocalIdentName} */
|
||||
(generator.localIdentName);
|
||||
const relativeResourcePath = makePathsRelative(
|
||||
/** @type {string} */
|
||||
(module.context),
|
||||
/** @type {string} */
|
||||
(module.getResource()),
|
||||
runtimeTemplate.compilation.compiler.root
|
||||
);
|
||||
const { hashFunction, hashDigest, hashDigestLength, hashSalt, uniqueName } =
|
||||
runtimeTemplate.outputOptions;
|
||||
const hash = createHash(hashFunction);
|
||||
|
||||
if (hashSalt) {
|
||||
hash.update(hashSalt);
|
||||
}
|
||||
|
||||
hash.update(relativeResourcePath);
|
||||
|
||||
if (!/\[local\]/.test(localIdentName)) {
|
||||
hash.update(local);
|
||||
}
|
||||
|
||||
const localIdentHash = hash.digest(hashDigest).slice(0, hashDigestLength);
|
||||
|
||||
return runtimeTemplate.compilation
|
||||
.getPath(localIdentName, {
|
||||
filename: relativeResourcePath,
|
||||
hash: localIdentHash,
|
||||
contentHash: localIdentHash,
|
||||
chunkGraph,
|
||||
module
|
||||
})
|
||||
.replace(/\[local\]/g, local)
|
||||
.replace(/\[uniqueName\]/g, /** @type {string} */ (uniqueName))
|
||||
.replace(/^((-?[0-9])|--)/, "_$1");
|
||||
};
|
||||
// 0 - replace, 1 - append, 2 - once
|
||||
/** @typedef {0 | 1 | 2} ExportMode */
|
||||
// 0 - none, 1 - name, 1 - value
|
||||
/** @typedef {0 | 1 | 2} InterpolationMode */
|
||||
|
||||
class CssIcssExportDependency extends NullDependency {
|
||||
/**
|
||||
* @param {string} name name
|
||||
* @param {string} value value
|
||||
* Example of dependency:
|
||||
*
|
||||
* :export { LOCAL_NAME: EXPORT_NAME }
|
||||
* @param {string} name export name
|
||||
* @param {string} value export value or true when we need interpolate name as a value
|
||||
* @param {string=} reexport reexport name
|
||||
* @param {Range=} range range
|
||||
*/
|
||||
constructor(name, value) {
|
||||
constructor(name, value, reexport, range) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.reexport = reexport;
|
||||
this.range = range;
|
||||
/** @type {undefined | InterpolationMode} */
|
||||
this.interpolationMode = undefined;
|
||||
/** @type {ExportMode} */
|
||||
this.exportMode = CssIcssExportDependency.EXPORT_MODE.REPLACE;
|
||||
this._hashUpdate = undefined;
|
||||
}
|
||||
|
||||
@@ -90,9 +163,8 @@ class CssIcssExportDependency extends NullDependency {
|
||||
/** @type {CssGeneratorExportsConvention} */
|
||||
(generator.convention)
|
||||
);
|
||||
this._hashUpdate = JSON.stringify(names);
|
||||
this._hashUpdate = `exportsConvention|${JSON.stringify(names)}|localIdentName|${JSON.stringify(generator.localIdentName)}`;
|
||||
}
|
||||
hash.update("exportsConvention");
|
||||
hash.update(this._hashUpdate);
|
||||
}
|
||||
|
||||
@@ -103,6 +175,10 @@ class CssIcssExportDependency extends NullDependency {
|
||||
const { write } = context;
|
||||
write(this.name);
|
||||
write(this.value);
|
||||
write(this.reexport);
|
||||
write(this.range);
|
||||
write(this.interpolationMode);
|
||||
write(this.exportMode);
|
||||
super.serialize(context);
|
||||
}
|
||||
|
||||
@@ -113,6 +189,10 @@ class CssIcssExportDependency extends NullDependency {
|
||||
const { read } = context;
|
||||
this.name = read();
|
||||
this.value = read();
|
||||
this.reexport = read();
|
||||
this.range = read();
|
||||
this.interpolationMode = read();
|
||||
this.exportMode = read();
|
||||
super.deserialize(context);
|
||||
}
|
||||
}
|
||||
@@ -120,14 +200,111 @@ class CssIcssExportDependency extends NullDependency {
|
||||
CssIcssExportDependency.Template = class CssIcssExportDependencyTemplate extends (
|
||||
NullDependency.Template
|
||||
) {
|
||||
// TODO looking how to cache
|
||||
/**
|
||||
* @param {string} symbol the name of symbol
|
||||
* @param {DependencyTemplateContext} templateContext the context object
|
||||
* @returns {string | undefined} found reference
|
||||
*/
|
||||
static findReference(symbol, templateContext) {
|
||||
for (const item of templateContext.module.dependencies) {
|
||||
if (item instanceof CssIcssImportDependency) {
|
||||
// Looking for the referring module
|
||||
const module = templateContext.moduleGraph.getModule(item);
|
||||
|
||||
if (!module) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
for (let i = module.dependencies.length - 1; i >= 0; i--) {
|
||||
const nestedDep = module.dependencies[i];
|
||||
if (
|
||||
nestedDep instanceof CssIcssExportDependency &&
|
||||
symbol === nestedDep.name
|
||||
) {
|
||||
if (nestedDep.reexport) {
|
||||
return this.findReference(nestedDep.reexport, {
|
||||
...templateContext,
|
||||
module
|
||||
});
|
||||
}
|
||||
|
||||
return CssIcssExportDependency.Template.getIdentifier(nestedDep, {
|
||||
...templateContext,
|
||||
module
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Dependency} dependency the dependency for which the template should be applied
|
||||
* @param {DependencyTemplateContext} templateContext the context object
|
||||
* @returns {string} identifier
|
||||
*/
|
||||
static getIdentifier(dependency, templateContext) {
|
||||
const dep = /** @type {CssIcssExportDependency} */ (dependency);
|
||||
|
||||
if (
|
||||
dep.interpolationMode ===
|
||||
CssIcssExportDependency.INTERPOLATION_MODE.NAME ||
|
||||
dep.interpolationMode === CssIcssExportDependency.INTERPOLATION_MODE.VALUE
|
||||
) {
|
||||
const { module: m, moduleGraph, runtime } = templateContext;
|
||||
const module = /** @type {CssModule} */ (m);
|
||||
const generator = /** @type {CssGenerator} */ (module.generator);
|
||||
const names = dep.getExportsConventionNames(
|
||||
dep.interpolationMode ===
|
||||
CssIcssExportDependency.INTERPOLATION_MODE.NAME
|
||||
? dep.name
|
||||
: dep.value,
|
||||
/** @type {CssGeneratorExportsConvention} */
|
||||
(generator.convention)
|
||||
);
|
||||
const usedNames =
|
||||
/** @type {string[]} */
|
||||
(
|
||||
names
|
||||
.map((name) =>
|
||||
moduleGraph.getExportInfo(module, name).getUsedName(name, runtime)
|
||||
)
|
||||
.filter(Boolean)
|
||||
);
|
||||
const local = usedNames.length === 0 ? names[0] : usedNames[0];
|
||||
const prefix =
|
||||
/** @type {CssIcssExportDependency & { prefix: string }} */
|
||||
(dependency).prefix;
|
||||
|
||||
return (
|
||||
(prefix || "") +
|
||||
getCssParser().escapeIdentifier(
|
||||
getLocalIdent(
|
||||
local,
|
||||
/** @type {CssModule} */
|
||||
(templateContext.module),
|
||||
templateContext.chunkGraph,
|
||||
templateContext.runtimeTemplate
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return /** @type {string} */ (dep.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Dependency} dependency the dependency for which the template should be applied
|
||||
* @param {ReplaceSource} source the current replace source which can be modified
|
||||
* @param {DependencyTemplateContext} templateContext the context object
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(dependency, source, { cssData, module: m, runtime, moduleGraph }) {
|
||||
apply(dependency, source, templateContext) {
|
||||
const dep = /** @type {CssIcssExportDependency} */ (dependency);
|
||||
if (!dep.range && templateContext.type !== "javascript") return;
|
||||
const { cssData } = templateContext;
|
||||
const { module: m, moduleGraph, runtime } = templateContext;
|
||||
const module = /** @type {CssModule} */ (m);
|
||||
const generator = /** @type {CssGenerator} */ (module.generator);
|
||||
const names = dep.getExportsConventionNames(
|
||||
@@ -145,12 +322,74 @@ CssIcssExportDependency.Template = class CssIcssExportDependencyTemplate extends
|
||||
.filter(Boolean)
|
||||
);
|
||||
|
||||
for (const used of [...usedNames, ...names]) {
|
||||
cssData.exports.set(used, dep.value);
|
||||
const allNames = new Set([...usedNames, ...names]);
|
||||
|
||||
/** @type {string} */
|
||||
let value;
|
||||
|
||||
if (dep.reexport) {
|
||||
const resolved = CssIcssExportDependencyTemplate.findReference(
|
||||
dep.reexport,
|
||||
templateContext
|
||||
);
|
||||
|
||||
if (resolved) {
|
||||
dep.value = resolved;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof dep.interpolationMode !== "undefined") {
|
||||
value = CssIcssExportDependencyTemplate.getIdentifier(
|
||||
dep,
|
||||
templateContext
|
||||
);
|
||||
} else {
|
||||
value = dep.value;
|
||||
}
|
||||
|
||||
if (templateContext.type === "javascript") {
|
||||
for (const used of allNames) {
|
||||
if (dep.exportMode === 2) {
|
||||
if (cssData.exports.has(used)) return;
|
||||
cssData.exports.set(
|
||||
used,
|
||||
`${getCssParser().unescapeIdentifier(value)}`
|
||||
);
|
||||
} else {
|
||||
const originalValue =
|
||||
dep.exportMode === 0 ? undefined : cssData.exports.get(used);
|
||||
const newValue = getCssParser().unescapeIdentifier(value);
|
||||
|
||||
cssData.exports.set(
|
||||
used,
|
||||
`${originalValue ? `${originalValue}${newValue ? " " : ""}` : ""}${newValue}`
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
dep.range &&
|
||||
templateContext.type === "css" &&
|
||||
dep.exportMode !== 1
|
||||
) {
|
||||
source.replace(dep.range[0], dep.range[1] - 1, value);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** @type {Record<"REPLACE" | "APPEND" | "ONCE", ExportMode>} */
|
||||
CssIcssExportDependency.EXPORT_MODE = {
|
||||
REPLACE: 0,
|
||||
APPEND: 1,
|
||||
ONCE: 2
|
||||
};
|
||||
|
||||
/** @type {Record<"NONE" | "NAME" | "VALUE", InterpolationMode>} */
|
||||
CssIcssExportDependency.INTERPOLATION_MODE = {
|
||||
NONE: 0,
|
||||
NAME: 1,
|
||||
VALUE: 2
|
||||
};
|
||||
|
||||
makeSerializable(
|
||||
CssIcssExportDependency,
|
||||
"webpack/lib/dependencies/CssIcssExportDependency"
|
||||
|
||||
124
node_modules/webpack/lib/dependencies/CssIcssFromIdentifierDependency.js
generated
vendored
Normal file
124
node_modules/webpack/lib/dependencies/CssIcssFromIdentifierDependency.js
generated
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Alexander Akait @alexander-akait
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { cssExportConvention } = require("../util/conventions");
|
||||
const makeSerializable = require("../util/makeSerializable");
|
||||
const CssIcssExportDependency = require("./CssIcssExportDependency");
|
||||
const CssIcssImportDependency = require("./CssIcssImportDependency");
|
||||
const ModuleDependency = require("./ModuleDependency");
|
||||
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
/** @typedef {import("../Dependency")} Dependency */
|
||||
/** @typedef {import("../Dependency").ReferencedExports} ReferencedExports */
|
||||
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
||||
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
||||
/** @typedef {import("../Module")} Module */
|
||||
/** @typedef {import("../CssModule")} CssModule */
|
||||
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
||||
/** @typedef {import("../css/CssGenerator")} CssGenerator */
|
||||
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
||||
|
||||
class CssIcssFromIdentifierDependency extends CssIcssImportDependency {
|
||||
/**
|
||||
* @param {string} request request request path which needs resolving
|
||||
* @param {"local" | "global"} mode mode of the parsed CSS
|
||||
* @param {Range} range the range of dependency
|
||||
* @param {string} name import class name
|
||||
* @param {string} exportName export class name
|
||||
* @param {string=} prefix prefix
|
||||
*/
|
||||
constructor(request, mode, range, name, exportName, prefix) {
|
||||
super(request, range, mode, name);
|
||||
this.exportName = exportName;
|
||||
this.value = name;
|
||||
this.prefix = prefix;
|
||||
this.interpolationMode = CssIcssExportDependency.INTERPOLATION_MODE.VALUE;
|
||||
this.exportMode = CssIcssExportDependency.EXPORT_MODE.APPEND;
|
||||
}
|
||||
|
||||
get type() {
|
||||
return "css from identifier";
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string | null} an identifier to merge equal requests
|
||||
*/
|
||||
getResourceIdentifier() {
|
||||
return `${super.getResourceIdentifier()}|exportName${this.exportName}|prefix${this.prefix}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name export name
|
||||
* @param {CssGeneratorExportsConvention} convention convention of the export name
|
||||
* @returns {string[]} convention results
|
||||
*/
|
||||
getExportsConventionNames(name, convention) {
|
||||
return cssExportConvention(name, convention);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectSerializerContext} context context
|
||||
*/
|
||||
serialize(context) {
|
||||
const { write } = context;
|
||||
write(this.exportName);
|
||||
write(this.prefix);
|
||||
write(this.interpolationMode);
|
||||
write(this.exportMode);
|
||||
super.serialize(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectDeserializerContext} context context
|
||||
*/
|
||||
deserialize(context) {
|
||||
const { read } = context;
|
||||
this.exportName = read();
|
||||
this.prefix = read();
|
||||
this.interpolationMode = read();
|
||||
this.exportMode = read();
|
||||
super.deserialize(context);
|
||||
}
|
||||
}
|
||||
|
||||
CssIcssFromIdentifierDependency.Template = class CssIcssFromIdentifierDependencyTemplate extends (
|
||||
ModuleDependency.Template
|
||||
) {
|
||||
/**
|
||||
* @param {Dependency} dependency the dependency for which the template should be applied
|
||||
* @param {ReplaceSource} source the current replace source which can be modified
|
||||
* @param {DependencyTemplateContext} templateContext the context object
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(dependency, source, templateContext) {
|
||||
const { moduleGraph } = templateContext;
|
||||
const dep = /** @type {CssIcssFromIdentifierDependency} */ (dependency);
|
||||
const module =
|
||||
/** @type {CssModule} */
|
||||
(moduleGraph.getModule(dep));
|
||||
|
||||
if (!moduleGraph.getExportsInfo(module).isExportProvided(dep.name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const template = new CssIcssExportDependency.Template();
|
||||
const originalName = dep.name;
|
||||
dep.name = dep.exportName;
|
||||
template.apply(dep, source, { ...templateContext, module });
|
||||
dep.name = originalName;
|
||||
}
|
||||
};
|
||||
|
||||
makeSerializable(
|
||||
CssIcssFromIdentifierDependency,
|
||||
"webpack/lib/dependencies/CssIcssFromIdentifierDependency"
|
||||
);
|
||||
|
||||
module.exports = CssIcssFromIdentifierDependency;
|
||||
48
node_modules/webpack/lib/dependencies/CssIcssGlobalIdentifierDependency.js
generated
vendored
Normal file
48
node_modules/webpack/lib/dependencies/CssIcssGlobalIdentifierDependency.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Alexander Akait @alexander-akait
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const makeSerializable = require("../util/makeSerializable");
|
||||
const CssIcssExportDependency = require("./CssIcssExportDependency");
|
||||
|
||||
/** @typedef {import("../css/CssParser").Range} Range */
|
||||
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
||||
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
||||
|
||||
class CssIcssGlobalIdentifierDependency extends CssIcssExportDependency {
|
||||
/**
|
||||
* @param {string} name export identifier name
|
||||
* @param {string} value identifier value
|
||||
* @param {string | undefined} reexport reexport name
|
||||
* @param {Range} range the range of dependency
|
||||
*/
|
||||
constructor(name, value, reexport, range) {
|
||||
super(name, value, reexport, range);
|
||||
this.exportMode = CssIcssExportDependency.EXPORT_MODE.APPEND;
|
||||
}
|
||||
|
||||
get type() {
|
||||
return "css global identifier";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exported names
|
||||
* @param {ModuleGraph} moduleGraph module graph
|
||||
* @returns {ExportsSpec | undefined} export names
|
||||
*/
|
||||
getExports(moduleGraph) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
CssIcssGlobalIdentifierDependency.Template = CssIcssExportDependency.Template;
|
||||
|
||||
makeSerializable(
|
||||
CssIcssGlobalIdentifierDependency,
|
||||
"webpack/lib/dependencies/CssIcssGlobalDependency"
|
||||
);
|
||||
|
||||
module.exports = CssIcssGlobalIdentifierDependency;
|
||||
114
node_modules/webpack/lib/dependencies/CssIcssImportDependency.js
generated
vendored
Executable file → Normal file
114
node_modules/webpack/lib/dependencies/CssIcssImportDependency.js
generated
vendored
Executable file → Normal file
@@ -5,40 +5,84 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("../WebpackError");
|
||||
const makeSerializable = require("../util/makeSerializable");
|
||||
const CssIcssExportDependency = require("./CssIcssExportDependency");
|
||||
const CssLocalIdentifierDependency = require("./CssLocalIdentifierDependency");
|
||||
const ModuleDependency = require("./ModuleDependency");
|
||||
const CssImportDependency = require("./CssImportDependency");
|
||||
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
/** @typedef {import("../Dependency")} Dependency */
|
||||
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
||||
/** @typedef {import("../Module")} Module */
|
||||
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
||||
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
||||
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
||||
/** @typedef {import("../Dependency").ReferencedExports} ReferencedExports */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
||||
|
||||
class CssIcssImportDependency extends ModuleDependency {
|
||||
class CssIcssImportDependency extends CssImportDependency {
|
||||
/**
|
||||
* Example of dependency:
|
||||
*
|
||||
*:import('./style.css') { IMPORTED_NAME: v-primary }
|
||||
* :import('./style.css') { IMPORTED_NAME: v-primary }
|
||||
* @param {string} request request request path which needs resolving
|
||||
* @param {string} exportName export name
|
||||
* @param {Range} range the range of dependency
|
||||
* @param {"local" | "global"} mode mode of the parsed CSS
|
||||
* @param {string} name importName name
|
||||
*/
|
||||
constructor(request, exportName, range) {
|
||||
super(request);
|
||||
this.exportName = exportName;
|
||||
this.range = range;
|
||||
constructor(request, range, mode, name) {
|
||||
super(request, range, mode);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
get type() {
|
||||
return "css :import";
|
||||
}
|
||||
|
||||
get category() {
|
||||
return "css-import";
|
||||
/**
|
||||
* @returns {string | null} an identifier to merge equal requests
|
||||
*/
|
||||
getResourceIdentifier() {
|
||||
return `${super.getResourceIdentifier()}|mode${this.mode}|name${this.name}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of exports referenced by this dependency
|
||||
* @param {ModuleGraph} moduleGraph module graph
|
||||
* @param {RuntimeSpec} runtime the runtime for which the module is analysed
|
||||
* @returns {ReferencedExports} referenced exports
|
||||
*/
|
||||
getReferencedExports(moduleGraph, runtime) {
|
||||
return [
|
||||
{
|
||||
name: [this.name],
|
||||
canMangle: true
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns warnings
|
||||
* @param {ModuleGraph} moduleGraph module graph
|
||||
* @returns {WebpackError[] | null | undefined} warnings
|
||||
*/
|
||||
getWarnings(moduleGraph) {
|
||||
const module = moduleGraph.getModule(this);
|
||||
|
||||
if (
|
||||
module &&
|
||||
!moduleGraph.getExportsInfo(module).isExportProvided(this.name)
|
||||
) {
|
||||
const error = new WebpackError(
|
||||
`Referenced name "${this.name}" in "${this.userRequest}" not found`
|
||||
);
|
||||
error.module = module;
|
||||
|
||||
return [error];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,8 +90,7 @@ class CssIcssImportDependency extends ModuleDependency {
|
||||
*/
|
||||
serialize(context) {
|
||||
const { write } = context;
|
||||
write(this.range);
|
||||
write(this.exportName);
|
||||
write(this.name);
|
||||
super.serialize(context);
|
||||
}
|
||||
|
||||
@@ -56,14 +99,13 @@ class CssIcssImportDependency extends ModuleDependency {
|
||||
*/
|
||||
deserialize(context) {
|
||||
const { read } = context;
|
||||
this.range = read();
|
||||
this.exportName = read();
|
||||
this.name = read();
|
||||
super.deserialize(context);
|
||||
}
|
||||
}
|
||||
|
||||
CssIcssImportDependency.Template = class CssIcssImportDependencyTemplate extends (
|
||||
ModuleDependency.Template
|
||||
CssImportDependency.Template
|
||||
) {
|
||||
/**
|
||||
* @param {Dependency} dependency the dependency for which the template should be applied
|
||||
@@ -72,43 +114,7 @@ CssIcssImportDependency.Template = class CssIcssImportDependencyTemplate extends
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(dependency, source, templateContext) {
|
||||
const dep = /** @type {CssIcssImportDependency} */ (dependency);
|
||||
const { range } = dep;
|
||||
const module =
|
||||
/** @type {Module} */
|
||||
(templateContext.moduleGraph.getModule(dep));
|
||||
let value;
|
||||
|
||||
for (const item of module.dependencies) {
|
||||
if (
|
||||
item instanceof CssLocalIdentifierDependency &&
|
||||
dep.exportName === item.name
|
||||
) {
|
||||
value = CssLocalIdentifierDependency.Template.getIdentifier(
|
||||
item,
|
||||
dep.exportName,
|
||||
{
|
||||
...templateContext,
|
||||
module
|
||||
}
|
||||
);
|
||||
break;
|
||||
} else if (
|
||||
item instanceof CssIcssExportDependency &&
|
||||
dep.exportName === item.name
|
||||
) {
|
||||
value = item.value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
throw new Error(
|
||||
`Imported '${dep.exportName}' name from '${dep.request}' not found`
|
||||
);
|
||||
}
|
||||
|
||||
source.replace(range[0], range[1], value);
|
||||
// We remove everything in CSS parser
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
61
node_modules/webpack/lib/dependencies/CssIcssLocalIdentifierDependency.js
generated
vendored
Normal file
61
node_modules/webpack/lib/dependencies/CssIcssLocalIdentifierDependency.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Ivan Kopeykin @vankop
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const makeSerializable = require("../util/makeSerializable");
|
||||
const CssIcssExportDependency = require("./CssIcssExportDependency");
|
||||
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
/** @typedef {import("../Dependency")} Dependency */
|
||||
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
||||
/** @typedef {import("../css/CssParser").Range} Range */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
||||
|
||||
class CssIcssLocalIdentifierDependency extends CssIcssExportDependency {
|
||||
/**
|
||||
* @param {string} name name
|
||||
* @param {Range} range range
|
||||
* @param {string=} prefix prefix
|
||||
*/
|
||||
constructor(name, range, prefix = "") {
|
||||
super(name, name, undefined, range);
|
||||
this.prefix = prefix;
|
||||
this.interpolationMode = CssIcssExportDependency.INTERPOLATION_MODE.VALUE;
|
||||
this.exportMode = CssIcssExportDependency.EXPORT_MODE.ONCE;
|
||||
}
|
||||
|
||||
get type() {
|
||||
return "css local identifier";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectSerializerContext} context context
|
||||
*/
|
||||
serialize(context) {
|
||||
const { write } = context;
|
||||
write(this.prefix);
|
||||
super.serialize(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectDeserializerContext} context context
|
||||
*/
|
||||
deserialize(context) {
|
||||
const { read } = context;
|
||||
this.prefix = read();
|
||||
super.deserialize(context);
|
||||
}
|
||||
}
|
||||
|
||||
CssIcssLocalIdentifierDependency.Template = CssIcssExportDependency.Template;
|
||||
|
||||
makeSerializable(
|
||||
CssIcssLocalIdentifierDependency,
|
||||
"webpack/lib/dependencies/CssLocalIdentifierDependency"
|
||||
);
|
||||
|
||||
module.exports = CssIcssLocalIdentifierDependency;
|
||||
98
node_modules/webpack/lib/dependencies/CssSelfLocalIdentifierDependency.js → node_modules/webpack/lib/dependencies/CssIcssSelfLocalIdentifierDependency.js
generated
vendored
Executable file → Normal file
98
node_modules/webpack/lib/dependencies/CssSelfLocalIdentifierDependency.js → node_modules/webpack/lib/dependencies/CssIcssSelfLocalIdentifierDependency.js
generated
vendored
Executable file → Normal file
@@ -6,9 +6,12 @@
|
||||
"use strict";
|
||||
|
||||
const Dependency = require("../Dependency");
|
||||
const WebpackError = require("../WebpackError");
|
||||
const makeSerializable = require("../util/makeSerializable");
|
||||
const CssLocalIdentifierDependency = require("./CssLocalIdentifierDependency");
|
||||
const CssIcssExportDependency = require("./CssIcssExportDependency");
|
||||
const CssLocalIdentifierDependency = require("./CssIcssLocalIdentifierDependency");
|
||||
|
||||
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
||||
/** @typedef {import("../Dependency").ReferencedExports} ReferencedExports */
|
||||
@@ -18,17 +21,36 @@ const CssLocalIdentifierDependency = require("./CssLocalIdentifierDependency");
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
||||
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
||||
/** @typedef {import("../CssModule")} CssModule */
|
||||
/** @typedef {import("../css/CssGenerator")} CssGenerator */
|
||||
|
||||
class CssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
|
||||
class CssIcssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
|
||||
/**
|
||||
* @param {string} name name
|
||||
* @param {string | undefined} referencedExport referenced export name
|
||||
* @param {Range} range range
|
||||
* @param {string=} prefix prefix
|
||||
* @param {Set<string>=} declaredSet set of declared names (will only be active when in declared set)
|
||||
* @param {string=} reexport reexport name
|
||||
*/
|
||||
constructor(name, range, prefix = "", declaredSet = undefined) {
|
||||
constructor(
|
||||
name,
|
||||
referencedExport,
|
||||
range,
|
||||
prefix = "",
|
||||
declaredSet = undefined,
|
||||
reexport = undefined
|
||||
) {
|
||||
super(name, range, prefix);
|
||||
this.declaredSet = declaredSet;
|
||||
this.referencedExport = referencedExport;
|
||||
this.reexport = reexport;
|
||||
this.interpolationMode = referencedExport
|
||||
? CssIcssExportDependency.INTERPOLATION_MODE.NONE
|
||||
: CssIcssExportDependency.INTERPOLATION_MODE.VALUE;
|
||||
this.exportMode = referencedExport
|
||||
? CssIcssExportDependency.EXPORT_MODE.APPEND
|
||||
: CssIcssExportDependency.EXPORT_MODE.ONCE;
|
||||
}
|
||||
|
||||
get type() {
|
||||
@@ -52,7 +74,12 @@ class CssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
|
||||
* @returns {ExportsSpec | undefined} export names
|
||||
*/
|
||||
getExports(moduleGraph) {
|
||||
if (this.declaredSet && !this.declaredSet.has(this.name)) return;
|
||||
if (
|
||||
(this.declaredSet && !this.declaredSet.has(this.name)) ||
|
||||
this.referencedExport
|
||||
) {
|
||||
return;
|
||||
}
|
||||
return super.getExports(moduleGraph);
|
||||
}
|
||||
|
||||
@@ -66,7 +93,39 @@ class CssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
|
||||
if (this.declaredSet && !this.declaredSet.has(this.name)) {
|
||||
return Dependency.NO_EXPORTS_REFERENCED;
|
||||
}
|
||||
return [[this.name]];
|
||||
return [
|
||||
{
|
||||
name: [this.referencedExport || this.name],
|
||||
canMangle: true
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns warnings
|
||||
* @param {ModuleGraph} moduleGraph module graph
|
||||
* @returns {WebpackError[] | null | undefined} warnings
|
||||
*/
|
||||
getWarnings(moduleGraph) {
|
||||
if (this.referencedExport && !this.reexport) {
|
||||
const module = moduleGraph.getModule(this);
|
||||
|
||||
if (
|
||||
module &&
|
||||
!moduleGraph
|
||||
.getExportsInfo(module)
|
||||
.isExportProvided(this.referencedExport)
|
||||
) {
|
||||
const error = new WebpackError(
|
||||
`Self-referencing name "${this.referencedExport}" not found`
|
||||
);
|
||||
error.module = module;
|
||||
|
||||
return [error];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,6 +134,7 @@ class CssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
|
||||
serialize(context) {
|
||||
const { write } = context;
|
||||
write(this.declaredSet);
|
||||
write(this.referencedExport);
|
||||
super.serialize(context);
|
||||
}
|
||||
|
||||
@@ -84,11 +144,12 @@ class CssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
|
||||
deserialize(context) {
|
||||
const { read } = context;
|
||||
this.declaredSet = read();
|
||||
this.referencedExport = read();
|
||||
super.deserialize(context);
|
||||
}
|
||||
}
|
||||
|
||||
CssSelfLocalIdentifierDependency.Template = class CssSelfLocalIdentifierDependencyTemplate extends (
|
||||
CssIcssSelfLocalIdentifierDependency.Template = class CssSelfLocalIdentifierDependencyTemplate extends (
|
||||
CssLocalIdentifierDependency.Template
|
||||
) {
|
||||
/**
|
||||
@@ -98,15 +159,32 @@ CssSelfLocalIdentifierDependency.Template = class CssSelfLocalIdentifierDependen
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(dependency, source, templateContext) {
|
||||
const dep = /** @type {CssSelfLocalIdentifierDependency} */ (dependency);
|
||||
const dep =
|
||||
/** @type {CssIcssSelfLocalIdentifierDependency} */
|
||||
(dependency);
|
||||
if (dep.declaredSet && !dep.declaredSet.has(dep.name)) return;
|
||||
if (dep.referencedExport) {
|
||||
const { module: m, moduleGraph, cssData } = templateContext;
|
||||
const module = /** @type {CssModule} */ (m);
|
||||
|
||||
if (
|
||||
!dep.reexport &&
|
||||
!moduleGraph
|
||||
.getExportsInfo(module)
|
||||
.isExportProvided(dep.referencedExport)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
dep.value = cssData.exports.get(dep.referencedExport) || "";
|
||||
}
|
||||
super.apply(dependency, source, templateContext);
|
||||
}
|
||||
};
|
||||
|
||||
makeSerializable(
|
||||
CssSelfLocalIdentifierDependency,
|
||||
"webpack/lib/dependencies/CssSelfLocalIdentifierDependency"
|
||||
CssIcssSelfLocalIdentifierDependency,
|
||||
"webpack/lib/dependencies/CssIcssSelfLocalIdentifierDependency"
|
||||
);
|
||||
|
||||
module.exports = CssSelfLocalIdentifierDependency;
|
||||
module.exports = CssIcssSelfLocalIdentifierDependency;
|
||||
56
node_modules/webpack/lib/dependencies/CssIcssSymbolDependency.js
generated
vendored
Executable file → Normal file
56
node_modules/webpack/lib/dependencies/CssIcssSymbolDependency.js
generated
vendored
Executable file → Normal file
@@ -6,6 +6,7 @@
|
||||
"use strict";
|
||||
|
||||
const makeSerializable = require("../util/makeSerializable");
|
||||
const CssIcssExportDependency = require("./CssIcssExportDependency");
|
||||
const NullDependency = require("./NullDependency");
|
||||
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
@@ -24,19 +25,21 @@ const NullDependency = require("./NullDependency");
|
||||
class CssIcssSymbolDependency extends NullDependency {
|
||||
/**
|
||||
* @param {string} name name
|
||||
* @param {string} value value
|
||||
* @param {string} symbol symbol
|
||||
* @param {Range} range range
|
||||
* @param {boolean=} isReference true when is reference, otherwise false
|
||||
*/
|
||||
constructor(name, value, range) {
|
||||
constructor(name, symbol, range, isReference) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.symbol = symbol;
|
||||
this.range = range;
|
||||
this.isReference = isReference;
|
||||
this._hashUpdate = undefined;
|
||||
}
|
||||
|
||||
get type() {
|
||||
return "css @value identifier";
|
||||
return "css symbol identifier";
|
||||
}
|
||||
|
||||
get category() {
|
||||
@@ -56,23 +59,6 @@ class CssIcssSymbolDependency extends NullDependency {
|
||||
hash.update(this._hashUpdate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exported names
|
||||
* @param {ModuleGraph} moduleGraph module graph
|
||||
* @returns {ExportsSpec | undefined} export names
|
||||
*/
|
||||
getExports(moduleGraph) {
|
||||
return {
|
||||
exports: [
|
||||
{
|
||||
name: this.name,
|
||||
canMangle: true
|
||||
}
|
||||
],
|
||||
dependencies: undefined
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of exports referenced by this dependency
|
||||
* @param {ModuleGraph} moduleGraph module graph
|
||||
@@ -80,7 +66,7 @@ class CssIcssSymbolDependency extends NullDependency {
|
||||
* @returns {ReferencedExports} referenced exports
|
||||
*/
|
||||
getReferencedExports(moduleGraph, runtime) {
|
||||
return [[this.name]];
|
||||
return [[this.symbol]];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,8 +75,10 @@ class CssIcssSymbolDependency extends NullDependency {
|
||||
serialize(context) {
|
||||
const { write } = context;
|
||||
write(this.name);
|
||||
write(this.symbol);
|
||||
write(this.value);
|
||||
write(this.range);
|
||||
write(this.isReference);
|
||||
super.serialize(context);
|
||||
}
|
||||
|
||||
@@ -100,13 +88,15 @@ class CssIcssSymbolDependency extends NullDependency {
|
||||
deserialize(context) {
|
||||
const { read } = context;
|
||||
this.name = read();
|
||||
this.symbol = read();
|
||||
this.value = read();
|
||||
this.range = read();
|
||||
this.isReference = read();
|
||||
super.deserialize(context);
|
||||
}
|
||||
}
|
||||
|
||||
CssIcssSymbolDependency.Template = class CssValueAtRuleDependencyTemplate extends (
|
||||
CssIcssSymbolDependency.Template = class CssIcssSymbolDependencyTemplate extends (
|
||||
NullDependency.Template
|
||||
) {
|
||||
/**
|
||||
@@ -115,12 +105,24 @@ CssIcssSymbolDependency.Template = class CssValueAtRuleDependencyTemplate extend
|
||||
* @param {DependencyTemplateContext} templateContext the context object
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(dependency, source, { cssData }) {
|
||||
const dep = /** @type {CssIcssSymbolDependency} */ (dependency);
|
||||
apply(dependency, source, templateContext) {
|
||||
if (templateContext.type === "css") {
|
||||
const dep = /** @type {CssIcssSymbolDependency} */ (dependency);
|
||||
/** @type {string | undefined} */
|
||||
const value = dep.isReference
|
||||
? CssIcssExportDependency.Template.findReference(
|
||||
dep.symbol,
|
||||
templateContext
|
||||
)
|
||||
: dep.symbol;
|
||||
|
||||
source.replace(dep.range[0], dep.range[1] - 1, dep.value);
|
||||
if (!value) {
|
||||
// TODO generate warning
|
||||
return;
|
||||
}
|
||||
|
||||
cssData.exports.set(dep.name, dep.value);
|
||||
source.replace(dep.range[0], dep.range[1] - 1, value);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
20
node_modules/webpack/lib/dependencies/CssImportDependency.js
generated
vendored
Executable file → Normal file
20
node_modules/webpack/lib/dependencies/CssImportDependency.js
generated
vendored
Executable file → Normal file
@@ -21,13 +21,15 @@ class CssImportDependency extends ModuleDependency {
|
||||
* \@import url("landscape.css") layer(forms) screen and (orientation: landscape) screen and (orientation: landscape);
|
||||
* @param {string} request request
|
||||
* @param {Range} range range of the argument
|
||||
* @param {string | undefined} layer layer
|
||||
* @param {string | undefined} supports list of supports conditions
|
||||
* @param {string | undefined} media list of media conditions
|
||||
* @param {"local" | "global"=} mode mode of the parsed CSS
|
||||
* @param {string=} layer layer
|
||||
* @param {string=} supports list of supports conditions
|
||||
* @param {string=} media list of media conditions
|
||||
*/
|
||||
constructor(request, range, layer, supports, media) {
|
||||
constructor(request, range, mode, layer, supports, media) {
|
||||
super(request);
|
||||
this.range = range;
|
||||
this.mode = mode;
|
||||
this.layer = layer;
|
||||
this.supports = supports;
|
||||
this.media = media;
|
||||
@@ -38,7 +40,7 @@ class CssImportDependency extends ModuleDependency {
|
||||
}
|
||||
|
||||
get category() {
|
||||
return "css-import";
|
||||
return `css-import${this.mode ? `-${this.mode}-module` : ""}`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,6 +49,10 @@ class CssImportDependency extends ModuleDependency {
|
||||
getResourceIdentifier() {
|
||||
let str = `context${this._context || ""}|module${this.request}`;
|
||||
|
||||
if (this.mode) {
|
||||
str += `|mode${this.mode}`;
|
||||
}
|
||||
|
||||
if (this.layer) {
|
||||
str += `|layer${this.layer}`;
|
||||
}
|
||||
@@ -67,6 +73,8 @@ class CssImportDependency extends ModuleDependency {
|
||||
*/
|
||||
serialize(context) {
|
||||
const { write } = context;
|
||||
write(this.range);
|
||||
write(this.mode);
|
||||
write(this.layer);
|
||||
write(this.supports);
|
||||
write(this.media);
|
||||
@@ -78,6 +86,8 @@ class CssImportDependency extends ModuleDependency {
|
||||
*/
|
||||
deserialize(context) {
|
||||
const { read } = context;
|
||||
this.range = read();
|
||||
this.mode = read();
|
||||
this.layer = read();
|
||||
this.supports = read();
|
||||
this.media = read();
|
||||
|
||||
250
node_modules/webpack/lib/dependencies/CssLocalIdentifierDependency.js
generated
vendored
250
node_modules/webpack/lib/dependencies/CssLocalIdentifierDependency.js
generated
vendored
@@ -1,250 +0,0 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Ivan Kopeykin @vankop
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { cssExportConvention } = require("../util/conventions");
|
||||
const createHash = require("../util/createHash");
|
||||
const { makePathsRelative } = require("../util/identifier");
|
||||
const makeSerializable = require("../util/makeSerializable");
|
||||
const memoize = require("../util/memoize");
|
||||
const NullDependency = require("./NullDependency");
|
||||
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
|
||||
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
||||
/** @typedef {import("../CssModule")} CssModule */
|
||||
/** @typedef {import("../Dependency")} Dependency */
|
||||
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
||||
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
||||
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
||||
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
||||
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
||||
/** @typedef {import("../css/CssGenerator")} CssGenerator */
|
||||
/** @typedef {import("../css/CssParser").Range} Range */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
||||
/** @typedef {import("../util/Hash")} Hash */
|
||||
|
||||
const getCssParser = memoize(() => require("../css/CssParser"));
|
||||
|
||||
/**
|
||||
* @param {string} local css local
|
||||
* @param {CssModule} module module
|
||||
* @param {ChunkGraph} chunkGraph chunk graph
|
||||
* @param {RuntimeTemplate} runtimeTemplate runtime template
|
||||
* @returns {string} local ident
|
||||
*/
|
||||
const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
|
||||
const generator = /** @type {CssGenerator} */ (module.generator);
|
||||
const localIdentName =
|
||||
/** @type {CssGeneratorLocalIdentName} */
|
||||
(generator.localIdentName);
|
||||
const relativeResourcePath = makePathsRelative(
|
||||
/** @type {string} */
|
||||
(module.context),
|
||||
/** @type {string} */
|
||||
(module.getResource()),
|
||||
runtimeTemplate.compilation.compiler.root
|
||||
);
|
||||
const { hashFunction, hashDigest, hashDigestLength, hashSalt, uniqueName } =
|
||||
runtimeTemplate.outputOptions;
|
||||
const hash = createHash(hashFunction);
|
||||
|
||||
if (hashSalt) {
|
||||
hash.update(hashSalt);
|
||||
}
|
||||
|
||||
hash.update(relativeResourcePath);
|
||||
|
||||
if (!/\[local\]/.test(localIdentName)) {
|
||||
hash.update(local);
|
||||
}
|
||||
|
||||
const localIdentHash = hash.digest(hashDigest).slice(0, hashDigestLength);
|
||||
|
||||
return runtimeTemplate.compilation
|
||||
.getPath(localIdentName, {
|
||||
filename: relativeResourcePath,
|
||||
hash: localIdentHash,
|
||||
contentHash: localIdentHash,
|
||||
chunkGraph,
|
||||
module
|
||||
})
|
||||
.replace(/\[local\]/g, local)
|
||||
.replace(/\[uniqueName\]/g, /** @type {string} */ (uniqueName))
|
||||
.replace(/^((-?[0-9])|--)/, "_$1");
|
||||
};
|
||||
|
||||
class CssLocalIdentifierDependency extends NullDependency {
|
||||
/**
|
||||
* @param {string} name name
|
||||
* @param {Range} range range
|
||||
* @param {string=} prefix prefix
|
||||
*/
|
||||
constructor(name, range, prefix = "") {
|
||||
super();
|
||||
this.name = name;
|
||||
this.range = range;
|
||||
this.prefix = prefix;
|
||||
this._conventionNames = undefined;
|
||||
this._hashUpdate = undefined;
|
||||
}
|
||||
|
||||
get type() {
|
||||
return "css local identifier";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name export name
|
||||
* @param {CssGeneratorExportsConvention} convention convention of the export name
|
||||
* @returns {string[]} convention results
|
||||
*/
|
||||
getExportsConventionNames(name, convention) {
|
||||
if (this._conventionNames) {
|
||||
return this._conventionNames;
|
||||
}
|
||||
this._conventionNames = cssExportConvention(this.name, convention);
|
||||
return this._conventionNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exported names
|
||||
* @param {ModuleGraph} moduleGraph module graph
|
||||
* @returns {ExportsSpec | undefined} export names
|
||||
*/
|
||||
getExports(moduleGraph) {
|
||||
const module = /** @type {CssModule} */ (moduleGraph.getParentModule(this));
|
||||
const generator = /** @type {CssGenerator} */ (module.generator);
|
||||
const names = this.getExportsConventionNames(
|
||||
this.name,
|
||||
/** @type {CssGeneratorExportsConvention} */ (generator.convention)
|
||||
);
|
||||
return {
|
||||
exports: names.map((name) => ({
|
||||
name,
|
||||
canMangle: true
|
||||
})),
|
||||
dependencies: undefined
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the hash
|
||||
* @param {Hash} hash hash to be updated
|
||||
* @param {UpdateHashContext} context context
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash, { chunkGraph }) {
|
||||
if (this._hashUpdate === undefined) {
|
||||
const module =
|
||||
/** @type {CssModule} */
|
||||
(chunkGraph.moduleGraph.getParentModule(this));
|
||||
const generator = /** @type {CssGenerator} */ (module.generator);
|
||||
const names = this.getExportsConventionNames(
|
||||
this.name,
|
||||
/** @type {CssGeneratorExportsConvention} */
|
||||
(generator.convention)
|
||||
);
|
||||
this._hashUpdate = `exportsConvention|${JSON.stringify(names)}|localIdentName|${JSON.stringify(generator.localIdentName)}`;
|
||||
}
|
||||
hash.update(this._hashUpdate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectSerializerContext} context context
|
||||
*/
|
||||
serialize(context) {
|
||||
const { write } = context;
|
||||
write(this.name);
|
||||
write(this.range);
|
||||
write(this.prefix);
|
||||
super.serialize(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectDeserializerContext} context context
|
||||
*/
|
||||
deserialize(context) {
|
||||
const { read } = context;
|
||||
this.name = read();
|
||||
this.range = read();
|
||||
this.prefix = read();
|
||||
super.deserialize(context);
|
||||
}
|
||||
}
|
||||
|
||||
CssLocalIdentifierDependency.Template = class CssLocalIdentifierDependencyTemplate extends (
|
||||
NullDependency.Template
|
||||
) {
|
||||
/**
|
||||
* @param {Dependency} dependency the dependency for which the template should be applied
|
||||
* @param {string} local local name
|
||||
* @param {DependencyTemplateContext} templateContext the context object
|
||||
* @returns {string} identifier
|
||||
*/
|
||||
static getIdentifier(
|
||||
dependency,
|
||||
local,
|
||||
{ module: m, chunkGraph, runtimeTemplate }
|
||||
) {
|
||||
const dep = /** @type {CssLocalIdentifierDependency} */ (dependency);
|
||||
const module = /** @type {CssModule} */ (m);
|
||||
|
||||
return (
|
||||
dep.prefix +
|
||||
getCssParser().escapeIdentifier(
|
||||
getLocalIdent(local, module, chunkGraph, runtimeTemplate)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Dependency} dependency the dependency for which the template should be applied
|
||||
* @param {ReplaceSource} source the current replace source which can be modified
|
||||
* @param {DependencyTemplateContext} templateContext the context object
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(dependency, source, templateContext) {
|
||||
const { module: m, moduleGraph, runtime, cssData } = templateContext;
|
||||
const dep = /** @type {CssLocalIdentifierDependency} */ (dependency);
|
||||
const module = /** @type {CssModule} */ (m);
|
||||
const generator = /** @type {CssGenerator} */ (module.generator);
|
||||
const names = dep.getExportsConventionNames(
|
||||
dep.name,
|
||||
/** @type {CssGeneratorExportsConvention} */
|
||||
(generator.convention)
|
||||
);
|
||||
const usedNames =
|
||||
/** @type {string[]} */
|
||||
(
|
||||
names
|
||||
.map((name) =>
|
||||
moduleGraph.getExportInfo(module, name).getUsedName(name, runtime)
|
||||
)
|
||||
.filter(Boolean)
|
||||
);
|
||||
const local = usedNames.length === 0 ? names[0] : usedNames[0];
|
||||
const identifier = CssLocalIdentifierDependencyTemplate.getIdentifier(
|
||||
dep,
|
||||
local,
|
||||
templateContext
|
||||
);
|
||||
|
||||
source.replace(dep.range[0], dep.range[1] - 1, identifier);
|
||||
|
||||
for (const used of [...usedNames, ...names]) {
|
||||
cssData.exports.set(used, getCssParser().unescapeIdentifier(identifier));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
makeSerializable(
|
||||
CssLocalIdentifierDependency,
|
||||
"webpack/lib/dependencies/CssLocalIdentifierDependency"
|
||||
);
|
||||
|
||||
module.exports = CssLocalIdentifierDependency;
|
||||
0
node_modules/webpack/lib/dependencies/CssUrlDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/CssUrlDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/DelegatedSourceDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/DelegatedSourceDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/DllEntryDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/DllEntryDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/DynamicExports.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/DynamicExports.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/EntryDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/EntryDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ExportsInfoDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ExportsInfoDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ExternalModuleDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ExternalModuleDependency.js
generated
vendored
Executable file → Normal file
2
node_modules/webpack/lib/dependencies/ExternalModuleInitFragment.js
generated
vendored
Executable file → Normal file
2
node_modules/webpack/lib/dependencies/ExternalModuleInitFragment.js
generated
vendored
Executable file → Normal file
@@ -99,7 +99,7 @@ class ExternalModuleInitFragment extends InitFragment {
|
||||
|
||||
return `import ${importsString} from ${JSON.stringify(
|
||||
this.importedModule
|
||||
)};`;
|
||||
)};\n`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
95
node_modules/webpack/lib/dependencies/ExternalModuleInitFragmentDependency.js
generated
vendored
Normal file
95
node_modules/webpack/lib/dependencies/ExternalModuleInitFragmentDependency.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Alexander Akait @alexander-akait
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const DependencyTemplate = require("../DependencyTemplate");
|
||||
const makeSerializable = require("../util/makeSerializable");
|
||||
const ExternalModuleInitFragment = require("./ExternalModuleInitFragment");
|
||||
const NullDependency = require("./NullDependency");
|
||||
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
/** @typedef {import("../Dependency")} Dependency */
|
||||
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
||||
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
||||
|
||||
class ExternalModuleInitFragmentDependency extends NullDependency {
|
||||
/**
|
||||
* @param {string} module module
|
||||
* @param {{ name: string, value: string }[]} importSpecifiers import specifiers
|
||||
* @param {string | undefined} defaultImport default import
|
||||
*/
|
||||
constructor(module, importSpecifiers, defaultImport) {
|
||||
super();
|
||||
this.importedModule = module;
|
||||
this.specifiers = importSpecifiers;
|
||||
this.default = defaultImport;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string} hash update
|
||||
*/
|
||||
_createHashUpdate() {
|
||||
return `${this.importedModule}${JSON.stringify(this.specifiers)}${
|
||||
this.default || "null"
|
||||
}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectSerializerContext} context context
|
||||
*/
|
||||
serialize(context) {
|
||||
const { write } = context;
|
||||
write(this.importedModule);
|
||||
write(this.specifiers);
|
||||
write(this.default);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectDeserializerContext} context context
|
||||
*/
|
||||
deserialize(context) {
|
||||
const { read } = context;
|
||||
this.importedModule = read();
|
||||
this.specifiers = read();
|
||||
this.default = read();
|
||||
}
|
||||
}
|
||||
|
||||
makeSerializable(
|
||||
ExternalModuleInitFragmentDependency,
|
||||
"webpack/lib/dependencies/ExternalModuleConstDependency"
|
||||
);
|
||||
|
||||
ExternalModuleInitFragmentDependency.Template = class ExternalModuleConstDependencyTemplate extends (
|
||||
DependencyTemplate
|
||||
) {
|
||||
/**
|
||||
* @param {Dependency} dependency the dependency for which the template should be applied
|
||||
* @param {ReplaceSource} source the current replace source which can be modified
|
||||
* @param {DependencyTemplateContext} templateContext the context object
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(dependency, source, templateContext) {
|
||||
const dep =
|
||||
/** @type {ExternalModuleInitFragmentDependency} */
|
||||
(dependency);
|
||||
const { chunkInitFragments, runtimeTemplate } = templateContext;
|
||||
|
||||
chunkInitFragments.push(
|
||||
new ExternalModuleInitFragment(
|
||||
`${runtimeTemplate.supportNodePrefixForCoreModules() ? "node:" : ""}${
|
||||
dep.importedModule
|
||||
}`,
|
||||
dep.specifiers,
|
||||
dep.default
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = ExternalModuleInitFragmentDependency;
|
||||
7
node_modules/webpack/lib/dependencies/HarmonyAcceptDependency.js
generated
vendored
Executable file → Normal file
7
node_modules/webpack/lib/dependencies/HarmonyAcceptDependency.js
generated
vendored
Executable file → Normal file
@@ -9,6 +9,7 @@ const Template = require("../Template");
|
||||
const AwaitDependenciesInitFragment = require("../async-modules/AwaitDependenciesInitFragment");
|
||||
const makeSerializable = require("../util/makeSerializable");
|
||||
const HarmonyImportDependency = require("./HarmonyImportDependency");
|
||||
const { ImportPhaseUtils } = require("./ImportPhase");
|
||||
const NullDependency = require("./NullDependency");
|
||||
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
@@ -120,7 +121,11 @@ HarmonyAcceptDependency.Template = class HarmonyAcceptDependencyTemplate extends
|
||||
for (const d of module.dependencies) {
|
||||
if (deferDependency && noDeferredDependency) break;
|
||||
if (isRelatedHarmonyImportDependency(dependency, d)) {
|
||||
if (/** @type {HarmonyImportDependency} */ (d).defer) {
|
||||
if (
|
||||
ImportPhaseUtils.isDefer(
|
||||
/** @type {HarmonyImportDependency} */ (d).phase
|
||||
)
|
||||
) {
|
||||
deferDependency = /** @type {HarmonyImportDependency} */ (d);
|
||||
} else {
|
||||
noDeferredDependency = /** @type {HarmonyImportDependency} */ (d);
|
||||
|
||||
3
node_modules/webpack/lib/dependencies/HarmonyAcceptImportDependency.js
generated
vendored
Executable file → Normal file
3
node_modules/webpack/lib/dependencies/HarmonyAcceptImportDependency.js
generated
vendored
Executable file → Normal file
@@ -7,6 +7,7 @@
|
||||
|
||||
const makeSerializable = require("../util/makeSerializable");
|
||||
const HarmonyImportDependency = require("./HarmonyImportDependency");
|
||||
const { ImportPhase } = require("./ImportPhase");
|
||||
const NullDependency = require("./NullDependency");
|
||||
|
||||
class HarmonyAcceptImportDependency extends HarmonyImportDependency {
|
||||
@@ -14,7 +15,7 @@ class HarmonyAcceptImportDependency extends HarmonyImportDependency {
|
||||
* @param {string} request the request string
|
||||
*/
|
||||
constructor(request) {
|
||||
super(request, Number.NaN);
|
||||
super(request, Infinity, ImportPhase.Evaluation);
|
||||
this.weak = true;
|
||||
}
|
||||
|
||||
|
||||
0
node_modules/webpack/lib/dependencies/HarmonyCompatibilityDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/HarmonyCompatibilityDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/HarmonyDetectionParserPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/HarmonyDetectionParserPlugin.js
generated
vendored
Executable file → Normal file
13
node_modules/webpack/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js
generated
vendored
Executable file → Normal file
13
node_modules/webpack/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js
generated
vendored
Executable file → Normal file
@@ -7,6 +7,7 @@
|
||||
|
||||
const makeSerializable = require("../util/makeSerializable");
|
||||
const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
|
||||
const { ImportPhase } = require("./ImportPhase");
|
||||
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
/** @typedef {import("../Dependency")} Dependency */
|
||||
@@ -37,7 +38,17 @@ class HarmonyEvaluatedImportSpecifierDependency extends HarmonyImportSpecifierDe
|
||||
* @param {string} operator operator
|
||||
*/
|
||||
constructor(request, sourceOrder, ids, name, range, attributes, operator) {
|
||||
super(request, sourceOrder, ids, name, range, false, attributes, []);
|
||||
super(
|
||||
request,
|
||||
sourceOrder,
|
||||
ids,
|
||||
name,
|
||||
range,
|
||||
false,
|
||||
ImportPhase.Evaluation,
|
||||
attributes,
|
||||
[]
|
||||
);
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
|
||||
53
node_modules/webpack/lib/dependencies/HarmonyExportDependencyParserPlugin.js
generated
vendored
Executable file → Normal file
53
node_modules/webpack/lib/dependencies/HarmonyExportDependencyParserPlugin.js
generated
vendored
Executable file → Normal file
@@ -5,6 +5,7 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
const CompatibilityPlugin = require("../CompatibilityPlugin");
|
||||
const WebpackError = require("../WebpackError");
|
||||
const { getImportAttributes } = require("../javascript/JavascriptParser");
|
||||
const InnerGraph = require("../optimize/InnerGraph");
|
||||
@@ -15,10 +16,10 @@ const HarmonyExportImportedSpecifierDependency = require("./HarmonyExportImporte
|
||||
const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDependency");
|
||||
const { ExportPresenceModes } = require("./HarmonyImportDependency");
|
||||
const {
|
||||
getImportMode,
|
||||
harmonySpecifierTag
|
||||
} = require("./HarmonyImportDependencyParserPlugin");
|
||||
const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
|
||||
const { ImportPhaseUtils, createGetImportPhase } = require("./ImportPhase");
|
||||
|
||||
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
||||
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
||||
@@ -26,6 +27,7 @@ const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDepe
|
||||
/** @typedef {import("../javascript/JavascriptParser").FunctionDeclaration} FunctionDeclaration */
|
||||
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
||||
/** @typedef {import("./HarmonyImportDependencyParserPlugin").HarmonySettings} HarmonySettings */
|
||||
/** @typedef {import("../CompatibilityPlugin").CompatibilitySettings} CompatibilitySettings */
|
||||
|
||||
const { HarmonyStarExportsList } = HarmonyExportImportedSpecifierDependency;
|
||||
|
||||
@@ -36,6 +38,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
||||
* @param {import("../../declarations/WebpackOptions").JavascriptParserOptions} options options
|
||||
*/
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
this.exportPresenceMode =
|
||||
options.reexportExportsPresence !== undefined
|
||||
? ExportPresenceModes.fromUserOption(options.reexportExportsPresence)
|
||||
@@ -44,7 +47,6 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
||||
: options.strictExportPresence
|
||||
? ExportPresenceModes.ERROR
|
||||
: ExportPresenceModes.AUTO;
|
||||
this.deferImport = options.deferImport;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,6 +55,8 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
||||
*/
|
||||
apply(parser) {
|
||||
const { exportPresenceMode } = this;
|
||||
const getImportPhase = createGetImportPhase(this.options.deferImport);
|
||||
|
||||
parser.hooks.export.tap(PLUGIN_NAME, (statement) => {
|
||||
const dep = new HarmonyExportHeaderDependency(
|
||||
/** @type {Range | false} */ (
|
||||
@@ -77,22 +81,20 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
||||
clearDep.loc = /** @type {DependencyLocation} */ (statement.loc);
|
||||
clearDep.loc.index = -1;
|
||||
parser.state.module.addPresentationalDependency(clearDep);
|
||||
let defer = false;
|
||||
if (this.deferImport) {
|
||||
({ defer } = getImportMode(parser, statement));
|
||||
if (defer) {
|
||||
const error = new WebpackError(
|
||||
"Deferred re-export (`export defer * as namespace from '...'`) is not a part of the Import Defer proposal.\nUse the following code instead:\n import defer * as namespace from '...';\n export { namespace };"
|
||||
);
|
||||
error.loc = statement.loc || undefined;
|
||||
parser.state.current.addError(error);
|
||||
}
|
||||
|
||||
const phase = getImportPhase(parser, statement);
|
||||
if (phase && ImportPhaseUtils.isDefer(phase)) {
|
||||
const error = new WebpackError(
|
||||
"Deferred re-export (`export defer * as namespace from '...'`) is not a part of the Import Defer proposal.\nUse the following code instead:\n import defer * as namespace from '...';\n export { namespace };"
|
||||
);
|
||||
error.loc = statement.loc || undefined;
|
||||
parser.state.current.addError(error);
|
||||
}
|
||||
const sideEffectDep = new HarmonyImportSideEffectDependency(
|
||||
/** @type {string} */ (source),
|
||||
parser.state.lastHarmonyImportOrder,
|
||||
getImportAttributes(statement),
|
||||
defer
|
||||
phase,
|
||||
getImportAttributes(statement)
|
||||
);
|
||||
sideEffectDep.loc = Object.create(
|
||||
/** @type {DependencyLocation} */ (statement.loc)
|
||||
@@ -157,6 +159,18 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
||||
parser.hooks.exportSpecifier.tap(
|
||||
PLUGIN_NAME,
|
||||
(statement, id, name, idx) => {
|
||||
// CompatibilityPlugin may change exports name
|
||||
// not handle re-export or import then export situation as current CompatibilityPlugin only
|
||||
// rename symbol in declaration module, not change exported symbol
|
||||
const variable = parser.getTagData(
|
||||
id,
|
||||
CompatibilityPlugin.nestedWebpackIdentifierTag
|
||||
);
|
||||
if (variable && /** @type {CompatibilitySettings} */ (variable).name) {
|
||||
// CompatibilityPlugin changes exports to a new name, should updates exports name
|
||||
id = /** @type {CompatibilitySettings} */ (variable).name;
|
||||
}
|
||||
|
||||
const settings =
|
||||
/** @type {HarmonySettings} */
|
||||
(parser.getTagData(id, harmonySpecifierTag));
|
||||
@@ -174,8 +188,8 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
||||
null,
|
||||
exportPresenceMode,
|
||||
null,
|
||||
settings.attributes,
|
||||
settings.defer
|
||||
settings.phase,
|
||||
settings.attributes
|
||||
)
|
||||
: new HarmonyExportSpecifierDependency(id, name);
|
||||
dep.loc = Object.create(
|
||||
@@ -207,9 +221,6 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
||||
parser.state.harmonyStarExports || new HarmonyStarExportsList();
|
||||
}
|
||||
const attributes = getImportAttributes(statement);
|
||||
const defer = this.deferImport
|
||||
? getImportMode(parser, statement).defer
|
||||
: false;
|
||||
const dep = new HarmonyExportImportedSpecifierDependency(
|
||||
/** @type {string} */
|
||||
(source),
|
||||
@@ -221,8 +232,8 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
||||
harmonyStarExports && harmonyStarExports.slice(),
|
||||
exportPresenceMode,
|
||||
harmonyStarExports,
|
||||
attributes,
|
||||
defer
|
||||
getImportPhase(parser, statement),
|
||||
attributes
|
||||
);
|
||||
if (harmonyStarExports) {
|
||||
harmonyStarExports.push(dep);
|
||||
|
||||
0
node_modules/webpack/lib/dependencies/HarmonyExportExpressionDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/HarmonyExportExpressionDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/HarmonyExportHeaderDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/HarmonyExportHeaderDependency.js
generated
vendored
Executable file → Normal file
20
node_modules/webpack/lib/dependencies/HarmonyExportImportedSpecifierDependency.js
generated
vendored
Executable file → Normal file
20
node_modules/webpack/lib/dependencies/HarmonyExportImportedSpecifierDependency.js
generated
vendored
Executable file → Normal file
@@ -27,6 +27,7 @@ const {
|
||||
} = require("../util/runtime");
|
||||
const HarmonyExportInitFragment = require("./HarmonyExportInitFragment");
|
||||
const HarmonyImportDependency = require("./HarmonyImportDependency");
|
||||
const { ImportPhaseUtils } = require("./ImportPhase");
|
||||
const processExportInfo = require("./processExportInfo");
|
||||
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
@@ -57,6 +58,7 @@ const processExportInfo = require("./processExportInfo");
|
||||
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
||||
/** @typedef {import("./HarmonyImportDependency").Ids} Ids */
|
||||
/** @typedef {import("./HarmonyImportDependency").ExportPresenceMode} ExportPresenceMode */
|
||||
/** @typedef {import("../dependencies/ImportPhase").ImportPhaseType} ImportPhaseType */
|
||||
|
||||
/** @typedef {"missing"|"unused"|"empty-star"|"reexport-dynamic-default"|"reexport-named-default"|"reexport-namespace-object"|"reexport-fake-namespace-object"|"reexport-undefined"|"normal-reexport"|"dynamic-reexport"} ExportModeType */
|
||||
|
||||
@@ -376,8 +378,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
||||
* @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency> | null} otherStarExports other star exports in the module before this import
|
||||
* @param {ExportPresenceMode} exportPresenceMode mode of checking export names
|
||||
* @param {HarmonyStarExportsList | null} allStarExports all star exports in the module
|
||||
* @param {ImportPhaseType} phase import phase
|
||||
* @param {ImportAttributes=} attributes import attributes
|
||||
* @param {boolean=} defer is defer phase
|
||||
*/
|
||||
constructor(
|
||||
request,
|
||||
@@ -388,10 +390,10 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
||||
otherStarExports,
|
||||
exportPresenceMode,
|
||||
allStarExports,
|
||||
attributes,
|
||||
defer
|
||||
phase,
|
||||
attributes
|
||||
) {
|
||||
super(request, sourceOrder, attributes, defer);
|
||||
super(request, sourceOrder, phase, attributes);
|
||||
|
||||
this.ids = ids;
|
||||
this.name = name;
|
||||
@@ -1050,12 +1052,14 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
||||
) {
|
||||
const importedModule = /** @type {Module} */ (moduleGraph.getModule(dep));
|
||||
const importVar = dep.getImportVar(moduleGraph);
|
||||
const isDeferred =
|
||||
ImportPhaseUtils.isDefer(dep.phase) &&
|
||||
!(/** @type {BuildMeta} */ (importedModule.buildMeta).async);
|
||||
|
||||
if (
|
||||
(mode.type === "reexport-namespace-object" ||
|
||||
mode.type === "reexport-fake-namespace-object") &&
|
||||
dep.defer &&
|
||||
!moduleGraph.isAsync(importedModule)
|
||||
isDeferred
|
||||
) {
|
||||
initFragments.push(
|
||||
...this.getReexportDeferredNamespaceObjectFragments(
|
||||
@@ -1200,7 +1204,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
||||
moduleGraph.isAsync(importedModule)
|
||||
? InitFragment.STAGE_ASYNC_HARMONY_IMPORTS
|
||||
: InitFragment.STAGE_HARMONY_IMPORTS,
|
||||
dep.sourceOrder,
|
||||
/** @type {number} */ (dep.sourceOrder),
|
||||
key,
|
||||
runtimeCondition
|
||||
)
|
||||
@@ -1261,7 +1265,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
||||
moduleGraph.isAsync(importedModule)
|
||||
? InitFragment.STAGE_ASYNC_HARMONY_IMPORTS
|
||||
: InitFragment.STAGE_HARMONY_IMPORTS,
|
||||
dep.sourceOrder
|
||||
/** @type {number} */ (dep.sourceOrder)
|
||||
)
|
||||
);
|
||||
break;
|
||||
|
||||
0
node_modules/webpack/lib/dependencies/HarmonyExportInitFragment.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/HarmonyExportInitFragment.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/HarmonyExportSpecifierDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/HarmonyExportSpecifierDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/HarmonyExports.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/HarmonyExports.js
generated
vendored
Executable file → Normal file
50
node_modules/webpack/lib/dependencies/HarmonyImportDependency.js
generated
vendored
Executable file → Normal file
50
node_modules/webpack/lib/dependencies/HarmonyImportDependency.js
generated
vendored
Executable file → Normal file
@@ -12,6 +12,7 @@ const InitFragment = require("../InitFragment");
|
||||
const Template = require("../Template");
|
||||
const AwaitDependenciesInitFragment = require("../async-modules/AwaitDependenciesInitFragment");
|
||||
const { filterRuntime, mergeRuntime } = require("../util/runtime");
|
||||
const { ImportPhaseUtils } = require("./ImportPhase");
|
||||
const ModuleDependency = require("./ModuleDependency");
|
||||
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
@@ -23,6 +24,7 @@ const ModuleDependency = require("./ModuleDependency");
|
||||
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
||||
/** @typedef {import("../WebpackError")} WebpackError */
|
||||
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
||||
/** @typedef {import("./ImportPhase").ImportPhaseType} ImportPhaseType */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
||||
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
||||
@@ -60,14 +62,13 @@ class HarmonyImportDependency extends ModuleDependency {
|
||||
/**
|
||||
* @param {string} request request string
|
||||
* @param {number} sourceOrder source order
|
||||
* @param {ImportPhaseType} phase import phase
|
||||
* @param {ImportAttributes=} attributes import attributes
|
||||
* @param {boolean=} defer import attributes
|
||||
*/
|
||||
constructor(request, sourceOrder, attributes, defer) {
|
||||
super(request);
|
||||
this.sourceOrder = sourceOrder;
|
||||
constructor(request, sourceOrder, phase, attributes) {
|
||||
super(request, sourceOrder);
|
||||
this.phase = phase;
|
||||
this.attributes = attributes;
|
||||
this.defer = defer;
|
||||
}
|
||||
|
||||
get category() {
|
||||
@@ -79,7 +80,7 @@ class HarmonyImportDependency extends ModuleDependency {
|
||||
*/
|
||||
getResourceIdentifier() {
|
||||
let str = super.getResourceIdentifier();
|
||||
if (this.defer) {
|
||||
if (ImportPhaseUtils.isDefer(this.phase)) {
|
||||
str += "|defer";
|
||||
}
|
||||
if (this.attributes) {
|
||||
@@ -104,10 +105,14 @@ class HarmonyImportDependency extends ModuleDependency {
|
||||
*/
|
||||
getImportVar(moduleGraph) {
|
||||
const module = /** @type {Module} */ (moduleGraph.getParentModule(this));
|
||||
const importedModule = /** @type {Module} */ (moduleGraph.getModule(this));
|
||||
const meta = moduleGraph.getMeta(module);
|
||||
const defer = this.defer;
|
||||
|
||||
const metaKey = defer ? "deferredImportVarMap" : "importVarMap";
|
||||
const isDeferred =
|
||||
ImportPhaseUtils.isDefer(this.phase) &&
|
||||
!(/** @type {BuildMeta} */ (importedModule.buildMeta).async);
|
||||
|
||||
const metaKey = isDeferred ? "deferredImportVarMap" : "importVarMap";
|
||||
let importVarMap = meta[metaKey];
|
||||
if (!importVarMap) {
|
||||
meta[metaKey] = importVarMap =
|
||||
@@ -115,19 +120,12 @@ class HarmonyImportDependency extends ModuleDependency {
|
||||
(new Map());
|
||||
}
|
||||
|
||||
let importVar = importVarMap.get(
|
||||
/** @type {Module} */
|
||||
(moduleGraph.getModule(this))
|
||||
);
|
||||
let importVar = importVarMap.get(importedModule);
|
||||
if (importVar) return importVar;
|
||||
importVar = `${Template.toIdentifier(
|
||||
`${this.userRequest}`
|
||||
)}__WEBPACK_${this.defer ? "DEFERRED_" : ""}IMPORTED_MODULE_${importVarMap.size}__`;
|
||||
importVarMap.set(
|
||||
/** @type {Module} */
|
||||
(moduleGraph.getModule(this)),
|
||||
importVar
|
||||
);
|
||||
)}__WEBPACK_${isDeferred ? "DEFERRED_" : ""}IMPORTED_MODULE_${importVarMap.size}__`;
|
||||
importVarMap.set(importedModule, importVar);
|
||||
return importVar;
|
||||
}
|
||||
|
||||
@@ -167,7 +165,7 @@ class HarmonyImportDependency extends ModuleDependency {
|
||||
request: this.request,
|
||||
originModule: module,
|
||||
runtimeRequirements,
|
||||
defer: this.defer
|
||||
dependency: this
|
||||
});
|
||||
}
|
||||
|
||||
@@ -289,9 +287,8 @@ class HarmonyImportDependency extends ModuleDependency {
|
||||
*/
|
||||
serialize(context) {
|
||||
const { write } = context;
|
||||
write(this.sourceOrder);
|
||||
write(this.attributes);
|
||||
write(this.defer);
|
||||
write(this.phase);
|
||||
super.serialize(context);
|
||||
}
|
||||
|
||||
@@ -300,9 +297,8 @@ class HarmonyImportDependency extends ModuleDependency {
|
||||
*/
|
||||
deserialize(context) {
|
||||
const { read } = context;
|
||||
this.sourceOrder = read();
|
||||
this.attributes = read();
|
||||
this.defer = read();
|
||||
this.phase = read();
|
||||
super.deserialize(context);
|
||||
}
|
||||
}
|
||||
@@ -344,7 +340,7 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
|
||||
const moduleKey = referencedModule
|
||||
? referencedModule.identifier()
|
||||
: dep.request;
|
||||
const key = `${dep.defer ? "deferred " : ""}harmony import ${moduleKey}`;
|
||||
const key = `${ImportPhaseUtils.isDefer(dep.phase) ? "deferred " : ""}harmony import ${moduleKey}`;
|
||||
|
||||
const runtimeCondition = dep.weak
|
||||
? false
|
||||
@@ -382,7 +378,7 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
|
||||
new ConditionalInitFragment(
|
||||
importStatement[0],
|
||||
InitFragment.STAGE_HARMONY_IMPORTS,
|
||||
dep.sourceOrder,
|
||||
/** @type {number} */ (dep.sourceOrder),
|
||||
key,
|
||||
runtimeCondition
|
||||
)
|
||||
@@ -395,7 +391,7 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
|
||||
new ConditionalInitFragment(
|
||||
importStatement[1],
|
||||
InitFragment.STAGE_ASYNC_HARMONY_IMPORTS,
|
||||
dep.sourceOrder,
|
||||
/** @type {number} */ (dep.sourceOrder),
|
||||
`${key} compat`,
|
||||
runtimeCondition
|
||||
)
|
||||
@@ -405,7 +401,7 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
|
||||
new ConditionalInitFragment(
|
||||
importStatement[0] + importStatement[1],
|
||||
InitFragment.STAGE_HARMONY_IMPORTS,
|
||||
dep.sourceOrder,
|
||||
/** @type {number} */ (dep.sourceOrder),
|
||||
key,
|
||||
runtimeCondition
|
||||
)
|
||||
|
||||
97
node_modules/webpack/lib/dependencies/HarmonyImportDependencyParserPlugin.js
generated
vendored
Executable file → Normal file
97
node_modules/webpack/lib/dependencies/HarmonyImportDependencyParserPlugin.js
generated
vendored
Executable file → Normal file
@@ -5,7 +5,6 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
const CommentCompilationWarning = require("../CommentCompilationWarning");
|
||||
const HotModuleReplacementPlugin = require("../HotModuleReplacementPlugin");
|
||||
const WebpackError = require("../WebpackError");
|
||||
const {
|
||||
@@ -21,6 +20,7 @@ const HarmonyExports = require("./HarmonyExports");
|
||||
const { ExportPresenceModes } = require("./HarmonyImportDependency");
|
||||
const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
|
||||
const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
|
||||
const { ImportPhaseUtils, createGetImportPhase } = require("./ImportPhase");
|
||||
|
||||
/** @typedef {import("estree").Expression} Expression */
|
||||
/** @typedef {import("estree").Identifier} Identifier */
|
||||
@@ -36,6 +36,7 @@ const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDepend
|
||||
/** @typedef {import("../javascript/JavascriptParser").Members} Members */
|
||||
/** @typedef {import("../javascript/JavascriptParser").MembersOptionals} MembersOptionals */
|
||||
/** @typedef {import("./HarmonyImportDependency").Ids} Ids */
|
||||
/** @typedef {import("./ImportPhase").ImportPhaseType} ImportPhaseType */
|
||||
|
||||
const harmonySpecifierTag = Symbol("harmony import");
|
||||
|
||||
@@ -47,7 +48,7 @@ const harmonySpecifierTag = Symbol("harmony import");
|
||||
* @property {string} name
|
||||
* @property {boolean} await
|
||||
* @property {ImportAttributes=} attributes
|
||||
* @property {boolean | undefined} defer
|
||||
* @property {ImportPhaseType} phase
|
||||
*/
|
||||
|
||||
const PLUGIN_NAME = "HarmonyImportDependencyParserPlugin";
|
||||
@@ -57,6 +58,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
||||
* @param {JavascriptParserOptions} options options
|
||||
*/
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
this.exportPresenceMode =
|
||||
options.importExportsPresence !== undefined
|
||||
? ExportPresenceModes.fromUserOption(options.importExportsPresence)
|
||||
@@ -66,7 +68,6 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
||||
? ExportPresenceModes.ERROR
|
||||
: ExportPresenceModes.AUTO;
|
||||
this.strictThisContextOnImports = options.strictThisContextOnImports;
|
||||
this.deferImport = options.deferImport;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,6 +77,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
||||
apply(parser) {
|
||||
const { exportPresenceMode } = this;
|
||||
|
||||
const getImportPhase = createGetImportPhase(this.options.deferImport);
|
||||
|
||||
/**
|
||||
* @param {Members} members members
|
||||
* @param {MembersOptionals} membersOptionals members Optionals
|
||||
@@ -119,26 +122,24 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
||||
parser.state.module.addPresentationalDependency(clearDep);
|
||||
parser.unsetAsiPosition(/** @type {Range} */ (statement.range)[1]);
|
||||
const attributes = getImportAttributes(statement);
|
||||
let defer = false;
|
||||
if (this.deferImport) {
|
||||
({ defer } = getImportMode(parser, statement));
|
||||
if (
|
||||
defer &&
|
||||
(statement.specifiers.length !== 1 ||
|
||||
statement.specifiers[0].type !== "ImportNamespaceSpecifier")
|
||||
) {
|
||||
const error = new WebpackError(
|
||||
"Deferred import can only be used with `import * as namespace from '...'` syntax."
|
||||
);
|
||||
error.loc = statement.loc || undefined;
|
||||
parser.state.current.addError(error);
|
||||
}
|
||||
const phase = getImportPhase(parser, statement);
|
||||
if (
|
||||
ImportPhaseUtils.isDefer(phase) &&
|
||||
(statement.specifiers.length !== 1 ||
|
||||
statement.specifiers[0].type !== "ImportNamespaceSpecifier")
|
||||
) {
|
||||
const error = new WebpackError(
|
||||
"Deferred import can only be used with `import * as namespace from '...'` syntax."
|
||||
);
|
||||
error.loc = statement.loc || undefined;
|
||||
parser.state.current.addError(error);
|
||||
}
|
||||
|
||||
const sideEffectDep = new HarmonyImportSideEffectDependency(
|
||||
/** @type {string} */ (source),
|
||||
parser.state.lastHarmonyImportOrder,
|
||||
attributes,
|
||||
defer
|
||||
phase,
|
||||
attributes
|
||||
);
|
||||
sideEffectDep.loc = /** @type {DependencyLocation} */ (statement.loc);
|
||||
parser.state.module.addDependency(sideEffectDep);
|
||||
@@ -148,9 +149,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
||||
PLUGIN_NAME,
|
||||
(statement, source, id, name) => {
|
||||
const ids = id === null ? [] : [id];
|
||||
const defer = this.deferImport
|
||||
? getImportMode(parser, statement).defer
|
||||
: false;
|
||||
const phase = getImportPhase(parser, statement);
|
||||
parser.tagVariable(
|
||||
name,
|
||||
harmonySpecifierTag,
|
||||
@@ -160,7 +159,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
||||
ids,
|
||||
sourceOrder: parser.state.lastHarmonyImportOrder,
|
||||
attributes: getImportAttributes(statement),
|
||||
defer
|
||||
phase
|
||||
})
|
||||
);
|
||||
return true;
|
||||
@@ -237,9 +236,9 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
||||
/** @type {Range} */
|
||||
(expr.range),
|
||||
exportPresenceMode,
|
||||
settings.phase,
|
||||
settings.attributes,
|
||||
[],
|
||||
settings.defer
|
||||
[]
|
||||
);
|
||||
dep.referencedPropertiesInDestructuring =
|
||||
parser.destructuringAssignmentPropertiesFor(expr);
|
||||
@@ -287,9 +286,9 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
||||
/** @type {Range} */
|
||||
(expr.range),
|
||||
exportPresenceMode,
|
||||
settings.phase,
|
||||
settings.attributes,
|
||||
ranges,
|
||||
settings.defer
|
||||
ranges
|
||||
);
|
||||
dep.referencedPropertiesInDestructuring =
|
||||
parser.destructuringAssignmentPropertiesFor(expr);
|
||||
@@ -337,9 +336,9 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
||||
settings.name,
|
||||
/** @type {Range} */ (expr.range),
|
||||
exportPresenceMode,
|
||||
settings.phase,
|
||||
settings.attributes,
|
||||
ranges,
|
||||
settings.defer
|
||||
ranges
|
||||
);
|
||||
dep.directImport = members.length === 0;
|
||||
dep.call = true;
|
||||
@@ -406,44 +405,4 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {JavascriptParser} parser parser
|
||||
* @param {ExportNamedDeclaration | ExportAllDeclaration | ImportDeclaration} node node
|
||||
* @returns {{ defer: boolean }} import attributes
|
||||
*/
|
||||
function getImportMode(parser, node) {
|
||||
const result = { defer: "phase" in node && node.phase === "defer" };
|
||||
if (!node.range) {
|
||||
return result;
|
||||
}
|
||||
const { options, errors } = parser.parseCommentOptions(node.range);
|
||||
if (errors) {
|
||||
for (const e of errors) {
|
||||
const { comment } = e;
|
||||
if (!comment.loc) continue;
|
||||
parser.state.module.addWarning(
|
||||
new CommentCompilationWarning(
|
||||
`Compilation error while processing magic comment(-s): /*${comment.value}*/: ${e.message}`,
|
||||
comment.loc
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!options) return result;
|
||||
if (options.webpackDefer) {
|
||||
if (typeof options.webpackDefer === "boolean") {
|
||||
result.defer = options.webpackDefer;
|
||||
} else if (node.loc) {
|
||||
parser.state.module.addWarning(
|
||||
new CommentCompilationWarning(
|
||||
"webpackDefer magic comment expected a boolean value.",
|
||||
node.loc
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports.getImportMode = getImportMode;
|
||||
module.exports.harmonySpecifierTag = harmonySpecifierTag;
|
||||
|
||||
7
node_modules/webpack/lib/dependencies/HarmonyImportSideEffectDependency.js
generated
vendored
Executable file → Normal file
7
node_modules/webpack/lib/dependencies/HarmonyImportSideEffectDependency.js
generated
vendored
Executable file → Normal file
@@ -16,16 +16,17 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
|
||||
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
||||
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
||||
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
||||
/** @typedef {import("./ImportPhase").ImportPhaseType} ImportPhaseType */
|
||||
|
||||
class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
|
||||
/**
|
||||
* @param {string} request the request string
|
||||
* @param {number} sourceOrder source order
|
||||
* @param {ImportPhaseType} phase import phase
|
||||
* @param {ImportAttributes=} attributes import attributes
|
||||
* @param {boolean=} defer is defer phase
|
||||
*/
|
||||
constructor(request, sourceOrder, attributes, defer) {
|
||||
super(request, sourceOrder, attributes, defer);
|
||||
constructor(request, sourceOrder, phase, attributes) {
|
||||
super(request, sourceOrder, phase, attributes);
|
||||
}
|
||||
|
||||
get type() {
|
||||
|
||||
18
node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js
generated
vendored
Executable file → Normal file
18
node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js
generated
vendored
Executable file → Normal file
@@ -15,6 +15,7 @@ const makeSerializable = require("../util/makeSerializable");
|
||||
const propertyAccess = require("../util/propertyAccess");
|
||||
const traverseDestructuringAssignmentProperties = require("../util/traverseDestructuringAssignmentProperties");
|
||||
const HarmonyImportDependency = require("./HarmonyImportDependency");
|
||||
const { ImportPhaseUtils } = require("./ImportPhase");
|
||||
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
/** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
|
||||
@@ -36,6 +37,7 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
|
||||
/** @typedef {import("../util/chainedImports").IdRanges} IdRanges */
|
||||
/** @typedef {import("./HarmonyImportDependency").ExportPresenceMode} ExportPresenceMode */
|
||||
/** @typedef {HarmonyImportDependency.Ids} Ids */
|
||||
/** @typedef {import("./ImportPhase").ImportPhaseType} ImportPhaseType */
|
||||
|
||||
const idsSymbol = Symbol("HarmonyImportSpecifierDependency.ids");
|
||||
|
||||
@@ -49,9 +51,9 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
||||
* @param {string} name name
|
||||
* @param {Range} range range
|
||||
* @param {ExportPresenceMode} exportPresenceMode export presence mode
|
||||
* @param {ImportPhaseType} phase import phase
|
||||
* @param {ImportAttributes | undefined} attributes import attributes
|
||||
* @param {IdRanges | undefined} idRanges ranges for members of ids; the two arrays are right-aligned
|
||||
* @param {boolean=} defer is defer phase
|
||||
*/
|
||||
constructor(
|
||||
request,
|
||||
@@ -60,11 +62,11 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
||||
name,
|
||||
range,
|
||||
exportPresenceMode,
|
||||
phase,
|
||||
attributes,
|
||||
idRanges, // TODO webpack 6 make this non-optional. It must always be set to properly trim ids.
|
||||
defer
|
||||
idRanges // TODO webpack 6 make this non-optional. It must always be set to properly trim ids.
|
||||
) {
|
||||
super(request, sourceOrder, attributes, defer);
|
||||
super(request, sourceOrder, phase, attributes);
|
||||
this.ids = ids;
|
||||
this.name = name;
|
||||
this.range = range;
|
||||
@@ -440,14 +442,14 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
||||
connection.module,
|
||||
{
|
||||
asiSafe: dep.asiSafe,
|
||||
deferredImport: dep.defer
|
||||
deferredImport: ImportPhaseUtils.isDefer(dep.phase)
|
||||
}
|
||||
);
|
||||
} else if (dep.namespaceObjectAsContext && ids.length === 1) {
|
||||
exportExpr =
|
||||
concatenationScope.createModuleReference(connection.module, {
|
||||
asiSafe: dep.asiSafe,
|
||||
deferredImport: dep.defer
|
||||
deferredImport: ImportPhaseUtils.isDefer(dep.phase)
|
||||
}) + propertyAccess(ids);
|
||||
} else {
|
||||
exportExpr = concatenationScope.createModuleReference(
|
||||
@@ -457,7 +459,7 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
||||
call: dep.call,
|
||||
directImport: dep.directImport,
|
||||
asiSafe: dep.asiSafe,
|
||||
deferredImport: dep.defer
|
||||
deferredImport: ImportPhaseUtils.isDefer(dep.phase)
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -482,7 +484,7 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
||||
initFragments,
|
||||
runtime,
|
||||
runtimeRequirements,
|
||||
defer: dep.defer
|
||||
dependency: dep
|
||||
});
|
||||
}
|
||||
return exportExpr;
|
||||
|
||||
0
node_modules/webpack/lib/dependencies/HarmonyModulesPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/HarmonyModulesPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/HarmonyTopLevelThisParserPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/HarmonyTopLevelThisParserPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ImportContextDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ImportContextDependency.js
generated
vendored
Executable file → Normal file
10
node_modules/webpack/lib/dependencies/ImportDependency.js
generated
vendored
Executable file → Normal file
10
node_modules/webpack/lib/dependencies/ImportDependency.js
generated
vendored
Executable file → Normal file
@@ -22,18 +22,21 @@ const ModuleDependency = require("./ModuleDependency");
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
||||
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
||||
/** @typedef {import("./ImportPhase").ImportPhaseType} ImportPhaseType */
|
||||
|
||||
class ImportDependency extends ModuleDependency {
|
||||
/**
|
||||
* @param {string} request the request
|
||||
* @param {Range} range expression range
|
||||
* @param {RawReferencedExports | null=} referencedExports list of referenced exports
|
||||
* @param {RawReferencedExports | null} referencedExports list of referenced exports
|
||||
* @param {ImportPhaseType} phase import phase
|
||||
* @param {ImportAttributes=} attributes import attributes
|
||||
*/
|
||||
constructor(request, range, referencedExports, attributes) {
|
||||
constructor(request, range, referencedExports, phase, attributes) {
|
||||
super(request);
|
||||
this.range = range;
|
||||
this.referencedExports = referencedExports;
|
||||
this.phase = phase;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
@@ -99,6 +102,7 @@ class ImportDependency extends ModuleDependency {
|
||||
serialize(context) {
|
||||
context.write(this.range);
|
||||
context.write(this.referencedExports);
|
||||
context.write(this.phase);
|
||||
context.write(this.attributes);
|
||||
super.serialize(context);
|
||||
}
|
||||
@@ -109,6 +113,7 @@ class ImportDependency extends ModuleDependency {
|
||||
deserialize(context) {
|
||||
this.range = context.read();
|
||||
this.referencedExports = context.read();
|
||||
this.phase = context.read();
|
||||
this.attributes = context.read();
|
||||
super.deserialize(context);
|
||||
}
|
||||
@@ -140,6 +145,7 @@ ImportDependency.Template = class ImportDependencyTemplate extends (
|
||||
module: /** @type {Module} */ (moduleGraph.getModule(dep)),
|
||||
request: dep.request,
|
||||
strict: /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule,
|
||||
dependency: dep,
|
||||
message: "import()",
|
||||
runtimeRequirements
|
||||
});
|
||||
|
||||
9
node_modules/webpack/lib/dependencies/ImportEagerDependency.js
generated
vendored
Executable file → Normal file
9
node_modules/webpack/lib/dependencies/ImportEagerDependency.js
generated
vendored
Executable file → Normal file
@@ -16,16 +16,18 @@ const ImportDependency = require("./ImportDependency");
|
||||
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
||||
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
||||
/** @typedef {ImportDependency.RawReferencedExports} RawReferencedExports */
|
||||
/** @typedef {import("./ImportPhase").ImportPhaseType} ImportPhaseType */
|
||||
|
||||
class ImportEagerDependency extends ImportDependency {
|
||||
/**
|
||||
* @param {string} request the request
|
||||
* @param {Range} range expression range
|
||||
* @param {RawReferencedExports | null=} referencedExports list of referenced exports
|
||||
* @param {RawReferencedExports | null} referencedExports list of referenced exports
|
||||
* @param {ImportPhaseType} phase import phase
|
||||
* @param {ImportAttributes=} attributes import attributes
|
||||
*/
|
||||
constructor(request, range, referencedExports, attributes) {
|
||||
super(request, range, referencedExports, attributes);
|
||||
constructor(request, range, referencedExports, phase, attributes) {
|
||||
super(request, range, referencedExports, phase, attributes);
|
||||
}
|
||||
|
||||
get type() {
|
||||
@@ -63,6 +65,7 @@ ImportEagerDependency.Template = class ImportEagerDependencyTemplate extends (
|
||||
request: dep.request,
|
||||
strict: /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule,
|
||||
message: "import() eager",
|
||||
dependency: dep,
|
||||
runtimeRequirements
|
||||
});
|
||||
|
||||
|
||||
0
node_modules/webpack/lib/dependencies/ImportMetaContextDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ImportMetaContextDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ImportMetaContextDependencyParserPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ImportMetaContextDependencyParserPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ImportMetaContextPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ImportMetaContextPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ImportMetaHotAcceptDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ImportMetaHotAcceptDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ImportMetaHotDeclineDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ImportMetaHotDeclineDependency.js
generated
vendored
Executable file → Normal file
110
node_modules/webpack/lib/dependencies/ImportMetaPlugin.js
generated
vendored
Executable file → Normal file
110
node_modules/webpack/lib/dependencies/ImportMetaPlugin.js
generated
vendored
Executable file → Normal file
@@ -6,11 +6,14 @@
|
||||
"use strict";
|
||||
|
||||
const { pathToFileURL } = require("url");
|
||||
const { SyncBailHook } = require("tapable");
|
||||
const Compilation = require("../Compilation");
|
||||
const ModuleDependencyWarning = require("../ModuleDependencyWarning");
|
||||
const {
|
||||
JAVASCRIPT_MODULE_TYPE_AUTO,
|
||||
JAVASCRIPT_MODULE_TYPE_ESM
|
||||
} = require("../ModuleTypeConstants");
|
||||
const RuntimeGlobals = require("../RuntimeGlobals");
|
||||
const Template = require("../Template");
|
||||
const BasicEvaluatedExpression = require("../javascript/BasicEvaluatedExpression");
|
||||
const {
|
||||
@@ -31,6 +34,8 @@ const ConstDependency = require("./ConstDependency");
|
||||
/** @typedef {import("../javascript/JavascriptParser")} Parser */
|
||||
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
||||
/** @typedef {import("../javascript/JavascriptParser").Members} Members */
|
||||
/** @typedef {import("../javascript/JavascriptParser").DestructuringAssignmentProperty} DestructuringAssignmentProperty */
|
||||
/** @typedef {import("./ConstDependency").RawRuntimeRequirements} RawRuntimeRequirements */
|
||||
|
||||
const getCriticalDependencyWarning = memoize(() =>
|
||||
require("./CriticalDependencyWarning")
|
||||
@@ -38,7 +43,35 @@ const getCriticalDependencyWarning = memoize(() =>
|
||||
|
||||
const PLUGIN_NAME = "ImportMetaPlugin";
|
||||
|
||||
/**
|
||||
* @typedef {object} ImportMetaPluginHooks
|
||||
* @property {SyncBailHook<[DestructuringAssignmentProperty], string | void>} propertyInDestructuring
|
||||
*/
|
||||
|
||||
/** @type {WeakMap<Compilation, ImportMetaPluginHooks>} */
|
||||
const compilationHooksMap = new WeakMap();
|
||||
|
||||
class ImportMetaPlugin {
|
||||
/**
|
||||
* @param {Compilation} compilation the compilation
|
||||
* @returns {ImportMetaPluginHooks} the attached hooks
|
||||
*/
|
||||
static getCompilationHooks(compilation) {
|
||||
if (!(compilation instanceof Compilation)) {
|
||||
throw new TypeError(
|
||||
"The 'compilation' argument must be an instance of Compilation"
|
||||
);
|
||||
}
|
||||
let hooks = compilationHooksMap.get(compilation);
|
||||
if (hooks === undefined) {
|
||||
hooks = {
|
||||
propertyInDestructuring: new SyncBailHook(["property"])
|
||||
};
|
||||
compilationHooksMap.set(compilation, hooks);
|
||||
}
|
||||
return hooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Compiler} compiler compiler
|
||||
*/
|
||||
@@ -46,6 +79,8 @@ class ImportMetaPlugin {
|
||||
compiler.hooks.compilation.tap(
|
||||
PLUGIN_NAME,
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
const hooks = ImportMetaPlugin.getCompilationHooks(compilation);
|
||||
|
||||
/**
|
||||
* @param {NormalModule} module module
|
||||
* @returns {string} file url
|
||||
@@ -135,25 +170,44 @@ class ImportMetaPlugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @type {RawRuntimeRequirements} */
|
||||
const runtimeRequirements = [];
|
||||
|
||||
let str = "";
|
||||
for (const { id: prop } of referencedPropertiesInDestructuring) {
|
||||
switch (prop) {
|
||||
for (const prop of referencedPropertiesInDestructuring) {
|
||||
const value = hooks.propertyInDestructuring.call(prop);
|
||||
|
||||
if (value) {
|
||||
str += value;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (prop.id) {
|
||||
case "url":
|
||||
str += `url: ${importMetaUrl()},`;
|
||||
break;
|
||||
case "webpack":
|
||||
str += `webpack: ${importMetaWebpackVersion()},`;
|
||||
break;
|
||||
case "main":
|
||||
str += `main: ${RuntimeGlobals.moduleCache}[${RuntimeGlobals.entryModuleId}] === ${RuntimeGlobals.module},`;
|
||||
runtimeRequirements.push(
|
||||
RuntimeGlobals.moduleCache,
|
||||
RuntimeGlobals.entryModuleId,
|
||||
RuntimeGlobals.module
|
||||
);
|
||||
break;
|
||||
default:
|
||||
str += `[${JSON.stringify(
|
||||
prop
|
||||
)}]: ${importMetaUnknownProperty([prop])},`;
|
||||
prop.id
|
||||
)}]: ${importMetaUnknownProperty([prop.id])},`;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const dep = new ConstDependency(
|
||||
`({${str}})`,
|
||||
/** @type {Range} */ (metaProperty.range)
|
||||
/** @type {Range} */ (metaProperty.range),
|
||||
runtimeRequirements
|
||||
);
|
||||
dep.loc = /** @type {DependencyLocation} */ (metaProperty.loc);
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
@@ -197,18 +251,18 @@ class ImportMetaPlugin {
|
||||
);
|
||||
|
||||
// import.meta.webpack
|
||||
parser.hooks.typeof
|
||||
.for("import.meta.webpack")
|
||||
.tap(
|
||||
PLUGIN_NAME,
|
||||
toConstantDependency(parser, JSON.stringify("number"))
|
||||
);
|
||||
parser.hooks.expression
|
||||
.for("import.meta.webpack")
|
||||
.tap(
|
||||
PLUGIN_NAME,
|
||||
toConstantDependency(parser, importMetaWebpackVersion())
|
||||
);
|
||||
parser.hooks.typeof
|
||||
.for("import.meta.webpack")
|
||||
.tap(
|
||||
PLUGIN_NAME,
|
||||
toConstantDependency(parser, JSON.stringify("number"))
|
||||
);
|
||||
parser.hooks.evaluateTypeof
|
||||
.for("import.meta.webpack")
|
||||
.tap(PLUGIN_NAME, evaluateToString("number"));
|
||||
@@ -216,10 +270,44 @@ class ImportMetaPlugin {
|
||||
.for("import.meta.webpack")
|
||||
.tap(PLUGIN_NAME, evaluateToNumber(webpackVersion));
|
||||
|
||||
parser.hooks.expression
|
||||
.for("import.meta.main")
|
||||
.tap(
|
||||
PLUGIN_NAME,
|
||||
toConstantDependency(
|
||||
parser,
|
||||
`${RuntimeGlobals.moduleCache}[${RuntimeGlobals.entryModuleId}] === ${RuntimeGlobals.module}`,
|
||||
[
|
||||
RuntimeGlobals.moduleCache,
|
||||
RuntimeGlobals.entryModuleId,
|
||||
RuntimeGlobals.module
|
||||
]
|
||||
)
|
||||
);
|
||||
parser.hooks.typeof
|
||||
.for("import.meta.main")
|
||||
.tap(
|
||||
PLUGIN_NAME,
|
||||
toConstantDependency(parser, JSON.stringify("boolean"))
|
||||
);
|
||||
parser.hooks.evaluateTypeof
|
||||
.for("import.meta.main")
|
||||
.tap(PLUGIN_NAME, evaluateToString("boolean"));
|
||||
|
||||
// Unknown properties
|
||||
parser.hooks.unhandledExpressionMemberChain
|
||||
.for("import.meta")
|
||||
.tap(PLUGIN_NAME, (expr, members) => {
|
||||
// keep import.meta.env unknown property
|
||||
// don't evaluate import.meta.env.UNKNOWN_PROPERTY -> undefined.UNKNOWN_PROPERTY
|
||||
// `dirname` and `filename` logic in NodeStuffPlugin
|
||||
if (
|
||||
members[0] === "env" ||
|
||||
members[0] === "dirname" ||
|
||||
members[0] === "filename"
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
const dep = new ConstDependency(
|
||||
importMetaUnknownProperty(members),
|
||||
/** @type {Range} */ (expr.range)
|
||||
|
||||
40
node_modules/webpack/lib/dependencies/ImportParserPlugin.js
generated
vendored
Executable file → Normal file
40
node_modules/webpack/lib/dependencies/ImportParserPlugin.js
generated
vendored
Executable file → Normal file
@@ -17,6 +17,7 @@ const ContextDependencyHelpers = require("./ContextDependencyHelpers");
|
||||
const ImportContextDependency = require("./ImportContextDependency");
|
||||
const ImportDependency = require("./ImportDependency");
|
||||
const ImportEagerDependency = require("./ImportEagerDependency");
|
||||
const { ImportPhaseUtils, createGetImportPhase } = require("./ImportPhase");
|
||||
const ImportWeakDependency = require("./ImportWeakDependency");
|
||||
|
||||
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
||||
@@ -311,27 +312,11 @@ class ImportParserPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
let phase = expr.phase;
|
||||
if (!phase && importOptions && importOptions.webpackDefer !== undefined) {
|
||||
if (typeof importOptions.webpackDefer !== "boolean") {
|
||||
parser.state.module.addWarning(
|
||||
new UnsupportedFeatureWarning(
|
||||
`\`webpackDefer\` expected a boolean, but received: ${importOptions.webpackDefer}.`,
|
||||
/** @type {DependencyLocation} */ (expr.loc)
|
||||
)
|
||||
);
|
||||
} else if (importOptions.webpackDefer) {
|
||||
phase = "defer";
|
||||
}
|
||||
}
|
||||
if (phase === "defer") {
|
||||
parser.state.module.addWarning(
|
||||
new UnsupportedFeatureWarning(
|
||||
"import.defer() is not implemented yet.",
|
||||
/** @type {DependencyLocation} */ (expr.loc)
|
||||
)
|
||||
);
|
||||
}
|
||||
const phase = createGetImportPhase(this.options.deferImport)(
|
||||
parser,
|
||||
expr,
|
||||
() => importOptions
|
||||
);
|
||||
|
||||
if (importOptions) {
|
||||
if (importOptions.webpackIgnore !== undefined) {
|
||||
@@ -533,6 +518,7 @@ class ImportParserPlugin {
|
||||
/** @type {string} */ (param.string),
|
||||
/** @type {Range} */ (expr.range),
|
||||
exports,
|
||||
phase,
|
||||
attributes
|
||||
);
|
||||
parser.state.current.addDependency(dep);
|
||||
@@ -541,6 +527,7 @@ class ImportParserPlugin {
|
||||
/** @type {string} */ (param.string),
|
||||
/** @type {Range} */ (expr.range),
|
||||
exports,
|
||||
phase,
|
||||
attributes
|
||||
);
|
||||
parser.state.current.addDependency(dep);
|
||||
@@ -557,6 +544,7 @@ class ImportParserPlugin {
|
||||
/** @type {string} */ (param.string),
|
||||
/** @type {Range} */ (expr.range),
|
||||
exports,
|
||||
phase,
|
||||
attributes
|
||||
);
|
||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||
@@ -568,6 +556,16 @@ class ImportParserPlugin {
|
||||
if (mode === "weak") {
|
||||
mode = "async-weak";
|
||||
}
|
||||
|
||||
if (ImportPhaseUtils.isDefer(phase)) {
|
||||
parser.state.module.addWarning(
|
||||
new UnsupportedFeatureWarning(
|
||||
"import.defer() is not yet supported for ContextModule (the import path is a dynamic expression).",
|
||||
/** @type {DependencyLocation} */ (expr.loc)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const dep = ContextDependencyHelpers.create(
|
||||
ImportContextDependency,
|
||||
/** @type {Range} */ (expr.range),
|
||||
|
||||
121
node_modules/webpack/lib/dependencies/ImportPhase.js
generated
vendored
Normal file
121
node_modules/webpack/lib/dependencies/ImportPhase.js
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Haijie Xie @hai-x
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const memoize = require("../util/memoize");
|
||||
|
||||
const getCommentCompilationWarning = memoize(() =>
|
||||
require("../CommentCompilationWarning")
|
||||
);
|
||||
|
||||
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
||||
/** @typedef {import("../javascript/JavascriptParser").ExportAllDeclaration} ExportAllDeclaration */
|
||||
/** @typedef {import("../javascript/JavascriptParser").ExportNamedDeclaration} ExportNamedDeclaration */
|
||||
/** @typedef {import("../javascript/JavascriptParser").ImportDeclaration} ImportDeclaration */
|
||||
/** @typedef {import("../javascript/JavascriptParser").ImportExpression} ImportExpression */
|
||||
|
||||
/** @typedef {typeof ImportPhase.Evaluation | typeof ImportPhase.Defer | typeof ImportPhase.Source} ImportPhaseType */
|
||||
|
||||
const ImportPhase = Object.freeze({
|
||||
Evaluation: 0b00,
|
||||
Defer: 0b01,
|
||||
Source: 0b10
|
||||
});
|
||||
|
||||
/**
|
||||
* @typedef {object} ImportPhaseUtils
|
||||
* @property {(phase: ImportPhaseType) => boolean} isDefer true if phase is defer
|
||||
* @property {(phase: ImportPhaseType) => boolean} isSource true if phase is source
|
||||
*/
|
||||
|
||||
/** @type {ImportPhaseUtils} */
|
||||
const ImportPhaseUtils = {
|
||||
isDefer(phase) {
|
||||
return phase === ImportPhase.Defer;
|
||||
},
|
||||
isSource(phase) {
|
||||
return phase === ImportPhase.Source;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef {() => Record<string, EXPECTED_ANY> | null} GetCommentOptions
|
||||
*/
|
||||
|
||||
/**
|
||||
* @callback GetImportPhase
|
||||
* @param {JavascriptParser} parser parser
|
||||
* @param {ExportNamedDeclaration | ExportAllDeclaration | ImportDeclaration | ImportExpression} node node
|
||||
* @param {GetCommentOptions=} getCommentOptions optional function that returns the comment options object.
|
||||
* @returns {ImportPhaseType} import phase
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {boolean=} enableImportPhase enable import phase detection
|
||||
* @returns {GetImportPhase} evaluates the import phase for ast node
|
||||
*/
|
||||
function createGetImportPhase(enableImportPhase) {
|
||||
return (parser, node, getCommentOptions) => {
|
||||
if (!enableImportPhase) return ImportPhase.Evaluation;
|
||||
|
||||
// We now only support `defer import`
|
||||
const phaseBySyntax =
|
||||
"phase" in node && node.phase === "defer"
|
||||
? ImportPhase.Defer
|
||||
: ImportPhase.Evaluation;
|
||||
|
||||
if (!node.range) {
|
||||
return phaseBySyntax;
|
||||
}
|
||||
|
||||
getCommentOptions =
|
||||
getCommentOptions ||
|
||||
(() => {
|
||||
if (!node.range) return null;
|
||||
const { options, errors } = parser.parseCommentOptions(node.range);
|
||||
if (errors) {
|
||||
for (const e of errors) {
|
||||
const { comment } = e;
|
||||
if (!comment.loc) continue;
|
||||
|
||||
const CommentCompilationWarning = getCommentCompilationWarning();
|
||||
parser.state.module.addWarning(
|
||||
new CommentCompilationWarning(
|
||||
`Compilation error while processing magic comment(-s): /*${comment.value}*/: ${e.message}`,
|
||||
comment.loc
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
return options;
|
||||
});
|
||||
|
||||
const options = getCommentOptions();
|
||||
|
||||
if (!options || !options.webpackDefer) return phaseBySyntax;
|
||||
|
||||
const { webpackDefer } = options;
|
||||
if (typeof webpackDefer === "boolean") {
|
||||
return webpackDefer ? ImportPhase.Defer : phaseBySyntax;
|
||||
} else if (node.loc) {
|
||||
const CommentCompilationWarning = getCommentCompilationWarning();
|
||||
parser.state.module.addWarning(
|
||||
new CommentCompilationWarning(
|
||||
"webpackDefer magic comment expected a boolean value.",
|
||||
node.loc
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return phaseBySyntax;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ImportPhase,
|
||||
ImportPhaseUtils,
|
||||
createGetImportPhase
|
||||
};
|
||||
0
node_modules/webpack/lib/dependencies/ImportPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ImportPlugin.js
generated
vendored
Executable file → Normal file
9
node_modules/webpack/lib/dependencies/ImportWeakDependency.js
generated
vendored
Executable file → Normal file
9
node_modules/webpack/lib/dependencies/ImportWeakDependency.js
generated
vendored
Executable file → Normal file
@@ -16,16 +16,18 @@ const ImportDependency = require("./ImportDependency");
|
||||
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
||||
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
||||
/** @typedef {ImportDependency.RawReferencedExports} RawReferencedExports */
|
||||
/** @typedef {import("./ImportPhase").ImportPhaseType} ImportPhaseType */
|
||||
|
||||
class ImportWeakDependency extends ImportDependency {
|
||||
/**
|
||||
* @param {string} request the request
|
||||
* @param {Range} range expression range
|
||||
* @param {RawReferencedExports | null=} referencedExports list of referenced exports
|
||||
* @param {RawReferencedExports | null} referencedExports list of referenced exports
|
||||
* @param {ImportPhaseType} phase import phase
|
||||
* @param {ImportAttributes=} attributes import attributes
|
||||
*/
|
||||
constructor(request, range, referencedExports, attributes) {
|
||||
super(request, range, referencedExports, attributes);
|
||||
constructor(request, range, referencedExports, phase, attributes) {
|
||||
super(request, range, referencedExports, phase, attributes);
|
||||
this.weak = true;
|
||||
}
|
||||
|
||||
@@ -61,6 +63,7 @@ ImportWeakDependency.Template = class ImportDependencyTemplate extends (
|
||||
strict: /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule,
|
||||
message: "import() weak",
|
||||
weak: true,
|
||||
dependency: dep,
|
||||
runtimeRequirements
|
||||
});
|
||||
|
||||
|
||||
0
node_modules/webpack/lib/dependencies/JsonExportsDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/JsonExportsDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/LoaderDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/LoaderDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/LoaderImportDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/LoaderImportDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/LoaderPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/LoaderPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/LocalModule.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/LocalModule.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/LocalModuleDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/LocalModuleDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/LocalModulesHelpers.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/LocalModulesHelpers.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ModuleDecoratorDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ModuleDecoratorDependency.js
generated
vendored
Executable file → Normal file
6
node_modules/webpack/lib/dependencies/ModuleDependency.js
generated
vendored
Executable file → Normal file
6
node_modules/webpack/lib/dependencies/ModuleDependency.js
generated
vendored
Executable file → Normal file
@@ -18,11 +18,13 @@ const DependencyTemplate = require("../DependencyTemplate");
|
||||
class ModuleDependency extends Dependency {
|
||||
/**
|
||||
* @param {string} request request path which needs resolving
|
||||
* @param {number=} sourceOrder source order
|
||||
*/
|
||||
constructor(request) {
|
||||
constructor(request, sourceOrder) {
|
||||
super();
|
||||
this.request = request;
|
||||
this.userRequest = request;
|
||||
this.sourceOrder = sourceOrder;
|
||||
/** @type {Range | undefined} */
|
||||
this.range = undefined;
|
||||
this._context = undefined;
|
||||
@@ -74,6 +76,7 @@ class ModuleDependency extends Dependency {
|
||||
write(this.userRequest);
|
||||
write(this._context);
|
||||
write(this.range);
|
||||
write(this.sourceOrder);
|
||||
super.serialize(context);
|
||||
}
|
||||
|
||||
@@ -86,6 +89,7 @@ class ModuleDependency extends Dependency {
|
||||
this.userRequest = read();
|
||||
this._context = read();
|
||||
this.range = read();
|
||||
this.sourceOrder = read();
|
||||
super.deserialize(context);
|
||||
}
|
||||
}
|
||||
|
||||
0
node_modules/webpack/lib/dependencies/ModuleDependencyTemplateAsId.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ModuleDependencyTemplateAsId.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ModuleDependencyTemplateAsRequireId.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ModuleDependencyTemplateAsRequireId.js
generated
vendored
Executable file → Normal file
2
node_modules/webpack/lib/dependencies/ModuleHotAcceptDependency.js
generated
vendored
Executable file → Normal file
2
node_modules/webpack/lib/dependencies/ModuleHotAcceptDependency.js
generated
vendored
Executable file → Normal file
@@ -17,7 +17,7 @@ class ModuleHotAcceptDependency extends ModuleDependency {
|
||||
* @param {Range} range location in source code
|
||||
*/
|
||||
constructor(request, range) {
|
||||
super(request);
|
||||
super(request, Infinity);
|
||||
this.range = range;
|
||||
this.weak = true;
|
||||
}
|
||||
|
||||
0
node_modules/webpack/lib/dependencies/ModuleHotDeclineDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/ModuleHotDeclineDependency.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/getFunctionExpression.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/dependencies/getFunctionExpression.js
generated
vendored
Executable file → Normal file
Reference in New Issue
Block a user