@unmagic/vms 0.1.3 → 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)) {
@@ -2515,7 +2519,7 @@ function processInlineArrowFunction(body, arrowFunctionArguments, counter, callE
2515
2519
  if (usedVars.size > 0 || vForItemUsage?.shouldCreateReference) ctx.needsProxyRefs = true;
2516
2520
  const functionIndex = counter.functionPropertyCounter - 1;
2517
2521
  const dataKey = vForInfoList && vForInfoList.length > 0 ? getFunctionIndexChar(functionIndex) : "";
2518
- const functionBody = createInlineHandlerBody(body, arrowFunctionArguments, usedVars, vForInfoList, vForItemUsage, isAsync, dataKey);
2522
+ const functionBody = createInlineHandlerBody(body, arrowFunctionArguments, usedVars, vForInfoList, vForItemUsage, isAsync, dataKey, ctx.scriptScope);
2519
2523
  const dataArgsAst = vForInfoList && vForInfoList.length > 0 ? vForInfoList.map((info) => {
2520
2524
  const indexName = getVForIndexName(info) || "index";
2521
2525
  return t.identifier(indexName);
@@ -2653,7 +2657,7 @@ function analyzeVForItemUsage(body, vForInfoList, isAsync = false) {
2653
2657
  /**
2654
2658
  * 创建内联处理函数的函数体
2655
2659
  */
2656
- function createInlineHandlerBody(body, arrowFunctionArguments, externalVars, vForInfoList, vForItemUsage, isAsync = false, dataKey = "a") {
2660
+ function createInlineHandlerBody(body, arrowFunctionArguments, externalVars, vForInfoList, vForItemUsage, isAsync = false, dataKey = "a", scriptScope) {
2657
2661
  const statements = [];
2658
2662
  const paramNameMapping = /* @__PURE__ */ new Map();
2659
2663
  if (arrowFunctionArguments.length > 0) {
@@ -2666,9 +2670,9 @@ function createInlineHandlerBody(body, arrowFunctionArguments, externalVars, vFo
2666
2670
  if (vForInfoList && vForInfoList.length > 0) {
2667
2671
  const indexVars = vForInfoList.map((info) => getVForIndexName(info) || "index").map((idx) => t.identifier(idx));
2668
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")))]));
2669
- if (vForItemUsage?.shouldCreateReference) statements.push(createLocalReference(vForInfoList, vForItemUsage));
2673
+ if (vForItemUsage?.shouldCreateReference) statements.push(createLocalReference(vForInfoList, vForItemUsage, scriptScope));
2670
2674
  }
2671
- 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);
2672
2676
  statements.push(...transformedBody.body);
2673
2677
  return t.blockStatement(statements);
2674
2678
  }
@@ -2678,15 +2682,15 @@ function createInlineHandlerBody(body, arrowFunctionArguments, externalVars, vFo
2678
2682
  * 因为 createInlineHandlerBody 中外层 item 会被 replaceVariableAccess 替换,
2679
2683
  * 而不会先声明为局部变量
2680
2684
  */
2681
- function createLocalReference(vForInfoList, vForItemUsage) {
2685
+ function createLocalReference(vForInfoList, vForItemUsage, scriptScope) {
2682
2686
  const itemName = vForItemUsage.itemName;
2683
- 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);
2684
2688
  return t.variableDeclaration("const", [t.variableDeclarator(t.identifier(itemName), accessExpression)]);
2685
2689
  }
2686
2690
  /**
2687
2691
  * 替换变量访问
2688
2692
  */
2689
- function replaceVariableAccess(body, externalVars, vForInfoList, vForItemUsage, paramNameMapping, isAsync = false) {
2693
+ function replaceVariableAccess(body, externalVars, vForInfoList, vForItemUsage, paramNameMapping, isAsync = false, scriptScope) {
2690
2694
  const localVars = /* @__PURE__ */ new Set();
2691
2695
  const ast = reparseBodyAsAST(body, isAsync);
2692
2696
  traverse(ast, { ...createLocalVarCollector(localVars) });
@@ -2715,7 +2719,7 @@ function replaceVariableAccess(body, externalVars, vForInfoList, vForItemUsage,
2715
2719
  }
2716
2720
  if (isVForItem) if (itemIndex === vForInfoList.length - 1 && vForItemUsage?.shouldCreateReference) return;
2717
2721
  else {
2718
- const accessExpression = buildProxyRefsItemAccess(vForInfoList, itemIndex);
2722
+ const accessExpression = buildProxyRefsItemAccess(vForInfoList, itemIndex, scriptScope);
2719
2723
  path.replaceWith(accessExpression);
2720
2724
  return;
2721
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-B8qDheMe.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.3",
3
+ "version": "0.1.4",
4
4
  "description": "基于 @unmagic/vue-mini 的Vue3 单文件组件构建工具",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",