1 of 8

Extensible numeric literals

For Stage 1

Daniel Ehrenberg

Igalia

2 of 8

Motivation

  • 1236536253453n BigInt (special case)
  • 4525i Imaginary numbers
  • 235435.461m IEEE 754-2008 64-bit decimal
  • 300px CSS Typed OM

3 of 8

Semantics

1234i

-->

i("1234", 1234)

4 of 8

Scoping details: Lexical?

function i() { ... }

import { i } from "literals.js";

1234i --> i("1234", 1234)

  • Hazard: i is likely to get shadowed

5 of 8

Scoping details: Mangled?

function __literal_i() { ... }

import { __literal_i } from "literals.js";

1234i --> __literal_i("1234", 1234)

  • Downside: Ugly when it leaks

6 of 8

Scoping details: Namespace?

function literal i() { ... }

import { literal i } from "literals.js";

1234i --> [literal i]("1234", 1234)

  • Could work, but complexity

7 of 8

Scoping details: Object property?

Literals.i = function i() { ... }

import "literals.js"; // mutates Literals

1234i --> Literals.i("1234", 1234)

  • Global mutable object :(

8 of 8

Status

  • Explainer
  • No spec text, implementations, tests, or Babel support
    • Need to answer scoping question first
  • Stage 1?