Skip to content

Instantly share code, notes, and snippets.


Ron Buckton rbuckton

View GitHub Profile
rbuckton /
Last active September 9, 2022 19:45
Pattern Matching Exploration

Pattern Matching Exploration

The following sections explore various ways we could consider introducing pattern matching to ECMAScript, and can be used to inform a discussion on how best to layer the proposal. The various explorations in this document are not intended to be taken as a whole, as some sections directly conflict with others. Any exploration will specifically call out other explorations that are related.

This list is by no means complete. Suggestions for additions or changes are welcome.

Extending Existing Syntax

rbuckton /
Created September 7, 2022 23:23
Pattern Matching Tenets

Pattern Matching Tenets

  1. Patterns should be [concise][]
  2. Patterns should be [expressive][]
  3. Patterns should be [explicit][]
  4. Patterns should be [extensible][]
  5. Pattern matching should be [exhaustive][]

Tenet 1 — Patterns should be concise


Notational Conventions

Examples in this document may use ECMAScript internal-values as specified in Such values will appear in ECMAScript examples as ~value-name~ and are not intended to denote new synatx.

This document uses abstract operations defined either in or in this document. Such abstract operations will be differentiated from normal ECMAScript functions by names like %OperationName% and are not intended to denote new syntax.

Portions of this document are enclosed in block-quotes. These sections reference portions of

rbuckton / ADT enum
Last active August 11, 2021 18:44
Example of how ADT enums could be implemented using
View ADT enum

If I were to change the definition of @@toEnum slightly, we could build ADT-style enums into

Currently, @@toEnum takes three arguments: key, value and autoValue. If we change this to take a more complex context argument, we have more flexibility:

interface ValueEnumFactoryContext {
    base: typeof Enum;
    name: string | symbol;
    kind: "value";
View private state helper


var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "method") throw new TypeError("Private method is not writable");
    if (kind === "accessor" && !f) throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "accessor" ?, value) : f ? f.value = value : state.set(receiver, value)), value;
rbuckton /
Created January 15, 2021 01:15
Regular Expression library flags across different engines

Based on list of Regular Expression Engines from

Engine Language Flags Note
[Boost.Regex][] C++ [imsx][Boost.Regex(flags)]
[DEELX][] C++ [imsg][DEELX(flags)]
[Glib/GRegex][] C++ [imsx][Glib/GRegex(flags)]
[GRETA][] C++ Could not find documentation.
[Gregex][] RTL, HLS Could not find documentation.
[RXP][] RTL Could not find documentation.
rbuckton /
Last active October 7, 2020 01:04
Syntax for grouped accessors and auto-accessors to classes and object literals.

Grouped Accessors and Auto-Accessors for ECMAScript classes and Object Literals

This introduces new syntax for grouped accessors and auto-accessors to classes and object literals. A grouped accessor is a single declaration that contains either or both both of the get and set methods for an accessor. An auto-accessor is a simplified variant of a grouped accessor that elides the bodies of the get and set methods and introduces a private backing field used by both the getter and setter.

Syntax - Grouped Accessors

rbuckton / string
Created September 22, 2020 03:09
Rough design for improving the native API for strings in ECMAScript
View string
  • Intl.StringInfo
    • .charCodes(s) - Returns an Iterable that yields each code unit within the string s.
    • .codePoints(s) - Returns an Iterable that yields each code point within the string s (essentially just yield* s).
    • .graphemeClusters(s) - Returns an Iterable that yields each grapheme cluster substring within the string s.
    • .codePointCount(s) - Counts the number of code points within the string s.
    • .graphemeClusterCount(s) - Counts the number of grapheme clusters within the string s.
    • .nthCodePoint(s, n) - Gets the n-th code point (as a number) within the string s.
    • .nthGraphemeCluster(s, n) - Gets the n-th grapheme cluster (as a substring) within the string s.
    • .codePointSize(codePoint) - Gets the size, in code units, of the provided code point.
  • .getUnicodeCategory(s, i) - Gets the unicode category for the code point at the specified index i in string s.
View ECMAScript RegExp

ECMAScript Regular Expression Language Additions

This is a strawperson for the addition of multiple Regular Expression features popular in various languages and parsers. The primary influences for this proposal come from prior art in the following languages and regular expression engines:

rbuckton /
Last active November 9, 2022 17:22
Proposal: Range Types for TypeScript

Range Types (T[X:Y]) for TypeScript

A Range Type is a type that produces a new tuple or array type that derives from T by dropping the excess ordered elements of T outside of the range starting at offset X (inclusive) through offset Y (exclusive).

A Range Type is denoted using a : operator in what would otherwise be an Indexed Access Type:

type T = [1, 2, 3][0:2];