@intlify/core-base 9.14.3 → 9.14.4

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.3
2
+ * core-base v9.14.4
3
3
  * (c) 2025 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -8,6 +8,80 @@
8
8
  var messageCompiler = require('@intlify/message-compiler');
9
9
  var shared = require('@intlify/shared');
10
10
 
11
+ function isMessageAST(val) {
12
+ return (shared.isObject(val) &&
13
+ resolveType(val) === 0 &&
14
+ (shared.hasOwn(val, 'b') || shared.hasOwn(val, 'body')));
15
+ }
16
+ const PROPS_BODY = ['b', 'body'];
17
+ function resolveBody(node) {
18
+ return resolveProps(node, PROPS_BODY);
19
+ }
20
+ const PROPS_CASES = ['c', 'cases'];
21
+ function resolveCases(node) {
22
+ return resolveProps(node, PROPS_CASES, []);
23
+ }
24
+ const PROPS_STATIC = ['s', 'static'];
25
+ function resolveStatic(node) {
26
+ return resolveProps(node, PROPS_STATIC);
27
+ }
28
+ const PROPS_ITEMS = ['i', 'items'];
29
+ function resolveItems(node) {
30
+ return resolveProps(node, PROPS_ITEMS, []);
31
+ }
32
+ const PROPS_TYPE = ['t', 'type'];
33
+ function resolveType(node) {
34
+ return resolveProps(node, PROPS_TYPE);
35
+ }
36
+ const PROPS_VALUE = ['v', 'value'];
37
+ function resolveValue$1(node, type) {
38
+ const resolved = resolveProps(node, PROPS_VALUE);
39
+ if (resolved != null) {
40
+ return resolved;
41
+ }
42
+ else {
43
+ throw createUnhandleNodeError(type);
44
+ }
45
+ }
46
+ const PROPS_MODIFIER = ['m', 'modifier'];
47
+ function resolveLinkedModifier(node) {
48
+ return resolveProps(node, PROPS_MODIFIER);
49
+ }
50
+ const PROPS_KEY = ['k', 'key'];
51
+ function resolveLinkedKey(node) {
52
+ const resolved = resolveProps(node, PROPS_KEY);
53
+ if (resolved) {
54
+ return resolved;
55
+ }
56
+ else {
57
+ throw createUnhandleNodeError(6 /* NodeTypes.Linked */);
58
+ }
59
+ }
60
+ function resolveProps(node, props, defaultValue) {
61
+ for (let i = 0; i < props.length; i++) {
62
+ const prop = props[i];
63
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
+ if (shared.hasOwn(node, prop) && node[prop] != null) {
65
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
+ return node[prop];
67
+ }
68
+ }
69
+ return defaultValue;
70
+ }
71
+ const AST_NODE_PROPS_KEYS = [
72
+ ...PROPS_BODY,
73
+ ...PROPS_CASES,
74
+ ...PROPS_STATIC,
75
+ ...PROPS_ITEMS,
76
+ ...PROPS_KEY,
77
+ ...PROPS_MODIFIER,
78
+ ...PROPS_VALUE,
79
+ ...PROPS_TYPE
80
+ ];
81
+ function createUnhandleNodeError(type) {
82
+ return new Error(`unhandled node type: ${type}`);
83
+ }
84
+
11
85
  const pathStateMachine = [];
