fix: handle function eval input wrapping#56
Merged
Conversation
105b901 to
c0fd184
Compare
Contributor
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.
Summary
Risk Assessment
✅ Low: The change is narrowly scoped to JavaScript expression wrapping for eval/run helpers, includes targeted coverage for prior edge cases, and does not introduce broad control-flow or integration changes.
Testing
npm test -- test/run.test.ts test/wrap-js.test.tsnpm testPipeline
Updates from git push no-mistakes
✅ **Rebase** - passed
Round 1 - passed ✅
🔧 **Review** - 1 issue found → auto-fixed (2)
Round 1 - found 1 warning
src/run.ts:64-unwrapNoArgIIFEunwraps every parenthesized no-arg call before confirming the inner expression is actually a function literal. Valid eval inputs such as(window.getValue)()or(obj.method)()are now converted into() => (window.getValue)/() => (obj.method), so the function is returned instead of invoked. Only unwrap when the inner expression matches the supported function forms; otherwise preserve the original expression wrapping.Round 2 (auto-fix) - found 1 warning
src/run.ts:63- No-arg IIFEs with a trailing semicolon, such as(() => 1)();, are not unwrapped becauserestmust be exactly(). After that, the existing function-detection regex still treats the original string as a function and sends the IIFE text toevaluate_script, so a common copy-pasted IIFE form remains broken despite the new documented support. Accept();here, or strip trailing semicolons before checking the no-arg call.Round 3 (auto-fix) - passed ✅
✅ **Test** - passed
Round 1 - passed ✅
npm test -- test/run.test.ts test/wrap-js.test.tsnpm test🔧 **Document** - 2 issues found → auto-fixed
Round 1 - found 2 issues (1 warning, 1 info)
src/suggestions.ts:75- The user-facing eval tip still teaches multi-statement code by recommending an IIFE as the primary pattern. The change updates eval handling to pass arrow/function inputs through and unwrap no-arg IIFEs, and README/command help now document direct arrow/function input as the preferred multi-statement form with IIFE as accepted compatibility. Update this suggestion and its comment to match the new guidance.src/cli.ts:241- The run command's public script API help listsawait page.eval(jsOrFn)but does not document that string inputs now use the same wrapping rules as the CLI eval command, including function passthrough and no-arg IIFE unwrapping. Since this change explicitly modifiespage.evalbehavior increatePageHelper, the run help should mention the accepted string/function forms or point to the eval syntax rules.Round 2 (auto-fix) - passed ✅
✅ **Lint** - passed
Round 1 - passed ✅
✅ **Push** - passed
Round 1 - passed ✅