From 9bce51f651aad297ef9eb6df832bfdaf1de05d84 Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期三, 22 四月 2026 14:27:54 +0800
Subject: [PATCH] 青岛推送
---
node_modules/webpack/lib/wasm-async/AsyncWebAssemblyParser.js | 37 +++++++++++++++++++++++++++++++------
1 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/node_modules/webpack/lib/wasm-async/AsyncWebAssemblyParser.js b/node_modules/webpack/lib/wasm-async/AsyncWebAssemblyParser.js
index 9da0cde..e69cff3 100644
--- a/node_modules/webpack/lib/wasm-async/AsyncWebAssemblyParser.js
+++ b/node_modules/webpack/lib/wasm-async/AsyncWebAssemblyParser.js
@@ -12,10 +12,14 @@
const StaticExportsDependency = require("../dependencies/StaticExportsDependency");
const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
+/** @typedef {import("./AsyncWebAssemblyModulesPlugin").AsyncWasmModuleClass} AsyncWasmModule */
/** @typedef {import("../Module").BuildInfo} BuildInfo */
/** @typedef {import("../Module").BuildMeta} BuildMeta */
+/** @typedef {import("../NormalModule")} NormalModule */
/** @typedef {import("../Parser").ParserState} ParserState */
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
+
+const WASM_HEADER = Buffer.from([0x00, 0x61, 0x73, 0x6d]);
const decoderOpts = {
ignoreCodeSection: true,
@@ -27,6 +31,7 @@
class WebAssemblyParser extends Parser {
/**
+ * Parses the provided source and updates the parser state.
* @param {string | Buffer | PreparsedAst} source the source to parse
* @param {ParserState} state the parser state
* @returns {ParserState} the parser state
@@ -36,18 +41,38 @@
throw new Error("WebAssemblyParser input must be a Buffer");
}
- // flag it as async module
- const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
- buildInfo.strict = true;
- const BuildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
- BuildMeta.exportsType = "namespace";
- BuildMeta.async = true;
+ const buildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
+ buildMeta.exportsType = "namespace";
+ buildMeta.async = true;
+
EnvironmentNotSupportAsyncWarning.check(
state.module,
state.compilation.runtimeTemplate,
"asyncWebAssembly"
);
+ // flag it as async module
+ const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
+
+ buildInfo.strict = true;
+
+ if (/** @type {AsyncWasmModule} */ (state.module).phase === "source") {
+ // For source phase, only validate magic header
+ if (source.length < 4 || !source.subarray(0, 4).equals(WASM_HEADER)) {
+ throw new Error(
+ "Source phase imports require valid WebAssembly modules. Invalid magic header (expected \\0asm)."
+ );
+ }
+
+ // Source phase exports the WebAssembly.Module as default
+ state.module.addDependency(
+ new StaticExportsDependency(["default"], false)
+ );
+
+ // Skip full parsing - no exports/imports needed for source phase
+ return state;
+ }
+
// parse it
const program = decode(source, decoderOpts);
const module = program.body[0];
--
Gitblit v1.9.3