annil 1.0.0 → 1.0.1

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.
Files changed (133) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +8 -2
  3. package/dist/api/DefineComponent/ReturnType/test/normalComponentDoc.test.js.map +1 -1
  4. package/dist/api/DefineComponent/ReturnType/test/normalPageDoc.test.js.map +1 -1
  5. package/dist/api/DefineComponent/index.js +18 -13
  6. package/dist/api/DefineComponent/index.js.map +1 -1
  7. package/dist/api/RootComponent/Lifetimes/LifetimesConstraint.d.ts +4 -1
  8. package/dist/api/RootComponent/Properties/{expected/normalEmpty.js → test/normalEmpty.test.js} +1 -1
  9. package/dist/api/RootComponent/Properties/test/normalEmpty.test.js.map +1 -0
  10. package/dist/api/RootComponent/Watch/test/WatchProperties.test.js +1 -1
  11. package/dist/api/RootComponent/Watch/test/WatchProperties.test.js.map +1 -1
  12. package/dist/api/SubComponent/SubComputed/test/normal.test.js.map +1 -1
  13. package/dist/api/SubComponent/SubData/test/error.test.js.map +1 -1
  14. package/dist/api/SubComponent/SubData/test/normal.test.js.map +1 -1
  15. package/dist/api/SubComponent/SubInstance/test/normal.test.js.map +1 -1
  16. package/dist/api/SubComponent/SubPageLifetimes/test/normal.test.js.map +1 -1
  17. package/dist/api/SubComponent/SubWatch/test/WatchRootData.test.js.map +1 -1
  18. package/dist/api/SubComponent/index.d.ts +1 -1
  19. package/dist/api/SubComponent/index.js.map +1 -1
  20. package/dist/behaviors/BComputedAndWatch/data-tracer.js +0 -3
  21. package/dist/behaviors/BComputedAndWatch/data-tracer.js.map +1 -1
  22. package/dist/behaviors/BComputedAndWatch/index.js +2 -1
  23. package/dist/behaviors/BComputedAndWatch/index.js.map +1 -1
  24. package/dist/behaviors/BComputedAndWatch/initComputed.js +3 -11
  25. package/dist/behaviors/BComputedAndWatch/initComputed.js.map +1 -1
  26. package/dist/behaviors/BComputedAndWatch/isEqual.js.map +1 -1
  27. package/dist/behaviors/BStore.js.map +1 -1
  28. package/dist/behaviors/BbeforeCreated.js.map +1 -1
  29. package/dist/types/GetComponentPrefix.js +1 -4
  30. package/dist/types/GetComponentPrefix.js.map +1 -1
  31. package/dist/types/ReplacePrefix.js +1 -4
  32. package/dist/types/ReplacePrefix.js.map +1 -1
  33. package/dist/utils/InternalFieldProtection.d.ts +2 -0
  34. package/dist/utils/InternalFieldProtection.js +11 -0
  35. package/dist/utils/InternalFieldProtection.js.map +1 -0
  36. package/dist/utils/collector.d.ts +5 -0
  37. package/dist/utils/collector.js +21 -0
  38. package/dist/utils/collector.js.map +1 -0
  39. package/dist/utils/createdHijack.d.ts +0 -0
  40. package/dist/utils/createdHijack.js +2 -0
  41. package/dist/utils/createdHijack.js.map +1 -0
  42. package/dist/utils/customEventsHandle.d.ts +2 -0
  43. package/dist/utils/customEventsHandle.js +20 -0
  44. package/dist/utils/customEventsHandle.js.map +1 -0
  45. package/dist/utils/eventsHandle.d.ts +2 -0
  46. package/dist/utils/eventsHandle.js +5 -0
  47. package/dist/utils/eventsHandle.js.map +1 -0
  48. package/dist/utils/funcConfigHandle.d.ts +2 -0
  49. package/dist/utils/funcConfigHandle.js +18 -0
  50. package/dist/utils/funcConfigHandle.js.map +1 -0
  51. package/dist/utils/onLoadHijack.d.ts +3 -0
  52. package/dist/utils/onLoadHijack.js +16 -0
  53. package/dist/utils/onLoadHijack.js.map +1 -0
  54. package/dist/utils/onLoadReceivedDataHandle.d.ts +3 -0
  55. package/dist/utils/onLoadReceivedDataHandle.js +14 -0
  56. package/dist/utils/onLoadReceivedDataHandle.js.map +1 -0
  57. package/dist/utils/rootComponentFieldHandle.d.ts +3 -0
  58. package/dist/utils/rootComponentFieldHandle.js +13 -0
  59. package/dist/utils/rootComponentFieldHandle.js.map +1 -0
  60. package/dist/utils/subComponentsHandle.d.ts +3 -0
  61. package/dist/utils/subComponentsHandle.js +12 -0
  62. package/dist/utils/subComponentsHandle.js.map +1 -0
  63. package/package.json +4 -3
  64. package/src/api/DefineComponent/ReturnType/test/normalComponentDoc.test.ts +2 -1
  65. package/src/api/DefineComponent/ReturnType/test/normalPageDoc.test.ts +2 -1
  66. package/src/api/DefineComponent/index.ts +27 -22
  67. package/src/api/RootComponent/Computed/test/normal.test.ts +1 -1
  68. package/src/api/RootComponent/Lifetimes/LifetimesConstraint.ts +8 -7
  69. package/src/api/RootComponent/PageLifetimes/test/normal.test.ts +1 -1
  70. package/src/api/RootComponent/Watch/test/WatchComputed.test.ts +1 -1
  71. package/src/api/RootComponent/Watch/test/WatchData.test.ts +1 -1
  72. package/src/api/RootComponent/Watch/test/WatchProperties.test.ts +8 -2
  73. package/src/api/SubComponent/SubComputed/test/normal.test.ts +2 -1
  74. package/src/api/SubComponent/SubData/test/error.test.ts +2 -1
  75. package/src/api/SubComponent/SubData/test/normal.test.ts +2 -1
  76. package/src/api/SubComponent/SubInstance/test/normal.test.ts +2 -1
  77. package/src/api/SubComponent/SubPageLifetimes/test/normal.test.ts +2 -1
  78. package/src/api/SubComponent/SubWatch/test/WatchRootData.test.ts +2 -1
  79. package/src/api/SubComponent/SubWatch/test/error.test.ts +1 -1
  80. package/src/api/SubComponent/index.ts +9 -1
  81. package/src/behaviors/BComputedAndWatch/data-tracer.ts +0 -3
  82. package/src/behaviors/BComputedAndWatch/index.ts +8 -4
  83. package/src/behaviors/BComputedAndWatch/initComputed.ts +25 -18
  84. package/src/behaviors/BComputedAndWatch/isEqual.ts +1 -0
  85. package/src/behaviors/BStore.ts +3 -1
  86. package/src/behaviors/BbeforeCreated.ts +3 -1
  87. package/src/types/GetComponentPrefix.ts +11 -11
  88. package/src/types/ReplacePrefix.ts +9 -10
  89. package/src/utils/InternalFieldProtection.ts +18 -0
  90. package/src/utils/collector.ts +41 -0
  91. package/src/utils/createdHijack.ts +21 -0
  92. package/src/utils/customEventsHandle.ts +31 -0
  93. package/src/utils/eventsHandle.ts +10 -0
  94. package/src/utils/funcConfigHandle.ts +30 -0
  95. package/src/utils/onLoadHijack.ts +30 -0
  96. package/src/utils/onLoadReceivedDataHandle.ts +31 -0
  97. package/src/utils/rootComponentFieldHandle.ts +27 -0
  98. package/src/utils/subComponentsHandle.ts +25 -0
  99. package/dist/api/RootComponent/Data/expected/error.js +0 -10
  100. package/dist/api/RootComponent/Data/expected/error.js.map +0 -1
  101. package/dist/api/RootComponent/Data/expected/normal.d.ts +0 -1
  102. package/dist/api/RootComponent/Data/expected/normal.js +0 -33
  103. package/dist/api/RootComponent/Data/expected/normal.js.map +0 -1
  104. package/dist/api/RootComponent/Properties/expected/error.d.ts +0 -1
  105. package/dist/api/RootComponent/Properties/expected/error.js +0 -38
  106. package/dist/api/RootComponent/Properties/expected/error.js.map +0 -1
  107. package/dist/api/RootComponent/Properties/expected/normalEmpty.d.ts +0 -1
  108. package/dist/api/RootComponent/Properties/expected/normalEmpty.js.map +0 -1
  109. package/dist/api/RootComponent/Properties/expected/normalOptional.d.ts +0 -1
  110. package/dist/api/RootComponent/Properties/expected/normalOptional.js +0 -80
  111. package/dist/api/RootComponent/Properties/expected/normalOptional.js.map +0 -1
  112. package/dist/api/RootComponent/Properties/expected/normalRequired.d.ts +0 -69
  113. package/dist/api/RootComponent/Properties/expected/normalRequired.js +0 -44
  114. package/dist/api/RootComponent/Properties/expected/normalRequired.js.map +0 -1
  115. package/dist/api/RootComponent/Properties/test/normalEmpty.test..d.ts +0 -1
  116. package/dist/api/RootComponent/Properties/test/normalEmpty.test..js +0 -20
  117. package/dist/api/RootComponent/Properties/test/normalEmpty.test..js.map +0 -1
  118. package/dist/types/RestorePropTypeOfList.d.ts +0 -2
  119. package/dist/types/RestorePropTypeOfList.js +0 -3
  120. package/dist/types/RestorePropTypeOfList.js.map +0 -1
  121. package/dist/utils/preprocessingOptions.d.ts +0 -18
  122. package/dist/utils/preprocessingOptions.js +0 -184
  123. package/dist/utils/preprocessingOptions.js.map +0 -1
  124. package/src/api/RootComponent/Data/expected/error.ts +0 -14
  125. package/src/api/RootComponent/Data/expected/normal.ts +0 -68
  126. package/src/api/RootComponent/Properties/expected/error.ts +0 -49
  127. package/src/api/RootComponent/Properties/expected/normalEmpty.ts +0 -33
  128. package/src/api/RootComponent/Properties/expected/normalOptional.ts +0 -136
  129. package/src/api/RootComponent/Properties/expected/normalRequired.ts +0 -100
  130. package/src/types/RestorePropTypeOfList.ts +0 -20
  131. package/src/utils/preprocessingOptions.ts +0 -334
  132. /package/dist/api/RootComponent/{Data/expected/error.d.ts → Properties/test/normalEmpty.test.d.ts} +0 -0
  133. /package/src/api/RootComponent/Properties/test/{normalEmpty.test..ts → normalEmpty.test.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rootComponentFieldHandle.js","sourceRoot":"","sources":["../../src/utils/rootComponentFieldHandle.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,UAAU,wBAAwB,CACtC,mBAAqC,EACrC,gBAAkC,EAClC,UAAsB;IAEtB,mBAAmB,CAAC,YAAY,IAAI,kBAAkB,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,YAAY,CAAC,CAAC;IAE3G,mBAAmB,CAAC,MAAM,IAAI,YAAY,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAIzF,mBAAmB,CAAC,aAAa;WAC5B,iBAAiB,CAAC,mBAAmB,CAAC,aAAa,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC;IAEvF,mBAAmB,CAAC,SAAS,IAAI,iBAAiB,CAAC,mBAAmB,CAAC,SAAS,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;IAE3G,mBAAmB,CAAC,KAAK,IAAI,iBAAiB,CAAC,mBAAmB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAE/F,iBAAiB,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ComponentOptions, FuncConfig } from "../api/DefineComponent";
