tc39 / proposal-pattern-matching

Pattern matching syntax for ECMAScript
https://tc39.es/proposal-pattern-matching/
MIT License
5.51k stars 89 forks source link

Syntax feature layering #306

Open Jack-Works opened 1 year ago

Jack-Works commented 1 year ago

[!NOTE] I'd like to continue to update this if it is necessary. This issue currently reflects what we have (in #293).

I'm trying to refactor what ideas we have based on the layering idea. This is also an answer to #305, #281

By layering, I do not mean we must have all features in layer 1 or must defer all features in layer 2.

This layering mostly focused on syntax, not runtime semantics.

I'll analyze this based on whether we can desugar a pattern into the composition of other patterns. (So you'll find the Primitive pattern (1 in { x: 1 }) is in Layer 2.)

This means we can pick all features from Layer 0 and some features from Layer 1 and 2, then the results become a somewhat usable pattern-matching proposal. (You may want to take a look at https://github.com/codehag/pattern-matching-epic).

I include:

Non-pattern structures

Level 0: Basic feature

We should have at least one of them to enter the pattern world.

Level 1: Good to have

Maybe future extensions.

Pattern

Level 0: Basic features, impossible to desugar

Level 1: Advance features, impossible to desugar

Level 2: Ergonomic features