Skip to content

Instantly share code, notes, and snippets.

Avatar

Ron Buckton rbuckton

View GitHub Profile
@rbuckton
rbuckton / pattern-matching-exploration.md
Last active September 9, 2022 19:45
Pattern Matching Exploration
View pattern-matching-exploration.md

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
rbuckton / pattern-matching-tenets.md
Created September 7, 2022 23:23
Pattern Matching Tenets
View pattern-matching-tenets.md

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

View pattern-matching-epic-but-with-extractors.md

Notational Conventions

Examples in this document may use ECMAScript internal-values as specified in https://tc39.es/ecma262/#sec-value-notation. 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 https://github.com/tc39/proposal-pattern-matching 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 https://github.com/codehag/pattern-matching-epic.

@rbuckton
rbuckton / ADT enum example.md
Last active August 11, 2021 18:44
Example of how ADT enums could be implemented using https://github.com/rbuckton/proposal-struct
View ADT enum example.md

If I were to change the definition of @@toEnum slightly, we could build ADT-style enums into https://github.com/rbuckton/proposal-struct.

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 breakdown.md

__classPrivateFieldSet

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" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
@rbuckton
rbuckton / regexp_flags.md
Created January 15, 2021 01:15
Regular Expression library flags across different engines
View regexp_flags.md

Based on list of Regular Expression Engines from https://en.wikipedia.org/wiki/Comparison_of_regular-expression_engines

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
rbuckton / grouped-and-auto-accessors.md
Last active October 7, 2020 01:04
Syntax for grouped accessors and auto-accessors to classes and object literals.
View grouped-and-auto-accessors.md

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
rbuckton / string methods.md
Created September 22, 2020 03:09
Rough design for improving the native API for strings in ECMAScript
View string methods.md
  • 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 Additions.md

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
rbuckton / ts-proposal-range-types.md
Last active November 9, 2022 17:22
Proposal: Range Types for TypeScript
View ts-proposal-range-types.md

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];