@formatjs/cli 6.16.1 → 6.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/formatjs
CHANGED
|
@@ -15098,15 +15098,55 @@ function doPrintAST(ast, isInPlural) {
|
|
|
15098
15098
|
function printTagElement(el) {
|
|
15099
15099
|
return `<${el.value}>${printAST(el.children)}</${el.value}>`;
|
|
15100
15100
|
}
|
|
15101
|
-
function
|
|
15102
|
-
return
|
|
15101
|
+
function quoteSyntaxToken(token) {
|
|
15102
|
+
return `'${token.split("'").join("''")}'`;
|
|
15103
|
+
}
|
|
15104
|
+
function isAlpha(ch) {
|
|
15105
|
+
if (!ch) return false;
|
|
15106
|
+
const code = ch.charCodeAt(0);
|
|
15107
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
15108
|
+
}
|
|
15109
|
+
function isTagSyntaxStart(message, index) {
|
|
15110
|
+
if (message[index] !== "<") return false;
|
|
15111
|
+
const next = message[index + 1];
|
|
15112
|
+
return next === "/" || isAlpha(next);
|
|
15113
|
+
}
|
|
15114
|
+
function findTagSyntaxEnd(message, index) {
|
|
15115
|
+
const closingIndex = message.indexOf(">", index + 1);
|
|
15116
|
+
return closingIndex === -1 ? message.length : closingIndex + 1;
|
|
15117
|
+
}
|
|
15118
|
+
function findBraceSyntaxEnd(message, index) {
|
|
15119
|
+
const closingIndex = message.indexOf("}", index + 1);
|
|
15120
|
+
return closingIndex === -1 ? index + 1 : closingIndex + 1;
|
|
15121
|
+
}
|
|
15122
|
+
function printEscapedMessage(message, isInPlural = false) {
|
|
15123
|
+
let result = "";
|
|
15124
|
+
let literalStart = 0;
|
|
15125
|
+
function quoteToken(start, end) {
|
|
15126
|
+
result += message.slice(literalStart, start);
|
|
15127
|
+
result += quoteSyntaxToken(message.slice(start, end));
|
|
15128
|
+
literalStart = end;
|
|
15129
|
+
}
|
|
15130
|
+
for (let i = 0; i < message.length; i++) {
|
|
15131
|
+
const ch = message[i];
|
|
15132
|
+
if (ch === "{") {
|
|
15133
|
+
const end = findBraceSyntaxEnd(message, i);
|
|
15134
|
+
quoteToken(i, end);
|
|
15135
|
+
i = end - 1;
|
|
15136
|
+
} else if (ch === "}") quoteToken(i, i + 1);
|
|
15137
|
+
else if (isTagSyntaxStart(message, i)) {
|
|
15138
|
+
const end = findTagSyntaxEnd(message, i);
|
|
15139
|
+
quoteToken(i, end);
|
|
15140
|
+
i = end - 1;
|
|
15141
|
+
} else if (isInPlural && ch === "#") quoteToken(i, i + 1);
|
|
15142
|
+
}
|
|
15143
|
+
return result + message.slice(literalStart);
|
|
15103
15144
|
}
|
|
15104
15145
|
function printLiteralElement({ value }, isInPlural, isFirstEl, isLastEl) {
|
|
15105
15146
|
let escaped = value;
|
|
15106
15147
|
if (!isFirstEl && escaped[0] === `'`) escaped = `''${escaped.slice(1)}`;
|
|
15107
15148
|
if (!isLastEl && escaped[escaped.length - 1] === `'`) escaped = `${escaped.slice(0, escaped.length - 1)}''`;
|
|
15108
|
-
|
|
15109
|
-
return isInPlural ? escaped.replace("#", "'#'") : escaped;
|
|
15149
|
+
return printEscapedMessage(escaped, isInPlural);
|
|
15110
15150
|
}
|
|
15111
15151
|
function printArgumentElement({ value }) {
|
|
15112
15152
|
return `{${value}}`;
|