@cocojs/mvc 0.1.0-beta.13 → 0.1.0-beta.15

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/index.cjs.js CHANGED
@@ -58,27 +58,6 @@ function isDescendantOf(s, p) {
58
58
  }
59
59
  return false;
60
60
  }
61
- /**
62
- * 生成一个只能执行一次的函数
63
- * @param fn
64
- */
65
- function once(fn) {
66
- let runTimes = 0;
67
- const onceFn = THIS => {
68
- if (onceFn.fn) {
69
- if (runTimes === 0) {
70
- runTimes++;
71
- return onceFn.fn.call(THIS);
72
- }
73
- }
74
- };
75
- onceFn.fn = fn;
76
- return onceFn;
77
- }
78
- // 是否是普通类,因为class会转成function,所以不通过toString判断
79
- function isClass(v) {
80
- return typeof v === 'function' && v.prototype && v.prototype.constructor === v;
81
- }
82
61
  /**
83
62
  * 在coco/mvc中是否是一个合法的类
84
63
  * @param v
@@ -149,153 +128,72 @@ function instantiateMetadata(metadataCls, args) {
149
128
  return metadata;
150
129
  }
151
130
 
152
- function _applyDecs2311(e, t, n, r, o, i) {
153
- var a, c, u, s, f, l, p, d = Symbol.metadata || Symbol.for("Symbol.metadata"), m = Object.defineProperty, h = Object.create, y = [h(null), h(null)], v = t.length;
154
- function g(t, n, r) {
155
- return function (o, i) {
156
- n && (i = o, o = e);
157
- for (var a = 0; a < t.length; a++)
158
- i = t[a].apply(o, r ? [i] : []);
159
- return r ? i : o;
160
- };
161
- }
162
- function b(e, t, n, r) {
163
- if ("function" != typeof e && (r || void 0 !== e))
164
- throw new TypeError(t + " must " + (n || "be") + " a function" + (r ? "" : " or undefined"));
165
- return e;
166
- }
167
- function applyDec(e, t, n, r, o, i, u, s, f, l, p) {
168
- function d(e) {
169
- if (!p(e))
170
- throw new TypeError("Attempted to access private element on non-instance");
171
- }
172
- var h = [].concat(t[0]), v = t[3], w = !u, D = 1 === o, S = 3 === o, j = 4 === o, E = 2 === o;
173
- function I(t, n, r) {
174
- return function (o, i) {
175
- return n && (i = o, o = e), r && r(o), P[t].call(o, i);
176
- };
177
- }
178
- if (!w) {
179
- var P = {}, k = [], F = S ? "get" : j || D ? "set" : "value";
180
- if (f ? (l || D ? P = {
181
- get: _setFunctionName(function () {
182
- return v(this);
183
- }, r, "get"),
184
- set: function (e) {
185
- t[4](this, e);
186
- }
187
- } : P[F] = v, l || _setFunctionName(P[F], r, E ? "" : F)) : l || (P = Object.getOwnPropertyDescriptor(e, r)), !l && !f) {
188
- if ((c = y[+s][r]) && 7 !== (c ^ o))
189
- throw Error("Decorating two elements with the same name (" + P[F].name + ") is not supported yet");
190
- y[+s][r] = o < 3 ? 1 : o;
191
- }
192
- }
193
- for (var N = e, O = h.length - 1; O >= 0; O -= n ? 2 : 1) {
194
- var T = b(h[O], "A decorator", "be", true), z = n ? h[O - 1] : void 0, A = {}, H = {
195
- kind: ["field", "accessor", "method", "getter", "setter", "class"][o],
196
- name: r,
197
- metadata: a,
198
- addInitializer: function (e, t) {
199
- if (e.v)
200
- throw new TypeError("attempted to call addInitializer after decoration was finished");
201
- b(t, "An initializer", "be", true), i.push(t);
202
- }.bind(null, A)
203
- };
204
- if (w)
205
- c = T.call(z, N, H), A.v = 1, b(c, "class decorators", "return") && (N = c);
206
- else if (H.static = s, H.private = f, c = H.access = {
207
- has: f ? p.bind() : function (e) {
208
- return r in e;
209
- }
210
- }, j || (c.get = f ? E ? function (e) {
211
- return d(e), P.value;
212
- } : I("get", 0, d) : function (e) {
213
- return e[r];
214
- }), E || S || (c.set = f ? I("set", 0, d) : function (e, t) {
215
- e[r] = t;
216
- }), N = T.call(z, D ? {
217
- get: P.get,
218
- set: P.set
219
- } : P[F], H), A.v = 1, D) {
220
- if ("object" == typeof N && N)
221
- (c = b(N.get, "accessor.get")) && (P.get = c), (c = b(N.set, "accessor.set")) && (P.set = c), (c = b(N.init, "accessor.init")) && k.unshift(c);
222
- else if (void 0 !== N)
223
- throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined");
224
- }
225
- else
226
- b(N, (l ? "field" : "method") + " decorators", "return") && (l ? k.unshift(N) : P[F] = N);
227
- }
228
- return o < 2 && u.push(g(k, s, 1), g(i, s, 0)), l || w || (f ? D ? u.splice(-1, 0, I("get", s), I("set", s)) : u.push(E ? P[F] : b.call.bind(P[F])) : m(e, r, P)), N;
229
- }
230
- function w(e) {
231
- return m(e, d, {
232
- configurable: true,
233
- enumerable: true,
234
- value: a
235
- });
236
- }
237
- return void 0 !== i && (a = i[d]), a = h(null == a ? null : a), f = [], l = function (e) {
238
- e && f.push(g(e));
239
- }, p = function (t, r) {
240
- for (var i = 0; i < n.length; i++) {
241
- var a = n[i], c = a[1], l = 7 & c;
242
- if ((8 & c) == t && !l == r) {
243
- var p = a[2], d = !!a[3], m = 16 & c;
244
- applyDec(t ? e : e.prototype, a, m, d ? "#" + p : _toPropertyKey(p), l, l < 2 ? [] : t ? s = s || [] : u = u || [], f, !!t, d, r, t && d ? function (t) {
245
- return _checkInRHS(t) === e;
246
- } : o);
247
- }
248
- }
249
- }, p(8, 0), p(0, 0), p(8, 1), p(0, 1), l(u), l(s), c = f, v || w(e), {
250
- e: c,
251
- get c() {
252
- var n = [];
253
- return v && [w(e = applyDec(e, [t], r, e.name, 5, n)), g(n, 1)];
254
- }
255
- };
131
+ /**
132
+ * 声明被装饰类是某个装饰器表达式的元数据类。
133
+ * 由 AOT 编译器转换为 bindPlaceholderMetadataClass 调用,不应在运行时执行。
134
+ * @public
135
+ */
136
+ function metadataFor(_decoratorExp) {
137
+ return function (_beDecoratedCls, _context) {
138
+ // metadataFor 正常应由 AOT 编译期转换为 bindPlaceholderMetadataClass 调用,
139
+ // 运行到这里说明代码未经 @cocojs/compiler 编译。
140
+ throw new Error('metadataFor 不应在运行时执行,请先使用 @cocojs/compiler 编译后再运行。');
141
+ };
256
142
  }
257
- function _checkInRHS(e) {
258
- if (Object(e) !== e)
259
- throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null"));
260
- return e;
143
+
144
+ const KindClass = 'class';
145
+ const KindField = 'field';
146
+ const KindMethod = 'method';
147
+ const KindGetter = 'getter';
148
+
149
+ // 与 AOT 注册表一样跨运行时模块实例共享,确保绑定方能读取创建方记录的选项
150
+ const decoratorOptionsKey = Symbol.for('coco.decoratorOptions');
151
+ const globalObject$1 = globalThis;
152
+ if (!globalObject$1[decoratorOptionsKey]) {
153
+ globalObject$1[decoratorOptionsKey] = {
154
+ metadata: new Map(),
155
+ placeholder: new Map(),
156
+ placeholderClassMap2RealMetadataClass: new Map()
157
+ };
261
158
  }
262
- function _identity(t) {
263
- return t;
159
+ // 元数据类 <--> 装饰器选项
160
+ const metadataDecoratorOptions = globalObject$1[decoratorOptionsKey].metadata;
161
+ // 占位的元数据类 <--> 装饰器选项
162
+ const placeholderDecoratorOptions = globalObject$1[decoratorOptionsKey].placeholder;
163
+ // 占位的元数据类 -> 真实的元数据类
164
+ const placeholderClassMap2RealMetadataClass = globalObject$1[decoratorOptionsKey].placeholderClassMap2RealMetadataClass;
165
+ // 记录创建装饰器表达式的选项
166
+ function addCreateDecoratorOption(isPlaceholderExp, metadataClass, options = null) {
167
+ if (isPlaceholderExp) {
168
+ // 是占位的元数据表达式,那么先临时记录到placeholderDecoratorOptions中,后续知道占位元数据类和真正的元数据类的映射关系后再保存到metadataDecoratorOptions中
169
+ placeholderDecoratorOptions.set(metadataClass, options);
170
+ } else {
171
+ // 不是占位的元数据表达式,那么直接保存在metadataDecoratorOptions中
172
+ metadataDecoratorOptions.set(metadataClass, options);
173
+ }
264
174
  }
265
- function _setFunctionName(e, t, n) {
266
- "symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : "");
267
- try {
268
- Object.defineProperty(e, "name", {
269
- configurable: !0,
270
- value: n ? n + " " + t : t
271
- });
272
- }
273
- catch (e) { }
274
- return e;
175
+ // 记录占位的元数据类和真实的元数据类之间的映射
176
+ function addPlaceholderClassToRealMetadataClassRelation(placeholderClass, realMetadataClass) {
177
+ placeholderClassMap2RealMetadataClass.set(placeholderClass, realMetadataClass);
275
178
  }
276
- function _toPrimitive(t, r) {
277
- if ("object" != typeof t || !t)
278
- return t;
279
- var e = t[Symbol.toPrimitive];
280
- if (void 0 !== e) {
281
- var i = e.call(t, r);
282
- if ("object" != typeof i)
283
- return i;
284
- throw new TypeError("@@toPrimitive must return a primitive value.");
179
+ function mergePlaceholderClass2RealMetadataClassRelation() {
180
+ for (const [placeholderClass, decoratorOptions] of placeholderDecoratorOptions.entries()) {
181
+ const realMetadataClass = placeholderClassMap2RealMetadataClass.get(placeholderClass);
182
+ if (realMetadataClass) {
183
+ addCreateDecoratorOption(false, realMetadataClass, decoratorOptions);
285
184
  }
286
- return ("string" === r ? String : Number)(t);
185
+ }
287
186
  }
288
- function _toPropertyKey(t) {
289
- var i = _toPrimitive(t, "string");
290
- return "symbol" == typeof i ? i : i + "";
187
+ function getPlaceholderClassMap2RealMetadataClass() {
188
+ return placeholderClassMap2RealMetadataClass;
189
+ }
190
+ function getCreateDecoratorOption(metadataClass) {
191
+ return metadataDecoratorOptions.get(metadataClass);
192
+ }
193
+ function clear$1() {
194
+ metadataDecoratorOptions.clear();
195
+ placeholderDecoratorOptions.clear();
291
196
  }
292
-
293
- const KindClass = 'class';
294
- const KindField = 'field';
295
- const KindMethod = 'method';
296
- const KindGetter = 'getter';
297
- const KindSetter = 'setter';
298
- const KindAccessor = 'accessor';
299
197
 
300
198
  // TODO: 错误码按照类型划分不同的段位
301
199
  var DiagnoseCode;
@@ -343,15 +241,15 @@ const DiagnoseCodeMsg = {
343
241
  [DiagnoseCode.CO10010]: `实例化组件失败,%s 类存在多个子类 %s,@qualifier装饰器指定了一个不存在的子类id: %s`,
344
242
  [DiagnoseCode.CO10011]: `实例化组件失败,%s 类不是ioc组件`,
345
243
  [DiagnoseCode.CO10012]: `%s 类 %s 字段不能使用autowired注入自身,字段置为undefined`,
346
- [DiagnoseCode.CO10013]: `实例化组件失败,%s 类的构造函数的依赖 %s 类也没有完全初始化,可能是循环依赖了?`,
244
+ [DiagnoseCode.CO10013]: `实例化组件失败,存在循环依赖: %s`,
347
245
  [DiagnoseCode.CO10014]: `元数据类 %s 创建了不止一个装饰器,每个元数据类只能创建一个对应的装饰器。`,
348
246
  [DiagnoseCode.CO10015]: `元数据类 %s 本身存在id属性,且不能被修改。`,
349
247
  [DiagnoseCode.CO10016]: `元数据类 %s 没有id属性或者id属性不是字符串,忘记调用assignMetadataId方法?`,
350
248
  [DiagnoseCode.CO10017]: `元数据类 %s 和 %s 的id属性相同,id属性不能重复。`,
351
249
  [DiagnoseCode.CO10018]: `createDecoratorExp的第一个参数 %s 必须是Metadata的子类。`,
352
250
  [DiagnoseCode.CO10019]: `框架暂不支持为 %s 添加装饰器。`,
353
- [DiagnoseCode.CO10020]: `有一个占位装饰器没有使用decorateSelf关联具体的元数据类,如果不使用的话,直接删除这个装饰器。`,
354
- [DiagnoseCode.CO10021]: `%s 类存在一个占位装饰器,但是没有使用decorateSelf装饰器关联真正的元数据类。`,
251
+ [DiagnoseCode.CO10020]: `有一个占位装饰器没有使用metadataFor关联具体的元数据类,如果不使用的话,直接删除这个装饰器。`,
252
+ [DiagnoseCode.CO10021]: `%s 类存在一个占位装饰器,但是没有使用metadataFor装饰器关联真正的元数据类。`,
355
253
  [DiagnoseCode.CO10022]: `元数据类 %s 只能有 KindClass 类型的装饰器,字段 %s 上的装饰器是无效的,请删除。`,
356
254
  [DiagnoseCode.CO10023]: `元数据类 %s 只能有 KindClass 类型的装饰器,方法 %s 上的装饰器是无效的,请删除。`,
357
255
  [DiagnoseCode.CO10024]: `元数据类 %s 存在多个组件装饰器 %s,一个元数据类最多只能有一个组件装饰器。`,
@@ -415,113 +313,12 @@ function reactiveAssignField(reactiveField) {
415
313
  return `${reactiveField}Setter`;
416
314
  }
417
315
 
418
- const decoratorParamMap = new Map();
419
- // 占位的元数据类 <--> 被装饰的类
420
- const placeholderMataClassMap2BeDecoratedClass = new Map();
421
- /**
422
- * 保存装饰器参数
423
- * @param isPlaceholderMetaClass 是否是占位的元数据类
424
- * @param beDecoratedCls 被装饰的类
425
- * @param params
426
- */
427
- function addDecoratorParams(isPlaceholderMetaClass, beDecoratedCls, params) {
428
- if (!isClass(beDecoratedCls)) {
429
- return;
430
- }
431
- if (!decoratorParamMap.has(beDecoratedCls)) {
432
- decoratorParamMap.set(beDecoratedCls, []);
433
- }
434
- const paramsList = decoratorParamMap.get(beDecoratedCls);
435
- paramsList.push(params);
436
- if (isPlaceholderMetaClass) {
437
- const beDecoratedClassList = placeholderMataClassMap2BeDecoratedClass.get(params.metadataClass);
438
- if (beDecoratedClassList) {
439
- beDecoratedClassList.push(beDecoratedCls);
440
- } else {
441
- placeholderMataClassMap2BeDecoratedClass.set(params.metadataClass, [beDecoratedCls]);
442
- }
443
- }
444
- }
445
- // 收集到的装饰器参数,其中部分装饰器对应的类是*占位*元数据类,那么替换成真实的元数据类
446
- function replacePlaceholderMetaClassParams2RealMetadataClassParams({
447
- placeholderClassMap2RealMetadataClass,
448
- notCalledDecorateSelfPlaceholderClassList
449
- }) {
450
- for (const [placeholderMetaClass, beDecoratedClassList] of placeholderMataClassMap2BeDecoratedClass.entries()) {
451
- const realMetadataClass = placeholderClassMap2RealMetadataClass.get(placeholderMetaClass);
452
- for (const beDecoratedClass of beDecoratedClassList) {
453
- if (!realMetadataClass) {
454
- throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10021, beDecoratedClass.name)));
455
- }
456
- const paramsList = decoratorParamMap.get(beDecoratedClass);
457
- for (const p of paramsList) {
458
- if (p.metadataClass === placeholderMetaClass) {
459
- p.metadataClass = realMetadataClass;
460
- }
461
- }
462
- }
463
- }
464
- // 所有没有执行的decorateSelf函数的占位的装饰器表达式,如果也没有被使用,那么打印警告信息
465
- for (const placeholderMetaClass of notCalledDecorateSelfPlaceholderClassList) {
466
- }
467
- }
468
- function getDecoratorParam() {
469
- return decoratorParamMap;
470
- }
471
- function clear$2() {
472
- decoratorParamMap.clear();
473
- }
474
-
475
- // 元数据类 <--> 装饰器选项
476
- const metadataDecoratorOptions = new Map();
477
- // 占位的元数据类 <--> 装饰器选项
478
- const placeholderDecoratorOptions = new Map();
479
- // 占位的元数据类 <--> 真实的元数据类
480
- const placeholderClassMap2RealMetadataClass = new Map();
481
- // 没有调用decorateSelf函数的占位的元数据类
482
- const notCalledDecorateSelfPlaceholderClassList = [];
483
- // 记录创建装饰器表达式的选项
484
- function addCreateDecoratorOption(isPlaceholderExp, metadataClass, options = null) {
485
- if (isPlaceholderExp) {
486
- // 是占位的元数据表达式,那么先临时记录到placeholderDecoratorOptions中,后续知道占位元数据类和真正的元数据类的映射关系后再保存到metadataDecoratorOptions中
487
- placeholderDecoratorOptions.set(metadataClass, options);
488
- } else {
489
- // 不是占位的元数据表达式,那么直接保存在metadataDecoratorOptions中
490
- metadataDecoratorOptions.set(metadataClass, options);
491
- }
316
+ const createdDecoratorSetKey = Symbol.for('coco.createdDecoratorMetadataSet');
317
+ const globalObject = globalThis;
318
+ if (!globalObject[createdDecoratorSetKey]) {
319
+ globalObject[createdDecoratorSetKey] = new Set();
492
320
  }
493
- // 记录占位的元数据类和真实的元数据类之间的映射
494
- function addPlaceholderClassToRealMetadataClassRelation(placeholderClass, realMetadataClass) {
495
- placeholderClassMap2RealMetadataClass.set(placeholderClass, realMetadataClass);
496
- }
497
- // 添加占位的装饰器表达式的参数
498
- function mergePlaceholderClass2RealMetadataClassRelation() {
499
- for (const [placeholderClass, decoratorOptions] of placeholderDecoratorOptions.entries()) {
500
- const realMetadataClass = placeholderClassMap2RealMetadataClass.get(placeholderClass);
501
- if (realMetadataClass) {
502
- addCreateDecoratorOption(false, realMetadataClass, decoratorOptions);
503
- } else {
504
- notCalledDecorateSelfPlaceholderClassList.push(placeholderClass);
505
- }
506
- }
507
- }
508
- function getCreateDecoratorOption(metadataClass) {
509
- return metadataDecoratorOptions.get(metadataClass);
510
- }
511
- function getPlaceholderClassMap2RealMetadataClass() {
512
- return {
513
- placeholderClassMap2RealMetadataClass,
514
- notCalledDecorateSelfPlaceholderClassList
515
- };
516
- }
517
- function clear$1() {
518
- metadataDecoratorOptions.clear();
519
- placeholderDecoratorOptions.clear();
520
- placeholderClassMap2RealMetadataClass.clear();
521
- notCalledDecorateSelfPlaceholderClassList.length = 0;
522
- }
523
-
524
- let createdDecoratorMetadataSet = new Set();
321
+ const createdDecoratorMetadataSet = globalObject[createdDecoratorSetKey];
525
322
  function checkIfMetadataCreateMoreThenOneDecorator(metadataClass) {
526
323
  if (!createdDecoratorMetadataSet.has(metadataClass)) {
527
324
  createdDecoratorMetadataSet.add(metadataClass);
@@ -529,184 +326,143 @@ function checkIfMetadataCreateMoreThenOneDecorator(metadataClass) {
529
326
  throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10014, metadataClass.name)));
530
327
  }
531
328
  }
532
- function createDecoratorExpFactory(fn) {
329
+ function createDecoratorExpFactory() {
533
330
  return function (isPlaceholderExp, metadataClass, option) {
534
- const MetaClsOrPlaceholderMetaCls = metadataClass;
535
- addCreateDecoratorOption(isPlaceholderExp, MetaClsOrPlaceholderMetaCls, option);
331
+ addCreateDecoratorOption(isPlaceholderExp, metadataClass, option);
332
+ // TODO: 这里只校验直接创建装饰器的元数据类,可能遗漏占位装饰器绑定的元数据类;
333
+ // 应改为在计算出所有运行时装饰器表达式及其元数据类之后统一校验。
536
334
  if (!isPlaceholderExp) {
537
- checkIfMetadataCreateMoreThenOneDecorator(MetaClsOrPlaceholderMetaCls);
538
- }
539
- const placeholderDecoratorModifyPrototype = new Map();
540
- function decorateSelf(userParam) {
541
- return function (beDecoratedCls, context) {
542
- switch (context.kind) {
543
- case KindClass:
544
- {
545
- if (isPlaceholderExp) {
546
- addPlaceholderClassToRealMetadataClassRelation(MetaClsOrPlaceholderMetaCls, beDecoratedCls);
547
- checkIfMetadataCreateMoreThenOneDecorator(beDecoratedCls);
548
- } else {
549
- throw new Error('decorateSelf函数只能调用一次');
550
- }
551
- fn(isPlaceholderExp, beDecoratedCls, {
552
- metadataKind: KindClass,
553
- metadataClass: MetaClsOrPlaceholderMetaCls,
554
- metadataParam: userParam
555
- });
556
- const config = placeholderDecoratorModifyPrototype.get(MetaClsOrPlaceholderMetaCls);
557
- if (typeof beDecoratedCls?.classDecoratorModifyPrototype === 'function') {
558
- // 直接flush掉待修改的类,然后设置成修改函数即可。
559
- if (config && config.toUpdateClassSet.size) {
560
- for (const cls of Array.from(config.toUpdateClassSet)) {
561
- beDecoratedCls?.classDecoratorModifyPrototype(cls.prototype);
562
- }
563
- }
564
- placeholderDecoratorModifyPrototype.set(MetaClsOrPlaceholderMetaCls, {
565
- classDecoratorModifyPrototype: beDecoratedCls.classDecoratorModifyPrototype
566
- });
567
- } else {
568
- placeholderDecoratorModifyPrototype.set(MetaClsOrPlaceholderMetaCls, {
569
- classDecoratorModifyPrototype: null
570
- });
571
- }
572
- break;
573
- }
574
- default:
575
- throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10019, context.kind)));
576
- }
577
- return undefined;
578
- };
335
+ checkIfMetadataCreateMoreThenOneDecorator(metadataClass);
579
336
  }
580
337
  function doCreateDecoratorExp(userParam) {
581
- return function (beDecoratedCls, context) {
582
- switch (context.kind) {
583
- case KindClass:
584
- {
585
- fn(isPlaceholderExp, beDecoratedCls, {
586
- metadataKind: KindClass,
587
- metadataClass: MetaClsOrPlaceholderMetaCls,
588
- metadataParam: userParam
589
- });
590
- // 修改prototype
591
- if (isPlaceholderExp) {
592
- const config = placeholderDecoratorModifyPrototype.get(MetaClsOrPlaceholderMetaCls);
593
- if (!config) {
594
- // 第一次遇到,先收集
595
- const toUpdateClassSet = new Set();
596
- toUpdateClassSet.add(beDecoratedCls);
597
- placeholderDecoratorModifyPrototype.set(MetaClsOrPlaceholderMetaCls, {
598
- toUpdateClassSet
599
- });
600
- } else {
601
- if (config.classDecoratorModifyPrototype) {
602
- // 已经装饰过自己了,直接修改
603
- config.classDecoratorModifyPrototype(beDecoratedCls.prototype);
604
- } else {
605
- if (config.classDecoratorModifyPrototype === undefined) {
606
- // 又装饰器其他类,同样收集
607
- config.toUpdateClassSet.add(beDecoratedCls);
608
- } else if (config.classDecoratorModifyPrototype === null) {
609
- // 不需要更新了,清空即可
610
- config.toUpdateClassSet?.clear();
611
- }
612
- }
613
- }
614
- } else {
615
- // 不是占位装饰器,直接修改被装饰类的原型链
616
- if (typeof MetaClsOrPlaceholderMetaCls?.classDecoratorModifyPrototype === 'function') {
617
- MetaClsOrPlaceholderMetaCls?.classDecoratorModifyPrototype(beDecoratedCls.prototype);
618
- }
619
- }
620
- break;
621
- }
622
- case KindMethod:
623
- case KindField:
624
- break;
625
- case KindGetter:
626
- case KindSetter:
627
- case KindAccessor:
628
- default:
629
- throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10019, context.kind)));
630
- }
631
- const execOnce = once(function initializer() {
632
- switch (context.kind) {
633
- case KindField:
634
- case KindMethod:
635
- fn(isPlaceholderExp, this.constructor, {
636
- metadataKind: context.kind,
637
- metadataClass: MetaClsOrPlaceholderMetaCls,
638
- metadataParam: userParam,
639
- field: context.name
640
- });
641
- break;
642
- }
643
- });
644
- context.addInitializer(function () {
645
- execOnce(this);
646
- });
647
- return undefined;
338
+ return function (_beDecoratedCls, _context) {
339
+ // 普通装饰器表达式正常应由 AOT 编译期转换为 registerComponent 注册代码,
340
+ // 运行到这里说明代码未经 @cocojs/compiler 编译。
341
+ throw new Error('装饰器不应在运行时执行,请先使用 @cocojs/compiler 编译后再运行。');
648
342
  };
649
343
  }
650
344
  if (isPlaceholderExp) {
651
- doCreateDecoratorExp.decorateSelf = decorateSelf;
345
+ const placeholderExp = doCreateDecoratorExp;
346
+ placeholderExp.$$metadataClass = metadataClass;
347
+ placeholderExp.$$isPlaceholderDecoratorExp = true;
348
+ placeholderExp.$$placeholderMetadataClass = metadataClass;
349
+ return placeholderExp;
350
+ } else {
351
+ const decoratorExp = doCreateDecoratorExp;
352
+ decoratorExp.$$metadataClass = metadataClass;
353
+ decoratorExp.$$isPlaceholderDecoratorExp = false;
354
+ return decoratorExp;
652
355
  }
653
- return doCreateDecoratorExp;
654
356
  };
655
357
  }
656
- const doCreateDecoratorExp = createDecoratorExpFactory(addDecoratorParams);
358
+ const doCreateDecoratorExp = createDecoratorExpFactory();
359
+ function createDecoratorExp(metadataClsOrOption, option) {
360
+ if (typeof metadataClsOrOption === 'function') {
361
+ const metadataCls = metadataClsOrOption;
362
+ if (!isSubClassOf(metadataCls, Metadata)) {
363
+ throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10018, metadataCls?.name)));
364
+ }
365
+ return doCreateDecoratorExp(false, metadataCls, option);
366
+ } else {
367
+ if (metadataClsOrOption !== undefined && !isPlainObject(metadataClsOrOption)) {
368
+ throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10018, metadataClsOrOption?.name)));
369
+ }
370
+ // 先提供一个默认的元数据类,再通过 @metadataFor(X) 替换为真实的元数据类
371
+ class PlaceholderMetadata extends Metadata {}
372
+ return doCreateDecoratorExp(true, PlaceholderMetadata, metadataClsOrOption);
373
+ }
374
+ }
657
375
  /**
658
- * 使用元数据类创建一个装饰器函数
659
- * 适用于装饰器不装饰自己元数据类的场景
376
+ * 建立占位元数据类与真实元数据类的关联。
377
+ * 由 `@metadataFor(X)` 经 AOT 编译后调用。
660
378
  * @public
661
379
  */
662
- function createDecoratorExp(metadataCls, option) {
663
- if (!isSubClassOf(metadataCls, Metadata)) {
664
- throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10018, metadataCls?.name)));
380
+ function bindPlaceholderMetadataClass(decoratorExp, metadataClass) {
381
+ addPlaceholderClassToRealMetadataClassRelation(decoratorExp.$$placeholderMetadataClass, metadataClass);
382
+ checkIfMetadataCreateMoreThenOneDecorator(metadataClass);
383
+ }
384
+
385
+ /**
386
+ * 注册表挂在 globalThis 上,保证同一个应用里多次加载运行时模块(例如 Jest 的 resetModules)
387
+ * 时注册方和 Application 读取到同一份数据。
388
+ * 每次调用时读取,避免框架 bundle 中生成的 registerComponent 调用先于模块级变量初始化执行。
389
+ */
390
+ function getGlobalRegistry() {
391
+ const registryKey = Symbol.for('coco.decoratorRegistry');
392
+ const globalObject = globalThis;
393
+ if (!globalObject[registryKey]) {
394
+ globalObject[registryKey] = new Map();
665
395
  }
666
- return doCreateDecoratorExp(false, metadataCls, option);
396
+ return globalObject[registryKey];
667
397
  }
