mm_statics 1.7.8 → 1.8.0

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 (2) hide show
  1. package/index.js +3 -90
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -223,7 +223,7 @@ Static.prototype._toAmd = async function (file_type, text) {
223
223
  // 处理require模块语句
224
224
  code = this._requireMod(code);
225
225
  // 添加return语句确保AMD模块正确导出
226
- code = this._addAmdReturn(code);
226
+ // code = this._addAmdReturn(code);
227
227
  // 格式化代码
228
228
  return await this._formatCode(code, file_type);
229
229
  } else {
@@ -244,8 +244,8 @@ Static.prototype._toAmd = async function (file_type, text) {
244
244
  let amd_code = this.convert.toAmd(inner_code);
245
245
  // 处理require模块语句
246
246
  amd_code = this._requireMod(amd_code);
247
- // 添加return语句确保AMD模块正确导出
248
- amd_code = this._addAmdReturn(amd_code);
247
+ // // 添加return语句确保AMD模块正确导出
248
+ // amd_code = this._addAmdReturn(amd_code);
249
249
  // 移除type="module"属性,因为AMD模块不需要这个属性
250
250
  let new_script = script.replace(/type\s*=\s*["']module["']/g, '').replace(inner_code, amd_code);
251
251
  // 清理多余的空格
@@ -263,93 +263,6 @@ Static.prototype._toAmd = async function (file_type, text) {
263
263
  return result;
264
264
  };
265
265
 
266
- /**
267
- * 为AMD模块添加return语句
268
- * @param {string} code AMD模块代码
269
- * @returns {string} 添加return后的代码
270
- */
271
- Static.prototype._addAmdReturn = function (code) {
272
- if (!code || typeof code !== 'string') {
273
- return code;
274
- }
275
-
276
- // 检查是否已经是简洁格式(没有 _exports["default"])
277
- if (!code.includes('_exports["default"]')) {
278
- return code;
279
- }
280
-
281
- // 解析 mm_es6_to_amd 生成的格式并转换为简洁的 AMD 格式
282
- // 原始格式: define(["exports", "countup"], function (_exports, _countup) { ... });
283
- // 目标格式: define(["countup"], function (_countup) { ... return { ... }; });
284
-
285
- // 1. 提取依赖数组(去掉 exports)
286
- const deps_match = code.match(/define\(\s*\[([^\]]+)\]/);
287
- if (!deps_match) {
288
- return code;
289
- }
290
- let deps_str = deps_match[1];
291
- // 移除 exports 依赖
292
- deps_str = deps_str.replace(/\s*(["'])exports\1\s*,?\s*/g, '');
293
- deps_str = deps_str.replace(/,\s*$/, ''); // 移除末尾逗号
294
-
295
- // 2. 提取函数参数(去掉 _exports)
296
- const params_match = code.match(/function\s*\(\s*([^)]+)\s*\)/);
297
- if (!params_match) {
298
- return code;
299
- }
300
- let params_str = params_match[1];
301
- // 移除 _exports 参数
302
- params_str = params_str.replace(/\s*_exports\s*,?\s*/g, '');
303
- params_str = params_str.replace(/,\s*$/, ''); // 移除末尾逗号
304
-
305
- // 3. 提取模块内容(去掉 exports 相关代码)
306
- const body_match = code.match(/function\s*\([^)]+\)\s*\{([\s\S]*)\}\s*\);$/);
307
- if (!body_match) {
308
- return code;
309
- }
310
- let body = body_match[1];
311
-
312
- // 移除 'use strict'
313
- body = body.replace(/^\s*["']use strict["']\s*;\s*/, '');
314
-
315
- // 移除 exports 相关代码
316
- body = body.replace(/Object\.defineProperty\(_exports,\s*["']__esModule["']\s*,\s*\{[^}]+\}\s*\);\s*/g, '');
317
- body = body.replace(/_exports\[["']default["']\s*=\s*void\s*0;\s*/g, '');
318
-
319
- // 提取并转换 default 导出对象
320
- // 使用字符串处理方法来处理嵌套的花括号
321
- const default_start = body.indexOf('_exports["default"] =');
322
- if (default_start === -1) {
323
- return code;
324
- }
325
-
326
- // 找到赋值后的第一个 {
327
- const obj_start = body.indexOf('{', default_start);
328
- if (obj_start === -1) {
329
- return code;
330
- }
331
-
332
- // 匹配花括号(处理嵌套)
333
- let brace_count = 1;
334
- let i = obj_start + 1;
335
- while (i < body.length && brace_count > 0) {
336
- if (body[i] === '{') brace_count++;
337
- if (body[i] === '}') brace_count--;
338
- i++;
339
- }
340
-
341
- // 提取对象字面量
342
- const default_obj = body.substring(obj_start, i);
343
- body = 'return ' + default_obj + ';';
344
-
345
- // 4. 重新组装简洁的 AMD 格式
346
- const new_amd = `define([${deps_str}], function(${params_str}) {\n${body}\n});`;
347
-
348
- return new_amd;
349
- };
350
-
351
-
352
-
353
266
  /**
354
267
  * 编译Vue组件
355
268
  * @param {string} code Vue组件代码
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_statics",
3
- "version": "1.7.8",
3
+ "version": "1.8.0",
4
4
  "description": "这是超级美眉statics函数模块,用于web服务端statics缓存",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -43,7 +43,7 @@
43
43
  "koa-send": "^5.0.1",
44
44
  "marked": "^18.0.4",
45
45
  "mm_cache": "^1.4.9",
46
- "mm_es6_to_amd": "^1.4.9",
46
+ "mm_es6_to_amd": "^1.5.0",
47
47
  "prettier": "^3.8.3"
48
48
  },
49
49
  "devDependencies": {