@dongmingzhixiu/vuexir-compiler 0.2.1 → 0.2.3
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.
- package/dist/transform/stores.js +13 -3
- package/package.json +1 -1
package/dist/transform/stores.js
CHANGED
|
@@ -155,7 +155,7 @@ export function parseStoreSource(src) {
|
|
|
155
155
|
found.push({ name: x.key, value: x.value });
|
|
156
156
|
}
|
|
157
157
|
void cursor;
|
|
158
|
-
def.getters = found.map((x) => getterShape(x.name, x.value));
|
|
158
|
+
def.getters = found.map((x) => getterShape(x.name, x.value, def.state));
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
const am = body.match(/actions\s*:\s*\{/);
|
|
@@ -284,7 +284,7 @@ export function parseSharedConstArrays(src) {
|
|
|
284
284
|
* 其余(遍历/过滤/排序/调用)→ 记录底层 state 字段供降级读取(语义丢失,调用方必须告警)。
|
|
285
285
|
* state 写法有三种:`(state) => state.list` 形参式、`this.list` 方法体式、`state.list`。
|
|
286
286
|
*/
|
|
287
|
-
function getterShape(name, value) {
|
|
287
|
+
function getterShape(name, value, state = []) {
|
|
288
288
|
const v = value.trim();
|
|
289
289
|
// 纯成员链
|
|
290
290
|
const m = v.match(/^\s*\(?\s*(\w+)\s*\)?\s*=>\s*([\w$.\[\]']+)\s*$/);
|
|
@@ -299,5 +299,15 @@ function getterShape(name, value) {
|
|
|
299
299
|
const uniq = [...new Set(refs)];
|
|
300
300
|
if (uniq.length === 1)
|
|
301
301
|
return { name, refField: uniq[0] };
|
|
302
|
-
|
|
302
|
+
if (uniq.length > 1) {
|
|
303
|
+
// 多依赖时优先挑「数组/列表」字段:列表类 getter(upcoming/soon/…)的渲染主体就是它
|
|
304
|
+
const listField = uniq.find((f) => state.some((st) => st.name === f && st.list));
|
|
305
|
+
if (listField)
|
|
306
|
+
return { name, refField: listField };
|
|
307
|
+
const objField = uniq.find((f) => state.some((st) => st.name === f && st.obj));
|
|
308
|
+
if (objField)
|
|
309
|
+
return { name, refField: objField };
|
|
310
|
+
return { name, multi: true };
|
|
311
|
+
}
|
|
312
|
+
return { name };
|
|
303
313
|
}
|