Skip to content

spec: is-web-assembly-compiled-module #282

@AugustinMauroy

Description

@AugustinMauroy

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) with value 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

Metadata

Metadata

Assignees

Labels

dep:EoLMigration handles deprecation introduced in an EoL version of nodedep:v20Migration handles deprecation introduced in node v20good first issueGood for newcomershelp wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions