@unmagic/vms 0.1.1 → 0.1.4

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.
@@ -1739,6 +1739,9 @@ function buildProxyRefsItemAccess(vForInfoList, targetItemIndex, scriptScope, us
1739
1739
  const propsVarName = scriptScope.propsVarName || "__vmsProps";
1740
1740
  expr = t.identifier(propsVarName);
1741
1741
  for (const prop of firstPartProps) expr = t.memberExpression(expr, t.identifier(prop));
1742
+ } else if (firstProp && scriptScope && isImportVariable(firstProp, scriptScope)) {
1743
+ expr = t.identifier(firstProp);
1744
+ for (let i = 1; i < firstPartProps.length; i++) expr = t.memberExpression(expr, t.identifier(firstPartProps[i]));
1742
1745
  } else {
1743
1746
  expr = t.identifier("__vmsProxyRefs");
1744
1747
  for (const prop of firstPartProps) expr = t.memberExpression(expr, t.identifier(prop));
@@ -1784,6 +1787,7 @@ function buildProxyRefsArgument(arg, vForInfoList, vForItemNames, arrowFunctionA
1784
1787
  const propsVarName = scriptScope.propsVarName || "__vmsProps";
1785
1788
  return t.memberExpression(t.identifier(propsVarName), t.identifier(arg.name));
1786
1789
  }
1790
+ if (scriptScope && isImportVariable(arg.name, scriptScope)) return arg;
1787
1791
  return t.memberExpression(t.identifier("__vmsProxyRefs"), t.identifier(arg.name));
1788
1792
  }
