Socket
Socket
Sign inDemoInstall

webpack

Package Overview
Dependencies
76
Maintainers
4
Versions
832
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.88.2 to 5.89.0

lib/util/chainedImports.js

33

lib/dependencies/CommonJsFullRequireDependency.js

@@ -10,2 +10,3 @@ /*

const { equals } = require("../util/ArrayHelpers");
const { getTrimmedIdsAndRange } = require("../util/chainedImports");
const makeSerializable = require("../util/makeSerializable");

@@ -30,7 +31,14 @@ const propertyAccess = require("../util/propertyAccess");

* @param {string[]} names accessed properties on module
* @param {Range[]=} idRanges ranges for members of ids; the two arrays are right-aligned
*/
constructor(request, range, names) {
constructor(
request,
range,
names,
idRanges /* TODO webpack 6 make this non-optional. It must always be set to properly trim ids. */
) {
super(request);
this.range = range;
this.names = names;
this.idRanges = idRanges;
this.call = false;

@@ -65,2 +73,3 @@ this.asiSafe = undefined;

write(this.names);
write(this.idRanges);
write(this.call);

@@ -77,2 +86,3 @@ write(this.asiSafe);

this.names = read();
this.idRanges = read();
this.call = read();

@@ -124,11 +134,22 @@ this.asiSafe = read();

});
const {
trimmedRange: [trimmedRangeStart, trimmedRangeEnd],
trimmedIds
} = getTrimmedIdsAndRange(
dep.names,
dep.range,
dep.idRanges,
moduleGraph,
dep
);
if (importedModule) {
const ids = dep.names;
const usedImported = moduleGraph
.getExportsInfo(importedModule)
.getUsedName(ids, runtime);
.getUsedName(trimmedIds, runtime);
if (usedImported) {
const comment = equals(usedImported, ids)
const comment = equals(usedImported, trimmedIds)
? ""
: Template.toNormalComment(propertyAccess(ids)) + " ";
: Template.toNormalComment(propertyAccess(trimmedIds)) + " ";
const access = `${comment}${propertyAccess(usedImported)}`;

@@ -141,3 +162,3 @@ requireExpr =

}
source.replace(dep.range[0], dep.range[1] - 1, requireExpr);
source.replace(trimmedRangeStart, trimmedRangeEnd - 1, requireExpr);
}

@@ -144,0 +165,0 @@ };

