Skip to content

Keep TypeScript division expressions out of regex highlighting - #4219

Open
justadityaraj wants to merge 1 commit into
micro-editor:masterfrom
justadityaraj:fix/3874-typescript-regexp-highlighting
Open

Keep TypeScript division expressions out of regex highlighting#4219
justadityaraj wants to merge 1 commit into
micro-editor:masterfrom
justadityaraj:fix/3874-typescript-regexp-highlighting

Conversation

@justadityaraj

Copy link
Copy Markdown

Context

TypeScript's regular-expression rule cannot distinguish regex literals from division expressions with the syntax highlighter's regular-expression engine. It therefore treats text between division operators, such as / 2.0, height /, as a regex constant. JavaScript already disables the same ambiguous rule, and the maintainer accepted that fallback for TypeScript in #3874.

Changes

  • Disable the ambiguous TypeScript regex-literal rule, matching the existing JavaScript behavior.
  • Add a regression that rejects constant highlighting in a chained division expression.

User impact

Ordinary TypeScript division expressions keep their correct token colors instead of having the operands between slash characters displayed as a regex literal. Regex literals remain unclassified rather than risking false highlighting across unrelated code.

Verification

  • Regression on clean master — failed with division highlighted as constant.
  • go test ./runtime -run TestTypeScriptDivisionIsNotRegexp -count=10 — passed.
  • go test ./... -count=1 — passed.
  • go generate ./runtime — passed with no additional tracked changes.
  • go build ./cmd/micro — passed.
  • git diff --check — passed.
  • go vet ./... — retains the existing unkeyed-literal and copied-lock warnings reproduced on clean master.
  • Micro's tcell simulation screen reproduced the incorrect regex coloring on clean master and the corrected division coloring after the change.
Before After
TypeScript division highlighted as a regex TypeScript division retains normal token colors

Fixes #3874

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.

Typescript ambiguous regexp highlighting with normal division

1 participant