@intlify/core 12.0.0-alpha.7 → 12.0.0-alpha.8
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/dist/core.esm-browser.js +35 -54
- package/dist/core.esm-browser.prod.js +348 -351
- package/dist/core.global.js +35 -54
- package/dist/core.global.prod.js +249 -252
- package/dist/core.js +1 -1
- package/dist/core.node.js +1 -1
- package/dist/core.runtime.esm-browser.js +29 -42
- package/dist/core.runtime.esm-browser.prod.js +201 -204
- package/dist/core.runtime.global.js +29 -42
- package/dist/core.runtime.global.prod.js +183 -186
- package/dist/core.runtime.js +3 -5
- package/dist/core.runtime.node.js +3 -5
- package/package.json +3 -3
package/dist/core.esm-browser.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @intlify/core v12.0.0-alpha.
|
|
2
|
+
* @intlify/core v12.0.0-alpha.8
|
|
3
3
|
* (c) 2016-present kazuya kawaguchi and contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
6
|
-
|
|
6
|
+
// packages/shared/src/utils.ts
|
|
7
7
|
/**
|
|
8
8
|
* Original Utilities
|
|
9
9
|
* written by kazuya kawaguchi
|
|
@@ -123,8 +123,7 @@ function generateCodeFrame(source, start = 0, end = source.length) {
|
|
|
123
123
|
}
|
|
124
124
|
return res.join("\n");
|
|
125
125
|
}
|
|
126
|
-
|
|
127
|
-
//#region packages/shared/src/warn.ts
|
|
126
|
+
// packages/shared/src/warn.ts
|
|
128
127
|
function warn(msg, err) {
|
|
129
128
|
if (typeof console !== "undefined") {
|
|
130
129
|
console.warn(`[intlify] ` + msg);
|
|
@@ -139,8 +138,7 @@ function warnOnce(msg) {
|
|
|
139
138
|
warn(msg);
|
|
140
139
|
}
|
|
141
140
|
}
|
|
142
|
-
|
|
143
|
-
//#region packages/shared/src/sanitize.ts
|
|
141
|
+
// packages/shared/src/sanitize.ts
|
|
144
142
|
function escapeHtml(rawText) {
|
|
145
143
|
return rawText.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'").replace(/\//g, "/").replace(/=/g, "=");
|
|
146
144
|
}
|
|
@@ -148,7 +146,7 @@ function escapeAttributeValue(value) {
|
|
|
148
146
|
return value.replace(/&(?![a-z0-9#]{2,6};)/gi, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
149
147
|
}
|
|
150
148
|
const javascriptSchemePattern = /^javascript:/i;
|
|
151
|
-
const urlAttributePattern = /^(?:href|src|action|formaction)$/i;
|
|
149
|
+
const urlAttributePattern = /^(?:href|xlink:href|src|action|formaction)$/i;
|
|
152
150
|
const numericCharacterReferencePattern = /&#(?:x([0-9a-f]+)|(\d+));?/gi;
|
|
153
151
|
const namedWhitespaceCharacterReferencePattern = /&(?:Tab|NewLine);/g;
|
|
154
152
|
const colonCharacterReferencePattern = /:?/gi;
|
|
@@ -157,7 +155,9 @@ const eventHandlerPattern = /(?:^|[\s"'<>/])on\w+\s*=\s*["']?[^"'>]+["']?/i;
|
|
|
157
155
|
const eventHandlerAttributePattern = /(^|[\s"'<>/])on(\w+\s*=)/gi;
|
|
158
156
|
const srcdocPattern = /(?:^|[\s"'<>/])srcdoc\s*=/i;
|
|
159
157
|
const srcdocAttributePattern = /(^|[\s"'<>/])s(rcdoc\s*=)/gi;
|
|
160
|
-
const
|
|
158
|
+
const dangerousElementPattern = /<(?:base|animate|set)(?=[\s/>]|$)/i;
|
|
159
|
+
const dangerousElementStartTagPattern = /<(base|animate|set)(?=[\s/>]|$)/gi;
|
|
160
|
+
const unquotedUrlAttributePattern = /(^|[\s"'<>/])((?:href|xlink:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi;
|
|
161
161
|
function decodeNumericCharacterReference(match, hex, decimal) {
|
|
162
162
|
const digits = hex || decimal;
|
|
163
163
|
if (!digits) return match;
|
|
@@ -216,11 +216,14 @@ function sanitizeTranslatedHtml(html) {
|
|
|
216
216
|
warn("Potentially dangerous srcdoc attribute detected in translation. Consider removing srcdoc from your translation messages.");
|
|
217
217
|
html = html.replace(srcdocAttributePattern, "$1s$2");
|
|
218
218
|
}
|
|
219
|
+
if (dangerousElementPattern.test(html)) {
|
|
220
|
+
warn("Potentially dangerous element (<base>, <animate> or <set>) detected in translation. Consider removing it from your translation messages.");
|
|
221
|
+
html = html.replace(dangerousElementStartTagPattern, "<$1");
|
|
222
|
+
}
|
|
219
223
|
html = html.replace(unquotedUrlAttributePattern, (match, boundary, prefix, attrValue) => hasJavascriptScheme(attrValue) ? `${boundary}${prefix}about:blank` : match);
|
|
220
224
|
return html;
|
|
221
225
|
}
|
|
222
|
-
|
|
223
|
-
//#region packages/shared/src/messages.ts
|
|
226
|
+
// packages/shared/src/messages.ts
|
|
224
227
|
const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
|
|
225
228
|
function deepCopy(src, des) {
|
|
226
229
|
if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des) || des === Object.prototype) throw new Error("Invalid value");
|
|
@@ -250,8 +253,7 @@ function deepCopy(src, des) {
|
|
|
250
253
|
}
|
|
251
254
|
}
|
|
252
255
|
}
|
|
253
|
-
|
|
254
|
-
//#region packages/message-compiler/src/location.ts
|
|
256
|
+
// packages/message-compiler/src/location.ts
|
|
255
257
|
function createPosition(line, column, offset) {
|
|
256
258
|
return {
|
|
257
259
|
line,
|
|
@@ -267,12 +269,10 @@ function createLocation(start, end, source) {
|
|
|
267
269
|
if (source != null) loc.source = source;
|
|
268
270
|
return loc;
|
|
269
271
|
}
|
|
270
|
-
|
|
271
|
-
//#region packages/message-compiler/src/helpers.ts
|
|
272
|
+
// packages/message-compiler/src/helpers.ts
|
|
272
273
|
const RE_HTML_TAG = /<[\w\s=":;#-/]+>/;
|
|
273
274
|
const detectHtmlTag = (source) => RE_HTML_TAG.test(source);
|
|
274
|
-
|
|
275
|
-
//#region packages/message-compiler/src/errors.ts
|
|
275
|
+
// packages/message-compiler/src/errors.ts
|
|
276
276
|
const CompileErrorCodes = {
|
|
277
277
|
EXPECTED_TOKEN: 1,
|
|
278
278
|
INVALID_TOKEN_IN_PLACEHOLDER: 2,
|
|
@@ -323,8 +323,7 @@ function createCompileError(code, loc, options = {}) {
|
|
|
323
323
|
function defaultOnError(error) {
|
|
324
324
|
throw error;
|
|
325
325
|
}
|
|
326
|
-
|
|
327
|
-
//#region packages/message-compiler/src/mangler.ts
|
|
326
|
+
// packages/message-compiler/src/mangler.ts
|
|
328
327
|
const ERROR_DOMAIN$2 = "minifier";
|
|
329
328
|
function mangle(node) {
|
|
330
329
|
node.t = node.type;
|
|
@@ -398,8 +397,7 @@ function mangle(node) {
|
|
|
398
397
|
}
|
|
399
398
|
delete node.type;
|
|
400
399
|
}
|
|
401
|
-
|
|
402
|
-
//#region packages/message-compiler/src/optimizer.ts
|
|
400
|
+
// packages/message-compiler/src/optimizer.ts
|
|
403
401
|
function optimize(ast) {
|
|
404
402
|
const body = ast.body;
|
|
405
403
|
if (body.type === 2) optimizeMessageNode(body);
|
|
@@ -493,8 +491,7 @@ function createScanner(str) {
|
|
|
493
491
|
skipToPeek
|
|
494
492
|
};
|
|
495
493
|
}
|
|
496
|
-
|
|
497
|
-
//#region packages/message-compiler/src/tokenizer.ts
|
|
494
|
+
// packages/message-compiler/src/tokenizer.ts
|
|
498
495
|
const EOF = void 0;
|
|
499
496
|
const DOT = ".";
|
|
500
497
|
const LITERAL_DELIMITER = "'";
|
|
@@ -999,8 +996,7 @@ function createTokenizer(source, options = {}) {
|
|
|
999
996
|
context
|
|
1000
997
|
};
|
|
1001
998
|
}
|
|
1002
|
-
|
|
1003
|
-
//#region packages/message-compiler/src/parser.ts
|
|
999
|
+
// packages/message-compiler/src/parser.ts
|
|
1004
1000
|
const ERROR_DOMAIN = "parser";
|
|
1005
1001
|
const KNOWN_ESCAPES = /\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6})/g;
|
|
1006
1002
|
const TEXT_ESCAPES = /\\([\\@{}|])/g;
|
|
@@ -1231,8 +1227,7 @@ function getTokenCaption(token) {
|
|
|
1231
1227
|
const name = (token.value || "").replace(/\r?\n/gu, "\\n");
|
|
1232
1228
|
return name.length > 10 ? name.slice(0, 9) + "…" : name;
|
|
1233
1229
|
}
|
|
1234
|
-
|
|
1235
|
-
//#region packages/core-base/src/ast.ts
|
|
1230
|
+
// packages/core-base/src/ast.ts
|
|
1236
1231
|
function isMessageAST(val) {
|
|
1237
1232
|
return isObject(val) && resolveType(val) === 0 && (hasOwn(val, "b") || hasOwn(val, "body"));
|
|
1238
1233
|
}
|
|
@@ -1292,8 +1287,7 @@ const AST_NODE_PROPS_KEYS = [
|
|
|
1292
1287
|
function createUnhandleNodeError(type) {
|
|
1293
1288
|
return /* @__PURE__ */ new Error(`unhandled node type: ${type}`);
|
|
1294
1289
|
}
|
|
1295
|
-
|
|
1296
|
-
//#region packages/core-base/src/format.ts
|
|
1290
|
+
// packages/core-base/src/format.ts
|
|
1297
1291
|
function format(ast) {
|
|
1298
1292
|
return (ctx) => formatParts(ctx, ast);
|
|
1299
1293
|
}
|
|
@@ -1341,8 +1335,7 @@ function formatMessagePart(ctx, node) {
|
|
|
1341
1335
|
default: throw new Error(`unhandled node on format message part: ${type}`);
|
|
1342
1336
|
}
|
|
1343
1337
|
}
|
|
1344
|
-
|
|
1345
|
-
//#region packages/core-base/src/compilation.ts
|
|
1338
|
+
// packages/core-base/src/compilation.ts
|
|
1346
1339
|
const WARN_MESSAGE = `Detected HTML in '{source}' message. Recommend not using HTML messages to avoid XSS.`;
|
|
1347
1340
|
function checkHtmlMessage(source, warnHtmlMessage) {
|
|
1348
1341
|
if (warnHtmlMessage && detectHtmlTag(source)) warn(format$1(WARN_MESSAGE, { source }));
|
|
@@ -1396,8 +1389,7 @@ function compile(message, context) {
|
|
|
1396
1389
|
} else return format(message);
|
|
1397
1390
|
}
|
|
1398
1391
|
}
|
|
1399
|
-
|
|
1400
|
-
//#region packages/core-base/src/errors.ts
|
|
1392
|
+
// packages/core-base/src/errors.ts
|
|
1401
1393
|
const CoreErrorCodes = {
|
|
1402
1394
|
INVALID_ARGUMENT: 17,
|
|
1403
1395
|
INVALID_DATE_ARGUMENT: 18,
|
|
@@ -1419,8 +1411,7 @@ const errorMessages = {
|
|
|
1419
1411
|
[CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION]: "cannot support async function",
|
|
1420
1412
|
[CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE]: "cannot support locale type"
|
|
1421
1413
|
};
|
|
1422
|
-
|
|
1423
|
-
//#region packages/core-base/src/fallbacker.ts
|
|
1414
|
+
// packages/core-base/src/fallbacker.ts
|
|
1424
1415
|
/** @internal */
|
|
1425
1416
|
function getLocale(context, options) {
|
|
1426
1417
|
return options.locale != null ? resolveLocale(options.locale) : resolveLocale(context.locale);
|
|
@@ -1536,8 +1527,7 @@ function appendItemToChain(chain, target, blocks) {
|
|
|
1536
1527
|
}
|
|
1537
1528
|
return follow;
|
|
1538
1529
|
}
|
|
1539
|
-
|
|
1540
|
-
//#region packages/core-base/src/resolver.ts
|
|
1530
|
+
// packages/core-base/src/resolver.ts
|
|
1541
1531
|
const pathStateMachine = [];
|
|
1542
1532
|
pathStateMachine[0] = {
|
|
1543
1533
|
["w"]: [0],
|
|
@@ -1760,8 +1750,7 @@ function resolveValue(obj, path) {
|
|
|
1760
1750
|
}
|
|
1761
1751
|
return last;
|
|
1762
1752
|
}
|
|
1763
|
-
|
|
1764
|
-
//#region packages/core-base/src/warnings.ts
|
|
1753
|
+
// packages/core-base/src/warnings.ts
|
|
1765
1754
|
const CoreWarnCodes = {
|
|
1766
1755
|
NOT_FOUND_KEY: 1,
|
|
1767
1756
|
FALLBACK_TO_TRANSLATE: 2,
|
|
@@ -1795,13 +1784,12 @@ const warnMessages = {
|
|
|
1795
1784
|
function getWarnMessage(code, ...args) {
|
|
1796
1785
|
return format$1(warnMessages[code], ...args);
|
|
1797
1786
|
}
|
|
1798
|
-
|
|
1799
|
-
//#region packages/core-base/src/context.ts
|
|
1787
|
+
// packages/core-base/src/context.ts
|
|
1800
1788
|
/**
|
|
1801
1789
|
* Intlify core-base version
|
|
1802
1790
|
* @internal
|
|
1803
1791
|
*/
|
|
1804
|
-
const VERSION = "12.0.0-alpha.
|
|
1792
|
+
const VERSION = "12.0.0-alpha.8";
|
|
1805
1793
|
const NOT_RESOLVED = -1;
|
|
1806
1794
|
const DEFAULT_LOCALE = "en-US";
|
|
1807
1795
|
const MISSING_RESOLVE_VALUE = "";
|
|
@@ -2005,8 +1993,7 @@ function isImplicitFallback(targetLocale, locales) {
|
|
|
2005
1993
|
for (let i = index + 1; i < locales.length; i++) if (isAlmostSameLocale(targetLocale, locales[i])) return true;
|
|
2006
1994
|
return false;
|
|
2007
1995
|
}
|
|
2008
|
-
|
|
2009
|
-
//#region packages/core-base/src/formatter.ts
|
|
1996
|
+
// packages/core-base/src/formatter.ts
|
|
2010
1997
|
function resolveFormatLocale(context, key, locale, formats, missingWarn, fallbackWarn, type) {
|
|
2011
1998
|
const { fallbackLocale, localeFallbacker, onWarn } = context;
|
|
2012
1999
|
const locales = localeFallbacker(context, fallbackLocale, locale);
|
|
@@ -2114,15 +2101,13 @@ function parseFormatArgs(args, options, initialOverrides, optionsKeys) {
|
|
|
2114
2101
|
if (isPlainObject(arg4)) overrides = arg4;
|
|
2115
2102
|
return overrides;
|
|
2116
2103
|
}
|
|
2117
|
-
|
|
2118
|
-
//#region packages/core-base/src/intl.ts
|
|
2104
|
+
// packages/core-base/src/intl.ts
|
|
2119
2105
|
const intlDefined = typeof Intl !== "undefined";
|
|
2120
2106
|
const Availabilities = {
|
|
2121
2107
|
dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== "undefined",
|
|
2122
2108
|
numberFormat: intlDefined && typeof Intl.NumberFormat !== "undefined"
|
|
2123
2109
|
};
|
|
2124
|
-
|
|
2125
|
-
//#region packages/core-base/src/datetime.ts
|
|
2110
|
+
// packages/core-base/src/datetime.ts
|
|
2126
2111
|
function datetime(context, ...args) {
|
|
2127
2112
|
const { datetimeFormats, onWarn } = context;
|
|
2128
2113
|
const { __datetimeFormatters } = context;
|
|
@@ -2192,8 +2177,7 @@ function parseDateTimeArgs(...args) {
|
|
|
2192
2177
|
function clearDateTimeFormat(ctx, locale, format) {
|
|
2193
2178
|
clearFormatCache(ctx.__datetimeFormatters, locale, format);
|
|
2194
2179
|
}
|
|
2195
|
-
|
|
2196
|
-
//#region packages/core-base/src/number.ts
|
|
2180
|
+
// packages/core-base/src/number.ts
|
|
2197
2181
|
function number(context, ...args) {
|
|
2198
2182
|
const { numberFormats, onWarn } = context;
|
|
2199
2183
|
const { __numberFormatters } = context;
|
|
@@ -2249,8 +2233,7 @@ function parseNumberArgs(...args) {
|
|
|
2249
2233
|
function clearNumberFormat(ctx, locale, format) {
|
|
2250
2234
|
clearFormatCache(ctx.__numberFormatters, locale, format);
|
|
2251
2235
|
}
|
|
2252
|
-
|
|
2253
|
-
//#region packages/core-base/src/runtime.ts
|
|
2236
|
+
// packages/core-base/src/runtime.ts
|
|
2254
2237
|
const DEFAULT_MODIFIER = (str) => str;
|
|
2255
2238
|
const DEFAULT_MESSAGE = (_ctx) => "";
|
|
2256
2239
|
const DEFAULT_MESSAGE_DATA_TYPE = "text";
|
|
@@ -2367,8 +2350,7 @@ function createMessageContext(options = {}) {
|
|
|
2367
2350
|
};
|
|
2368
2351
|
return ctx;
|
|
2369
2352
|
}
|
|
2370
|
-
|
|
2371
|
-
//#region packages/core-base/src/translate.ts
|
|
2353
|
+
// packages/core-base/src/translate.ts
|
|
2372
2354
|
const NOOP_MESSAGE_FUNCTION = () => "";
|
|
2373
2355
|
const isMessageFunction = (val) => isFunction(val);
|
|
2374
2356
|
/** @internal */
|
|
@@ -2598,5 +2580,4 @@ function getMessageContextOptions(context, locale, message, options) {
|
|
|
2598
2580
|
pluralIndex: isNumber(options.plural) ? options.plural : void 0
|
|
2599
2581
|
};
|
|
2600
2582
|
}
|
|
2601
|
-
//#endregion
|
|
2602
2583
|
export { AST_NODE_PROPS_KEYS, CORE_ERROR_CODES_EXTEND_POINT, CORE_WARN_CODES_EXTEND_POINT, CoreWarnCodes, DATETIME_FORMAT_OPTIONS_KEYS, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_RESOLVED, NUMBER_FORMAT_OPTIONS_KEYS, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compile, createCompileError, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getLocale, getLocaleMessage, getWarnMessage, handleMissing, isAlmostSameLocale, isFallbackLocale, isImplicitFallback, isMessageAST, isMessageFormat, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, isWarnOption, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveLocale, resolveValue, resolveWithKeyValue, setLocaleMessage, translate, updateFallbackLocale };
|