@mybricks/to-code-taro 1.1.6 → 1.1.8

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 (35) hide show
  1. package/dist/cjs/generate/generateTaroProjectJson.js +45 -0
  2. package/dist/cjs/generate/utils/appConfig.js +1 -2
  3. package/dist/cjs/handleCom.js +1 -1
  4. package/dist/cjs/handleModule.js +6 -8
  5. package/dist/cjs/handleSlot.d.ts +1 -0
  6. package/dist/cjs/handleSlot.js +7 -4
  7. package/dist/cjs/processors/processModule.js +1 -0
  8. package/dist/cjs/processors/processSceneLogic.js +5 -1
  9. package/dist/cjs/taro-template.json +1061 -1057
  10. package/dist/cjs/toCodeTaro.js +89 -0
  11. package/dist/cjs/utils/logic/handleProcess.js +30 -18
  12. package/dist/cjs/utils/templates/component.js +1 -1
  13. package/dist/cjs/utils/templates/index.d.ts +2 -0
  14. package/dist/cjs/utils/templates/index.js +8 -3
  15. package/dist/cjs/utils/templates/renderManager.js +2 -6
  16. package/dist/cjs/utils/templates/scene.d.ts +1 -1
  17. package/dist/cjs/utils/templates/scene.js +8 -6
  18. package/dist/esm/generate/generateTaroProjectJson.js +41 -0
  19. package/dist/esm/generate/utils/appConfig.js +1 -2
  20. package/dist/esm/handleCom.js +1 -1
  21. package/dist/esm/handleModule.js +5 -7
  22. package/dist/esm/handleSlot.d.ts +1 -0
  23. package/dist/esm/handleSlot.js +11 -8
  24. package/dist/esm/processors/processModule.js +1 -0
  25. package/dist/esm/processors/processSceneLogic.js +4 -2
  26. package/dist/esm/taro-template.json +1061 -1057
  27. package/dist/esm/toCodeTaro.js +112 -0
  28. package/dist/esm/utils/logic/handleProcess.js +45 -17
  29. package/dist/esm/utils/templates/component.js +2 -2
  30. package/dist/esm/utils/templates/index.d.ts +2 -0
  31. package/dist/esm/utils/templates/index.js +6 -1
  32. package/dist/esm/utils/templates/renderManager.js +3 -5
  33. package/dist/esm/utils/templates/scene.d.ts +1 -1
  34. package/dist/esm/utils/templates/scene.js +6 -3
  35. package/package.json +1 -1
@@ -32,6 +32,16 @@ import { processModules } from "./processors/processModule";
32
32
  * Taro 代码生成主函数
33
33
  */
