• Stars
    star
    105
  • Rank 328,196 (Top 7 %)
  • Language
  • Created over 6 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

`as` destructuring patterns

ECMAScript As-Patterns for Matching and Destructuring

Status

Stage: 0

Author: Kat Marchán (npm, @maybekatz)

Champions: Kat Marchán (npm, @maybekatz)

Introduction

When matching non-Identifier values, it's often the case that users might want to also bind that value to an Identifier while doing the matching. For this reason, it's proposed that destructuring be extended with the ability to do this sort of binding. Furthermore, the separate pattern matching proposal will benefit from this change by allowing matching operations against values that are also put into identifiers, since identifiers are irrefutable patterns.

The syntax uses an as keyword, and looks as follows:

const {x: {y} as x} = {x: {y: 1}}
// x is {y: 1}
// y is 1

Or:

function foo ([{y} as x, [z] as zed = [1]]) {
  // x is {y: ...}
  // y is x.y
  // z is runs an initializer if arguments[0][1] is undefined
}

This applies similarly to match:

match (x) {
  when {x: {y: 1} as x} ~> console.log(x.y === 1)
}

Note: This syntax is used by F#. It's also reminiscent of as syntax in import statements, so there's some precedent in the language for this sort of binding (import * as bar from './x.js')

The Big Picture

Related Active Proposals

As-Patterns

Syntax

12.15.5 Destructuring Assignment Changes:

AssignmentRebinding :
  `as` IdentifierReference

AssignmentElement :
  DestructuringAssignmentTarget
  DestructuringAssignmentTarget AssignmentRebinding
  DestructuringAssignmentTarget Initializer
  DestructuringAssignmentTarget AssignmentRebinding Initializer

13.3.3 Destructuring Binding Patterns Changes:

BindingRebinding :
  `as` IdentifierReference

BindingElement :
  SingleNameBinding
  BindingPattern
  BindingPattern BindingRebinding
  BindingPattern Initializer
  BindingPattern BindingRebinding Initializer

Match Operator Syntax Changes:

MatchRebinding :
  `as` IdentifierReference

MatchElement :
  SingleNameBinding
  MatchPattern
  MatchPattern MatchRebinding
  MatchPattern Initializer
  MatchPattern MatchRebinding Initializer

More Repositories

1

npx

execute npm package binaries (moved)
JavaScript
2,625
star
2

miette

Fancy extension for std::error::Error with pretty, detailed diagnostic printing.
Rust
2,005
star
3

big-brain

Utility AI library for the Bevy game engine
Rust
1,032
star
4

cacache-rs

A high-performance, concurrent, content-addressable disk cache, with support for both sync and async APIs. 💩💵 but for your 🦀
Rust
529
star
5

cipm

standalone ci-oriented package installer for npm projects (moved)
JavaScript
400
star
6

make-fetch-happen

Get in loser, we're making requests!
JavaScript
384
star
7

pacote

programmatic npm package and metadata downloader (moved!)
JavaScript
280
star
8

cacache

💩💵 but for your data. If you've got the hash, we've got the cache ™ (moved)
JavaScript
240
star
9

chanl

Portable channel-based concurrency for Common Lisp
Common Lisp
164
star
10

mona

Composable parsing for JavaScript
JavaScript
152
star
11

rust-notes

Personal notes while learning Rust. Mainly documenting pain points along the way.
145
star
12

maybe-hugs

Polyglot implementations of conditional hugging
OCaml
114
star
13

sheeple

Cheeky prototypes for Common Lisp
Common Lisp
99
star
14

pattycake

playground for pattern matching api
JavaScript
98
star
15

ssri

Standard Subresource Integrity library for Node.js
JavaScript
82
star
16

json-parse-better-errors

get better errors
JavaScript
67
star
17

squirl

Common Lisp port of the Chipmunk 2d physics library
Common Lisp
53
star
18

supports-color

Detects whether a terminal supports color, and gives details about that support
Rust
42
star
19

figgy-pudding

Cascading, controlled-visibility options object management.
JavaScript
39
star
20

genfun

Prototype-friendly multimethods for JavaScript.
JavaScript
38
star
21

ssri-rs

Rusty implementation of Subresource Integrity
Rust
38
star
22

can.viewify

require() mustache and ejs modules as compiled CanJS views
JavaScript
37
star
23

protoduck

Duck typing for the most serious of ducks.
JavaScript
35
star
24

chillax

CouchDB abstraction layer for Common Lisp
Common Lisp
34
star
25

cl-openal

Common Lisp bindings for the OpenAL audio library.
Common Lisp
34
star
26

conserv

Common Lisp
31
star
27

memento-mori

Robustness through actors, for Common Lisp
Common Lisp
31
star
28

talks

Notes and slides for all my talks
JavaScript
26
star
29

until-it-dies

A batteries-included game engine.
Common Lisp
25
star
30

supports-hyperlinks

Detect whether the current terminal supports rendering hyperlinks
Rust
25
star
31

