Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tc39-proposal-pattern-matching#6761

Closed
vincentdchan wants to merge 41 commits intobabel:masterfrom
vincentdchan:pattern-matching
Closed

tc39-proposal-pattern-matching#6761
vincentdchan wants to merge 41 commits intobabel:masterfrom
vincentdchan:pattern-matching

Conversation

@vincentdchan
Copy link
Contributor

@vincentdchan vincentdchan commented Nov 7, 2017

Q                       A
Fixed Issues? No
Patch: Bug Fix? No
Major: Breaking Change? No
Minor: New Feature? parsing pattern matching expression
Tests Added + Pass? Yes
Documentation PR No
Any Dependency Changes? No
License MIT

Example:

var test = {
    a: [1,2,3],
    b: {
      bb: "ok"
    },
    c: [[1,2], [3,4]],
}

// nested
assert.equal(match(test) {
  {c:[[1,2], [d, 4]]}: d, // match 3, and bind d to 3
  else: "foo"
}, 3);
var test = {
    a: 1,
    b: 2,
    c: {
      cc: "hello",
      ccc: " world",
    },
};

// rest matching
assert.equal(match(test) {
  {c: {cc, ...rest}}: cc + rest.ccc,  // match object, and bind rest property to `rest`
  else: "foo"
}, "hello world");

Progress:

  • a parser for match expression
  • a transform plugin
  • rest identifier feature

define AST in types.js
add a parsing plugin
add basic test and fix a parsing bug
new AST of clause
fix "else" parsing bug
add a test case
fix a bug about string literal
add test of match function call
@xtuc xtuc added Spec: Pattern Matching PR: New Feature 🚀 A type of pull request used for our changelog categories labels Nov 7, 2017
@babel-bot
Copy link
Collaborator

babel-bot commented Nov 7, 2017

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/7391/

@hzoo
Copy link
Member

hzoo commented Nov 7, 2017

Thanks for the PR! Issue for babel is at babel/proposals#6

Just FYI @krzkaczor also had started a PR at babel/babylon#635 before we moved babylon back into this repo

@vincentdchan
Copy link
Contributor Author

@hzoo Oh, I'll take a look at it, I'm sure some code and tests can be reused.

@hzoo
Copy link
Member

hzoo commented Nov 9, 2017

Btw can ast test changes in https://deploy-preview-1421--babel.netlify.com/repl/build/5694/, from babel/website#1421

ah nvm need to make a syntax plugin and add it to stage-0 to test

@@ -0,0 +1,3 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you commit these config files locally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, got it

@vincentdchan vincentdchan force-pushed the pattern-matching branch 4 times, most recently from 994c02c to 5802d25 Compare November 11, 2017 02:22
@vincentdchan
Copy link
Contributor Author

@hzoo got it.

@vincentdchan vincentdchan force-pushed the pattern-matching branch 2 times, most recently from 380cca0 to e7a325d Compare November 13, 2017 14:35
@vincentdchan vincentdchan changed the title Babylon: parsing part of pattern matching tc39-proposal-pattern-matching Nov 13, 2017
@xtuc
Copy link
Member

xtuc commented Dec 11, 2017

@titouancreach yes we will, we are currently busy with the Babel 7 release sorry

# Conflicts:
#	packages/babel-preset-stage-0/package.json
#	packages/babel-preset-stage-0/src/index.js
@babakness
Copy link

Please merge this!! Excited to try it out :-)

ID: id,
});
} else {
return template.expression(`(PATTERN[Symbol.match] &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposal refers to Symbol.matches, not Symbol.match

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ricochet1k Thx. I am going to fix it.

@vincentdchan
Copy link
Contributor Author

@babakness It's coming soon! I am working on it.

@vincentdchan
Copy link
Contributor Author

vincentdchan commented Feb 28, 2018

@hzoo @xtuc It's complete!


switch (pattern.type) {
case "NumericLiteral":
case "BigIntLiteral":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since BigInt is not implemented in Babel, I think we should already include it here. It sounds like extra maintenance if it change.

Also it's not testable?

We'll need to create a issue to track that tho.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should we keep it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to remove it, but let's wait for more thoughts on this.

BODY
}()`)({
BODY: bodyExpr,
}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like templates but this one could be clearer using t.* builders IMO

},
[1, 2, 3, 4]: 3,
[1, 2, 3, 4, 5]: 4
}, 666);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this feature called stupid-fixture-nesting-folder? That isn't stupid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I just copy the folder from another plugin, I'll remove it. Of cause it isn't stupid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

2: "3"
}
} catch (e) {
assert.equal(e.toString(), "Error: No patterns are matched");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zkat: [...] the new spec throws a MatchError when no clauses were able to match [...]

@vincentdchan
Copy link
Contributor Author

There are still two issues here:

This PR lasted four months. 😂😂😂

@xtuc
Copy link
Member

xtuc commented Mar 5, 2018

This PR lasted four months.

I didn't finish my last review, sorry. And sorry if that takes so long, thanks!

@zkat
Copy link

zkat commented Mar 25, 2018

nudge: this spec looks pretty different now. See https://github.com/tc39/proposal-pattern-matching

@xtuc
Copy link
Member

xtuc commented Mar 26, 2018

Thanks for the update @zkat, we can see the changes in the PR here tc39/proposal-pattern-matching#65.

Sorry for the delai @vincentdchan, TC39 was missing a champion on this proposal and @zkat took over championing now (thanks 😄 )

@vincentdchan
Copy link
Contributor Author

@xtuc OK. I have communicated with @zkat privately, and I will still work on this PR. But it takes time to implement the new proposal.

@xtuc
Copy link
Member

xtuc commented Mar 26, 2018

@vincentdchan sounds good to me, thanks for your work on this!

@zloirock
Copy link
Member

I added Symbol.{patternMatch, patternValue} for this proposal to core-js@3.

@xtuc
Copy link
Member

xtuc commented Mar 27, 2018

Btw @vincentdchan we could close this PR and open a new one if you want to avoid the old comments here, might be easier to follow?

@vincentdchan vincentdchan mentioned this pull request Mar 27, 2018
5 tasks
@vincentdchan
Copy link
Contributor Author

Closed! Move to #7633

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: New Feature 🚀 A type of pull request used for our changelog categories Spec: Pattern Matching

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants