(sourceCode: string, mapping: MigrationMapping)
| 13 | |
| 14 | /** Migrates the legacy message IDs within a single file. */ |
| 15 | export function migrateFile(sourceCode: string, mapping: MigrationMapping) { |
| 16 | const legacyIds = Object.keys(mapping); |
| 17 | |
| 18 | for (const legacyId of legacyIds) { |
| 19 | const canonicalId = mapping[legacyId]; |
| 20 | const pattern = new RegExp(escapeRegExp(legacyId), 'g'); |
| 21 | sourceCode = sourceCode.replace(pattern, canonicalId); |
| 22 | } |
| 23 | |
| 24 | return sourceCode; |
| 25 | } |
| 26 | |
| 27 | /** Escapes special regex characters in a string. */ |
| 28 | function escapeRegExp(str: string): string { |
no test coverage detected
searching dependent graphs…