2
+ import type { SubComponentOptions } from "../api/SubComponent";
3
+ export declare function subComponentsHandle(componentOptions: ComponentOptions, subComponents: SubComponentOptions[], funcConfig: FuncConfig): void;
@@ -0,0 +1,12 @@
1
+ import { funcFieldsCollect, otherFieldsHandle } from "./collector";
2
+ import { eventsHandle } from "./eventsHandle";
3
+ export function subComponentsHandle(componentOptions, subComponents, funcConfig) {
4
+ subComponents.forEach((subOption) => {
5
+ subOption.events && eventsHandle(componentOptions, subOption.events);
6
+ subOption.pageLifetimes && funcFieldsCollect(subOption.pageLifetimes, funcConfig, "pageLifetimes");
7
+ subOption.lifetimes && funcFieldsCollect(subOption.lifetimes, funcConfig, "lifetimes");
8
+ subOption.watch && funcFieldsCollect(subOption.watch, funcConfig, "watch");
9
+ otherFieldsHandle(componentOptions, subOption);
10
+ });
11
+ }
12
+ //# sourceMappingURL=subComponentsHandle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subComponentsHandle.js","sourceRoot":"","sources":["../../src/utils/subComponentsHandle.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,UAAU,mBAAmB,CACjC,gBAAkC,EAClC,aAAoC,EACpC,UAAsB;IAEtB,aAAa,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;QAClC,SAAS,CAAC,MAAM,IAAI,YAAY,CAAC,gBAAgB,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QAIrE,SAAS,CAAC,aAAa,IAAI,iBAAiB,CAAC,SAAS,CAAC,aAAa,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC;QAEnG,SAAS,CAAC,SAAS,IAAI,iBAAiB,CAAC,SAAS,CAAC,SAAS,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QAEvF,SAAS,CAAC,KAAK,IAAI,iBAAiB,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;QAE3E,iBAAiB,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "annil",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "微信小程序(原生开发)插件",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
- "jest": "jest --watch",
7
+ "test": "jest --watch",
8
+ "coverage": "jest --collectCoverage",
8
9
  "prepare": "husky install",
