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
pluginsis not an array, or a member is not an object with a unique, non-emptyname, atransformfunction, anenforceof"pre"or"post"(or none), and well-formedimports. 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
}