-
Notifications
You must be signed in to change notification settings - Fork 59
Wrap JS functions within parenthesis before eval on the JS side #392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thank you for making this pull request. Did you know? You can try it on Binder: Also, the version of ITables developed in this PR can be installed with (this requires |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR shifts the responsibility of wrapping JavaScript function definitions in parentheses from the Python side to the JavaScript eval logic, cleaning up the Python code and centralizing the behavior in the frontend.
- Update the Python
JavascriptFunctionto use a stricter regex and remove its manual wrapping in evaluation routines. - Remove legacy wrapping in
get_keys_to_be_evaluatedand enhanceevalNestedKeysin JS to handle wrapping. - Adjust changelog entries to reflect that wrapping now happens on the JS side.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/itables/typing.py | Import re and tighten the JavascriptFunction regex check. |
| src/itables/javascript.py | Drop Python-side wrapping of function bodies. |
| packages/dt_for_itables/src/index.js | Detect function patterns, wrap them, and eval safely in JS. |
| packages/dt_for_itables/CHANGELOG.md | Note JS-side function wrapping behavior. |
| docs/changelog.md | Document that wrapping is now handled in JS eval. |
Comments suppressed due to low confidence (1)
packages/dt_for_itables/src/index.js:75
- There's an extra
"in the template literal after${obj[first]}; it may lead to confusing output. Adjust the punctuation for a clear error message.
console.error(`Error evaluating ${context}='${obj[first]}'": ${e.message}`);
| assert value.lstrip().startswith( | ||
| "function" | ||
| ), "A Javascript function is expected to start with 'function'" | ||
| assert re.compile(r"^\s*function\s*\(").match( |
Copilot
AI
May 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider moving the regex compilation to a module- or class-level constant instead of compiling it on every instantiation to reduce runtime overhead.
| assert re.compile(r"^\s*function\s*\(").match( | |
| assert JAVASCRIPT_FUNCTION_REGEX.match( |
packages/dt_for_itables/src/index.js
Outdated
| if (typeof code !== 'string') { | ||
| throw new Error(`Expected a string to evaluate in context '${context}', but got ${typeof code}.`); | ||
| } | ||
| console.log(code); |
Copilot
AI
May 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This console.log appears to be a debugging statement; remove it or replace it with a proper logger if you intend to log in production.
docs/changelog.md
Outdated
| **Changed** | ||
| - The `warn_on_undocumented_option` option now defaults to `True` and only check the option names | ||
| - We have added a new option `warn_on_unexpected_option_type` that defaults to `warn_on_undocumented_option` when `typeguard>=4.4.1` is installed (`False` otherwise) | ||
| - Wrapping JS function definitions in parenthesis prior to JS eval is now done on the JS side. |
Copilot
AI
May 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Minor spelling: use "parentheses" (plural) instead of "parenthesis" for correctness.
| - Wrapping JS function definitions in parenthesis prior to JS eval is now done on the JS side. | |
| - Wrapping JS function definitions in parentheses prior to JS eval is now done on the JS side. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #392 +/- ##
==========================================
- Coverage 89.05% 89.05% -0.01%
==========================================
Files 44 44
Lines 1837 1836 -1
==========================================
- Hits 1636 1635 -1
Misses 201 201 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
54eb3ce to
d461dcf
Compare
This is cleaner than the current change by reference on the nested
dataobject.