668
398
  /**
669
- * 创建一个未绑定元数据的装饰器表达式
670
- * 需要在正式的元数据类上添加decorateSelf装饰器来关联真实的元数据类,装饰器到其他类的使用方式和createDecoratorExp是一致的。
671
- * 适用于装饰器装饰自己元数据类的场景
399
+ * 全局静态注册函数。编译期由 coco-compiler 注入到每个源文件末尾。
400
+ * 源码中类、字段、方法、getter 上的装饰器经 AOT 编译后统一转换为对它的调用,
401
+ * 用于保存原始装饰器参数。
402
+ * `@metadataFor(X)` 不产生注册参数,只额外生成 bindPlaceholderMetadataClass 调用。
672
403
  * @public
673
404
  */
674
- function createPlaceholderDecoratorExp(option) {
675
- // 先提供一个默认的元数据类,再替换为真实的元数据类
676
- class PlaceholderMetadata extends Metadata {}
677
- return doCreateDecoratorExp(true, PlaceholderMetadata, option);
405
+ function registerComponent(cls, params) {
406
+ getGlobalRegistry().set(cls, params);
407
+ }
408
+ /** 读取userDecoratorParams */
409
+ function getRegistry() {
410
+ return getGlobalRegistry();
411
+ }
412
+
413
+ function createRuntimeDecoratorParams(userDecoratorParams) {
414
+ const runtimeDecoratorParams = new Map();
415
+ const placeholderClassMap2RealMetadataClass = getPlaceholderClassMap2RealMetadataClass();
416
+ // 基于userDecoratorParams生成runtimeDecoratorParams,并将其中的占位元数据类替换为真实元数据类
417
+ for (const [cls, params] of userDecoratorParams) {
418
+ runtimeDecoratorParams.set(cls, params.map(p => {
419
+ if (p.isPlaceholderDecoratorExp) {
420
+ const realClass = placeholderClassMap2RealMetadataClass.get(p.metadataClass);
421
+ if (!realClass) {
422
+ throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10021, cls.name)));
423
+ }
424
+ return {
425
+ metadataKind: p.metadataKind,
426
+ metadataClass: realClass,
427
+ metadataParam: p.metadataParam,
428
+ field: p.field
429
+ };
430
+ }
431
+ return {
432
+ metadataKind: p.metadataKind,
433
+ metadataClass: p.metadataClass,
434
+ metadataParam: p.metadataParam,
435
+ field: p.field
436
+ };
437
+ }));
438
+ }
439
+ for (const [beDecoratedCls, params] of runtimeDecoratorParams.entries()) {
440
+ for (const p of params) {
441
+ if (!p.metadataClass) {
442
+ throw new Error(`组件 ${beDecoratedCls?.name} 的装饰器没有对应的元数据类,请确认装饰器由 createDecoratorExp 创建。`);
443
+ }
444
+ }
445
+ if (!isCocoClass(beDecoratedCls)) {
446
+ throw new Error(`所有被装饰器的对象${beDecoratedCls?.name}必须都是类或者类字段或类方法,且必须存在静态$$id字段。`);
447
+ }
448
+ }
449
+ return runtimeDecoratorParams;
678
450
  }
679
451
 
680
452
  /**
681
453
  * 装饰器表达式模块的工作流
682
454
  */
683
455
  function initDecoratorParamModule() {
684
- // 收集field和method装饰器参数
685
- for (const Cls of getDecoratorParam().keys()) {
686
- /**
687
- * TODO: 如果view组件的state需要用到props初始化的话,会导致报错,例如:
688
- * class {
689
- * constructor(props){
690
- * this.name = props.name // 这里会报错
691
- * }
692
- * }
693
- */
694
- new Cls();
695
- }
696
- // 创建的装饰器表达式的选项,将占位的元数据类替换成真实的元数据类
456
+ // start 时把userDecoratorParams解析为runtimeDecoratorParams并校验,覆盖 Application 构造后声明的局部类。
457
+ const userDecoratorParams = getRegistry();
697
458
  mergePlaceholderClass2RealMetadataClassRelation();
698
- // 收集到的所有的装饰器参数,占位的元数据类替换成真实的元数据类
699
- replacePlaceholderMetaClassParams2RealMetadataClassParams(getPlaceholderClassMap2RealMetadataClass());
700
- // 所有的被装饰类都要符合一定的要求
701
- for (const beDecoratedClass of getDecoratorParam().keys()) {
702
- if (!isCocoClass(beDecoratedClass)) {
703
- throw new Error(`所有被装饰器的对象${beDecoratedClass?.name}必须都是类或者类字段或类方法,且必须存在静态$$id字段。`);
704
- }
705
- }
459
+ const runtimeDecoratorParams = createRuntimeDecoratorParams(userDecoratorParams);
460
+ // 注册表的职责是“待启动消费的注册信息”,解析完成后清空,避免重复消费上一次的注册
461
+ userDecoratorParams.clear();
462
+ return runtimeDecoratorParams;
706
463
  }
707
464
  function clearDecoratorParamModule() {
708
465
  clear$1();
709
- clear$2();
710
466
  }
711
467
 
712
468
  /**
@@ -717,72 +473,59 @@ var Type;
717
473
  Type[Type["Class"] = KindClass] = "Class";
718
474
  Type[Type["Field"] = KindField] = "Field";
719
475
  Type[Type["Method"] = KindMethod] = "Method";
476
+ Type[Type["Getter"] = KindGetter] = "Getter";
720
477
  })(Type || (Type = {}));
721
478
  /**
722
479
  * @public
723
480
  */
724
- const target = createPlaceholderDecoratorExp();
481
+ const target = createDecoratorExp();
725
482
 
726
- let _initClass$z;
727
483
  /**
728
484
  * @public
729
485
  */
730
- let _Target;
731
- new class extends _identity {
732
- static [class Target extends Metadata {
733
- static {
734
- [_Target, _initClass$z] = _applyDecs2311(this, [target.decorateSelf([Type.Class])], [], 0, void 0, Metadata).c;
735
- }
736
- value;
737
- }];
738
- $$id = "Target";
739
- Type = Type;
740
- constructor() {
741
- super(_Target), _initClass$z();
742
- }
743
- }();
744
- var Target = _Target;
745
-
746
- let _initClass$y;
486
+ class Target extends Metadata {
487
+ static $$id = "Target";
488
+ static Type = Type;
489
+ value;
490
+ }
491
+ bindPlaceholderMetadataClass(target, Target);
492
+ registerComponent(Target, [{
493
+ metadataKind: "class",
494
+ metadataClass: target.$$metadataClass,
495
+ metadataParam: [Type.Class],
496
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
497
+ }]);
498
+
747
499
  /**
748
500
  * @public
749
501
  */
750
- let _Autowired;
751
- new class extends _identity {
752
- static [class Autowired extends Metadata {
753
- static {
754
- [_Autowired, _initClass$y] = _applyDecs2311(this, [target([Target.Type.Field])], [], 0, void 0, Metadata).c;
755
- }
756
- value;
757
- }];
758
- $$id = "Autowired";
759
- constructor() {
760
- super(_Autowired), _initClass$y();
761
- }
762
- }();
763
- var Autowired = _Autowired;
502
+ class Autowired extends Metadata {
503
+ static $$id = "Autowired";
504
+ value;
505
+ }
506
+ registerComponent(Autowired, [{
507
+ metadataKind: "class",
508
+ metadataClass: target.$$metadataClass,
509
+ metadataParam: [Target.Type.Field],
510
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
511
+ }]);
764
512
 
765
513
  // TODO: cls?: Class<any>如果去掉的话,在项目中会报错,应该是ts-server是拿到参数了,但是声明中确没有
766
514
  var autowired = createDecoratorExp(Autowired);
767
515
 
768
- let _initClass$x;
769
516
  /**
770
517
  * @public
771
518
  */
772
- let _Id;
773
- new class extends _identity {
774
- static [class Id extends Metadata {
775
- static {
776
- [_Id, _initClass$x] = _applyDecs2311(this, [target([Target.Type.Method])], [], 0, void 0, Metadata).c;
777
- }
778
- value;
779
- }];
780
- $$id = "Id";
781
- constructor() {
782
- super(_Id), _initClass$x();
783
- }
784
- }();
785
- var Id = _Id;
519
+ class Id extends Metadata {
520
+ static $$id = "Id";
521
+ value;
522
+ }
523
+ registerComponent(Id, [{
524
+ metadataKind: "class",
525
+ metadataClass: target.$$metadataClass,
526
+ metadataParam: [Target.Type.Method],
527
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
528
+ }]);
786
529
 
787
530
  /**
788
531
  * @id装饰器
@@ -790,7 +533,6 @@ var Id = _Id;
790
533
  */
791
534
  var id = createDecoratorExp(Id);
792
535
 
793
- let _initClass$w;
794
536
  /**
795
537
  * Component不添加@scope(SCOPE.Singleton)的原因:
796
538
  * 因为不设置默认就是singleton,还可以避免 scope <-> target 循环依赖的问题
@@ -798,20 +540,16 @@ let _initClass$w;
798
540
  /**
799
541
  * @public
800
542
  */
801
- let _Component;
802
- new class extends _identity {
803
- static [class Component extends Metadata {
804
- static {
805
- [_Component, _initClass$w] = _applyDecs2311(this, [target([Target.Type.Class, Target.Type.Method])], [], 0, void 0, Metadata).c;
806
- }
807
- value;
808
- }];
809
- $$id = "Component";
810
- constructor() {
811
- super(_Component), _initClass$w();
812
- }
813
- }();
814
- var Component = _Component;
543
+ class Component extends Metadata {
544
+ static $$id = "Component";
545
+ value;
546
+ }
547
+ registerComponent(Component, [{
548
+ metadataKind: "class",
549
+ metadataClass: target.$$metadataClass,
550
+ metadataParam: [Target.Type.Class, Target.Type.Method],
551
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
552
+ }]);
815
553
 
816
554
  /**
817
555
  * ioc组件,只有ioc组件才能实例化
@@ -819,48 +557,37 @@ var Component = _Component;
819
557
  */
820
558
  var component = createDecoratorExp(Component);
821
559
 
822
- let _initClass$v;
823
560
  /**
824
561
  * @public
825
562
  */
826
- let _Configuration;
827
- new class extends _identity {
828
- static [class Configuration extends Metadata {
829
- static {
830
- [_Configuration, _initClass$v] = _applyDecs2311(this, [target([Target.Type.Class])], [], 0, void 0, Metadata).c;
831
- }
832
- }];
833
- $$id = "Configuration";
834
- constructor() {
835
- super(_Configuration), _initClass$v();
836
- }
837
- }();
838
- var Configuration = _Configuration;
563
+ class Configuration extends Metadata {
564
+ static $$id = "Configuration";
565
+ }
566
+ registerComponent(Configuration, [{
567
+ metadataKind: "class",
568
+ metadataClass: target.$$metadataClass,
569
+ metadataParam: [Target.Type.Class],
570
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
571
+ }]);
839
572
 
840
573
  var configuration = createDecoratorExp(Configuration);
841
574
 
842
- let _initClass$u;
843
575
  /**
844
576
  * @public
845
577
  */
846
- let _ConstructorInject;
847
- new class extends _identity {
848
- static [class ConstructorInject extends Metadata {
849
- static {
850
- [_ConstructorInject, _initClass$u] = _applyDecs2311(this, [target([Target.Type.Class])], [], 0, void 0, Metadata).c;
851
- }
852
- value;
853
- }];
854
- $$id = "ConstructorInject";
855
- constructor() {
856
- super(_ConstructorInject), _initClass$u();
857
- }
858
- }();
859
- var ConstructorInject = _ConstructorInject;
578
+ class ConstructorInject extends Metadata {
579
+ static $$id = "ConstructorInject";
580
+ value;
581
+ }
582
+ registerComponent(ConstructorInject, [{
583
+ metadataKind: "class",
584
+ metadataClass: target.$$metadataClass,
585
+ metadataParam: [Target.Type.Class],
586
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
587
+ }]);
860
588
 
861
589
  var constructorInject = createDecoratorExp(ConstructorInject);
862
590
 
863
- let _initClass$t;
864
591
  /**
865
592
  * @public
866
593
  */
@@ -874,62 +601,48 @@ exports.SCOPE = void 0;
874
601
  /**
875
602
  * @public
876
603
  */
877
- let _Scope;
878
- new class extends _identity {
879
- static [class Scope extends Metadata {
880
- static {
881
- [_Scope, _initClass$t] = _applyDecs2311(this, [target([Target.Type.Class, Target.Type.Method])], [], 0, void 0, Metadata).c;
882
- }
883
- value = exports.SCOPE.Singleton;
884
- }];
885
- $$id = "Scope";
886
- constructor() {
887
- super(_Scope), _initClass$t();
888
- }
889
- }();
890
- var Scope = _Scope;
604
+ class Scope extends Metadata {
605
+ static $$id = "Scope";
606
+ value = exports.SCOPE.Singleton;
607
+ }
608
+ registerComponent(Scope, [{
609
+ metadataKind: "class",
610
+ metadataClass: target.$$metadataClass,
611
+ metadataParam: [Target.Type.Class, Target.Type.Method],
612
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
613
+ }]);
891
614
 
892
615
  var scope = createDecoratorExp(Scope);
893
616
 
894
- let _initClass$s;
895
617
  /**
896
618
  * @public
897
619
  */
898
- let _Qualifier;
899
- new class extends _identity {
900
- static [class Qualifier extends Metadata {
901
- static {
902
- [_Qualifier, _initClass$s] = _applyDecs2311(this, [target([Target.Type.Field])], [], 0, void 0, Metadata).c;
903
- }
904
- value;
905
- }];
906
- $$id = "Qualifier";
907
- constructor() {
908
- super(_Qualifier), _initClass$s();
909
- }
910
- }();
911
- var Qualifier = _Qualifier;
620
+ class Qualifier extends Metadata {
621
+ static $$id = "Qualifier";
622
+ value;
623
+ }
624
+ registerComponent(Qualifier, [{
625
+ metadataKind: "class",
626
+ metadataClass: target.$$metadataClass,
627
+ metadataParam: [Target.Type.Field],
628
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
629
+ }]);
912
630
 
913
631
  var qualifier = createDecoratorExp(Qualifier);
914
632
 
915
- let _initClass$r;
916
633
  /**
917
634
  * @public
918
635
  */
