Files
rea/src/native/parsers/demangle.ts
T
Iwakurakaoru0822andClaude Opus 5.5 6c88094da4 fix(native): pass Swift symbols to swift-demangle as operands
`swift-demangle` parsed a symbol beginning with `-` as an option, so
`-help` replaced the results with usage text and the call failed as
unreadable output. A symbol containing a line feed split into extra
output records, and the CRLF-tolerant parser stripped a carriage return
that belonged to the final symbol.

Pass the symbols after `--`, split records on the LF the demangler
emits, and reject multi-line symbols in the shared CLI/MCP input schema.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 22:40:19 -07:00

37 lines
1.0 KiB
TypeScript

import { z } from "zod";
const resultSchema = z.object({
input: z.string(),
output: z.string(),
status: z.enum(["demangled", "unchanged", "invalid"]),
});
/**
* Preserve input ordering while parsing `swift-demangle --compact` lines.
* The demangler ends each record with LF, so a carriage return belongs to the
* symbol text.
*/
export const parseDemangledSymbols = (
inputs: readonly string[],
output: string,
) => {
const lines = output.replace(/\n$/u, "").split("\n");
if (lines.length !== inputs.length)
throw new TypeError("swift-demangle output count does not match input");
return inputs.map((input, index) => {
const value = lines[index];
if (value === undefined)
throw new TypeError("swift-demangle omitted an output line");
return resultSchema.parse({
input,
output: value,
status:
value === input
? input.startsWith("$s") || input.startsWith("_$s")
? "invalid"
: "unchanged"
: "demangled",
});
});
};