9
10
  "lint": "eslint . --fix && npm run fmt",
10
11
  "fmt": "dprint fmt",
11
- "test": "tsc --watch",
12
+ "type": "tsc --watch",
12
13
  "build": "tsc -p tsconfig.build.json"
13
14
  },
14
15
  "devDependencies": {
@@ -11,8 +11,9 @@ import type {
11
11
  CaptureComposed,
12
12
  Composed,
13
13
  } from "../../../RootComponent/CustomEvents/CustomEventsTag";
14
- import type { Mock_User } from "../../../RootComponent/Properties/expected/normalRequired";
14
+
15
15
  import type { PropertiesConstraint } from "../../../RootComponent/Properties/PropertiesConstraint";
16
+ import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
16
17
  import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
17
18
  import type { SubComponentDoc } from "../../../SubComponent/SubComponentDoc";
18
19
  import { DefineComponent } from "../..";
@@ -1,6 +1,7 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
  import { RootComponent, type SpecificType } from "../../../..";
3
- import type { Mock_User } from "../../../RootComponent/Properties/expected/normalRequired";
3
+
4
+ import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
4
5
  import { DefineComponent } from "../..";
5
6
 
6
7
  const OnlyPropsRootDoc = RootComponent()({
@@ -5,15 +5,11 @@ import { BComputedAndWatch } from "../../behaviors/BComputedAndWatch";
5
5
  import { initComputed } from "../../behaviors/BComputedAndWatch/initComputed";
6
6
  import { BStore } from "../../behaviors/BStore";
7
7
  import type { WMComponent, WMCompPageLifetimes, WMPageLifetimes } from "../../types/OfficialTypeAlias";
8
+ import { funcConfigHandle } from "../../utils/funcConfigHandle";
8
9
  import { isEmptyObject } from "../../utils/isEmptyObject";
9
- import {
10
- excludeFields,
11
- funcConfigHandle,
12
- onLoadHijack,
13
- onLoadReceivedDataHandle,
14
- rootComponentFieldHandle,
15
- subComponentsHandle,
16
- } from "../../utils/preprocessingOptions";
10
+ import { onLoadReceivedDataHandle } from "../../utils/onLoadReceivedDataHandle";
11
+ import { rootComponentFieldHandle } from "../../utils/rootComponentFieldHandle";
12
+ import { subComponentsHandle } from "../../utils/subComponentsHandle";
17
13
  import type { LifetimesConstraint } from "../RootComponent/Lifetimes/LifetimesConstraint";
18
14
  import type { RootComponentDoc } from "../RootComponent/RootComponentDoc";
19
15
  import type { SubComponentDoc } from "../SubComponent/SubComponentDoc";
@@ -23,6 +19,9 @@ import type { CreatePageDoc } from "./ReturnType/CreatePageDoc";
23
19
  import type { RootComponentOption } from "./RootComponent/RootComponentOption";
24
20
  import type { SubComponentsOption } from "./SubComponents/SubComponentsOption";
25
21
 
22
+ import { InternalFieldProtection } from "../../utils/InternalFieldProtection";
23
+ import { onLoadHijack } from "../../utils/onLoadHijack";
24
+
26
25
  type RootOptions<
27
26
  TRootComponentDoc extends RootComponentDoc,
28
27
  TSubComponentTuple extends SubComponentDoc[],
@@ -92,8 +91,9 @@ export type DefineComponentOptions = {
92
91
  export const DefineComponent: DefineComponentConstructor = function(options): any {
93
92
  // console.log("------------------------------------------------分割线------------------------------------------------");
94
93
 
95
- // 最终的配置
96
- const componentOptions: ComponentOptions = {
94
+ // 最终的配置,默认配置与根组件和子组件列表配置汇集而成。
95
+ const finalOptions: ComponentOptions = {
96
+ // default options
97
97
  options: {
98
98
  // addGlobalClass: true,
99
99
  multipleSlots: true,
@@ -104,31 +104,36 @@ export const DefineComponent: DefineComponentConstructor = function(options): an
104
104
  behaviors: [BStore, BComputedAndWatch],
105
105
  };
106
106
  /**
107
- * 有些选项配置是函数,且可能分布在根组件和子组件中,tempConfig 用于收集这些配置,最终再一起整合进componentOptions配置。rootComponentHandle和subComponentsHandle都会收集配置,funcConfigHandle整理配置。
107
+ * 有些选项配置是函数,且可能分布在根组件和子组件中,funcConfig 用于收集这些配置,最终再一起整合进finalOptions配置。rootComponentHandle和subComponentsHandle都会收集函数配置到funcConfig中,再由funcConfigHandle整合配置到finalOptions中。
108
108
  */
109
- const funcConfig: FuncConfig = {};
109
+ const allFuncConfig: FuncConfig = {};
110
110
 
111
111
  if (options.rootComponent && !isEmptyObject(options.rootComponent)) {
112
- rootComponentFieldHandle(options.rootComponent, componentOptions, funcConfig);
112
+ rootComponentFieldHandle(options.rootComponent, finalOptions, allFuncConfig);
113
113
  }
114
114
 
115
115
  if (options.subComponents && !isEmptyObject(options.subComponents)) {
116
- subComponentsHandle(componentOptions, options.subComponents, funcConfig);
116
+ subComponentsHandle(finalOptions, options.subComponents, allFuncConfig);
117
117
  }
118
- if (!isEmptyObject(funcConfig)) {
119
- funcConfigHandle(componentOptions, options.rootComponent?.isPage, funcConfig);
118
+ // 框架无法测试页面
119
+ /* istanbul ignore next */
120
+ if (!isEmptyObject(allFuncConfig)) {
121
+ funcConfigHandle(finalOptions, options.rootComponent?.isPage, allFuncConfig);
120
122
  }
121
123
 
122
- componentOptions.methods && excludeFields(componentOptions.methods, ["disposer", "applySetData"]);
124
+ finalOptions.methods && InternalFieldProtection(finalOptions.methods);
123
125
 
124
- componentOptions.behaviors!.push(BBeforeCreate);
126
+ finalOptions.behaviors!.push(BBeforeCreate);
125
127
 
126
- onLoadHijack(componentOptions, [onLoadReceivedDataHandle, initComputed], []);
128
+ onLoadHijack(finalOptions, [onLoadReceivedDataHandle, initComputed], []);
127
129
 
128
- if (componentOptions.isPage) {
129
- Reflect.deleteProperty(componentOptions.options!, "virtualHost");
130
+ // 框架无法测试页面
131
+ /* istanbul ignore next */
132
+ if (finalOptions.isPage) {
133
+ Reflect.deleteProperty(finalOptions.options!, "virtualHost");
130
134
  }
131
- Component(componentOptions as any);
135
+
136
+ Component(finalOptions as any);
132
137
  };
133
138
 
134
139
  export type PageOptions = {
@@ -2,7 +2,7 @@ import { Checking, type Test } from "hry-types";
2
2
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
3
3
  import type { SpecificType } from "../../../../types/SpecificType";
4
4
  import { RootComponent } from "../..";
5
- import type { Mock_User } from "../../Properties/expected/normalRequired";
5
+ import type { Mock_User } from "../../Properties/test/normalRequired.test";
6
6
 
7
7
  /**
8
8
  * computed字段约束为 [ComputedConstraint](../ComputedConstraint.ts)
@@ -1,10 +1,11 @@
1
1
  import type { WMCompLifetimes } from "../../../types/OfficialTypeAlias";
2
+ import type { ComponentOptions } from "../../DefineComponent";
2
3
 
3
4
  export type LifetimesConstraint = // 官方组件生命周期
4
- WMCompLifetimes["lifetimes"];
5
- // & {
6
- // /**
7
- // * 建立组件时的真正配置对象
8
- // */
9
- // beforeCreate?: (options: WMTrivialOption<any, any, any, any, false>) => void;
10
- // };
5
+ & WMCompLifetimes["lifetimes"]
6
+ & {
7
+ /**
8
+ * 建立组件时的真正配置对象
9
+ */
10
+ beforeCreate?: (options: ComponentOptions) => void;
11
+ };
@@ -2,7 +2,7 @@ import { Checking, type Test } from "hry-types";
2
2
  import { RootComponent, type SpecificType } from "../../../..";
3
3
 
4
4
  import type { RemoveNullOfRequired } from "../../../../types/RemoveNullOfRequired";
5
- import type { Mock_User } from "../../Properties/expected/normalRequired";
5
+ import type { Mock_User } from "../../Properties/test/normalRequired.test";
6
6
 
7
7
  /**
8
8
  * 组件时
@@ -2,7 +2,7 @@ import { Checking, type Test } from "hry-types";
2
2
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
3
3
  import type { SpecificType } from "../../../../types/SpecificType";
4
4
  import { RootComponent } from "../..";
5
- import { type Mock_User } from "../../Properties/expected/normalRequired";
5
+ import type { Mock_User } from "../../Properties/test/normalRequired.test";
6
6
 
7
7
  /**
8
8
  * 1 computed字段时需要手写类型,可悬停鼠标到key查看类型,深度只读
@@ -3,7 +3,7 @@ import { Checking, type Test } from "hry-types";
3
3
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
4
4
  import { observable } from "mobx";
5
5
  import { RootComponent } from "../..";
6
- import type { Mock_User } from "../../Properties/expected/normalRequired";
6
+ import type { Mock_User } from "../../Properties/test/normalRequired.test";
7
7
 
8
8
  const obj = observable({
9
9
  gender: <"male" | "female"> "male",
@@ -4,13 +4,19 @@ import type { ReadonlyDeep } from "hry-types/src/Any/_api";
4
4
  import { RootComponent } from "../..";
5
5
 
6
6
  import type { SpecificType } from "../../../..";
7
+ // import {
8
+ // type Mock_Cart,
9
+ // mock_requiredTypes,
10
+ // mock_requiredUnion,
11
+ // type Mock_User,
12
+ // } from "../../Properties/expected/normalRequired";
13
+ import type { OptionalType } from "../../Properties/PropertiesConstraint";
7
14
  import {
8
15
  type Mock_Cart,
9
16
  mock_requiredTypes,
10
17
  mock_requiredUnion,
11
18
  type Mock_User,
12
- } from "../../Properties/expected/normalRequired";
13
- import type { OptionalType } from "../../Properties/PropertiesConstraint";
19
+ } from "../../Properties/test/normalRequired.test";
14
20
  const mock_optional = {
15
21
  optional_num: {
16
22
  type: Number,
@@ -1,7 +1,8 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
3
3
  import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
4
- import type { Mock_User } from "../../../RootComponent/Properties/expected/normalRequired";
4
+
5
+ import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
5
6
  import { SubComponent } from "../..";
6
7
 
7
8
  type OnlyCustomCompDoc = ComponentDoc<{
@@ -1,5 +1,6 @@
1
1
  import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
2
- import type { Mock_User } from "../../../RootComponent/Properties/expected/normalRequired";
2
+
3
+ import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
3
4
  import { SubComponent } from "../..";
4
5
 
5
6
  type OnlyCustomCompDoc = ComponentDoc<{
@@ -3,7 +3,8 @@ import type { ReadonlyDeep } from "hry-types/src/Any/_api";
3
3
  import type { Wm } from "../../../../thirdLib";
4
4
  import type { CompDocExtends } from "../../../../types/CompDocExtends";
5
5
  import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
6
- import type { Mock_User } from "../../../RootComponent/Properties/expected/normalRequired";
6
+
7
+ import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
7
8
  import { SubComponent } from "../..";
8
9
 
9
10
  type CompDoc = ComponentDoc<{
@@ -1,7 +1,8 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
3
3
  import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
4
- import type { Mock_User } from "../../../RootComponent/Properties/expected/normalRequired";
4
+
5
+ import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
5
6
  import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
6
7
  import { SubComponent } from "../..";
7
8
 
@@ -1,5 +1,6 @@
1
1
  import { Checking, type Test } from "hry-types";
2
- import type { Mock_User } from "../../../RootComponent/Properties/expected/normalRequired";
2
+
3
+ import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
3
4
  import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
4
5
  import { SubComponent } from "../..";
5
6
 
@@ -2,7 +2,8 @@ import { Checking, type Test } from "hry-types";
2
2
 
3
3
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
4
4
  import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
5
- import type { Mock_User } from "../../../RootComponent/Properties/expected/normalRequired";
5
+
6
+ import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
6
7
  import { SubComponent } from "../..";
7
8
 
8
9
  type TestObj = {
@@ -1,4 +1,4 @@
1
- import type { Wm } from "../../../../thirdLib";
1
+ import type { Wm } from "../../../..";
2
2
  import { SubComponent } from "../..";
3
3
 
4
4
  // 测试1
@@ -153,7 +153,15 @@ type SubComponentConstructor<
153
153
  & InheritDoc
154
154
  & SubDataDoc
155
155
  & SubStoreDoc
156
- & SubComputedDoc
156
+ // 改用SubComputedDoc是会报错的
157
+ & IfExtends<
158
+ SubComputedConstraint<
159
+ Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)>
160
+ >,
161
+ TSubComputed,
162
+ {},
163
+ GetSubComputedDoc<TSubComputed>
164
+ >
157
165
  )
158
166
  >,
159
167
  >(
@@ -6,9 +6,6 @@ export function deepProxy(
6
6
  basePath: string[] = [],
7
7
  ): object {
8
8
  const handler = {
9
- set() {
10
- throw Error("计算属性中不可以改变data对象的值");
11
- },
12
9
  get(target: object, prop: string) {
13
10
  // // 得到原始的对象 在unwrap时使用
14
11
  // console.log(target, prop);
@@ -28,7 +28,10 @@ export const BComputedAndWatch = Behavior({
28
28
 
29
29
  // computed handle
30
30
  if (computedConfig && !isEmptyObject(computedConfig)) {
31
- const methodsConfig = options.methods ||= {};
31
+ /* istanbul ignore next */
32
+ options.methods ||= {};
33
+
34
+ const methodsConfig = options.methods;
32
35
 
33
36
  // 把计算属性配置保留在methods的__computedConfig__字段下带入到组件实例中。
34
37
  methodsConfig.__computedConfig__ = () => computedConfig;
@@ -42,7 +45,7 @@ export const BComputedAndWatch = Behavior({
42
45
  switch (computedStatus) {
43
46
  case undefined:
44
47
  // 1 触发来自attach时或没有计算属性时
45
- originalFunc && originalFunc.call(this);
48
+ originalFunc && /* istanbul ignore next */ originalFunc.call(this);
46
49
 
47
50
  break;
48
51
  case "初始化中":
@@ -58,7 +61,7 @@ export const BComputedAndWatch = Behavior({
58
61
  this.__computedStatus__ = "更新完毕";
59
62
  } else {
60
63
  // 无需更新计算属性
61
- originalFunc && originalFunc.call(this);
64
+ originalFunc && /* istanbul ignore next */ originalFunc.call(this);
62
65
  }
63
66
  }
64
67
  break;
@@ -68,7 +71,7 @@ export const BComputedAndWatch = Behavior({
68
71
  // console.log("来自计算属性更新后的自身回调");
69
72
  this.__computedStatus__ = "待更新";
70
73
 
71
- originalFunc && originalFunc.call(this);
74
+ originalFunc && /* istanbul ignore next */ originalFunc.call(this);
72
75
  }
73
76
  break;
74
77
  }
@@ -78,6 +81,7 @@ export const BComputedAndWatch = Behavior({
78
81
  // watch handle
79
82
  const watchConfig = options.watch;
80
83
  if (watchConfig && !isEmptyObject(watchConfig)) {
84
+ /* istanbul ignore next */
81
85
  const methodsConfig = options.methods ||= {};
82
86
 
83
87
  // 把watch配置保留在methods的__watchConfig__字段下带入到组件实例中。
@@ -37,19 +37,21 @@ export function getComputedInfo(
37
37
  // 建立当前计算字段的依赖
38
38
  const dependences: ComputedDependence[] = [];
39
39
  let initValue: unknown;
40
- try {
41
- initValue = computedFunc.call({
42
- data: deepProxy(this.data, dependences),
43
- });
44
- } catch (error) {
45
- // 为js开发考虑使用了 this.data.xxx.age 当xxx为undefined时
46
- if (!isValidDependences(dependences, computedKeys)) {
47
- // 情况2 依赖了未初始化的计算属性的子属性(会报错) 见computed测试文件
48
- return false;
49
- }
50
- // 其他错误正常报错
51
- throw error;
52
- }
40
+ // try {
41
+ initValue = computedFunc.call({
42
+ data: deepProxy(this.data, dependences),
43
+ });
44
+ // } catch (error) {
45
+ // // 为js开发考虑使用了 this.data.xxx.age 当xxx为undefined时
46
+ // if (!isValidDependences(dependences, computedKeys)) {
47
+ // console.log(222);
48
+
49
+ // // 情形2 依赖了未初始化的计算属性的子属性(会报错) 对应测试文件[NoOptionalProperties.ts](../../../jest/computed/NoOptionalProperties/NoOptionalProperties.test.ts)的age字段
50
+ // return false;
51
+ // }
52
+ // // 其他错误正常报错
53
+ // throw error;
54
+ // }
53
55
  if (isValidDependences(dependences, computedKeys)) {
54
56
  // 有效的依赖
55
57
  initValue = unwrap(initValue);
@@ -60,7 +62,9 @@ export function getComputedInfo(
60
62
 
61
63
  return { dependences, value: initValue };
62
64
  } else {
63
- // 情况1 依赖了其他未初始化的计算属性(不报错) 见computed测试文件
65
+ /**
66
+ * 情形1 依赖了其他未初始化的计算属性(不报错) 对应测试文件[NoOptionalProperties.ts](../../../jest/computed/NoOptionalProperties/NoOptionalProperties.test.ts)的copyPropUser字段
67
+ */
64
68
  return false;
65
69
  }
66
70
  }
@@ -76,6 +80,7 @@ export function getComputedInfo(
76
80
  */
77
81
  function uniqueDependences(dependences: ComputedDependence[]): ComputedDependence[] {
78
82
  if (dependences.length === 1) return dependences;
83
+ // console.log(dependences);
79
84
 
80
85
  for (let f = 0; f < dependences.length; f++) {
81
86
  const firstPath = dependences[f].paths.join(".") + ".";
@@ -83,15 +88,17 @@ function uniqueDependences(dependences: ComputedDependence[]): ComputedDependenc
83
88
  const curPath = dependences[i].paths.join(".") + ".";
84
89
  // console.log(firstPath,curPath)
85
90
  if (firstPath.startsWith(curPath)) {
86
- // console.log('删除:',f)
87
- // 例如 path[0] = 'a.b.c',curPath = 'a.b'
91
+ // console.log("删除:", curPath, f);
92
+
93
+ // 例如 path[0] = 'a.b.c.',curPath = 'a.b.'
88
94
  dependences.splice(f, 1);
89
95
 
90
96
  return uniqueDependences(dependences);
91
97
  }
92
98
  if (curPath.startsWith(firstPath)) {
93
- // console.log('删除:',i)
94
- // 例如 curPath = 'a.b.c' path[0] = 'a.b',
99
+ // console.log("删除:", firstPath, i);
100
+
101
+ // 例如 curPath = 'a.b.' path[0] = 'a.b.c.',
95
102
  dependences.splice(i, 1);
96
103
 
97
104
  return uniqueDependences(dependences);
@@ -12,6 +12,7 @@ export function isEqual(value: unknown, other: unknown) {
12
12
  const keys1 = Object.keys(value);
13
13
  const keys2 = Object.keys(other);
14
14
  // 对象类型长度不等,一定不相等
15
+ /* istanbul ignore next */
15
16
  if (keys1.length !== keys2.length) {
16
17
  return false;
17
18
  }
@@ -15,6 +15,7 @@ export const BStore = Behavior({
15
15
  options.data[key] = toJS(storeConfig[key]());
16
16
 
17
17
  // 把响应式数据配置保留在methods的__storeConfig__字段下带入到组件实例中(不用函数返回方式也可以,但不符合methods字段类型),后续再从原型上删除。
18
+ /* istanbul ignore next */
18
19
  options.methods ||= {};
19
20
 
20
21
  options.methods.__storeConfig__ = () => storeConfig;
@@ -50,7 +51,8 @@ export const BStore = Behavior({
50
51
  deleteProtoField(this, "__storeConfig__");
51
52
  },
52
53
  detached(this: Instance) {
53
- // 清除store数据
54
+ // 清除store数据 test中模拟了测试,所以忽略 框架不支持 issue {@link https://github.com/wechat-miniprogram/miniprogram-simulate/issues/110}
55
+ /* istanbul ignore next */
54
56
  for (const key in this.disposer) {
55
57
  this.disposer[key]();
56
58
  }
@@ -1,5 +1,7 @@
1
+ import type { ComponentOptions } from "../api/DefineComponent";
2
+
1
3
  export const BBeforeCreate = Behavior({
2
- definitionFilter(options: any) {
4
+ definitionFilter(options: ComponentOptions) {
3
5
  // 触发beforeCreate生命周期函数
4
6
  const beforeCreateFunc = options.lifetimes?.beforeCreate;
5
7
 
@@ -1,4 +1,4 @@
1
- import { Checking, type Test } from "hry-types";
1
+ // import { Checking, type Test } from "hry-types";
2
2
  import type { IfExtends } from "hry-types/src/Any/IfExtends";
3
3
  import type { ComponentDoc } from "../api/DefineComponent/ReturnType/ComponentDoc";
4
4
 
@@ -14,21 +14,21 @@ export type ExtractDocPrefix<TComponentDoc extends ComponentDoc> = keyof IfExten
14
14
  > extends `${infer P}_${string}` ? P
15
15
  : "";
16
16
 
17
- type Test1 = ExtractDocPrefix<{ properties: { xxx_name: string } }>;
17
+ // type Test1 = ExtractDocPrefix<{ properties: { xxx_name: string } }>;
18
18
 
19
- type Test1Expect = "xxx";
19
+ // type Test1Expect = "xxx";
20
20
 
21
- Checking<Test1, Test1Expect, Test.Pass>;
21
+ // Checking<Test1, Test1Expect, Test.Pass>;
22
22
 
23
- type Test2 = ExtractDocPrefix<{ customEvents: { xxx_name: string } }>;
23
+ // type Test2 = ExtractDocPrefix<{ customEvents: { xxx_name: string } }>;
24
24
 
25
- type Test2Expect = "xxx";
25
+ // type Test2Expect = "xxx";
26
26
 
27
- Checking<Test2, Test2Expect, Test.Pass>;
27
+ // Checking<Test2, Test2Expect, Test.Pass>;
28
28
 
29
- // type lll = never extends `${infer P}_${string}` ? P: ""; // => string bug?
30
- type Test3 = ExtractDocPrefix<{}>;
29
+ // // type lll = never extends `${infer P}_${string}` ? P: ""; // => string bug?
30
+ // type Test3 = ExtractDocPrefix<{}>;
31
31
 
32
- type Test3Expect = string;
32
+ // type Test3Expect = string;
33
33
 
34
- Checking<Test3, Test3Expect, Test.Pass>;
34
+ // Checking<Test3, Test3Expect, Test.Pass>;
@@ -1,4 +1,3 @@
1
- import { Checking, type Test } from "hry-types";
2
1
  import type { IfExtends } from "hry-types/src/Any/IfExtends";
3
2
  import type { ComponentDoc } from "../api/DefineComponent/ReturnType/ComponentDoc";
4
3
  // import type { ComponentDoc } from "../api/DefineComponent/CreateDoc/ComponentDoc";
@@ -28,20 +27,20 @@ export type ReplacePrefix<TComponentDoc extends ComponentDoc, TPrefix extends st
28
27
  { customEvents: _ReplacePrefix<TComponentDoc["customEvents"], TPrefix> }
29
28
  >;
30
29
 
31
- type Test1 = ReplacePrefix<{ properties: { xxx_name: string } }, "xxxDaa">;
30
+ // type Test1 = ReplacePrefix<{ properties: { xxx_name: string } }, "xxxDaa">;
32
31
 
33
- type Test1Expect = { properties: { xxxDaa_name: string } };
32
+ // type Test1Expect = { properties: { xxxDaa_name: string } };
34
33
 
35
- Checking<Test1, Test1Expect, Test.Pass>;
34
+ // Checking<Test1, Test1Expect, Test.Pass>;
36
35
 
37
- type Test2 = ReplacePrefix<{ customEvents: { xxx_name: string } }, "xxxDaa">;
36
+ // type Test2 = ReplacePrefix<{ customEvents: { xxx_name: string } }, "xxxDaa">;
38
37
 
39
- type Test2Expect = { customEvents: { xxxDaa_name: string } };
38
+ // type Test2Expect = { customEvents: { xxxDaa_name: string } };
40
39
 
41
- Checking<Test2, Test2Expect, Test.Pass>;
40
+ // Checking<Test2, Test2Expect, Test.Pass>;
42
41
 
43
- type Test3 = ReplacePrefix<{}, "xxxDaa">;
42
+ // type Test3 = ReplacePrefix<{}, "xxxDaa">;
44
43
 
45
- type Test3Expect = {};
44
+ // type Test3Expect = {};
46
45
 
47
- Checking<Test3, Test3Expect, Test.Pass>;
46
+ // Checking<Test3, Test3Expect, Test.Pass>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 内部保护字段 即不允许配置的字段名(所有方法下)
3
+ */
4
+ export const INNERFIELDS = ["disposer"];
5
+
6
+ /**
7
+ * 报错的形式避免输入字段和内部字段冲突
8
+ */
9
+ /* istanbul ignore next */
10
+ export function InternalFieldProtection(methodsConfig: object) {
11
+ const fields = ["disposer"];
12
+ const methodsConfigKeys = Object.keys(methodsConfig);
13
+ for (const key of fields) {
14
+ if (methodsConfigKeys.includes(key)) {
15
+ throw Error(`${key}已被内部字段占用`);
16
+ }
17
+ }
18
+ }