nodejs / nodejs/userland-migrations
spec: `is-web-assembly-compiled-module`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 85
- Forks
- 55
- Avg merge
- 3d 11h
- Merged PRs (30d)
- 9
Description
Description
Since util.types.isWebAssemblyCompiledModule is deprecated (DEP0177) and has reached End-of-Life status in Node.js v20.12.0, we should provide a codemod to replace it.
- The codemod should replace
util.types.isWebAssemblyCompiledModule(value)withvalue instanceof WebAssembly.Module. - The codemod should handle both CommonJS and ESM import patterns.
- The codemod should preserve the logical context in which the function is used.
- The codemod should handle destructured imports from
util.types.
Additional Information
Note that util.types.isWebAssemblyCompiledModule() was removed in Node.js v20.12.0. The function was deprecated because it was a specialized type-checking utility that can be replaced with the standard instanceof operator. Instead of util.types.isWebAssemblyCompiledModule(value), developers should use value instanceof WebAssembly.Module.
The instanceof operator provides the same functionality and is a more idiomatic JavaScript approach for type checking.
Examples
Example 1: Basic usage with CommonJS
Before:
const util = require("node:util");
if (util.types.isWebAssemblyCompiledModule(value)) {
console.log("It's a WebAssembly module");
}
After:
if (value instanceof WebAssembly.Module) {
console.log("It's a WebAssembly module");
}
Example 2: Destructured import CommonJS
Before:
const { types } = require("node:util");
const result = types.isWebAssemblyCompiledModule(module);
After:
const result = module instanceof WebAssembly.Module;
Example 3: Direct destructured function import
Before:
const { isWebAssemblyCompiledModule } = require("node:util").types;
if (isWebAssemblyCompiledModule(compiledModule)) {
// do something
}
After:
if (compiledModule instanceof WebAssembly.Module) {
// do something
}
Example 4: ESM import
Before:
import util from "node:util";
const isModule = util.types.isWebAssemblyCompiledModule(value);
After:
const isModule = value instanceof WebAssembly.Module;
Example 5: ESM named import
Before:
import { types } from "node:util";
if (types.isWebAssemblyCompiledModule(obj)) {
return true;
}
After:
if (obj instanceof WebAssembly.Module) {
return true;
}
Example 6: In conditional expression
Before:
const util = require("node:util");
const check = util.types.isWebAssemblyCompiledModule(data) ? "module" : "not module";
After:
const check = data instanceof WebAssembly.Module ? "module" : "not module";
Example 7: In function return statement
Before:
const { types } = require("node:util");
function isWasmModule(value) {
return types.isWebAssemblyCompiledModule(value);
}
After:
function isWasmModule(value) {
return value instanceof WebAssembly.Module;
}
Example 8: Negated condition
Before:
const util = require("node:util");
if (!util.types.isWebAssemblyCompiledModule(value)) {
throw new Error("Not a WebAssembly module");
}
After:
if (!(value instanceof WebAssembly.Module)) {
throw new Error("Not a WebAssembly module");
}
Refs
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.