matrix-curious

FAQ and resources for those curious about joining the Matrix network!
23
star
32

sykobot

An IRC bot from another universe. No, really.
Common Lisp
21
star
33

turron

Rusty NuGet client
Rust
20
star
34

npm-pick-manifest

Standard manifest picker/semver resolver for npm
JavaScript
20
star
35

cl-ffmpeg

CFFI bindings for FFMPEG
Common Lisp
19
star
36

proposal-collection-literals

[WITHDRAWN] tc39 proposal for custom collection literals
18
star
37

cl-devil

Common Lisp bindings for DevIL
Common Lisp
16
star
38

okimdone

tells you when it's done
Shell
15
star
39

srisum-rs

Compute and check subresource integrity digests.
Rust
14
star
40

thisdiagnostic

Add nice user-facing diagnostics to your errors without being weird about it.
Rust
14
star
41

is_ci

Super lightweight and dead-simple CI detection.
Rust
12
star
42

common-worm

A simple, hackish version of the classic snake game, written in Common Lisp
Common Lisp
12
star
43

supports-unicode

Detects whether a terminal supports unicode.
Rust
12
star
44

nanotubes

Fancy websocket wrapper for Rust
Rust
12
star
45

srisum

Compute and check Subresource Integrity digests.
JavaScript
11
star
46

DWG.Directories

Standard directories for .NET
10
star
47

cadr

content-addressable filesystem snapshots
JavaScript
10
star
48

protocols

Multi-type protocol-based polymorphism
JavaScript
10
star
49

cl-speedy-queue

Lightweight, optimized queue implementation for CL
Common Lisp
9
star
50

playwright

Like Erlang, but not
JavaScript
9
star
51

sykosomatic

Cooperative storytelling
Common Lisp
7
star
52

cond

Restartable error handling system for JavaScript
JavaScript
7
star
53

destealify

Browserify transform for processing StealJS modules
JavaScript
7
star
54

bacon-browser

Utility library for higher-level, declarative interaction with various bits of browser-level events and features.
JavaScript
7
star
55

sykosomatic-legacy

text-based online game engine
Common Lisp
7
star
56

shepherdb

A Sheeple-based persistent object store.
Common Lisp
6
star
57

clutter

nothing to see here
Common Lisp
6
star
58

facile

CouchDB view server for Factor
Factor
6
star
59

fl-protocols

fantasy-land specification bridge for @zkat/protocols
JavaScript
6
star
60

electron-collider

Rust
5
star
61

my-precious

a local package archive, of our own
JavaScript
5
star
62

checksum-stream

Calculates and/or checks data coming through a stream and emits the digest before stream end.
JavaScript
5
star
63

cl-form

Generic form validation utility for CL
Common Lisp
5
star
64

common-brick

Breakout clone with "realistic" physics.
Common Lisp
4
star
65

surf-middleware-cache

http caching middleware for the Surf http client
Rust
4
star
66

specificity

Runnable specifications for Common Lisp
4
star
67

friendfavor

Find out what your friends think of something -- or someone!
Common Lisp
4
star
68

shortening

The personal URL shortener.
Common Lisp
3
star
69

kallisti

kallisti
Rust
3
star
70

clutterscript

Pay this no heed, I'm just learning stuff.
JavaScript
3
star
71

cl-event2

libevent2 bindings for Common Lisp
Common Lisp
3
star
72

yashmup

Toy project -- writing a shmup in CL
Common Lisp
3
star
73

test

just a place to test random github shit
2
star
74

marina

placeholder for programming language
2
star
75

mona-csv

simple mona-based csv parser
JavaScript
1
star
76

proto

Alternative to JavaScript's `new`.
Makefile
1
star
77

dynvar

Dynamic variables for JS
JavaScript
1
star
78

protoduck-fl

fantasy-land specification bridge for protoduck
JavaScript
1
star
79

mona-json

mona-based JSON parser
JavaScript
1
star
80

mona-strings

String parsers for mona
JavaScript
1
star
81

logloc

Adds source location to console loggers
JavaScript
1
star
82

zkat

it me
1
star
83

node-otp

The Node.js Open Telecom Platform
1
star
84

fetch-cache

Cache API implementation + protocol
JavaScript
1
star
85

tswrp

JavaScript
1
star
86

chownr-rs

Like chown -r for Rust
Rust
1
star
87

presentations

various presentations
JavaScript
1
star
88

storychat

~~~ tell me a story <3 with your words ~~~
JavaScript
1
star
89

mona-combinators

Parser combinators for mona
JavaScript
1
star
90

fig-roll

rolls up your configs into a nice figgy pudding
1
star
91

chatoid

Toy chatroom using webrtc
JavaScript
1
star
92

ironsworn-mechanics

Various support utilities and some custom rendering for mechanics in Ironsworn-family games (Starforged, Sundered Isles, etc).
TypeScript
1
star
93

zkat.github.io

Web sight
TypeScript
1
star