-
Notifications
You must be signed in to change notification settings - Fork 2k
Add support for leading vertical bar in union types #907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for leading vertical bar in union types #907
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! See inline for a question and some suggested additional test cases.
@@ -83,6 +83,8 @@ union Feed = Story | Article | Advert | |||
|
|||
union AnnotatedUnion @onUnion = A | B | |||
|
|||
union AnnotatedUnionTwo @onUnion = A | B |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you intend to have | A | B
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope the printer will only print without it or with it I think it's better to leave it out and add it with prettier for ex
}; | ||
expect(printJson(doc)).to.equal(printJson(expected)); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please also add test cases for | Wo | Rld |
, union Hello = Wo | Rld |
, Wo || Rld
and union Hello = |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay
@robzhu I added severals news tests |
@alexandrebodin, thank you for the high quality PR and fast turnaround! |
@@ -943,6 +943,9 @@ function parseUnionTypeDefinition(lexer: Lexer<*>): UnionTypeDefinitionNode { | |||
*/ | |||
function parseUnionMembers(lexer: Lexer<*>): Array<NamedTypeNode> { | |||
const members = []; | |||
if (peek(lexer, TokenKind.PIPE)) { | |||
skip(lexer, TokenKind.PIPE); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wrapping peek
is unnecessary. skip
is effectively a call to peek
.
@@ -943,6 +943,9 @@ function parseUnionTypeDefinition(lexer: Lexer<*>): UnionTypeDefinitionNode { | |||
*/ | |||
function parseUnionMembers(lexer: Lexer<*>): Array<NamedTypeNode> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every method in the parser has parse language atop it. It would be nice to include this here as well
This is not the only place in the IDL where bar-separated tokens exists. Should we remain consistent and update the others as well? Or would that not be fitting? |
@leebyron I could update the other places if you can point them to me. |
Let me take a quick look |
This adds a bit of cleanup after #907 for post-commit review: * Removes unnecessary `peek()` * Adds leading pipe support to directive locations * Removes some redundant tests * Orders tests so similar tests remain together
This adds a bit of cleanup after #907 for post-commit review: * Removes unnecessary `peek()` * Adds leading pipe support to directive locations * Removes some redundant tests * Orders tests so similar tests remain together
Implementation of the leading vertical bar in the language parser.
Issue #897