@intlify/core 12.0.0-alpha.7 → 12.0.0-alpha.9

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.
@@ -1,11 +1,11 @@
1
1
  /**
2
- * @intlify/core v12.0.0-alpha.7
2
+ * @intlify/core v12.0.0-alpha.9
3
3
  * (c) 2016-present kazuya kawaguchi and contributors
4
4
  * @license MIT
5
5
  **/
6
6
  var IntlifyCore = (function(exports) {
7
7
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
- //#region packages/shared/src/utils.ts
8
+ // packages/shared/src/utils.ts
9
9
  /**
10
10
  * Original Utilities
11
11
  * written by kazuya kawaguchi
@@ -125,8 +125,7 @@ var IntlifyCore = (function(exports) {
125
125
  }
126
126
  return res.join("\n");
127
127
  }
128
- //#endregion
129
- //#region packages/shared/src/warn.ts
128
+ // packages/shared/src/warn.ts
130
129
  function warn(msg, err) {
131
130
  if (typeof console !== "undefined") {
132
131
  console.warn(`[intlify] ` + msg);
@@ -141,8 +140,7 @@ var IntlifyCore = (function(exports) {
141
140
  warn(msg);
142
141
  }
143
142
  }
144
- //#endregion
145
- //#region packages/shared/src/sanitize.ts
143
+ // packages/shared/src/sanitize.ts
146
144
  function escapeHtml(rawText) {
147
145
  return rawText.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/\//g, "&#x2F;").replace(/=/g, "&#x3D;");
148
146
  }
@@ -150,7 +148,7 @@ var IntlifyCore = (function(exports) {
150
148
  return value.replace(/&(?![a-z0-9#]{2,6};)/gi, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
151
149
  }
152
150
  const javascriptSchemePattern = /^javascript:/i;
153
- const urlAttributePattern = /^(?:href|src|action|formaction)$/i;
151
+ const urlAttributePattern = /^(?:href|xlink:href|src|action|formaction)$/i;
154
152
  const numericCharacterReferencePattern = /&#(?:x([0-9a-f]+)|(\d+));?/gi;
155
153
  const namedWhitespaceCharacterReferencePattern = /&(?:Tab|NewLine);/g;
156
154
  const colonCharacterReferencePattern = /&colon;?/gi;
@@ -159,7 +157,9 @@ var IntlifyCore = (function(exports) {
159
157
  const eventHandlerAttributePattern = /(^|[\s"'<>/])on(\w+\s*=)/gi;
160
158
  const srcdocPattern = /(?:^|[\s"'<>/])srcdoc\s*=/i;
161
159
  const srcdocAttributePattern = /(^|[\s"'<>/])s(rcdoc\s*=)/gi;
162
- const unquotedUrlAttributePattern = /(^|[\s"'<>/])((?:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi;
160
+ const dangerousElementPattern = /<(?:base|animate|set|script)(?=[\s/>]|$)/i;
161
+ const dangerousElementStartTagPattern = /<(base|animate|set|script)(?=[\s/>]|$)/gi;
162
+ const unquotedUrlAttributePattern = /(^|[\s"'<>/])((?:href|xlink:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi;
163
163
  function decodeNumericCharacterReference(match, hex, decimal) {
164
164
  const digits = hex || decimal;
165
165
  if (!digits) return match;
@@ -218,11 +218,14 @@ var IntlifyCore = (function(exports) {
218
218
  warn("Potentially dangerous srcdoc attribute detected in translation. Consider removing srcdoc from your translation messages.");
219
219
  html = html.replace(srcdocAttributePattern, "$1&#115;$2");
220
220
  }
221
+ if (dangerousElementPattern.test(html)) {
222
+ warn("Potentially dangerous element (<base>, <animate>, <set> or <script>) detected in translation. Consider removing it from your translation messages.");
223
+ html = html.replace(dangerousElementStartTagPattern, "&lt;$1");
224
+ }
221
225
  html = html.replace(unquotedUrlAttributePattern, (match, boundary, prefix, attrValue) => hasJavascriptScheme(attrValue) ? `${boundary}${prefix}about:blank` : match);
222
226
  return html;
223
227
  }
224
- //#endregion
225
- //#region packages/shared/src/messages.ts
228
+ // packages/shared/src/messages.ts
226
229
  const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
227
230
  function deepCopy(src, des) {
228
231
  if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des) || des === Object.prototype) throw new Error("Invalid value");
@@ -252,8 +255,7 @@ var IntlifyCore = (function(exports) {
252
255
  }
253
256
  }
254
257
  }
255
- //#endregion
256
- //#region packages/message-compiler/src/location.ts
258
+ // packages/message-compiler/src/location.ts
257
259
  function createPosition(line, column, offset) {
258
260
  return {
259
261
  line,
@@ -269,12 +271,10 @@ var IntlifyCore = (function(exports) {
269
271
  if (source != null) loc.source = source;
270
272
  return loc;
271
273
  }
272
- //#endregion
273
- //#region packages/message-compiler/src/helpers.ts
274
+ // packages/message-compiler/src/helpers.ts
274
275
  const RE_HTML_TAG = /<[\w\s=":;#-/]+>/;
275
276
  const detectHtmlTag = (source) => RE_HTML_TAG.test(source);
276
- //#endregion
277
- //#region packages/message-compiler/src/errors.ts
277
+ // packages/message-compiler/src/errors.ts
278
278
  const CompileErrorCodes = {
279
279
  EXPECTED_TOKEN: 1,
280
280
  INVALID_TOKEN_IN_PLACEHOLDER: 2,
@@ -325,8 +325,7 @@ var IntlifyCore = (function(exports) {
325
325
  function defaultOnError(error) {
326
326
  throw error;
327
327
  }
328
- //#endregion
329
- //#region packages/message-compiler/src/mangler.ts
328
+ // packages/message-compiler/src/mangler.ts
330
329
  const ERROR_DOMAIN$2 = "minifier";
331
330
  function mangle(node) {
332
331
  node.t = node.type;
@@ -400,8 +399,7 @@ var IntlifyCore = (function(exports) {
400
399
  }
401
400
  delete node.type;
402
401
  }
403
- //#endregion
404
- //#region packages/message-compiler/src/optimizer.ts
402
+ // packages/message-compiler/src/optimizer.ts
405
403
  function optimize(ast) {
406
404
  const body = ast.body;
407
405
  if (body.type === 2) optimizeMessageNode(body);
@@ -495,8 +493,7 @@ var IntlifyCore = (function(exports) {
495
493
  skipToPeek
496
494
  };
497
495
  }
498
- //#endregion
499
- //#region packages/message-compiler/src/tokenizer.ts
496
+ // packages/message-compiler/src/tokenizer.ts
500
497
  const EOF = void 0;
501
498
  const DOT = ".";
502
499
  const LITERAL_DELIMITER = "'";
@@ -1001,8 +998,7 @@ var IntlifyCore = (function(exports) {
1001
998
  context
1002
999
  };
1003
1000
  }
1004
- //#endregion
1005
- //#region packages/message-compiler/src/parser.ts
1001
+ // packages/message-compiler/src/parser.ts
1006
1002
  const ERROR_DOMAIN = "parser";
1007
1003
  const KNOWN_ESCAPES = /\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6})/g;
1008
1004
  const TEXT_ESCAPES = /\\([\\@{}|])/g;
@@ -1233,8 +1229,7 @@ var IntlifyCore = (function(exports) {
1233
1229
  const name = (token.value || "").replace(/\r?\n/gu, "\\n");
1234
1230
  return name.length > 10 ? name.slice(0, 9) + "…" : name;
1235
1231
  }
1236
- //#endregion
1237
- //#region packages/core-base/src/ast.ts
1232
+ // packages/core-base/src/ast.ts
1238
1233
  function isMessageAST(val) {
1239
1234
  return isObject(val) && resolveType(val) === 0 && (hasOwn(val, "b") || hasOwn(val, "body"));
1240
1235
  }
@@ -1294,8 +1289,7 @@ var IntlifyCore = (function(exports) {
1294
1289
  function createUnhandleNodeError(type) {
1295
1290
  return /* @__PURE__ */ new Error(`unhandled node type: ${type}`);
1296
1291
  }
1297
- //#endregion
1298
- //#region packages/core-base/src/format.ts
1292
+ // packages/core-base/src/format.ts
1299
1293
  function format(ast) {
1300
1294
  return (ctx) => formatParts(ctx, ast);
1301
1295
  }
@@ -1343,8 +1337,7 @@ var IntlifyCore = (function(exports) {
1343
1337
  default: throw new Error(`unhandled node on format message part: ${type}`);
1344
1338
  }
1345
1339
  }
1346
- //#endregion
1347
- //#region packages/core-base/src/compilation.ts
1340
+ // packages/core-base/src/compilation.ts
1348
1341
  const WARN_MESSAGE = `Detected HTML in '{source}' message. Recommend not using HTML messages to avoid XSS.`;
1349
1342
  function checkHtmlMessage(source, warnHtmlMessage) {
1350
1343
  if (warnHtmlMessage && detectHtmlTag(source)) warn(format$1(WARN_MESSAGE, { source }));
@@ -1398,8 +1391,7 @@ var IntlifyCore = (function(exports) {
1398
1391
  } else return format(message);
1399
1392
  }
1400
1393
  }
1401
- //#endregion
1402
- //#region packages/core-base/src/errors.ts
1394
+ // packages/core-base/src/errors.ts
1403
1395
  const CoreErrorCodes = {
1404
1396
  INVALID_ARGUMENT: 17,
1405
1397
  INVALID_DATE_ARGUMENT: 18,
@@ -1421,8 +1413,7 @@ var IntlifyCore = (function(exports) {
1421
1413
  [CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION]: "cannot support async function",
1422
1414
  [CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE]: "cannot support locale type"
1423
1415
  };
1424
- //#endregion
1425
- //#region packages/core-base/src/fallbacker.ts
1416
+ // packages/core-base/src/fallbacker.ts
1426
1417
  /** @internal */
1427
1418
  function getLocale(context, options) {
1428
1419
  return options.locale != null ? resolveLocale(options.locale) : resolveLocale(context.locale);
@@ -1538,8 +1529,7 @@ var IntlifyCore = (function(exports) {
1538
1529
  }
1539
1530
  return follow;
1540
1531
  }
1541
- //#endregion
1542
- //#region packages/core-base/src/resolver.ts
1532
+ // packages/core-base/src/resolver.ts
1543
1533
  const pathStateMachine = [];
1544
1534
  pathStateMachine[0] = {
1545
1535
  ["w"]: [0],
@@ -1762,8 +1752,7 @@ var IntlifyCore = (function(exports) {
1762
1752
  }
1763
1753
  return last;
1764
1754
  }
1765
- //#endregion
1766
- //#region packages/core-base/src/warnings.ts
1755
+ // packages/core-base/src/warnings.ts
1767
1756
  const CoreWarnCodes = {
1768
1757
  NOT_FOUND_KEY: 1,
1769
1758
  FALLBACK_TO_TRANSLATE: 2,
@@ -1797,13 +1786,12 @@ var IntlifyCore = (function(exports) {
1797
1786
  function getWarnMessage(code, ...args) {
1798
1787
  return format$1(warnMessages[code], ...args);
1799
1788
  }
1800
- //#endregion
1801
- //#region packages/core-base/src/context.ts
1789
+ // packages/core-base/src/context.ts
1802
1790
  /**
1803
1791
  * Intlify core-base version
1804
1792
  * @internal
1805
1793
  */
1806
- const VERSION = "12.0.0-alpha.7";
1794
+ const VERSION = "12.0.0-alpha.9";
1807
1795
  const NOT_RESOLVED = -1;
1808
1796
  const DEFAULT_LOCALE = "en-US";
1809
1797
  const MISSING_RESOLVE_VALUE = "";
@@ -2007,8 +1995,7 @@ var IntlifyCore = (function(exports) {
2007
1995
  for (let i = index + 1; i < locales.length; i++) if (isAlmostSameLocale(targetLocale, locales[i])) return true;
2008
1996
  return false;
2009
1997
  }
2010
- //#endregion
2011
- //#region packages/core-base/src/formatter.ts
1998
+ // packages/core-base/src/formatter.ts
2012
1999
  function resolveFormatLocale(context, key, locale, formats, missingWarn, fallbackWarn, type) {
2013
2000
  const { fallbackLocale, localeFallbacker, onWarn } = context;
2014
2001
  const locales = localeFallbacker(context, fallbackLocale, locale);
@@ -2116,15 +2103,13 @@ var IntlifyCore = (function(exports) {
2116
2103
  if (isPlainObject(arg4)) overrides = arg4;
2117
2104
  return overrides;
2118
2105
  }
2119
- //#endregion
2120
- //#region packages/core-base/src/intl.ts
2106
+ // packages/core-base/src/intl.ts
2121
2107
  const intlDefined = typeof Intl !== "undefined";
2122
2108
  const Availabilities = {
2123
2109
  dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== "undefined",
2124
2110
  numberFormat: intlDefined && typeof Intl.NumberFormat !== "undefined"
2125
2111
  };
2126
- //#endregion
2127
- //#region packages/core-base/src/datetime.ts
2112
+ // packages/core-base/src/datetime.ts
2128
2113
  function datetime(context, ...args) {
2129
2114
  const { datetimeFormats, onWarn } = context;
2130
2115
  const { __datetimeFormatters } = context;
@@ -2194,8 +2179,7 @@ var IntlifyCore = (function(exports) {
2194
2179
  function clearDateTimeFormat(ctx, locale, format) {
2195
2180
  clearFormatCache(ctx.__datetimeFormatters, locale, format);
2196
2181
  }
2197
- //#endregion
2198
- //#region packages/core-base/src/number.ts
2182
+ // packages/core-base/src/number.ts
2199
2183
  function number(context, ...args) {
2200
2184
  const { numberFormats, onWarn } = context;
2201
2185
  const { __numberFormatters } = context;
@@ -2251,8 +2235,7 @@ var IntlifyCore = (function(exports) {
2251
2235
  function clearNumberFormat(ctx, locale, format) {
2252
2236
  clearFormatCache(ctx.__numberFormatters, locale, format);
2253
2237
  }
2254
- //#endregion
2255
- //#region packages/core-base/src/runtime.ts
2238
+ // packages/core-base/src/runtime.ts
2256
2239
  const DEFAULT_MODIFIER = (str) => str;
2257
2240
  const DEFAULT_MESSAGE = (_ctx) => "";
2258
2241
  const DEFAULT_MESSAGE_DATA_TYPE = "text";
@@ -2369,8 +2352,7 @@ var IntlifyCore = (function(exports) {
2369
2352
  };
2370
2353
  return ctx;
2371
2354
  }
2372
- //#endregion
2373
- //#region packages/core-base/src/translate.ts
2355
+ // packages/core-base/src/translate.ts
2374
2356
  const NOOP_MESSAGE_FUNCTION = () => "";
2375
2357
  const isMessageFunction = (val) => isFunction(val);
2376
2358
  /** @internal */
@@ -2600,7 +2582,6 @@ var IntlifyCore = (function(exports) {
2600
2582
  pluralIndex: isNumber(options.plural) ? options.plural : void 0
2601
2583
  };
2602
2584
  }
2603
- //#endregion
2604
2585
  exports.AST_NODE_PROPS_KEYS = AST_NODE_PROPS_KEYS;
2605
2586
  exports.CORE_ERROR_CODES_EXTEND_POINT = CORE_ERROR_CODES_EXTEND_POINT;
2606
2587
  exports.CORE_WARN_CODES_EXTEND_POINT = CORE_WARN_CODES_EXTEND_POINT;