---
title: "Chroma: TypeScript number literals in a Go lexer | VulCode"
description: "In Chroma we taught the TypeScript lexer binary, octal, exponent and underscore-separated numbers, which it used to split into two tokens. A Go project."
url: "https://vulcode.com/en/opensource/contributions/chroma"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

alecthomas/chroma

# Chroma

A general purpose syntax highlighter in pure Go: it turns source code and other structured text into highlighted HTML or ANSI-coloured text.

[See the repository](https://github.com/alecthomas/chroma) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: Go
- **GitHub stars**: 5,086
- **Merged changes**: 1

## What we changed

The TypeScript lexer recognises binary, octal, upper-case hex, exponent and underscore-separated literals such as 0b1010, 0o17, 0XFF, 1e5 and 1_000, instead of splitting them into a number and a name.

### What this work shows

- Lexers and syntax highlighting

- Regular expressions for numeric literals

- Golden-file tests

What was broken

### 0b1010 split into a number and a name

The TypeScript lexer had only three number rules. Literals such as 0b1010, 0o17, 0XFF, 1e5 and 1_000 were split into a number and a name, so each part was highlighted separately.

How we fixed it

### Number rules from the JavaScript lexer

We ported the number rules from the JavaScript lexer: separate rules for binary, octal and hex with a lower- or upper-case prefix, and a float rule that still keeps a fraction and an exponent together, as in 1.5e10. A new number_literals fixture checks all of these cases.

[#1396](https://github.com/alecthomas/chroma/pull/1396)

## Merged change 1

- [#1396 fix(lexers): recognize TypeScript binary, octal and exponent literals Merged 15 October 2026](https://github.com/alecthomas/chroma/pull/1396)

## What it taught us

The lexers of two related languages drift apart quietly, so it is better to close the whole class of cases at once. TypeScript writes numbers the same way JavaScript does, so we ported the rules from the JavaScript lexer and covered them with a golden-file test.

[More about this technology: Golang](https://vulcode.com/en/technologies/go)

## Other projects we write code for

- [**urfave/cli** Go · 24,329 stars A declarative Go package for building command line tools.](https://vulcode.com/en/opensource/contributions/urfave-cli)

- [**chezmoi** Go · 22,342 stars A dotfiles manager that keeps the same settings on many different machines, securely.](https://vulcode.com/en/opensource/contributions/chezmoi)

- [**goquery** Go · 14,995 stars A Go library for traversing and changing HTML documents in the style of jQuery, built on the golang.org/x/net/html parser.](https://vulcode.com/en/opensource/contributions/goquery)

- [**Ebitengine** Go · 13,647 stars A 2D game engine in Go, used in games released for computers, phones, browsers and consoles.](https://vulcode.com/en/opensource/contributions/ebiten)

- [**Fission** Go · 8,950 stars A serverless functions framework for Kubernetes that runs code as functions and scales them down to zero when they are idle.](https://vulcode.com/en/opensource/contributions/fission)

- [**Concourse** Go · 7,944 stars A container-based automation system written in Go and used mostly for CI/CD. Pipelines and tasks are described in YAML files.](https://vulcode.com/en/opensource/contributions/concourse)

## Describe your project.

A free quote comes back within an hour during working hours.

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
