@vureact/compiler-core 1.3.0 → 1.4.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.
@@ -1,5 +1,5 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } function _optionalChainDelete(ops) { const result = _optionalChain(ops); return result == null ? true : result; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10;/**
2
- * @vureact/compiler-core v1.3.0
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } function _optionalChainDelete(ops) { const result = _optionalChain(ops); return result == null ? true : result; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11;/**
2
+ * @vureact/compiler-core v1.4.0
3
3
  * (c) 2025-present Ruihong Zhong (Ryan John)
4
4
  * @license MIT
5
5
  */
@@ -32,6 +32,16 @@ var PACKAGE_NAME = {
32
32
  runtime: "@vureact/runtime-core",
33
33
  router: "@vureact/router"
34
34
  };
35
+ var RUNTIME_PACKAGES = {
36
+ router: {
37
+ name: PACKAGE_NAME.router,
38
+ version: "^1.0.0"
39
+ },
40
+ runtime: {
41
+ name: PACKAGE_NAME.runtime,
42
+ version: "^1.0.0"
43
+ }
44
+ };
35
45
  var STYLE_MODULE_NAME = "$style";
36
46
  var MACRO_API_NAMES = {
37
47
  props: "defineProps",
@@ -418,8 +428,8 @@ function getBabelParseOptions(lang = "js", context = "script", filename) {
418
428
  function stringToExpr(input, lang, filename = "") {
419
429
  return _parser.parseExpression.call(void 0, input, getBabelParseOptions(lang, "expression", filename));
420
430
  }
421
- function atComponentOrHookRoot(path8, rootScope, inScriptFile = false) {
422
- const { parentPath, scope } = path8;
431
+ function atComponentOrHookRoot(path9, rootScope, inScriptFile = false) {
432
+ const { parentPath, scope } = path9;
423
433
  const parentBlock = scope.block;
424
434
  if (!parentPath) return !inScriptFile;
425
435
  if (parentBlock === rootScope) {
@@ -1650,9 +1660,9 @@ function resolveScriptMeta(result, ctx) {
1650
1660
  const scriptAST = _optionalChain([result, 'access', _48 => _48.script, 'optionalAccess', _49 => _49.ast]);
1651
1661
  if (!scriptAST) return;
1652
1662
  _core.traverse.call(void 0, scriptAST, {
1653
- VariableDeclarator(path8) {
1654
- const { node } = path8;
1655
- if (!atComponentOrHookRoot(path8, scriptAST.program) || !t16.isIdentifier(node.id)) {
1663
+ VariableDeclarator(path9) {
1664
+ const { node } = path9;
1665
+ if (!atComponentOrHookRoot(path9, scriptAST.program) || !t16.isIdentifier(node.id)) {
1656
1666
  return;
1657
1667
  }
1658
1668
  if (node.init && t16.isCallExpression(node.init) && t16.isIdentifier(node.init.callee)) {
@@ -1986,36 +1996,36 @@ function insertRequiredImports(ctx) {
1986
1996
  const processedModules = /* @__PURE__ */ new Set();
1987
1997
  let hasProcessedImports = false;
1988
1998
  recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.memo);
1989
- function resolveRequiredImport(path8) {
1990
- const { node } = path8;
1999
+ function resolveRequiredImport(path9) {
2000
+ const { node } = path9;
1991
2001
  const moduleName = node.source.value.toLowerCase();
1992
2002
  const isVueLike = isVueEcosystemPackage(moduleName);
1993
2003
  mergeImports(node, ctx);
1994
- if (processedModules.has(moduleName) && !path8.removed) {
1995
- path8.remove();
2004
+ if (processedModules.has(moduleName) && !path9.removed) {
2005
+ path9.remove();
1996
2006
  return;
1997
2007
  }
1998
2008
  processedModules.add(moduleName);
1999
2009
  if (!hasProcessedImports) {
2000
2010
  const required = createRequiredImports(ctx);
2001
2011
  if (isVueLike) {
2002
- path8.replaceWithMultiple(required);
2012
+ path9.replaceWithMultiple(required);
2003
2013
  } else if (moduleName === PACKAGE_NAME.react) {
2004
- path8.insertAfter(required);
2014
+ path9.insertAfter(required);
2005
2015
  } else {
2006
- path8.insertBefore(required);
2016
+ path9.insertBefore(required);
2007
2017
  }
2008
2018
  hasProcessedImports = true;
2009
2019
  }
2010
- if (isVueLike && !path8.removed) {
2011
- path8.remove();
2020
+ if (isVueLike && !path9.removed) {
2021
+ path9.remove();
2012
2022
  return;
2013
2023
  }
2014
2024
  replaceVueSuffix(ctx, node.source);
2015
2025
  }
2016
- function resolveStyleFileExt(path8) {
2026
+ function resolveStyleFileExt(path9) {
2017
2027
  if (!ctx.preprocessStyles) return;
2018
- const { node } = path8;
2028
+ const { node } = path9;
2019
2029
  if (!node || !node.source || !node.source.value) return;
2020
2030
  const importSource = node.source.value;
2021
2031
  if (typeof importSource !== "string") return;
@@ -2027,16 +2037,16 @@ function insertRequiredImports(ctx) {
2027
2037
  return {
2028
2038
  // 增加 Program.exit 兜底注入 required imports(处理无 ImportDeclaration 的 SFC)
2029
2039
  Program: {
2030
- exit(path8) {
2040
+ exit(path9) {
2031
2041
  if (hasProcessedImports) return;
2032
2042
  const required = createRequiredImports(ctx);
2033
- path8.unshiftContainer("body", required);
2043
+ path9.unshiftContainer("body", required);
2034
2044
  hasProcessedImports = true;
2035
2045
  }
2036
2046
  },
2037
- ImportDeclaration(path8) {
2038
- resolveRequiredImport(path8);
2039
- resolveStyleFileExt(path8);
2047
+ ImportDeclaration(path9) {
2048
+ resolveRequiredImport(path9);
2049
+ resolveStyleFileExt(path9);
2040
2050
  }
2041
2051
  };
2042
2052
  }
@@ -2107,10 +2117,10 @@ function createRequiredImports(ctx) {
2107
2117
 
2108
2118
  // src/core/transform/sfc/script/shared/babel-utils.ts
2109
2119
 
2110
- function findRootVariablePath(path8) {
2111
- const rootId = findRootIdentifier(path8.node);
2120
+ function findRootVariablePath(path9) {
2121
+ const rootId = findRootIdentifier(path9.node);
2112
2122
  if (!_optionalChain([rootId, 'optionalAccess', _59 => _59.name])) return null;
2113
- const binding = path8.scope.getBinding(rootId.name);
2123
+ const binding = path9.scope.getBinding(rootId.name);
2114
2124
  if (!binding) return null;
2115
2125
  const rootPath = getVariableDeclaratorPath(binding.path);
2116
2126
  return rootPath;
@@ -2122,14 +2132,14 @@ function findRootIdentifier(node) {
2122
2132
  }
2123
2133
  return t19.isIdentifier(current) ? current : null;
2124
2134
  }
2125
- function getVariableDeclaratorPath(path8) {
2126
- if (path8.isVariableDeclarator()) {
2127
- return path8;
2135
+ function getVariableDeclaratorPath(path9) {
2136
+ if (path9.isVariableDeclarator()) {
2137
+ return path9;
2128
2138
  }
2129
- return path8.findParent((p) => p.isVariableDeclarator());
2139
+ return path9.findParent((p) => p.isVariableDeclarator());
2130
2140
  }
2131
- function isVariableDeclTopLevel(path8) {
2132
- const variableDeclaratorPath = path8;
2141
+ function isVariableDeclTopLevel(path9) {
2142
+ const variableDeclaratorPath = path9;
2133
2143
  const variableDeclarationPath = variableDeclaratorPath.parentPath;
2134
2144
  if (!variableDeclarationPath) {
2135
2145
  return false;
@@ -2143,61 +2153,61 @@ function isVariableDeclTopLevel(path8) {
2143
2153
  }
2144
2154
  return false;
2145
2155
  }
2146
- function isRealVariableAccess(path8) {
2147
- return isIdentifierAccess(path8) && !isPropertyName(path8);
2156
+ function isRealVariableAccess(path9) {
2157
+ return isIdentifierAccess(path9) && !isPropertyName(path9);
2148
2158
  }
2149
- function isIdentifierAccess(path8) {
2150
- if (isIdentifierDeclaration(path8)) {
2159
+ function isIdentifierAccess(path9) {
2160
+ if (isIdentifierDeclaration(path9)) {
2151
2161
  return false;
2152
2162
  }
2153
- const binding = path8.scope.getBinding(path8.node.name);
2163
+ const binding = path9.scope.getBinding(path9.node.name);
2154
2164
  if (!binding) {
2155
2165
  return true;
2156
2166
  }
2157
- return binding.identifier !== path8.node;
2167
+ return binding.identifier !== path9.node;
2158
2168
  }
2159
- function isIdentifierDeclaration(path8) {
2160
- const parent = path8.parentPath;
2169
+ function isIdentifierDeclaration(path9) {
2170
+ const parent = path9.parentPath;
2161
2171
  if (!parent) return false;
2162
- if (parent.isVariableDeclarator() && parent.node.id === path8.node) {
2172
+ if (parent.isVariableDeclarator() && parent.node.id === path9.node) {
2163
2173
  return true;
2164
2174
  }
2165
- if (parent.isFunctionDeclaration() && parent.node.id === path8.node) {
2175
+ if (parent.isFunctionDeclaration() && parent.node.id === path9.node) {
2166
2176
  return true;
2167
2177
  }
2168
- if (parent.isFunctionExpression() && parent.node.id === path8.node) {
2178
+ if (parent.isFunctionExpression() && parent.node.id === path9.node) {
2169
2179
  return true;
2170
2180
  }
2171
- if (parent.isClassDeclaration() && parent.node.id === path8.node) {
2181
+ if (parent.isClassDeclaration() && parent.node.id === path9.node) {
2172
2182
  return true;
2173
2183
  }
2174
- if (parent.isImportSpecifier() && parent.node.local === path8.node) {
2184
+ if (parent.isImportSpecifier() && parent.node.local === path9.node) {
2175
2185
  return true;
2176
2186
  }
2177
- if (parent.isImportDefaultSpecifier() && parent.node.local === path8.node) {
2187
+ if (parent.isImportDefaultSpecifier() && parent.node.local === path9.node) {
2178
2188
  return true;
2179
2189
  }
2180
- if (parent.isImportNamespaceSpecifier() && parent.node.local === path8.node) {
2190
+ if (parent.isImportNamespaceSpecifier() && parent.node.local === path9.node) {
2181
2191
  return true;
2182
2192
  }
2183
- if (parent.isFunction() && parent.node.params.includes(path8.node)) {
2193
+ if (parent.isFunction() && parent.node.params.includes(path9.node)) {
2184
2194
  return true;
2185
2195
  }
2186
- if (parent.isCatchClause() && parent.node.param === path8.node) {
2196
+ if (parent.isCatchClause() && parent.node.param === path9.node) {
2187
2197
  return true;
2188
2198
  }
2189
2199
  return false;
2190
2200
  }
2191
- function isPropertyName(path8) {
2192
- const parent = path8.parentPath;
2201
+ function isPropertyName(path9) {
2202
+ const parent = path9.parentPath;
2193
2203
  if (!parent) return false;
2194
- if (parent.isObjectProperty() && parent.node.key === path8.node) {
2204
+ if (parent.isObjectProperty() && parent.node.key === path9.node) {
2195
2205
  return true;
2196
2206
  }
2197
- if (parent.isClassProperty() && parent.node.key === path8.node) {
2207
+ if (parent.isClassProperty() && parent.node.key === path9.node) {
2198
2208
  return true;
2199
2209
  }
2200
- if (parent.isMemberExpression() && parent.node.property === path8.node) {
2210
+ if (parent.isMemberExpression() && parent.node.property === path9.node) {
2201
2211
  return true;
2202
2212
  }
2203
2213
  return false;
@@ -2308,26 +2318,26 @@ function resolveStaticHoisting(ctx) {
2308
2318
  return {};
2309
2319
  }
2310
2320
  return {
2311
- "ImportDeclaration|ExportDeclaration"(path8) {
2312
- if (t20.isImportDeclaration(path8.node)) {
2313
- scriptIR.imports.push(path8.node);
2314
- } else if (t20.isExportDeclaration(path8.node)) {
2315
- scriptIR.exports.push(path8.node);
2321
+ "ImportDeclaration|ExportDeclaration"(path9) {
2322
+ if (t20.isImportDeclaration(path9.node)) {
2323
+ scriptIR.imports.push(path9.node);
2324
+ } else if (t20.isExportDeclaration(path9.node)) {
2325
+ scriptIR.exports.push(path9.node);
2316
2326
  }
2317
- path8.remove();
2327
+ path9.remove();
2318
2328
  },
2319
- "TSInterfaceDeclaration|TSTypeAliasDeclaration|TSEnumDeclaration|TSModuleDeclaration|TSModuleDeclaration"(path8) {
2320
- if (t20.isProgram(path8.parent)) {
2321
- scriptIR.tsTypes.push(path8.node);
2322
- path8.remove();
2329
+ "TSInterfaceDeclaration|TSTypeAliasDeclaration|TSEnumDeclaration|TSModuleDeclaration|TSModuleDeclaration"(path9) {
2330
+ if (t20.isProgram(path9.parent)) {
2331
+ scriptIR.tsTypes.push(path9.node);
2332
+ path9.remove();
2323
2333
  }
2324
2334
  },
2325
- VariableDeclarator(path8) {
2326
- const { node } = path8;
2327
- if (!isVariableDeclTopLevel(path8) || !isSimpleLiteral(node.init) || getScriptNodeMeta(node)) {
2335
+ VariableDeclarator(path9) {
2336
+ const { node } = path9;
2337
+ if (!isVariableDeclTopLevel(path9) || !isSimpleLiteral(node.init) || getScriptNodeMeta(node)) {
2328
2338
  return;
2329
2339
  }
2330
- const declarationPath = path8.findParent((p) => p.isVariableDeclaration());
2340
+ const declarationPath = path9.findParent((p) => p.isVariableDeclaration());
2331
2341
  if (!declarationPath) return;
2332
2342
  scriptIR.statement.global.push(declarationPath.node);
2333
2343
  declarationPath.remove();
@@ -2344,14 +2354,14 @@ function collectLocalStatements(ctx, ast) {
2344
2354
 
2345
2355
  function resolveDefineAsyncComponent(ctx) {
2346
2356
  return {
2347
- CallExpression(path8) {
2348
- const { node } = path8;
2357
+ CallExpression(path9) {
2358
+ const { node } = path9;
2349
2359
  if (!isCalleeNamed(node, VUE_API_MAP.defineAsyncComponent)) {
2350
2360
  return;
2351
2361
  }
2352
2362
  const [arg] = node.arguments;
2353
2363
  checkIsUnsupported(ctx, arg);
2354
- pushToGlobalScope(path8, ctx);
2364
+ pushToGlobalScope(path9, ctx);
2355
2365
  recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.lazy);
2356
2366
  }
2357
2367
  };
@@ -2414,15 +2424,15 @@ function warnMultipleOptionsUsed(ctx, node) {
2414
2424
  }
2415
2425
  );
2416
2426
  }
2417
- function pushToGlobalScope(path8, ctx) {
2418
- const { node } = path8;
2427
+ function pushToGlobalScope(path9, ctx) {
2428
+ const { node } = path9;
2419
2429
  const callee = node.callee;
2420
2430
  callee.name = REACT_API_MAP.lazy;
2421
2431
  callee.loc.identifierName = REACT_API_MAP.lazy;
2422
2432
  if (node.typeParameters) {
2423
2433
  node.typeParameters = void 0;
2424
2434
  }
2425
- let declarationPath = path8.parentPath;
2435
+ let declarationPath = path9.parentPath;
2426
2436
  while (declarationPath) {
2427
2437
  if (declarationPath.isVariableDeclaration()) {
2428
2438
  break;
@@ -2433,12 +2443,12 @@ function pushToGlobalScope(path8, ctx) {
2433
2443
  if (_optionalChain([declarationPath, 'optionalAccess', _61 => _61.isVariableDeclaration, 'call', _62 => _62()])) {
2434
2444
  fullNode = declarationPath.node;
2435
2445
  declarationPath.remove();
2436
- } else if (path8.parentPath.isVariableDeclarator()) {
2437
- fullNode = path8.parent;
2438
- path8.parentPath.remove();
2446
+ } else if (path9.parentPath.isVariableDeclarator()) {
2447
+ fullNode = path9.parent;
2448
+ path9.parentPath.remove();
2439
2449
  } else {
2440
- fullNode = path8.node;
2441
- path8.remove();
2450
+ fullNode = path9.node;
2451
+ path9.remove();
2442
2452
  }
2443
2453
  const scriptIR = getScriptIR(ctx);
2444
2454
  scriptIR.statement.global.push(fullNode);
@@ -2469,15 +2479,15 @@ function createUseImperativeHandle(refId, init) {
2469
2479
  function resolveDefineExpose(ctx) {
2470
2480
  if (ctx.inputType !== "sfc") return {};
2471
2481
  return {
2472
- CallExpression(path8) {
2473
- const { node } = path8;
2482
+ CallExpression(path9) {
2483
+ const { node } = path9;
2474
2484
  const { filename, scriptData } = ctx;
2475
2485
  if (!isCalleeNamed(node, MACRO_API_NAMES.expose)) {
2476
2486
  return;
2477
2487
  }
2478
2488
  const [expose] = node.arguments;
2479
2489
  if (!expose) {
2480
- path8.remove();
2490
+ path9.remove();
2481
2491
  return;
2482
2492
  }
2483
2493
  const adapter = ADAPTER_RULES.react[MACRO_API_NAMES.expose];
@@ -2494,7 +2504,7 @@ function resolveDefineExpose(ctx) {
2494
2504
  const { forwardRef } = scriptData;
2495
2505
  const newNode = createUseImperativeHandle(t23.identifier(forwardRef.refField), init);
2496
2506
  forwardRef.enabled = true;
2497
- path8.replaceWith(newNode);
2507
+ path9.replaceWith(newNode);
2498
2508
  }
2499
2509
  };
2500
2510
  }
@@ -2503,8 +2513,8 @@ function resolveDefineExpose(ctx) {
2503
2513
 
2504
2514
  function resolveDefineOptions(ctx) {
2505
2515
  return {
2506
- CallExpression(path8) {
2507
- const { node } = path8;
2516
+ CallExpression(path9) {
2517
+ const { node } = path9;
2508
2518
  if (!isCalleeNamed(node, MACRO_API_NAMES.options)) {
2509
2519
  return;
2510
2520
  }
@@ -2516,7 +2526,7 @@ function resolveDefineOptions(ctx) {
2516
2526
  file: filename,
2517
2527
  loc: _optionalChain([node, 'optionalAccess', _63 => _63.loc])
2518
2528
  });
2519
- path8.remove();
2529
+ path9.remove();
2520
2530
  return;
2521
2531
  }
2522
2532
  if (!t24.isObjectExpression(options)) {
@@ -2533,7 +2543,7 @@ function resolveDefineOptions(ctx) {
2533
2543
  extractName(prop, ctx);
2534
2544
  }
2535
2545
  }
2536
- path8.remove();
2546
+ path9.remove();
2537
2547
  }
2538
2548
  };
2539
2549
  }
@@ -2565,8 +2575,8 @@ function resolveEmitCalls(ctx) {
2565
2575
  return `on${capitalize(camelCase(normalized))}`;
2566
2576
  };
2567
2577
  return {
2568
- CallExpression(path8) {
2569
- const { node } = path8;
2578
+ CallExpression(path9) {
2579
+ const { node } = path9;
2570
2580
  const { filename, templateData, scriptData } = ctx;
2571
2581
  if (!t25.isIdentifier(node.callee)) return;
2572
2582
  const { name } = node.callee;
@@ -2577,7 +2587,7 @@ function resolveEmitCalls(ctx) {
2577
2587
  result = meta.source === MACRO_API_NAMES.emits;
2578
2588
  }
2579
2589
  if (!result) {
2580
- const binding = path8.scope.getBinding(name);
2590
+ const binding = path9.scope.getBinding(name);
2581
2591
  if (binding) {
2582
2592
  const parent = binding.path.node;
2583
2593
  if (t25.isVariableDeclarator(parent) && t25.isCallExpression(parent.init) && t25.isIdentifier(parent.init.callee)) {
@@ -2596,7 +2606,7 @@ function resolveEmitCalls(ctx) {
2596
2606
  source: scriptData.source,
2597
2607
  loc: _optionalChain([callee, 'optionalAccess', _68 => _68.loc])
2598
2608
  });
2599
- path8.remove();
2609
+ path9.remove();
2600
2610
  return;
2601
2611
  }
2602
2612
  const propCall = t25.optionalCallExpression(
@@ -2609,7 +2619,7 @@ function resolveEmitCalls(ctx) {
2609
2619
  args,
2610
2620
  true
2611
2621
  );
2612
- path8.replaceWith(propCall);
2622
+ path9.replaceWith(propCall);
2613
2623
  }
2614
2624
  };
2615
2625
  }
@@ -2647,9 +2657,9 @@ function cloneCallableParams(params) {
2647
2657
  // src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-emits.ts
2648
2658
  function resolveEmitsTopLevelTypes(ctx) {
2649
2659
  return {
2650
- "TSInterfaceDeclaration|TSTypeAliasDeclaration"(path8) {
2651
- if (!t27.isProgram(path8.parent)) return;
2652
- const { node } = path8;
2660
+ "TSInterfaceDeclaration|TSTypeAliasDeclaration"(path9) {
2661
+ if (!t27.isProgram(path9.parent)) return;
2662
+ const { node } = path9;
2653
2663
  if (t27.isTSInterfaceDeclaration(node)) {
2654
2664
  const typeLiteral = t27.tsTypeLiteral(node.body.body);
2655
2665
  if (!hasEmitsSignatureInType(typeLiteral)) return;
@@ -2714,8 +2724,8 @@ function resolveTopLevelEmitType(tsType) {
2714
2724
  }
2715
2725
  return tsType;
2716
2726
  }
2717
- function resolveDefineEmitsIface(path8, ctx) {
2718
- const { node } = path8;
2727
+ function resolveDefineEmitsIface(path9, ctx) {
2728
+ const { node } = path9;
2719
2729
  const [runtimeArg] = node.arguments;
2720
2730
  const tsParams = _optionalChain([node, 'access', _69 => _69.typeParameters, 'optionalAccess', _70 => _70.params]);
2721
2731
  if (_optionalChain([tsParams, 'optionalAccess', _71 => _71.length])) {
@@ -3015,8 +3025,8 @@ function resolveTupleElementParam(element, index) {
3015
3025
 
3016
3026
  // src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-props.ts
3017
3027
 
3018
- function resolveDefinePropsIface(path8, ctx) {
3019
- const { node } = path8;
3028
+ function resolveDefinePropsIface(path9, ctx) {
3029
+ const { node } = path9;
3020
3030
  const [runtimeArg] = node.arguments;
3021
3031
  const tsParams = _optionalChain([node, 'access', _79 => _79.typeParameters, 'optionalAccess', _80 => _80.params]);
3022
3032
  if (_optionalChain([tsParams, 'optionalAccess', _81 => _81.length])) {
@@ -3162,9 +3172,9 @@ var SLOT_CHILDREN_NAME = "children";
3162
3172
  var SLOT_FN_PARAM_NAME = "props";
3163
3173
  function resolveSlotsTopLevelTypes(ctx) {
3164
3174
  return {
3165
- "TSInterfaceDeclaration|TSTypeAliasDeclaration"(path8) {
3166
- if (!t29.isProgram(path8.parent)) return;
3167
- const { node } = path8;
3175
+ "TSInterfaceDeclaration|TSTypeAliasDeclaration"(path9) {
3176
+ if (!t29.isProgram(path9.parent)) return;
3177
+ const { node } = path9;
3168
3178
  if (t29.isTSInterfaceDeclaration(node)) {
3169
3179
  const typeLiteral = t29.tsTypeLiteral(node.body.body);
3170
3180
  if (!hasSlotsSignatureInType(typeLiteral)) return;
@@ -3186,8 +3196,8 @@ function resolveSlotsTopLevelTypes(ctx) {
3186
3196
  }
3187
3197
  };
3188
3198
  }
3189
- function resolveDefineSlotsIface(path8, ctx) {
3190
- const { node } = path8;
3199
+ function resolveDefineSlotsIface(path9, ctx) {
3200
+ const { node } = path9;
3191
3201
  const tsParams = _optionalChain([node, 'access', _83 => _83.typeParameters, 'optionalAccess', _84 => _84.params]);
3192
3202
  if (!_optionalChain([tsParams, 'optionalAccess', _85 => _85.length])) return;
3193
3203
  const {
@@ -3378,8 +3388,8 @@ function resolvePropName2(key) {
3378
3388
  function resolvePropsIface(ctx) {
3379
3389
  const isTS = ctx.scriptData.lang.startsWith("ts");
3380
3390
  return {
3381
- CallExpression(path8) {
3382
- const { node, parentPath } = path8;
3391
+ CallExpression(path9) {
3392
+ const { node, parentPath } = path9;
3383
3393
  const name = node.callee.name;
3384
3394
  if (!isCalleeNamed(node, MACRO_API_NAMES.props) && !isCalleeNamed(node, MACRO_API_NAMES.emits) && !isCalleeNamed(node, MACRO_API_NAMES.slots)) {
3385
3395
  return;
@@ -3388,7 +3398,7 @@ function resolvePropsIface(ctx) {
3388
3398
  if (parentPath.isVariableDeclaration() || parentPath.isVariableDeclarator()) {
3389
3399
  parentPath.remove();
3390
3400
  } else {
3391
- path8.remove();
3401
+ path9.remove();
3392
3402
  }
3393
3403
  };
3394
3404
  if (ctx.inputType !== "sfc") {
@@ -3402,11 +3412,11 @@ function resolvePropsIface(ctx) {
3402
3412
  propsTSIface.hasPropsInJsEnv = true;
3403
3413
  } else {
3404
3414
  if (name === MACRO_API_NAMES.props) {
3405
- resolveDefinePropsIface(path8, ctx);
3415
+ resolveDefinePropsIface(path9, ctx);
3406
3416
  } else if (name === MACRO_API_NAMES.emits) {
3407
- resolveDefineEmitsIface(path8, ctx);
3417
+ resolveDefineEmitsIface(path9, ctx);
3408
3418
  } else if (name === MACRO_API_NAMES.slots) {
3409
- resolveDefineSlotsIface(path8, ctx);
3419
+ resolveDefineSlotsIface(path9, ctx);
3410
3420
  }
3411
3421
  }
3412
3422
  removePath();
@@ -3451,15 +3461,27 @@ function analyzeDeps(node, ctx, parentPath) {
3451
3461
  function addDependency(exp) {
3452
3462
  deps.set(getDependencyKey(exp), exp);
3453
3463
  }
3464
+ const analyzeTargetPath = parentPath && parentPath.node === analyzeTarget ? parentPath : null;
3465
+ if (analyzeTargetPath) {
3466
+ if (t31.isMemberExpression(analyzeTarget) || t31.isOptionalMemberExpression(analyzeTarget)) {
3467
+ const rootId = findRootIdentifier(analyzeTarget);
3468
+ if (rootId) {
3469
+ tryAddDependency(analyzeTargetPath, rootId.name, analyzeTargetPath.scope);
3470
+ processedIdentifiers.add(rootId);
3471
+ }
3472
+ } else if (t31.isIdentifier(analyzeTarget)) {
3473
+ tryAddDependency(analyzeTargetPath, analyzeTarget.name, analyzeTargetPath.scope);
3474
+ }
3475
+ }
3454
3476
  _core.traverse.call(void 0,
3455
3477
  analyzeTarget,
3456
3478
  {
3457
3479
  "MemberExpression|OptionalMemberExpression"(memberPath) {
3458
- const path8 = memberPath;
3459
- if (isNestedMemberObject(path8)) return;
3460
- const rootId = findRootIdentifier(path8.node);
3480
+ const path9 = memberPath;
3481
+ if (isNestedMemberObject(path9)) return;
3482
+ const rootId = findRootIdentifier(path9.node);
3461
3483
  if (!rootId) return;
3462
- tryAddDependency(path8, rootId.name, path8.scope);
3484
+ tryAddDependency(path9, rootId.name, path9.scope);
3463
3485
  processedIdentifiers.add(rootId);
3464
3486
  },
3465
3487
  Identifier(idPath) {
@@ -3491,16 +3513,19 @@ function analyzeDeps(node, ctx, parentPath) {
3491
3513
  }
3492
3514
  const sourcedExpression = traceBindingSource(binding, /* @__PURE__ */ new Set(), TRACE_MAX_DEPTH);
3493
3515
  if (sourcedExpression) {
3494
- addDependency(sourcedExpression);
3516
+ const normalizedSource = normalizeSourcedDependency(sourcedExpression);
3517
+ if (normalizedSource) {
3518
+ addDependency(normalizedSource);
3519
+ }
3495
3520
  }
3496
3521
  }
3497
- function normalizeDependencyExpr(path8, rootName) {
3498
- if (t31.isIdentifier(path8.node)) {
3499
- return t31.identifier(path8.node.name);
3522
+ function normalizeDependencyExpr(path9, rootName) {
3523
+ if (t31.isIdentifier(path9.node)) {
3524
+ return t31.identifier(path9.node.name);
3500
3525
  }
3501
- if (t31.isMemberExpression(path8.node) || t31.isOptionalMemberExpression(path8.node)) {
3502
- const normalizedExp = normalizeMemberForCallSite(path8, path8.node);
3503
- const safeExp = t31.isMemberExpression(normalizedExp) || t31.isOptionalMemberExpression(normalizedExp) ? ensureOptionalForRefValue(normalizedExp) : normalizedExp;
3526
+ if (t31.isMemberExpression(path9.node) || t31.isOptionalMemberExpression(path9.node)) {
3527
+ const normalizedExp = normalizeMemberForCallSite(path9, path9.node);
3528
+ const safeExp = t31.isMemberExpression(normalizedExp) || t31.isOptionalMemberExpression(normalizedExp) ? ensureOptionalForMemberChain(normalizedExp) : normalizedExp;
3504
3529
  if (isReactValidDependencyExpr(safeExp)) {
3505
3530
  return t31.cloneNode(safeExp, true);
3506
3531
  }
@@ -3508,6 +3533,21 @@ function analyzeDeps(node, ctx, parentPath) {
3508
3533
  }
3509
3534
  return null;
3510
3535
  }
3536
+ function normalizeSourcedDependency(exp) {
3537
+ if (t31.isIdentifier(exp)) {
3538
+ return t31.identifier(exp.name);
3539
+ }
3540
+ if (t31.isMemberExpression(exp) || t31.isOptionalMemberExpression(exp)) {
3541
+ const root = findRootIdentifier(exp);
3542
+ if (!root) return null;
3543
+ const safeExp = t31.isMemberExpression(exp) || t31.isOptionalMemberExpression(exp) ? ensureOptionalForMemberChain(exp) : exp;
3544
+ if (isReactValidDependencyExpr(safeExp)) {
3545
+ return t31.cloneNode(safeExp, true);
3546
+ }
3547
+ return t31.identifier(root.name);
3548
+ }
3549
+ return null;
3550
+ }
3511
3551
  function isReactValidDependencyExpr(node2) {
3512
3552
  if (t31.isIdentifier(node2)) {
3513
3553
  return true;
@@ -3540,8 +3580,8 @@ function analyzeDeps(node, ctx, parentPath) {
3540
3580
  }
3541
3581
  return false;
3542
3582
  }
3543
- function normalizeMemberForCallSite(path8, node2) {
3544
- const parent = path8.parentPath;
3583
+ function normalizeMemberForCallSite(path9, node2) {
3584
+ const parent = path9.parentPath;
3545
3585
  const isDirectCallee = !!parent && (parent.isCallExpression() && parent.node.callee === node2 || parent.isOptionalCallExpression() && parent.node.callee === node2);
3546
3586
  if (!isDirectCallee) {
3547
3587
  return node2;
@@ -3551,8 +3591,8 @@ function analyzeDeps(node, ctx, parentPath) {
3551
3591
  }
3552
3592
  return node2.object;
3553
3593
  }
3554
- function ensureOptionalForRefValue(node2) {
3555
- if (!hasRefValueAccess(node2)) {
3594
+ function ensureOptionalForMemberChain(node2) {
3595
+ if (!hasTrailingMemberAccess(node2)) {
3556
3596
  return node2;
3557
3597
  }
3558
3598
  if (t31.isOptionalMemberExpression(node2) && node2.optional) {
@@ -3562,19 +3602,8 @@ function analyzeDeps(node, ctx, parentPath) {
3562
3602
  const property = t31.cloneNode(node2.property, true);
3563
3603
  return t31.optionalMemberExpression(object, property, node2.computed, true);
3564
3604
  }
3565
- function hasRefValueAccess(node2) {
3566
- let current = node2;
3567
- while (t31.isMemberExpression(current) || t31.isOptionalMemberExpression(current)) {
3568
- if (current.computed) {
3569
- if (t31.isStringLiteral(current.property) && current.property.value === "value") {
3570
- return true;
3571
- }
3572
- } else if (t31.isIdentifier(current.property) && current.property.name === "value") {
3573
- return true;
3574
- }
3575
- current = current.object;
3576
- }
3577
- return false;
3605
+ function hasTrailingMemberAccess(node2) {
3606
+ return t31.isMemberExpression(node2.object) || t31.isOptionalMemberExpression(node2.object);
3578
3607
  }
3579
3608
  function isEligibleBindingSource(binding) {
3580
3609
  if (binding.kind === "param") {
@@ -3582,16 +3611,13 @@ function analyzeDeps(node, ctx, parentPath) {
3582
3611
  }
3583
3612
  const bindingPath = binding.path;
3584
3613
  const declaratorPath = getVariableDeclaratorPath(bindingPath);
3585
- const isImportBinding = bindingPath.isImportSpecifier() || bindingPath.isImportDefaultSpecifier() || bindingPath.isImportNamespaceSpecifier();
3586
3614
  const isReactiveVarBinding = !!declaratorPath && isReactiveBinding(declaratorPath.node);
3587
3615
  const nodeInit = _optionalChain([declaratorPath, 'optionalAccess', _92 => _92.node, 'access', _93 => _93.init]);
3588
3616
  const isReactiveApiCallVarBinding = !!declaratorPath && t31.isCallExpression(nodeInit) && t31.isIdentifier(nodeInit.callee) && reactiveStateApis.has(nodeInit.callee.name);
3589
3617
  const isHookCallVarBinding = !!declaratorPath && t31.isCallExpression(nodeInit) && isHookLikeCallee(nodeInit.callee);
3590
3618
  const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (t31.isArrowFunctionExpression(nodeInit) || t31.isFunctionExpression(nodeInit));
3591
- if (declaratorPath && nodeInit && (t31.isArrowFunctionExpression(nodeInit) || t31.isFunctionExpression(nodeInit))) {
3592
- markAsAnalyzed(nodeInit, false);
3593
- }
3594
- return isImportBinding || isReactiveVarBinding || isReactiveApiCallVarBinding || isHookCallVarBinding || isFunctionBinding;
3619
+ const isReactiveFunctionBinding = isFunctionBinding && (isReactiveBinding(_optionalChain([declaratorPath, 'optionalAccess', _94 => _94.node])) || isReactiveBinding(bindingPath.node));
3620
+ return isReactiveVarBinding || isReactiveApiCallVarBinding || isHookCallVarBinding || isReactiveFunctionBinding;
3595
3621
  }
3596
3622
  function isHookLikeCallee(callee) {
3597
3623
  if (t31.isIdentifier(callee)) {
@@ -3687,39 +3713,31 @@ function getDependencyKey(exp) {
3687
3713
  }
3688
3714
  return exp.type;
3689
3715
  }
3690
- function isNestedMemberObject(path8) {
3691
- const parent = path8.parentPath;
3716
+ function isNestedMemberObject(path9) {
3717
+ const parent = path9.parentPath;
3692
3718
  if (!parent) return false;
3693
3719
  if (parent.isMemberExpression() || parent.isOptionalMemberExpression()) {
3694
- return parent.node.object === path8.node;
3720
+ return parent.node.object === path9.node;
3695
3721
  }
3696
3722
  return false;
3697
3723
  }
3698
3724
  function isReactiveBinding(node) {
3699
3725
  if (!node) return false;
3700
- return !!_optionalChain([getScriptNodeMeta, 'call', _94 => _94(node), 'optionalAccess', _95 => _95.is_reactive]);
3701
- }
3702
- function markAsAnalyzed(node, flag = true) {
3703
- const analyzed = getIsAnalyzed(node);
3704
- if (analyzed) return;
3705
- setScriptNodeMeta(node, { is_deps_analyzed: flag });
3706
- }
3707
- function getIsAnalyzed(node) {
3708
- return _optionalChain([getScriptNodeMeta, 'call', _96 => _96(node), 'optionalAccess', _97 => _97.is_deps_analyzed]);
3726
+ return !!_optionalChain([getScriptNodeMeta, 'call', _95 => _95(node), 'optionalAccess', _96 => _96.is_reactive]);
3709
3727
  }
3710
3728
 
3711
3729
  // src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
3712
3730
  function resolveAnalysisOnlyAdapter(ctx) {
3713
3731
  return {
3714
- "CallExpression|Identifier"(path8) {
3715
- const node = path8.node;
3732
+ "CallExpression|Identifier"(path9) {
3733
+ const node = path9.node;
3716
3734
  const apiName = getApiName(node);
3717
3735
  const adapter = ADAPTER_RULES.runtime[apiName];
3718
3736
  if (!adapter || adapter.type !== "analyzed-deps") {
3719
3737
  return;
3720
3738
  }
3721
3739
  if (t32.isCallExpression(node)) {
3722
- resolveCallNode(path8, adapter, ctx);
3740
+ resolveCallNode(path9, adapter, ctx);
3723
3741
  } else {
3724
3742
  replaceIdName(node, adapter.target);
3725
3743
  }
@@ -3737,15 +3755,15 @@ function getApiName(node) {
3737
3755
  }
3738
3756
  return apiName;
3739
3757
  }
3740
- function resolveCallNode(path8, adapter, ctx) {
3741
- const { node } = path8;
3758
+ function resolveCallNode(path9, adapter, ctx) {
3759
+ const { node } = path9;
3742
3760
  const { arguments: args } = node;
3743
3761
  if (!args.length) return;
3744
3762
  const fn = args[0];
3745
3763
  if (!t32.isArrowFunctionExpression(fn) && !t32.isFunctionExpression(fn)) {
3746
3764
  return;
3747
3765
  }
3748
- const fnPath = path8.get("arguments")[0];
3766
+ const fnPath = path9.get("arguments")[0];
3749
3767
  const deps = analyzeDeps(fn, ctx, fnPath);
3750
3768
  args.push(deps);
3751
3769
  replaceCallName(node, adapter.target);
@@ -3755,41 +3773,24 @@ function resolveCallNode(path8, adapter, ctx) {
3755
3773
  // src/core/transform/sfc/script/syntax-processor/process/resolve-arrow-deps.ts
3756
3774
  function resolveArrowFnDeps(ctx, ast) {
3757
3775
  return {
3758
- ArrowFunctionExpression(path8) {
3759
- const { node, parentPath } = path8;
3760
- if (isSkip(path8) || !atComponentOrHookRoot(parentPath, ast.program)) {
3776
+ ArrowFunctionExpression(path9) {
3777
+ const { node, parentPath } = path9;
3778
+ if (isSkip(path9) || !atComponentOrHookRoot(parentPath, ast.program)) {
3761
3779
  return;
3762
3780
  }
3763
- const deps = analyzeDeps(node, ctx, path8);
3781
+ const deps = analyzeDeps(node, ctx, path9);
3764
3782
  if (!deps.elements.length) return;
3765
3783
  const newNode = createUseCallback(node, deps);
3766
- const declaratorPath = getVariableDeclaratorPath(path8);
3767
- markAsAnalyzed(newNode.arguments[0]);
3784
+ const declaratorPath = getVariableDeclaratorPath(path9);
3768
3785
  recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useCallback);
3769
- setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _98 => _98.node]), { is_reactive: true, reactive_type: "indirect" });
3770
- path8.replaceWith(newNode);
3771
- }
3772
- };
3773
- }
3774
- function resolveUnanalyzedArrow(ctx) {
3775
- return {
3776
- ArrowFunctionExpression(path8) {
3777
- const { node } = path8;
3778
- const analyzed = getIsAnalyzed(node);
3779
- if (typeof analyzed === "undefined" || analyzed) return;
3780
- const newNode = createUseCallback(node);
3781
- const declaratorPath = getVariableDeclaratorPath(path8);
3782
- if (_optionalChain([declaratorPath, 'optionalAccess', _99 => _99.node])) {
3783
- setScriptNodeMeta(declaratorPath.node, { is_reactive: true, reactive_type: "indirect" });
3784
- }
3785
- markAsAnalyzed(newNode.arguments[0]);
3786
- path8.replaceWith(newNode);
3786
+ setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _97 => _97.node]), { is_reactive: true, reactive_type: "indirect" });
3787
+ path9.replaceWith(newNode);
3787
3788
  }
3788
3789
  };
3789
3790
  }
3790
- function isSkip(path8) {
3791
- const { parentPath } = path8;
3792
- const isVariableDecl = () => getVariableDeclaratorPath(path8) !== null;
3791
+ function isSkip(path9) {
3792
+ const { parentPath } = path9;
3793
+ const isVariableDecl = () => getVariableDeclaratorPath(path9) !== null;
3793
3794
  const isReturnFunc = () => !isVariableDecl() && parentPath.isReturnStatement();
3794
3795
  const isCallback = () => {
3795
3796
  if (!parentPath) {
@@ -3798,12 +3799,12 @@ function isSkip(path8) {
3798
3799
  if (parentPath.isCallExpression()) {
3799
3800
  const callExpressionPath = parentPath;
3800
3801
  const args = callExpressionPath.node.arguments;
3801
- return args.some((arg) => arg === path8.node);
3802
+ return args.some((arg) => arg === path9.node);
3802
3803
  }
3803
3804
  if (parentPath.isArrayExpression()) {
3804
3805
  const arrayExpressionPath = parentPath;
3805
3806
  const elements = arrayExpressionPath.node.elements;
3806
- return elements.some((element) => element === path8.node);
3807
+ return elements.some((element) => element === path9.node);
3807
3808
  }
3808
3809
  return false;
3809
3810
  };
@@ -3827,13 +3828,13 @@ function isSkip(path8) {
3827
3828
 
3828
3829
  function resolveElementRef(ctx) {
3829
3830
  return {
3830
- CallExpression(path8) {
3831
+ CallExpression(path9) {
3831
3832
  const {
3832
3833
  inputType,
3833
3834
  templateData: { refBindings }
3834
3835
  } = ctx;
3835
3836
  if (inputType !== "sfc") return;
3836
- const { node } = path8;
3837
+ const { node } = path9;
3837
3838
  const isUseTemplateRef = isCalleeNamed(node, VUE_API_MAP.useTemplateRef);
3838
3839
  const isCompRefBindings = Object.keys(refBindings.componentRefs).length > 0 && isCalleeNamed(node, VUE_API_MAP.ref);
3839
3840
  const shouldProcess = isUseTemplateRef || isCompRefBindings;
@@ -3841,8 +3842,8 @@ function resolveElementRef(ctx) {
3841
3842
  return;
3842
3843
  }
3843
3844
  if (isCompRefBindings) {
3844
- const varDeclaratorPath = _optionalChain([getVariableDeclaratorPath, 'call', _100 => _100(path8), 'optionalAccess', _101 => _101.node]);
3845
- if (!t33.isIdentifier(_optionalChain([varDeclaratorPath, 'optionalAccess', _102 => _102.id]))) {
3845
+ const varDeclaratorPath = _optionalChain([getVariableDeclaratorPath, 'call', _98 => _98(path9), 'optionalAccess', _99 => _99.node]);
3846
+ if (!t33.isIdentifier(_optionalChain([varDeclaratorPath, 'optionalAccess', _100 => _100.id]))) {
3846
3847
  return;
3847
3848
  }
3848
3849
  const varName = varDeclaratorPath.id.name;
@@ -3850,22 +3851,22 @@ function resolveElementRef(ctx) {
3850
3851
  if (!compRef) return;
3851
3852
  }
3852
3853
  node.arguments[0] = t33.identifier("null");
3853
- resolveTypeParameters(ctx, path8);
3854
+ resolveTypeParameters(ctx, path9);
3854
3855
  replaceCallName(node, REACT_API_MAP.useRef);
3855
3856
  recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useRef);
3856
3857
  },
3857
- MemberExpression(path8) {
3858
- resolveRefValueToCurrent(path8);
3858
+ MemberExpression(path9) {
3859
+ resolveRefValueToCurrent(path9);
3859
3860
  }
3860
3861
  };
3861
3862
  }
3862
- function resolveTypeParameters(ctx, path8) {
3863
+ function resolveTypeParameters(ctx, path9) {
3863
3864
  const {
3864
3865
  templateData: { refBindings },
3865
3866
  scriptData
3866
3867
  } = ctx;
3867
- const { node } = path8;
3868
- const varDeclaratorNode = _optionalChain([getVariableDeclaratorPath, 'call', _103 => _103(path8), 'optionalAccess', _104 => _104.node]);
3868
+ const { node } = path9;
3869
+ const varDeclaratorNode = _optionalChain([getVariableDeclaratorPath, 'call', _101 => _101(path9), 'optionalAccess', _102 => _102.node]);
3869
3870
  if (!scriptData.lang.startsWith("ts") || !varDeclaratorNode) {
3870
3871
  return;
3871
3872
  }
@@ -3877,17 +3878,17 @@ function resolveTypeParameters(ctx, path8) {
3877
3878
  node.typeParameters = t33.tsTypeParameterInstantiation([t33.tsTypeReference(t33.identifier(type))]);
3878
3879
  }
3879
3880
  }
3880
- function resolveRefValueToCurrent(path8) {
3881
- const { node } = path8;
3881
+ function resolveRefValueToCurrent(path9) {
3882
+ const { node } = path9;
3882
3883
  if (node.computed || !t33.isIdentifier(node.property) || node.property.name !== "value") {
3883
3884
  return;
3884
3885
  }
3885
- const rootPath = findRootVariablePath(path8);
3886
- if (!_optionalChain([rootPath, 'optionalAccess', _105 => _105.node]) || !t33.isCallExpression(rootPath.node.init) || !isCalleeNamed(rootPath.node.init, REACT_API_MAP.useRef)) {
3886
+ const rootPath = findRootVariablePath(path9);
3887
+ if (!_optionalChain([rootPath, 'optionalAccess', _103 => _103.node]) || !t33.isCallExpression(rootPath.node.init) || !isCalleeNamed(rootPath.node.init, REACT_API_MAP.useRef)) {
3887
3888
  return;
3888
3889
  }
3889
3890
  const rootId = findRootIdentifier(node);
3890
- if (!t33.isIdentifier(node.object) || node.object.name !== _optionalChain([rootId, 'optionalAccess', _106 => _106.name])) {
3891
+ if (!t33.isIdentifier(node.object) || node.object.name !== _optionalChain([rootId, 'optionalAccess', _104 => _104.name])) {
3891
3892
  return;
3892
3893
  }
3893
3894
  node.property.name = "current";
@@ -3898,21 +3899,25 @@ function resolveRefValueToCurrent(path8) {
3898
3899
  function resolveExprMemo(ctx, ast) {
3899
3900
  const isScriptFile = ctx.inputType !== "sfc";
3900
3901
  return {
3901
- VariableDeclarator(path8) {
3902
- const { node } = path8;
3902
+ VariableDeclarator(path9) {
3903
+ const { node } = path9;
3903
3904
  const { init } = node;
3904
- if (!init) return;
3905
3905
  const shouldMemo = () => {
3906
- if (!atComponentOrHookRoot(path8, ast.program, isScriptFile)) {
3906
+ if (!init) return false;
3907
+ if (!atComponentOrHookRoot(path9, ast.program, isScriptFile)) {
3908
+ return false;
3909
+ }
3910
+ if (!t34.isVariableDeclaration(path9.parent) || path9.parent.kind !== "const") {
3907
3911
  return false;
3908
3912
  }
3913
+ if (t34.isFunction(init)) return false;
3909
3914
  if (t34.isCallExpression(init) && t34.isIdentifier(init.callee) && init.callee.name.startsWith("use")) {
3910
3915
  return false;
3911
3916
  }
3912
3917
  return true;
3913
3918
  };
3914
3919
  if (!shouldMemo()) return;
3915
- const initPath = path8.get("init");
3920
+ const initPath = path9.get("init");
3916
3921
  if (!initPath.isExpression()) return;
3917
3922
  const deps = analyzeDeps(initPath.node, ctx, initPath);
3918
3923
  if (!deps.elements.length) return;
@@ -3928,8 +3933,8 @@ function resolveExprMemo(ctx, ast) {
3928
3933
  function resolveLintRules(ctx, ast) {
3929
3934
  const inScriptFile = ctx.inputType !== "sfc";
3930
3935
  return {
3931
- CallExpression(path8) {
3932
- const { node, parentPath } = path8;
3936
+ CallExpression(path9) {
3937
+ const { node, parentPath } = path9;
3933
3938
  if (!t35.isIdentifier(node.callee)) return;
3934
3939
  const { name: callName } = node.callee;
3935
3940
  const addLog = (t41) => {
@@ -3948,7 +3953,7 @@ function resolveLintRules(ctx, ast) {
3948
3953
  );
3949
3954
  return;
3950
3955
  }
3951
- if (!atComponentOrHookRoot(path8, ast.program)) {
3956
+ if (!atComponentOrHookRoot(path9, ast.program)) {
3952
3957
  addLog(
3953
3958
  `The ${macro} must be defined at the top level of the component, not inside blocks or functions.`
3954
3959
  );
@@ -3964,7 +3969,7 @@ function resolveLintRules(ctx, ast) {
3964
3969
  };
3965
3970
  const lintHooks = () => {
3966
3971
  if (!callName.startsWith("use")) return;
3967
- if (!atComponentOrHookRoot(path8, ast.program, inScriptFile)) {
3972
+ if (!atComponentOrHookRoot(path9, ast.program, inScriptFile)) {
3968
3973
  addLog(
3969
3974
  `The ${callName} hook must be called at the top level, not inside loops, conditions, or nested functions.`
3970
3975
  );
@@ -3982,9 +3987,9 @@ function resolveLintRules(ctx, ast) {
3982
3987
  function resolveProvide(ctx) {
3983
3988
  if (ctx.inputType === "style") return {};
3984
3989
  return {
3985
- CallExpression(path8) {
3986
- const { node } = path8;
3987
- const providerTarget = _optionalChain([ADAPTER_RULES, 'access', _107 => _107.runtime, 'access', _108 => _108[VUE_API_MAP.provide], 'optionalAccess', _109 => _109.target]);
3990
+ CallExpression(path9) {
3991
+ const { node } = path9;
3992
+ const providerTarget = _optionalChain([ADAPTER_RULES, 'access', _105 => _105.runtime, 'access', _106 => _106[VUE_API_MAP.provide], 'optionalAccess', _107 => _107.target]);
3988
3993
  const isProvideCall = isCalleeNamed(node, VUE_API_MAP.provide) || providerTarget && isCalleeNamed(node, providerTarget);
3989
3994
  if (!isProvideCall) return;
3990
3995
  const { provide } = ctx.scriptData;
@@ -3993,7 +3998,7 @@ function resolveProvide(ctx) {
3993
3998
  const adapter = ADAPTER_RULES.runtime[VUE_API_MAP.provide];
3994
3999
  assignProviderValue(target, key, value);
3995
4000
  recordImport(ctx, adapter.package, adapter.target);
3996
- path8.parentPath.remove();
4001
+ path9.parentPath.remove();
3997
4002
  }
3998
4003
  };
3999
4004
  }
@@ -4002,7 +4007,7 @@ function findOrCreateCtxProvider(root) {
4002
4007
  return root;
4003
4008
  }
4004
4009
  let cur = root.provide;
4005
- while (_optionalChain([cur, 'optionalAccess', _110 => _110.isOccupied])) {
4010
+ while (_optionalChain([cur, 'optionalAccess', _108 => _108.isOccupied])) {
4006
4011
  cur = _nullishCoalesce(cur.provide, () => ( {}));
4007
4012
  }
4008
4013
  return cur || (root.provide = {});
@@ -4035,8 +4040,8 @@ function assignProviderValue(target, key, value) {
4035
4040
 
4036
4041
  function resolveRenameAdapter(ctx) {
4037
4042
  return {
4038
- "CallExpression|Identifier"(path8) {
4039
- const node = path8.node;
4043
+ "CallExpression|Identifier"(path9) {
4044
+ const node = path9.node;
4040
4045
  const isCallNode = t37.isCallExpression(node);
4041
4046
  let apiName = "";
4042
4047
  if (t37.isIdentifier(node)) {
@@ -4052,8 +4057,8 @@ function resolveRenameAdapter(ctx) {
4052
4057
  }
4053
4058
  if (adapter.isTrackable) {
4054
4059
  const reactiveType = getReactiveType(apiName);
4055
- const declaratorPath = getVariableDeclaratorPath(path8);
4056
- setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _111 => _111.node]), {
4060
+ const declaratorPath = getVariableDeclaratorPath(path9);
4061
+ setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _109 => _109.node]), {
4057
4062
  is_reactive: true,
4058
4063
  reactive_type: reactiveType
4059
4064
  });
@@ -4091,10 +4096,11 @@ function processVueSyntax2(ast, ctx) {
4091
4096
  // provide 需要在 rename 之前收集并移除原始调用,避免被重命名后失配
4092
4097
  resolveProvide,
4093
4098
  resolveRenameAdapter,
4099
+ // fix:在分析函数前分析可优化为 useMemo 的顶层变量声明,
4100
+ // 使得后续能够被函数依赖分析
4101
+ resolveExprMemo,
4094
4102
  resolveArrowFnDeps,
4095
- resolveUnanalyzedArrow,
4096
4103
  resolveAnalysisOnlyAdapter,
4097
- resolveExprMemo,
4098
4104
  resolveLintRules
4099
4105
  ],
4100
4106
  excludeBabel: [resolveTemplateSlotIface, resolveCompIProps]
@@ -4107,12 +4113,12 @@ function processVueSyntax2(ast, ctx) {
4107
4113
  }
4108
4114
  function vueSyntaxProcessor2(ast, ctx, options) {
4109
4115
  const runExcludeThenApply = (cfg) => {
4110
- _optionalChain([cfg, 'access', _112 => _112.excludeBabel, 'optionalAccess', _113 => _113.forEach, 'call', _114 => _114((fn) => fn(ctx, ast))]);
4111
- _optionalChain([cfg, 'access', _115 => _115.applyBabel, 'optionalAccess', _116 => _116.forEach, 'call', _117 => _117((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
4116
+ _optionalChain([cfg, 'access', _110 => _110.excludeBabel, 'optionalAccess', _111 => _111.forEach, 'call', _112 => _112((fn) => fn(ctx, ast))]);
4117
+ _optionalChain([cfg, 'access', _113 => _113.applyBabel, 'optionalAccess', _114 => _114.forEach, 'call', _115 => _115((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
4112
4118
  };
4113
4119
  const runApplyThenExclude = (cfg) => {
4114
- _optionalChain([cfg, 'access', _118 => _118.applyBabel, 'optionalAccess', _119 => _119.forEach, 'call', _120 => _120((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
4115
- _optionalChain([cfg, 'access', _121 => _121.excludeBabel, 'optionalAccess', _122 => _122.forEach, 'call', _123 => _123((fn) => fn(ctx, ast))]);
4120
+ _optionalChain([cfg, 'access', _116 => _116.applyBabel, 'optionalAccess', _117 => _117.forEach, 'call', _118 => _118((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
4121
+ _optionalChain([cfg, 'access', _119 => _119.excludeBabel, 'optionalAccess', _120 => _120.forEach, 'call', _121 => _121((fn) => fn(ctx, ast))]);
4116
4122
  };
4117
4123
  runExcludeThenApply(options.preprocess);
4118
4124
  runExcludeThenApply(options.process);
@@ -4348,12 +4354,12 @@ function wrapSingleQuotes(content, condition) {
4348
4354
  return condition || strCodeTypes.isStringLiteral(content) ? `'${content}'` : content;
4349
4355
  }
4350
4356
  function checkPropIsDynamicKey(ctx, node) {
4351
- const isKeyStatic = _optionalChain([node, 'access', _124 => _124.arg, 'optionalAccess', _125 => _125.isStatic]);
4357
+ const isKeyStatic = _optionalChain([node, 'access', _122 => _122.arg, 'optionalAccess', _123 => _123.isStatic]);
4352
4358
  const { source, filename } = ctx;
4353
4359
  if (node.rawName === "v-bind" && !node.name) {
4354
4360
  logger.warn("Keyless v-bind will overwrite all previously declared props at runtime.", {
4355
4361
  source,
4356
- loc: _optionalChain([node, 'access', _126 => _126.arg, 'optionalAccess', _127 => _127.loc]),
4362
+ loc: _optionalChain([node, 'access', _124 => _124.arg, 'optionalAccess', _125 => _125.loc]),
4357
4363
  file: filename
4358
4364
  });
4359
4365
  return;
@@ -4361,7 +4367,7 @@ function checkPropIsDynamicKey(ctx, node) {
4361
4367
  if (isKeyStatic === false) {
4362
4368
  logger.warn("Avoid using dynamic slot names, as they generate complex JSX prop expressions.", {
4363
4369
  source,
4364
- loc: _optionalChain([node, 'access', _128 => _128.arg, 'optionalAccess', _129 => _129.loc]),
4370
+ loc: _optionalChain([node, 'access', _126 => _126.arg, 'optionalAccess', _127 => _127.loc]),
4365
4371
  file: filename
4366
4372
  });
4367
4373
  }
@@ -4406,19 +4412,19 @@ function resolvePropAsBabelExp(ir, ctx) {
4406
4412
  }
4407
4413
  if (isClassAttr(name) && !value.isStringLiteral && !valueContent.startsWith(STYLE_MODULE_NAME)) {
4408
4414
  const dirCls = ADAPTER_RULES.runtime.dirCls;
4409
- const arg = _optionalChain([mergedItems, 'optionalAccess', _130 => _130.join, 'call', _131 => _131(",")]) || wrapSingleQuotes(valueContent);
4415
+ const arg = _optionalChain([mergedItems, 'optionalAccess', _128 => _128.join, 'call', _129 => _129(",")]) || wrapSingleQuotes(valueContent);
4410
4416
  const expression = createRuntimeCall(dirCls.target, [arg]);
4411
4417
  applyRuntimeExpression(expression, true, name);
4412
4418
  return;
4413
4419
  }
4414
- if (isStyleAttr(name) && (!isSimpleStyle(valueContent) || _optionalChain([mergedItems, 'optionalAccess', _132 => _132.some, 'call', _133 => _133((item) => !isSimpleStyle(item))]))) {
4420
+ if (isStyleAttr(name) && (!isSimpleStyle(valueContent) || _optionalChain([mergedItems, 'optionalAccess', _130 => _130.some, 'call', _131 => _131((item) => !isSimpleStyle(item))]))) {
4415
4421
  const dirStyle = ADAPTER_RULES.runtime.dirStyle;
4416
- const arg = _optionalChain([mergedItems, 'optionalAccess', _134 => _134.join, 'call', _135 => _135(",")]) || valueContent;
4422
+ const arg = _optionalChain([mergedItems, 'optionalAccess', _132 => _132.join, 'call', _133 => _133(",")]) || valueContent;
4417
4423
  const expression = createRuntimeCall(dirStyle.target, [arg]);
4418
4424
  applyRuntimeExpression(expression, true, name);
4419
4425
  return;
4420
4426
  }
4421
- if (ir.type === 3 /* EVENT */ && _optionalChain([ir, 'access', _136 => _136.modifiers, 'optionalAccess', _137 => _137.length])) {
4427
+ if (ir.type === 3 /* EVENT */ && _optionalChain([ir, 'access', _134 => _134.modifiers, 'optionalAccess', _135 => _135.length])) {
4422
4428
  const dirOn = ADAPTER_RULES.runtime.dirOn;
4423
4429
  const eventName = wrapSingleQuotes(ir.__vOnEvName || name, ir.isStatic);
4424
4430
  const expression = createRuntimeCall(dirOn.target, [eventName, valueContent]);
@@ -4473,7 +4479,7 @@ function resolveElementChildrenRules(children, ctx, parentIR, ir) {
4473
4479
  continue;
4474
4480
  }
4475
4481
  const nodeIR = child;
4476
- if (_optionalChain([parentIR, 'optionalAccess', _138 => _138.isBuiltIn])) {
4482
+ if (_optionalChain([parentIR, 'optionalAccess', _136 => _136.isBuiltIn])) {
4477
4483
  if (parentIR.tag == VUE_API_MAP.Transition) {
4478
4484
  resolveTransitionRules(nodeIR, parentIR, ir, ctx);
4479
4485
  }
@@ -4514,7 +4520,7 @@ function walkElementNodes(node, onElement) {
4514
4520
  }
4515
4521
  function resolveDefaultStyleModuleName(node) {
4516
4522
  const { exp } = node;
4517
- if (_optionalChain([exp, 'optionalAccess', _139 => _139.type]) !== _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
4523
+ if (_optionalChain([exp, 'optionalAccess', _137 => _137.type]) !== _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
4518
4524
  return;
4519
4525
  }
4520
4526
  if (exp.content.includes("$style")) {
@@ -4552,7 +4558,7 @@ function injectStyleScopeAttribute(node, ctx) {
4552
4558
  return;
4553
4559
  }
4554
4560
  const hasDynamicIs = node.props.some((prop) => {
4555
- if (prop.type !== _compilercore.NodeTypes.DIRECTIVE || _optionalChain([prop, 'access', _140 => _140.arg, 'optionalAccess', _141 => _141.type]) !== _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
4561
+ if (prop.type !== _compilercore.NodeTypes.DIRECTIVE || _optionalChain([prop, 'access', _138 => _138.arg, 'optionalAccess', _139 => _139.type]) !== _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
4556
4562
  return false;
4557
4563
  }
4558
4564
  return prop.arg.content === "is";
@@ -4618,7 +4624,7 @@ function mergeStyleProps(oldAttr, newAttr) {
4618
4624
  const oldStyle = oldAttr.value.content;
4619
4625
  const newStyle = parseStyleString(newAttr.value.content);
4620
4626
  let merged = oldAttr.value.merge;
4621
- if (!_optionalChain([merged, 'optionalAccess', _142 => _142.length])) {
4627
+ if (!_optionalChain([merged, 'optionalAccess', _140 => _140.length])) {
4622
4628
  merged = oldAttr.value.merge = [oldStyle, newStyle];
4623
4629
  } else {
4624
4630
  merged.push(newStyle);
@@ -4648,7 +4654,7 @@ function warnUnsupportedVueDollarVar(ctx, node) {
4648
4654
  const { source, filename } = ctx;
4649
4655
  let value = "";
4650
4656
  let loc;
4651
- if (node.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([node, 'access', _143 => _143.exp, 'optionalAccess', _144 => _144.type]) === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
4657
+ if (node.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([node, 'access', _141 => _141.exp, 'optionalAccess', _142 => _142.type]) === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
4652
4658
  value = node.exp.content;
4653
4659
  loc = node.exp.loc;
4654
4660
  } else if (node.type === _compilercore.NodeTypes.INTERPOLATION && node.content.type === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
@@ -4702,11 +4708,11 @@ function resolveRefProp(node, ctx, nodeIR) {
4702
4708
  } = ctx;
4703
4709
  let propIR;
4704
4710
  if (node.type === _compilercore.NodeTypes.ATTRIBUTE) {
4705
- const tag = _optionalChain([node, 'access', _145 => _145.value, 'optionalAccess', _146 => _146.content]);
4711
+ const tag = _optionalChain([node, 'access', _143 => _143.value, 'optionalAccess', _144 => _144.content]);
4706
4712
  if (!tag) return;
4707
4713
  collectComponentRef(tag, ctx);
4708
4714
  const domRefBinding = Object.values(refBindings.domRefs).find((r) => r.tag === tag);
4709
- const refVar = _optionalChain([domRefBinding, 'optionalAccess', _147 => _147.name]) || _optionalChain([refBindings, 'access', _148 => _148.componentRefs, 'access', _149 => _149[tag], 'optionalAccess', _150 => _150.name]);
4715
+ const refVar = _optionalChain([domRefBinding, 'optionalAccess', _145 => _145.name]) || _optionalChain([refBindings, 'access', _146 => _146.componentRefs, 'access', _147 => _147[tag], 'optionalAccess', _148 => _148.name]);
4710
4716
  propIR = createPropsIR("ref", "ref", refVar || "null");
4711
4717
  } else {
4712
4718
  const exp = node.exp;
@@ -4741,8 +4747,8 @@ function collectComponentRef(tag, ctx) {
4741
4747
  function resolveDynamicAttributeProp(node, ir, ctx, nodeIR) {
4742
4748
  const arg = node.arg;
4743
4749
  const exp = node.exp;
4744
- const name = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _151 => _151.content]), () => ( ""));
4745
- const content = _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _152 => _152.content]), () => ( "true"));
4750
+ const name = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _149 => _149.content]), () => ( ""));
4751
+ const content = _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _150 => _150.content]), () => ( "true"));
4746
4752
  warnUnsupportedVueDollarVar(ctx, node);
4747
4753
  if (name === "is") {
4748
4754
  resolveDynamicIsProp(node, ir, ctx, nodeIR);
@@ -4753,7 +4759,7 @@ function resolveDynamicAttributeProp(node, ir, ctx, nodeIR) {
4753
4759
  return;
4754
4760
  }
4755
4761
  const dynamicPropIR = createPropsIR(node.rawName, name, content);
4756
- dynamicPropIR.isStatic = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _153 => _153.isStatic]), () => ( true));
4762
+ dynamicPropIR.isStatic = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _151 => _151.isStatic]), () => ( true));
4757
4763
  checkPropIsDynamicKey(ctx, node);
4758
4764
  resolvePropertyIR(dynamicPropIR, ir, ctx, nodeIR, true);
4759
4765
  }
@@ -4781,7 +4787,7 @@ function resolvePropertyIR(node, ir, ctx, nodeIR, isDynamic = false) {
4781
4787
  // src/core/transform/sfc/template/syntax-processor/process/props/resolve-attribute-prop.ts
4782
4788
  function resolveAttributeProp(node, ir, ctx, nodeIR) {
4783
4789
  const name = node.name;
4784
- const content = _nullishCoalesce(_optionalChain([node, 'access', _154 => _154.value, 'optionalAccess', _155 => _155.content]), () => ( "true"));
4790
+ const content = _nullishCoalesce(_optionalChain([node, 'access', _152 => _152.value, 'optionalAccess', _153 => _153.content]), () => ( "true"));
4785
4791
  if (name === "is") {
4786
4792
  resolveStaticIsProp(content, ir, ctx, nodeIR);
4787
4793
  return;
@@ -4805,10 +4811,10 @@ function resolveRouterLinkVSlotProp(node, nodeIR, ctx) {
4805
4811
  type: 2 /* SLOT */,
4806
4812
  name: "customRender",
4807
4813
  rawName: _nullishCoalesce(node.rawName, () => ( "v-slot")),
4808
- isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _156 => _156.isStatic]), () => ( true)),
4814
+ isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _154 => _154.isStatic]), () => ( true)),
4809
4815
  isScoped: true,
4810
4816
  callback: {
4811
- arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _157 => _157.content, 'optionalAccess', _158 => _158.trim, 'call', _159 => _159()]), () => ( "")),
4817
+ arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _155 => _155.content, 'optionalAccess', _156 => _156.trim, 'call', _157 => _157()]), () => ( "")),
4812
4818
  exp: []
4813
4819
  }
4814
4820
  };
@@ -4824,10 +4830,10 @@ function resolveVFor(node, _ir, _ctx, nodeIR) {
4824
4830
  };
4825
4831
  }
4826
4832
  function resolveForResult(forParseResult) {
4827
- const source = _optionalChain([forParseResult, 'access', _160 => _160.source, 'optionalAccess', _161 => _161.content]);
4828
- const value = _optionalChain([forParseResult, 'access', _162 => _162.value, 'optionalAccess', _163 => _163.content]);
4829
- const index = _optionalChain([forParseResult, 'access', _164 => _164.index, 'optionalAccess', _165 => _165.content]);
4830
- const key = _optionalChain([forParseResult, 'access', _166 => _166.key, 'optionalAccess', _167 => _167.content]);
4833
+ const source = _optionalChain([forParseResult, 'access', _158 => _158.source, 'optionalAccess', _159 => _159.content]);
4834
+ const value = _optionalChain([forParseResult, 'access', _160 => _160.value, 'optionalAccess', _161 => _161.content]);
4835
+ const index = _optionalChain([forParseResult, 'access', _162 => _162.index, 'optionalAccess', _163 => _163.content]);
4836
+ const key = _optionalChain([forParseResult, 'access', _164 => _164.key, 'optionalAccess', _165 => _165.content]);
4831
4837
  return {
4832
4838
  source,
4833
4839
  value,
@@ -4847,7 +4853,7 @@ function resolveVHtml(node, ir, ctx, nodeIR) {
4847
4853
  // src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-if.ts
4848
4854
  function resolveVIf(node, _ir, ctx, nodeIR, siblingNodesIR) {
4849
4855
  const name = node.name === "else-if" ? "elseIf" : node.name;
4850
- const value = _nullishCoalesce(_optionalChain([node, 'access', _168 => _168.exp, 'optionalAccess', _169 => _169.content]), () => ( "true"));
4856
+ const value = _nullishCoalesce(_optionalChain([node, 'access', _166 => _166.exp, 'optionalAccess', _167 => _167.content]), () => ( "true"));
4851
4857
  const prevNode = siblingNodesIR[siblingNodesIR.length - 1];
4852
4858
  const isElseBranch = name === "else" || name === "elseIf";
4853
4859
  let hasError = false;
@@ -4886,7 +4892,7 @@ function resolveVIf(node, _ir, ctx, nodeIR, siblingNodesIR) {
4886
4892
  // src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-memo.ts
4887
4893
  function resolveVMemo(node, _ir, ctx, nodeIR) {
4888
4894
  const exp = node.exp;
4889
- let value = _optionalChain([exp, 'optionalAccess', _170 => _170.content]);
4895
+ let value = _optionalChain([exp, 'optionalAccess', _168 => _168.content]);
4890
4896
  if (value !== void 0) {
4891
4897
  if (!value.trim() || !value.startsWith("[") && !value.endsWith("]")) {
4892
4898
  const { source, filename } = ctx;
@@ -4926,14 +4932,14 @@ function resolveVModel(node, _ir, ctx, elementNode, nodeIR) {
4926
4932
  const getterName = exp.content;
4927
4933
  const isComponent = elementNode.tagType === _compilercore.ElementTypes.COMPONENT;
4928
4934
  const inputType = resolveHtmlInput(elementNode, isComponent);
4929
- const propName = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _171 => _171.content]), () => ( resolveModelPropName(inputType, isComponent)));
4935
+ const propName = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _169 => _169.content]), () => ( resolveModelPropName(inputType, isComponent)));
4930
4936
  let valuePropIR;
4931
4937
  let eventPropIR;
4932
4938
  if (isComponent) {
4933
4939
  valuePropIR = createPropsIR("v-model", propName, getterName);
4934
4940
  const eventReactName = `onUpdate${capitalize(camelCase(propName))}`;
4935
4941
  const eventVueName = `update:${propName}`;
4936
- const isTS = _optionalChain([ctx, 'access', _172 => _172.scriptData, 'optionalAccess', _173 => _173.lang, 'optionalAccess', _174 => _174.startsWith, 'call', _175 => _175("ts")]);
4942
+ const isTS = _optionalChain([ctx, 'access', _170 => _170.scriptData, 'optionalAccess', _171 => _171.lang, 'optionalAccess', _172 => _172.startsWith, 'call', _173 => _173("ts")]);
4937
4943
  const valueArg = isTS ? "value: any" : "value";
4938
4944
  const processedValue = applyValueModifiers("value", modifiers);
4939
4945
  const handlerBody = `(${valueArg}) => { ${getterName} = ${processedValue} }`;
@@ -4971,7 +4977,7 @@ function getRadioValue(elementNode) {
4971
4977
  const valueAttr = elementNode.props.find(
4972
4978
  (prop) => prop.type === _compilercore.NodeTypes.ATTRIBUTE && prop.name === "value"
4973
4979
  );
4974
- if (!_optionalChain([valueAttr, 'optionalAccess', _176 => _176.value, 'optionalAccess', _177 => _177.content])) return '""';
4980
+ if (!_optionalChain([valueAttr, 'optionalAccess', _174 => _174.value, 'optionalAccess', _175 => _175.content])) return '""';
4975
4981
  const content = valueAttr.value.content;
4976
4982
  return /^['"]/.test(content) ? content : `"${content}"`;
4977
4983
  }
@@ -4981,7 +4987,7 @@ function resolveHtmlInput(node, isComponent) {
4981
4987
  const typeProp = node.props.find(
4982
4988
  (prop) => prop.type === _compilercore.NodeTypes.ATTRIBUTE && prop.name === "type"
4983
4989
  );
4984
- return _optionalChain([typeProp, 'optionalAccess', _178 => _178.value, 'optionalAccess', _179 => _179.content, 'optionalAccess', _180 => _180.toLowerCase, 'call', _181 => _181()]);
4990
+ return _optionalChain([typeProp, 'optionalAccess', _176 => _176.value, 'optionalAccess', _177 => _177.content, 'optionalAccess', _178 => _178.toLowerCase, 'call', _179 => _179()]);
4985
4991
  }
4986
4992
  function applyValueModifiers(valueExp, modifiers) {
4987
4993
  let result = valueExp;
@@ -5180,7 +5186,7 @@ function resolveVSlotProp(node, _ir, ctx) {
5180
5186
  const name = !arg || arg.content === "default" ? "children" : arg.content;
5181
5187
  const content = !isScoped ? [] : void 0;
5182
5188
  const callback = isScoped ? {
5183
- arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _182 => _182.content, 'optionalAccess', _183 => _183.trim, 'call', _184 => _184()]), () => ( "")),
5189
+ arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _180 => _180.content, 'optionalAccess', _181 => _181.trim, 'call', _182 => _182()]), () => ( "")),
5184
5190
  exp: []
5185
5191
  } : void 0;
5186
5192
  checkPropIsDynamicKey(ctx, node);
@@ -5188,7 +5194,7 @@ function resolveVSlotProp(node, _ir, ctx) {
5188
5194
  type: 2 /* SLOT */,
5189
5195
  name,
5190
5196
  rawName: _nullishCoalesce(node.rawName, () => ( "default")),
5191
- isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _185 => _185.isStatic]), () => ( true)),
5197
+ isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _183 => _183.isStatic]), () => ( true)),
5192
5198
  isScoped,
5193
5199
  content,
5194
5200
  callback
@@ -5222,7 +5228,7 @@ function resolveElementNode(node, ir, ctx, siblingNodesIR) {
5222
5228
  if (routerAdapter) {
5223
5229
  if (!ctx.route) ctx.route = true;
5224
5230
  nodeIR.isRoute = true;
5225
- recordImport(ctx, _optionalChain([routerAdapter, 'optionalAccess', _186 => _186.package]), routerAdapter.target);
5231
+ recordImport(ctx, _optionalChain([routerAdapter, 'optionalAccess', _184 => _184.package]), routerAdapter.target);
5226
5232
  }
5227
5233
  resolveProps(node, ir, ctx, nodeIR, siblingNodesIR);
5228
5234
  return nodeIR;
@@ -5358,7 +5364,7 @@ function resolveSlotProps(node, ctx) {
5358
5364
  for (const prop of node.props) {
5359
5365
  if (prop.type === _compilercore.NodeTypes.ATTRIBUTE) {
5360
5366
  const attr = prop.name;
5361
- const value = _optionalChain([prop, 'access', _187 => _187.value, 'optionalAccess', _188 => _188.content, 'access', _189 => _189.trim, 'call', _190 => _190()]);
5367
+ const value = _optionalChain([prop, 'access', _185 => _185.value, 'optionalAccess', _186 => _186.content, 'access', _187 => _187.trim, 'call', _188 => _188()]);
5362
5368
  if (attr === "name" && value) {
5363
5369
  result.name = camelCase(value);
5364
5370
  } else {
@@ -5448,24 +5454,24 @@ function resolveTemplate2(root, ctx) {
5448
5454
  // src/core/transform/sfc/index.ts
5449
5455
  function transform(ast, ctx, options) {
5450
5456
  const { template, script, style } = ast;
5451
- const templateIR = resolveTemplate2(_optionalChain([template, 'optionalAccess', _191 => _191.ast]), ctx);
5452
- const scriptIR = resolveScript2(_optionalChain([script, 'optionalAccess', _192 => _192.ast]), ctx);
5457
+ const templateIR = resolveTemplate2(_optionalChain([template, 'optionalAccess', _189 => _189.ast]), ctx);
5458
+ const scriptIR = resolveScript2(_optionalChain([script, 'optionalAccess', _190 => _190.ast]), ctx);
5453
5459
  const result = {
5454
5460
  template: templateIR,
5455
5461
  script: scriptIR,
5456
- style: _optionalChain([style, 'optionalAccess', _193 => _193.source, 'optionalAccess', _194 => _194.content])
5462
+ style: _optionalChain([style, 'optionalAccess', _191 => _191.source, 'optionalAccess', _192 => _192.content])
5457
5463
  };
5458
- executePlugins(_optionalChain([options, 'optionalAccess', _195 => _195.plugins]), result, ctx);
5464
+ executePlugins(_optionalChain([options, 'optionalAccess', _193 => _193.plugins]), result, ctx);
5459
5465
  return result;
5460
5466
  }
5461
5467
 
5462
5468
  // package.json
5463
- var version = "1.3.0";
5469
+ var version = "1.4.0";
5464
5470
  var bin = {
5465
5471
  vureact: "./bin/vureact.js"
5466
5472
  };
5467
5473
 
5468
- // src/compiler/shared/types.ts
5474
+ // src/compiler/shared/types/cache-types.ts
5469
5475
  var CacheKey = /* @__PURE__ */ ((CacheKey2) => {
5470
5476
  CacheKey2["SFC"] = "sfc";
5471
5477
  CacheKey2["SCRIPT"] = "script";
@@ -5507,10 +5513,146 @@ function simpleFormat(code) {
5507
5513
  }
5508
5514
 
5509
5515
  // src/compiler/shared/helper.ts
5510
- var _child_process = require('child_process');
5511
5516
  var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
5512
5517
 
5513
5518
 
5519
+
5520
+ // src/compiler/shared/file-lock-manager.ts
5521
+
5522
+
5523
+
5524
+ var _properlockfile = require('proper-lockfile'); var _properlockfile2 = _interopRequireDefault(_properlockfile);
5525
+ var FileLockManager = class _FileLockManager {
5526
+
5527
+ /**
5528
+ * 获取单例实例
5529
+ */
5530
+ static getInstance() {
5531
+ if (!_FileLockManager.instance) {
5532
+ _FileLockManager.instance = new _FileLockManager();
5533
+ }
5534
+ return _FileLockManager.instance;
5535
+ }
5536
+ /**
5537
+ * 获取文件锁并更新文件内容
5538
+ * @param filePath 文件路径
5539
+ * @param updater 更新函数,接收当前内容,返回更新后的内容
5540
+ * @param options 锁选项
5541
+ */
5542
+ async updateFile(filePath, updater, options = {}) {
5543
+ return this.withLock(
5544
+ filePath,
5545
+ async () => {
5546
+ let current = null;
5547
+ try {
5548
+ const content = await _fs2.default.promises.readFile(filePath, "utf-8");
5549
+ if (content.trim()) {
5550
+ try {
5551
+ current = JSON.parse(content);
5552
+ } catch (e11) {
5553
+ current = content;
5554
+ }
5555
+ }
5556
+ } catch (error) {
5557
+ console.error(_kleur2.default.red("\u2716"), `Failed to read file ${filePath}`);
5558
+ console.error(error);
5559
+ }
5560
+ const updated = await updater(current);
5561
+ const contentToWrite = typeof updated === "string" ? updated : JSON.stringify(updated, null, 2);
5562
+ await this.writeFile(filePath, contentToWrite);
5563
+ return updated;
5564
+ },
5565
+ options
5566
+ );
5567
+ }
5568
+ /**
5569
+ * 获取文件锁并执行操作
5570
+ * @param filePath 文件路径
5571
+ * @param operation 要执行的操作函数
5572
+ * @param options 锁选项
5573
+ */
5574
+ async withLock(filePath, operation, options = {}) {
5575
+ const {
5576
+ stale = 1e4,
5577
+ update = stale / 2,
5578
+ retries = 5,
5579
+ realpath = true,
5580
+ lockfilePath
5581
+ } = options;
5582
+ await _fs2.default.promises.mkdir(_path2.default.dirname(filePath), { recursive: true });
5583
+ try {
5584
+ await _fs2.default.promises.access(filePath);
5585
+ } catch (e12) {
5586
+ await this.writeFile(filePath, "");
5587
+ }
5588
+ const release = await _properlockfile2.default.lock(filePath, {
5589
+ stale,
5590
+ update,
5591
+ retries,
5592
+ realpath,
5593
+ lockfilePath
5594
+ });
5595
+ try {
5596
+ return await operation();
5597
+ } finally {
5598
+ await release();
5599
+ }
5600
+ }
5601
+ /**
5602
+ * 检查文件是否被锁定
5603
+ * @param filePath 文件路径
5604
+ * @param options 锁选项
5605
+ */
5606
+ async isLocked(filePath, options = {}) {
5607
+ const { stale = 1e4, realpath = true, lockfilePath } = options;
5608
+ try {
5609
+ return await _properlockfile2.default.check(filePath, { stale, realpath, lockfilePath });
5610
+ } catch (e13) {
5611
+ return false;
5612
+ }
5613
+ }
5614
+ /**
5615
+ * 尝试获取锁(非阻塞)
5616
+ * @param filePath 文件路径
5617
+ * @param options 锁选项
5618
+ * @returns 如果成功获取锁,返回释放函数;否则返回 null
5619
+ */
5620
+ async tryLock(filePath, options = {}) {
5621
+ const { stale = 1e4, update = stale / 2, realpath = true, lockfilePath } = options;
5622
+ try {
5623
+ const release = await _properlockfile2.default.lock(filePath, {
5624
+ stale,
5625
+ update,
5626
+ retries: 0,
5627
+ // 不重试
5628
+ realpath,
5629
+ lockfilePath
5630
+ });
5631
+ return release;
5632
+ } catch (e14) {
5633
+ return null;
5634
+ }
5635
+ }
5636
+ /**
5637
+ * 释放文件锁
5638
+ * @param filePath 文件路径
5639
+ * @param options 锁选项
5640
+ */
5641
+ async unlock(filePath, options = {}) {
5642
+ const { realpath = true, lockfilePath } = options;
5643
+ try {
5644
+ await _properlockfile2.default.unlock(filePath, { realpath, lockfilePath });
5645
+ } catch (e15) {
5646
+ }
5647
+ }
5648
+ async writeFile(filePath, content) {
5649
+ await _fs2.default.promises.mkdir(_path2.default.dirname(filePath), { recursive: true });
5650
+ await _fs2.default.promises.writeFile(filePath, content, "utf-8");
5651
+ }
5652
+ };
5653
+ var fileLock = FileLockManager.getInstance();
5654
+
5655
+ // src/compiler/shared/helper.ts
5514
5656
  var Helper = (_class3 = class {
5515
5657
 
5516
5658
 
@@ -5518,7 +5660,7 @@ var Helper = (_class3 = class {
5518
5660
  __init6() {this.outDir = "react-app"}
5519
5661
  constructor(opts) {;_class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this);
5520
5662
  this.compilerOpts = opts;
5521
- if (_optionalChain([opts, 'access', _196 => _196.output, 'optionalAccess', _197 => _197.workspace])) {
5663
+ if (_optionalChain([opts, 'access', _194 => _194.output, 'optionalAccess', _195 => _195.workspace])) {
5522
5664
  this.workspaceDir = opts.output.workspace;
5523
5665
  }
5524
5666
  const excludePatterns = PathFilter.withDefaults(opts.exclude || []);
@@ -5535,8 +5677,8 @@ var Helper = (_class3 = class {
5535
5677
  * 获取输入文件的路径
5536
5678
  */
5537
5679
  getInputPath() {
5538
- const { input } = this.compilerOpts;
5539
- return _path2.default.resolve(this.getProjectRoot(), input || "src");
5680
+ const { input = "src" } = this.compilerOpts;
5681
+ return _path2.default.resolve(this.getProjectRoot(), input);
5540
5682
  }
5541
5683
  /**
5542
5684
  * 检查 input 路径是否是单个文件
@@ -5547,13 +5689,15 @@ var Helper = (_class3 = class {
5547
5689
  }
5548
5690
  /**
5549
5691
  * 获取输出文件的路径。如:'[root]/.vureact/dist/'
5692
+ * @param addInput 会输出如:'[root]/.vureact/dist/[input]/'
5550
5693
  */
5551
- getOuputPath() {
5552
- return _path2.default.resolve(this.getWorkspaceDir(), this.getOutDirName());
5694
+ getOuputPath(addInput = false) {
5695
+ const { input = "src" } = this.compilerOpts;
5696
+ return _path2.default.resolve(this.getWorkspaceDir(), this.getOutDirName(), addInput ? input : "");
5553
5697
  }
5554
5698
  getOutDirName() {
5555
5699
  const { output } = this.compilerOpts;
5556
- return _optionalChain([output, 'optionalAccess', _198 => _198.outDir]) || this.outDir;
5700
+ return _optionalChain([output, 'optionalAccess', _196 => _196.outDir]) || this.outDir;
5557
5701
  }
5558
5702
  getWorkspaceDir() {
5559
5703
  return _path2.default.resolve(this.getProjectRoot(), this.workspaceDir);
@@ -5567,7 +5711,7 @@ var Helper = (_class3 = class {
5567
5711
  }
5568
5712
  getIgnoreAssets() {
5569
5713
  const { output } = this.compilerOpts;
5570
- if (_optionalChain([output, 'optionalAccess', _199 => _199.ignoreAssets])) {
5714
+ if (_optionalChain([output, 'optionalAccess', _197 => _197.ignoreAssets])) {
5571
5715
  return new Set(output.ignoreAssets.map(normalizePath));
5572
5716
  }
5573
5717
  return /* @__PURE__ */ new Set([
@@ -5581,7 +5725,9 @@ var Helper = (_class3 = class {
5581
5725
  "eslint.config.",
5582
5726
  "readme.",
5583
5727
  "vue.",
5584
- "vureact.config.js"
5728
+ ".vue",
5729
+ "vureact.config.js",
5730
+ "vureact.config.ts"
5585
5731
  ]);
5586
5732
  }
5587
5733
  getIsCache() {
@@ -5648,12 +5794,12 @@ var Helper = (_class3 = class {
5648
5794
  */
5649
5795
  async formatCode({ code, fileInfo }) {
5650
5796
  const { format } = this.compilerOpts;
5651
- if (!_optionalChain([format, 'optionalAccess', _200 => _200.enabled])) return code;
5652
- if (_optionalChain([format, 'optionalAccess', _201 => _201.formatter]) === "builtin") {
5797
+ if (!_optionalChain([format, 'optionalAccess', _198 => _198.enabled])) return code;
5798
+ if (_optionalChain([format, 'optionalAccess', _199 => _199.formatter]) === "builtin") {
5653
5799
  return simpleFormat(code);
5654
5800
  }
5655
- const { lang } = _nullishCoalesce(_optionalChain([fileInfo, 'optionalAccess', _202 => _202.jsx]), () => ( _optionalChain([fileInfo, 'optionalAccess', _203 => _203.script])));
5656
- return await formatWithPrettier(code, lang, _optionalChain([format, 'optionalAccess', _204 => _204.prettierOptions]));
5801
+ const { lang } = _nullishCoalesce(_optionalChain([fileInfo, 'optionalAccess', _200 => _200.jsx]), () => ( _optionalChain([fileInfo, 'optionalAccess', _201 => _201.script])));
5802
+ return await formatWithPrettier(code, lang, _optionalChain([format, 'optionalAccess', _202 => _202.prettierOptions]));
5657
5803
  }
5658
5804
  /**
5659
5805
  * 通用的缓存校验工具函数
@@ -5680,11 +5826,25 @@ var Helper = (_class3 = class {
5680
5826
  return a.fileSize === b.fileSize && a.mtime === b.mtime;
5681
5827
  }
5682
5828
  /**
5683
- * 统一的写文件方法,包含自动创建目录
5829
+ * 统一的写文件方法,包含自动创建目录(带文件互斥锁可选)
5830
+ * @param filePath - 要写入的文件路径
5831
+ * @param content - 要写入的内容
5832
+ * @param options - 可选配置项
5833
+ * @param options.lock - 是否启用文件锁(默认false)
5684
5834
  */
5685
- async writeFileWithDir(filePath, content) {
5686
- await _fs2.default.promises.mkdir(_path2.default.dirname(filePath), { recursive: true });
5687
- await _fs2.default.promises.writeFile(filePath, content, "utf-8");
5835
+ async writeFileWithDir(filePath, content, options) {
5836
+ if (_optionalChain([options, 'optionalAccess', _203 => _203.lock])) {
5837
+ await fileLock.updateFile(filePath, async () => content, options);
5838
+ } else {
5839
+ await _fs2.default.promises.mkdir(_path2.default.dirname(filePath), { recursive: true });
5840
+ await _fs2.default.promises.writeFile(filePath, content, "utf-8");
5841
+ }
5842
+ }
5843
+ async rmFile(filePath) {
5844
+ try {
5845
+ await _fs2.default.promises.rm(filePath, { recursive: true, force: true });
5846
+ } catch (e16) {
5847
+ }
5688
5848
  }
5689
5849
  async loadCache(key) {
5690
5850
  const cacheFile = this.getCachePath();
@@ -5700,7 +5860,7 @@ var Helper = (_class3 = class {
5700
5860
  target: data[key] || [],
5701
5861
  source: data
5702
5862
  };
5703
- } catch (e11) {
5863
+ } catch (e17) {
5704
5864
  return defaultData;
5705
5865
  }
5706
5866
  }
@@ -5727,9 +5887,19 @@ var Helper = (_class3 = class {
5727
5887
  if (!this.getIsCache() || !data) {
5728
5888
  return;
5729
5889
  }
5730
- const { key, source, target } = data;
5731
- source[key] = target;
5732
- await this.writeFileWithDir(this.getCachePath(), JSON.stringify(source));
5890
+ const getDefaultValue = () => ({
5891
+ ["sfc" /* SFC */]: [],
5892
+ ["script" /* SCRIPT */]: [],
5893
+ ["style" /* STYLE */]: [],
5894
+ ["copied" /* ASSET */]: []
5895
+ });
5896
+ const cachePath = this.getCachePath();
5897
+ await fileLock.updateFile(cachePath, (currentData) => {
5898
+ const { key, target } = data;
5899
+ const mergedData = currentData || getDefaultValue();
5900
+ mergedData[key] = target;
5901
+ return mergedData;
5902
+ });
5733
5903
  }
5734
5904
  genHash(content) {
5735
5905
  return genHashByXXH(content);
@@ -5772,9 +5942,9 @@ var Helper = (_class3 = class {
5772
5942
  };
5773
5943
  }
5774
5944
  async removeOutputFile(filePath, resolveOutputPath) {
5775
- const path8 = resolveOutputPath ? this.resolveOutputPath(filePath) : filePath;
5776
- if (!_fs2.default.existsSync(path8)) return;
5777
- await _fs2.default.promises.unlink(path8);
5945
+ const path9 = resolveOutputPath ? this.resolveOutputPath(filePath) : filePath;
5946
+ if (!_fs2.default.existsSync(path9)) return;
5947
+ await _fs2.default.promises.unlink(path9);
5778
5948
  }
5779
5949
  updateCache(targetFile, newData, cache) {
5780
5950
  const index = cache.target.findIndex((c) => c.file === targetFile);
@@ -5784,23 +5954,11 @@ var Helper = (_class3 = class {
5784
5954
  cache.target.push(newData);
5785
5955
  }
5786
5956
  }
5787
- resolveViteCreateApp() {
5788
- const { output } = this.compilerOpts;
5789
- const config = _optionalChain([output, 'optionalAccess', _205 => _205.bootstrapVite]);
5790
- const template = typeof config === "object" ? config.template : "react-ts";
5791
- const outDirName = this.getOutDirName();
5792
- const cmd = `npm create vite@latest ${outDirName} -- --template ${template}`;
5793
- _child_process.execSync.call(void 0, cmd, {
5794
- cwd: this.getWorkspaceDir(),
5795
- stdio: "ignore"
5796
- // 隐藏 create-vite 内部的输出日志,保持终端整洁
5797
- });
5798
- }
5799
5957
  /**
5800
5958
  * 获取需要排除编译的文件
5801
5959
  */
5802
5960
  getExcludes() {
5803
- if (!_optionalChain([this, 'access', _206 => _206.compilerOpts, 'access', _207 => _207.exclude, 'optionalAccess', _208 => _208.length])) {
5961
+ if (!_optionalChain([this, 'access', _204 => _204.compilerOpts, 'access', _205 => _205.exclude, 'optionalAccess', _206 => _206.length])) {
5804
5962
  return PathFilter.withDefaults();
5805
5963
  }
5806
5964
  return this.compilerOpts.exclude;
@@ -5839,17 +5997,34 @@ var Helper = (_class3 = class {
5839
5997
  /**
5840
5998
  * 读取 package.json 文件内容,并处理成对象返回
5841
5999
  */
5842
- async resolvePackageFile(path8) {
6000
+ async resolvePackageFile(path9) {
6001
+ if (!_fs2.default.existsSync(path9)) {
6002
+ return {};
6003
+ }
5843
6004
  try {
5844
- if (!_fs2.default.existsSync(path8)) {
6005
+ const content = await _fs2.default.promises.readFile(path9, "utf-8");
6006
+ if (!content.trim()) {
5845
6007
  return {};
5846
6008
  }
5847
- return JSON.parse(await _fs2.default.promises.readFile(path8, "utf-8"));
6009
+ return JSON.parse(content);
5848
6010
  } catch (error) {
5849
- console.error(error);
6011
+ console.error(_kleur2.default.red("\u274C"), `Failed to parse JSON file ${path9}:
6012
+ `, error);
5850
6013
  return {};
5851
6014
  }
5852
6015
  }
6016
+ /**
6017
+ * 获取目录到文件的相对路径
6018
+ * @returns 结果路径不包含文件拓展名,并以诸如 ./ 开头
6019
+ */
6020
+ resolveRelativePath(from, to) {
6021
+ let relativePath2 = _path2.default.relative(from, to);
6022
+ relativePath2 = relativePath2.substring(0, relativePath2.indexOf("."));
6023
+ if (!relativePath2.startsWith(".")) {
6024
+ relativePath2 = `./${relativePath2}`;
6025
+ }
6026
+ return normalizePath(relativePath2);
6027
+ }
5853
6028
  }, _class3);
5854
6029
 
5855
6030
  // src/core/parse/style-only.ts
@@ -5881,7 +6056,7 @@ function parseOnlyStyle(source, ctx, options) {
5881
6056
  ast: void 0
5882
6057
  }
5883
6058
  };
5884
- executePlugins(_optionalChain([options, 'optionalAccess', _209 => _209.plugins]), result, ctx);
6059
+ executePlugins(_optionalChain([options, 'optionalAccess', _207 => _207.plugins]), result, ctx);
5885
6060
  return result;
5886
6061
  }
5887
6062
 
@@ -5997,65 +6172,11 @@ var BaseCompiler = (_class5 = class extends Helper {
5997
6172
  __init8() {this.version = exports.version = version}
5998
6173
 
5999
6174
  __init9() {this.createContext = CompilationAdapter.createContext}
6000
- /**
6001
- * 创建基础编译器实例
6002
- *
6003
- * @param options - 编译器配置选项,包括缓存设置、插件配置、样式预处理等,
6004
- * 所有选项都会传递给父类 {@link Helper} 进行初始化
6005
- *
6006
- * @see {@link CompilerOptions} 查看完整的配置选项说明
6007
- */
6008
6175
  constructor(options = {}) {
6009
6176
  super(options);_class5.prototype.__init8.call(this);_class5.prototype.__init9.call(this);;
6010
6177
  this.options = options;
6011
6178
  }
6012
- /**
6013
- * 编译 Vue 源代码为 React 代码
6014
- *
6015
- * 该方法执行完整的编译流程,包括:
6016
- * 1. 上下文初始化:创建独立的编译上下文
6017
- * 2. 解析阶段:将 Vue 源代码解析为抽象语法树(AST)
6018
- * 3. 转换阶段:将 Vue AST 转换为 React 中间表示(IR)
6019
- * 4. 生成阶段:将 React IR 生成为目标代码
6020
- * 5. 插件执行:在各阶段执行注册的插件
6021
- * 6. 结果处理:整理编译结果并返回
6022
- *
6023
- * 编译过程使用 try-finally 确保上下文资源被正确清理,
6024
- * 即使编译过程中发生错误也不会导致资源泄漏。
6025
- *
6026
- * @param source - Vue 源代码字符串
6027
- * @param filename - 源文件名,用于生成文件ID和输出路径
6028
- * @returns {CompilationResult} 编译结果,包含生成的代码和文件信息
6029
- *
6030
- * @example
6031
- * ```typescript
6032
- * const vueCode = `
6033
- * <template>
6034
- * <div class="container">{{ message }}</div>
6035
- * </template>
6036
- *
6037
- * <script setup lang="ts">
6038
- * import { ref } from 'vue;
6039
- * const message = ref('Hello Vue')
6040
- * </script>
6041
- *
6042
- * <style scoped>
6043
- * .container {
6044
- * padding: 20px;
6045
- * }
6046
- * </style>
6047
- * `;
6048
- *
6049
- * const result = compiler.compile(vueCode, 'MyComponent.vue');
6050
- * console.log(result);
6051
- * ```
6052
- *
6053
- * @throws 不会直接抛出异常,错误通过日志系统记录
6054
- * @see {@link parse} 解析函数
6055
- * @see {@link transform} 转换函数
6056
- * @see {@link generate} 生成函数
6057
- * @see {@link executePlugins} 插件执行函数
6058
- */
6179
+ /** 编译 Vue 源代码为 React 代码 */
6059
6180
  compile(source, filename) {
6060
6181
  const { plugins, preprocessStyles = true } = this.options;
6061
6182
  const fileId = this.genHash(filename);
@@ -6067,16 +6188,16 @@ var BaseCompiler = (_class5 = class extends Helper {
6067
6188
  });
6068
6189
  const genOptions = this.prepareGenerateOptions(filename);
6069
6190
  const resolveSFCAndScriptFile = () => {
6070
- const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _210 => _210.parser]) });
6071
- const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _211 => _211.transformer]) });
6191
+ const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _208 => _208.parser]) });
6192
+ const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _209 => _209.transformer]) });
6072
6193
  const gen = generate(ir, ctx.data, {
6073
6194
  ...genOptions,
6074
- plugins: _optionalChain([plugins, 'optionalAccess', _212 => _212.codegen])
6195
+ plugins: _optionalChain([plugins, 'optionalAccess', _210 => _210.codegen])
6075
6196
  });
6076
6197
  return this.resolveMainResult(ir, gen, ctx.data);
6077
6198
  };
6078
6199
  const resolveStyleFile = () => {
6079
- const result = parseOnlyStyle(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _213 => _213.parser]) });
6200
+ const result = parseOnlyStyle(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _211 => _211.parser]) });
6080
6201
  return this.resolveStyleResult(result, ctx.data);
6081
6202
  };
6082
6203
  try {
@@ -6091,61 +6212,12 @@ var BaseCompiler = (_class5 = class extends Helper {
6091
6212
  ctx.clear();
6092
6213
  }
6093
6214
  }
6094
- /**
6095
- * 初始化 Babel 代码生成选项
6096
- *
6097
- * 合并用户自定义的生成选项与默认选项,确保代码生成的一致性和正确性。
6098
- * 默认配置优化了代码的可读性和性能:
6099
- * 1. 最小化 Unicode 转义:只转义必要的字符,保持代码可读性
6100
- * 2. 统一引号风格:使用单引号,符合 JavaScript 社区常见约定
6101
- * 3. 代码压缩:启用最小化,移除不必要的空白字符
6102
- *
6103
- * 如果用户提供了自定义选项,会与默认选项进行深度合并,
6104
- * 用户选项的优先级高于默认选项。
6105
- *
6106
- * @private
6107
- * @param filename - 可选的文件名,用于源码映射配置
6108
- * @returns {GeneratorOptions} 合并后的 Babel 生成选项
6109
- *
6110
- * @remarks
6111
- * - 源码映射支持:如果启用了 sourceMaps 且提供了文件名,会自动设置 sourceFileName
6112
- * - 选项合并策略:用户选项会覆盖默认选项,实现灵活的配置
6113
- * - 性能优化:默认启用 minified 以减少生成代码的体积
6114
- * - 编码安全:使用 jsesc 确保特殊字符的正确转义
6115
- *
6116
- * @example
6117
- * ```typescript
6118
- * // 默认选项
6119
- * const defaultOptions = {
6120
- * jsescOption: { minimal: true, quotes: 'single' },
6121
- * minified: true
6122
- * };
6123
- *
6124
- * // 用户自定义选项
6125
- * const userOptions = {
6126
- * minified: false, // 覆盖默认值
6127
- * sourceMaps: true // 新增选项
6128
- * };
6129
- *
6130
- * // 合并结果
6131
- * const merged = {
6132
- * jsescOption: { minimal: true, quotes: 'single' },
6133
- * minified: false, // 用户值
6134
- * sourceMaps: true // 用户值
6135
- * };
6136
- * ```
6137
- *
6138
- * @see {@link GeneratorOptions} Babel 生成选项类型定义
6139
- */
6140
6215
  prepareGenerateOptions(filename) {
6141
6216
  const userOptions = this.options.generate || {};
6142
6217
  const mergedOptions = {
6143
- // 配置 jsesc 避免 Unicode 转义
6144
6218
  jsescOption: {
6145
6219
  minimal: true,
6146
- // 只转义必要的字符
6147
6220
  quotes: "single"
6148
- // 使用单引号
6149
6221
  },
6150
6222
  minified: true,
6151
6223
  ...userOptions
@@ -6155,36 +6227,6 @@ var BaseCompiler = (_class5 = class extends Helper {
6155
6227
  }
6156
6228
  return mergedOptions;
6157
6229
  }
6158
- /**
6159
- * 处理 SFC 和 Script 文件的编译结果
6160
- *
6161
- * 根据编译上下文中的输入类型(SFC 或 Script),整理并返回相应的编译结果。
6162
- * 对于 SFC 文件,返回包含 JSX 和 CSS 信息的完整结果;
6163
- * 对于 Script 文件,返回仅包含脚本信息的结果。
6164
- *
6165
- * 关键处理逻辑:
6166
- * 1. 构建基础结果:包含文件ID、路由信息和生成的代码
6167
- * 2. 确定输出路径:根据源文件路径和语言类型生成输出文件路径
6168
- * 3. 区分文件类型:
6169
- * - SFC 文件:生成 .tsx 扩展名,包含样式信息
6170
- * - Script 文件:保持原扩展名,不包含样式信息
6171
- * 4. 样式处理:提取样式文件路径、作用域ID和样式代码
6172
- *
6173
- * @private
6174
- * @param ir - React 中间表示(IR)描述符,包含转换后的组件信息
6175
- * @param gen - 代码生成结果,包含生成的代码和源码映射
6176
- * @param ctxData - 编译上下文数据,包含文件信息和编译状态
6177
- * @returns {CompilationResult} 整理后的编译结果
6178
- *
6179
- * @remarks
6180
- * - 文件扩展名处理:Vue SFC 文件会转换为 .tsx 或 .jsx 文件
6181
- * - 样式分离:SFC 中的样式会被提取到独立的 CSS 文件中
6182
- * - 路由检测:自动检测组件是否使用路由,用于依赖注入
6183
- * - 作用域样式:为 Scoped CSS 生成唯一的作用域ID
6184
- *
6185
- * @see {@link SFCCompilationResult} SFC 编译结果类型
6186
- * @see {@link ScriptCompilationResult} Script 编译结果类型
6187
- */
6188
6230
  resolveMainResult(ir, gen, ctxData) {
6189
6231
  const { fileId, filename, scriptData, styleData, inputType } = ctxData;
6190
6232
  const base = {
@@ -6199,13 +6241,12 @@ var BaseCompiler = (_class5 = class extends Helper {
6199
6241
  fileInfo: {
6200
6242
  jsx: {
6201
6243
  file: `${file}x`,
6202
- // 'xxx.ts' + 'x' => 'xxx.tsx'
6203
6244
  lang
6204
6245
  },
6205
6246
  css: {
6206
- file: _optionalChain([styleData, 'optionalAccess', _214 => _214.filePath]),
6207
- hash: _optionalChain([styleData, 'optionalAccess', _215 => _215.scopeId]),
6208
- code: _optionalChain([ir, 'optionalAccess', _216 => _216.style])
6247
+ file: _optionalChain([styleData, 'optionalAccess', _212 => _212.filePath]),
6248
+ hash: _optionalChain([styleData, 'optionalAccess', _213 => _213.scopeId]),
6249
+ code: _optionalChain([ir, 'optionalAccess', _214 => _214.style])
6209
6250
  }
6210
6251
  },
6211
6252
  ...base
@@ -6216,11 +6257,6 @@ var BaseCompiler = (_class5 = class extends Helper {
6216
6257
  ...base
6217
6258
  };
6218
6259
  }
6219
- /**
6220
- * 处理 Style 文件的编译结果
6221
- * @param data style 文件解析结果
6222
- * @param ctxData 上下文数据
6223
- */
6224
6260
  resolveStyleResult(data, ctxData) {
6225
6261
  const { fileId, filename } = ctxData;
6226
6262
  const { lang, content = "" } = data.style.source;
@@ -6254,23 +6290,24 @@ function formattDuration(n) {
6254
6290
 
6255
6291
  // src/compiler/shared/file-compiler/index.ts
6256
6292
 
6257
-
6258
6293
  var _ora = require('ora'); var _ora2 = _interopRequireDefault(_ora);
6259
6294
 
6260
6295
  // src/compiler/shared/file-compiler/asset-manager.ts
6261
6296
 
6262
6297
 
6263
6298
  var AssetManager = (_class6 = class {
6264
- constructor(fileCompiler, cleanupManager) {;_class6.prototype.__init10.call(this);
6299
+ constructor(fileCompiler, cleanupManager) {;_class6.prototype.__init10.call(this);_class6.prototype.__init11.call(this);
6265
6300
  this.fileCompiler = fileCompiler;
6266
6301
  this.cleanupManager = cleanupManager;
6267
6302
  }
6268
6303
  // 需要经过管线编译处理的文件类型
6269
6304
  __init10() {this.pipelineFiles = [".js", ".ts", ".less", ".scss", ".sass"]}
6305
+ __init11() {this.skippedCount = 0}
6270
6306
  /**
6271
6307
  * 运行资源文件处理管线
6272
6308
  */
6273
6309
  async runAssetPipeline() {
6310
+ const { options } = this.fileCompiler;
6274
6311
  const rootPath = this.fileCompiler.getProjectRoot();
6275
6312
  const inputPath = this.fileCompiler.getInputPath();
6276
6313
  const exclusions = this.fileCompiler.getIgnoreAssets();
@@ -6279,7 +6316,7 @@ var AssetManager = (_class6 = class {
6279
6316
  const relativeToRoot = normalizePath(this.fileCompiler.relativePath(p));
6280
6317
  const filename = _path2.default.basename(p).toLowerCase();
6281
6318
  const ext = _path2.default.extname(p).toLowerCase();
6282
- if (!_optionalChain([this, 'access', _217 => _217.fileCompiler, 'access', _218 => _218.options, 'access', _219 => _219.output, 'optionalAccess', _220 => _220.ignoreAssets])) {
6319
+ if (!_optionalChain([options, 'access', _215 => _215.output, 'optionalAccess', _216 => _216.ignoreAssets])) {
6283
6320
  const shouldExclude = Array.from(exclusions).some((pattern) => {
6284
6321
  if (pattern.endsWith(".")) {
6285
6322
  return filename.startsWith(pattern);
@@ -6289,9 +6326,7 @@ var AssetManager = (_class6 = class {
6289
6326
  }
6290
6327
  return relativeToRoot === pattern || filename === pattern;
6291
6328
  });
6292
- if (shouldExclude) {
6293
- return false;
6294
- }
6329
+ if (shouldExclude) return false;
6295
6330
  } else if (exclusions.has(relativeToRoot) || exclusions.has(filename)) {
6296
6331
  return false;
6297
6332
  }
@@ -6303,20 +6338,16 @@ var AssetManager = (_class6 = class {
6303
6338
  return true;
6304
6339
  });
6305
6340
  const absFiles = new Set(assetFiles.map((f) => this.fileCompiler.getAbsPath(f)));
6306
- const cache = await this.fileCompiler.loadCache("copied" /* ASSET */);
6307
6341
  await this.cleanupManager.cleanupOldOutput("copied" /* ASSET */, (u) => !absFiles.has(u.file));
6308
- await this.updateAssetCaches(assetFiles, cache);
6309
- return assetFiles.length;
6310
- }
6311
- /**
6312
- * 更新资源文件缓存
6313
- */
6314
- async updateAssetCaches(files, cache) {
6315
- for (const file of files) {
6316
- const meta = await this.processAsset(file, cache);
6317
- this.updateCache(file, meta, cache);
6318
- }
6342
+ if (!assetFiles.length) return 0;
6343
+ const cache = await this.fileCompiler.loadCache("copied" /* ASSET */);
6344
+ const copied = await Promise.all(
6345
+ assetFiles.map((file) => {
6346
+ return this.processAsset(file, cache);
6347
+ })
6348
+ );
6319
6349
  await this.fileCompiler.saveCache(cache);
6350
+ return copied.filter(Boolean).length;
6320
6351
  }
6321
6352
  /**
6322
6353
  * Process single asset file, compare with cache and decide whether to copy.
@@ -6330,11 +6361,16 @@ var AssetManager = (_class6 = class {
6330
6361
  const cache = (this.fileCompiler.getIsCache() ? existingCache : void 0) || await this.fileCompiler.loadCache("copied" /* ASSET */);
6331
6362
  const record = cache.target.find((f) => f.file === absPath);
6332
6363
  if (record && this.fileCompiler.compareFileMeta(record, fileMeta)) {
6333
- return fileMeta;
6364
+ this.skippedCount++;
6365
+ return;
6334
6366
  }
6335
6367
  const outputPath = this.fileCompiler.resolveOutputPath(absPath);
6336
6368
  await _fs2.default.promises.mkdir(_path2.default.dirname(outputPath), { recursive: true });
6337
6369
  await _fs2.default.promises.copyFile(absPath, outputPath);
6370
+ this.updateCache(absPath, fileMeta, cache);
6371
+ if (this.fileCompiler.getIsCache() && !existingCache) {
6372
+ await this.fileCompiler.saveCache(cache);
6373
+ }
6338
6374
  return fileMeta;
6339
6375
  }
6340
6376
  /**
@@ -6349,31 +6385,61 @@ var AssetManager = (_class6 = class {
6349
6385
  cache.target.push(newData);
6350
6386
  }
6351
6387
  }
6388
+ /**
6389
+ * 获取跳过的文件数量
6390
+ */
6391
+ getSkippedCount() {
6392
+ return this.skippedCount;
6393
+ }
6394
+ /**
6395
+ * 重置跳过的文件数量
6396
+ */
6397
+ resetSkippedCount() {
6398
+ this.skippedCount = 0;
6399
+ }
6352
6400
  }, _class6);
6353
6401
 
6354
6402
  // src/compiler/shared/file-compiler/cache-manager.ts
6355
- var CacheManager = class {
6356
- constructor(fileCompiler) {
6403
+ var CacheManager = (_class7 = class {
6404
+ constructor(fileCompiler) {;_class7.prototype.__init12.call(this);
6357
6405
  this.fileCompiler = fileCompiler;
6358
6406
  }
6407
+ __init12() {this.pendingUpdates = /* @__PURE__ */ new Map()}
6359
6408
  /**
6360
- * 增量更新缓存记录
6409
+ * 批量更新缓存记录
6361
6410
  */
6362
6411
  async updateCacheIncrementally(unit, key) {
6363
6412
  if (!this.fileCompiler.getIsCache()) return;
6364
- const cache = await this.fileCompiler.loadCache(key);
6365
6413
  const meta = { ...unit };
6366
6414
  delete meta.source;
6367
6415
  if (key === "sfc" /* SFC */) {
6368
- _optionalChainDelete([meta, 'access', _221 => _221.output, 'optionalAccess', _222 => _222.jsx, 'access', _223 => delete _223.code]);
6369
- _optionalChainDelete([meta, 'access', _224 => _224.output, 'optionalAccess', _225 => _225.css, 'access', _226 => delete _226.code]);
6416
+ _optionalChainDelete([meta, 'access', _217 => _217.output, 'optionalAccess', _218 => _218.jsx, 'access', _219 => delete _219.code]);
6417
+ _optionalChainDelete([meta, 'access', _220 => _220.output, 'optionalAccess', _221 => _221.css, 'access', _222 => delete _222.code]);
6370
6418
  } else if (key === "script" /* SCRIPT */) {
6371
- _optionalChainDelete([meta, 'access', _227 => _227.output, 'optionalAccess', _228 => _228.script, 'access', _229 => delete _229.code]);
6419
+ _optionalChainDelete([meta, 'access', _223 => _223.output, 'optionalAccess', _224 => _224.script, 'access', _225 => delete _225.code]);
6372
6420
  } else if (key === "style" /* STYLE */) {
6373
- _optionalChainDelete([meta, 'access', _230 => _230.output, 'optionalAccess', _231 => _231.style, 'access', _232 => delete _232.code]);
6421
+ _optionalChainDelete([meta, 'access', _226 => _226.output, 'optionalAccess', _227 => _227.style, 'access', _228 => delete _228.code]);
6422
+ }
6423
+ if (!this.pendingUpdates.has(key)) {
6424
+ this.pendingUpdates.set(key, []);
6425
+ }
6426
+ this.pendingUpdates.get(key).push({ unit, meta });
6427
+ }
6428
+ /**
6429
+ * 批量保存缓存
6430
+ */
6431
+ async flushCache(key) {
6432
+ if (!this.fileCompiler.getIsCache() || !this.pendingUpdates.has(key)) {
6433
+ return;
6434
+ }
6435
+ const updates = this.pendingUpdates.get(key);
6436
+ if (updates.length === 0) return;
6437
+ const cache = await this.fileCompiler.loadCache(key);
6438
+ for (const { unit, meta } of updates) {
6439
+ this.updateCache(unit.file, meta, cache);
6374
6440
  }
6375
- this.updateCache(unit.file, meta, cache);
6376
6441
  await this.fileCompiler.saveCache(cache);
6442
+ this.pendingUpdates.set(key, []);
6377
6443
  }
6378
6444
  /**
6379
6445
  * 更新缓存
@@ -6386,7 +6452,7 @@ var CacheManager = class {
6386
6452
  cache.target.push(newData);
6387
6453
  }
6388
6454
  }
6389
- };
6455
+ }, _class7);
6390
6456
 
6391
6457
  // src/compiler/shared/file-compiler/cleanup-manager.ts
6392
6458
 
@@ -6416,19 +6482,37 @@ var CleanupManager = class {
6416
6482
  const toRemove = cache.target.filter(filter);
6417
6483
  if (!toRemove.length) return;
6418
6484
  const removeFn = async (m) => {
6419
- if (key === "sfc" /* SFC */) {
6420
- const meta = m;
6421
- if (!_optionalChain([meta, 'optionalAccess', _233 => _233.output])) return;
6422
- const { jsx, css } = meta.output;
6423
- await this.fileCompiler.removeOutputFile(jsx.file);
6424
- if (_optionalChain([css, 'optionalAccess', _234 => _234.file])) {
6425
- await this.fileCompiler.removeOutputFile(css.file);
6485
+ let meta;
6486
+ switch (key) {
6487
+ case "sfc" /* SFC */: {
6488
+ meta = m;
6489
+ const { jsx, css } = meta.output;
6490
+ await this.fileCompiler.removeOutputFile(jsx.file);
6491
+ if (_optionalChain([css, 'optionalAccess', _229 => _229.file])) {
6492
+ await this.fileCompiler.removeOutputFile(css.file);
6493
+ }
6494
+ break;
6495
+ }
6496
+ case "script" /* SCRIPT */: {
6497
+ meta = m;
6498
+ await this.fileCompiler.removeOutputFile(meta.output.script.file);
6499
+ break;
6500
+ }
6501
+ case "style" /* STYLE */: {
6502
+ meta = m;
6503
+ await this.fileCompiler.removeOutputFile(meta.output.style.file);
6504
+ break;
6505
+ }
6506
+ // 静态资产缓存直接删除对应文件
6507
+ default: {
6508
+ await this.fileCompiler.removeOutputFile(m.file, true);
6509
+ break;
6426
6510
  }
6427
- } else if (key === "script" /* SCRIPT */ || key === "copied" /* ASSET */) {
6428
- await this.fileCompiler.removeOutputFile(m.file, true);
6429
6511
  }
6430
6512
  };
6431
6513
  await Promise.all(toRemove.map(removeFn));
6514
+ const removedFiles = new Set(toRemove.map((m) => m.file));
6515
+ cache.target = cache.target.filter((m) => !removedFiles.has(m.file));
6432
6516
  await this.fileCompiler.saveCache(cache);
6433
6517
  }
6434
6518
  };
@@ -6465,7 +6549,7 @@ var CompilationUnitProcessor = class {
6465
6549
  const isScriptFile = key === "script" /* SCRIPT */;
6466
6550
  const isStyleFile = key === "style" /* STYLE */;
6467
6551
  if (isSFC || isScriptFile) {
6468
- unit.hasRoute = _optionalChain([result, 'optionalAccess', _235 => _235.hasRoute]);
6552
+ unit.hasRoute = _optionalChain([result, 'optionalAccess', _230 => _230.hasRoute]);
6469
6553
  }
6470
6554
  const resolveFileInfo = () => {
6471
6555
  if (isSFC) {
@@ -6485,7 +6569,7 @@ var CompilationUnitProcessor = class {
6485
6569
  const { script } = result.fileInfo;
6486
6570
  unit.output = {
6487
6571
  script: {
6488
- file: _optionalChain([script, 'optionalAccess', _236 => _236.file]),
6572
+ file: _optionalChain([script, 'optionalAccess', _231 => _231.file]),
6489
6573
  code
6490
6574
  }
6491
6575
  };
@@ -6532,18 +6616,14 @@ var CompilationUnitProcessor = class {
6532
6616
  // src/compiler/shared/file-compiler/file-processor.ts
6533
6617
 
6534
6618
 
6535
- var FileProcessor = (_class7 = class {
6536
- constructor(fileCompiler, compilationUnitProcessor, cacheManager) {;_class7.prototype.__init11.call(this);
6619
+
6620
+ var FileProcessor = (_class8 = class {
6621
+ constructor(fileCompiler, compilationUnitProcessor, cacheManager) {;_class8.prototype.__init13.call(this);
6537
6622
  this.fileCompiler = fileCompiler;
6538
6623
  this.compilationUnitProcessor = compilationUnitProcessor;
6539
6624
  this.cacheManager = cacheManager;
6540
6625
  }
6541
- __init11() {this.pkgs = {
6542
- router: {
6543
- name: PACKAGE_NAME.router,
6544
- version: "^1.0.0"
6545
- }
6546
- }}
6626
+ __init13() {this.skippedCount = 0}
6547
6627
  /**
6548
6628
  * Process a single Vue file (this method is called directly in CLI Watch mode)
6549
6629
  */
@@ -6566,13 +6646,16 @@ var FileProcessor = (_class7 = class {
6566
6646
  const absPath = this.fileCompiler.getAbsPath(filePath);
6567
6647
  const fileMeta = await this.fileCompiler.getFileMeta(absPath);
6568
6648
  const cache = (this.fileCompiler.getIsCache() ? existingCache : void 0) || await this.fileCompiler.loadCache(key);
6569
- const record = _optionalChain([cache, 'optionalAccess', _237 => _237.target, 'access', _238 => _238.find, 'call', _239 => _239((c) => c.file === absPath)]);
6649
+ const record = _optionalChain([cache, 'optionalAccess', _232 => _232.target, 'access', _233 => _233.find, 'call', _234 => _234((c) => c.file === absPath)]);
6570
6650
  const { shouldCompile, hash } = await this.fileCompiler.checkCacheStatus(
6571
6651
  fileMeta,
6572
6652
  record,
6573
6653
  () => _fs2.default.promises.readFile(absPath, "utf-8")
6574
6654
  );
6575
- if (!shouldCompile) return;
6655
+ if (!shouldCompile) {
6656
+ this.skippedCount++;
6657
+ return;
6658
+ }
6576
6659
  const source = await _fs2.default.promises.readFile(absPath, "utf-8");
6577
6660
  if (!source.trim()) return;
6578
6661
  const initUnit = {
@@ -6585,57 +6668,119 @@ var FileProcessor = (_class7 = class {
6585
6668
  hash: hash || this.fileCompiler.genHash(source)
6586
6669
  };
6587
6670
  const processed = await this.compilationUnitProcessor.resolve(initUnit, key);
6588
- if (_optionalChain([processed, 'optionalAccess', _240 => _240.output])) {
6671
+ if (_optionalChain([processed, 'optionalAccess', _235 => _235.output])) {
6589
6672
  await this.compilationUnitProcessor.saveCompiledFiles(processed, key);
6590
6673
  if (key === "sfc" /* SFC */ || key === "script" /* SCRIPT */) {
6591
- if (_optionalChain([processed, 'optionalAccess', _241 => _241.hasRoute])) {
6592
- await this.injectVuReactRouteDep();
6593
- await this.copyRouteSetupNotes();
6674
+ if (_optionalChain([processed, 'optionalAccess', _236 => _236.hasRoute])) {
6675
+ await this.addRouterToPackageJson();
6676
+ await this.updateEntryWithRouterProvider();
6594
6677
  }
6595
6678
  }
6596
6679
  await this.cacheManager.updateCacheIncrementally(processed, key);
6597
6680
  }
6598
6681
  return processed;
6599
6682
  }
6600
- async injectVuReactRouteDep() {
6601
- const pkgPath = this.fileCompiler.getOutputPkgPath();
6602
- const pkg = await this.fileCompiler.resolvePackageFile(pkgPath);
6603
- const { router } = this.pkgs;
6604
- if (!pkg["dependencies"]) {
6605
- pkg["dependencies"] = {};
6683
+ /**
6684
+ * package.json 注入路由依赖项
6685
+ */
6686
+ async addRouterToPackageJson() {
6687
+ const { output } = this.fileCompiler.options;
6688
+ if (_optionalChain([output, 'optionalAccess', _237 => _237.bootstrapVite]) === false) {
6689
+ return;
6606
6690
  }
6607
- pkg["dependencies"][router.name] = router.version;
6608
- await _fs2.default.promises.writeFile(pkgPath, JSON.stringify(pkg, null, 2), "utf-8");
6691
+ const { router } = RUNTIME_PACKAGES;
6692
+ const filePath = this.fileCompiler.getOutputPkgPath();
6693
+ const packageJson = await this.fileCompiler.resolvePackageFile(filePath);
6694
+ if (_optionalChain([packageJson, 'optionalAccess', _238 => _238.dependencies, 'optionalAccess', _239 => _239[router.name]])) {
6695
+ return;
6696
+ }
6697
+ if (!packageJson.dependencies) {
6698
+ packageJson.dependencies = {};
6699
+ }
6700
+ packageJson.dependencies[router.name] = router.version;
6701
+ const newData = JSON.stringify(packageJson, null, 2);
6702
+ await this.fileCompiler.writeFileWithDir(filePath, newData, {
6703
+ lock: true
6704
+ });
6609
6705
  }
6610
6706
  /**
6611
- * 如果使用了路由,则拷贝路由配置说明文档到输出目录根部。
6707
+ * 注入路由提供器到 React 应用的入口文件(如 main.tsx)
6612
6708
  */
6613
- async copyRouteSetupNotes() {
6614
- const outputDir = this.fileCompiler.getOuputPath();
6615
- const packageRoot = _path2.default.resolve(getDirname(import.meta.url), "../");
6616
- const templateDir = _path2.default.join(packageRoot, "templates");
6617
- if (!_fs2.default.existsSync(templateDir)) {
6709
+ async updateEntryWithRouterProvider() {
6710
+ const { exclude, output, router } = this.fileCompiler.options;
6711
+ const inputPath = this.fileCompiler.getInputPath();
6712
+ const outputPath = this.fileCompiler.getOuputPath(true);
6713
+ if (_optionalChain([output, 'optionalAccess', _240 => _240.bootstrapVite]) === false || _optionalChain([router, 'optionalAccess', _241 => _241.autoUpdateEntry]) === false || !_optionalChain([router, 'optionalAccess', _242 => _242.configFile])) {
6618
6714
  return;
6619
6715
  }
6620
- const files = ["route-setup-notes.md", "route-setup-notes.zh.md"];
6621
- for (const file of files) {
6622
- const srcPath = _path2.default.join(templateDir, file);
6623
- if (!_fs2.default.existsSync(srcPath)) continue;
6624
- const destPath = _path2.default.join(outputDir, file);
6625
- await _fs2.default.promises.copyFile(srcPath, destPath);
6716
+ const getMainFile = async (filename) => {
6717
+ const filePath = _path2.default.resolve(outputPath, filename);
6718
+ try {
6719
+ return { filePath, content: await _fs2.default.promises.readFile(filePath, "utf-8") };
6720
+ } catch (e18) {
6721
+ return;
6722
+ }
6723
+ };
6724
+ const fileData = await getMainFile("main.tsx") || await getMainFile("main.jsx");
6725
+ if (!fileData) {
6726
+ console.warn(
6727
+ `${_kleur2.default.yellow("\u26A0\uFE0F")} React application entry file not found, please confirm the filename is main.tsx or main.jsx?`
6728
+ );
6729
+ return;
6626
6730
  }
6731
+ const prepareRouterEntry = () => {
6732
+ const importPath = this.fileCompiler.resolveRelativePath(inputPath, router.configFile);
6733
+ let content = fileData.content;
6734
+ if (_optionalChain([exclude, 'optionalAccess', _243 => _243.includes, 'call', _244 => _244(router.configFile)]) || _optionalChain([exclude, 'optionalAccess', _245 => _245.includes, 'call', _246 => _246(importPath)])) {
6735
+ return content;
6736
+ }
6737
+ const routerModule = "RouterInstance";
6738
+ if (content.includes(routerModule) || content.includes(importPath)) {
6739
+ return content;
6740
+ }
6741
+ const routerImport = `import ${routerModule} from '${importPath}'`;
6742
+ if (content.includes("./App")) {
6743
+ const appImportRegex = /import\s+(?:App|.*)\s+from\s+['"]\.\/App\.(?:tsx|jsx)['"]/;
6744
+ content = content.replace(appImportRegex, routerImport);
6745
+ } else {
6746
+ const lastImportMatch = content.match(/import.*from.*\n/g);
6747
+ if (lastImportMatch) {
6748
+ const lastImport = lastImportMatch.pop();
6749
+ content = content.replace(lastImport, `${lastImport}
6750
+ ${routerImport}`);
6751
+ } else {
6752
+ content = `${routerImport}${content}`;
6753
+ }
6754
+ }
6755
+ const providerTag = `<${routerModule}.RouterProvider />`;
6756
+ fileData.content = content.replace(/<App\s*\/?>/g, providerTag);
6757
+ };
6758
+ prepareRouterEntry();
6759
+ await this.fileCompiler.writeFileWithDir(fileData.filePath, fileData.content);
6627
6760
  }
6628
- }, _class7);
6761
+ /**
6762
+ * 获取跳过的文件数量
6763
+ */
6764
+ getSkippedCount() {
6765
+ return this.skippedCount;
6766
+ }
6767
+ /**
6768
+ * 重置跳过的文件数量
6769
+ */
6770
+ resetSkippedCount() {
6771
+ this.skippedCount = 0;
6772
+ }
6773
+ }, _class8);
6629
6774
 
6630
6775
  // src/compiler/shared/file-compiler/pipeline-manager.ts
6631
6776
 
6632
- var PipelineManager = (_class8 = class {
6633
- constructor(fileCompiler, fileProcessor) {;_class8.prototype.__init12.call(this);
6777
+ var PipelineManager = (_class9 = class {
6778
+ constructor(fileCompiler, fileProcessor) {;_class9.prototype.__init14.call(this);
6634
6779
  this.fileCompiler = fileCompiler;
6635
6780
  this.fileProcessor = fileProcessor;
6636
6781
  this.cleanupManager = new CleanupManager(fileCompiler);
6637
6782
  }
6638
- __init12() {this.skippedCount = 0}
6783
+ __init14() {this.skippedCount = 0}
6639
6784
 
6640
6785
  /**
6641
6786
  * 运行 SFC 编译管线
@@ -6675,28 +6820,21 @@ var PipelineManager = (_class8 = class {
6675
6820
  }
6676
6821
  return false;
6677
6822
  });
6678
- if (!files.length) return 0;
6679
- const cache = await this.fileCompiler.loadCache(key);
6680
6823
  const absFiles = new Set(files.map((f) => this.fileCompiler.getAbsPath(f)));
6681
6824
  await this.cleanupManager.cleanupOldOutput(key, (c) => !absFiles.has(c.file));
6682
- const results = await Promise.all(
6683
- files.map(async (f) => {
6684
- if (key === "sfc" /* SFC */) {
6685
- return this.fileProcessor.processFile(key, f, cache);
6686
- } else {
6687
- return this.fileProcessor.processFile(key, f, cache);
6688
- }
6689
- })
6825
+ if (!files.length) return 0;
6826
+ const cache = await this.fileCompiler.loadCache(key);
6827
+ const compiled = await Promise.all(
6828
+ files.map(async (f) => this.fileProcessor.processFile(key, f, cache))
6690
6829
  );
6691
- const compiledCount = results.filter(Boolean).length;
6692
- this.skippedCount += files.length - compiledCount;
6693
- return compiledCount;
6830
+ await this.fileCompiler.flushCache(key);
6831
+ return compiled.filter(Boolean).length;
6694
6832
  }
6695
6833
  /**
6696
6834
  * 获取跳过的文件数量
6697
6835
  */
6698
6836
  getSkippedCount() {
6699
- return this.skippedCount;
6837
+ return this.skippedCount += this.fileProcessor.getSkippedCount();
6700
6838
  }
6701
6839
  /**
6702
6840
  * 重置跳过的文件数量
@@ -6704,24 +6842,22 @@ var PipelineManager = (_class8 = class {
6704
6842
  resetSkippedCount() {
6705
6843
  this.skippedCount = 0;
6706
6844
  }
6707
- }, _class8);
6845
+ }, _class9);
6708
6846
 
6709
6847
  // src/compiler/shared/file-compiler/vite-bootstrapper.ts
6848
+ var _child_process = require('child_process');
6710
6849
 
6711
6850
 
6712
6851
 
6713
-
6714
- var ViteBootstrapper = (_class9 = class {
6715
- constructor(fileCompiler, options) {;_class9.prototype.__init13.call(this);_class9.prototype.__init14.call(this);
6852
+ var ViteBootstrapper = (_class10 = class {
6853
+ constructor(fileCompiler, options) {;_class10.prototype.__init15.call(this);_class10.prototype.__init16.call(this);
6716
6854
  this.fileCompiler = fileCompiler;
6717
6855
  this.options = options;
6718
6856
  }
6719
- __init13() {this.spinner = _ora2.default.call(void 0, )}
6720
- __init14() {this.pkgs = {
6721
- runtime: {
6722
- name: PACKAGE_NAME.runtime,
6723
- version: "^1.0.0"
6724
- }
6857
+ __init15() {this.spinner = _ora2.default.call(void 0, )}
6858
+ __init16() {this.defaultConfig = {
6859
+ template: "react-ts",
6860
+ viteVersion: "@latest"
6725
6861
  }}
6726
6862
  /**
6727
6863
  * 检查是否需要初始化 Vite 环境
@@ -6739,27 +6875,27 @@ var ViteBootstrapper = (_class9 = class {
6739
6875
  */
6740
6876
  async bootstrapIfNeeded() {
6741
6877
  const { bootstrapVite } = this.options.output || {};
6878
+ const workspaceDir = this.fileCompiler.getWorkspaceDir();
6879
+ await _fs2.default.promises.mkdir(workspaceDir, { recursive: true });
6742
6880
  if (bootstrapVite === false) {
6743
6881
  return false;
6744
6882
  }
6745
6883
  if (this.isSingleFile()) {
6746
- console.info(_kleur2.default.dim("Skipping Vite initialization for single file compilation"));
6884
+ console.info("Skipping Vite initialization for single file compilation");
6747
6885
  return false;
6748
6886
  }
6749
- const workspaceDir = this.fileCompiler.getWorkspaceDir();
6750
6887
  const outputPkgPath = this.fileCompiler.getOutputPkgPath();
6751
6888
  if (_fs2.default.existsSync(outputPkgPath)) {
6752
6889
  return false;
6753
6890
  }
6754
6891
  this.spinner.start("Bootstrapping Vite React environment...");
6755
- await _fs2.default.promises.mkdir(workspaceDir, { recursive: true });
6756
6892
  try {
6757
- this.resolveViteCreateApp();
6893
+ await this.resolveViteCreateApp();
6758
6894
  } catch (err) {
6759
6895
  this.spinner.stop();
6760
6896
  console.error(
6761
6897
  _kleur2.default.red("\u2716"),
6762
- "Failed to bootstrap Vite environment. Please check npm/network\n",
6898
+ "Failed to bootstrap Vite environment. Please check npm/network.",
6763
6899
  err
6764
6900
  );
6765
6901
  return false;
@@ -6779,7 +6915,7 @@ var ViteBootstrapper = (_class9 = class {
6779
6915
  ...vite
6780
6916
  };
6781
6917
  if (!isDev) {
6782
- const { runtime } = this.pkgs;
6918
+ const { runtime } = RUNTIME_PACKAGES;
6783
6919
  deps[runtime.name] = runtime.version;
6784
6920
  }
6785
6921
  return deps;
@@ -6791,130 +6927,197 @@ var ViteBootstrapper = (_class9 = class {
6791
6927
  const newDevDeps = resolveDeps(rootPkg.devDependencies, vitePkg.devDependencies, true);
6792
6928
  vitePkg.dependencies = newDeps;
6793
6929
  vitePkg.devDependencies = newDevDeps;
6794
- await _fs2.default.promises.writeFile(outputPkgPath, JSON.stringify(vitePkg, null, 2), "utf-8");
6930
+ const newVitePkg = JSON.stringify(vitePkg, null, 2);
6931
+ await this.fileCompiler.writeFileWithDir(outputPkgPath, newVitePkg);
6795
6932
  this.spinner.succeed("Standard Vite React environment initialized");
6796
6933
  return true;
6797
6934
  }
6798
6935
  /**
6799
6936
  * 执行 vite 创建命令
6800
6937
  */
6801
- resolveViteCreateApp() {
6938
+ async resolveViteCreateApp() {
6802
6939
  const { output } = this.options;
6803
- const config = _optionalChain([output, 'optionalAccess', _242 => _242.bootstrapVite]);
6804
- const template = typeof config === "object" ? config.template : "react-ts";
6940
+ const { viteVersion, template: tmpl } = this.defaultConfig;
6941
+ const bootstrapVite = _optionalChain([output, 'optionalAccess', _247 => _247.bootstrapVite]);
6805
6942
  const outDirName = this.fileCompiler.getOutDirName();
6806
- const cmd = `npm create vite@latest ${outDirName} -- --template ${template}`;
6943
+ const configObject = typeof bootstrapVite === "object" ? bootstrapVite : null;
6944
+ const viteVer = _optionalChain([configObject, 'optionalAccess', _248 => _248.vite]) || viteVersion;
6945
+ const reactVer = _optionalChain([configObject, 'optionalAccess', _249 => _249.react]);
6946
+ const template = _optionalChain([configObject, 'optionalAccess', _250 => _250.template]) || tmpl;
6947
+ const cmd = `npm create vite${viteVer} ${outDirName} -- --template ${template}`;
6807
6948
  _child_process.execSync.call(void 0, cmd, {
6808
6949
  cwd: this.fileCompiler.getWorkspaceDir(),
6809
6950
  stdio: "ignore"
6810
6951
  // 隐藏 create-vite 内部的输出日志,保持终端整洁
6811
6952
  });
6953
+ if (reactVer) {
6954
+ await this.resolveReactVersion(reactVer);
6955
+ }
6812
6956
  }
6813
- }, _class9);
6814
-
6815
- // src/compiler/shared/file-compiler/index.ts
6816
- var FileCompiler = (_class10 = class extends BaseCompiler {
6817
- __init15() {this.skippedCount = 0}
6818
- __init16() {this.spinner = _ora2.default.call(void 0, )}
6819
- // 管理器实例
6820
-
6821
-
6822
-
6823
-
6824
-
6825
-
6826
-
6827
6957
  /**
6828
- * 创建文件系统编译器实例
6829
- *
6830
- * @param options - 编译器配置选项,继承自 BaseCompiler 的选项
6831
- * 包括输入路径、输出配置、缓存设置、排除模式等
6832
- * @see {@link CompilerOptions} 查看完整的选项说明
6958
+ * 处理 React 包版本
6959
+ * @param ver 版本号
6833
6960
  */
6834
- constructor(options = {}) {
6835
- super(options);_class10.prototype.__init15.call(this);_class10.prototype.__init16.call(this);;
6836
- this.initializeManagers();
6961
+ async resolveReactVersion(ver) {
6962
+ const outputPkgPath = this.fileCompiler.getOutputPkgPath();
6963
+ const vitePkg = await this.fileCompiler.resolvePackageFile(outputPkgPath);
6964
+ const typesVer = `^${ver.split(".")[0].replace(/@|\^/, "")}.0.0`;
6965
+ vitePkg.dependencies.react = ver;
6966
+ vitePkg.dependencies["react-dom"] = ver;
6967
+ vitePkg.devDependencies["@types/react"] = typesVer;
6968
+ vitePkg.devDependencies["@types/react-dom"] = typesVer;
6969
+ await this.fileCompiler.writeFileWithDir(outputPkgPath, JSON.stringify(vitePkg, null, 2), {
6970
+ lock: true
6971
+ });
6972
+ }
6973
+ }, _class10);
6974
+
6975
+ // src/compiler/shared/file-compiler/setup-manager.ts
6976
+ var SetupManager = class {
6977
+ constructor(getCompiler) {
6978
+ this.getCompiler = getCompiler;
6979
+ this.setup();
6837
6980
  }
6838
6981
  /**
6839
6982
  * 初始化所有管理器实例
6840
6983
  *
6841
- * 按照依赖关系顺序创建各个管理器:
6984
+ * !必须按照依赖关系顺序创建各个管理器:
6842
6985
  * 1. 基础管理器(无依赖)
6843
6986
  * 2. 依赖基础管理器的管理器
6844
6987
  * 3. 依赖其他管理器的管理器
6845
- *
6846
- * @private
6847
6988
  */
6848
- initializeManagers() {
6849
- this.cacheManager = new CacheManager(this);
6850
- this.cleanupManager = new CleanupManager(this);
6851
- this.compilationUnitProcessor = new CompilationUnitProcessor(this);
6852
- this.fileProcessor = new FileProcessor(this, this.compilationUnitProcessor, this.cacheManager);
6853
- this.viteBootstrapper = new ViteBootstrapper(this, this.options);
6854
- this.pipelineManager = new PipelineManager(this, this.fileProcessor);
6855
- this.assetManager = new AssetManager(this, this.cleanupManager);
6989
+ setup() {
6990
+ const fileCompiler = this.getCompiler();
6991
+ this.setupBaseManager(fileCompiler);
6992
+ this.setupManagedByBase(fileCompiler);
6993
+ this.setupCompositeManager(fileCompiler);
6856
6994
  }
6857
6995
  /**
6858
- * 执行完整的编译流程
6859
- *
6860
- * 该方法执行以下步骤:
6861
- * 1. 环境初始化:清理旧输出(如果禁用缓存)并初始化 Vite 项目环境
6862
- * 2. Vue 文件编译:批量处理所有 .vue 文件
6863
- * 3. Script 文件编译:批量处理所有 .js/.ts 文件
6864
- * 4. 资源文件拷贝:处理剩余的非编译文件
6865
- * 5. 统计输出:显示编译结果和性能统计
6866
- *
6867
- * @async
6868
- * @throws {Error} 当编译过程中发生致命错误时抛出
6869
- * @returns {Promise<void>}
6996
+ * 创建基础的管理器(无外部依赖)
6997
+ */
6998
+ setupBaseManager(fileCompiler) {
6999
+ fileCompiler.manager = {};
7000
+ const manager = fileCompiler.manager;
7001
+ manager.cacheManager = new CacheManager(fileCompiler);
7002
+ manager.cleanupManager = new CleanupManager(fileCompiler);
7003
+ }
7004
+ /**
7005
+ * 创建依赖基础管理器的管理器
7006
+ */
7007
+ setupManagedByBase(fileCompiler) {
7008
+ const manager = fileCompiler.manager;
7009
+ manager.fileProcessor = new FileProcessor(
7010
+ fileCompiler,
7011
+ new CompilationUnitProcessor(fileCompiler),
7012
+ manager.cacheManager
7013
+ );
7014
+ }
7015
+ /**
7016
+ * 创建依赖其他管理器的管理器
6870
7017
  */
7018
+ setupCompositeManager(fileCompiler) {
7019
+ const manager = fileCompiler.manager;
7020
+ manager.viteBootstrapper = new ViteBootstrapper(fileCompiler, fileCompiler.options);
7021
+ manager.pipelineManager = new PipelineManager(fileCompiler, manager.fileProcessor);
7022
+ manager.assetManager = new AssetManager(fileCompiler, manager.cleanupManager);
7023
+ }
7024
+ };
7025
+
7026
+ // src/compiler/shared/file-compiler/index.ts
7027
+ var FileCompiler = (_class11 = class extends BaseCompiler {
7028
+
7029
+ __init17() {this.spinner = _ora2.default.call(void 0, )}
7030
+ constructor(options = {}) {
7031
+ super(options);_class11.prototype.__init17.call(this);;
7032
+ new SetupManager(() => this);
7033
+ }
7034
+ /** 执行完整的编译流程 */
6871
7035
  async execute() {
6872
7036
  console.info("\n\n", _kleur2.default.magenta(`${_kleur2.default.bold("VUREACT")} v${this.version}`), "\n");
6873
7037
  const startTime = performance.now();
6874
- if (!this.getIsCache()) {
6875
- await _fs2.default.promises.rm(this.getWorkspaceDir(), { recursive: true, force: true });
6876
- }
6877
- await this.viteBootstrapper.bootstrapIfNeeded();
7038
+ const rmWorkspace = async () => {
7039
+ await this.rmFile(this.getWorkspaceDir());
7040
+ };
6878
7041
  try {
7042
+ if (!this.getIsCache()) {
7043
+ await rmWorkspace();
7044
+ }
7045
+ await this.manager.viteBootstrapper.bootstrapIfNeeded();
6879
7046
  const sfcCount = await this.runPipelineWithSpinner("sfc" /* SFC */);
6880
7047
  const scriptCount = await this.runPipelineWithSpinner("script" /* SCRIPT */);
6881
7048
  const styleCount = await this.runPipelineWithSpinner("style" /* STYLE */);
6882
7049
  const assetCount = await this.runPipelineWithSpinner("copied" /* ASSET */);
6883
- await _optionalChain([this, 'access', _243 => _243.options, 'access', _244 => _244.onSuccess, 'optionalCall', _245 => _245()]);
7050
+ await _optionalChain([this, 'access', _251 => _251.options, 'access', _252 => _252.onSuccess, 'optionalCall', _253 => _253()]);
6884
7051
  const endTime = calcElapsedTime(startTime);
6885
7052
  this.printCoreLogs();
6886
7053
  this.showCompileStats(endTime, sfcCount, scriptCount, styleCount, assetCount);
6887
7054
  } catch (error) {
6888
7055
  const endTime = calcElapsedTime(startTime);
7056
+ await rmWorkspace();
6889
7057
  console.error(_kleur2.default.red("\u2716"), `Build failed in ${endTime}`);
6890
7058
  console.error(error);
7059
+ } finally {
7060
+ this.resetSkippedCount();
6891
7061
  }
6892
7062
  }
6893
- /**
6894
- * 运行管线并显示加载动画
6895
- *
6896
- * @private
6897
- * @param text - 加载动画显示的文本
6898
- * @param pipelineFn - 要执行的管线函数
6899
- * @returns 返回的处理的文件数
6900
- */
7063
+ /** 处理单个 Vue 单文件组件(SFC) */
7064
+ async processSFC(filePath, existingCache) {
7065
+ return this.manager.fileProcessor.processSFC(filePath, existingCache);
7066
+ }
7067
+ /** 处理单个 JavaScript/TypeScript 脚本文件 */
7068
+ async processScript(filePath, existingCache) {
7069
+ return this.manager.fileProcessor.processScript(filePath, existingCache);
7070
+ }
7071
+ /** 处理单个 CSS/LESS/SCSS 样式文件 */
7072
+ async processStyle(filePath, existingCache) {
7073
+ return this.manager.fileProcessor.processStyle(filePath, existingCache);
7074
+ }
7075
+ /** 处理单个文件(Vue 或 Script) */
7076
+ async processFile(key, filePath, existingCache) {
7077
+ if (key === "sfc" /* SFC */) {
7078
+ return this.manager.fileProcessor.processFile(key, filePath, existingCache);
7079
+ } else if (key === "script" /* SCRIPT */) {
7080
+ return this.manager.fileProcessor.processFile(
7081
+ key,
7082
+ filePath,
7083
+ existingCache
7084
+ );
7085
+ }
7086
+ return this.manager.fileProcessor.processFile(
7087
+ key,
7088
+ filePath,
7089
+ existingCache
7090
+ );
7091
+ }
7092
+ /** 处理单个资源文件 */
7093
+ async processAsset(filePath, existingCache) {
7094
+ return this.manager.assetManager.processAsset(filePath, existingCache);
7095
+ }
7096
+ /** 批量保存缓存 */
7097
+ async flushCache(key) {
7098
+ await this.manager.cacheManager.flushCache(key);
7099
+ }
7100
+ /** 删除指定路径对应的输出文件和缓存 */
7101
+ async removeOutputPath(targetPath, type) {
7102
+ return await this.manager.cleanupManager.removeOutputPath(targetPath, type);
7103
+ }
6901
7104
  async runPipelineWithSpinner(name) {
6902
7105
  const options = {
6903
7106
  ["sfc" /* SFC */]: {
6904
7107
  text: "Compiling Vue files...",
6905
- pipeline: () => this.pipelineManager.runSfcPipeline()
7108
+ pipeline: () => this.manager.pipelineManager.runSfcPipeline()
6906
7109
  },
6907
7110
  ["script" /* SCRIPT */]: {
6908
7111
  text: "Compiling script files...",
6909
- pipeline: () => this.pipelineManager.runScriptPipeline()
7112
+ pipeline: () => this.manager.pipelineManager.runScriptPipeline()
6910
7113
  },
6911
7114
  ["style" /* STYLE */]: {
6912
7115
  text: "Compiling style files...",
6913
- pipeline: () => this.pipelineManager.runStylePipeline()
7116
+ pipeline: () => this.manager.pipelineManager.runStylePipeline()
6914
7117
  },
6915
7118
  ["copied" /* ASSET */]: {
6916
7119
  text: "Copying assets...",
6917
- pipeline: () => this.assetManager.runAssetPipeline()
7120
+ pipeline: () => this.manager.assetManager.runAssetPipeline()
6918
7121
  }
6919
7122
  };
6920
7123
  const { text, pipeline } = options[name];
@@ -6927,166 +7130,36 @@ var FileCompiler = (_class10 = class extends BaseCompiler {
6927
7130
  this.spinner.stop();
6928
7131
  }
6929
7132
  }
6930
- /**
6931
- * 处理单个 Vue 单文件组件(SFC)
6932
- *
6933
- * 此方法主要用于 CLI 的 watch 模式,当检测到文件变更时调用。
6934
- * 支持增量编译,如果文件未变更则跳过编译。
6935
- *
6936
- * @async
6937
- * @param filePath - Vue 文件的绝对路径
6938
- * @param existingCache - 可选的预加载缓存对象,用于增量编译
6939
- * @returns {Promise<SFCUnit | undefined>} 编译单元对象,如果跳过编译则返回 undefined
6940
- * @see {@link FileProcessor.processSFC}
6941
- */
6942
- async processSFC(filePath, existingCache) {
6943
- return this.fileProcessor.processSFC(filePath, existingCache);
6944
- }
6945
- /**
6946
- * 处理单个 JavaScript/TypeScript 脚本文件
6947
- *
6948
- * 此方法主要用于 CLI 的 watch 模式,当检测到文件变更时调用。
6949
- * 支持增量编译,如果文件未变更则跳过编译。
6950
- *
6951
- * @async
6952
- * @param filePath - 脚本文件的绝对路径
6953
- * @param existingCache - 可选的预加载缓存对象,用于增量编译
6954
- * @returns {Promise<ScriptUnit | undefined>} 编译单元对象,如果跳过编译则返回 undefined
6955
- * @see {@link FileProcessor.processScript}
6956
- */
6957
- async processScript(filePath, existingCache) {
6958
- return this.fileProcessor.processScript(filePath, existingCache);
6959
- }
6960
- /**
6961
- * 处理单个 CSS/LESS/SCSS 样式文件
6962
- *
6963
- * 此方法主要用于 CLI 的 watch 模式,当检测到文件变更时调用。
6964
- * 支持增量编译,如果文件未变更则跳过编译。
6965
- *
6966
- * @async
6967
- * @param filePath - style 文件的绝对路径
6968
- * @param existingCache - 可选的预加载缓存对象,用于增量编译
6969
- * @returns {Promise<ScriptUnit | undefined>} 编译单元对象,如果跳过编译则返回 undefined
6970
- * @see {@link FileProcessor.processStyle}
6971
- */
6972
- async processStyle(filePath, existingCache) {
6973
- return this.fileProcessor.processStyle(filePath, existingCache);
6974
- }
6975
- /**
6976
- * 处理单个文件(Vue 或 Script)
6977
- *
6978
- * 通用的文件处理方法,根据 CacheKey 类型自动选择处理逻辑。
6979
- * 主要用于内部调用和统一的文件处理接口。
6980
- *
6981
- * @async
6982
- * @param key - 文件类型标识(SFC 或 SCRIPT)
6983
- * @param filePath - 文件的绝对路径
6984
- * @param existingCache - 可选的预加载缓存对象
6985
- * @returns {Promise<SFCUnit | ScriptUnit | undefined>} 编译单元对象
6986
- * @see {@link FileProcessor.processFile}
6987
- */
6988
- async processFile(key, filePath, existingCache) {
6989
- if (key === "sfc" /* SFC */) {
6990
- return this.fileProcessor.processFile(key, filePath, existingCache);
6991
- } else if (key === "script" /* SCRIPT */) {
6992
- return this.fileProcessor.processFile(key, filePath, existingCache);
6993
- }
6994
- return this.fileProcessor.processFile(
6995
- key,
6996
- filePath,
6997
- existingCache
6998
- );
6999
- }
7000
- /**
7001
- * 处理单个资源文件
7002
- *
7003
- * 比较文件与缓存,决定是否需要拷贝。
7004
- * 资源文件包括图片、字体、样式文件等非编译文件。
7005
- *
7006
- * @async
7007
- * @param filePath - 资源文件的绝对路径
7008
- * @param existingCache - 可选的预加载缓存对象
7009
- * @returns {Promise<FileCacheMeta>} 资源文件的缓存元数据
7010
- * @see {@link AssetManager.processAsset}
7011
- */
7012
- async processAsset(filePath, existingCache) {
7013
- return this.assetManager.processAsset(filePath, existingCache);
7014
- }
7015
- /**
7016
- * 删除指定路径对应的输出文件和缓存
7017
- *
7018
- * 当源文件被删除或重命名时,需要清理对应的输出文件。
7019
- * 主要用于 watch 模式下的文件删除处理。
7020
- *
7021
- * @async
7022
- * @param targetPath - 源代码的路径(文件或文件夹)
7023
- * @param type - 清理类型,指定是 SFC、SCRIPT 还是 ASSET
7024
- * @returns {Promise<void>}
7025
- * @see {@link CleanupManager.removeOutputPath}
7026
- */
7027
- async removeOutputPath(targetPath, type) {
7028
- return this.cleanupManager.removeOutputPath(targetPath, type);
7029
- }
7030
- /**
7031
- * 获取跳过的文件数量
7032
- *
7033
- * 在增量编译中,未变更的文件会被跳过。
7034
- * 此方法返回当前编译会话中跳过的文件数量。
7035
- *
7036
- * @returns {number} 跳过的文件数量
7037
- */
7038
- getSkippedCount() {
7039
- return this.skippedCount;
7040
- }
7041
- /**
7042
- * 重置跳过的文件数量
7043
- *
7044
- * 在每次新的编译会话开始时调用,重置计数器。
7045
- */
7046
- resetSkippedCount() {
7047
- this.skippedCount = 0;
7048
- }
7049
- /**
7050
- * 显示编译统计信息
7051
- *
7052
- * 在编译完成后调用,显示以下信息:
7053
- * 1. 编译耗时
7054
- * 2. 输出目录
7055
- * 3. 跳过的文件数量
7056
- * 4. 处理的文件分类统计
7057
- *
7058
- * @private
7059
- * @param endTime - 格式化后的编译耗时字符串
7060
- * @param sfcCount - 处理的 Vue 文件数量
7061
- * @param scriptCount - 处理的脚本文件数量
7062
- * @param assetCount - 处理的资源文件数量
7063
- */
7064
7133
  showCompileStats(endTime, sfcCount, scriptCount, styleCount, assetCount) {
7065
- const dir = normalizePath(this.relativePath(this.getOuputPath()));
7066
7134
  this.spinner.succeed(`Build completed in ${endTime}`);
7067
- console.info(` Output directory: ${_kleur2.default.dim(dir)}`);
7068
7135
  console.info();
7069
- this.skippedCount += this.pipelineManager.getSkippedCount();
7070
- this.pipelineManager.resetSkippedCount();
7071
- if (this.skippedCount) {
7072
- console.info(_kleur2.default.dim(`Skipped ${this.skippedCount} unchanged file(s)`));
7073
- this.resetSkippedCount();
7074
- }
7075
7136
  if (sfcCount || scriptCount || styleCount || assetCount) {
7076
7137
  const stats = [];
7077
7138
  if (sfcCount) stats.push(`${sfcCount} SFC(s)`);
7078
7139
  if (scriptCount) stats.push(`${scriptCount} script(s)`);
7079
7140
  if (styleCount) stats.push(`${styleCount} style(s)`);
7080
7141
  if (assetCount) stats.push(`${assetCount} asset(s)`);
7081
- console.info(_kleur2.default.gray(`Processed ${stats.join(", ")}`));
7142
+ this.spinner.succeed(`Processed: ${stats.join(", ")}`);
7143
+ }
7144
+ const skippedCount = this.manager.pipelineManager.getSkippedCount() + this.manager.assetManager.getSkippedCount();
7145
+ if (skippedCount) {
7146
+ console.info(_kleur2.default.gray(`\u21B7 Cached: ${_kleur2.default.white(skippedCount)} unchanged file(s)`));
7147
+ this.resetSkippedCount();
7082
7148
  }
7149
+ const dir = normalizePath(this.relativePath(this.getOuputPath()));
7150
+ console.info();
7151
+ console.info(`\u{1F4E6} Output: ${dir}`);
7083
7152
  console.info();
7084
7153
  }
7085
- }, _class10);
7154
+ resetSkippedCount() {
7155
+ this.manager.pipelineManager.resetSkippedCount();
7156
+ this.manager.assetManager.resetSkippedCount();
7157
+ }
7158
+ }, _class11);
7086
7159
 
7087
7160
  // src/compiler/shared/define-config.ts
7088
- function defineConfig(options) {
7089
- return options;
7161
+ function defineConfig(config) {
7162
+ return typeof config === "function" ? config() : config;
7090
7163
  }
7091
7164
 
7092
7165
  // src/compiler/index.ts