in js/src/fluent-serialize.ts [19:45]
export function fluentSerializePattern(
pattern: Pattern,
onError: (error: SerializeError) => void
): string {
let str = ''
for (const part of pattern) {
if (typeof part === 'string') {
str += part
.replaceAll('\\', '\\\\')
.replaceAll('{', '\\u007b')
.replaceAll('}', '\\u007d')
} else {
try {
str += `{ ${expression(part)} }`
} catch (error) {
if (error instanceof SerializeError) {
error.pos = str.length
onError(error)
} else {
onError(new SerializeError(`fluent: ${error}`, str.length))
}
str += ERROR_RESULT
}
}
}
return str
}