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

Skip to content

Update MF2 to match upstream changes #414

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 44 commits into from
Jan 7, 2024
Merged

Update MF2 to match upstream changes #414

merged 44 commits into from
Jan 7, 2024

Conversation

eemeli
Copy link
Member

@eemeli eemeli commented Jan 3, 2024

This should bring the implementation to parity with the current spec, pre-emptively also including changes from:

Some ESLint changes are included, which is why this touches some files outside the packages/mf2-* directories. I've also dropped commitlint, as it was getting too annoying during development.

The @messageformat/fluent package is here made ES-only, as that was the easiest way to satisfy TS regarding its @fluent/syntax dependency. This may be a temporary thing; we'll see. The Fluent -> MF2 converters now use duck-typing to detect plural selectors; this can be disabled with an option.

The XLIFF representation is streamlined a bit. Am considering using <originalData> and <res:resourceData> for some of what's currently in a wholly custom <mf:messageformat> container.

The messageformat exports are refactored quite a bit, adding new endpoints messageformat/functions and messageformat/functions/utils with relevant parts of the API.

Two new data model tools are added:

import { validate, visit } from 'messageformat'

visit is a specialized message data visitor, and validate checks that the model does not have any data model errors, and reports the function & variable dependencies of a message. Currently it effectively duplicates functionality from the CST parser; that should get resolved at some point, but that'll require a datamodel -> CST mapper so that the errors can still be reported by character position.

The JSON test fixtures are refactored a bit, separating out:

  • syntax errors
  • tests that are independent of all function calls
  • tests for each function

The internal file structures of the main package have evolved quite a bit, and feel like they make some sense again. I'm not really expecting anyone to review all the changes here, as that would likely be quite a slog.

CC @aphillips, @mradbourne

@aphillips
Copy link

Very happy to see this working going on. I didn't read to the bottom of the code yet. I do notice lots of good general code hygiene in here as well.

@eemeli
Copy link
Member Author

eemeli commented Jan 3, 2024

Added CST backreferences to the parsed data model, available as [Symbol.for('CST')] on most nodes. This let me dedupe the data model error validation, which sparked another refactor of the visitor. It now lets you run code on both node entry & exit, provides more context, has more nodes it covers, and a catch-all node() that can be useful for stuff like:

function trimCST(msg: Message) {
delete msg[cst];
visit(msg, {
node(node) {
delete node[cst];
}
});
}

@eemeli
Copy link
Member Author

eemeli commented Jan 3, 2024

Added stringifyCST(), as that was clearly missing. This update should now be pretty much complete; next steps can be taken separately.

@eemeli eemeli merged commit 1974fb9 into main Jan 7, 2024
@eemeli eemeli deleted the mf2-update branch January 7, 2024 17:09
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.

2 participants