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:
57
node_modules/webpack/lib/dependencies/ImportMetaPlugin.js
generated
vendored
57
node_modules/webpack/lib/dependencies/ImportMetaPlugin.js
generated
vendored
@@ -8,6 +8,7 @@
|
||||
const { pathToFileURL } = require("url");
|
||||
const { SyncBailHook } = require("tapable");
|
||||
const Compilation = require("../Compilation");
|
||||
const DefinePlugin = require("../DefinePlugin");
|
||||
const ModuleDependencyWarning = require("../ModuleDependencyWarning");
|
||||
const {
|
||||
JAVASCRIPT_MODULE_TYPE_AUTO,
|
||||
@@ -43,6 +44,31 @@ const getCriticalDependencyWarning = memoize(() =>
|
||||
|
||||
const PLUGIN_NAME = "ImportMetaPlugin";
|
||||
|
||||
/**
|
||||
* Collect import.meta.env definitions from DefinePlugin and build JSON string
|
||||
* @param {Compilation} compilation the compilation
|
||||
* @returns {string} env object as JSON string
|
||||
*/
|
||||
const collectImportMetaEnvDefinitions = (compilation) => {
|
||||
const definePluginHooks = DefinePlugin.getCompilationHooks(compilation);
|
||||
const definitions = definePluginHooks.definitions.call({});
|
||||
if (!definitions) {
|
||||
return "{}";
|
||||
}
|
||||
|
||||
/** @type {string[]} */
|
||||
const pairs = [];
|
||||
for (const key of Object.keys(definitions)) {
|
||||
if (key.startsWith("import.meta.env.")) {
|
||||
const envKey = key.slice("import.meta.env.".length);
|
||||
const value = definitions[key];
|
||||
pairs.push(`${JSON.stringify(envKey)}:${value}`);
|
||||
}
|
||||
}
|
||||
|
||||
return `{${pairs.join(",")}}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef {object} ImportMetaPluginHooks
|
||||
* @property {SyncBailHook<[DestructuringAssignmentProperty], string | void>} propertyInDestructuring
|
||||
@@ -294,6 +320,37 @@ class ImportMetaPlugin {
|
||||
.for("import.meta.main")
|
||||
.tap(PLUGIN_NAME, evaluateToString("boolean"));
|
||||
|
||||
// import.meta.env
|
||||
parser.hooks.typeof
|
||||
.for("import.meta.env")
|
||||
.tap(
|
||||
PLUGIN_NAME,
|
||||
toConstantDependency(parser, JSON.stringify("object"))
|
||||
);
|
||||
parser.hooks.expression
|
||||
.for("import.meta.env")
|
||||
.tap(PLUGIN_NAME, (expr) => {
|
||||
const envCode = collectImportMetaEnvDefinitions(compilation);
|
||||
const dep = new ConstDependency(
|
||||
envCode,
|
||||
/** @type {Range} */ (expr.range)
|
||||
);
|
||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
});
|
||||
parser.hooks.evaluateTypeof
|
||||
.for("import.meta.env")
|
||||
.tap(PLUGIN_NAME, evaluateToString("object"));
|
||||
parser.hooks.evaluateIdentifier
|
||||
.for("import.meta.env")
|
||||
.tap(PLUGIN_NAME, (expr) =>
|
||||
new BasicEvaluatedExpression()
|
||||
.setTruthy()
|
||||
.setSideEffects(false)
|
||||
.setRange(/** @type {Range} */ (expr.range))
|
||||
);
|
||||
|
||||
// Unknown properties
|
||||
parser.hooks.unhandledExpressionMemberChain
|
||||
.for("import.meta")
|
||||
|
||||
Reference in New Issue
Block a user