@intlify/core-base 11.0.0-beta.0 → 11.0.0-beta.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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core-base v11.0.0-beta.0
2
+ * core-base v11.0.0-beta.2
3
3
  * (c) 2024 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -13,10 +13,14 @@ function format(ast) {
13
13
  return msg;
14
14
  }
15
15
  function formatParts(ctx, ast) {
16
- const body = ast.b || ast.body;
17
- if ((body.t || body.type) === 1 /* NodeTypes.Plural */) {
16
+ const body = resolveBody(ast);
17
+ if (body == null) {
18
+ throw createUnhandleNodeError(0 /* NodeTypes.Resource */);
19
+ }
20
+ const type = resolveType(body);
21
+ if (type === 1 /* NodeTypes.Plural */) {
18
22
  const plural = body;
19
- const cases = plural.c || plural.cases;
23
+ const cases = resolveCases(plural);
20
24
  return ctx.plural(cases.reduce((messages, c) => [
21
25
  ...messages,
22
26
  formatMessageParts(ctx, c)
@@ -26,53 +30,120 @@ function formatParts(ctx, ast) {
26
30
  return formatMessageParts(ctx, body);
27
31
  }
28
32
  }
33
+ const PROPS_BODY = ['b', 'body'];
34
+ function resolveBody(node) {
35
+ return resolveProps(node, PROPS_BODY);
36
+ }
37
+ const PROPS_CASES = ['c', 'cases'];
38
+ function resolveCases(node) {
39
+ return resolveProps(node, PROPS_CASES, []);
40
+ }
29
41
  function formatMessageParts(ctx, node) {
30
- const _static = node.s || node.static;
31
- if (_static != null) {
42
+ const static_ = resolveStatic(node);
43
+ if (static_ != null) {
32
44
  return ctx.type === 'text'
33
- ? _static
34
- : ctx.normalize([_static]);
45
+ ? static_
46
+ : ctx.normalize([static_]);
35
47
  }
36
48
  else {
37
- const messages = (node.i || node.items).reduce((acm, c) => [...acm, formatMessagePart(ctx, c)], []);
49
+ const messages = resolveItems(node).reduce((acm, c) => [...acm, formatMessagePart(ctx, c)], []);
38
50
  return ctx.normalize(messages);
39
51
  }
40
52
  }
53
+ const PROPS_STATIC = ['s', 'static'];
54
+ function resolveStatic(node) {
55
+ return resolveProps(node, PROPS_STATIC);
56
+ }
57
+ const PROPS_ITEMS = ['i', 'items'];
58
+ function resolveItems(node) {
59
+ return resolveProps(node, PROPS_ITEMS, []);
60
+ }
41
61
  function formatMessagePart(ctx, node) {
42
- const type = node.t || node.type;
62
+ const type = resolveType(node);
43
63
  switch (type) {
44
64
  case 3 /* NodeTypes.Text */: {
45
- const text = node;
46
- return (text.v || text.value);
65
+ return resolveValue$1(node, type);
47
66
  }
48
67
  case 9 /* NodeTypes.Literal */: {
49
- const literal = node;
50
- return (literal.v || literal.value);
68
+ return resolveValue$1(node, type);
51
69
  }
52
70
  case 4 /* NodeTypes.Named */: {
53
71
  const named = node;
54
- return ctx.interpolate(ctx.named(named.k || named.key));
72
+ if (shared.hasOwn(named, 'k') && named.k) {
73
+ return ctx.interpolate(ctx.named(named.k));
74
+ }
75
+ if (shared.hasOwn(named, 'key') && named.key) {
76
+ return ctx.interpolate(ctx.named(named.key));
77
+ }
78
+ throw createUnhandleNodeError(type);
55
79
  }
56
80
  case 5 /* NodeTypes.List */: {
57
81
  const list = node;
58
- return ctx.interpolate(ctx.list(list.i != null ? list.i : list.index));
82
+ if (shared.hasOwn(list, 'i') && shared.isNumber(list.i)) {
83
+ return ctx.interpolate(ctx.list(list.i));
84
+ }
85
+ if (shared.hasOwn(list, 'index') && shared.isNumber(list.index)) {
86
+ return ctx.interpolate(ctx.list(list.index));
87
+ }
88
+ throw createUnhandleNodeError(type);
59
89
  }
60
90
  case 6 /* NodeTypes.Linked */: {
61
91
  const linked = node;
62
- const modifier = linked.m || linked.modifier;
63
- return ctx.linked(formatMessagePart(ctx, linked.k || linked.key), modifier ? formatMessagePart(ctx, modifier) : undefined, ctx.type);
92
+ const modifier = resolveLinkedModifier(linked);
93
+ const key = resolveLinkedKey(linked);
94
+ return ctx.linked(formatMessagePart(ctx, key), modifier ? formatMessagePart(ctx, modifier) : undefined, ctx.type);
64
95
  }
65
96
  case 7 /* NodeTypes.LinkedKey */: {
66
- const linkedKey = node;
67
- return (linkedKey.v || linkedKey.value);
97
+ return resolveValue$1(node, type);
68
98
  }
69
99
  case 8 /* NodeTypes.LinkedModifier */: {
70
- const linkedModifier = node;
71
- return (linkedModifier.v || linkedModifier.value);
100
+ return resolveValue$1(node, type);
72
101
  }
73
102
  default:
74
- throw new Error(`unhandled node type on format message part: ${type}`);
103
+ throw new Error(`unhandled node on format message part: ${type}`);
104
+ }
105
+ }
106
+ const PROPS_TYPE = ['t', 'type'];
107
+ function resolveType(node) {
108
+ return resolveProps(node, PROPS_TYPE);
109
+ }
110
+ const PROPS_VALUE = ['v', 'value'];
111
+ function resolveValue$1(node, type) {
112
+ const resolved = resolveProps(node, PROPS_VALUE);
113
+ if (resolved) {
114
+ return resolved;
75
115
  }
116
+ else {
117
+ throw createUnhandleNodeError(type);
118
+ }
119
+ }
120
+ const PROPS_MODIFIER = ['m', 'modifier'];
121
+ function resolveLinkedModifier(node) {
122
+ return resolveProps(node, PROPS_MODIFIER);
123
+ }
124
+ const PROPS_KEY = ['k', 'key'];
125
+ function resolveLinkedKey(node) {
126
+ const resolved = resolveProps(node, PROPS_KEY);
127
+ if (resolved) {
128
+ return resolved;
129
+ }
130
+ else {
131
+ throw createUnhandleNodeError(6 /* NodeTypes.Linked */);
132
+ }
133
+ }
134
+ function resolveProps(node, props, defaultValue) {
135
+ for (let i = 0; i < props.length; i++) {
136
+ const prop = props[i];
137
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
138
+ if (shared.hasOwn(node, prop) && node[prop] != null) {
139
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
140
+ return node[prop];
141
+ }
142
+ }
143
+ return defaultValue;
144
+ }
145
+ function createUnhandleNodeError(type) {
146
+ return new Error(`unhandled node type: ${type}`);
76
147
  }
77
148
 
78
149
  const WARN_MESSAGE = `Detected HTML in '{source}' message. Recommend not using HTML messages to avoid XSS.`;
@@ -82,13 +153,15 @@ function checkHtmlMessage(source, warnHtmlMessage) {
82
153
  }
83
154
  }
84
155
  const defaultOnCacheKey = (message) => message;
85
- let compileCache = Object.create(null);
156
+ let compileCache = shared.create();
86
157
  function clearCompileCache() {
87
- compileCache = Object.create(null);
158
+ compileCache = shared.create();
159
+ }
160
+ function isMessageAST(val) {
161
+ return (shared.isObject(val) &&
162
+ resolveType(val) === 0 &&
163
+ (shared.hasOwn(val, 'b') || shared.hasOwn(val, 'body')));
88
164
  }
89
- const isMessageAST = (val) => shared.isObject(val) &&
90
- (val.t === 0 || val.type === 0) &&
91
- ('b' in val || 'body' in val);
92
165
  function baseCompile(message, options = {}) {
93
166
  // error detecting on compile
94
167
  let detectError = false;
@@ -643,7 +716,7 @@ function getWarnMessage(code, ...args) {
643
716
  * Intlify core-base version
644
717
  * @internal
645
718
  */
646
- const VERSION = '11.0.0-beta.0';
719
+ const VERSION = '11.0.0-beta.2';
647
720
  const NOT_REOSLVED = -1;
648
721
  const DEFAULT_LOCALE = 'en-US';
649
722
  const MISSING_RESOLVE_VALUE = '';
@@ -733,17 +806,17 @@ function createCoreContext(options = {}) {
733
806
  : _locale;
734
807
  const messages = shared.isPlainObject(options.messages)
735
808
  ? options.messages
736
- : { [_locale]: {} };
809
+ : createResources(_locale);
737
810
  const datetimeFormats = shared.isPlainObject(options.datetimeFormats)
738
811
  ? options.datetimeFormats
739
- : { [_locale]: {} }
812
+ : createResources(_locale)
740
813
  ;
741
814
  const numberFormats = shared.isPlainObject(options.numberFormats)
742
815
  ? options.numberFormats
743
- : { [_locale]: {} }
816
+ : createResources(_locale)
744
817
  ;
745
- const modifiers = shared.assign({}, options.modifiers || {}, getDefaultLinkedModifiers());
746
- const pluralRules = options.pluralRules || {};
818
+ const modifiers = shared.assign(shared.create(), options.modifiers, getDefaultLinkedModifiers());
819
+ const pluralRules = options.pluralRules || shared.create();
747
820
  const missing = shared.isFunction(options.missing) ? options.missing : null;
748
821
  const missingWarn = shared.isBoolean(options.missingWarn) || shared.isRegExp(options.missingWarn)
749
822
  ? options.missingWarn
@@ -831,6 +904,7 @@ function createCoreContext(options = {}) {
831
904
  }
832
905
  return context;
833
906
  }
907
+ const createResources = (locale) => ({ [locale]: shared.create() });
834
908
  /** @internal */
835
909
  function isTranslateFallbackWarn(fallback, key) {
836
910
  return fallback instanceof RegExp ? fallback.test(key) : fallback;
@@ -998,8 +1072,8 @@ const DATETIME_FORMAT_OPTIONS_KEYS = [
998
1072
  /** @internal */
999
1073
  function parseDateTimeArgs(...args) {
1000
1074
  const [arg1, arg2, arg3, arg4] = args;
1001
- const options = {};
1002
- let overrides = {};
1075
+ const options = shared.create();
1076
+ let overrides = shared.create();
1003
1077
  let value;
1004
1078
  if (shared.isString(arg1)) {
1005
1079
  // Only allow ISO strings - other date formats are often supported,
@@ -1172,8 +1246,8 @@ const NUMBER_FORMAT_OPTIONS_KEYS = [
1172
1246
  /** @internal */
1173
1247
  function parseNumberArgs(...args) {
1174
1248
  const [arg1, arg2, arg3, arg4] = args;
1175
- const options = {};
1176
- let overrides = {};
1249
+ const options = shared.create();
1250
+ let overrides = shared.create();
1177
1251
  if (!shared.isNumber(arg1)) {
1178
1252
  throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1179
1253
  }
@@ -1272,7 +1346,7 @@ function createMessageContext(options = {}) {
1272
1346
  const _list = options.list || [];
1273
1347
  const list = (index) => _list[index];
1274
1348
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1275
- const _named = options.named || {};
1349
+ const _named = options.named || shared.create();
1276
1350
  shared.isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
1277
1351
  const named = (key) => _named[key];
1278
1352
  function message(key, useLinked) {
@@ -1339,7 +1413,7 @@ function createMessageContext(options = {}) {
1339
1413
  ["type" /* HelperNameMap.TYPE */]: type,
1340
1414
  ["interpolate" /* HelperNameMap.INTERPOLATE */]: interpolate,
1341
1415
  ["normalize" /* HelperNameMap.NORMALIZE */]: normalize,
1342
- ["values" /* HelperNameMap.VALUES */]: shared.assign({}, _list, _named)
1416
+ ["values" /* HelperNameMap.VALUES */]: shared.assign(shared.create(), _list, _named)
1343
1417
  };
1344
1418
  return ctx;
1345
1419
  }
@@ -1381,7 +1455,7 @@ function translate(context, ...args) {
1381
1455
  : [
1382
1456
  key,
1383
1457
  locale,
1384
- messages[locale] || {}
1458
+ messages[locale] || shared.create()
1385
1459
  ];
1386
1460
  // NOTE:
1387
1461
  // Fix to work around `ssrTransfrom` bug in Vite.
@@ -1477,7 +1551,7 @@ function escapeParams(options) {
1477
1551
  function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
1478
1552
  const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
1479
1553
  const locales = localeFallbacker(context, fallbackLocale, locale); // eslint-disable-line @typescript-eslint/no-explicit-any
1480
- let message = {};
1554
+ let message = shared.create();
1481
1555
  let targetLocale;
1482
1556
  let format = null;
1483
1557
  let from = locale;
@@ -1507,7 +1581,7 @@ function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn
1507
1581
  }
1508
1582
  }
1509
1583
  message =
1510
- messages[targetLocale] || {};
1584
+ messages[targetLocale] || shared.create();
1511
1585
  // for vue-devtools timeline event
1512
1586
  let start = null;
1513
1587
  let startTag;
@@ -1635,7 +1709,7 @@ function evaluateMessage(context, msg, msgCtx) {
1635
1709
  /** @internal */
1636
1710
  function parseTranslateArgs(...args) {
1637
1711
  const [arg1, arg2, arg3] = args;
1638
- const options = {};
1712
+ const options = shared.create();
1639
1713
  if (!shared.isString(arg1) &&
1640
1714
  !shared.isNumber(arg1) &&
1641
1715
  !isMessageFunction(arg1) &&
@@ -441,7 +441,7 @@ export declare type IsEmptyObject<T> = T extends {
441
441
 
442
442
  /* Excluded from this release type: isImplicitFallback */
443
443
 
444
- export declare const isMessageAST: (val: unknown) => val is ResourceNode;
444
+ export declare function isMessageAST(val: unknown): val is ResourceNode;
445
445
 
446
446
  export declare const isMessageFunction: <T>(val: unknown) => val is MessageFunction<T>;
447
447
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core-base v11.0.0-beta.0
2
+ * core-base v11.0.0-beta.2
3
3
  * (c) 2024 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -51,6 +51,8 @@ const isDate = (val) => toTypeString(val) === '[object Date]';
51
51
  const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
52
52
  const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
53
53
  const assign = Object.assign;
54
+ const _create = Object.create;
55
+ const create = (obj = null) => _create(obj);
54
56
  function escapeHtml(rawText) {
55
57
  return rawText
56
58
  .replace(/</g, '&lt;')
@@ -58,6 +60,10 @@ function escapeHtml(rawText) {
58
60
  .replace(/"/g, '&quot;')
59
61
  .replace(/'/g, '&apos;');
60
62
  }
63
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
64
+ function hasOwn(obj, key) {
65
+ return hasOwnProperty.call(obj, key);
66
+ }
61
67
  /* eslint-enable */
62
68
  /**
63
69
  * Useful Utilities By Evan you
@@ -1648,10 +1654,14 @@ function format(ast) {
1648
1654
  return msg;
1649
1655
  }
1650
1656
  function formatParts(ctx, ast) {
1651
- const body = ast.b || ast.body;
1652
- if ((body.t || body.type) === 1 /* NodeTypes.Plural */) {
1657
+ const body = resolveBody(ast);
1658
+ if (body == null) {
1659
+ throw createUnhandleNodeError(0 /* NodeTypes.Resource */);
1660
+ }
1661
+ const type = resolveType(body);
1662
+ if (type === 1 /* NodeTypes.Plural */) {
1653
1663
  const plural = body;
1654
- const cases = plural.c || plural.cases;
1664
+ const cases = resolveCases(plural);
1655
1665
  return ctx.plural(cases.reduce((messages, c) => [
1656
1666
  ...messages,
1657
1667
  formatMessageParts(ctx, c)
@@ -1661,54 +1671,121 @@ function formatParts(ctx, ast) {
1661
1671
  return formatMessageParts(ctx, body);
1662
1672
  }
1663
1673
  }
1674
+ const PROPS_BODY = ['b', 'body'];
1675
+ function resolveBody(node) {
1676
+ return resolveProps(node, PROPS_BODY);
1677
+ }
1678
+ const PROPS_CASES = ['c', 'cases'];
1679
+ function resolveCases(node) {
1680
+ return resolveProps(node, PROPS_CASES, []);
1681
+ }
1664
1682
  function formatMessageParts(ctx, node) {
1665
- const _static = node.s || node.static;
1666
- if (_static != null) {
1683
+ const static_ = resolveStatic(node);
1684
+ if (static_ != null) {
1667
1685
  return ctx.type === 'text'
1668
- ? _static
1669
- : ctx.normalize([_static]);
1686
+ ? static_
1687
+ : ctx.normalize([static_]);
1670
1688
  }
1671
1689
  else {
1672
- const messages = (node.i || node.items).reduce((acm, c) => [...acm, formatMessagePart(ctx, c)], []);
1690
+ const messages = resolveItems(node).reduce((acm, c) => [...acm, formatMessagePart(ctx, c)], []);
1673
1691
  return ctx.normalize(messages);
1674
1692
  }
1675
1693
  }
1694
+ const PROPS_STATIC = ['s', 'static'];
1695
+ function resolveStatic(node) {
1696
+ return resolveProps(node, PROPS_STATIC);
1697
+ }
1698
+ const PROPS_ITEMS = ['i', 'items'];
1699
+ function resolveItems(node) {
1700
+ return resolveProps(node, PROPS_ITEMS, []);
1701
+ }
1676
1702
  function formatMessagePart(ctx, node) {
1677
- const type = node.t || node.type;
1703
+ const type = resolveType(node);
1678
1704
  switch (type) {
1679
1705
  case 3 /* NodeTypes.Text */: {
1680
- const text = node;
1681
- return (text.v || text.value);
1706
+ return resolveValue$1(node, type);
1682
1707
  }
1683
1708
  case 9 /* NodeTypes.Literal */: {
1684
- const literal = node;
1685
- return (literal.v || literal.value);
1709
+ return resolveValue$1(node, type);
1686
1710
  }
1687
1711
  case 4 /* NodeTypes.Named */: {
1688
1712
  const named = node;
1689
- return ctx.interpolate(ctx.named(named.k || named.key));
1713
+ if (hasOwn(named, 'k') && named.k) {
1714
+ return ctx.interpolate(ctx.named(named.k));
1715
+ }
1716
+ if (hasOwn(named, 'key') && named.key) {
1717
+ return ctx.interpolate(ctx.named(named.key));
1718
+ }
1719
+ throw createUnhandleNodeError(type);
1690
1720
  }
1691
1721
  case 5 /* NodeTypes.List */: {
1692
1722
  const list = node;
1693
- return ctx.interpolate(ctx.list(list.i != null ? list.i : list.index));
1723
+ if (hasOwn(list, 'i') && isNumber(list.i)) {
1724
+ return ctx.interpolate(ctx.list(list.i));
1725
+ }
1726
+ if (hasOwn(list, 'index') && isNumber(list.index)) {
1727
+ return ctx.interpolate(ctx.list(list.index));
1728
+ }
1729
+ throw createUnhandleNodeError(type);
1694
1730
  }
1695
1731
  case 6 /* NodeTypes.Linked */: {
1696
1732
  const linked = node;
1697
- const modifier = linked.m || linked.modifier;
1698
- return ctx.linked(formatMessagePart(ctx, linked.k || linked.key), modifier ? formatMessagePart(ctx, modifier) : undefined, ctx.type);
1733
+ const modifier = resolveLinkedModifier(linked);
1734
+ const key = resolveLinkedKey(linked);
1735
+ return ctx.linked(formatMessagePart(ctx, key), modifier ? formatMessagePart(ctx, modifier) : undefined, ctx.type);
1699
1736
  }
1700
1737
  case 7 /* NodeTypes.LinkedKey */: {
1701
- const linkedKey = node;
1702
- return (linkedKey.v || linkedKey.value);
1738
+ return resolveValue$1(node, type);
1703
1739
  }
1704
1740
  case 8 /* NodeTypes.LinkedModifier */: {
1705
- const linkedModifier = node;
1706
- return (linkedModifier.v || linkedModifier.value);
1741
+ return resolveValue$1(node, type);
1707
1742
  }
1708
1743
  default:
1709
- throw new Error(`unhandled node type on format message part: ${type}`);
1744
+ throw new Error(`unhandled node on format message part: ${type}`);
1710
1745
  }
1711
1746
  }
1747
+ const PROPS_TYPE = ['t', 'type'];
1748
+ function resolveType(node) {
1749
+ return resolveProps(node, PROPS_TYPE);
1750
+ }
1751
+ const PROPS_VALUE = ['v', 'value'];
1752
+ function resolveValue$1(node, type) {
1753
+ const resolved = resolveProps(node, PROPS_VALUE);
1754
+ if (resolved) {
1755
+ return resolved;
1756
+ }
1757
+ else {
1758
+ throw createUnhandleNodeError(type);
1759
+ }
1760
+ }
1761
+ const PROPS_MODIFIER = ['m', 'modifier'];
1762
+ function resolveLinkedModifier(node) {
1763
+ return resolveProps(node, PROPS_MODIFIER);
1764
+ }
1765
+ const PROPS_KEY = ['k', 'key'];
1766
+ function resolveLinkedKey(node) {
1767
+ const resolved = resolveProps(node, PROPS_KEY);
1768
+ if (resolved) {
1769
+ return resolved;
1770
+ }
1771
+ else {
1772
+ throw createUnhandleNodeError(6 /* NodeTypes.Linked */);
1773
+ }
1774
+ }
1775
+ function resolveProps(node, props, defaultValue) {
1776
+ for (let i = 0; i < props.length; i++) {
1777
+ const prop = props[i];
1778
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1779
+ if (hasOwn(node, prop) && node[prop] != null) {
1780
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1781
+ return node[prop];
1782
+ }
1783
+ }
1784
+ return defaultValue;
1785
+ }
1786
+ function createUnhandleNodeError(type) {
1787
+ return new Error(`unhandled node type: ${type}`);
1788
+ }
1712
1789
 
1713
1790
  const WARN_MESSAGE = `Detected HTML in '{source}' message. Recommend not using HTML messages to avoid XSS.`;
1714
1791
  function checkHtmlMessage(source, warnHtmlMessage) {
@@ -1717,13 +1794,15 @@ function checkHtmlMessage(source, warnHtmlMessage) {
1717
1794
  }
1718
1795
  }
1719
1796
  const defaultOnCacheKey = (message) => message;
1720
- let compileCache = Object.create(null);
1797
+ let compileCache = create();
1721
1798
  function clearCompileCache() {
1722
- compileCache = Object.create(null);
1799
+ compileCache = create();
1800
+ }
1801
+ function isMessageAST(val) {
1802
+ return (isObject(val) &&
1803
+ resolveType(val) === 0 &&
1804
+ (hasOwn(val, 'b') || hasOwn(val, 'body')));
1723
1805
  }
1724
- const isMessageAST = (val) => isObject(val) &&
1725
- (val.t === 0 || val.type === 0) &&
1726
- ('b' in val || 'body' in val);
1727
1806
  function baseCompile(message, options = {}) {
1728
1807
  // error detecting on compile
1729
1808
  let detectError = false;
@@ -2278,7 +2357,7 @@ function getWarnMessage(code, ...args) {
2278
2357
  * Intlify core-base version
2279
2358
  * @internal
2280
2359
  */
2281
- const VERSION = '11.0.0-beta.0';
2360
+ const VERSION = '11.0.0-beta.2';
2282
2361
  const NOT_REOSLVED = -1;
2283
2362
  const DEFAULT_LOCALE = 'en-US';
2284
2363
  const MISSING_RESOLVE_VALUE = '';
@@ -2368,17 +2447,17 @@ function createCoreContext(options = {}) {
2368
2447
  : _locale;
2369
2448
  const messages = isPlainObject(options.messages)
2370
2449
  ? options.messages
2371
- : { [_locale]: {} };
2450
+ : createResources(_locale);
2372
2451
  const datetimeFormats = isPlainObject(options.datetimeFormats)
2373
2452
  ? options.datetimeFormats
2374
- : { [_locale]: {} }
2453
+ : createResources(_locale)
2375
2454
  ;
2376
2455
  const numberFormats = isPlainObject(options.numberFormats)
2377
2456
  ? options.numberFormats
2378
- : { [_locale]: {} }
2457
+ : createResources(_locale)
2379
2458
  ;
2380
- const modifiers = assign({}, options.modifiers || {}, getDefaultLinkedModifiers());
2381
- const pluralRules = options.pluralRules || {};
2459
+ const modifiers = assign(create(), options.modifiers, getDefaultLinkedModifiers());
2460
+ const pluralRules = options.pluralRules || create();
2382
2461
  const missing = isFunction(options.missing) ? options.missing : null;
2383
2462
  const missingWarn = isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
2384
2463
  ? options.missingWarn
@@ -2466,6 +2545,7 @@ function createCoreContext(options = {}) {
2466
2545
  }
2467
2546
  return context;
2468
2547
  }
2548
+ const createResources = (locale) => ({ [locale]: create() });
2469
2549
  /** @internal */
2470
2550
  function isTranslateFallbackWarn(fallback, key) {
2471
2551
  return fallback instanceof RegExp ? fallback.test(key) : fallback;
@@ -2633,8 +2713,8 @@ const DATETIME_FORMAT_OPTIONS_KEYS = [
2633
2713
  /** @internal */
2634
2714
  function parseDateTimeArgs(...args) {
2635
2715
  const [arg1, arg2, arg3, arg4] = args;
2636
- const options = {};
2637
- let overrides = {};
2716
+ const options = create();
2717
+ let overrides = create();
2638
2718
  let value;
2639
2719
  if (isString(arg1)) {
2640
2720
  // Only allow ISO strings - other date formats are often supported,
@@ -2807,8 +2887,8 @@ const NUMBER_FORMAT_OPTIONS_KEYS = [
2807
2887
  /** @internal */
2808
2888
  function parseNumberArgs(...args) {
2809
2889
  const [arg1, arg2, arg3, arg4] = args;
2810
- const options = {};
2811
- let overrides = {};
2890
+ const options = create();
2891
+ let overrides = create();
2812
2892
  if (!isNumber(arg1)) {
2813
2893
  throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
2814
2894
  }
@@ -2907,7 +2987,7 @@ function createMessageContext(options = {}) {
2907
2987
  const _list = options.list || [];
2908
2988
  const list = (index) => _list[index];
2909
2989
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2910
- const _named = options.named || {};
2990
+ const _named = options.named || create();
2911
2991
  isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
2912
2992
  const named = (key) => _named[key];
2913
2993
  function message(key, useLinked) {
@@ -2974,7 +3054,7 @@ function createMessageContext(options = {}) {
2974
3054
  ["type" /* HelperNameMap.TYPE */]: type,
2975
3055
  ["interpolate" /* HelperNameMap.INTERPOLATE */]: interpolate,
2976
3056
  ["normalize" /* HelperNameMap.NORMALIZE */]: normalize,
2977
- ["values" /* HelperNameMap.VALUES */]: assign({}, _list, _named)
3057
+ ["values" /* HelperNameMap.VALUES */]: assign(create(), _list, _named)
2978
3058
  };
2979
3059
  return ctx;
2980
3060
  }
@@ -3016,7 +3096,7 @@ function translate(context, ...args) {
3016
3096
  : [
3017
3097
  key,
3018
3098
  locale,
3019
- messages[locale] || {}
3099
+ messages[locale] || create()
3020
3100
  ];
3021
3101
  // NOTE:
3022
3102
  // Fix to work around `ssrTransfrom` bug in Vite.
@@ -3112,7 +3192,7 @@ function escapeParams(options) {
3112
3192
  function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
3113
3193
  const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
3114
3194
  const locales = localeFallbacker(context, fallbackLocale, locale); // eslint-disable-line @typescript-eslint/no-explicit-any
3115
- let message = {};
3195
+ let message = create();
3116
3196
  let targetLocale;
3117
3197
  let format = null;
3118
3198
  let from = locale;
@@ -3142,7 +3222,7 @@ function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn
3142
3222
  }
3143
3223
  }
3144
3224
  message =
3145
- messages[targetLocale] || {};
3225
+ messages[targetLocale] || create();
3146
3226
  // for vue-devtools timeline event
3147
3227
  let start = null;
3148
3228
  let startTag;
@@ -3270,7 +3350,7 @@ function evaluateMessage(context, msg, msgCtx) {
3270
3350
  /** @internal */
3271
3351
  function parseTranslateArgs(...args) {
3272
3352
  const [arg1, arg2, arg3] = args;
3273
- const options = {};
3353
+ const options = create();
3274
3354
  if (!isString(arg1) &&
3275
3355
  !isNumber(arg1) &&
3276
3356
  !isMessageFunction(arg1) &&