Skip to content

Commit 67e112d

Browse files
committed
fix: 🐛 migration script support for get function
1 parent bde9c32 commit 67e112d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

schematics/src/migrate/migration.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function run(path) {
7171
to: match => match.replace(/TranslateService|TranslatePipe/g, 'TranslocoService')
7272
};
7373

74-
const instantTranslation = {
74+
const serviceTranslation = {
7575
...tsFiles,
7676
from: /[^]*(?=(?:private|protected|public)\s+([^,:()]+)\s*:\s*(?:TranslocoService\s*(?:,|\))))[^]*/gm,
7777
to: match => {
@@ -82,9 +82,12 @@ export function run(path) {
8282
.split('')
8383
.map(char => (['$', '^'].includes(char) ? `\\${char}` : char))
8484
.join('');
85-
return match.replace(new RegExp(`(?:(?:=\\s*|this\\.)${sanitizedName})\\.(instant|transform)`, 'g'), str =>
86-
str.replace(/instant|transform/, 'translate')
85+
const functionsMap = { instant: 'translate', transform: 'translate', get: 'selectTranslate' };
86+
const translationCalls = new RegExp(
87+
`(?:(?:\\s*|this\\.)${sanitizedName})(?:\\s*\\t*\\r*\\n*)*\\.(?:\\s*\\t*\\r*\\n*)*(instant|transform|get)`,
88+
'g'
8789
);
90+
return match.replace(translationCalls, str => str.replace(/instant|transform|get/, func => functionsMap[func]));
8891
}
8992
};
9093

@@ -112,8 +115,8 @@ export function run(path) {
112115
step: 'constructor injections'
113116
},
114117
{
115-
matchers: [instantTranslation],
116-
step: 'instant translations'
118+
matchers: [serviceTranslation],
119+
step: 'service translations'
117120
}
118121
];
119122

0 commit comments

Comments
 (0)