Skip to content

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

Merged
merged 6 commits into from
Apr 2, 2021

Conversation

Pike
Copy link
Contributor

@Pike Pike commented Mar 17, 2021

  • Stricter typing for @fluent/langneg

@Pike Pike linked an issue Mar 17, 2021 that may be closed by this pull request
Pike added 4 commits March 29, 2021 02:02
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.
@Pike Pike force-pushed the strict-typing branch 3 times, most recently from 7c20668 to 8dab470 Compare April 1, 2021 12:28
@Pike Pike marked this pull request as ready for review April 2, 2021 15:43
@Pike Pike requested a review from zbraniecki April 2, 2021 15:43
Copy link
Collaborator

@zbraniecki zbraniecki left a 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 {
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

@Pike
Copy link
Contributor Author

Pike commented Apr 2, 2021

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 visit and genericVisit methods. Given they're there, I don't think that should block.

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.

@Pike Pike merged commit 29ab4a6 into projectfluent:master Apr 2, 2021
@Pike Pike deleted the strict-typing branch April 2, 2021 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve typing support to aid Pontoon flow-to-ts migration
2 participants