919
- let _Value;
920
- new class extends _identity {
921
- static [class Value extends Metadata {
922
- static {
923
- [_Value, _initClass$r] = _applyDecs2311(this, [target([Target.Type.Field])], [], 0, void 0, Metadata).c;
924
- }
925
- value;
926
- }];
927
- $$id = "Value";
928
- constructor() {
929
- super(_Value), _initClass$r();
930
- }
931
- }();
932
- var Value = _Value;
636
+ class Value extends Metadata {
637
+ static $$id = "Value";
638
+ value;
639
+ }
640
+ registerComponent(Value, [{
641
+ metadataKind: "class",
642
+ metadataClass: target.$$metadataClass,
643
+ metadataParam: [Target.Type.Field],
644
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
645
+ }]);
933
646
 
934
647
  var value = createDecoratorExp(Value, {
935
648
  componentPostConstruct: function (metadata, application, target) {
@@ -971,6 +684,9 @@ class MetadataRepository {
971
684
  case KindMethod:
972
685
  this.addMethodKindMetadata(beDecoratedCls, field, metadataClass, metadataParam);
973
686
  break;
687
+ case KindGetter:
688
+ this.addGetterKindMetadata(beDecoratedCls, field, metadataClass, metadataParam);
689
+ break;
974
690
  }
975
691
  }
976
692
  }
@@ -994,7 +710,8 @@ class MetadataRepository {
994
710
  config = {
995
711
  classMetadata: [],
996
712
  fieldMetadata: new Map(),
997
- methodMetadata: new Map()
713
+ methodMetadata: new Map(),
714
+ getterMetadata: new Map()
998
715
  };
999
716
  map.set(cls, config);
1000
717
  }
@@ -1044,6 +761,22 @@ class MetadataRepository {
1044
761
  const metadata = instantiateMetadata(MetadataCls, args);
1045
762
  methodMetas.push(metadata);
1046
763
  }
764
+ addGetterKindMetadata(Cls, fieldName, MetadataCls, args) {
765
+ let config = this.getMetadataByClass(Cls);
766
+ if (!config) {
767
+ config = this.addToMap(Cls);
768
+ }
769
+ const {
770
+ getterMetadata
771
+ } = config;
772
+ let methodMetas = getterMetadata.get(fieldName);
773
+ if (!methodMetas) {
774
+ methodMetas = [];
775
+ getterMetadata.set(fieldName, methodMetas);
776
+ }
777
+ const metadata = instantiateMetadata(MetadataCls, args);
778
+ methodMetas.push(metadata);
779
+ }
1047
780
  /**
1048
781
  * 获取指定类的类类型的元数据
1049
782
  * @param beDecoratedCls 指定类
@@ -1208,7 +941,7 @@ class ComponentMetadataClass {
1208
941
  // 遍历所有被装饰器的元数据类,将自己添加为被装饰器类的组件装饰器
1209
942
  const beDecoratedClasses = decorateTree.get(current) || new Set();
1210
943
  for (const beDecoratedClass of beDecoratedClasses) {
1211
- // 忽略自己装饰自己的情况(decorateSelf),因为这不算是组件装饰器
944
+ // 忽略自己装饰自己的情况(bind),因为这不算是组件装饰器
1212
945
  if (beDecoratedClass === current) {
1213
946
  // 避免自引用导致的无限循环
1214
947
  if (!visited.has(beDecoratedClass)) {
@@ -1408,137 +1141,6 @@ class ComponentMetadataClass {
1408
1141
  }
1409
1142
  }
1410
1143
 
1411
- /**
1412
- * component
1413
- * 1. 只能用在class或者method上,且只能装饰一次
1414
- * 2. 不能和其他component复合装饰器同时使用
1415
- */
1416
- /**
1417
- * view
1418
- * 1. 只能用在class,且只能装饰一次
1419
- * 2. 不能和其他component复合装饰器同时使用
1420
- */
1421
- /**
1422
- * page
1423
- * 1. 只能用在class,且只能装饰一次
1424
- * 2. 不能和其他component复合装饰器同时使用
1425
- */
1426
- /**
1427
- * layout
1428
- * 1. 只能用在class,且只能使用一次
1429
- * 2. 不能和其他component复合装饰器同时使用
1430
- */
1431
- /**
1432
- * qualifier
1433
- * 1. 只能用在field上,且只能装饰一次
1434
- * 2. 依赖component配合使用
1435
- */
1436
- /**
1437
- * autowired
1438
- * 1. 只能用在field上,且只能装饰一次
1439
- * 2. TODO: 只能在view及其复合装饰器组件内部、controller及其复合装饰器组件内部、api装饰器组件内部
1440
- * 3. 自动注入收到分层概念的约束,具体如下:
1441
- * 3.1 view及其复合装饰器内部:controller及其复合装饰器组件, global-data, store, route, router,util及其复合装饰器组件
1442
- * 3.2 controller及其复合装饰器内部:util及其复合装饰器组件
1443
- * 3.3 util及其复合装饰器内部:util以及复合装饰器组件
1444
- */
1445
- /**
1446
- * configuration
1447
- * 1. 只能用在class上,且只能装饰一次
1448
- * 2. 不能和其他component复合装饰器同时使用
1449
- */
1450
- /**
1451
- * constructor-inject
1452
- * 1. 只能用在class上,且只能装饰一次
1453
- */
1454
- /**
1455
- * init
1456
- * 1. 只能用在method上,且只能装饰一次
1457
- * 2. 不能和其他component复合装饰器同时使用
1458
- */
1459
- /**
1460
- * start
1461
- * 1. 只能用在field上,且只能装饰一次
1462
- * 2. 不能和其他component复合装饰器同时使用
1463
- */
1464
- /**
1465
- * target
1466
- * 1. 只能用在field上,且只能装饰一次
1467
- * 2. 不能和其他component复合装饰器同时使用
1468
- */
1469
- /**
1470
- * value
1471
- * 1. 只能用在field上,且只能装饰一次
1472
- */
1473
- /**
1474
- * reactive
1475
- * 1. 只能用在field上,且只能装饰一次
1476
- */
1477
- /**
1478
- * memoized
1479
- * 1. 只能用在method上,且只能装饰一次
1480
- * 2. 不能和其他component复合装饰器同时使用
1481
- */
1482
- /**
1483
- * store
1484
- * 1. 只能用在class上,且只能装饰一次
1485
- * 2. 不能和其他component复合装饰器同时使用
1486
- */
1487
- /**
1488
- * render
1489
- * 1. 只能用在class上,且只能装饰一次
1490
- * 2. 不能和其他component复合装饰器同时使用
1491
- */
1492
- /**
1493
- * route
1494
- * 1. 只能用在class上,且只能装饰一次
1495
- * 2. 在class上使用时,依赖page同时使用
1496
- */
1497
- /**
1498
- * router
1499
- * 1. 只能用在class上,且只能装饰一次
1500
- * 2. 不能和其他component复合装饰器同时使用
1501
- */
1502
- /**
1503
- * util
1504
- * 1. 只能用在class上,且只能装饰一次
1505
- * 2. 不能和其他component复合装饰器同时使用
1506
- */
1507
- /**
1508
- * api
1509
- * 1. 只能用在class上,且只能装饰一次
1510
- * 2. 不能和其他component复合装饰器同时使用
1511
- */
1512
- /**
1513
- * bind
1514
- * 1. 只能用在method上,且只能装饰一次
1515
- * 2. 只能在有view装饰器或者view复合装饰器组件上使用
1516
- */
1517
- /**
1518
- * flow
1519
- * 1. 只能用在class上,且只能装饰一次
1520
- * 2. 不能和其他component复合装饰器同时使用
1521
- */
1522
- /**
1523
- * global-data
1524
- * 1. 只能用在class上,且只能装饰一次
1525
- * 2. 不能和component复合装饰器同时使用
1526
- */
1527
- /**
1528
- * ref
1529
- * 1. 只能用在field上,且只能装饰一次
1530
- * 2. 宿主组件必须是view组件或者是view复合组件
1531
- */
1532
- /**
1533
- * refs
1534
- * 1. 只能用在field上,且只能装饰一次
1535
- * 2. 宿主组件必须是view组件或者是view复合组件
1536
- */
1537
- /**
1538
- * web-application
1539
- * 1. 只能用在class上,且只能装饰一次
1540
- * 2.
1541
- */
1542
1144
  function deleteMetadatas(metadatas, idxs) {
1543
1145
  idxs.sort((a, b) => b - a);
1544
1146
  idxs.forEach(idx => metadatas.splice(idx, 1));
@@ -2003,12 +1605,13 @@ class IocComponentDefinition {
2003
1605
  this.clsDefinitionMap.set(cls, componentDefinition);
2004
1606
  }
2005
1607
  /**
2006
- * 获取真正会实例化的类定义
1608
+ * 解析组件实际需要实例化的类。
1609
+ * 没有子类时返回自身,只有一个子类时返回该子类,多个子类时抛出异常。
2007
1610
  * @param ClsOrId 想要实例化的类或类id
2008
1611
  * @param qualifier 如果存在多个后端类,需要通过qualifier指定具体的类id
2009
1612
  * @returns 真正会实例化的类定义
2010
1613
  */
2011
- getInstantiateDefinition(ClsOrId, qualifier) {
1614
+ resolve(ClsOrId, qualifier) {
2012
1615
  const definition = this.getDefinition(ClsOrId);
2013
1616
  if (!definition) {
2014
1617
  const diagnose = createDiagnose(DiagnoseCode.CO10011, typeof ClsOrId === 'string' ? ClsOrId : ClsOrId.name);
@@ -2060,10 +1663,72 @@ class IocComponentDefinition {
2060
1663
  }
2061
1664
  }
2062
1665
 
1666
+ var InjectType;
1667
+ (function (InjectType) {
1668
+ InjectType["constructor"] = "c";
1669
+ InjectType["autowired"] = "a";
1670
+ })(InjectType || (InjectType = {}));
1671
+ class DependencyGraph {
1672
+ // 创建中的ioc组件定义
1673
+ creating = new Set();
1674
+ // 已经完成newComponent的ioc组件
1675
+ earlyCreate = new Set();
1676
+ // 当前实例化路径
1677
+ stack = [];
1678
+ injectStr(type) {
1679
+ const s = type === InjectType.constructor ? '-c->' : type === InjectType.autowired ? '-a->' : '';
1680
+ return s ? `${s} ` : s;
1681
+ }
1682
+ addDependency(targetDefinition, instantiateDefinition, injectType) {
1683
+ // console.info('addDep', instantiateDefinition.cls.name);
1684
+ if (this.creating.has(instantiateDefinition) && (!instantiateDefinition.isSingleton || !this.earlyCreate.has(instantiateDefinition))) {
1685
+ const fullStack = [...this.stack, {
1686
+ targetDef: targetDefinition,
1687
+ instantiateDef: instantiateDefinition,
1688
+ injectType
1689
+ }];
1690
+ const loopDependencyInfo = fullStack.map(i => `${this.injectStr(i.injectType)}${i.instantiateDef.cls.name}${i.targetDef !== i.instantiateDef ? `{${i.targetDef.cls.name}}` : ''}`).join(' ');
1691
+ const diagnose = createDiagnose(DiagnoseCode.CO10013, loopDependencyInfo);
1692
+ throw new Error(stringifyDiagnose(diagnose));
1693
+ }
1694
+ this.creating.add(instantiateDefinition);
1695
+ this.stack.push({
1696
+ instantiateDef: instantiateDefinition,
1697
+ targetDef: targetDefinition,
1698
+ injectType
1699
+ });
1700
+ }
1701
+ removeDependency(targetDefinition, instantiateDefinition) {
1702
+ // console.info('rmDep', instantiateDefinition.cls.name);
1703
+ const now = this.stack.pop();
1704
+ if (now.targetDef !== targetDefinition || now.instantiateDef !== instantiateDefinition) {
1705
+ throw new Error();
1706
+ }
1707
+ this.earlyCreate.delete(instantiateDefinition);
1708
+ this.creating.delete(instantiateDefinition);
1709
+ }
1710
+ makeEarlyCreated(instantiateDefinition) {
1711
+ // console.info('mkEarly', instantiateDefinition.cls.name);
1712
+ if (!this.creating.has(instantiateDefinition)) {
1713
+ throw new Error('没有创建就调用了makeEarlyCreated,是一个bug');
1714
+ }
1715
+ this.earlyCreate.add(instantiateDefinition);
1716
+ }
1717
+ }
1718
+
1719
+ var InstantiateStage;
1720
+ (function (InstantiateStage) {
1721
+ // 在等待构造函数创建中
1722
+ InstantiateStage["WAITING_CTOR_ARGS"] = "waitCtorArgs";
1723
+ // 刚new出来,componentPostConstruct已执行,autowired未注入
1724
+ InstantiateStage["UNINITIALIZED"] = "uninitialized";
1725
+ // 初始化完毕:属性全部注入,init已执行,start未执行
1726
+ InstantiateStage["INITIALIZED"] = "initialized";
1727
+ })(InstantiateStage || (InstantiateStage = {}));
2063
1728
  class IocComponentFactory {
2064
1729
  // 单例构造函数和单例的映射关系
2065
1730
  singletonInstances = new Map();
2066
- createComponent(application, definition, constructorArgs) {
1731
+ newComponent(application, definition, constructorArgs) {
2067
1732
  const {
2068
1733
  cls,
2069
1734
  instantiateType
@@ -2084,7 +1749,8 @@ class IocComponentFactory {
2084
1749
  const {
2085
1750
  classMetadata,
2086
1751
  methodMetadata,
2087
- fieldMetadata
1752
+ fieldMetadata,
1753
+ getterMetadata
2088
1754
  } = metadatas;
2089
1755
  for (const meta of classMetadata) {
2090
1756
  const option = getCreateDecoratorOption(meta.constructor);
@@ -2114,22 +1780,33 @@ class IocComponentFactory {
2114
1780
  }
2115
1781
  }
2116
1782
  }
1783
+ for (const [getter, metaList] of getterMetadata.entries()) {
1784
+ for (const meta of metaList) {
1785
+ const option = getCreateDecoratorOption(meta.constructor);
1786
+ if (option) {
1787
+ option.componentPostConstruct.call(component, meta, application, {
1788
+ name: getter,
1789
+ kind: KindGetter
1790
+ });
1791
+ }
1792
+ }
1793
+ }
2117
1794
  }
2118
1795
  return component;
2119
1796
  }
2120
1797
  getComponents(application, userOption) {
2121
- const targetClsInstanceMap = new Map(); // 想要实例化的类和对应的实例
2122
- const instanceInstantiateClsMap = new Map(); // 新建实例和对应的实例化类
1798
+ /**
1799
+ * TODO: dependencyGraph 在 getComponents 内部创建,getComponents 一旦重入(如 init 内再次 getComponent),
1800
+ * 就会拿到另一张图、丢失外层创建链路,循环依赖检查因此失效。
1801
+ * 解决方向二选一:
1802
+ * 1. 约束 getComponents 只能顺序调用;
1803
+ * 2. 把 dependencyGraph 提升为唯一实例供重入共享。
1804
+ */
1805
+ const dependencyGraph = new DependencyGraph();
1806
+ const newCreateInstance = []; // 新建实例和对应的实例化类
2123
1807
  const newSingletonInstances = new Map(); // 新增的单例,最后要合并到singletonInstances
2124
- const instantiatingStage = new Set(); // 实例化中
2125
- const assignningStage = new Set(); // field赋值中
2126
- const finishedStage = new Set(); // 已完成
2127
- // 已经有的单例填充到finishedStage和instances
2128
- for (const [cls, instance] of this.singletonInstances.entries()) {
2129
- targetClsInstanceMap.set(cls, instance);
2130
- }
2131
1808
  // 完整的初始化一个组件
2132
- const instantiateComponent = opt => {
1809
+ const instantiateComponent = (opt, injectType) => {
2133
1810
  const {
2134
1811
  classOrId
2135
1812
  } = opt;
@@ -2145,7 +1822,8 @@ class IocComponentFactory {
2145
1822
  qualifier = application.propertiesConfig.getValue(`${targetDefinition.id}.qualifier`);
2146
1823
  }
2147
1824
  // 真正实例化的类定义
2148
- const instantiateDefinition = application.iocComponentDefinition.getInstantiateDefinition(classOrId, qualifier);
1825
+ const instantiateDefinition = application.iocComponentDefinition.resolve(classOrId, qualifier);
1826
+ // 尝试走缓存
2149
1827
  if (instantiateDefinition.isSingleton) {
2150
1828
  if (this.singletonInstances.has(instantiateDefinition.cls)) {
2151
1829
  return this.singletonInstances.get(instantiateDefinition.cls);
@@ -2153,76 +1831,94 @@ class IocComponentFactory {
2153
1831
  return newSingletonInstances.get(instantiateDefinition.cls);
2154
1832
  }
2155
1833
  }
2156
- if (instantiatingStage.has(targetDefinition.cls)) {
2157
- // 理论上不可能走到这里
2158
- throw new Error(`循环依赖: ${targetDefinition.cls.name}`);
2159
- }
2160
- // 在实例化中或者已实例化,返回实例
2161
- if (assignningStage.has(targetDefinition.cls) || finishedStage.has(targetDefinition.cls)) {
2162
- return targetClsInstanceMap.get(targetDefinition.cls);
2163
- }
2164
- instantiatingStage.add(targetDefinition.cls);
1834
+ dependencyGraph.addDependency(targetDefinition, instantiateDefinition, injectType);
1835
+ // newAddStage(targetDefinition.cls, InstantiateStage.WAITING_CTOR_ARGS);
1836
+ // 没有缓存,只能真的创建了
2165
1837
  const constructorArgs = [];
2166
1838
  const constructorInject = application.metadataRepository.listClassKindMetadata(instantiateDefinition.cls, ConstructorInject);
2167
- if (constructorInject.length > 0) {
2168
- // 因为元数据不能重复,所以只有一个
1839
+ if (constructorInject.length === 1) {
2169
1840
  const constructorInjectParams = constructorInject[0].value;
2170
- for (const dependency of constructorInjectParams) {
2171
- if (dependency === undefined) {
1841
+ for (const dependencyCls of constructorInjectParams) {
1842
+ if (dependencyCls === undefined) {
2172
1843
  constructorArgs.push(undefined);
2173
1844
  } else {
2174
1845
  const depInstance = instantiateComponent({
2175
- classOrId: dependency
2176
- });
2177
- // 确保依赖已完全注入
2178
- if (!finishedStage.has(dependency) && !this.singletonInstances.has(dependency)) {
2179
- const diagnose = createDiagnose(DiagnoseCode.CO10013, targetDefinition.cls.name, dependency.name);
2180
- throw new Error(stringifyDiagnose(diagnose));
2181
- }
1846
+ classOrId: dependencyCls
1847
+ }, InjectType.constructor);
2182
1848
  constructorArgs.push(depInstance);
2183
1849
  }
2184
1850
  }
1851
+ } else if (constructorInject.length > 1) {
1852
+ throw new Error(`${targetDefinition.cls.name}存在不止一个@constructorInject装饰器`);
2185
1853
  }
2186
1854
  // 2. 实例化,同时执行componentPostConstruct
2187
- const instance = this.createComponent(application, instantiateDefinition, constructorArgs);
1855
+ const instance = this.newComponent(application, instantiateDefinition, constructorArgs);
1856
+ dependencyGraph.makeEarlyCreated(instantiateDefinition);
1857
+ newCreateInstance.push(instance);
1858
+ // updateStage(targetDefinition.cls, InstantiateStage.UNINITIALIZED);
2188
1859
  if (instantiateDefinition.isSingleton) {
2189
1860
  newSingletonInstances.set(instantiateDefinition.cls, instance);
2190
1861
  }
2191
- targetClsInstanceMap.set(targetDefinition.cls, instance);
2192
- instanceInstantiateClsMap.set(instance, instantiateDefinition.cls);
2193
- instantiatingStage.delete(targetDefinition.cls);
2194
- assignningStage.add(targetDefinition.cls);
2195
1862
  // 3. 递归实例化field注入
2196
- const autowiredFields = application.metadataRepository.listFieldByMetadataCls(instantiateDefinition.cls, Autowired);
2197
- for (const field of autowiredFields) {
2198
- const autowiredMetadatas = application.metadataRepository.listFieldKindMetadata(instantiateDefinition.cls, field, Autowired);
2199
- if (autowiredMetadatas.length > 0) {
2200
- const autowiredCls = autowiredMetadatas[0].value;
2201
- if (autowiredCls === undefined) {
2202
- instance[field] = undefined;
2203
- } else if (autowiredCls === instantiateDefinition.cls) {
2204
- // 检查自依赖:不能注入自己
2205
- // TODO: 如果autowiredCls是instantiateDefinition.cls的祖先类或者子孙类怎么办?
2206
- const diagnose = createDiagnose(DiagnoseCode.CO10012, instantiateDefinition.cls.name, field);
2207
- printDiagnose(diagnose);
2208
- instance[field] = undefined;
2209
- } else {
2210
- const qualifierMetadatas = application.metadataRepository.listFieldKindMetadata(instantiateDefinition.cls, field, Qualifier);
2211
- let qualifier;
2212
- if (qualifierMetadatas.length > 0) {
2213
- qualifier = qualifierMetadatas[0].value;
2214
- }
2215
- const autowiredInstance = instantiateComponent({
2216
- classOrId: autowiredCls,
2217
- qualifier
2218
- });
2219
- instance[field] = autowiredInstance;
2220
- }
1863
+ const componentClasses = [instantiateDefinition.cls];
1864
+ let parentCls = Object.getPrototypeOf(instantiateDefinition.cls);
1865
+ while (application.iocComponentDefinition.existDefinition(parentCls)) {
1866
+ componentClasses.unshift(parentCls);
1867
+ parentCls = Object.getPrototypeOf(parentCls);
1868
+ }
1869
+ const autowiredFields = new Map();
1870
+ for (const declaringClass of componentClasses) {
1871
+ const fields = application.metadataRepository.listFieldByMetadataCls(declaringClass, Autowired);
1872
+ for (const field of fields) {
1873
+ const autowired = application.metadataRepository.listFieldKindMetadata(declaringClass, field, Autowired)[0];
1874
+ const qualifier = application.metadataRepository.listFieldKindMetadata(declaringClass, field, Qualifier)[0];
1875
+ // 子类同名字段覆盖父类,并按子类字段的位置注入。
1876
+ autowiredFields.delete(field);
1877
+ autowiredFields.set(field, {
1878
+ declaringClass,
1879
+ field,
1880
+ autowired,
1881
+ qualifier
1882
+ });
1883
+ }
1884
+ }
1885
+ for (const {
1886
+ field,
1887
+ autowired,
1888
+ qualifier
1889
+ } of autowiredFields.values()) {
1890
+ const autowiredCls = autowired.value;
1891
+ if (autowiredCls === undefined) {
1892
+ instance[field] = undefined;
1893
+ continue;
2221
1894
  }
1895
+ if (instantiateDefinition.isSingleton && autowiredCls === instantiateDefinition.cls) {
1896
+ // 检查自依赖:不能注入自己
1897
+ // TODO: 如果autowiredCls是instantiateDefinition.cls的祖先类或者子孙类怎么办?
1898
+ const diagnose = createDiagnose(DiagnoseCode.CO10012, instantiateDefinition.cls.name, field);
1899
+ printDiagnose(diagnose);
1900
+ instance[field] = undefined;
1901
+ continue;
1902
+ }
1903
+ const realAutowiredDef = application.iocComponentDefinition.resolve(autowiredCls, qualifier?.value);
1904
+ if (instantiateDefinition.isSingleton && realAutowiredDef.cls !== autowiredCls && realAutowiredDef.cls === instantiateDefinition.cls) {
1905
+ // 自身更好是注入类的唯一子类
1906
+ const diagnose = createDiagnose(DiagnoseCode.CO10012, instantiateDefinition.cls.name, field);
1907
+ printDiagnose(diagnose);
1908
+ instance[field] = undefined;
1909
+ continue;
1910
+ }
1911
+ instance[field] = instantiateComponent({
1912
+ classOrId: autowiredCls,
1913
+ qualifier: qualifier?.value
1914
+ }, InjectType.autowired);
1915
+ }
1916
+ // 4. autowired也注入完毕
1917
+ if (typeof instance['init'] === 'function') {
1918
+ instance['init']?.call(instance, application);
2222
1919
  }
2223
- // 4. 标记为完全注入
2224
- assignningStage.delete(targetDefinition.cls);
2225
- finishedStage.add(targetDefinition.cls);
1920
+ dependencyGraph.removeDependency(targetDefinition, instantiateDefinition);
1921
+ // updateStage(targetDefinition.cls, InstantiateStage.INITIALIZED);
2226
1922
  return instance;
2227
1923
  };
2228
1924
  // TODO: 如果初始化多个,有没有先后顺序问题?
@@ -2231,22 +1927,12 @@ class IocComponentFactory {
2231
1927
  if (newSingletonInstances.size > 0) {
2232
1928
  for (const [cls, instance] of newSingletonInstances.entries()) {
2233
1929
  this.singletonInstances.set(cls, instance);
2234
- // 现在默认子类的singleton和父类都是保持一致的。TODO: 如果子类的singleton不是单例了,应该如何处理
2235
- }
2236
- }
2237
- // 5. 所有新增的单例执行init方法
2238
- for (const cls of finishedStage.keys()) {
2239
- // 这里应该是根据instance来判断是否已经存在的
2240
- const instance = targetClsInstanceMap.get(cls);
2241
- if (typeof instance['init'] === 'function') {
2242
- instance['init']?.call(instance, application);
2243
1930
  }
2244
1931
  }
2245
1932
  // 执行start方法
2246
- for (const cls of finishedStage.keys()) {
2247
- const instance = targetClsInstanceMap.get(cls);
2248
- if (typeof instance['start'] === 'function') {
2249
- instance['start']?.call(instance, application);
1933
+ for (const ins of newCreateInstance) {
1934
+ if (typeof ins['start'] === 'function') {
1935
+ ins['start']?.call(ins, application);
2250
1936
  }
2251
1937
  }
2252
1938
  return instance;
@@ -2257,8 +1943,8 @@ class IocComponentFactory {
2257
1943
  const diagnose = createDiagnose(DiagnoseCode.CO10011, typeof viewClass === 'string' ? viewClass : viewClass.name);
2258
1944
  throw new Error(stringifyDiagnose(diagnose));
2259
1945
  }
2260
- // 视图组件目前简单的认为全是prototype,且不支持实例化子组件
2261
- const instance = this.createComponent(application, targetDefinition, [props]);
1946
+ // 视图组件目前简单的认为全是prototype,且不支持实例化子组件,TODO:补充不支持继承的限制和测试用例
1947
+ const instance = this.newComponent(application, targetDefinition, [props]);
2262
1948
  const autowiredFields = application.metadataRepository.listFieldByMetadataCls(targetDefinition.cls, Autowired);
2263
1949
  for (const field of autowiredFields) {
2264
1950
  const autowiredMetadatas = application.metadataRepository.listFieldKindMetadata(targetDefinition.cls, field, Autowired);
@@ -2402,17 +2088,17 @@ class Application {
2402
2088
  this.propertiesConfig = new PropertiesConfig(jsonConfig);
2403
2089
  }
2404
2090
  /**
2405
- * 在项目中,所以的组件都已经收集到coco/index里面了,所以不需要进行组件收集;
2406
- * 在测试时,组件是在执行到对应的行装饰器才会执行,所以需要先收集在启动。
2091
+ * 应用模块在 start 前完成 AOT 注册;测试中的局部类可能在 Application 构造后才注册,
2092
+ * 因此 start 时统一解析注册表。
2407
2093
  */
2408
2094
  start() {
2409
- initDecoratorParamModule();
2410
- // 用装饰器参数初始化元数据数据
2095
+ const runtimeDecoratorParams = initDecoratorParamModule();
2096
+ // 使用 AOT 解析完成的装饰器参数(runtimeDecoratorParams)初始化元数据仓库
2411
2097
  const {
2412
2098
  metadataRepository,
2413
2099
  idClassMap,
2414
2100
  componentMetadataClass
2415
- } = initMetadataModule(getDecoratorParam());
2101
+ } = initMetadataModule(runtimeDecoratorParams);
2416
2102
  this.metadataRepository = metadataRepository;
2417
2103
  this.idClassMap = idClassMap;
2418
2104
  this.componentMetadataClass = componentMetadataClass;
@@ -2475,23 +2161,18 @@ class Application {
2475
2161
  }
2476
2162
  }
2477
2163
 
2478
- let _initClass$q;
2479
2164
  /**
2480
2165
  * @public
2481
2166
  */
2482
- let _Bind;
2483
- new class extends _identity {
2484
- static [class Bind extends Metadata {
2485
- static {
2486
- [_Bind, _initClass$q] = _applyDecs2311(this, [target([Target.Type.Method])], [], 0, void 0, Metadata).c;
2487
- }
2488
- }];
2489
- $$id = "Bind";
2490
- constructor() {
2491
- super(_Bind), _initClass$q();
2492
- }
2493
- }();
2494
- var Bind = _Bind;
2167
+ class Bind extends Metadata {
2168
+ static $$id = "Bind";
2169
+ }
2170
+ registerComponent(Bind, [{
2171
+ metadataKind: "class",
2172
+ metadataClass: target.$$metadataClass,
2173
+ metadataParam: [Target.Type.Method],
2174
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2175
+ }]);
2495
2176
 
2496
2177
  var bind = createDecoratorExp(Bind, {
2497
2178
  componentPostConstruct: function (metadata, application, target) {
@@ -2502,23 +2183,23 @@ var bind = createDecoratorExp(Bind, {
2502
2183
  }
2503
2184
  });
2504
2185
 
2505
- let _initClass$p;
2506
2186
  /**
2507
2187
  * @public
2508
2188
  */
2509
- let _Cookie;
2510
- new class extends _identity {
2511
- static [class Cookie extends Metadata {
2512
- static {
2513
- [_Cookie, _initClass$p] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
2514
- }
2515
- }];
2516
- $$id = "Cookie";
2517
- constructor() {
2518
- super(_Cookie), _initClass$p();
2519
- }
2520
- }();
2521
- var Cookie = _Cookie;
2189
+ class Cookie extends Metadata {
2190
+ static $$id = "Cookie";
2191
+ }
2192
+ registerComponent(Cookie, [{
2193
+ metadataKind: "class",
2194
+ metadataClass: component.$$metadataClass,
2195
+ metadataParam: undefined,
2196
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
2197
+ }, {
2198
+ metadataKind: "class",
2199
+ metadataClass: target.$$metadataClass,
2200
+ metadataParam: [Target.Type.Class],
2201
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2202
+ }]);
2522
2203
 
2523
2204
  var cookie = createDecoratorExp(Cookie);
2524
2205
 
@@ -2709,7 +2390,6 @@ function mapChildren(children, func, context) {
2709
2390
  function forEachChildren(children, forEachFunc, forEachContext) {
2710
2391
  mapChildren(children, function () {
2711
2392
  forEachFunc.apply(this, arguments);
2712
- // Don't return anything.
2713
2393
  }, forEachContext);
2714
2394
  }
2715
2395
 
@@ -2757,117 +2437,113 @@ const Children = {
2757
2437
  forEach: forEachChildren,
2758
2438
  };
2759
2439
 
2760
- let _initClass$o;
2761
2440
  /**
2762
2441
  * @public
2763
2442
  */
2764
- let _View;
2765
- new class extends _identity {
2766
- static [class View extends Metadata {
2767
- static {
2768
- [_View, _initClass$o] = _applyDecs2311(this, [target([Target.Type.Class]), scope(exports.SCOPE.Prototype), component()], [], 0, void 0, Metadata).c;
2769
- }
2770
- // 当@view作为类装饰时,下面的函数将修改被装饰器的prototype
2771
- // TODO: View的复合装饰器也要支持的吧
2772
- static classDecoratorModifyPrototype(prototype) {
2773
- if (!prototype) {
2774
- prototype.updater = ReactNoopUpdateQueue;
2775
- }
2443
+ class View extends Metadata {
2444
+ static $$id = "View";
2445
+ }
2446
+ registerComponent(View, [{
2447
+ metadataKind: "class",
2448
+ metadataClass: component.$$metadataClass,
2449
+ metadataParam: undefined,
2450
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
2451
+ }, {
2452
+ metadataKind: "class",
2453
+ metadataClass: scope.$$metadataClass,
2454
+ metadataParam: exports.SCOPE.Prototype,
2455
+ isPlaceholderDecoratorExp: scope.$$isPlaceholderDecoratorExp
2456
+ }, {
2457
+ metadataKind: "class",
2458
+ metadataClass: target.$$metadataClass,
2459
+ metadataParam: [Target.Type.Class],
2460
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2461
+ }]);
2462
+
2463
+ var view = createDecoratorExp(View, {
2464
+ // 当@view作为类装饰时,实例化后给组件实例挂载updater,用于触发调度器
2465
+ // TODO: View的复合装饰器也要支持的吧
2466
+ componentPostConstruct() {
2467
+ if (!this.updater) {
2468
+ this.updater = ReactNoopUpdateQueue;
2776
2469
  }
2777
- }];
2778
- $$id = "View";
2779
- constructor() {
2780
- super(_View), _initClass$o();
2781
2470
  }
2782
- }();
2783
- var View = _View;
2784
-
2785
- var view = createDecoratorExp(View);
2471
+ });
2786
2472
 
2787
- let _initClass$n;
2788
2473
  /**
2789
2474
  * @public
2790
2475
  */
2791
- let _Layout;
2792
- new class extends _identity {
2793
- static [class Layout extends Metadata {
2794
- static {
2795
- [_Layout, _initClass$n] = _applyDecs2311(this, [target([Target.Type.Class]), view()], [], 0, void 0, Metadata).c;
2796
- }
2797
- }];
2798
- $$id = "Layout";
2799
- constructor() {
2800
- super(_Layout), _initClass$n();
2801
- }
2802
- }();
2803
- var Layout = _Layout;
2476
+ class Layout extends Metadata {
2477
+ static $$id = "Layout";
2478
+ }
2479
+ registerComponent(Layout, [{
2480
+ metadataKind: "class",
2481
+ metadataClass: view.$$metadataClass,
2482
+ metadataParam: undefined,
2483
+ isPlaceholderDecoratorExp: view.$$isPlaceholderDecoratorExp
2484
+ }, {
2485
+ metadataKind: "class",
2486
+ metadataClass: target.$$metadataClass,
2487
+ metadataParam: [Target.Type.Class],
2488
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2489
+ }]);
2804
2490
 
2805
2491
  var layout = createDecoratorExp(Layout);
2806
2492
 
2807
- let _initClass$m;
2808
2493
  /**
2809
2494
  * @public
2810
2495
  */
2811
- let _LocalStorage$1;
2812
- new class extends _identity {
2813
- static [class LocalStorage extends Metadata {
2814
- static {
2815
- [_LocalStorage$1, _initClass$m] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
2816
- }
2817
- }];
2818
- $$id = "LocalStorage";
2819
- constructor() {
2820
- super(_LocalStorage$1), _initClass$m();
2821
- }
2822
- }();
2823
- var LocalStorage = _LocalStorage$1;
2496
+ let LocalStorage$1 = class LocalStorage extends Metadata {
2497
+ static $$id = "LocalStorage";
2498
+ };
2499
+ registerComponent(LocalStorage$1, [{
2500
+ metadataKind: "class",
2501
+ metadataClass: component.$$metadataClass,
2502
+ metadataParam: undefined,
2503
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
2504
+ }, {
2505
+ metadataKind: "class",
2506
+ metadataClass: target.$$metadataClass,
2507
+ metadataParam: [Target.Type.Class],
2508
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2509
+ }]);
2824
2510
 
2825
- var localStorageDecorator = createDecoratorExp(LocalStorage);
2511
+ var localStorageDecorator = createDecoratorExp(LocalStorage$1);
2826
2512
 
2827
- let _initClass$l;
2828
- let _LocalStorage;
2829
- new class extends _identity {
2830
- static [class LocalStorage {
2831
- static {
2832
- [_LocalStorage, _initClass$l] = _applyDecs2311(this, [localStorageDecorator()], []).c;
2833
- }
2834
- setItem(key, value) {
2835
- return localStorage.setItem(key, value);
2836
- }
2837
- getItem(key) {
2838
- return localStorage.getItem(key);
2839
- }
2840
- removeItem(key) {
2841
- return localStorage.removeItem(key);
2842
- }
2843
- key(index) {
2844
- return localStorage.key(index);
2845
- }
2846
- }];
2847
- $$id = "LocalStorage";
2848
- constructor() {
2849
- super(_LocalStorage), _initClass$l();
2513
+ class LocalStorage {
2514
+ static $$id = "LocalStorage";
2515
+ setItem(key, value) {
2516
+ return localStorage.setItem(key, value);
2517
+ }
2518
+ getItem(key) {
2519
+ return localStorage.getItem(key);
2850
2520
  }
2851
- }();
2852
- var _LocalStorage_default = _LocalStorage;
2521
+ removeItem(key) {
2522
+ return localStorage.removeItem(key);
2523
+ }
2524
+ key(index) {
2525
+ return localStorage.key(index);
2526
+ }
2527
+ }
2528
+ registerComponent(LocalStorage, [{
2529
+ metadataKind: "class",
2530
+ metadataClass: localStorageDecorator.$$metadataClass,
2531
+ metadataParam: undefined,
2532
+ isPlaceholderDecoratorExp: localStorageDecorator.$$isPlaceholderDecoratorExp
2533
+ }]);
2853
2534
 
2854
- let _initClass$k;
2855
2535
  /**
2856
2536
  * @public
2857
2537
  */
2858
- let _Memoized;
2859
- new class extends _identity {
2860
- static [class Memoized extends Metadata {
2861
- static {
2862
- [_Memoized, _initClass$k] = _applyDecs2311(this, [target([Target.Type.Method, Target.Type.Field])], [], 0, void 0, Metadata).c;
2863
- }
2864
- }];
2865
- $$id = "Memoized";
2866
- constructor() {
2867
- super(_Memoized), _initClass$k();
2868
- }
2869
- }();
2870
- var Memoized = _Memoized;
2538
+ class Memoized extends Metadata {
2539
+ static $$id = "Memoized";
2540
+ }
2541
+ registerComponent(Memoized, [{
2542
+ metadataKind: "class",
2543
+ metadataClass: target.$$metadataClass,
2544
+ metadataParam: [Target.Type.Method, Target.Type.Field, Target.Type.Getter],
2545
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2546
+ }]);
2871
2547
 
2872
2548
  class Subscriber {
2873
2549
  static Executing;
@@ -2937,49 +2613,57 @@ var memoized = createDecoratorExp(Memoized, {
2937
2613
  const diagnose = createDiagnose(DiagnoseCode.CO10028, this.constructor.name, name, name, type);
2938
2614
  console.error(stringifyDiagnose(diagnose));
2939
2615
  }
2616
+ } else if (kind === KindGetter) {
2617
+ const descriptor = Object.getOwnPropertyDescriptor(this.constructor.prototype, name);
2618
+ const getter = descriptor?.get;
2619
+ if (typeof getter !== 'function') {
2620
+ console.error('不应该拿不到getter函数');
2621
+ return;
2622
+ }
2623
+ const subscriber = new Subscriber(getter.bind(this));
2624
+ const memoizedGetter = subscriber.memoizedFn;
2625
+ Object.defineProperty(this, name, {
2626
+ ...descriptor,
2627
+ get: memoizedGetter
2628
+ });
2940
2629
  } else ;
2941
2630
  }
2942
2631
  });
2943
2632
 
2944
- let _initClass$j;
2945
2633
  /**
2946
2634
  * @public
2947
2635
  */
2948
- let _Page;
2949
- new class extends _identity {
2950
- static [class Page extends Metadata {
2951
- static {
2952
- [_Page, _initClass$j] = _applyDecs2311(this, [target([Target.Type.Class]), view()], [], 0, void 0, Metadata).c;
2953
- }
2954
- }];
2955
- $$id = "Page";
2956
- constructor() {
2957
- super(_Page), _initClass$j();
2958
- }
2959
- }();
2960
- var Page = _Page;
2636
+ class Page extends Metadata {
2637
+ static $$id = "Page";
2638
+ }
2639
+ registerComponent(Page, [{
2640
+ metadataKind: "class",
2641
+ metadataClass: view.$$metadataClass,
2642
+ metadataParam: undefined,
2643
+ isPlaceholderDecoratorExp: view.$$isPlaceholderDecoratorExp
2644
+ }, {
2645
+ metadataKind: "class",
2646
+ metadataClass: target.$$metadataClass,
2647
+ metadataParam: [Target.Type.Class],
2648
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2649
+ }]);
2961
2650
 
2962
2651
  var page = createDecoratorExp(Page);
2963
2652
 
2964
- let _initClass$i;
2965
2653
  /**
2966
2654
  * 加在field表明是响应式
2967
2655
  * 加在metadata上用于自定义reactive元数据
2968
2656
  * @public
2969
2657
  */
2970
- let _Reactive;
2971
- new class extends _identity {
2972
- static [class Reactive extends Metadata {
2973
- static {
2974
- [_Reactive, _initClass$i] = _applyDecs2311(this, [target([Target.Type.Field])], [], 0, void 0, Metadata).c;
2975
- }
2976
- }];
2977
- $$id = "Reactive";
2978
- constructor() {
2979
- super(_Reactive), _initClass$i();
2980
- }
2981
- }();
2982
- var Reactive = _Reactive;
2658
+ class Reactive extends Metadata {
2659
+ static $$id = "Reactive";
2660
+ }
2661
+ registerComponent(Reactive, [{
2662
+ metadataKind: "class",
2663
+ metadataClass: target.$$metadataClass,
2664
+ metadataParam: [Target.Type.Field],
2665
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2666
+ }]);
2983
2667
 
2984
2668
  class Publisher {
2985
2669
  name;
@@ -3056,23 +2740,18 @@ var reactive = createDecoratorExp(Reactive, {
3056
2740
  }
3057
2741
  });
3058
2742
 
3059
- let _initClass$h;
3060
2743
  /**
3061
2744
  * @public
3062
2745
  */
3063
- let _Ref;
3064
- new class extends _identity {
3065
- static [class Ref extends Metadata {
3066
- static {
3067
- [_Ref, _initClass$h] = _applyDecs2311(this, [target([Target.Type.Field])], [], 0, void 0, Metadata).c;
3068
- }
3069
- }];
3070
- $$id = "Ref";
3071
- constructor() {
3072
- super(_Ref), _initClass$h();
3073
- }
3074
- }();
3075
- var Ref$1 = _Ref;
2746
+ let Ref$1 = class Ref extends Metadata {
2747
+ static $$id = "Ref";
2748
+ };
2749
+ registerComponent(Ref$1, [{
2750
+ metadataKind: "class",
2751
+ metadataClass: target.$$metadataClass,
2752
+ metadataParam: [Target.Type.Field],
2753
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2754
+ }]);
3076
2755
 
3077
2756
  var ref = createDecoratorExp(Ref$1, {
3078
2757
  componentPostConstruct: function (metadata, application, target) {
@@ -3085,23 +2764,18 @@ var ref = createDecoratorExp(Ref$1, {
3085
2764
  }
3086
2765
  });
3087
2766
 
3088
- let _initClass$g;
3089
2767
  /**
3090
2768
  * @public
3091
2769
  */
3092
- let _Refs;
3093
- new class extends _identity {
3094
- static [class Refs extends Metadata {
3095
- static {
3096
- [_Refs, _initClass$g] = _applyDecs2311(this, [target([Target.Type.Field])], [], 0, void 0, Metadata).c;
3097
- }
3098
- }];
3099
- $$id = "Refs";
3100
- constructor() {
3101
- super(_Refs), _initClass$g();
3102
- }
3103
- }();
3104
- var Refs = _Refs;
2770
+ class Refs extends Metadata {
2771
+ static $$id = "Refs";
2772
+ }
2773
+ registerComponent(Refs, [{
2774
+ metadataKind: "class",
2775
+ metadataClass: target.$$metadataClass,
2776
+ metadataParam: [Target.Type.Field],
2777
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2778
+ }]);
3105
2779
 
3106
2780
  var refs = createDecoratorExp(Refs, {
3107
2781
  componentPostConstruct: function (metadata, application, target) {
@@ -3109,166 +2783,146 @@ var refs = createDecoratorExp(Refs, {
3109
2783
  }
3110
2784
  });
3111
2785
 
3112
- let _initClass$f;
3113
2786
  /**
3114
2787
  * @public
3115
2788
  */
3116
- let _SessionStorage$1;
3117
- new class extends _identity {
3118
- static [class SessionStorage extends Metadata {
3119
- static {
3120
- [_SessionStorage$1, _initClass$f] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
3121
- }
3122
- }];
3123
- $$id = "SessionStorage";
3124
- constructor() {
3125
- super(_SessionStorage$1), _initClass$f();
3126
- }
3127
- }();
3128
- var SessionStorage = _SessionStorage$1;
2789
+ let SessionStorage$1 = class SessionStorage extends Metadata {
2790
+ static $$id = "SessionStorage";
2791
+ };
2792
+ registerComponent(SessionStorage$1, [{
2793
+ metadataKind: "class",
2794
+ metadataClass: component.$$metadataClass,
2795
+ metadataParam: undefined,
2796
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
2797
+ }, {
2798
+ metadataKind: "class",
2799
+ metadataClass: target.$$metadataClass,
2800
+ metadataParam: [Target.Type.Class],
2801
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2802
+ }]);
3129
2803
 
3130
- var sessionStorageDecorator = createDecoratorExp(SessionStorage);
2804
+ var sessionStorageDecorator = createDecoratorExp(SessionStorage$1);
3131
2805
 
3132
- let _initClass$e;
3133
- let _SessionStorage;
3134
- new class extends _identity {
3135
- static [class SessionStorage {
3136
- static {
3137
- [_SessionStorage, _initClass$e] = _applyDecs2311(this, [sessionStorageDecorator()], []).c;
3138
- }
3139
- setItem(key, value) {
3140
- return sessionStorage.setItem(key, value);
3141
- }
3142
- getItem(key) {
3143
- return sessionStorage.getItem(key);
3144
- }
3145
- removeItem(key) {
3146
- return sessionStorage.removeItem(key);
3147
- }
3148
- key(index) {
3149
- return sessionStorage.key(index);
3150
- }
3151
- }];
3152
- $$id = "SessionStorage";
3153
- constructor() {
3154
- super(_SessionStorage), _initClass$e();
2806
+ class SessionStorage {
2807
+ static $$id = "SessionStorage";
2808
+ setItem(key, value) {
2809
+ return sessionStorage.setItem(key, value);
2810
+ }
2811
+ getItem(key) {
2812
+ return sessionStorage.getItem(key);
3155
2813
  }
3156
- }();
3157
- var _SessionStorage_default = _SessionStorage;
2814
+ removeItem(key) {
2815
+ return sessionStorage.removeItem(key);
2816
+ }
2817
+ key(index) {
2818
+ return sessionStorage.key(index);
2819
+ }
2820
+ }
2821
+ registerComponent(SessionStorage, [{
2822
+ metadataKind: "class",
2823
+ metadataClass: sessionStorageDecorator.$$metadataClass,
2824
+ metadataParam: undefined,
2825
+ isPlaceholderDecoratorExp: sessionStorageDecorator.$$isPlaceholderDecoratorExp
2826
+ }]);
3158
2827
 
3159
- let _initClass$d;
3160
2828
  /**
3161
2829
  * @public
3162
2830
  */
3163
- let _Store;
3164
- new class extends _identity {
3165
- static [class Store extends Metadata {
3166
- static {
3167
- [_Store, _initClass$d] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
3168
- }
3169
- }];
3170
- $$id = "Store";
3171
- constructor() {
3172
- super(_Store), _initClass$d();
3173
- }
3174
- }();
3175
- var Store = _Store;
2831
+ class Store extends Metadata {
2832
+ static $$id = "Store";
2833
+ }
2834
+ registerComponent(Store, [{
2835
+ metadataKind: "class",
2836
+ metadataClass: component.$$metadataClass,
2837
+ metadataParam: undefined,
2838
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
2839
+ }, {
2840
+ metadataKind: "class",
2841
+ metadataClass: target.$$metadataClass,
2842
+ metadataParam: [Target.Type.Class],
2843
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2844
+ }]);
3176
2845
 
3177
2846
  var store = createDecoratorExp(Store);
3178
2847
 
3179
- let _initClass$c;
3180
- let _Router$1;
3181
- new class extends _identity {
3182
- static [class Router extends Metadata {
3183
- static {
3184
- [_Router$1, _initClass$c] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
3185
- }
3186
- }];
3187
- $$id = "Router";
3188
- constructor() {
3189
- super(_Router$1), _initClass$c();
3190
- }
3191
- }();
3192
- var Router$1 = _Router$1;
2848
+ let Router$1 = class Router extends Metadata {
2849
+ static $$id = "Router";
2850
+ };
2851
+ registerComponent(Router$1, [{
2852
+ metadataKind: "class",
2853
+ metadataClass: component.$$metadataClass,
2854
+ metadataParam: undefined,
2855
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
2856
+ }, {
2857
+ metadataKind: "class",
2858
+ metadataClass: target.$$metadataClass,
2859
+ metadataParam: [Target.Type.Class],
2860
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2861
+ }]);
3193
2862
 
3194
- let _initClass$b;
3195
2863
  /**
3196
2864
  * @public
3197
2865
  */
3198
- let _Route$1;
3199
- new class extends _identity {
3200
- static [class Route extends Metadata {
3201
- static {
3202
- [_Route$1, _initClass$b] = _applyDecs2311(this, [target([Target.Type.Class])], [], 0, void 0, Metadata).c;
3203
- }
3204
- value;
3205
- }];
3206
- $$id = "Route";
3207
- constructor() {
3208
- super(_Route$1), _initClass$b();
3209
- }
3210
- }();
3211
- var RouteMeta = _Route$1;
2866
+ let Route$1 = class Route extends Metadata {
2867
+ static $$id = "Route";
2868
+ value;
2869
+ };
2870
+ registerComponent(Route$1, [{
2871
+ metadataKind: "class",
2872
+ metadataClass: target.$$metadataClass,
2873
+ metadataParam: [Target.Type.Class],
2874
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2875
+ }]);
3212
2876
 
3213
- var route = createDecoratorExp(RouteMeta);
2877
+ var route = createDecoratorExp(Route$1);
3214
2878
 
3215
2879
  var router = createDecoratorExp(Router$1);
3216
2880
 
3217
- let _initClass$a;
3218
2881
  /**
3219
2882
  * @public
3220
2883
  */
3221
- let _Router;
3222
- new class extends _identity {
3223
- static [class Router {
3224
- static {
3225
- [_Router, _initClass$a] = _applyDecs2311(this, [router()], []).c;
3226
- }
3227
- route;
3228
- render;
3229
- routeComponentMapper;
3230
- }];
3231
- $$id = "Router";
3232
- constructor() {
3233
- super(_Router), _initClass$a();
3234
- }
3235
- }();
3236
- var Router = _Router;
3237
-
3238
- let _initClass$9;
3239
- let _Render$1;
3240
- new class extends _identity {
3241
- static [class Render extends Metadata {
3242
- static {
3243
- [_Render$1, _initClass$9] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
3244
- }
3245
- }];
3246
- $$id = "Render";
3247
- constructor() {
3248
- super(_Render$1), _initClass$9();
3249
- }
3250
- }();
3251
- var Render$1 = _Render$1;
2884
+ class Router {
2885
+ static $$id = "Router";
2886
+ route;
2887
+ render;
2888
+ routeComponentMapper;
2889
+ }
2890
+ registerComponent(Router, [{
2891
+ metadataKind: "class",
2892
+ metadataClass: router.$$metadataClass,
2893
+ metadataParam: undefined,
2894
+ isPlaceholderDecoratorExp: router.$$isPlaceholderDecoratorExp
2895
+ }]);
2896
+
2897
+ let Render$1 = class Render extends Metadata {
2898
+ static $$id = "Render";
2899
+ };
2900
+ registerComponent(Render$1, [{
2901
+ metadataKind: "class",
2902
+ metadataClass: component.$$metadataClass,
2903
+ metadataParam: undefined,
2904
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
2905
+ }, {
2906
+ metadataKind: "class",
2907
+ metadataClass: target.$$metadataClass,
2908
+ metadataParam: [Target.Type.Class],
2909
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2910
+ }]);
3252
2911
 
3253
2912
  var render$1 = createDecoratorExp(Render$1);
3254
2913
 
3255
- let _initClass$8;
3256
2914
  /**
3257
2915
  * @public
3258
2916
  */
3259
- let _Render;
3260
- new class extends _identity {
3261
- static [class Render {
3262
- static {
3263
- [_Render, _initClass$8] = _applyDecs2311(this, [render$1()], []).c;
3264
- }
3265
- }];
3266
- $$id = "Render";
3267
- constructor() {
3268
- super(_Render), _initClass$8();
3269
- }
3270
- }();
3271
- var Render = _Render;
2917
+ class Render {
2918
+ static $$id = "Render";
2919
+ }
2920
+ registerComponent(Render, [{
2921
+ metadataKind: "class",
2922
+ metadataClass: render$1.$$metadataClass,
2923
+ metadataParam: undefined,
2924
+ isPlaceholderDecoratorExp: render$1.$$isPlaceholderDecoratorExp
2925
+ }]);
3272
2926
 
3273
2927
  /**
3274
2928
  * Mapping from registration name to event name
@@ -3277,7 +2931,6 @@ const registrationNameDependencies = {};
3277
2931
  const allNativeEvents = new Set();
3278
2932
  function registerTwoPhaseEvent(registrationName, dependencies) {
3279
2933
  registerDirectEvent(registrationName, dependencies);
3280
- // registerDirectEvent(registrationName + 'Capture', dependencies);
3281
2934
  }
3282
2935
  function registerDirectEvent(registrationName, dependencies) {
3283
2936
  registrationNameDependencies[registrationName] = dependencies;
@@ -4737,7 +4390,6 @@ function executeDispatch(domEvent, listener, currentTarget, reactEventType) {
4737
4390
  domEvent.stopPropagation();
4738
4391
  },
4739
4392
  });
4740
- // domEvent.currentTarget = null;
4741
4393
  }
4742
4394
  function processDispatchQueueItemsInOrder(domEvent, dispatchListeners, inCapturePhase, reactEventType) {
4743
4395
  if (inCapturePhase) {
@@ -6302,7 +5954,9 @@ function initProps(instance, newProps) {
6302
5954
  continue;
6303
5955
  }
6304
5956
  _values[field] = newProps[field];
6305
- definePublisher(instance.props, field, function getter() { return _values[field]; }, function setter(object, key, newValue) {
5957
+ definePublisher(instance.props, field, function getter() {
5958
+ return _values[field];
5959
+ }, function setter(object, key, newValue) {
6306
5960
  _values[field] = newValue;
6307
5961
  });
6308
5962
  }
@@ -6354,7 +6008,7 @@ const storeComponentUpdater = {
6354
6008
  scheduleUpdateOnFiber(root, viewComponentFiber, viewInstance);
6355
6009
  }
6356
6010
  }
6357
- }
6011
+ },
6358
6012
  };
6359
6013
  function reactiveStoreField(ctor, viewComponent) {
6360
6014
  const { application } = getCommonApi();
@@ -6373,7 +6027,7 @@ function reactiveStoreField(ctor, viewComponent) {
6373
6027
  },
6374
6028
  set() {
6375
6029
  console.error('store实例在初始化之后不允许修改');
6376
- }
6030
+ },
6377
6031
  });
6378
6032
  }
6379
6033
  });
@@ -6927,7 +6581,6 @@ function insertOrAppendPlacementNodeIntoContainer(node, before, parent) {
6927
6581
  sibling = sibling.sibling;
6928
6582
  }
6929
6583
  }
6930
- // throw new Error('todo')
6931
6584
  }
6932
6585
  }
6933
6586
  function detachFiberMutation(fiber) {
@@ -7098,7 +6751,6 @@ function commitMutationEffectsOnFiber(finishedWork, root) {
7098
6751
  resetTextContent(instance);
7099
6752
  }
7100
6753
  catch (error) {
7101
- // todo captureCommitPhaseError(finishedWork, finishedWork.return, error);
7102
6754
  }
7103
6755
  }
7104
6756
  if (flags & Update) {
@@ -7786,34 +7438,29 @@ function render(element, container) {
7786
7438
  return legacyRenderSubtreeIntoContainer(null, element, container);
7787
7439
  }
7788
7440
 
7789
- let _initClass$7;
7790
7441
  /**
7791
7442
  * @public
7792
7443
  */
7793
- let _WebRender;
7794
- new class extends _identity {
7795
- static [class WebRender extends Render {
7796
- static {
7797
- [_WebRender, _initClass$7] = _applyDecs2311(this, [render$1()], [], 0, void 0, Render).c;
7798
- }
7799
- container;
7800
- init(application) {
7801
- registerCommonApi(application);
7802
- this.container = document.getElementById('root');
7803
- if (!this.container) {
7804
- console.error('未找到根节点');
7805
- }
7806
- }
7807
- render(component) {
7808
- return render(jsx(component, undefined), this.container);
7444
+ class WebRender extends Render {
7445
+ static $$id = "WebRender";
7446
+ container;
7447
+ init(application) {
7448
+ registerCommonApi(application);
7449
+ this.container = document.getElementById('root');
7450
+ if (!this.container) {
7451
+ console.error('未找到根节点');
7809
7452
  }
7810
- }];
7811
- $$id = "WebRender";
7812
- constructor() {
7813
- super(_WebRender), _initClass$7();
7814
7453
  }
7815
- }();
7816
- var _WebRender_default = _WebRender;
7454
+ render(component) {
7455
+ return render(jsx(component, undefined), this.container);
7456
+ }
7457
+ }
7458
+ registerComponent(WebRender, [{
7459
+ metadataKind: "class",
7460
+ metadataClass: render$1.$$metadataClass,
7461
+ metadataParam: undefined,
7462
+ isPlaceholderDecoratorExp: render$1.$$isPlaceholderDecoratorExp
7463
+ }]);
7817
7464
 
7818
7465
  class DynamicRoute {
7819
7466
  regExp;
@@ -7896,175 +7543,175 @@ class RouteComponentMapper {
7896
7543
  }
7897
7544
  }
7898
7545
 
7899
- let _initClass$6;
7900
- let _Route;
7901
- new class extends _identity {
7902
- static [class Route {
7903
- static {
7904
- [_Route, _initClass$6] = _applyDecs2311(this, [store()], []).c;
7905
- }
7906
- // window.location.pathname
7907
- pathname;
7908
- // 动态路由参数
7909
- params = {};
7910
- }];
7911
- $$id = "Route";
7912
- constructor() {
7913
- super(_Route), _initClass$6();
7914
- }
7915
- }();
7916
- var Route = _Route;
7546
+ class Route {
7547
+ static $$id = "Route";
7548
+ // window.location.pathname
7549
+ pathname;
7550
+ // 动态路由参数
7551
+ params = {};
7552
+ }
7553
+ registerComponent(Route, [{
7554
+ metadataKind: "class",
7555
+ metadataClass: component.$$metadataClass,
7556
+ metadataParam: undefined,
7557
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
7558
+ }]);
7917
7559
 
7918
- let _initClass$5;
7919
7560
  /**
7920
7561
  * @public
7921
7562
  */
7922
- let _HistoryRouter;
7923
- new class extends _identity {
7924
- static [class HistoryRouter extends Router {
7925
- static {
7926
- [_HistoryRouter, _initClass$5] = _applyDecs2311(this, [router(), constructorInject([Render])], [], 0, void 0, Router).c;
7927
- }
7928
- constructor(render) {
7929
- super();
7930
- this.render = render;
7931
- }
7932
- handleRouteChange = () => {
7933
- const pathname = window.location.pathname;
7934
- const {
7935
- pageComponent,
7936
- params
7937
- } = this.routeComponentMapper.match(pathname);
7938
- this.route.pathname = pathname;
7939
- this.route.params = params || {};
7940
- if (pageComponent) {
7941
- this.render.render(pageComponent);
7942
- }
7943
- };
7944
- init(application) {
7945
- const routeComponentMap = application.listBeDecoratedClsByClassKindMetadata(RouteMeta);
7946
- this.routeComponentMapper = new RouteComponentMapper();
7947
- this.routeComponentMapper.init(routeComponentMap);
7948
- this.route = application.getComponent(Route);
7949
- }
7950
- start() {
7951
- window.addEventListener('popstate', this.handleRouteChange);
7952
- // 初始化渲染
7953
- this.handleRouteChange();
7954
- }
7955
- removeListener() {
7956
- window.removeEventListener('popstate', this.handleRouteChange);
7957
- }
7958
- navigateTo(url) {
7959
- window.history.pushState({}, '', url);
7960
- this.handleRouteChange();
7563
+ class HistoryRouter extends Router {
7564
+ static $$id = "HistoryRouter";
7565
+ constructor(render) {
7566
+ super();
7567
+ this.render = render;
7568
+ }
7569
+ handleRouteChange = () => {
7570
+ const pathname = window.location.pathname;
7571
+ const {
7572
+ pageComponent,
7573
+ params
7574
+ } = this.routeComponentMapper.match(pathname);
7575
+ this.route.pathname = pathname;
7576
+ this.route.params = params || {};
7577
+ if (pageComponent) {
7578
+ this.render.render(pageComponent);
7961
7579
  }
7962
- }];
7963
- $$id = "HistoryRouter";
7964
- constructor() {
7965
- super(_HistoryRouter), _initClass$5();
7580
+ };
7581
+ init(application) {
7582
+ const routeComponentMap = application.listBeDecoratedClsByClassKindMetadata(Route$1);
7583
+ this.routeComponentMapper = new RouteComponentMapper();
7584
+ this.routeComponentMapper.init(routeComponentMap);
7585
+ this.route = application.getComponent(Route);
7586
+ }
7587
+ start() {
7588
+ window.addEventListener('popstate', this.handleRouteChange);
7589
+ // 初始化渲染
7590
+ this.handleRouteChange();
7591
+ }
7592
+ removeListener() {
7593
+ window.removeEventListener('popstate', this.handleRouteChange);
7966
7594
  }
7967
- }();
7968
- var _HistoryRouter_default = _HistoryRouter;
7595
+ navigateTo(url) {
7596
+ window.history.pushState({}, '', url);
7597
+ this.handleRouteChange();
7598
+ }
7599
+ }
7600
+ registerComponent(HistoryRouter, [{
7601
+ metadataKind: "class",
7602
+ metadataClass: constructorInject.$$metadataClass,
7603
+ metadataParam: [Render],
7604
+ isPlaceholderDecoratorExp: constructorInject.$$isPlaceholderDecoratorExp
7605
+ }, {
7606
+ metadataKind: "class",
7607
+ metadataClass: router.$$metadataClass,
7608
+ metadataParam: undefined,
7609
+ isPlaceholderDecoratorExp: router.$$isPlaceholderDecoratorExp
7610
+ }]);
7969
7611
 
7970
- let _initClass$4;
7971
7612
  /**
7972
7613
  * @public
7973
7614
  */
7974
- let _Util;
7975
- new class extends _identity {
7976
- static [class Util extends Metadata {
7977
- static {
7978
- [_Util, _initClass$4] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
7979
- }
7980
- }];
7981
- $$id = "Util";
7982
- constructor() {
7983
- super(_Util), _initClass$4();
7984
- }
7985
- }();
7986
- var Util = _Util;
7615
+ class Util extends Metadata {
7616
+ static $$id = "Util";
7617
+ }
7618
+ registerComponent(Util, [{
7619
+ metadataKind: "class",
7620
+ metadataClass: component.$$metadataClass,
7621
+ metadataParam: undefined,
7622
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
7623
+ }, {
7624
+ metadataKind: "class",
7625
+ metadataClass: target.$$metadataClass,
7626
+ metadataParam: [Target.Type.Class],
7627
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
7628
+ }]);
7987
7629
 
7988
7630
  var util = createDecoratorExp(Util);
7989
7631
 
7990
- let _initClass$3;
7991
7632
  /**
7992
7633
  * @public
7993
7634
  */
7994
- let _Api;
7995
- new class extends _identity {
7996
- static [class Api extends Metadata {
7997
- static {
7998
- [_Api, _initClass$3] = _applyDecs2311(this, [target([Target.Type.Class]), util()], [], 0, void 0, Metadata).c;
7999
- }
8000
- }];
8001
- $$id = "Api";
8002
- constructor() {
8003
- super(_Api), _initClass$3();
8004
- }
8005
- }();
8006
- var Api = _Api;
7635
+ class Api extends Metadata {
7636
+ static $$id = "Api";
7637
+ }
7638
+ registerComponent(Api, [{
7639
+ metadataKind: "class",
7640
+ metadataClass: util.$$metadataClass,
7641
+ metadataParam: undefined,
7642
+ isPlaceholderDecoratorExp: util.$$isPlaceholderDecoratorExp
7643
+ }, {
7644
+ metadataKind: "class",
7645
+ metadataClass: target.$$metadataClass,
7646
+ metadataParam: [Target.Type.Class],
7647
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
7648
+ }]);
8007
7649
 
8008
7650
  var api = createDecoratorExp(Api);
8009
7651
 
8010
- let _initClass$2;
8011
7652
  /**
8012
7653
  * @public
8013
7654
  */
8014
- let _Flow;
8015
- new class extends _identity {
8016
- static [class Flow extends Metadata {
8017
- static {
8018
- [_Flow, _initClass$2] = _applyDecs2311(this, [target([Target.Type.Class]), component(), scope(exports.SCOPE.Prototype)], [], 0, void 0, Metadata).c;
8019
- }
8020
- }];
8021
- $$id = "Flow";
8022
- constructor() {
8023
- super(_Flow), _initClass$2();
8024
- }
8025
- }();
8026
- var Flow = _Flow;
8027
-
8028
- var flow = createDecoratorExp(Flow);
7655
+ class Service extends Metadata {
7656
+ static $$id = "Service";
7657
+ }
7658
+ registerComponent(Service, [{
7659
+ metadataKind: "class",
7660
+ metadataClass: scope.$$metadataClass,
7661
+ metadataParam: exports.SCOPE.Prototype,
7662
+ isPlaceholderDecoratorExp: scope.$$isPlaceholderDecoratorExp
7663
+ }, {
7664
+ metadataKind: "class",
7665
+ metadataClass: component.$$metadataClass,
7666
+ metadataParam: undefined,
7667
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
7668
+ }, {
7669
+ metadataKind: "class",
7670
+ metadataClass: target.$$metadataClass,
7671
+ metadataParam: [Target.Type.Class],
7672
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
7673
+ }]);
7674
+
7675
+ var service = createDecoratorExp(Service);
8029
7676
 
8030
- let _initClass$1;
8031
7677
  // TODO: view 包添加 viewData装饰器
8032
7678
  /**
8033
7679
  * @public
8034
7680
  */
8035
- let _GlobalData;
8036
- new class extends _identity {
8037
- static [class GlobalData extends Metadata {
8038
- static {
8039
- [_GlobalData, _initClass$1] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
8040
- }
8041
- }];
8042
- $$id = "GlobalData";
8043
- constructor() {
8044
- super(_GlobalData), _initClass$1();
8045
- }
8046
- }();
8047
- var GlobalData = _GlobalData;
7681
+ class GlobalData extends Metadata {
7682
+ static $$id = "GlobalData";
7683
+ }
7684
+ registerComponent(GlobalData, [{
7685
+ metadataKind: "class",
7686
+ metadataClass: component.$$metadataClass,
7687
+ metadataParam: undefined,
7688
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
7689
+ }, {
7690
+ metadataKind: "class",
7691
+ metadataClass: target.$$metadataClass,
7692
+ metadataParam: [Target.Type.Class],
7693
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
7694
+ }]);
8048
7695
 
8049
7696
  var globalData = createDecoratorExp(GlobalData);
8050
7697
 
8051
- let _initClass;
8052
7698
  /**
8053
7699
  * @public
8054
7700
  */
8055
- let _WebApplication;
8056
- new class extends _identity {
8057
- static [class WebApplication extends Metadata {
8058
- static {
8059
- [_WebApplication, _initClass] = _applyDecs2311(this, [target([Target.Type.Class]), configuration()], [], 0, void 0, Metadata).c;
8060
- }
8061
- }];
8062
- $$id = "WebApplication";
8063
- constructor() {
8064
- super(_WebApplication), _initClass();
8065
- }
8066
- }();
8067
- var WebApplication = _WebApplication;
7701
+ class WebApplication extends Metadata {
7702
+ static $$id = "WebApplication";
7703
+ }
7704
+ registerComponent(WebApplication, [{
7705
+ metadataKind: "class",
7706
+ metadataClass: configuration.$$metadataClass,
7707
+ metadataParam: undefined,
7708
+ isPlaceholderDecoratorExp: configuration.$$isPlaceholderDecoratorExp
7709
+ }, {
7710
+ metadataKind: "class",
7711
+ metadataClass: target.$$metadataClass,
7712
+ metadataParam: [Target.Type.Class],
7713
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
7714
+ }]);
8068
7715
 
8069
7716
  var webApplication = createDecoratorExp(WebApplication);
8070
7717
 
@@ -8077,16 +7724,15 @@ exports.Component = Component;
8077
7724
  exports.Configuration = Configuration;
8078
7725
  exports.ConstructorInject = ConstructorInject;
8079
7726
  exports.Cookie = Cookie;
8080
- exports.Flow = Flow;
8081
7727
  exports.GlobalData = GlobalData;
8082
- exports.HistoryRouter = _HistoryRouter_default;
7728
+ exports.HistoryRouter = HistoryRouter;
8083
7729
  exports.Id = Id;
8084
7730
  exports.KindClass = KindClass;
8085
7731
  exports.KindField = KindField;
8086
7732
  exports.KindMethod = KindMethod;
8087
7733
  exports.Layout = Layout;
8088
- exports.LocalStorage = _LocalStorage_default;
8089
- exports.LocalStorageMeta = LocalStorage;
7734
+ exports.LocalStorage = LocalStorage;
7735
+ exports.LocalStorageMeta = LocalStorage$1;
8090
7736
  exports.Memoized = Memoized;
8091
7737
  exports.Metadata = Metadata;
8092
7738
  exports.Page = Page;
@@ -8098,30 +7744,31 @@ exports.Ref = Ref$1;
8098
7744
  exports.Refs = Refs;
8099
7745
  exports.Render = Render;
8100
7746
  exports.Route = Route;
8101
- exports.RouteMeta = RouteMeta;
7747
+ exports.RouteMeta = Route$1;
8102
7748
  exports.Router = Router;
8103
7749
  exports.RouterMeta = Router$1;
8104
7750
  exports.Scope = Scope;
8105
- exports.SessionStorage = _SessionStorage_default;
8106
- exports.SessionStorageMeta = SessionStorage;
7751
+ exports.Service = Service;
7752
+ exports.SessionStorage = SessionStorage;
7753
+ exports.SessionStorageMeta = SessionStorage$1;
8107
7754
  exports.Store = Store;
8108
7755
  exports.Target = Target;
8109
7756
  exports.Util = Util;
8110
7757
  exports.Value = Value;
8111
7758
  exports.View = View;
8112
7759
  exports.WebApplication = WebApplication;
8113
- exports.WebRender = _WebRender_default;
7760
+ exports.WebRender = WebRender;
8114
7761
  exports.api = api;
8115
7762
  exports.autowired = autowired;
8116
7763
  exports.bind = bind;
7764
+ exports.bindPlaceholderMetadataClass = bindPlaceholderMetadataClass;
8117
7765
  exports.component = component;
8118
7766
  exports.configuration = configuration;
8119
7767
  exports.constructorInject = constructorInject;
8120
7768
  exports.cookie = cookie;
8121
7769
  exports.createDecoratorExp = createDecoratorExp;
8122
- exports.createPlaceholderDecoratorExp = createPlaceholderDecoratorExp;
8123
7770
  exports.definePublisher = definePublisher;
8124
- exports.flow = flow;
7771
+ exports.getRegistry = getRegistry;
8125
7772
  exports.globalData = globalData;
8126
7773
  exports.id = id;
8127
7774
  exports.jsx = jsx;
@@ -8129,13 +7776,16 @@ exports.jsxs = jsx;
8129
7776
  exports.layout = layout;
8130
7777
  exports.localStorage = localStorageDecorator;
8131
7778
  exports.memoized = memoized;
7779
+ exports.metadataFor = metadataFor;
8132
7780
  exports.page = page;
8133
7781
  exports.qualifier = qualifier;
8134
7782
  exports.reactive = reactive;
8135
7783
  exports.ref = ref;
8136
7784
  exports.refs = refs;
7785
+ exports.registerComponent = registerComponent;
8137
7786
  exports.route = route;
8138
7787
  exports.scope = scope;
7788
+ exports.service = service;
8139
7789
  exports.sessionStorage = sessionStorageDecorator;
8140
7790
  exports.store = store;
8141
7791
  exports.target = target;