[]previous and next page

validatePlugins

Checks a list of compiler plugins and returns it as a frozen copy.

Checks a list of compiler plugins and returns it as a frozen copy. The same list (or a list this function returned) is accepted again at no cost.

Import#

ts
import { validatePlugins } from "@shadow-js/compiler";

Signature#

ts
function validatePlugins(
  plugins: unknown,
  label = "compile(): plugins",
): readonly CompilerPlugin[]

Parameters#

Name Description
plugins The value to check, normally the plugins option.
label How the error messages name the option.

Returns#

The plugins in the given order.

Throws#

  • TypeError When plugins is not an array, or a member is not an object with a unique, non-empty name, a transform function, an enforce of "pre" or "post" (or none), and well-formed imports. The message names the member (plugins[1].name).

Examples#

ts
import { validatePlugins } from "@shadow-js/compiler";

const list = validatePlugins([{ name: "noop", transform() {} }]);
console.log(list.length); // 1
try {
  validatePlugins([{ name: "", transform() {} }]);
} catch (error) {
  console.log(String(error).includes("plugins[0].name")); // true
}