Skip to content

[highlights] fix highlights lexers - #1157

Merged
ije merged 3 commits into
mainfrom
ije/fix-highlights-lexers
Sep 25, 2026
Merged

ije merged 3 commits into
mainfrom
ije/fix-highlights-lexers

Conversation

@ije

@ije ije commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Hangs and quadratic scans

  • Elixir: a regex sigil spanning a newline no longer hangs.
  • Replace repeated scans with bounded or cached lookahead in Julia, F#, Ruby, SCSS/Less/Sass, Bash, Elixir, C#, XML, and PowerShell.

Fresh local stress-test timings on roughly 256 KB inputs:

Input Main This branch
Julia ;f( chains 5.15 s 2.3 ms
F# interpolated string with repeated }} 546 ms 1.1 ms
Ruby string with repeated interpolations 479 ms 3.9 ms
SCSS repeated unclosed #{ 422 ms 3.4 ms
Bash long string with $x expansions 374 ms 0.8 ms
Elixir heredoc with escapes 169 ms 0.7 ms
C# repeated $"…" strings 117 ms 2.0 ms
XML <!DOCTYPE [...]> subset 81 ms 0.4 ms
PowerShell dash-free input triggering Verb-Noun checks 81 ms 1.2 ms

Highlighting fixes

  • JSX/TSX: comments inside open tags no longer consume the rest of the file as a string. Handle component type arguments such as <Select<Option> /> and distinguish generic arrows such as <T extends X>(…) and <const T,>(…) from JSX.
  • TypeScript: fix arrow return types, uppercase names in type positions, qualified constructors, and contextual keywords such as using, accessor, and asserts. A template: property selects embedded markup only when its contents look like markup.
  • Svelte/Astro/Vue: preserve attributes after {…} expressions, including across streamed lines; fix Vue interpolation boundaries. <style lang="scss|sass|less"> selects the corresponding CSS dialect.
  • Markdown/MDX: fix autolinks, badge links, fence info strings (rust,ignore, js{4}), intraword underscores, emphasis containing code spans, and fences inside block quotes. MDX import/export blocks follow JavaScript lexical state.
  • Fenced code: resolve all registered language names and aliases, preserve multiline state inside quoted fences, and recognize document-start syntax such as shebangs and front matter within fence bodies. Live edits restore TOML nesting state inside Markdown/MDX fences.
  • YAML: preserve ${{ … }}, spaces, commas, and embedded brackets in plain scalars; recognize numeric and escaped quoted keys; allow comments after block-scalar headers such as | # comment.
  • Shell and build files: fix CMake unquoted escapes, Bash arithmetic shifts and command positions, flags and paths, and Dockerfile comments or blank lines inside continued instructions.
  • Ruby/Perl/PHP: fix block-comment terminators, distinguish shifts from heredocs, and recognize heredocs after Ruby member calls and Perl filehandles. PHP single-quoted strings escape only quotes and backslashes.
  • SQL: recognize T-SQL temporary tables and PostgreSQL JSON operators without starting comments; distinguish table column lists from function calls.
  • C family: recognize complete hex, octal, and universal escapes; preserve C++ raw-string suffixes when streamed; fix C++ namespace paths, HLSL declarators, and Zig continue expressions and slice sentinels.
  • JVM/.NET/mobile: improve contextual keyword classification, trailing-lambda calls, import boundaries, and declaration handling. Comparisons and conditional operators no longer leave stale type state.
  • Functional languages: fix OCaml/F#/Lisp parameters and bindings, trailing-dot floats, F# ranges and quoted identifiers, and comment-banner scanning.
  • Other fixes: add Python t-string highlighting; improve CSS escaped selectors and dialect constructs, PowerShell keys, Rust paths and tuple fields, assembly registers, and grouped Go type declarations.

Performance

Combined tokenization time is approximately 4% lower across two local A/B runs of the language samples, each repeated to at least 256 KiB. These measurements use the raw Wasm record-output mode.

Language Approximate time change
Astro −24%
Svelte −18%
Makefile −16%
Vue −14%
Lisp, Dockerfile −11–12%
HTML, OCaml −10%
JavaScript, TypeScript, TSX −8–10%
Fortran −8–10%
Swift +5%
PHP, Perl, YAML +3–4%

Small differences are sensitive to benchmark noise. Improvements include single-pass framework expressions, lazy JSX/signature checks, shared scanners, and cheaper byte-set checks.

Size and memory

  • Wasm grows from 158,514 to 161,909 B (+2.1%); gzipped size grows from 70,919 to 75,322 B (+6.2%).
  • Streaming checkpoints grow from 1,280 to 1,536 B. Byte-set storage grows by 1,024 B, and keyword-table reservations grow by 128 B.
  • Total reserved space in the first memory page grows by 1,408 B. Input and the live heap still begin at byte 65,536.
  • Centralize language registration, name lookup, and dispatch in languages.wat; generate Markdown fence lookup from the same registry.

Intentional behavior changes

  • C: in /* c */ #define X, the # is now an operator because another non-whitespace byte precedes it on the same line.
  • SQL: a spaced COUNT (*) is no longer highlighted as a function call; COUNT(*) still is.
  • Rust: path calls such as Self::new() use function; dot calls such as value.method() retain function.method.

@vercel

vercel Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
pierre-diffshub Ready Ready Preview Sep 25, 2026 9:31am UTC
pierre-docs-diffs Ready Ready Preview Sep 25, 2026 9:31am UTC
pierre-docs-trees Ready Ready Preview Sep 25, 2026 9:31am UTC
1 Skipped Deployment
Project Deployment Actions Updated
pierrejs-diff-demo Skipped Skipped Sep 25, 2026 9:31am UTC

Request Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ba3932f407

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/highlights/src/langs/html.wat
@vercel
vercel Bot temporarily deployed to Preview – pierrejs-diff-demo September 25, 2026 09:29 Inactive
@ije
ije merged commit cc4963a into main Sep 25, 2026
8 checks passed
@ije
ije deleted the ije/fix-highlights-lexers branch September 25, 2026 13:44

This branch was successfully deployed

3 active and 1 inactive deployments
Preview – pierre-docs-diffs — e93bc216 Deployed Sep 25, 2026 by vercel[bot]
Preview – pierre-docs-trees — e93bc216 Deployed Sep 25, 2026 by vercel[bot]
Preview – pierre-diffshub — e93bc216 Deployed Sep 25, 2026 by vercel[bot]
Preview – pierrejs-diff-demo — e93bc216 Deployed Sep 25, 2026 by vercel[bot]
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.

1 participant