W3cubDocs

/Sass

LegacySyncFunction

LegacySyncFunction: ((this: LegacyPluginThis, args: LegacyValue[]) => LegacyValue)

Type declaration

    • (this: LegacyPluginThis, args: LegacyValue[]): LegacyValue
    • A synchronous callback that implements a custom Sass function. This can be passed to functions for either render or renderSync.

      If this throws an error, Sass will treat that as the function failing with that error message.

      constresult = sass.renderSync({
      file:'style.scss',
      functions: {
      "sum($arg1, $arg2)": (arg1, arg2) => {
      if (!(arg1instanceofsass.types.Number)) {
      thrownewError("$arg1: Expected a number");
      } elseif (!(arg2instanceofsass.types.Number)) {
      thrownewError("$arg2: Expected a number");
      }
      returnnewsass.types.Number(arg1.getValue() + arg2.getValue());
      }
      }
      });

      Deprecated

      This only works with the legacy render and renderSync APIs. Use CustomFunction with compile, compileString, compileAsync, and compileStringAsync instead.

      Parameters

      Returns LegacyValue

© 2006–2025 the Sass team, and numerous contributors
Licensed under the MIT License.
https://sass-lang.com/documentation/js-api/types/LegacySyncFunction