Skip to content

Conversation

@mwouts
Copy link
Owner

@mwouts mwouts commented May 31, 2025

This is cleaner than the current change by reference on the nested data object.

@mwouts mwouts added this to the 2.4.1 milestone May 31, 2025
@mwouts mwouts requested a review from Copilot May 31, 2025 12:25
@github-actions
Copy link

Thank you for making this pull request.

Did you know? You can try it on Binder: Binder:lab.

Also, the version of ITables developed in this PR can be installed with pip:

pip install git+https://github.com/mwouts/itables.git@parenthesis_for_eval_in_javascript

(this requires nodejs, see more at Developing ITables)

Copy link

Copilot AI left a 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 JavascriptFunction to use a stricter regex and remove its manual wrapping in evaluation routines.
  • Remove legacy wrapping in get_keys_to_be_evaluated and enhance evalNestedKeys in 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(
Copy link

Copilot AI May 31, 2025

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.

Suggested change
assert re.compile(r"^\s*function\s*\(").match(
assert JAVASCRIPT_FUNCTION_REGEX.match(

Copilot uses AI. Check for mistakes.
if (typeof code !== 'string') {
throw new Error(`Expected a string to evaluate in context '${context}', but got ${typeof code}.`);
}
console.log(code);
Copy link

Copilot AI May 31, 2025

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.

Copilot uses AI. Check for mistakes.
**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.
Copy link

Copilot AI May 31, 2025

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.

Suggested change
- 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.

Copilot uses AI. Check for mistakes.
@codecov-commenter
Copy link

codecov-commenter commented May 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.05%. Comparing base (a8ea92e) to head (d461dcf).
Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mwouts mwouts force-pushed the parenthesis_for_eval_in_javascript branch from 54eb3ce to d461dcf Compare May 31, 2025 12:32
@mwouts mwouts merged commit 149947d into main May 31, 2025
14 checks passed
@mwouts mwouts deleted the parenthesis_for_eval_in_javascript branch May 31, 2025 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants