fix: avoid re-stringify per await by single-pass parse#5
Open
fix: avoid re-stringify per await by single-pass parse#5
Conversation
- stringify(program, leafSerializer) accepts custom leaf serialization - parse(program, leafDeserializer) accepts custom leaf deserialization - leaf values wrapped as ['leaf', serializedString] nodes - supports Date, RegExp, BigInt, Set, Map, and undefined via superjson - preserves undefined in objects using internal sentinel mechanism
- simplify defaultLeafDeserializer to remove unreachable branch - add test for default deserializer when not provided - add test for fallback to default deserializer when null passed - add test to exercise defensive undefined parameter handling - achieves 100% branch coverage
- remove unused Symbol('replaced') that was vestigial from replacer pattern
- move awaitId tracking into state object passed to transformValue
- reset awaitId per stringify() call for proper isolation
- simplifies code path and removes global mutable state per-call
- JSON.parse reviver can only receive null (not undefined) - replace isNil(value) with direct null check - remove unused is-nil import
- document transformValue behavior for stringify - document resolveAwaitedValues behavior for parse - document restoreUndefined purpose - improve code readability through strategic comments
document the leaf (de)serializer API: - explain default JSON limitation - show how to extend with superjson - provide complete example with Date, RegExp, BigInt, Map, Set - clarify leaf wrapper format for safety
- add test to verify ['leaf', 1, 2, 3] is properly quoted and unquoted - fix: add 'leaf' to keywords list so it's quoted when appearing as array data - ensures leaf marker is not confused with actual leaf data
…e coverage - Added getTypeInfo() helper for better error messages - Improved assertion messages with type information - Added property test for type distinctness (different primitives have different serializations) - Added property test for serialization stability (idempotence) - Better error handling and reporting in all property tests - Now running 6 property tests with comprehensive coverage - All 60 tests passing
- Converted all source files (.mjs) to TypeScript (.ts) in src/ directory - Converted all test files (.test.mjs) to TypeScript (.test.ts) in test/ directory - Set up TypeScript build configuration with tsconfig.json - Added proper types and type safety throughout the codebase - Updated package.json with TypeScript build scripts - Configured ES2022 target and ESM module resolution - All 61 tests passing - Added type definitions for better IDE support and type checking - Builds to dist/ directory with declaration files (.d.ts) - Maintains full backward compatibility with ESM exports - Ready for publication with TypeScript support
- Removed all old .mjs source and test files (now using TypeScript) - Updated package.json for proper npm packaging: - Added 'bin' entry for CLI tool (sendscript command) - Added 'files' field to specify publishable content - Added 'engines' field requiring Node >= 18 - Added 'typescript' keyword - Enhanced 'prepublishOnly' to run tests before publishing - Added 'test:watch' script for development - Created .npmignore to exclude source/dev files from npm package - Made dist/cli.js executable - Verified all 61 tests passing - Ready for npm release with proper TypeScript support and CLI entry point
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR changes parse.mjs to use a single JSON.parse pass with an explicit await marker. It avoids repeated JSON stringify/parse cycles for awaited sub-programs and keeps plain promise values intact unless explicitly awaited.