34
34
  var toCodeTaro = function toCodeTaro(tojson, config) {
35
+ // 将 modules 中的场景展开到 scenes 中,使 toCode 能识别并处理模块
36
+ if (tojson.modules) {
37
+ Object.values(tojson.modules).forEach(function (mod) {
38
+ if (mod.json) {
39
+ tojson.scenes.push(mod.json);
40
+ }
41
+ });
42
+ // 预处理:从 modules.json 重建 frames 中模块的事件数据
43
+ rebuildModuleFrames(tojson);
44
+ }
35
45
  return getCode({
36
46
  tojson: tojson,
37
47
  toCodejson: toCode(tojson)
@@ -60,6 +70,15 @@ var getCode = function getCode(params, config) {
60
70
 
61
71
  // 构建场景和事件映射
62
72
  var sceneMap = buildSceneMap(tojson.scenes);
73
+ // 将模块场景也加入 sceneMap,使 getSceneById 能查到模块
74
+ if (tojson.modules) {
75
+ Object.values(tojson.modules).forEach(function (mod) {
76
+ var _mod$json;
77
+ if ((_mod$json = mod.json) !== null && _mod$json !== void 0 && _mod$json.id) {
78
+ sceneMap[mod.json.id] = mod.json;
79
+ }
80
+ });
81
+ }
63
82
  var eventsMap = buildEventsMap(tojson.frames);
64
83
  var getSceneById = createGetSceneById(sceneMap);
65
84
  var getExtensionEventById = createGetExtensionEventById(eventsMap);
@@ -242,6 +261,99 @@ var getCode = function getCode(params, config) {
242
261
  };
243
262
  };
244
263
 
264
+ /**
265
+ * 预处理:从 modules.json 重建 frames 中模块的事件数据
266
+ *
267
+ * 背景:tojson.frames 中模块的 frame 可能是空壳(coms: {}, diagrams[0].conAry: []),
268
+ * 而完整的组件事件数据在 modules[moduleId].json 中(coms/cons/outputEvents)。
269
+ * toCode 的 handleFrame 需要 frame.coms 包含组件事件子 frames 才能生成事件代码。
270
+ */
271
+ var rebuildModuleFrames = function rebuildModuleFrames(tojson) {
272
+ var modules = tojson.modules;
273
+ if (!modules) return;
274
+ Object.values(modules).forEach(function (mod) {
275
+ var moduleJson = mod.json;
276
+ if (!moduleJson) return;
277
+ var frame = tojson.frames.find(function (f) {
278
+ return f.id === moduleJson.id;
279
+ });
280
+ if (!frame || Object.keys(frame.coms).length > 0) return;
281
+ var coms = moduleJson.coms || {};
282
+ var cons = moduleJson.cons || {};
283
+ Object.values(coms).forEach(function (com) {
284
+ var _com$model2;
285
+ var outputEvents = (_com$model2 = com.model) === null || _com$model2 === void 0 ? void 0 : _com$model2.outputEvents;
286
+ if (!outputEvents || Object.keys(outputEvents).length === 0) return;
287
+ var comFrames = [];
288
+ Object.entries(outputEvents).forEach(function (_ref4) {
289
+ var _activeEvent$options;
290
+ var _ref5 = _slicedToArray(_ref4, 2),
291
+ pinId = _ref5[0],
292
+ events = _ref5[1];
293
+ var activeEvent = Array.isArray(events) ? events.find(function (e) {
294
+ return e.active;
295
+ }) : null;
296
+ if (!(activeEvent !== null && activeEvent !== void 0 && (_activeEvent$options = activeEvent.options) !== null && _activeEvent$options !== void 0 && _activeEvent$options.id)) return;
297
+ var diagramId = activeEvent.options.id;
298
+ var consKey = "".concat(com.id, "-").concat(pinId);
299
+ var connections = cons[consKey] || [];
300
+ var conAry = connections.map(function (con) {
301
+ return {
302
+ id: con.id,
303
+ from: {
304
+ id: pinId,
305
+ title: activeEvent.options.title || pinId,
306
+ parent: {
307
+ id: com.id,
308
+ type: "com"
309
+ }
310
+ },
311
+ to: {
312
+ id: con.pinId,
313
+ title: con.pinId,
314
+ parent: {
315
+ id: con.comId,
316
+ type: "com"
317
+ }
318
+ },
319
+ startPinParentKey: con.startPinParentKey || con.frameKey,
320
+ finishPinParentKey: con.finishPinParentKey || con.targetFrameKey
321
+ };
322
+ });
323
+ if (conAry.length === 0) return;
324
+ comFrames.push({
325
+ id: "".concat(com.id, "_").concat(pinId, "_frame"),
326
+ title: activeEvent.options.title || "".concat(com.title, " > ").concat(pinId),
327
+ type: "com",
328
+ coms: {},
329
+ autoRunComs: {},
330
+ inputs: [],
331
+ outputs: [],
332
+ frames: [],
333
+ diagrams: [{
334
+ id: diagramId,
335
+ title: activeEvent.options.title || "".concat(com.title, " > ").concat(pinId),
336
+ starter: {
337
+ type: "com",
338
+ comId: com.id,
339
+ pinId: pinId
340
+ },
341
+ conAry: conAry,
342
+ runtimeBefore: [],
343
+ runtimeAfter: []
344
+ }]
345
+ });
346
+ });
347
+ if (comFrames.length > 0) {
348
+ frame.coms[com.id] = {
349
+ id: com.id,
350
+ frames: comFrames
351
+ };
352
+ }
353
+ });
354
+ });
355
+ };
356
+
245
357
  /**
246
358
  * 初始化配置
247
359
  */
@@ -114,6 +114,8 @@ export var handleProcess = function handleProcess(event, config) {
114
114
  // 处理节点调用
115
115
  // 边遍历边构建映射:确保引用时只能看到已声明的变量
116
116
  var outputToInputPinMap = new Map();
117
+ // 跟踪已声明的变量名,用于去重(同一组件+pin 多次调用时追加后缀)
118
+ var declaredVarCount = new Map();
117
119
  process.nodesInvocation.forEach(function (props) {
118
120
  var _props$nextParam, _config$getCallTempla, _props$meta$model;
119
121
  var componentType = props.componentType,
@@ -121,12 +123,13 @@ export var handleProcess = function handleProcess(event, config) {
121
123
  runType = props.runType;
122
124
  var nextValue = getNextValue(props, config, event, outputToInputPinMap);
123
125
  var isSameScope = checkIsSameScope(event, props);
124
- var nextCode = getNextCode(props, config, isSameScope, event);
126
+ var _getNextCode = getNextCode(props, config, isSameScope, event, declaredVarCount),
127
+ nextCode = _getNextCode.code,
128
+ declaredVarName = _getNextCode.varName;
125
129
 
126
- // 声明后记录映射,供后续引用
127
- var inputPinId = props.id.replace(/[^a-zA-Z0-9_]/g, '_');
130
+ // 声明后记录映射,供后续引用(存储完整变量名,支持去重后缀)
128
131
  (_props$nextParam = props.nextParam) === null || _props$nextParam === void 0 || _props$nextParam.forEach(function (np) {
129
- outputToInputPinMap.set("".concat(props.meta.id, "_").concat(np.id), inputPinId);
132
+ outputToInputPinMap.set("".concat(props.meta.id, "_").concat(np.id), declaredVarName);
130
133
  });
131
134
  if (code) {
132
135
  code += "\n";
@@ -167,20 +170,24 @@ export var handleProcess = function handleProcess(event, config) {
167
170
  var componentNameWithId = getComponentNameWithId(props, config, event);
168
171
  code += "".concat(indent, "/** \u8C03\u7528 ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode).concat(componentNameWithId, "(").concat(runType === "input" ? nextValue : "", ")");
169
172
  } else if (category === "var") {
173
+ var _props$extData;
170
174
  var varKey = getSafeVarName(props.meta);
175
+ // 处理 xpath:如 "/a" -> "a","/a/b" -> "a.b",用于读取变量的指定属性
176
+ var xpath = (_props$extData = props.extData) === null || _props$extData === void 0 ? void 0 : _props$extData.xpath;
177
+ var xpathArg = xpath ? ", \"".concat(xpath.replace(/^\//, "").replace(/\//g, "."), "\"") : "";
171
178
  if (props.meta.global) {
172
179
  config.addParentDependencyImport({
173
180
  packageName: "../../common/global",
174
181
  dependencyNames: ["globalVars"],
175
182
  importType: "named"
176
183
  });
177
- code += "".concat(indent, "/** ").concat(props.title, " \u5168\u5C40\u53D8\u91CF ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "globalVars.").concat(varKey, ".").concat(props.id, "(").concat(nextValue, ")");
184
+ code += "".concat(indent, "/** ").concat(props.title, " \u5168\u5C40\u53D8\u91CF ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "globalVars.").concat(varKey, ".").concat(props.id, "(").concat(nextValue).concat(xpathArg, ")");
178
185
  } else {
179
186
  var currentProvider = getCurrentProvider({
180
187
  isSameScope: isSameScope,
181
188
  props: props
182
189
  }, config);
183
- code += "".concat(indent, "/** ").concat(props.title, " \u53D8\u91CF ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "this.$vars.").concat(varKey, ".").concat(props.id, "(").concat(nextValue, ")");
190
+ code += "".concat(indent, "/** ").concat(props.title, " \u53D8\u91CF ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "this.$vars.").concat(varKey, ".").concat(props.id, "(").concat(nextValue).concat(xpathArg, ")");
184
191
  }
185
192
  } else if (category === "fx") {
186
193
  if (props.meta.global) {
@@ -283,17 +290,31 @@ var getComponentNameWithId = function getComponentNameWithId(props, config, even
283
290
  var sanitizedName = name.replace(/-/g, '_');
284
291
  return "".concat(sanitizedName, "_").concat(props.meta.id);
285
292
  };
286
- var getNextCode = function getNextCode(props, config, isSameScope, event) {
293
+ var getNextCode = function getNextCode(props, config, isSameScope, event, declaredVarCount) {
287
294
  var nextParam = props.nextParam;
288
295
  if (!nextParam.length) {
289
- return "";
296
+ return {
297
+ code: "",
298
+ varName: ""
299
+ };
290
300
  }
291
301
  var componentNameWithId = getComponentNameWithId(props, config, event);
292
302
  // 使用输入端口ID(props.id)来区分同一组件的不同调用
293
303
  // 这样可以确保 trigger 和 cancel 两个输入端口生成不同的变量名
294
304
  var pinId = props.id;
295
305
  var sanitizedPinId = pinId.replace(/[^a-zA-Z0-9_]/g, '_');
296
- return "const ".concat(componentNameWithId, "_").concat(sanitizedPinId, "_result: any = ");
306
+ var varName = "".concat(componentNameWithId, "_").concat(sanitizedPinId, "_result");
307
+
308
+ // 去重:同一变量名多次声明时追加后缀
309
+ var count = declaredVarCount.get(varName) || 0;
310
+ declaredVarCount.set(varName, count + 1);
311
+ if (count > 0) {
312
+ varName = "".concat(varName, "_").concat(count);
313
+ }
314
+ return {
315
+ code: "const ".concat(varName, ": any = "),
316
+ varName: varName
317
+ };
297
318
  };
298
319
 
299
320
  /**
@@ -312,6 +333,13 @@ function getFrameInputValueExpr(meta, config, event) {
312
333
  var pinProxy = scene === null || scene === void 0 || (_pinValueProxies = scene.pinValueProxies) === null || _pinValueProxies === void 0 ? void 0 : _pinValueProxies[proxyKey];
313
334
  var pinId = pinProxy === null || pinProxy === void 0 ? void 0 : pinProxy.pinId;
314
335
  if (typeof pinId === "string" && pinId) {
336
+ var _config$getParams;
337
+ // 优先使用 getParams 映射(场景级输入:回调参数名如 data)
338
+ var paramsMap = (_config$getParams = config.getParams) === null || _config$getParams === void 0 ? void 0 : _config$getParams.call(config);
339
+ if (paramsMap !== null && paramsMap !== void 0 && paramsMap[pinId]) {
340
+ return paramsMap[pinId];
341
+ }
342
+ // fallback:插槽场景使用 params.inputValues
315
343
  return "params?.inputValues?.[".concat(JSON.stringify(pinId), "]");
316
344
  }
317
345
  }
@@ -334,21 +362,21 @@ var getNextValue = function getNextValue(props, config, event, outputToInputPinM
334
362
  // 变量组件直接返回 Subject,不加 .id 后缀
335
363
  if ((_param$meta2 = param.meta) !== null && _param$meta2 !== void 0 && (_param$meta2 = _param$meta2.def) !== null && _param$meta2 !== void 0 && (_param$meta2 = _param$meta2.namespace) !== null && _param$meta2 !== void 0 && _param$meta2.includes(".var")) {
336
364
  var _param$meta3;
337
- // 从 outputToInputPinMap 中查找对应的输入端口ID
365
+ // 从 outputToInputPinMap 中查找完整变量名(已包含去重后缀)
338
366
  var _key = "".concat((_param$meta3 = param.meta) === null || _param$meta3 === void 0 ? void 0 : _param$meta3.id, "_").concat(param.id);
339
- var _inputPinId = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(_key);
340
- if (_inputPinId) {
341
- return "".concat(componentNameWithId, "_").concat(_inputPinId, "_result");
367
+ var _fullVarName = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(_key);
368
+ if (_fullVarName) {
369
+ return _fullVarName;
342
370
  }
343
371
  return "".concat(componentNameWithId, "_result");
344
372
  }
345
373
 
346
- // 从 outputToInputPinMap 中查找对应的输入端口ID
374
+ // 从 outputToInputPinMap 中查找完整变量名(已包含去重后缀)
347
375
  // key = `${componentId}_${outputPinId}`
348
376
  var key = "".concat((_param$meta4 = param.meta) === null || _param$meta4 === void 0 ? void 0 : _param$meta4.id, "_").concat(param.id);
349
- var inputPinId = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(key);
350
- if (inputPinId) {
351
- return "".concat(componentNameWithId, "_").concat(inputPinId, "_result.").concat(param.id);
377
+ var fullVarName = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(key);
378
+ if (fullVarName) {
379
+ return "".concat(fullVarName, ".").concat(param.id);
352
380
  }
353
381
  return "".concat(componentNameWithId, "_result.").concat(param.id);
354
382
  });
@@ -1,4 +1,4 @@
1
- import { indentation, toPascalCase } from "./index";
1
+ import { indentation, toSlotFunctionName } from "./index";
2
2
  /** 生成组件 Inputs 映射代码 */
3
3
  export var genComponentInputsCode = function genComponentInputsCode(indent, providerName, comId) {
4
4
  return "".concat(indent, "inputs['").concat(comId, "'] = useBindInputs(controllers.current.").concat(providerName, ", '").concat(comId, "');\n");
@@ -21,7 +21,7 @@ export var genSlotRenderRef = function genSlotRenderRef(_ref) {
21
21
  renderId = _ref.renderId,
22
22
  indent = _ref.indent,
23
23
  isLast = _ref.isLast;
24
- var renderFunctionName = toPascalCase("".concat(renderId, "_Render"));
24
+ var renderFunctionName = toSlotFunctionName(renderId);
25
25
  return "".concat(indent).concat(slotId, ": {\n").concat(indent, " render: ").concat(renderFunctionName, ",\n").concat(indent, "}").concat(isLast ? '' : ',', "\n");
26
26
  };
27
27
 
@@ -6,6 +6,8 @@ export declare const firstCharToUpperCase: (str: string) => string;
6
6
  export declare const formatSlotContent: (uiContent: string, baseIndentSize: number, renderBodyIndent: string) => string;
7
7
  /** 将字符串转为大驼峰 */
8
8
  export declare const toPascalCase: (str: string) => string;
9
+ /** 生成插槽渲染函数名:S${ID} (SCREAMING_SNAKE_CASE) */
10
+ export declare const toSlotFunctionName: (renderId: string) => string;
9
11
  /** Taro/React UI 组件代码生成 */
10
12
  export declare const getUiComponentCode: (params: {
11
13
  componentName: string;
@@ -23,6 +23,11 @@ export var toPascalCase = function toPascalCase(str) {
23
23
  }).join("");
24
24
  };
25
25
 
26
+ /** 生成插槽渲染函数名:S${ID} (SCREAMING_SNAKE_CASE) */
27
+ export var toSlotFunctionName = function toSlotFunctionName(renderId) {
28
+ return "S".concat(renderId.replace(/[^a-zA-Z0-9]/g, "_").toUpperCase());
29
+ };
30
+
26
31
  /** 根节点data去除无用属性 */
27
32
  var formatData = function formatData(data, isRoot) {
28
33
  if (!data) return {};
@@ -54,7 +59,7 @@ export var getUiComponentCode = function getUiComponentCode(params, config) {
54
59
  var ui = "".concat(indent, "<WithCom");
55
60
  ui += "\n".concat(indent2, "component={").concat(componentName, "}");
56
61
  ui += "\n".concat(indent2, "id='").concat(meta.id, "'");
57
- ui += "\n".concat(indent2, "className='").concat(meta.id, " mybricks_com'");
62
+ ui += "\n".concat(indent2, "className='mybricks_com ").concat(meta.id, "'");
58
63
  if (meta.name) {
59
64
  ui += "\n".concat(indent2, "name='").concat(meta.name, "'");
60
65
  }
@@ -1,7 +1,7 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/esm/createClass";
3
3
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
- import { indentation, toPascalCase } from "./index";
4
+ import { indentation, toSlotFunctionName } from "./index";
5
5
 
6
6
  /** Render 函数管理器 */
7
7
  export var RenderManager = /*#__PURE__*/function () {
@@ -50,7 +50,7 @@ export var RenderManager = /*#__PURE__*/function () {
50
50
  logicCode = _ref.logicCode,
51
51
  useWrap = _ref.useWrap,
52
52
  description = _ref.description;
53
- var renderFunctionName = toPascalCase("".concat(renderId, "_Render"));
53
+ var renderFunctionName = toSlotFunctionName(renderId);
54
54
  if (description) {
55
55
  code += "".concat(indent, "/** ").concat(description, " */\n");
56
56
  }
@@ -114,11 +114,9 @@ export var RenderManager = /*#__PURE__*/function () {
114
114
  // 如果是容器协议插槽,直接调用 wrap
115
115
  code += "".concat(indent).concat(indent3, "params?.wrap?.(descriptors)\n");
116
116
  } else {
117
- code += "".concat(indent).concat(indent3, "<>\n");
118
117
  code += modifiedRenderCode.split("\n").map(function (line) {
119
118
  return "".concat(indent).concat(indent2).concat(line);
120
119
  }).join("\n") + "\n";
121
- code += "".concat(indent).concat(indent3, "</>\n");
122
120
  }
123
121
  code += "".concat(indent).concat(indent2, ");\n");
124
122
  code += "".concat(indent, "}\n\n");
@@ -139,7 +137,7 @@ export var RenderManager = /*#__PURE__*/function () {
139
137
  }, {
140
138
  key: "genRenderRef",
141
139
  value: function genRenderRef(slotId, renderId, indent) {
142
- var renderFunctionName = toPascalCase("".concat(renderId, "_Render"));
140
+ var renderFunctionName = toSlotFunctionName(renderId);
143
141
  return "".concat(indent).concat(slotId, ": {\n").concat(indent, " render: ").concat(renderFunctionName, ",\n").concat(indent, "},\n");
144
142
  }
145
143
  }]);
@@ -1,7 +1,7 @@
1
1
  /** 生成响应式 data 管理器 */
2
2
  export declare const genReactiveDataManager: (indent: string, utilsPackageName: string) => string;
3
3
  /** 生成根组件定义代码 (useAppContext) */
4
- export declare const genRootDefineCode: (indent: string, utilsPackageName: string, hasJsModules?: boolean) => string;
4
+ export declare const genRootDefineCode: (indent: string, utilsPackageName: string, hasJsModules?: boolean, isModule?: boolean) => string;
5
5
  /** 生成普通插槽定义代码 */
6
6
  export declare const genSlotDefineCode: (indent: string) => string;
7
7
  /** 生成控制器初始化代码 */
@@ -6,9 +6,12 @@ export var genReactiveDataManager = function genReactiveDataManager(indent, util
6
6
  /** 生成根组件定义代码 (useAppContext) */
7
7
  export var genRootDefineCode = function genRootDefineCode(indent, utilsPackageName) {
8
8
  var hasJsModules = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
9
+ var isModule = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
9
10
  // 使用 useAppContext 获取 comRefs / $vars / $fxs / appContext
10
11
  var code = "".concat(indent, "const {comRefs, $vars, $fxs, appContext} = useAppContext();\n");
11
- code += "".concat(indent, "usePageLife();\n");
12
+ if (!isModule) {
13
+ code += "".concat(indent, "usePageLife();\n");
14
+ }
12
15
  // 如果有 JS 计算组件,需要初始化 comModules
13
16
  if (hasJsModules) {
14
17
  code += "".concat(indent, "const comModules = jsModules({ createJSHandle });\n");
@@ -48,9 +51,9 @@ export var genComponentTemplate = function genComponentTemplate(_ref) {
48
51
  var pageScopeCode = "const PageScopeContext = createContext<any>(null);\n" + "function usePageScope<T = any>() {\n" + " return useContext(PageScopeContext) as T;\n" + "}\n\n";
49
52
 
50
53
  // 渲染定义放在组件外部,保持引用稳定
51
- var code = "".concat(pageScopeCode).concat(renderDefinitions, "\n") + "function ".concat(componentName, "() {\n") + " // \u9875\u9762\u7EA7 scope\uFF1A\u4F60\u53EF\u4EE5\u628A useState/useMemo \u7684\u7ED3\u679C\u653E\u5230\u8FD9\u4E2A ref \u4E0A\uFF0C\u8BA9\u63D2\u69FD\u8BFB\u53D6\n" + " const pageScopeRef = useRef<any>({});\n" + "".concat(combinedJsCode, "\n") + " return (\n" + " <PageScopeContext.Provider value={pageScopeRef}>\n" + " <>\n" + "".concat(uiResult.split('\n').map(function (line) {
54
+ var code = "".concat(pageScopeCode).concat(renderDefinitions, "\n") + "function ".concat(componentName, "() {\n") + " // \u9875\u9762\u7EA7 scope\uFF1A\u4F60\u53EF\u4EE5\u628A useState/useMemo \u7684\u7ED3\u679C\u653E\u5230\u8FD9\u4E2A ref \u4E0A\uFF0C\u8BA9\u63D2\u69FD\u8BFB\u53D6\n" + " const pageScopeRef = useRef<any>({});\n" + "".concat(combinedJsCode, "\n") + " return (\n" + " <PageScopeContext.Provider value={pageScopeRef}>\n" + (hasPopups ? " <>\n" : "") + "".concat(uiResult.split('\n').map(function (line) {
52
55
  return " ".concat(line);
53
- }).join('\n'), "\n") + (hasPopups ? " <PopupRenderer popupMap={POPUP_MAP} />\n" : "") + " </>\n" + " </PageScopeContext.Provider>\n" + " );\n" + "}\n\n";
56
+ }).join('\n'), "\n") + (hasPopups ? " <PopupRenderer popupMap={POPUP_MAP} />\n" : "") + (hasPopups ? " </>\n" : "") + " </PageScopeContext.Provider>\n" + " );\n" + "}\n\n";
54
57
  if (isPopup) {
55
58
  code += "(".concat(componentName, " as any).isPopup = true;\n\n");
56
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mybricks/to-code-taro",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "To code for Taro",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",