LegacyAsyncFunction

LegacyAsyncFunction: ((this: LegacyPluginThis, done: ((result: LegacyValue) => void)) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, arg4: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, arg4: LegacyValue, arg5: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, arg4: LegacyValue, arg5: LegacyValue, arg6: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, args: [LegacyValue[], LegacyAsyncFunctionDone]) => void)

カスタムSass関数を実装する非同期コールバックです。これはfunctionsに渡すことができますが、renderの場合のみです。

非同期関数はundefinedを返す必要があります。その最後の引数は常にコールバックとなり、実行が完了したら関数の結果とともにコールバックを呼び出す必要があります。

これがエラーをスローした場合、Sassはそのエラーメッセージで関数が失敗したとみなします。

sass.render({
file: 'style.scss',
functions: {
"sum($arg1, $arg2)": (arg1, arg2, done) => {
if (!(arg1 instanceof sass.types.Number)) {
throw new Error("$arg1: Expected a number");
} else if (!(arg2 instanceof sass.types.Number)) {
throw new Error("$arg2: Expected a number");
}
done(new sass.types.Number(arg1.getValue() + arg2.getValue()));
}
}
}, (result, error) => {
// ...
});

これは、functionsに渡されるシグネチャで宣言されている各引数に対して1つの引数が渡されます。シグネチャが任意の引数を取る場合、それらはコールバックの前の最後の引数として、単一の引数リストとして渡されます。

非推奨

これは、レガシーなrenderおよびrenderSync APIでのみ動作します。CustomFunctioncompilecompileStringcompileAsync、およびcompileStringAsyncとともに使用してください