oven-sh/bun · error · SyntaxError

Could not parse parameters for function

Error message

Could not parse parameters for function ${name}:
${contents.slice(0, contents.indexOf("\n"))}

What it means

SyntaxError in bundle-functions.ts: after the function name and optional generics, the parameter list did not match /^\(([^)]*)\)(?:\s*:\s*([^{\n]+))?\s*{?/. Note the inner pattern excludes `)`, so default values or types containing parentheses inside the parameter list break the match. The message prints the offending line for diagnosis.

Solutions

  1. Remove parentheses inside parameter default values or type annotations, or extract them into a type alias
  2. Broaden the parameter regex in bundle-functions.ts to allow nested parentheses
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/codegen/bundle-functions.ts:235 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/07859e39c8d5e868. Report an issue: GitHub.

Appendix: source

Thrown at src/codegen/bundle-functions.ts:235

          }
        }

        if (depth > 0) {
          throw new SyntaxError(
            `Function ${name} has an unclosed generic type. Missing ${depth} closing angle bracket(s).`,
          );
        }
        remaining = remaining.slice(cursor).trimStart();
      }

      // parse function parameters
      assert(
        remaining.startsWith("("),
        new SyntaxError(`Function ${name} is missing parameter list start. Found:\n\n\t${remaining.slice(0, 100)}`),
      );
      const paramMatch = remaining.match(/^\(([^)]*)\)(?:\s*:\s*([^{\n]+))?\s*{?/);
      if (!paramMatch)
        throw new SyntaxError(
          `Could not parse parameters for function ${name}:\n` + contents.slice(0, contents.indexOf("\n")),
        );
      const paramString = paramMatch[1];
      const params =
        paramString.trim().length === 0 ? [] : paramString.split(",").map(x => x.replace(/:.+$/, "").trim());
      if (params[0] === "this") {
        params.shift();
      }

      const { result, rest } = sliceSourceCode(remaining.slice(paramMatch[0].length - 1), true, x =>
        globalThis.requireTransformer(x, SRC_DIR + "/" + basename),
      );

      const source = result.trim().slice(2, -1);
      const constEnumsUsedInFunction: string[] = [];
      if (topLevelEnums.length) {
        // If the function references a top-level const enum let's add the code
        // to the top-level scope of the function so that the transpiler will

View on GitHub (pinned to 8c5296ac45)