Repository navigation
Conversation
BREAKING CHANGE: the values of a `MessageTree` can be arrays. Code that treats a non-leaf value as an object has to check it with `isMessageObject` first.
Add CallSpec.subtree. vue-i18n tm and $tm use it.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Member
Author
|
@antfubot Can you please review this PR? (don't know if mentioning you will work :P |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tm('home.benefits.list')on an array in a JSON locale file reportedmissing-key. The JSON reader skipped arrays, so the message tree had no array nodes for a usage to match.The message tree now holds arrays, and
jsonandjsoncread and write them by the shape the file has. An item has the key of its index (list.0,steps.0.title).planArrayDelete, shared by the tree operations and the in-place JSON edit. An item in the middle is emptied so the other indexes stay. The last item is cut off together with the empty items next to it. When nothing is left, the array is removed.tmand$tm, and i18nextt(key, { returnObjects }). A call that names an array counts the whole array, since the items of an array have no names to read them by.list[0]anda["b"], match the keyslist.0anda.b.Related issue
Closes #172
Evidence
The new tests group by behavior.
"0"and"1"stays an object, and every delete case gives the same result through the in-place edit and through the tree operations. Deleting the last item of["", "B", "", "D"]leaves["", "B"].x18nbinary cover diagnostics, hover, annotations, quick fixes,check --fix,delete --unusedandseton arrays. The scenario from the issue is pinned bycheck finds no missing key and no unused item for tm() and a bracket pathinpackages/cli/test/arrays.test.ts.The same commands on the base (
da68e6c7) and on this branch, in a temporary project with vue-i18n 11 andhome.benefits.list: ["Fast", "Small"]inen.json:Nothing was run in VS Code or the web UI. The editor behavior is covered by the language server tests.
Merge Danger
Door: two-way
Blast Radius: core, JSON locale files, vue-i18n and i18next projects
The first commit is marked breaking, and the break is narrow. The values of a
MessageTreecan be arrays, so code that reads those values has to check for an object withisMessageObjectbefore it reads fields. Code that only builds trees or passes them on is not affected. Only JSON files produce arrays. The PR addsMessageNode,ArrayDeletePlan,planArrayDelete,isMessageObject, theshapefield ofsetops andCallSpec.subtree(a boolean, or{ option }).Arrays in JSON files were skipped before and are keys now. A project that reads an array in a way x18n cannot follow will see its items as unused, for example
t('home', options)on the parent object, orreturnObjectsset in the init code.x18n delete --unused --dry-runlists them before anything is deleted.