@@ -382,5 +382,12 @@ /*

* @param {string[]} members members
* @param {Range[]} memberRanges member ranges
* @returns {boolean | void} true when handled
*/
const chainHandler = (expr, calleeMembers, callExpr, members) => {
const chainHandler = (
expr,
calleeMembers,
callExpr,
members,
memberRanges
) => {
if (callExpr.arguments.length !== 1) return;

@@ -395,3 +402,4 @@ const param = parser.evaluateExpression(callExpr.arguments[0]);

/** @type {Range} */ (expr.range),
members
members,
/** @type {Range[]} */ memberRanges
);

@@ -412,5 +420,12 @@ dep.asiSafe = !parser.isAsiPosition(

* @param {string[]} members members
* @param {Range[]} memberRanges member ranges
* @returns {boolean | void} true when handled
*/
const callChainHandler = (expr, calleeMembers, callExpr, members) => {
const callChainHandler = (
expr,
calleeMembers,
callExpr,
members,
memberRanges
) => {
if (callExpr.arguments.length !== 1) return;

@@ -425,3 +440,4 @@ const param = parser.evaluateExpression(callExpr.arguments[0]);

/** @type {Range} */ (expr.callee.range),
members
members,
/** @type {Range[]} */ memberRanges
);

@@ -428,0 +444,0 @@ dep.call = true;

76

lib/dependencies/HarmonyImportSpecifierDependency.js

@@ -12,2 +12,3 @@ /*

} = require("../optimize/InnerGraph");
const { getTrimmedIdsAndRange } = require("../util/chainedImports");
const makeSerializable = require("../util/makeSerializable");

@@ -328,27 +329,13 @@ const propertyAccess = require("../util/propertyAccess");

const ids = dep.getIds(moduleGraph); // determine minimal set of IDs.
let trimmedIds = this._trimIdsToThoseImported(ids, moduleGraph, dep);
const {
trimmedRange: [trimmedRangeStart, trimmedRangeEnd],
trimmedIds
} = getTrimmedIdsAndRange(
dep.getIds(moduleGraph),
dep.range,
dep.idRanges,
moduleGraph,
dep
);
let [rangeStart, rangeEnd] = dep.range;
if (trimmedIds.length !== ids.length) {
// The array returned from dep.idRanges is right-aligned with the array returned from dep.getIds.
// Meaning, the two arrays may not always have the same number of elements, but the last element of
// dep.idRanges corresponds to [the expression fragment to the left of] the last element of dep.getIds.
// Use this to find the correct replacement range based on the number of ids that were trimmed.
const idx =
dep.idRanges === undefined
? -1 /* trigger failure case below */
: dep.idRanges.length + (trimmedIds.length - ids.length);
if (idx < 0 || idx >= dep.idRanges.length) {
// cspell:ignore minifiers
// Should not happen but we can't throw an error here because of backward compatibility with
// external plugins in wp5. Instead, we just disable trimming for now. This may break some minifiers.
trimmedIds = ids;
// TODO webpack 6 remove the "trimmedIds = ids" above and uncomment the following line instead.
// throw new Error("Missing range starts data for id replacement trimming.");
} else {
[rangeStart, rangeEnd] = dep.idRanges[idx];
}
}
const exportExpr = this._getCodeForIds(

@@ -361,5 +348,5 @@ dep,

if (dep.shorthand) {
source.insert(rangeEnd, `: ${exportExpr}`);
source.insert(trimmedRangeEnd, `: ${exportExpr}`);
} else {
source.replace(rangeStart, rangeEnd - 1, exportExpr);
source.replace(trimmedRangeStart, trimmedRangeEnd - 1, exportExpr);
}

@@ -369,39 +356,2 @@ }

/**
* @summary Determine which IDs in the id chain are actually referring to namespaces or imports,
* and which are deeper member accessors on the imported object. Only the former should be re-rendered.
* @param {string[]} ids ids
* @param {ModuleGraph} moduleGraph moduleGraph
* @param {HarmonyImportSpecifierDependency} dependency dependency
* @returns {string[]} generated code
*/
_trimIdsToThoseImported(ids, moduleGraph, dependency) {
/** @type {string[]} */
let trimmedIds = [];
const exportsInfo = moduleGraph.getExportsInfo(
/** @type {Module} */ (moduleGraph.getModule(dependency))
);
let currentExportsInfo = /** @type {ExportsInfo=} */ exportsInfo;
for (let i = 0; i < ids.length; i++) {
if (i === 0 && ids[i] === "default") {
continue; // ExportInfo for the next level under default is still at the root ExportsInfo, so don't advance currentExportsInfo
}
const exportInfo = currentExportsInfo.getExportInfo(ids[i]);
if (exportInfo.provided === false) {
// json imports have nested ExportInfo for elements that things that are not actually exported, so check .provided
trimmedIds = ids.slice(0, i);
break;
}
const nestedInfo = exportInfo.getNestedExportsInfo();
if (!nestedInfo) {
// once all nested exports are traversed, the next item is the actual import so stop there
trimmedIds = ids.slice(0, i + 1);
break;
}
currentExportsInfo = nestedInfo;
}
// Never trim to nothing. This can happen for invalid imports (e.g. import { notThere } from "./module", or import { anything } from "./missingModule")
return trimmedIds.length ? trimmedIds : ids;
}
/**
* @param {HarmonyImportSpecifierDependency} dep dependency

@@ -408,0 +358,0 @@ * @param {ReplaceSource} source source

{
"name": "webpack",
"version": "5.88.2",
"version": "5.89.0",
"author": "Tobias Koppers @sokra",

@@ -5,0 +5,0 @@ "description": "Packs ECMAScript/CommonJs/AMD modules for the browser. Allows you to split your codebase into multiple bundles, which can be loaded on demand. Supports loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc