Skip to content

Commit

Permalink
Allow trailing comma after rest param for component types
Browse files Browse the repository at this point in the history
Summary:
Similar to D63488906, this diff does the same for component types.

Changelog: [parser] Trailing comma is now allowed after rest parameter in component type.

Reviewed By: alexmckenley

Differential Revision: D63661834

fbshipit-source-id: 5a1b80d186316bd24521a2fe79024171c1c41973
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Oct 1, 2024
1 parent aba1e98 commit ded62d3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
type Comp1 = component(p1: Tp1, 'p2': Tp2);

type Comp2 = component(...Rest);

type Comp3 = component(...Rest,);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type":"Program",
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":3,"column":32}},
"range":[0,77],
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":5,"column":33}},
"range":[0,112],
"body":[
{
"type":"TypeAlias",
Expand Down Expand Up @@ -124,6 +124,49 @@
"rendersType":null,
"typeParameters":null
}
},
{
"type":"TypeAlias",
"loc":{"source":null,"start":{"line":5,"column":0},"end":{"line":5,"column":33}},
"range":[79,112],
"id":{
"type":"Identifier",
"loc":{"source":null,"start":{"line":5,"column":5},"end":{"line":5,"column":10}},
"range":[84,89],
"name":"Comp3",
"typeAnnotation":null,
"optional":false
},
"typeParameters":null,
"right":{
"type":"ComponentTypeAnnotation",
"loc":{"source":null,"start":{"line":5,"column":13},"end":{"line":5,"column":32}},
"range":[92,111],
"params":[],
"rest":{
"type":"ComponentTypeParameter",
"loc":{"source":null,"start":{"line":5,"column":23},"end":{"line":5,"column":31}},
"range":[102,110],
"name":null,
"typeAnnotation":{
"type":"GenericTypeAnnotation",
"loc":{"source":null,"start":{"line":5,"column":26},"end":{"line":5,"column":30}},
"range":[105,109],
"id":{
"type":"Identifier",
"loc":{"source":null,"start":{"line":5,"column":26},"end":{"line":5,"column":30}},
"range":[105,109],
"name":"Rest",
"typeAnnotation":null,
"optional":false
},
"typeParameters":null
},
"optional":false
},
"rendersType":null,
"typeParameters":null
}
}
],
"comments":[]
Expand Down
2 changes: 2 additions & 0 deletions lib/Parser/JSParserImpl-flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ Optional<ESTree::Node *> JSParserImpl::parseComponentTypeRestParameterFlow(
typeAnnotation = *optLeft;
}

checkAndEat(TokenKind::comma, JSLexer::GrammarContext::Type);

return setLocation(
start,
getPrevTokenEndLoc(),
Expand Down

0 comments on commit ded62d3

Please sign in to comment.