1789
1793
  if (t.isOptionalMemberExpression(arg)) {
@@ -2171,9 +2175,10 @@ function getTemplateNodeProp(node, prop, returnValue, counter, wxsExpressionStat
2171
2175
  * 2. babelParse(code) — 重新解析为完整 AST
2172
2176
  *
2173
2177
  * 注意:isAsync 必须正确传递,否则 babel 无法解析 await 关键字。
2178
+ * 注意:不能使用 compact: true,否则多语句的 { } 会被移除导致解析错误
2174
2179
  */
2175
2180
  function reparseBodyAsAST(body, isAsync) {
2176
- const code = generate(t.arrowFunctionExpression([], body, isAsync), { compact: true }).code;
2181
+ const code = generate(t.arrowFunctionExpression([], body, isAsync)).code;
2177
2182
  return parse$1(code, {
2178
2183
  sourceType: "module",
2179
2184
  plugins: ["typescript"]
@@ -2252,6 +2257,11 @@ function processASTExpression(ast, counter, callExpressionWithArgs, excludeBindi
2252
2257
  if (t.isCallExpression(ast)) return processCallableExpression(ast.callee, ast.arguments, counter, callExpressionWithArgs, excludeBindingVars, vForItemName, vForInfoList, ctx, returnValue);
2253
2258
  else if (t.isMemberExpression(ast)) return processCallableExpression(ast, null, counter, callExpressionWithArgs, excludeBindingVars, vForItemName, vForInfoList, ctx, returnValue);
2254
2259
  else if (t.isArrowFunctionExpression(ast)) return processArrowFunctionExpression(ast, counter, callExpressionWithArgs, excludeBindingVars, vForItemName, node, returnValue, ctx);
2260
+ else if (t.isAssignmentExpression(ast)) return processInlineArrowFunction(t.blockStatement([t.expressionStatement(ast)]), [], counter, callExpressionWithArgs, excludeBindingVars, node, returnValue, ctx, false);
2261
+ else if (t.isSequenceExpression(ast)) {
2262
+ const statements = ast.expressions.map((expr) => t.expressionStatement(expr));
2263
+ return processInlineArrowFunction(t.blockStatement(statements), [], counter, callExpressionWithArgs, excludeBindingVars, node, returnValue, ctx, false);
2264
+ } else if (t.isLogicalExpression(ast) || t.isConditionalExpression(ast)) return createShortExprHandler(ast, [], callExpressionWithArgs, vForInfoList, getVForVariables(ctx, node), ctx, counter, returnValue, false);
2255
2265
  return "";
2256
2266
  }
2257
2267
  /**
@@ -2343,6 +2353,10 @@ function collectExternalVarsFromExpression(body, arrowFunctionArgumentNames, vFo
2343
2353
  collectVarsFromNode(node.left);
2344
2354
  collectVarsFromNode(node.right);
2345
2355
  } else if (t.isUnaryExpression(node)) collectVarsFromNode(node.argument);
2356
+ else if (t.isAssignmentExpression(node)) {
2357
+ collectVarsFromNode(node.left);
2358
+ collectVarsFromNode(node.right);
2359
+ }
2346
2360
  };
2347
2361
  if (t.isConditionalExpression(body)) {
2348
2362
  collectVarsFromNode(body.test);
@@ -2375,6 +2389,14 @@ function rewriteExpressionVars(expr, varsToCollect, arrowFunctionArgumentNames,
2375
2389
  else if (t.isLogicalExpression(node)) return t.logicalExpression(node.operator, processExpr(node.left), processExpr(node.right));
2376
2390
  else if (t.isBinaryExpression(node)) return t.binaryExpression(node.operator, processExpr(node.left), processExpr(node.right));
2377
2391
  else if (t.isUnaryExpression(node)) return t.unaryExpression(node.operator, processExpr(node.argument));
2392
+ else if (t.isAssignmentExpression(node)) {
2393
+ const left = node.left;
2394
+ if (t.isIdentifier(left) || t.isMemberExpression(left)) {
2395
+ const rewritten = processExpr(left);
2396
+ if (t.isIdentifier(rewritten) || t.isMemberExpression(rewritten)) return t.assignmentExpression(node.operator, rewritten, processExpr(node.right));
2397
+ }
2398
+ return t.assignmentExpression(node.operator, left, processExpr(node.right));
2399
+ }
2378
2400
  return node;
2379
2401
  };
2380
2402
  return processExpr(expr);
@@ -2497,7 +2519,7 @@ function processInlineArrowFunction(body, arrowFunctionArguments, counter, callE
2497
2519
  if (usedVars.size > 0 || vForItemUsage?.shouldCreateReference) ctx.needsProxyRefs = true;
2498
2520
  const functionIndex = counter.functionPropertyCounter - 1;
2499
2521
  const dataKey = vForInfoList && vForInfoList.length > 0 ? getFunctionIndexChar(functionIndex) : "";
2500
- const functionBody = createInlineHandlerBody(body, arrowFunctionArguments, usedVars, vForInfoList, vForItemUsage, isAsync, dataKey);
2522
+ const functionBody = createInlineHandlerBody(body, arrowFunctionArguments, usedVars, vForInfoList, vForItemUsage, isAsync, dataKey, ctx.scriptScope);
2501
2523
  const dataArgsAst = vForInfoList && vForInfoList.length > 0 ? vForInfoList.map((info) => {
2502
2524
  const indexName = getVForIndexName(info) || "index";
2503
2525
  return t.identifier(indexName);
@@ -2635,7 +2657,7 @@ function analyzeVForItemUsage(body, vForInfoList, isAsync = false) {
2635
2657
  /**
2636
2658
  * 创建内联处理函数的函数体
2637
2659
  */
2638
- function createInlineHandlerBody(body, arrowFunctionArguments, externalVars, vForInfoList, vForItemUsage, isAsync = false, dataKey = "a") {
2660
+ function createInlineHandlerBody(body, arrowFunctionArguments, externalVars, vForInfoList, vForItemUsage, isAsync = false, dataKey = "a", scriptScope) {
2639
2661
  const statements = [];
2640
2662
  const paramNameMapping = /* @__PURE__ */ new Map();
2641
2663
  if (arrowFunctionArguments.length > 0) {
@@ -2648,9 +2670,9 @@ function createInlineHandlerBody(body, arrowFunctionArguments, externalVars, vFo
2648
2670
  if (vForInfoList && vForInfoList.length > 0) {
2649
2671
  const indexVars = vForInfoList.map((info) => getVForIndexName(info) || "index").map((idx) => t.identifier(idx));
2650
2672
  statements.push(t.variableDeclaration("const", [t.variableDeclarator(t.objectPattern([t.objectProperty(t.identifier(dataKey), t.arrayPattern(indexVars), false, false)]), t.memberExpression(t.memberExpression(t.identifier(EVENT_PARAM_NAME), t.identifier("currentTarget")), t.identifier("dataset")))]));
2651
- if (vForItemUsage?.shouldCreateReference) statements.push(createLocalReference(vForInfoList, vForItemUsage));
2673
+ if (vForItemUsage?.shouldCreateReference) statements.push(createLocalReference(vForInfoList, vForItemUsage, scriptScope));
2652
2674
  }
2653
- const transformedBody = replaceVariableAccess(t.cloneNode(body, true), externalVars, vForInfoList, vForItemUsage, paramNameMapping, isAsync);
2675
+ const transformedBody = replaceVariableAccess(t.cloneNode(body, true), externalVars, vForInfoList, vForItemUsage, paramNameMapping, isAsync, scriptScope);
2654
2676
  statements.push(...transformedBody.body);
2655
2677
  return t.blockStatement(statements);
2656
2678
  }
@@ -2660,15 +2682,15 @@ function createInlineHandlerBody(body, arrowFunctionArguments, externalVars, vFo
2660
2682
  * 因为 createInlineHandlerBody 中外层 item 会被 replaceVariableAccess 替换,
2661
2683
  * 而不会先声明为局部变量
2662
2684
  */
2663
- function createLocalReference(vForInfoList, vForItemUsage) {
2685
+ function createLocalReference(vForInfoList, vForItemUsage, scriptScope) {
2664
2686
  const itemName = vForItemUsage.itemName;
2665
- const accessExpression = buildProxyRefsItemAccess(vForInfoList, vForInfoList.findIndex((info) => getVForItemName(info) === itemName), void 0, true);
2687
+ const accessExpression = buildProxyRefsItemAccess(vForInfoList, vForInfoList.findIndex((info) => getVForItemName(info) === itemName), scriptScope, true);
2666
2688
  return t.variableDeclaration("const", [t.variableDeclarator(t.identifier(itemName), accessExpression)]);
2667
2689
  }
2668
2690
  /**
2669
2691
  * 替换变量访问
2670
2692
  */
2671
- function replaceVariableAccess(body, externalVars, vForInfoList, vForItemUsage, paramNameMapping, isAsync = false) {
2693
+ function replaceVariableAccess(body, externalVars, vForInfoList, vForItemUsage, paramNameMapping, isAsync = false, scriptScope) {
2672
2694
  const localVars = /* @__PURE__ */ new Set();
2673
2695
  const ast = reparseBodyAsAST(body, isAsync);
2674
2696
  traverse(ast, { ...createLocalVarCollector(localVars) });
@@ -2697,7 +2719,7 @@ function replaceVariableAccess(body, externalVars, vForInfoList, vForItemUsage,
2697
2719
  }
2698
2720
  if (isVForItem) if (itemIndex === vForInfoList.length - 1 && vForItemUsage?.shouldCreateReference) return;
2699
2721
  else {
2700
- const accessExpression = buildProxyRefsItemAccess(vForInfoList, itemIndex);
2722
+ const accessExpression = buildProxyRefsItemAccess(vForInfoList, itemIndex, scriptScope);
2701
2723
  path.replaceWith(accessExpression);
2702
2724
  return;
2703
2725
  }
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import dotenv from "dotenv-flow";
2
2
  //#region src/index.ts
3
3
  async function runVMS(options) {
4
4
  dotenv.config({ node_env: options.mode });
5
- const { dev, prod } = await import("./cli-B7IxnuYZ.js");
5
+ const { dev, prod } = await import("./cli-ZmVRYzq_.js");
6
6
  if (options.mode === "production") return prod(options);
7
7
  else return dev();
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unmagic/vms",
3
- "version": "0.1.1",
3
+ "version": "0.1.4",
4
4
  "description": "基于 @unmagic/vue-mini 的Vue3 单文件组件构建工具",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",