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的簽章中宣告的每個參數,都會傳遞給這個函式一個對應的參數。如果簽章接受任意數量參數,則它們會在回呼之前的最後一個參數中,以單個參數列表的形式傳遞。

已棄用

這僅適用於舊版renderrenderSync API。請改用CustomFunction搭配compilecompileStringcompileAsynccompileStringAsync