@intlify/core-base 9.14.1 → 9.14.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 v9.14.1
2
+ * core-base v9.14.2
3
3
  * (c) 2024 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -241,7 +241,7 @@ function resolveWithKeyValue(obj, path) {
241
241
  *
242
242
  * @VueI18nGeneral
243
243
  */
244
- function resolveValue(obj, path) {
244
+ function resolveValue$1(obj, path) {
245
245
  // check object
246
246
  if (!shared.isObject(obj)) {
247
247
  return null;
@@ -334,7 +334,7 @@ function createMessageContext(options = {}) {
334
334
  const _list = options.list || [];
335
335
  const list = (index) => _list[index];
336
336
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
337
- const _named = options.named || {};
337
+ const _named = options.named || shared.create();
338
338
  shared.isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
339
339
  const named = (key) => _named[key];
340
340
  function message(key) {
@@ -401,7 +401,7 @@ function createMessageContext(options = {}) {
401
401
  ["type" /* HelperNameMap.TYPE */]: type,
402
402
  ["interpolate" /* HelperNameMap.INTERPOLATE */]: interpolate,
403
403
  ["normalize" /* HelperNameMap.NORMALIZE */]: normalize,
404
- ["values" /* HelperNameMap.VALUES */]: shared.assign({}, _list, _named)
404
+ ["values" /* HelperNameMap.VALUES */]: shared.assign(shared.create(), _list, _named)
405
405
  };
406
406
  return ctx;
407
407
  }
@@ -635,7 +635,7 @@ function appendItemToChain(chain, target, blocks) {
635
635
  * Intlify core-base version
636
636
  * @internal
637
637
  */
638
- const VERSION = '9.14.1';
638
+ const VERSION = '9.14.2';
639
639
  const NOT_REOSLVED = -1;
640
640
  const DEFAULT_LOCALE = 'en-US';
641
641
  const MISSING_RESOLVE_VALUE = '';
@@ -725,17 +725,17 @@ function createCoreContext(options = {}) {
725
725
  : _locale;
726
726
  const messages = shared.isPlainObject(options.messages)
727
727
  ? options.messages
728
- : { [_locale]: {} };
728
+ : createResources(_locale);
729
729
  const datetimeFormats = shared.isPlainObject(options.datetimeFormats)
730
730
  ? options.datetimeFormats
731
- : { [_locale]: {} }
731
+ : createResources(_locale)
732
732
  ;
733
733
  const numberFormats = shared.isPlainObject(options.numberFormats)
734
734
  ? options.numberFormats
735
- : { [_locale]: {} }
735
+ : createResources(_locale)
736
736
  ;
737
- const modifiers = shared.assign({}, options.modifiers || {}, getDefaultLinkedModifiers());
738
- const pluralRules = options.pluralRules || {};
737
+ const modifiers = shared.assign(shared.create(), options.modifiers, getDefaultLinkedModifiers());
738
+ const pluralRules = options.pluralRules || shared.create();
739
739
  const missing = shared.isFunction(options.missing) ? options.missing : null;
740
740
  const missingWarn = shared.isBoolean(options.missingWarn) || shared.isRegExp(options.missingWarn)
741
741
  ? options.missingWarn
@@ -823,6 +823,7 @@ function createCoreContext(options = {}) {
823
823
  }
824
824
  return context;
825
825
  }
826
+ const createResources = (locale) => ({ [locale]: shared.create() });
826
827
  /** @internal */
827
828
  function isTranslateFallbackWarn(fallback, key) {
828
829
  return fallback instanceof RegExp ? fallback.test(key) : fallback;
@@ -889,10 +890,14 @@ function format(ast) {
889
890
  return msg;
890
891
  }
891
892
  function formatParts(ctx, ast) {
892
- const body = ast.b || ast.body;
893
- if ((body.t || body.type) === 1 /* NodeTypes.Plural */) {
893
+ const body = resolveBody(ast);
894
+ if (body == null) {
895
+ throw createUnhandleNodeError(0 /* NodeTypes.Resource */);
896
+ }
897
+ const type = resolveType(body);
898
+ if (type === 1 /* NodeTypes.Plural */) {
894
899
  const plural = body;
895
- const cases = plural.c || plural.cases;
900
+ const cases = resolveCases(plural);
896
901
  return ctx.plural(cases.reduce((messages, c) => [
897
902
  ...messages,
898
903
  formatMessageParts(ctx, c)
@@ -902,53 +907,120 @@ function formatParts(ctx, ast) {
902
907
  return formatMessageParts(ctx, body);
903
908
  }
904
909
  }
910
+ const PROPS_BODY = ['b', 'body'];
911
+ function resolveBody(node) {
912
+ return resolveProps(node, PROPS_BODY);
913
+ }
914
+ const PROPS_CASES = ['c', 'cases'];
915
+ function resolveCases(node) {
916
+ return resolveProps(node, PROPS_CASES, []);
917
+ }
905
918
  function formatMessageParts(ctx, node) {
906
- const _static = node.s || node.static;
907
- if (_static) {
919
+ const static_ = resolveStatic(node);
920
+ if (static_ != null) {
908
921
  return ctx.type === 'text'
909
- ? _static
910
- : ctx.normalize([_static]);
922
+ ? static_
923
+ : ctx.normalize([static_]);
911
924
  }
912
925
  else {
913
- const messages = (node.i || node.items).reduce((acm, c) => [...acm, formatMessagePart(ctx, c)], []);
926
+ const messages = resolveItems(node).reduce((acm, c) => [...acm, formatMessagePart(ctx, c)], []);
914
927
  return ctx.normalize(messages);
915
928
  }
916
929
  }
930
+ const PROPS_STATIC = ['s', 'static'];
931
+ function resolveStatic(node) {
932
+ return resolveProps(node, PROPS_STATIC);
933
+ }
934
+ const PROPS_ITEMS = ['i', 'items'];
935
+ function resolveItems(node) {
936
+ return resolveProps(node, PROPS_ITEMS, []);
937
+ }
917
938
  function formatMessagePart(ctx, node) {
918
- const type = node.t || node.type;
939
+ const type = resolveType(node);
919
940
  switch (type) {
920
941
  case 3 /* NodeTypes.Text */: {
921
- const text = node;
922
- return (text.v || text.value);
942
+ return resolveValue(node, type);
923
943
  }
924
944
  case 9 /* NodeTypes.Literal */: {
925
- const literal = node;
926
- return (literal.v || literal.value);
945
+ return resolveValue(node, type);
927
946
  }
928
947
  case 4 /* NodeTypes.Named */: {
929
948
  const named = node;
930
- return ctx.interpolate(ctx.named(named.k || named.key));
949
+ if (shared.hasOwn(named, 'k') && named.k) {
950
+ return ctx.interpolate(ctx.named(named.k));
951
+ }
952
+ if (shared.hasOwn(named, 'key') && named.key) {
953
+ return ctx.interpolate(ctx.named(named.key));
954
+ }
955
+ throw createUnhandleNodeError(type);
931
956
  }
932
957
  case 5 /* NodeTypes.List */: {
933
958
  const list = node;
934
- return ctx.interpolate(ctx.list(list.i != null ? list.i : list.index));
959
+ if (shared.hasOwn(list, 'i') && shared.isNumber(list.i)) {
960
+ return ctx.interpolate(ctx.list(list.i));
961
+ }
962
+ if (shared.hasOwn(list, 'index') && shared.isNumber(list.index)) {
963
+ return ctx.interpolate(ctx.list(list.index));
964
+ }
965
+ throw createUnhandleNodeError(type);
935
966
  }
936
967
  case 6 /* NodeTypes.Linked */: {
937
968
  const linked = node;
938
- const modifier = linked.m || linked.modifier;
939
- return ctx.linked(formatMessagePart(ctx, linked.k || linked.key), modifier ? formatMessagePart(ctx, modifier) : undefined, ctx.type);
969
+ const modifier = resolveLinkedModifier(linked);
970
+ const key = resolveLinkedKey(linked);
971
+ return ctx.linked(formatMessagePart(ctx, key), modifier ? formatMessagePart(ctx, modifier) : undefined, ctx.type);
940
972
  }
941
973
  case 7 /* NodeTypes.LinkedKey */: {
942
- const linkedKey = node;
943
- return (linkedKey.v || linkedKey.value);
974
+ return resolveValue(node, type);
944
975
  }
945
976
  case 8 /* NodeTypes.LinkedModifier */: {
946
- const linkedModifier = node;
947
- return (linkedModifier.v || linkedModifier.value);
977
+ return resolveValue(node, type);
948
978
  }
949
979
  default:
950
- throw new Error(`unhandled node type on format message part: ${type}`);
980
+ throw new Error(`unhandled node on format message part: ${type}`);
981
+ }
982
+ }
983
+ const PROPS_TYPE = ['t', 'type'];
984
+ function resolveType(node) {
985
+ return resolveProps(node, PROPS_TYPE);
986
+ }
987
+ const PROPS_VALUE = ['v', 'value'];
988
+ function resolveValue(node, type) {
989
+ const resolved = resolveProps(node, PROPS_VALUE);
990
+ if (resolved) {
991
+ return resolved;
951
992
  }
993
+ else {
994
+ throw createUnhandleNodeError(type);
995
+ }
996
+ }
997
+ const PROPS_MODIFIER = ['m', 'modifier'];
998
+ function resolveLinkedModifier(node) {
999
+ return resolveProps(node, PROPS_MODIFIER);
1000
+ }
1001
+ const PROPS_KEY = ['k', 'key'];
1002
+ function resolveLinkedKey(node) {
1003
+ const resolved = resolveProps(node, PROPS_KEY);
1004
+ if (resolved) {
1005
+ return resolved;
1006
+ }
1007
+ else {
1008
+ throw createUnhandleNodeError(6 /* NodeTypes.Linked */);
1009
+ }
1010
+ }
1011
+ function resolveProps(node, props, defaultValue) {
1012
+ for (let i = 0; i < props.length; i++) {
1013
+ const prop = props[i];
1014
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1015
+ if (shared.hasOwn(node, prop) && node[prop] != null) {
1016
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1017
+ return node[prop];
1018
+ }
1019
+ }
1020
+ return defaultValue;
1021
+ }
1022
+ function createUnhandleNodeError(type) {
1023
+ return new Error(`unhandled node type: ${type}`);
952
1024
  }
953
1025
 
954
1026
  const WARN_MESSAGE = `Detected HTML in '{source}' message. Recommend not using HTML messages to avoid XSS.`;
@@ -958,7 +1030,7 @@ function checkHtmlMessage(source, warnHtmlMessage) {
958
1030
  }
959
1031
  }
960
1032
  const defaultOnCacheKey = (message) => message;
961
- let compileCache = Object.create(null);
1033
+ let compileCache = shared.create();
962
1034
  function onCompileWarn(_warn) {
963
1035
  if (_warn.code === messageCompiler.CompileWarnCodes.USE_MODULO_SYNTAX) {
964
1036
  shared.warn(`The use of named interpolation with modulo syntax is deprecated. ` +
@@ -968,11 +1040,13 @@ function onCompileWarn(_warn) {
968
1040
  }
969
1041
  }
970
1042
  function clearCompileCache() {
971
- compileCache = Object.create(null);
1043
+ compileCache = shared.create();
1044
+ }
1045
+ function isMessageAST(val) {
1046
+ return (shared.isObject(val) &&
1047
+ resolveType(val) === 0 &&
1048
+ (shared.hasOwn(val, 'b') || shared.hasOwn(val, 'body')));
972
1049
  }
973
- const isMessageAST = (val) => shared.isObject(val) &&
974
- (val.t === 0 || val.type === 0) &&
975
- ('b' in val || 'body' in val);
976
1050
  function baseCompile(message, options = {}) {
977
1051
  // error detecting on compile
978
1052
  let detectError = false;
@@ -1104,7 +1178,7 @@ function translate(context, ...args) {
1104
1178
  : [
1105
1179
  key,
1106
1180
  locale,
1107
- messages[locale] || {}
1181
+ messages[locale] || shared.create()
1108
1182
  ];
1109
1183
  // NOTE:
1110
1184
  // Fix to work around `ssrTransfrom` bug in Vite.
@@ -1200,7 +1274,7 @@ function escapeParams(options) {
1200
1274
  function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
1201
1275
  const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
1202
1276
  const locales = localeFallbacker(context, fallbackLocale, locale); // eslint-disable-line @typescript-eslint/no-explicit-any
1203
- let message = {};
1277
+ let message = shared.create();
1204
1278
  let targetLocale;
1205
1279
  let format = null;
1206
1280
  let from = locale;
@@ -1230,7 +1304,7 @@ function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn
1230
1304
  }
1231
1305
  }
1232
1306
  message =
1233
- messages[targetLocale] || {};
1307
+ messages[targetLocale] || shared.create();
1234
1308
  // for vue-devtools timeline event
1235
1309
  let start = null;
1236
1310
  let startTag;
@@ -1358,7 +1432,7 @@ function evaluateMessage(context, msg, msgCtx) {
1358
1432
  /** @internal */
1359
1433
  function parseTranslateArgs(...args) {
1360
1434
  const [arg1, arg2, arg3] = args;
1361
- const options = {};
1435
+ const options = shared.create();
1362
1436
  if (!shared.isString(arg1) &&
1363
1437
  !shared.isNumber(arg1) &&
1364
1438
  !isMessageFunction(arg1) &&
@@ -1587,8 +1661,8 @@ const DATETIME_FORMAT_OPTIONS_KEYS = [
1587
1661
  /** @internal */
1588
1662
  function parseDateTimeArgs(...args) {
1589
1663
  const [arg1, arg2, arg3, arg4] = args;
1590
- const options = {};
1591
- let overrides = {};
1664
+ const options = shared.create();
1665
+ let overrides = shared.create();
1592
1666
  let value;
1593
1667
  if (shared.isString(arg1)) {
1594
1668
  // Only allow ISO strings - other date formats are often supported,
@@ -1761,8 +1835,8 @@ const NUMBER_FORMAT_OPTIONS_KEYS = [
1761
1835
  /** @internal */
1762
1836
  function parseNumberArgs(...args) {
1763
1837
  const [arg1, arg2, arg3, arg4] = args;
1764
- const options = {};
1765
- let overrides = {};
1838
+ const options = shared.create();
1839
+ let overrides = shared.create();
1766
1840
  if (!shared.isNumber(arg1)) {
1767
1841
  throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1768
1842
  }
@@ -1847,7 +1921,7 @@ exports.registerLocaleFallbacker = registerLocaleFallbacker;
1847
1921
  exports.registerMessageCompiler = registerMessageCompiler;
1848
1922
  exports.registerMessageResolver = registerMessageResolver;
1849
1923
  exports.resolveLocale = resolveLocale;
1850
- exports.resolveValue = resolveValue;
1924
+ exports.resolveValue = resolveValue$1;
1851
1925
  exports.resolveWithKeyValue = resolveWithKeyValue;
1852
1926
  exports.setAdditionalMeta = setAdditionalMeta;
1853
1927
  exports.setDevToolsHook = setDevToolsHook;
@@ -442,7 +442,7 @@ export declare type IsEmptyObject<T> = IsNever<keyof T> extends true ? true : fa
442
442
 
443
443
  /* Excluded from this release type: isImplicitFallback */
444
444
 
445
- export declare const isMessageAST: (val: unknown) => val is ResourceNode;
445
+ export declare function isMessageAST(val: unknown): val is ResourceNode;
446
446
 
447
447
  export declare const isMessageFunction: <T>(val: unknown) => val is MessageFunction<T>;
448
448
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core-base v9.14.1
2
+ * core-base v9.14.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
@@ -1973,7 +1979,7 @@ function resolveWithKeyValue(obj, path) {
1973
1979
  *
1974
1980
  * @VueI18nGeneral
1975
1981
  */
1976
- function resolveValue(obj, path) {
1982
+ function resolveValue$1(obj, path) {
1977
1983
  // check object
1978
1984
  if (!isObject(obj)) {
1979
1985
  return null;
@@ -2066,7 +2072,7 @@ function createMessageContext(options = {}) {
2066
2072
  const _list = options.list || [];
2067
2073
  const list = (index) => _list[index];
2068
2074
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2069
- const _named = options.named || {};
2075
+ const _named = options.named || create();
2070
2076
  isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
2071
2077
  const named = (key) => _named[key];
2072
2078
  function message(key) {
@@ -2133,7 +2139,7 @@ function createMessageContext(options = {}) {
2133
2139
  ["type" /* HelperNameMap.TYPE */]: type,
2134
2140
  ["interpolate" /* HelperNameMap.INTERPOLATE */]: interpolate,
2135
2141
  ["normalize" /* HelperNameMap.NORMALIZE */]: normalize,
2136
- ["values" /* HelperNameMap.VALUES */]: assign({}, _list, _named)
2142
+ ["values" /* HelperNameMap.VALUES */]: assign(create(), _list, _named)
2137
2143
  };
2138
2144
  return ctx;
2139
2145
  }
@@ -2367,7 +2373,7 @@ function appendItemToChain(chain, target, blocks) {
2367
2373
  * Intlify core-base version
2368
2374
  * @internal
2369
2375
  */
2370
- const VERSION = '9.14.1';
2376
+ const VERSION = '9.14.2';
2371
2377
  const NOT_REOSLVED = -1;
2372
2378
  const DEFAULT_LOCALE = 'en-US';
2373
2379
  const MISSING_RESOLVE_VALUE = '';
@@ -2457,17 +2463,17 @@ function createCoreContext(options = {}) {
2457
2463
  : _locale;
2458
2464
  const messages = isPlainObject(options.messages)
2459
2465
  ? options.messages
2460
- : { [_locale]: {} };
2466
+ : createResources(_locale);
2461
2467
  const datetimeFormats = isPlainObject(options.datetimeFormats)
2462
2468
  ? options.datetimeFormats
2463
- : { [_locale]: {} }
2469
+ : createResources(_locale)
2464
2470
  ;
2465
2471
  const numberFormats = isPlainObject(options.numberFormats)
2466
2472
  ? options.numberFormats
2467
- : { [_locale]: {} }
2473
+ : createResources(_locale)
2468
2474
  ;
2469
- const modifiers = assign({}, options.modifiers || {}, getDefaultLinkedModifiers());
2470
- const pluralRules = options.pluralRules || {};
2475
+ const modifiers = assign(create(), options.modifiers, getDefaultLinkedModifiers());
2476
+ const pluralRules = options.pluralRules || create();
2471
2477
  const missing = isFunction(options.missing) ? options.missing : null;
2472
2478
  const missingWarn = isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
2473
2479
  ? options.missingWarn
@@ -2555,6 +2561,7 @@ function createCoreContext(options = {}) {
2555
2561
  }
2556
2562
  return context;
2557
2563
  }
2564
+ const createResources = (locale) => ({ [locale]: create() });
2558
2565
  /** @internal */
2559
2566
  function isTranslateFallbackWarn(fallback, key) {
2560
2567
  return fallback instanceof RegExp ? fallback.test(key) : fallback;
@@ -2621,10 +2628,14 @@ function format(ast) {
2621
2628
  return msg;
2622
2629
  }
2623
2630
  function formatParts(ctx, ast) {
2624
- const body = ast.b || ast.body;
2625
- if ((body.t || body.type) === 1 /* NodeTypes.Plural */) {
2631
+ const body = resolveBody(ast);
2632
+ if (body == null) {
2633
+ throw createUnhandleNodeError(0 /* NodeTypes.Resource */);
2634
+ }
2635
+ const type = resolveType(body);
2636
+ if (type === 1 /* NodeTypes.Plural */) {
2626
2637
  const plural = body;
2627
- const cases = plural.c || plural.cases;
2638
+ const cases = resolveCases(plural);
2628
2639
  return ctx.plural(cases.reduce((messages, c) => [
2629
2640
  ...messages,
2630
2641
  formatMessageParts(ctx, c)
@@ -2634,54 +2645,121 @@ function formatParts(ctx, ast) {
2634
2645
  return formatMessageParts(ctx, body);
2635
2646
  }
2636
2647
  }
2648
+ const PROPS_BODY = ['b', 'body'];
2649
+ function resolveBody(node) {
2650
+ return resolveProps(node, PROPS_BODY);
2651
+ }
2652
+ const PROPS_CASES = ['c', 'cases'];
2653
+ function resolveCases(node) {
2654
+ return resolveProps(node, PROPS_CASES, []);
2655
+ }
2637
2656
  function formatMessageParts(ctx, node) {
2638
- const _static = node.s || node.static;
2639
- if (_static) {
2657
+ const static_ = resolveStatic(node);
2658
+ if (static_ != null) {
2640
2659
  return ctx.type === 'text'
2641
- ? _static
2642
- : ctx.normalize([_static]);
2660
+ ? static_
2661
+ : ctx.normalize([static_]);
2643
2662
  }
2644
2663
  else {
2645
- const messages = (node.i || node.items).reduce((acm, c) => [...acm, formatMessagePart(ctx, c)], []);
2664
+ const messages = resolveItems(node).reduce((acm, c) => [...acm, formatMessagePart(ctx, c)], []);
2646
2665
  return ctx.normalize(messages);
2647
2666
  }
2648
2667
  }
2668
+ const PROPS_STATIC = ['s', 'static'];
2669
+ function resolveStatic(node) {
2670
+ return resolveProps(node, PROPS_STATIC);
2671
+ }
2672
+ const PROPS_ITEMS = ['i', 'items'];
2673
+ function resolveItems(node) {
2674
+ return resolveProps(node, PROPS_ITEMS, []);
2675
+ }
2649
2676
  function formatMessagePart(ctx, node) {
2650
- const type = node.t || node.type;
2677
+ const type = resolveType(node);
2651
2678
  switch (type) {
2652
2679
  case 3 /* NodeTypes.Text */: {
2653
- const text = node;
2654
- return (text.v || text.value);
2680
+ return resolveValue(node, type);
2655
2681
  }
2656
2682
  case 9 /* NodeTypes.Literal */: {
2657
- const literal = node;
2658
- return (literal.v || literal.value);
2683
+ return resolveValue(node, type);
2659
2684
  }
2660
2685
  case 4 /* NodeTypes.Named */: {
2661
2686
  const named = node;
2662
- return ctx.interpolate(ctx.named(named.k || named.key));
2687
+ if (hasOwn(named, 'k') && named.k) {
2688
+ return ctx.interpolate(ctx.named(named.k));
2689
+ }
2690
+ if (hasOwn(named, 'key') && named.key) {
2691
+ return ctx.interpolate(ctx.named(named.key));
2692
+ }
2693
+ throw createUnhandleNodeError(type);
2663
2694
  }
2664
2695
  case 5 /* NodeTypes.List */: {
2665
2696
  const list = node;
2666
- return ctx.interpolate(ctx.list(list.i != null ? list.i : list.index));
2697
+ if (hasOwn(list, 'i') && isNumber(list.i)) {
2698
+ return ctx.interpolate(ctx.list(list.i));
2699
+ }
2700
+ if (hasOwn(list, 'index') && isNumber(list.index)) {
2701
+ return ctx.interpolate(ctx.list(list.index));
2702
+ }
2703
+ throw createUnhandleNodeError(type);
2667
2704
  }
2668
2705
  case 6 /* NodeTypes.Linked */: {
2669
2706
  const linked = node;
2670
- const modifier = linked.m || linked.modifier;
2671
- return ctx.linked(formatMessagePart(ctx, linked.k || linked.key), modifier ? formatMessagePart(ctx, modifier) : undefined, ctx.type);
2707
+ const modifier = resolveLinkedModifier(linked);
2708
+ const key = resolveLinkedKey(linked);
2709
+ return ctx.linked(formatMessagePart(ctx, key), modifier ? formatMessagePart(ctx, modifier) : undefined, ctx.type);
2672
2710
  }
2673
2711
  case 7 /* NodeTypes.LinkedKey */: {
2674
- const linkedKey = node;
2675
- return (linkedKey.v || linkedKey.value);
2712
+ return resolveValue(node, type);
2676
2713
  }
2677
2714
  case 8 /* NodeTypes.LinkedModifier */: {
2678
- const linkedModifier = node;
2679
- return (linkedModifier.v || linkedModifier.value);
2715
+ return resolveValue(node, type);
2680
2716
  }
2681
2717
  default:
2682
- throw new Error(`unhandled node type on format message part: ${type}`);
2718
+ throw new Error(`unhandled node on format message part: ${type}`);
2683
2719
  }
2684
2720
  }
2721
+ const PROPS_TYPE = ['t', 'type'];
2722
+ function resolveType(node) {
2723
+ return resolveProps(node, PROPS_TYPE);
2724
+ }
2725
+ const PROPS_VALUE = ['v', 'value'];
2726
+ function resolveValue(node, type) {
2727
+ const resolved = resolveProps(node, PROPS_VALUE);
2728
+ if (resolved) {
2729
+ return resolved;
2730
+ }
2731
+ else {
2732
+ throw createUnhandleNodeError(type);
2733
+ }
2734
+ }
2735
+ const PROPS_MODIFIER = ['m', 'modifier'];
2736
+ function resolveLinkedModifier(node) {
2737
+ return resolveProps(node, PROPS_MODIFIER);
2738
+ }
2739
+ const PROPS_KEY = ['k', 'key'];
2740
+ function resolveLinkedKey(node) {
2741
+ const resolved = resolveProps(node, PROPS_KEY);
2742
+ if (resolved) {
2743
+ return resolved;
2744
+ }
2745
+ else {
2746
+ throw createUnhandleNodeError(6 /* NodeTypes.Linked */);
2747
+ }
2748
+ }
2749
+ function resolveProps(node, props, defaultValue) {
2750
+ for (let i = 0; i < props.length; i++) {
2751
+ const prop = props[i];
2752
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2753
+ if (hasOwn(node, prop) && node[prop] != null) {
2754
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2755
+ return node[prop];
2756
+ }
2757
+ }
2758
+ return defaultValue;
2759
+ }
2760
+ function createUnhandleNodeError(type) {
2761
+ return new Error(`unhandled node type: ${type}`);
2762
+ }
2685
2763
 
2686
2764
  const WARN_MESSAGE = `Detected HTML in '{source}' message. Recommend not using HTML messages to avoid XSS.`;
2687
2765
  function checkHtmlMessage(source, warnHtmlMessage) {
@@ -2690,7 +2768,7 @@ function checkHtmlMessage(source, warnHtmlMessage) {
2690
2768
  }
2691
2769
  }
2692
2770
  const defaultOnCacheKey = (message) => message;
2693
- let compileCache = Object.create(null);
2771
+ let compileCache = create();
2694
2772
  function onCompileWarn(_warn) {
2695
2773
  if (_warn.code === CompileWarnCodes.USE_MODULO_SYNTAX) {
2696
2774
  warn(`The use of named interpolation with modulo syntax is deprecated. ` +
@@ -2700,11 +2778,13 @@ function onCompileWarn(_warn) {
2700
2778
  }
2701
2779
  }
2702
2780
  function clearCompileCache() {
2703
- compileCache = Object.create(null);
2781
+ compileCache = create();
2782
+ }
2783
+ function isMessageAST(val) {
2784
+ return (isObject(val) &&
2785
+ resolveType(val) === 0 &&
2786
+ (hasOwn(val, 'b') || hasOwn(val, 'body')));
2704
2787
  }
2705
- const isMessageAST = (val) => isObject(val) &&
2706
- (val.t === 0 || val.type === 0) &&
2707
- ('b' in val || 'body' in val);
2708
2788
  function baseCompile(message, options = {}) {
2709
2789
  // error detecting on compile
2710
2790
  let detectError = false;
@@ -2836,7 +2916,7 @@ function translate(context, ...args) {
2836
2916
  : [
2837
2917
  key,
2838
2918
  locale,
2839
- messages[locale] || {}
2919
+ messages[locale] || create()
2840
2920
  ];
2841
2921
  // NOTE:
2842
2922
  // Fix to work around `ssrTransfrom` bug in Vite.
@@ -2932,7 +3012,7 @@ function escapeParams(options) {
2932
3012
  function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
2933
3013
  const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
2934
3014
  const locales = localeFallbacker(context, fallbackLocale, locale); // eslint-disable-line @typescript-eslint/no-explicit-any
2935
- let message = {};
3015
+ let message = create();
2936
3016
  let targetLocale;
2937
3017
  let format = null;
2938
3018
  let from = locale;
@@ -2962,7 +3042,7 @@ function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn
2962
3042
  }
2963
3043
  }
2964
3044
  message =
2965
- messages[targetLocale] || {};
3045
+ messages[targetLocale] || create();
2966
3046
  // for vue-devtools timeline event
2967
3047
  let start = null;
2968
3048
  let startTag;
@@ -3090,7 +3170,7 @@ function evaluateMessage(context, msg, msgCtx) {
3090
3170
  /** @internal */
3091
3171
  function parseTranslateArgs(...args) {
3092
3172
  const [arg1, arg2, arg3] = args;
3093
- const options = {};
3173
+ const options = create();
3094
3174
  if (!isString(arg1) &&
3095
3175
  !isNumber(arg1) &&
3096
3176
  !isMessageFunction(arg1) &&
@@ -3319,8 +3399,8 @@ const DATETIME_FORMAT_OPTIONS_KEYS = [
3319
3399
  /** @internal */
3320
3400
  function parseDateTimeArgs(...args) {
3321
3401
  const [arg1, arg2, arg3, arg4] = args;
3322
- const options = {};
3323
- let overrides = {};
3402
+ const options = create();
3403
+ let overrides = create();
3324
3404
  let value;
3325
3405
  if (isString(arg1)) {
3326
3406
  // Only allow ISO strings - other date formats are often supported,
@@ -3493,8 +3573,8 @@ const NUMBER_FORMAT_OPTIONS_KEYS = [
3493
3573
  /** @internal */
3494
3574
  function parseNumberArgs(...args) {
3495
3575
  const [arg1, arg2, arg3, arg4] = args;
3496
- const options = {};
3497
- let overrides = {};
3576
+ const options = create();
3577
+ let overrides = create();
3498
3578
  if (!isNumber(arg1)) {
3499
3579
  throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
3500
3580
  }
@@ -3535,4 +3615,4 @@ function clearNumberFormat(ctx, locale, format) {
3535
3615
  }
3536
3616
  }
3537
3617
 
3538
- export { CompileErrorCodes, CoreErrorCodes, CoreWarnCodes, DATETIME_FORMAT_OPTIONS_KEYS, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_REOSLVED, NUMBER_FORMAT_OPTIONS_KEYS, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compile, compileToFunction, createCompileError, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getAdditionalMeta, getDevToolsHook, getFallbackContext, getLocale, getWarnMessage, handleMissing, initI18nDevTools, isAlmostSameLocale, isImplicitFallback, isMessageAST, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveLocale, resolveValue, resolveWithKeyValue, setAdditionalMeta, setDevToolsHook, setFallbackContext, translate, translateDevTools, updateFallbackLocale };
3618
+ export { CompileErrorCodes, CoreErrorCodes, CoreWarnCodes, DATETIME_FORMAT_OPTIONS_KEYS, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_REOSLVED, NUMBER_FORMAT_OPTIONS_KEYS, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compile, compileToFunction, createCompileError, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getAdditionalMeta, getDevToolsHook, getFallbackContext, getLocale, getWarnMessage, handleMissing, initI18nDevTools, isAlmostSameLocale, isImplicitFallback, isMessageAST, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveLocale, resolveValue$1 as resolveValue, resolveWithKeyValue, setAdditionalMeta, setDevToolsHook, setFallbackContext, translate, translateDevTools, updateFallbackLocale };