-
Notifications
You must be signed in to change notification settings - Fork 79
Typing fixes for Pontoon TypeScript migration, fix #524 #525
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
Conversation
Pike
commented
Mar 17, 2021
- Stricter typing for @fluent/langneg
The AST now aligns with the fluent-rs one, and less so with the reference AST. That's OK as it helps consumers of the library in types JS variants to use narrowing reliably.
7c20668
to
8dab470
Compare
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.
lgtm. one suggestion, optional, if-minor.
getInlineExpression(ps: FluentParserStream): AST.Expression | AST.Placeable { | ||
getInlineExpression( | ||
ps: FluentParserStream | ||
): AST.InlineExpression | AST.Placeable { |
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.
suggestion (if-minor)
: this could be a bit cleaner if we separated getPlaceable
from getInlineExpression
.
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.
I gave this a look, and my intuition isn't strong here. And I don't think our tests are exhaustive. Like, I was rather surprised that
shared-photos = {NUMBER({1 ->
*[1] 2
})}
works. Which made me wonder if it's not about expressions when it comes down to block vs inline, but placeable.
I've paged most of that context out of my brain, so it's not minor to me.
Playground also seems to behave differently to my local repo, and I'll call shotgun on that one. It still uses the 0.14
compat build.
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.
ouch. That's not spec compliant, right?
Spec doesn't allow for it - https://github.com/projectfluent/fluent/blob/master/spec/fluent.ebnf#L74
Rust doesn't allow for it - https://github.com/projectfluent/fluent-rs/blob/master/fluent-syntax/src/parser/expression.rs#L176
maybe it's time to consider Rust->JS export for the parser?
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.
I think the spec allows it, https://github.com/projectfluent/fluent/blob/master/spec/fluent.ebnf#L59 has the inline_placeable
as inline expression. And I tested the fluent-rs parser, too, and it was fine.
jazz = {{{1->
*[1] 2
}}->
*[1] 3
}
OTH is illegal. Works on playground as in not only in the resolver, but also shows an AST.
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.
ah, right. The placeholder
loophole in inline :) retracting my previous statement.
I've also tested this with temporarily installing my branch on the corresponding Pontoon PR, mozilla/pontoon#1902. When doing the TS conversion there, I end up with just two remaining issues, where the Transformer claims to not have the Which is a long winding way of saying that this doesn't just look nice in theory, but also stood the test of a TypeScript consumer. |