feat(developer): ldml fix all remaining TODOs around markers and variables 🙀 #9688
feat(developer): ldml fix all remaining TODOs around markers and variables 🙀 #9688
Conversation
User Test ResultsTest specification and instructions User tests are not required Test Artifacts
|
mcdurdin
left a comment
There was a problem hiding this comment.
LGTM but would be good to refactor away the potentially gnarly string replacement snippet
common/web/types/src/kmx/kmx-plus.ts
Outdated
| if(s === undefined || s === null) { | ||
| s = ''; | ||
| } |
There was a problem hiding this comment.
| if(s === undefined || s === null) { | |
| s = ''; | |
| } | |
| s = s ?? ''; |
Seems shorter 😁
Ref https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing
common/web/types/src/kmx/kmx-plus.ts
Outdated
| return this.allocList(sections.strs, s.split(' ').map(s => { | ||
| s = sections.vars.substituteStrings(s, sections); | ||
| s = sections.vars.substituteMarkerString(s); | ||
| s = unescapeString(s); | ||
| return s; | ||
| })); |
There was a problem hiding this comment.
| return this.allocList(sections.strs, s.split(' ').map(s => { | |
| s = sections.vars.substituteStrings(s, sections); | |
| s = sections.vars.substituteMarkerString(s); | |
| s = unescapeString(s); | |
| return s; | |
| })); | |
| return this.allocList(sections.strs, s.split(' ').map(t => { | |
| t = sections.vars.substituteStrings(t, sections); | |
| t = sections.vars.substituteMarkerString(t); | |
| t = unescapeString(t); | |
| return t; | |
| })); |
Reusing s on inner scope is not ideal for readability
| cookedTo = sections.vars.substituteStrings(cookedTo, sections); | ||
| cookedTo = sections.vars.substituteMarkerString(cookedTo); | ||
| const to = sections.strs.allocAndUnescapeString(cookedTo, true); |
There was a problem hiding this comment.
This pattern is repeated, refactor? It is also similar in disp.ts but written nested for added confusions!
| cookedLongPressDefault = sections.vars.substituteStrings(cookedLongPressDefault, sections); | ||
| cookedLongPressDefault = sections.vars.substituteMarkerString(cookedLongPressDefault) | ||
| const longPressDefault = sections.strs.allocAndUnescapeString(cookedLongPressDefault); |
| to: sections.strs.allocAndUnescapeString( | ||
| sections.vars.substituteMarkerString( | ||
| sections.vars.substituteStrings(display.to, sections))), |
There was a problem hiding this comment.
This is similar to the code in keys.ts
| display: sections.strs.allocAndUnescapeString( | ||
| sections.vars.substituteStrings(display.display, sections)), |
| let toCooked = sections.vars.substituteStrings(toRaw, sections); | ||
| toCooked = sections.vars.substituteMarkerString(toCooked); | ||
| const to = sections.strs.allocAndUnescapeString(toCooked, true); |
|
@mcdurdin trying to DRY this out a little bit… const id = sections.strs.allocString(key.id);
const longPress: ListItem = sections.list.allocListFromSpaces(
key.longPress, {
substituteStrs: true,
markers: true,
unescape: true,
},
sections);
const longPressDefault = sections.strs.allocString(key.longPressDefault,
{
stringVariables: true,
markers: true,
unescape: true,
},
sections); |
- refactor string preprocessing pipeline into an options bag
|
Work in progress. tests fail. |
I like. These objects then lend themselves to being constants defined as part of the structural definitions, which is then easy to compare against the spec. |
|
VERY strange basically |
export class ListItem extends Array<ListIndex> implements OrderedStringList {
… but yet, inside of ListItem.toStringArray(): > this.map(q => q);
Uncaught TypeError TypeError: source is not iterable
at ListItem (/Users/srl295/src/keymanapp/keyman/common/web/types/src/kmx/string-list.ts:41:23)
at eval (repl:1:6)If I'm in a member function, why is it allocating a ListItem? is it looking for a copy constructor? this works, though > Array.from(this.values())
(3) [ListIndex, ListIndex, ListIndex]
Array.from(this.values())[0]
á
Array.from(this.values())[1]
é
Array.from(this.values()).map(q => q)
(3) [ListIndex, ListIndex, ListIndex]
Array.from(this.values()).map(q => q.toString())
(3) ['á', 'é', 'í']so somehow TypeScript's |
|
OK I think i undertstand now.
|
|
I'll do another check w/ base branch and then merge this. |
|
Changes in this pull request will be available for download in Keyman version 17.0.187-alpha |
For: #9121
For: #9119
@keymanapp-test-bot skip