babel / babel/proposals

Pattern Matching (Stage 0)

Open
#6 4 comments 45 reactions 1 assignee Claimed by @sebmarkbage View on GitHub
Proposal Issue Transform: In Progress
Dominant language
No language data
Stars
435
Forks
23
PR merge metrics
No merged PRs in 30d

Description

Original issue submitted by @xtuc in https://github.com/babel/babylon/issues/610

This issue is to keep track of the implementation in the parser of this proposal.

Champions: Brian Terlson (Microsoft, @bterlson), Sebastian Markbåge (Facebook, @sebmarkbage)
Spec Repo: https://github.com/tc39/proposal-pattern-matching
> https://github.com/tc39/proposals/pull/56

> Remember that proposals are just that; subject to change until Stage 4!

## Examples

```js
let length = vector => match (vector) {
{ x, y, z }: Math.sqrt(x ** 2 + y ** 2 + z ** 2),
{ x, y }: Math.sqrt(x ** 2 + y ** 2),
[...]: vector.length,
else: {
throw new Error("Unknown vector type");
}
}
```

```js
let isVerbose = config => match (config) {
{ output: { verbose: true } }: true,
else: false
}

let outOfBoundsPoint = p => match (p) {
{ x > 100, y }: true,
{ x, y > 100 }: true,
else: false
}
```

You can find more example in the spec repo.

## Parsing

> https://github.com/babel/babylon/blob/master/CONTRIBUTING.md#creating-a-new-plugin-spec-new

- [ ] Babylon plugin: `patternMatching`

## Transform

- [ ] Babel plugin

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.