ZIm/crates/eval/examples/buffer_string_input_support/prompt.md
2025-04-15 16:52:08 +00:00

840 B

I need to extend the SWC parsing APIs to support both Buffer and string inputs for the source code. Please update the parse and parse_sync functions to accept Either<Buffer, String> instead of just String. Add a helper function to convert the Either type into a UTF-8 string, using String::from_utf8_lossy for buffers to handle invalid characters gracefully. Ensure the TypeScript definitions in binding.d.ts reflect the new parameter types. Include unit tests for both buffer and string inputs in api_test.js, verifying that asynchronous and synchronous parsing produce identical results regardless of input type. Maintain backward compatibility with existing string-based calls and ensure the filename fallback logic remains unchanged. Simplify the src handling to avoid code duplication between async/sync paths.