NAK-569 Add evalRaw() function for platform-consistent JSON output
#12
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.
Summary
This PR introduces the
evalRaw(equation)function to the parsec-web JavaScript wrapper, providing platform-consistent output that returns raw C++ JSON strings. This enhancement enables seamless integration with Flutter web while maintaining full backward compatibility with the existingeval()API.🎯 Problem Statement
The current parsec-web library converts C++ JSON results to JavaScript types, causing platform inconsistencies between web and native implementations. This creates challenges for Flutter web integration where unified JSON parsing is expected across all platforms.
Before:
eval("5 > 3")→true(JavaScript boolean)'{"val": "true", "type": "b"}'(JSON string)After:
evalRaw("5 > 3")→'{"val": "true", "type": "b"}'(Raw C++ JSON)🚀 Solution
New
evalRaw(equation)FunctionDual API Design
eval(equation): Existing behavior with JavaScript type conversion (unchanged)evalRaw(equation): New raw JSON output for platform consistency📋 Key Features
Platform Consistency
Error Handling
🧪 Testing
Comprehensive Test Suite
tests/evalraw.test.jsTest Categories
inf,-inf,-nan)eval()behaviorEnhanced Internal Testing
Added
runComprehensiveTestsBoth()method that tests botheval()andevalRaw()functions simultaneously with detailed reporting.📁 Files Changed
Core Implementation
js/equations_parser_wrapper.js: AddedevalRaw()function and enhanced testingevalRaw(equation)method (63 lines)runComprehensiveTestsBoth()method for dual testing_runSingleTestRaw(),_createTestResultRaw(),_evaluateTestResultRaw()Test Suite
tests/evalraw.test.js: Comprehensive test suite (344 lines)evalRaw()functionalityeval()behavior🎁 Benefits
For Flutter Web Integration
For JavaScript Users
eval()API unchangedeval()for JavaScript types orevalRaw()for JSON🔍 Implementation Details
Clean Architecture
eval()andevalRaw()logicPerformance Considerations
evalRaw()is actually faster (no type conversion overhead)🧭 Future Considerations
This implementation provides the foundation for:
📝 Test Plan
Manual Testing Steps
Basic Functionality:
Full Test Suite:
npm testInteractive Testing:
Verification Checklist
evalRaw()tests pass (35/35)eval()andevalRaw()produce correct outputs🔥 Ready for Flutter Web Integration!