@intlify/core-base 11.1.2 → 11.1.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 v11.1.2
2
+ * core-base v11.1.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
  function format(ast) {
12
86
  const msg = (ctx) => formatParts(ctx, ast);
13
87
  return msg;
@@ -30,14 +104,6 @@ function formatParts(ctx, ast) {
30
104
  return formatMessageParts(ctx, body);
31
105
  }
32
106
  }
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
- }
41
107
  function formatMessageParts(ctx, node) {
42
108
  const static_ = resolveStatic(node);
43
109
  if (static_ != null) {
@@ -50,14 +116,6 @@ function formatMessageParts(ctx, node) {
50
116
  return ctx.normalize(messages);
51
117
  }
52
118
  }
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
- }
61
119
  function formatMessagePart(ctx, node) {
62
120
  const type = resolveType(node);
63
121
  switch (type) {
@@ -103,59 +161,12 @@ function formatMessagePart(ctx, node) {
103
161
  throw new Error(`unhandled node on format message part: ${type}`);
104
162
  }
105
163
  }
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;
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}`);
147
- }
148
164
 
149
165
  const defaultOnCacheKey = (message) => message;
150
166
  let compileCache = shared.create();
151
167
  function clearCompileCache() {
152
168
  compileCache = shared.create();
153
169
  }
154
- function isMessageAST(val) {
155
- return (shared.isObject(val) &&
156
- resolveType(val) === 0 &&
157
- (shared.hasOwn(val, 'b') || shared.hasOwn(val, 'body')));
158
- }
159
170
  function baseCompile(message, options = {}) {
160
171
  // error detecting on compile
161
172
  let detectError = false;
@@ -663,7 +674,16 @@ function resolveValue(obj, path) {
663
674
  let last = obj;
664
675
  let i = 0;
665
676
  while (i < len) {
666
- const val = last[hit[i]];
677
+ const key = hit[i];
678
+ /**
679
+ * NOTE:
680
+ * if `key` is intlify message format AST node key and `last` is intlify message format AST, skip it.
681
+ * because the AST node is not a key-value structure.
682
+ */
683
+ if (AST_NODE_PROPS_KEYS.includes(key) && isMessageAST(last)) {
684
+ return null;
685
+ }
686
+ const val = last[key];
667
687
  if (val === undefined) {
668
688
  return null;
669
689
  }
@@ -705,7 +725,7 @@ function getWarnMessage(code, ...args) {
705
725
  * Intlify core-base version
706
726
  * @internal
707
727
  */
708
- const VERSION = '11.1.2';
728
+ const VERSION = '11.1.4';
709
729
  const NOT_REOSLVED = -1;
710
730
  const DEFAULT_LOCALE = 'en-US';
711
731
  const MISSING_RESOLVE_VALUE = '';
@@ -1573,6 +1593,7 @@ function getMessageContextOptions(context, locale, message, options) {
1573
1593
 
1574
1594
  exports.CompileErrorCodes = messageCompiler.CompileErrorCodes;
1575
1595
  exports.createCompileError = messageCompiler.createCompileError;
1596
+ exports.AST_NODE_PROPS_KEYS = AST_NODE_PROPS_KEYS;
1576
1597
  exports.CORE_ERROR_CODES_EXTEND_POINT = CORE_ERROR_CODES_EXTEND_POINT;
1577
1598
  exports.CORE_WARN_CODES_EXTEND_POINT = CORE_WARN_CODES_EXTEND_POINT;
1578
1599
  exports.CoreErrorCodes = CoreErrorCodes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlify/core-base",
3
- "version": "11.1.2",
3
+ "version": "11.1.4",
4
4
  "description": "@intlify/core-base",
5
5
  "keywords": [
6
6
  "core",
@@ -33,11 +33,11 @@
33
33
  "jsdelivr": "dist/core-base.global.js",
34
34
  "types": "dist/core-base.d.ts",
35
35
  "dependencies": {
36
- "@intlify/shared": "11.1.2",
37
- "@intlify/message-compiler": "11.1.2"
36
+ "@intlify/message-compiler": "11.1.4",
37
+ "@intlify/shared": "11.1.4"
38
38
  },
39
39
  "devDependencies": {
40
- "@intlify/devtools-types": "11.1.2"
40
+ "@intlify/devtools-types": "11.1.4"
41
41
  },
42
42
  "engines": {
43
43
  "node": ">= 16"