12
86
  pathStateMachine[0 /* States.BEFORE_PATH */] = {
13
87
  ["w" /* PathCharTypes.WORKSPACE */]: [0 /* States.BEFORE_PATH */],
@@ -241,7 +315,7 @@ function resolveWithKeyValue(obj, path) {
241
315
  *
242
316
  * @VueI18nGeneral
243
317
  */
244
- function resolveValue$1(obj, path) {
318
+ function resolveValue(obj, path) {
245
319
  // check object
246
320
  if (!shared.isObject(obj)) {
247
321
  return null;
@@ -263,7 +337,16 @@ function resolveValue$1(obj, path) {
263
337
  let last = obj;
264
338
  let i = 0;
265
339
  while (i < len) {
266
- const val = last[hit[i]];
340
+ const key = hit[i];
341
+ /**
342
+ * NOTE:
343
+ * if `key` is intlify message format AST node key and `last` is intlify message format AST, skip it.
344
+ * because the AST node is not a key-value structure.
345
+ */
346
+ if (AST_NODE_PROPS_KEYS.includes(key) && isMessageAST(last)) {
347
+ return null;
348
+ }
349
+ const val = last[key];
267
350
  if (val === undefined) {
268
351
  return null;
269
352
  }
@@ -635,7 +718,7 @@ function appendItemToChain(chain, target, blocks) {
635
718
  * Intlify core-base version
636
719
  * @internal
637
720
  */
638
- const VERSION = '9.14.3';
721
+ const VERSION = '9.14.4';
639
722
  const NOT_REOSLVED = -1;
640
723
  const DEFAULT_LOCALE = 'en-US';
641
724
  const MISSING_RESOLVE_VALUE = '';
@@ -907,14 +990,6 @@ function formatParts(ctx, ast) {
907
990
  return formatMessageParts(ctx, body);
908
991
  }
909
992
  }
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
- }
918
993
  function formatMessageParts(ctx, node) {
919
994
  const static_ = resolveStatic(node);
920
995
  if (static_ != null) {
@@ -927,22 +1002,14 @@ function formatMessageParts(ctx, node) {
927
1002
  return ctx.normalize(messages);
928
1003
  }
929
1004
  }
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
- }
938
1005
  function formatMessagePart(ctx, node) {
939
1006
  const type = resolveType(node);
940
1007
  switch (type) {
941
1008
  case 3 /* NodeTypes.Text */: {
942
- return resolveValue(node, type);
1009
+ return resolveValue$1(node, type);
943
1010
  }
944
1011
  case 9 /* NodeTypes.Literal */: {
945
- return resolveValue(node, type);
1012
+ return resolveValue$1(node, type);
946
1013
  }
947
1014
  case 4 /* NodeTypes.Named */: {
948
1015
  const named = node;
@@ -971,57 +1038,15 @@ function formatMessagePart(ctx, node) {
971
1038
  return ctx.linked(formatMessagePart(ctx, key), modifier ? formatMessagePart(ctx, modifier) : undefined, ctx.type);
972
1039
  }
973
1040
  case 7 /* NodeTypes.LinkedKey */: {
974
- return resolveValue(node, type);
1041
+ return resolveValue$1(node, type);
975
1042
  }
976
1043
  case 8 /* NodeTypes.LinkedModifier */: {
977
- return resolveValue(node, type);
1044
+ return resolveValue$1(node, type);
978
1045
  }
979
1046
  default:
980
1047
  throw new Error(`unhandled node on format message part: ${type}`);
981
1048
  }
982
1049
  }
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;
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}`);
1024
- }
1025
1050
 
1026
1051
  const WARN_MESSAGE = `Detected HTML in '{source}' message. Recommend not using HTML messages to avoid XSS.`;
1027
1052
  function checkHtmlMessage(source, warnHtmlMessage) {
@@ -1042,11 +1067,6 @@ function onCompileWarn(_warn) {
1042
1067
  function clearCompileCache() {
1043
1068
  compileCache = shared.create();
1044
1069
  }
1045
- function isMessageAST(val) {
1046
- return (shared.isObject(val) &&
1047
- resolveType(val) === 0 &&
1048
- (shared.hasOwn(val, 'b') || shared.hasOwn(val, 'body')));
1049
- }
1050
1070
  function baseCompile(message, options = {}) {
1051
1071
  // error detecting on compile
1052
1072
  let detectError = false;
@@ -1879,6 +1899,7 @@ function clearNumberFormat(ctx, locale, format) {
1879
1899
 
1880
1900
  exports.CompileErrorCodes = messageCompiler.CompileErrorCodes;
1881
1901
  exports.createCompileError = messageCompiler.createCompileError;
1902
+ exports.AST_NODE_PROPS_KEYS = AST_NODE_PROPS_KEYS;
1882
1903
  exports.CoreErrorCodes = CoreErrorCodes;
1883
1904
  exports.CoreWarnCodes = CoreWarnCodes;
1884
1905
  exports.DATETIME_FORMAT_OPTIONS_KEYS = DATETIME_FORMAT_OPTIONS_KEYS;
@@ -1921,7 +1942,7 @@ exports.registerLocaleFallbacker = registerLocaleFallbacker;
1921
1942
  exports.registerMessageCompiler = registerMessageCompiler;
1922
1943
  exports.registerMessageResolver = registerMessageResolver;
1923
1944
  exports.resolveLocale = resolveLocale;
1924
- exports.resolveValue = resolveValue$1;
1945
+ exports.resolveValue = resolveValue;
1925
1946
  exports.resolveWithKeyValue = resolveWithKeyValue;
1926
1947
  exports.setAdditionalMeta = setAdditionalMeta;
1927
1948
  exports.setDevToolsHook = setDevToolsHook;
@@ -20,6 +20,8 @@ declare type AdditionalPayloads = {
20
20
  meta?: Record<string, unknown>;
21
21
  };
22
22
 
23
+ export declare const AST_NODE_PROPS_KEYS: string[];
24
+
23
25
  export declare function clearCompileCache(): void;
24
26
 
25
27
  /* Excluded from this release type: clearDateTimeFormat */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core-base v9.14.3
2
+ * core-base v9.14.4
3
3
  * (c) 2025 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -1746,6 +1746,80 @@ function baseCompile$1(source, options = {}) {
1746
1746
  }
1747
1747
  }
1748
1748
 
1749
+ function isMessageAST(val) {
1750
+ return (isObject(val) &&
1751
+ resolveType(val) === 0 &&
1752
+ (hasOwn(val, 'b') || hasOwn(val, 'body')));
1753
+ }
1754
+ const PROPS_BODY = ['b', 'body'];
1755
+ function resolveBody(node) {
1756
+ return resolveProps(node, PROPS_BODY);
1757
+ }
1758
+ const PROPS_CASES = ['c', 'cases'];
1759
+ function resolveCases(node) {
1760
+ return resolveProps(node, PROPS_CASES, []);
1761
+ }
1762
+ const PROPS_STATIC = ['s', 'static'];
1763
+ function resolveStatic(node) {
1764
+ return resolveProps(node, PROPS_STATIC);
1765
+ }
1766
+ const PROPS_ITEMS = ['i', 'items'];
1767
+ function resolveItems(node) {
1768
+ return resolveProps(node, PROPS_ITEMS, []);
1769
+ }
1770
+ const PROPS_TYPE = ['t', 'type'];
1771
+ function resolveType(node) {
1772
+ return resolveProps(node, PROPS_TYPE);
1773
+ }
1774
+ const PROPS_VALUE = ['v', 'value'];
1775
+ function resolveValue$1(node, type) {
1776
+ const resolved = resolveProps(node, PROPS_VALUE);
1777
+ if (resolved != null) {
1778
+ return resolved;
1779
+ }
1780
+ else {
1781
+ throw createUnhandleNodeError(type);
1782
+ }
1783
+ }
1784
+ const PROPS_MODIFIER = ['m', 'modifier'];
1785
+ function resolveLinkedModifier(node) {
1786
+ return resolveProps(node, PROPS_MODIFIER);
1787
+ }
1788
+ const PROPS_KEY = ['k', 'key'];
1789
+ function resolveLinkedKey(node) {
1790
+ const resolved = resolveProps(node, PROPS_KEY);
1791
+ if (resolved) {
1792
+ return resolved;
1793
+ }
1794
+ else {
1795
+ throw createUnhandleNodeError(6 /* NodeTypes.Linked */);
1796
+ }
1797
+ }
1798
+ function resolveProps(node, props, defaultValue) {
1799
+ for (let i = 0; i < props.length; i++) {
1800
+ const prop = props[i];
1801
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1802
+ if (hasOwn(node, prop) && node[prop] != null) {
1803
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1804
+ return node[prop];
1805
+ }
1806
+ }
1807
+ return defaultValue;
1808
+ }
1809
+ const AST_NODE_PROPS_KEYS = [
1810
+ ...PROPS_BODY,
1811
+ ...PROPS_CASES,
1812
+ ...PROPS_STATIC,
1813
+ ...PROPS_ITEMS,
1814
+ ...PROPS_KEY,
1815
+ ...PROPS_MODIFIER,
1816
+ ...PROPS_VALUE,
1817
+ ...PROPS_TYPE
1818
+ ];
1819
+ function createUnhandleNodeError(type) {
1820
+ return new Error(`unhandled node type: ${type}`);
1821
+ }
1822
+
1749
1823
  const pathStateMachine = [];
1750
1824
  pathStateMachine[0 /* States.BEFORE_PATH */] = {
1751
1825
  ["w" /* PathCharTypes.WORKSPACE */]: [0 /* States.BEFORE_PATH */],
@@ -1979,7 +2053,7 @@ function resolveWithKeyValue(obj, path) {
1979
2053
  *
1980
2054
  * @VueI18nGeneral
1981
2055
  */
1982
- function resolveValue$1(obj, path) {
2056
+ function resolveValue(obj, path) {
1983
2057
  // check object
1984
2058
  if (!isObject(obj)) {
1985
2059
  return null;
@@ -2001,7 +2075,16 @@ function resolveValue$1(obj, path) {
2001
2075
  let last = obj;
2002
2076
  let i = 0;
2003
2077
  while (i < len) {
2004
- const val = last[hit[i]];
2078
+ const key = hit[i];
2079
+ /**
2080
+ * NOTE:
2081
+ * if `key` is intlify message format AST node key and `last` is intlify message format AST, skip it.
2082
+ * because the AST node is not a key-value structure.
2083
+ */
2084
+ if (AST_NODE_PROPS_KEYS.includes(key) && isMessageAST(last)) {
2085
+ return null;
2086
+ }
2087
+ const val = last[key];
2005
2088
  if (val === undefined) {
2006
2089
  return null;
2007
2090
  }
@@ -2373,7 +2456,7 @@ function appendItemToChain(chain, target, blocks) {
2373
2456
  * Intlify core-base version
2374
2457
  * @internal
2375
2458
  */
2376
- const VERSION = '9.14.3';
2459
+ const VERSION = '9.14.4';
2377
2460
  const NOT_REOSLVED = -1;
2378
2461
  const DEFAULT_LOCALE = 'en-US';
2379
2462
  const MISSING_RESOLVE_VALUE = '';
@@ -2645,14 +2728,6 @@ function formatParts(ctx, ast) {
2645
2728
  return formatMessageParts(ctx, body);
2646
2729
  }
2647
2730
  }
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
- }
2656
2731
  function formatMessageParts(ctx, node) {
2657
2732
  const static_ = resolveStatic(node);
2658
2733
  if (static_ != null) {
@@ -2665,22 +2740,14 @@ function formatMessageParts(ctx, node) {
2665
2740
  return ctx.normalize(messages);
2666
2741
  }
2667
2742
  }
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
- }
2676
2743
  function formatMessagePart(ctx, node) {
2677
2744
  const type = resolveType(node);
2678
2745
  switch (type) {
2679
2746
  case 3 /* NodeTypes.Text */: {
2680
- return resolveValue(node, type);
2747
+ return resolveValue$1(node, type);
2681
2748
  }
2682
2749
  case 9 /* NodeTypes.Literal */: {
2683
- return resolveValue(node, type);
2750
+ return resolveValue$1(node, type);
2684
2751
  }
2685
2752
  case 4 /* NodeTypes.Named */: {
2686
2753
  const named = node;
@@ -2709,57 +2776,15 @@ function formatMessagePart(ctx, node) {
2709
2776
  return ctx.linked(formatMessagePart(ctx, key), modifier ? formatMessagePart(ctx, modifier) : undefined, ctx.type);
2710
2777
  }
2711
2778
  case 7 /* NodeTypes.LinkedKey */: {
2712
- return resolveValue(node, type);
2779
+ return resolveValue$1(node, type);
2713
2780
  }
2714
2781
  case 8 /* NodeTypes.LinkedModifier */: {
2715
- return resolveValue(node, type);
2782
+ return resolveValue$1(node, type);
2716
2783
  }
2717
2784
  default:
2718
2785
  throw new Error(`unhandled node on format message part: ${type}`);
2719
2786
  }
2720
2787
  }
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
- }
2763
2788
 
2764
2789
  const WARN_MESSAGE = `Detected HTML in '{source}' message. Recommend not using HTML messages to avoid XSS.`;
2765
2790
  function checkHtmlMessage(source, warnHtmlMessage) {
@@ -2780,11 +2805,6 @@ function onCompileWarn(_warn) {
2780
2805
  function clearCompileCache() {
2781
2806
  compileCache = create();
2782
2807
  }
2783
- function isMessageAST(val) {
2784
- return (isObject(val) &&
2785
- resolveType(val) === 0 &&
2786
- (hasOwn(val, 'b') || hasOwn(val, 'body')));
2787
- }
2788
2808
  function baseCompile(message, options = {}) {
2789
2809
  // error detecting on compile
2790
2810
  let detectError = false;
@@ -3615,4 +3635,4 @@ function clearNumberFormat(ctx, locale, format) {
3615
3635
  }
3616
3636
  }
3617
3637
 
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 };
3638
+ export { AST_NODE_PROPS_KEYS, 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 };