Add JS-CATCH-FALLBACK-01 rule and update npm packages
Add PHP-ALIAS-01 rule: prohibit field aliasing in serialization 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
81
node_modules/webpack/lib/javascript/JavascriptModulesPlugin.js
generated
vendored
81
node_modules/webpack/lib/javascript/JavascriptModulesPlugin.js
generated
vendored
@@ -20,6 +20,7 @@ const Compilation = require("../Compilation");
|
||||
const { tryRunOrWebpackError } = require("../HookWebpackError");
|
||||
const HotUpdateChunk = require("../HotUpdateChunk");
|
||||
const InitFragment = require("../InitFragment");
|
||||
const { JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants");
|
||||
const {
|
||||
JAVASCRIPT_MODULE_TYPE_AUTO,
|
||||
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
||||
@@ -79,7 +80,7 @@ const chunkHasJs = (chunk, chunkGraph) => {
|
||||
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) return true;
|
||||
|
||||
return Boolean(
|
||||
chunkGraph.getChunkModulesIterableBySourceType(chunk, "javascript")
|
||||
chunkGraph.getChunkModulesIterableBySourceType(chunk, JAVASCRIPT_TYPE)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -99,7 +100,7 @@ const chunkHasRuntimeOrJs = (chunk, chunkGraph) => {
|
||||
}
|
||||
|
||||
return Boolean(
|
||||
chunkGraph.getChunkModulesIterableBySourceType(chunk, "javascript")
|
||||
chunkGraph.getChunkModulesIterableBySourceType(chunk, JAVASCRIPT_TYPE)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -181,7 +182,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
||||
* @property {ChunkGraph} chunkGraph the chunk graph
|
||||
* @property {CodeGenerationResults} codeGenerationResults results of code generation
|
||||
* @property {boolean | undefined} strictMode rendering in strict context
|
||||
* @property {boolean } inlined inlined
|
||||
* @property {boolean} inlined inlined
|
||||
* @property {boolean=} inlinedInIIFE the inlined entry module is wrapped in an IIFE
|
||||
*/
|
||||
|
||||
@@ -197,6 +198,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
||||
* @property {boolean | undefined} strictMode rendering in strict context
|
||||
* @property {boolean} factory true: renders as factory method, false: pure module content
|
||||
* @property {boolean=} inlinedInIIFE the inlined entry module is wrapped in an IIFE, existing only when `factory` is set to false
|
||||
* @property {boolean=} renderInObject render module in object container
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -276,7 +278,7 @@ class JavascriptModulesPlugin {
|
||||
|
||||
constructor(options = {}) {
|
||||
this.options = options;
|
||||
/** @type {WeakMap<Source, { source: Source, needModule:boolean, needExports: boolean, needRequire: boolean, needThisAsExports: boolean, needStrict: boolean | undefined }>} */
|
||||
/** @type {WeakMap<Source, { source: Source, needModule:boolean, needExports: boolean, needRequire: boolean, needThisAsExports: boolean, needStrict: boolean | undefined, renderShorthand: boolean }>} */
|
||||
this._moduleFactoryCache = new WeakMap();
|
||||
}
|
||||
|
||||
@@ -487,7 +489,7 @@ class JavascriptModulesPlugin {
|
||||
});
|
||||
const modules = chunkGraph.getChunkModulesIterableBySourceType(
|
||||
chunk,
|
||||
"javascript"
|
||||
JAVASCRIPT_TYPE
|
||||
);
|
||||
if (modules) {
|
||||
const xor = new StringXor();
|
||||
@@ -527,7 +529,8 @@ class JavascriptModulesPlugin {
|
||||
}
|
||||
);
|
||||
compilation.hooks.executeModule.tap(PLUGIN_NAME, (options, context) => {
|
||||
const source = options.codeGenerationResult.sources.get("javascript");
|
||||
const source =
|
||||
options.codeGenerationResult.sources.get(JAVASCRIPT_TYPE);
|
||||
if (source === undefined) return;
|
||||
const { module } = options;
|
||||
const code = source.source();
|
||||
@@ -615,11 +618,12 @@ class JavascriptModulesPlugin {
|
||||
runtimeTemplate,
|
||||
codeGenerationResults,
|
||||
strictMode,
|
||||
factory
|
||||
factory,
|
||||
renderInObject
|
||||
} = renderContext;
|
||||
try {
|
||||
const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
|
||||
const moduleSource = codeGenResult.sources.get("javascript");
|
||||
const moduleSource = codeGenResult.sources.get(JAVASCRIPT_TYPE);
|
||||
if (!moduleSource) return null;
|
||||
if (codeGenResult.data !== undefined) {
|
||||
const chunkInitFragments = codeGenResult.data.get("chunkInitFragments");
|
||||
@@ -654,6 +658,8 @@ class JavascriptModulesPlugin {
|
||||
const cacheEntry = this._moduleFactoryCache.get(
|
||||
moduleSourcePostContent
|
||||
);
|
||||
const renderShorthand =
|
||||
renderInObject === true && runtimeTemplate.supportsMethodShorthand();
|
||||
let source;
|
||||
if (
|
||||
cacheEntry &&
|
||||
@@ -661,7 +667,8 @@ class JavascriptModulesPlugin {
|
||||
cacheEntry.needExports === needExports &&
|
||||
cacheEntry.needRequire === needRequire &&
|
||||
cacheEntry.needThisAsExports === needThisAsExports &&
|
||||
cacheEntry.needStrict === needStrict
|
||||
cacheEntry.needStrict === needStrict &&
|
||||
cacheEntry.renderShorthand === renderShorthand
|
||||
) {
|
||||
source = cacheEntry.source;
|
||||
} else {
|
||||
@@ -682,16 +689,24 @@ class JavascriptModulesPlugin {
|
||||
);
|
||||
}
|
||||
if (needRequire) args.push(RuntimeGlobals.require);
|
||||
if (!needThisAsExports && runtimeTemplate.supportsArrowFunction()) {
|
||||
|
||||
if (renderShorthand) {
|
||||
// we can optimize function to methodShorthand if render module factory in object
|
||||
factorySource.add(`(${args.join(", ")}) {\n\n`);
|
||||
} else if (
|
||||
!needThisAsExports &&
|
||||
runtimeTemplate.supportsArrowFunction()
|
||||
) {
|
||||
factorySource.add(`/***/ ((${args.join(", ")}) => {\n\n`);
|
||||
} else {
|
||||
factorySource.add(`/***/ (function(${args.join(", ")}) {\n\n`);
|
||||
}
|
||||
|
||||
if (needStrict) {
|
||||
factorySource.add('"use strict";\n');
|
||||
}
|
||||
factorySource.add(moduleSourcePostContent);
|
||||
factorySource.add("\n\n/***/ })");
|
||||
factorySource.add(`\n\n/***/ }${renderShorthand ? "" : ")"}`);
|
||||
source = new CachedSource(factorySource);
|
||||
this._moduleFactoryCache.set(moduleSourcePostContent, {
|
||||
source,
|
||||
@@ -699,7 +714,8 @@ class JavascriptModulesPlugin {
|
||||
needExports,
|
||||
needRequire,
|
||||
needThisAsExports,
|
||||
needStrict
|
||||
needStrict,
|
||||
renderShorthand
|
||||
});
|
||||
}
|
||||
moduleSourcePostContainer = tryRunOrWebpackError(
|
||||
@@ -734,7 +750,7 @@ class JavascriptModulesPlugin {
|
||||
const { chunk, chunkGraph } = renderContext;
|
||||
const modules = chunkGraph.getOrderedChunkModulesIterableBySourceType(
|
||||
chunk,
|
||||
"javascript",
|
||||
JAVASCRIPT_TYPE,
|
||||
compareModulesByIdOrIdentifier(chunkGraph)
|
||||
);
|
||||
const allModules = modules ? [...modules] : [];
|
||||
@@ -757,12 +773,15 @@ class JavascriptModulesPlugin {
|
||||
strictMode: allStrict
|
||||
};
|
||||
const moduleSources =
|
||||
Template.renderChunkModules(chunkRenderContext, allModules, (module) =>
|
||||
this.renderModule(
|
||||
module,
|
||||
{ ...chunkRenderContext, factory: true },
|
||||
hooks
|
||||
)
|
||||
Template.renderChunkModules(
|
||||
chunkRenderContext,
|
||||
allModules,
|
||||
(module, renderInObject) =>
|
||||
this.renderModule(
|
||||
module,
|
||||
{ ...chunkRenderContext, factory: true, renderInObject },
|
||||
hooks
|
||||
)
|
||||
) || new RawSource("{}");
|
||||
let source = tryRunOrWebpackError(
|
||||
() => hooks.renderChunk.call(moduleSources, chunkRenderContext),
|
||||
@@ -818,7 +837,7 @@ class JavascriptModulesPlugin {
|
||||
const allModules = [
|
||||
...(chunkGraph.getOrderedChunkModulesIterableBySourceType(
|
||||
chunk,
|
||||
"javascript",
|
||||
JAVASCRIPT_TYPE,
|
||||
compareModulesByIdOrIdentifier(chunkGraph)
|
||||
) || [])
|
||||
];
|
||||
@@ -874,10 +893,10 @@ class JavascriptModulesPlugin {
|
||||
(m) => !(/** @type {Set<Module>} */ (inlinedModules).has(m))
|
||||
)
|
||||
: allModules,
|
||||
(module) =>
|
||||
(module, renderInObject) =>
|
||||
this.renderModule(
|
||||
module,
|
||||
{ ...chunkRenderContext, factory: true },
|
||||
{ ...chunkRenderContext, factory: true, renderInObject },
|
||||
hooks
|
||||
),
|
||||
prefix
|
||||
@@ -1280,7 +1299,9 @@ class JavascriptModulesPlugin {
|
||||
entryModule,
|
||||
entrypoint
|
||||
] of chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)) {
|
||||
if (!chunkGraph.getModuleSourceTypes(entryModule).has("javascript")) {
|
||||
if (
|
||||
!chunkGraph.getModuleSourceTypes(entryModule).has(JAVASCRIPT_TYPE)
|
||||
) {
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
@@ -1540,6 +1561,19 @@ class JavascriptModulesPlugin {
|
||||
])
|
||||
: Template.indent("return cachedModule.exports;"),
|
||||
"}",
|
||||
// Add helpful error message in development mode when module is not found
|
||||
...(outputOptions.pathinfo
|
||||
? [
|
||||
"// Check if module exists (development only)",
|
||||
"if (__webpack_modules__[moduleId] === undefined) {",
|
||||
Template.indent([
|
||||
'var e = new Error("Cannot find module \'" + moduleId + "\'");',
|
||||
"e.code = 'MODULE_NOT_FOUND';",
|
||||
"throw e;"
|
||||
]),
|
||||
"}"
|
||||
]
|
||||
: []),
|
||||
"// Create a new module (and put it into the cache)",
|
||||
"var module = __webpack_module_cache__[moduleId] = {",
|
||||
Template.indent([
|
||||
@@ -1652,7 +1686,6 @@ class JavascriptModulesPlugin {
|
||||
const inlinedModulesToInfo = new Map();
|
||||
/** @type {Set<string>} */
|
||||
const nonInlinedModuleThroughIdentifiers = new Set();
|
||||
/** @type {Map<Module, Source>} */
|
||||
|
||||
for (const m of allModules) {
|
||||
const isInlinedModule = inlinedModules && inlinedModules.has(m);
|
||||
|
||||
Reference in New Issue
Block a user