Skip to content

Conversation

@trebitowski
Copy link
Collaborator

@trebitowski trebitowski commented Dec 19, 2025

Changes

Use acorn-loose as fallback parser for logic rules with imports and top-level returns.

This change attempts to parse logic rules with acorn-loose if the standard acorn parser fails. The acorn-loose parser is designed to handle syntactically invalid JavaScript by constructing a valid AST even when there are syntax errors. Since we only use the AST to locate and inline import statements, the AST remains usable for our purposes even when the syntax is technically invalid. acorn-loose is meant for our use case of parsing code during transformation steps. We still try to parse using acorn first as recommended by the acorn team.

This is necessary because logic rules can contain both import statements (for shared code) and top-level return statements, which is technically invalid JavaScript syntax. Standard acorn throws a SyntaxError when encountering this combination. However, this syntax is acceptable in our context because we transform the code before evaluation by inlining the imports and wrapping everything in a function, which makes it valid JavaScript.

Checklist before requesting a review

  • Cleaned up debug prints, comments, and unused code
  • Tested end to end
  • Included screenshots or walkthrough video of change if impacts UX

Related pull requests

Link other PRs here that are related to this change

@trebitowski trebitowski changed the title Fix shared code parse Fix: Shared code parsing issue Dec 19, 2025
@trebitowski trebitowski changed the title Fix: Shared code parsing issue Fix: Support return statements for logic rules using shared code Dec 19, 2025
@trebitowski trebitowski force-pushed the fix-shared-code-parse branch from ff3861f to 01d16ce Compare December 19, 2025 03:48
@trebitowski trebitowski changed the title Fix: Support return statements for logic rules using shared code fix: Support return statements for logic rules using shared code Dec 19, 2025
@trebitowski trebitowski merged commit 921f53f into master Dec 19, 2025
7 of 10 checks passed
@trebitowski trebitowski deleted the fix-shared-code-parse branch December 19, 2025 04:57
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