Skip to content

fix(view/compiler): bail on unterminated strings and invalid numeric literals - #190

Merged
JosunLP merged 1 commit into
devfrom
fix/170-compiler-invalid-literals
Jul 6, 2026
Merged

fix(view/compiler): bail on unterminated strings and invalid numeric literals#190
JosunLP merged 1 commit into
devfrom
fix/170-compiler-invalid-literals

Conversation

@JosunLP

@JosunLP JosunLP commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #170 (Medium; build-breaking).

scanStringLiteral returned i + 1 unconditionally and never verified the closing quote, so an unterminated literal (<p bq-text="'oops">) was copied verbatim and compileExpression returned { ok: true } with a broken body. Because emitModule writes every expression into one module, a single malformed entry throws at import time and takes down all precompiled expressions in that file — with no per-expression runtime fallback. Malformed numeric literals (1ex) hit the same class of bug via scanNumericLiteral.

Fix

  • scanStringLiteral throws Bail('unterminated string literal') when it reaches end-of-input without the matching quote.
  • Scanned numeric runs are validated against a numeric-literal regex (decimal/hex/octal/binary with _ separators); invalid runs throw Bail('invalid numeric literal').

Both bails route through the existing try/catch in compileExpression to { ok: false, reason }, so the expression cleanly falls back to the runtime evaluator instead of poisoning the module.

Verification

  • New tests: unterminated 'oops / "unclosed / greeting + 'tail bail; escaped-quote strings still compile; 1ex/1e/0xG1 bail while 1, 1.5, 0xFF, 1e3, 1_000, .5, 0b1010 still compile. Both new tests fail on the pre-fix code.
  • View suites (compiler/view/stable/1-14): all pass. tsc --noEmit clean.

🤖 Generated with Claude Code

…literals

scanStringLiteral returned start+1 unconditionally, never checking the
closing quote was found, so an unterminated literal (e.g. bq-text="'oops")
was copied verbatim and compileExpression reported { ok: true } with a
syntactically broken body. Since emitModule writes every expression into
one module, one bad entry throws at import and takes down every
precompiled expression in the file (no per-expression runtime fallback).

scanStringLiteral now throws Bail on reaching end-of-input without the
matching quote, and scanned numeric runs are validated against a
numeric-literal regex (rejecting e.g. 1ex). Both bails route through the
existing catch to { ok: false }, so the expression falls back to the
runtime evaluator.

Fixes #170

Co-Authored-By: Claude Fable 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 94960515-dbdb-46db-bc17-b86b536695b8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/170-compiler-invalid-literals

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added view Changes to the view module tests Chenges to the tests labels Jul 6, 2026
@JosunLP
JosunLP merged commit 6adff7f into dev Jul 6, 2026
9 checks passed
@JosunLP
JosunLP deleted the fix/170-compiler-invalid-literals branch July 6, 2026 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Chenges to the tests view Changes to the view module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant