@vureact/compiler-core 1.6.2 → 1.7.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
1
  /**
2
- * @vureact/compiler-core v1.6.2
2
+ * @vureact/compiler-core v1.7.0
3
3
  * (c) 2025-present Ruihong Zhong (Ryan John)
4
4
  * @license MIT
5
5
  */
@@ -1058,7 +1058,7 @@ function buildStandardProp(nodeIR) {
1058
1058
  babelExp: { ast: keyAST },
1059
1059
  value: {
1060
1060
  content,
1061
- isStringLiteral: isStringLiteral13,
1061
+ isStringLiteral: isStringLiteral14,
1062
1062
  babelExp: { ast: valueAST }
1063
1063
  }
1064
1064
  } = nodeIR;
@@ -1067,7 +1067,7 @@ function buildStandardProp(nodeIR) {
1067
1067
  }
1068
1068
  let value;
1069
1069
  if (content !== "true") {
1070
- value = isStringLiteral13 ? t9.stringLiteral(content) : buildJsxExpressionNode(valueAST);
1070
+ value = isStringLiteral14 ? t9.stringLiteral(content) : buildJsxExpressionNode(valueAST);
1071
1071
  }
1072
1072
  return t9.jsxAttribute(keyAST, value);
1073
1073
  }
@@ -2408,33 +2408,270 @@ function resolveContext(scriptSetup, ctx) {
2408
2408
  scriptSetup.content = content;
2409
2409
  }
2410
2410
 
2411
- // src/plugins/postcss.ts
2411
+ // src/plugins/postcss/index.ts
2412
2412
  import postcss from "postcss";
2413
+
2414
+ // src/plugins/postcss/deep.ts
2415
+ import selectorParser2 from "postcss-selector-parser";
2416
+
2417
+ // src/plugins/postcss/standard.ts
2418
+ import selectorParser from "postcss-selector-parser";
2419
+
2420
+ // src/plugins/postcss/utils.ts
2421
+ function findFirstPseudoIndex(nodes, start, end) {
2422
+ for (let i = start; i <= end; i++) {
2423
+ if (nodes[i]?.type === "pseudo") {
2424
+ return i;
2425
+ }
2426
+ }
2427
+ return end + 1;
2428
+ }
2429
+ function hasScopeAttribute(nodes, start, end, scopeId) {
2430
+ if (start > end) {
2431
+ return false;
2432
+ }
2433
+ for (let i = start; i <= end; i++) {
2434
+ const node = nodes[i];
2435
+ if (node?.type === "attribute" && node.attribute === scopeId) {
2436
+ return true;
2437
+ }
2438
+ }
2439
+ return false;
2440
+ }
2441
+ function hasNestingSelector(nodes, start, end) {
2442
+ if (start > end) {
2443
+ return false;
2444
+ }
2445
+ for (let i = start; i <= end; i++) {
2446
+ if (nodes[i]?.type === "nesting") {
2447
+ return true;
2448
+ }
2449
+ }
2450
+ return false;
2451
+ }
2452
+ function findScopeTargetIndex(nodes, start, end) {
2453
+ if (start > end) {
2454
+ return -1;
2455
+ }
2456
+ let candidate = -1;
2457
+ let nestingFallback = -1;
2458
+ for (let i = start; i <= end; i++) {
2459
+ const node = nodes[i];
2460
+ if (node?.type === "nesting") {
2461
+ nestingFallback = i;
2462
+ continue;
2463
+ }
2464
+ if (node?.type === "tag" || node?.type === "class" || node?.type === "id") {
2465
+ candidate = i;
2466
+ }
2467
+ }
2468
+ return candidate === -1 ? nestingFallback : candidate;
2469
+ }
2470
+ function isRuleIgnored(rule) {
2471
+ return rule.parent != null && rule.parent.type === "atrule" && rule.parent?.name === "keyframes";
2472
+ }
2473
+ function isNestedInRule(rule) {
2474
+ let current = rule.parent;
2475
+ while (current) {
2476
+ if (current.type === "rule") {
2477
+ return true;
2478
+ }
2479
+ current = current.parent;
2480
+ }
2481
+ return false;
2482
+ }
2483
+
2484
+ // src/plugins/postcss/standard.ts
2485
+ function resolveStandard(s, scopeId) {
2486
+ try {
2487
+ return selectorParser((selectors) => {
2488
+ selectors.each((selector) => {
2489
+ const compoundEnd = selector.nodes.length - 1;
2490
+ if (compoundEnd < 0) {
2491
+ return;
2492
+ }
2493
+ let compoundStart = 0;
2494
+ for (let i = compoundEnd; i >= 0; i--) {
2495
+ if (selector.nodes[i]?.type === "combinator") {
2496
+ compoundStart = i + 1;
2497
+ break;
2498
+ }
2499
+ }
2500
+ const firstPseudoIndex = findFirstPseudoIndex(selector.nodes, compoundStart, compoundEnd);
2501
+ if (hasNestingSelector(selector.nodes, compoundStart, firstPseudoIndex - 1)) {
2502
+ return;
2503
+ }
2504
+ if (hasScopeAttribute(selector.nodes, compoundStart, firstPseudoIndex - 1, scopeId)) {
2505
+ return;
2506
+ }
2507
+ const insertTargetIndex = findScopeTargetIndex(
2508
+ selector.nodes,
2509
+ compoundStart,
2510
+ firstPseudoIndex - 1
2511
+ );
2512
+ if (insertTargetIndex === -1) {
2513
+ return;
2514
+ }
2515
+ selector.insertAfter(
2516
+ selector.nodes[insertTargetIndex],
2517
+ selectorParser.attribute({
2518
+ attribute: scopeId,
2519
+ raws: {},
2520
+ value: void 0
2521
+ // 不加 = 值,等同于 [data-css-xxx]
2522
+ })
2523
+ );
2524
+ });
2525
+ }).processSync(s);
2526
+ } catch (e) {
2527
+ console.warn(e);
2528
+ return `${s}[${scopeId}]`;
2529
+ }
2530
+ }
2531
+
2532
+ // src/plugins/postcss/deep.ts
2533
+ function resolveDeep(s, scopeId, nestedInRule) {
2534
+ try {
2535
+ const root = selectorParser2().astSync(s);
2536
+ const resolvedSelectors = [];
2537
+ root.nodes.forEach((selector) => {
2538
+ const resolved = resolveSingleSelectorWithDeep(selector, scopeId, nestedInRule);
2539
+ resolvedSelectors.push(...resolved);
2540
+ });
2541
+ return resolvedSelectors.join(", ");
2542
+ } catch (e) {
2543
+ console.warn(e);
2544
+ return s.replace(/:deep\((.*)\)/g, "$1");
2545
+ }
2546
+ }
2547
+ function resolveSingleSelectorWithDeep(selector, scopeId, nestedInRule) {
2548
+ const deepIndex = findTopLevelDeepIndex(selector.nodes);
2549
+ if (deepIndex === -1) {
2550
+ return [resolveStandard(selector.toString(), scopeId)];
2551
+ }
2552
+ const deepNode = selector.nodes[deepIndex];
2553
+ if (deepNode?.type !== "pseudo") {
2554
+ return [resolveStandard(selector.toString(), scopeId)];
2555
+ }
2556
+ const leftRaw = selector.nodes.slice(0, deepIndex).map((node) => node.toString()).join("");
2557
+ const rightRaw = selector.nodes.slice(deepIndex + 1).map((node) => node.toString()).join("");
2558
+ const leftScoped = scopeDeepLeftSide(leftRaw, scopeId, nestedInRule);
2559
+ const deepInnerSelectors = deepNode.nodes?.length ? deepNode.nodes : [];
2560
+ if (!deepInnerSelectors.length) {
2561
+ return [leftScoped + rightRaw];
2562
+ }
2563
+ const results = [];
2564
+ for (const innerSelector of deepInnerSelectors) {
2565
+ const combined = joinDeepParts(leftScoped, innerSelector.toString().trim(), rightRaw);
2566
+ if (combined.includes(":deep(")) {
2567
+ results.push(resolveDeep(combined, scopeId, nestedInRule));
2568
+ continue;
2569
+ }
2570
+ results.push(combined);
2571
+ }
2572
+ return results;
2573
+ }
2574
+ function findTopLevelDeepIndex(nodes) {
2575
+ for (let i = 0; i < nodes.length; i++) {
2576
+ const node = nodes[i];
2577
+ if (node?.type === "pseudo" && (node.value === ":deep" || node.value === "::v-deep")) {
2578
+ return i;
2579
+ }
2580
+ }
2581
+ return -1;
2582
+ }
2583
+ function scopeDeepLeftSide(leftRaw, scopeId, nestedInRule) {
2584
+ if (!leftRaw.trim()) {
2585
+ return nestedInRule ? "&" : `[${scopeId}]`;
2586
+ }
2587
+ try {
2588
+ const root = selectorParser2().astSync(leftRaw);
2589
+ root.each((selector) => {
2590
+ injectScopeToRightMostCompound(selector, scopeId);
2591
+ });
2592
+ return root.toString();
2593
+ } catch (e) {
2594
+ console.warn(e);
2595
+ return resolveStandard(leftRaw, scopeId);
2596
+ }
2597
+ }
2598
+ function injectScopeToRightMostCompound(selector, scopeId) {
2599
+ const nodes = selector.nodes;
2600
+ if (!nodes.length) {
2601
+ return;
2602
+ }
2603
+ let compoundEnd = nodes.length - 1;
2604
+ while (compoundEnd >= 0 && nodes[compoundEnd]?.type === "combinator") {
2605
+ compoundEnd--;
2606
+ }
2607
+ if (compoundEnd < 0) {
2608
+ return;
2609
+ }
2610
+ let compoundStart = 0;
2611
+ for (let i = compoundEnd; i >= 0; i--) {
2612
+ if (nodes[i]?.type === "combinator") {
2613
+ compoundStart = i + 1;
2614
+ break;
2615
+ }
2616
+ }
2617
+ const firstPseudoIndex = findFirstPseudoIndex(nodes, compoundStart, compoundEnd);
2618
+ if (hasScopeAttribute(nodes, compoundStart, firstPseudoIndex - 1, scopeId)) {
2619
+ return;
2620
+ }
2621
+ const insertTargetIndex = findScopeTargetIndex(nodes, compoundStart, firstPseudoIndex - 1);
2622
+ if (insertTargetIndex === -1) {
2623
+ return;
2624
+ }
2625
+ const insertTarget = nodes[insertTargetIndex];
2626
+ insertTarget.spaces = {
2627
+ ...insertTarget.spaces,
2628
+ after: ""
2629
+ };
2630
+ selector.insertAfter(
2631
+ insertTarget,
2632
+ selectorParser2.attribute({
2633
+ attribute: scopeId,
2634
+ raws: {},
2635
+ value: void 0
2636
+ })
2637
+ );
2638
+ }
2639
+ function joinDeepParts(leftScoped, innerRaw, rightRaw) {
2640
+ if (!leftScoped) {
2641
+ return `${innerRaw}${rightRaw}`;
2642
+ }
2643
+ const needsGap = !/\s$/.test(leftScoped);
2644
+ const gap = needsGap ? " " : "";
2645
+ return `${leftScoped}${gap}${innerRaw}${rightRaw}`;
2646
+ }
2647
+
2648
+ // src/plugins/postcss/selector.ts
2649
+ function resolveSelector(s, scopeId, options) {
2650
+ if (s.includes(":global(")) {
2651
+ return s.replace(/:global\(([^)]+)\)/g, (_, inner) => inner);
2652
+ }
2653
+ if (s.includes(":deep(")) {
2654
+ return resolveDeep(s, scopeId, options?.nestedInRule ?? false);
2655
+ }
2656
+ if (s.includes(":slotted(")) {
2657
+ return s.replace(/:slotted\((.*)\)/, "$1");
2658
+ }
2659
+ return resolveStandard(s, scopeId);
2660
+ }
2661
+
2662
+ // src/plugins/postcss/index.ts
2413
2663
  function processScopedWithPostCss(input, hash) {
2414
2664
  const scopeId = `data-css-${hash}`;
2415
2665
  const result = postcss([
2416
2666
  {
2417
- postcssPlugin: "postcss-scoped-simple",
2667
+ postcssPlugin: "postcss-scoped-vureact",
2418
2668
  Rule(rule) {
2419
- if (rule.parent && rule.parent.type === "atrule" && rule.parent.name === "keyframes") {
2669
+ if (isRuleIgnored(rule)) {
2420
2670
  return;
2421
2671
  }
2422
- rule.selectors = rule.selectors.map((selector) => {
2423
- if (selector.includes(":global(")) {
2424
- return selector.replace(/:global\((.*)\)/, "$1");
2425
- }
2426
- if (selector.includes(":deep(")) {
2427
- return selector.replace(/:deep\((.*)\)/, "$1");
2428
- }
2429
- const pseudoElementRegex = /(::[a-zA-Z-]+)$/;
2430
- const match = selector.match(pseudoElementRegex);
2431
- if (match) {
2432
- const base = selector.replace(pseudoElementRegex, "");
2433
- const pseudo = match[1];
2434
- return `${base}[${scopeId}]${pseudo}`;
2435
- }
2436
- return `${selector}[${scopeId}]`;
2437
- });
2672
+ rule.selectors = rule.selectors.map(
2673
+ (selector) => resolveSelector(selector, scopeId, { nestedInRule: isNestedInRule(rule) })
2674
+ );
2438
2675
  }
2439
2676
  }
2440
2677
  ]).process(input);
@@ -3118,30 +3355,32 @@ function resolveEmitCalls(ctx) {
3118
3355
  };
3119
3356
  if (!checkIfFromDefineEmits()) return;
3120
3357
  const [callee, ...args] = node.arguments;
3121
- const eventName = t28.isStringLiteral(callee) ? formatEmitEventName(callee.value) : void 0;
3122
- if (!eventName) {
3123
- logger.warn(`Expected String type but got ${callee?.type}, expression will be removed`, {
3124
- file: filename,
3125
- source: scriptData.source,
3126
- loc: callee?.loc
3127
- });
3128
- path9.remove();
3129
- return;
3358
+ let propCall;
3359
+ if (t28.isStringLiteral(callee)) {
3360
+ const eventName = formatEmitEventName(callee.value);
3361
+ propCall = createPropCall(ctx.propField, t28.identifier(eventName), args);
3362
+ } else {
3363
+ propCall = createPropCall(ctx.propField, callee, args, true);
3364
+ logger.error(
3365
+ `Non-string event name cannot be converted to React onXxx style. The emit call will not work as expected.`,
3366
+ {
3367
+ file: filename,
3368
+ source: scriptData.source,
3369
+ loc: callee?.loc
3370
+ }
3371
+ );
3130
3372
  }
3131
- const propCall = t28.optionalCallExpression(
3132
- t28.optionalMemberExpression(
3133
- t28.identifier(ctx.propField),
3134
- t28.identifier(eventName),
3135
- false,
3136
- true
3137
- ),
3138
- args,
3139
- true
3140
- );
3141
3373
  replaceNode(path9, propCall, node);
3142
3374
  }
3143
3375
  };
3144
3376
  }
3377
+ function createPropCall(rootName, callee, args, computed = false) {
3378
+ return t28.optionalCallExpression(
3379
+ t28.memberExpression(t28.identifier(rootName), callee, computed),
3380
+ args,
3381
+ true
3382
+ );
3383
+ }
3145
3384
 
3146
3385
  // src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/index.ts
3147
3386
  import * as t36 from "@babel/types";
@@ -4154,20 +4393,249 @@ function createPropsTypeAssertion(propsIdentifier, typeAnnotation) {
4154
4393
  }
4155
4394
 
4156
4395
  // src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
4157
- import * as t39 from "@babel/types";
4396
+ import * as t43 from "@babel/types";
4158
4397
 
4159
- // src/core/transform/sfc/script/shared/dependency-analyzer.ts
4398
+ // src/core/transform/sfc/script/shared/dependency-analyzer/index.ts
4160
4399
  import { traverse as traverse2 } from "@babel/core";
4400
+ import * as t42 from "@babel/types";
4401
+
4402
+ // src/core/transform/sfc/script/shared/dependency-analyzer/binding-utils.ts
4403
+ function isBindingDeclaredInsideBoundary(binding, boundary) {
4404
+ let current = binding.path;
4405
+ while (current) {
4406
+ if (current.node === boundary) {
4407
+ return true;
4408
+ }
4409
+ current = current.parentPath;
4410
+ }
4411
+ return false;
4412
+ }
4413
+ function isReactiveBinding(node) {
4414
+ if (!node) return false;
4415
+ return !!getScriptNodeMeta(node)?.is_reactive;
4416
+ }
4417
+
4418
+ // src/core/transform/sfc/script/shared/dependency-analyzer/dep-checker.ts
4161
4419
  import * as t38 from "@babel/types";
4420
+ function isEligibleBindingSource(binding) {
4421
+ if (binding.kind === "param") {
4422
+ return false;
4423
+ }
4424
+ const reactiveStateApis = getReactiveStateApis();
4425
+ const bindingPath = binding.path;
4426
+ const declaratorPath = getVariableDeclaratorPath(bindingPath);
4427
+ const isReactiveVarBinding = !!declaratorPath && isReactiveBinding(declaratorPath.node);
4428
+ const nodeInit = declaratorPath?.node.init;
4429
+ const isReactiveApiCallVarBinding = !!declaratorPath && t38.isCallExpression(nodeInit) && t38.isIdentifier(nodeInit.callee) && reactiveStateApis.has(nodeInit.callee.name);
4430
+ const isHookCallVarBinding = !!declaratorPath && t38.isCallExpression(nodeInit) && isHookLikeCallee(nodeInit.callee);
4431
+ const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (t38.isArrowFunctionExpression(nodeInit) || t38.isFunctionExpression(nodeInit));
4432
+ const isReactiveFunctionBinding = isFunctionBinding && (isReactiveBinding(declaratorPath?.node) || isReactiveBinding(bindingPath.node));
4433
+ return isReactiveVarBinding || isReactiveApiCallVarBinding || isHookCallVarBinding || isReactiveFunctionBinding;
4434
+ }
4435
+ function isReactValidDependencyExpr(node) {
4436
+ if (t38.isIdentifier(node)) {
4437
+ return true;
4438
+ }
4439
+ if (t38.isMemberExpression(node) || t38.isOptionalMemberExpression(node)) {
4440
+ return isStaticMemberChain(node);
4441
+ }
4442
+ return false;
4443
+ }
4444
+ function isStaticMemberChain(node) {
4445
+ let current = node;
4446
+ while (t38.isMemberExpression(current) || t38.isOptionalMemberExpression(current)) {
4447
+ if (!current.computed && !t38.isIdentifier(current.property)) {
4448
+ return false;
4449
+ }
4450
+ if (current.computed && !t38.isStringLiteral(current.property) && !t38.isNumericLiteral(current.property)) {
4451
+ return false;
4452
+ }
4453
+ current = current.object;
4454
+ }
4455
+ return t38.isIdentifier(current);
4456
+ }
4457
+ function isHookLikeCallee(callee) {
4458
+ if (t38.isIdentifier(callee)) {
4459
+ return callee.name.startsWith("use");
4460
+ }
4461
+ if (t38.isMemberExpression(callee) && !callee.computed && t38.isIdentifier(callee.property)) {
4462
+ return callee.property.name.startsWith("use");
4463
+ }
4464
+ return false;
4465
+ }
4466
+
4467
+ // src/core/transform/sfc/script/shared/dependency-analyzer/dep-key.ts
4468
+ import * as t39 from "@babel/types";
4469
+ function getDependencyKey(exp) {
4470
+ if (t39.isIdentifier(exp)) {
4471
+ return exp.name;
4472
+ }
4473
+ if (t39.isMemberExpression(exp) || t39.isOptionalMemberExpression(exp)) {
4474
+ const objectKey = getDependencyKey(exp.object);
4475
+ const opt = exp.optional ? "?" : "";
4476
+ if (!exp.computed && t39.isIdentifier(exp.property)) {
4477
+ return `${objectKey}${opt}.${exp.property.name}`;
4478
+ }
4479
+ if (t39.isStringLiteral(exp.property) || t39.isNumericLiteral(exp.property)) {
4480
+ return `${objectKey}${opt}[${JSON.stringify(exp.property.value)}]`;
4481
+ }
4482
+ return `${objectKey}${opt}[*]`;
4483
+ }
4484
+ return exp.type;
4485
+ }
4486
+
4487
+ // src/core/transform/sfc/script/shared/dependency-analyzer/dep-normalizer.ts
4488
+ import * as t40 from "@babel/types";
4489
+ function normalizeDependencyExpr(path9, rootName, ctx) {
4490
+ if (t40.isIdentifier(path9.node)) {
4491
+ return t40.identifier(path9.node.name);
4492
+ }
4493
+ if (t40.isMemberExpression(path9.node) || t40.isOptionalMemberExpression(path9.node)) {
4494
+ if (rootName === ctx.propField) {
4495
+ const safePropsExp = ensureOptionalForMemberChain(path9.node);
4496
+ if (isReactValidDependencyExpr(safePropsExp)) {
4497
+ return t40.cloneNode(safePropsExp, true);
4498
+ }
4499
+ return t40.identifier(rootName);
4500
+ }
4501
+ const normalizedExp = normalizeMemberForCallSite(path9, path9.node);
4502
+ const safeExp = t40.isMemberExpression(normalizedExp) || t40.isOptionalMemberExpression(normalizedExp) ? ensureOptionalForMemberChain(normalizedExp) : normalizedExp;
4503
+ if (isReactValidDependencyExpr(safeExp)) {
4504
+ return t40.cloneNode(safeExp, true);
4505
+ }
4506
+ return t40.identifier(rootName);
4507
+ }
4508
+ return null;
4509
+ }
4510
+ function normalizeSourcedDependency(exp) {
4511
+ if (t40.isIdentifier(exp)) {
4512
+ return t40.identifier(exp.name);
4513
+ }
4514
+ if (t40.isMemberExpression(exp) || t40.isOptionalMemberExpression(exp)) {
4515
+ const root = findRootIdentifier(exp);
4516
+ if (!root) return null;
4517
+ const safeExp = t40.isMemberExpression(exp) || t40.isOptionalMemberExpression(exp) ? ensureOptionalForMemberChain(exp) : exp;
4518
+ if (isReactValidDependencyExpr(safeExp)) {
4519
+ return t40.cloneNode(safeExp, true);
4520
+ }
4521
+ return t40.identifier(root.name);
4522
+ }
4523
+ return null;
4524
+ }
4525
+ function normalizeMemberForCallSite(path9, node) {
4526
+ const parent = path9.parentPath;
4527
+ const isDirectCallee = !!parent && (parent.isCallExpression() && parent.node.callee === node || parent.isOptionalCallExpression() && parent.node.callee === node);
4528
+ if (!isDirectCallee) {
4529
+ return node;
4530
+ }
4531
+ if (!t40.isExpression(node.object)) {
4532
+ return node;
4533
+ }
4534
+ return node.object;
4535
+ }
4536
+ function ensureOptionalForMemberChain(node) {
4537
+ if (!hasTrailingMemberAccess(node)) {
4538
+ return node;
4539
+ }
4540
+ if (t40.isOptionalMemberExpression(node) && node.optional) {
4541
+ return node;
4542
+ }
4543
+ const object = t40.cloneNode(node.object, true);
4544
+ const property = t40.cloneNode(node.property, true);
4545
+ return t40.optionalMemberExpression(object, property, node.computed, true);
4546
+ }
4547
+ function hasTrailingMemberAccess(node) {
4548
+ return t40.isMemberExpression(node.object) || t40.isOptionalMemberExpression(node.object);
4549
+ }
4550
+
4551
+ // src/core/transform/sfc/script/shared/dependency-analyzer/shared-utils.ts
4162
4552
  var TRACE_MAX_DEPTH = 20;
4553
+ function isNestedMemberObject(path9) {
4554
+ const parent = path9.parentPath;
4555
+ if (!parent) return false;
4556
+ if (parent.isMemberExpression() || parent.isOptionalMemberExpression()) {
4557
+ return parent.node.object === path9.node;
4558
+ }
4559
+ return false;
4560
+ }
4561
+
4562
+ // src/core/transform/sfc/script/shared/dependency-analyzer/trace-utils.ts
4563
+ import * as t41 from "@babel/types";
4564
+ function traceBindingSource(binding, seen, depth) {
4565
+ if (depth <= 0) return null;
4566
+ const declaratorPath = getVariableDeclaratorPath(binding.path);
4567
+ if (!declaratorPath || !declaratorPath.node.init) return null;
4568
+ if (seen.has(declaratorPath.node)) return null;
4569
+ seen.add(declaratorPath.node);
4570
+ const { init } = declaratorPath.node;
4571
+ return isExpressionSourcedFromEligibleBinding(init, declaratorPath.scope, seen, depth - 1);
4572
+ }
4573
+ function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
4574
+ if (depth <= 0) return null;
4575
+ if (t41.isIdentifier(exp)) {
4576
+ const sourceBinding = scope.getBinding(exp.name);
4577
+ if (!sourceBinding) return null;
4578
+ if (isEligibleBindingSource(sourceBinding)) {
4579
+ return exp;
4580
+ }
4581
+ return traceBindingSource(sourceBinding, seen, depth - 1);
4582
+ }
4583
+ if (t41.isMemberExpression(exp) || t41.isOptionalMemberExpression(exp)) {
4584
+ const root = findRootIdentifier(exp);
4585
+ if (!root) return null;
4586
+ const sourceBinding = scope.getBinding(root.name);
4587
+ if (!sourceBinding) return null;
4588
+ if (isEligibleBindingSource(sourceBinding)) {
4589
+ return t41.cloneNode(exp);
4590
+ }
4591
+ const sourcedRoot = traceBindingSource(sourceBinding, seen, depth - 1);
4592
+ if (sourcedRoot) {
4593
+ const rebuilt = rebuildMemberWithNewRoot(exp, sourcedRoot);
4594
+ if (rebuilt) {
4595
+ return rebuilt;
4596
+ }
4597
+ return t41.cloneNode(sourcedRoot, true);
4598
+ }
4599
+ }
4600
+ return null;
4601
+ }
4602
+ function rebuildMemberWithNewRoot(node, nextRoot) {
4603
+ const replacedObject = (() => {
4604
+ if (t41.isIdentifier(node.object)) {
4605
+ return t41.cloneNode(nextRoot, true);
4606
+ }
4607
+ if (t41.isMemberExpression(node.object) || t41.isOptionalMemberExpression(node.object)) {
4608
+ return rebuildMemberWithNewRoot(node.object, nextRoot);
4609
+ }
4610
+ return null;
4611
+ })();
4612
+ if (!replacedObject) {
4613
+ return null;
4614
+ }
4615
+ const property = t41.cloneNode(node.property, true);
4616
+ if (t41.isMemberExpression(node)) {
4617
+ return t41.memberExpression(
4618
+ replacedObject,
4619
+ property,
4620
+ node.computed
4621
+ );
4622
+ }
4623
+ return t41.optionalMemberExpression(
4624
+ replacedObject,
4625
+ property,
4626
+ node.computed,
4627
+ node.optional
4628
+ );
4629
+ }
4630
+
4631
+ // src/core/transform/sfc/script/shared/dependency-analyzer/index.ts
4163
4632
  function analyzeDeps(node, ctx, parentPath) {
4164
4633
  if (!parentPath) {
4165
- return t38.arrayExpression([]);
4634
+ return t42.arrayExpression([]);
4166
4635
  }
4167
- const isFnExpr = t38.isArrowFunctionExpression(node) || t38.isFunctionExpression(node);
4636
+ const isFnExpr = t42.isArrowFunctionExpression(node) || t42.isFunctionExpression(node);
4168
4637
  const analyzeTarget = isFnExpr ? node.body : node;
4169
4638
  const bindingLocalBoundary = isFnExpr ? node : analyzeTarget;
4170
- const reactiveStateApis = getReactiveStateApis();
4171
4639
  const deps = /* @__PURE__ */ new Map();
4172
4640
  const processedIdentifiers = /* @__PURE__ */ new WeakSet();
4173
4641
  function addDependency(exp) {
@@ -4175,13 +4643,13 @@ function analyzeDeps(node, ctx, parentPath) {
4175
4643
  }
4176
4644
  const analyzeTargetPath = parentPath && parentPath.node === analyzeTarget ? parentPath : null;
4177
4645
  if (analyzeTargetPath) {
4178
- if (t38.isMemberExpression(analyzeTarget) || t38.isOptionalMemberExpression(analyzeTarget)) {
4646
+ if (t42.isMemberExpression(analyzeTarget) || t42.isOptionalMemberExpression(analyzeTarget)) {
4179
4647
  const rootId = findRootIdentifier(analyzeTarget);
4180
4648
  if (rootId) {
4181
4649
  tryAddDependency(analyzeTargetPath, rootId.name, analyzeTargetPath.scope);
4182
4650
  processedIdentifiers.add(rootId);
4183
4651
  }
4184
- } else if (t38.isIdentifier(analyzeTarget)) {
4652
+ } else if (t42.isIdentifier(analyzeTarget)) {
4185
4653
  tryAddDependency(analyzeTargetPath, analyzeTarget.name, analyzeTargetPath.scope);
4186
4654
  }
4187
4655
  }
@@ -4207,17 +4675,19 @@ function analyzeDeps(node, ctx, parentPath) {
4207
4675
  parentPath.scope
4208
4676
  );
4209
4677
  function tryAddDependency(depPath, rootName, scope) {
4210
- const normalized = normalizeDependencyExpr(depPath, rootName);
4678
+ const normalized = normalizeDependencyExpr(depPath, rootName, ctx);
4211
4679
  if (!normalized) return;
4212
- const binding = scope.getBinding(rootName);
4213
- if (!binding) return;
4214
- const isLocalBinding = isBindingDeclaredInsideBoundary(binding, bindingLocalBoundary);
4215
4680
  if (rootName === ctx.propField) {
4216
- if (!isLocalBinding) {
4681
+ const propsBinding = scope.getBinding(rootName);
4682
+ const isLocalPropsBinding = !!propsBinding && isBindingDeclaredInsideBoundary(propsBinding, bindingLocalBoundary);
4683
+ if (!isLocalPropsBinding) {
4217
4684
  addDependency(normalized);
4218
4685
  }
4219
4686
  return;
4220
4687
  }
4688
+ const binding = scope.getBinding(rootName);
4689
+ if (!binding) return;
4690
+ const isLocalBinding = isBindingDeclaredInsideBoundary(binding, bindingLocalBoundary);
4221
4691
  const directEligible = !isLocalBinding && isEligibleBindingSource(binding);
4222
4692
  if (directEligible) {
4223
4693
  addDependency(normalized);
@@ -4231,211 +4701,7 @@ function analyzeDeps(node, ctx, parentPath) {
4231
4701
  }
4232
4702
  }
4233
4703
  }
4234
- function normalizeDependencyExpr(path9, rootName) {
4235
- if (t38.isIdentifier(path9.node)) {
4236
- return t38.identifier(path9.node.name);
4237
- }
4238
- if (t38.isMemberExpression(path9.node) || t38.isOptionalMemberExpression(path9.node)) {
4239
- const normalizedExp = normalizeMemberForCallSite(path9, path9.node);
4240
- const safeExp = t38.isMemberExpression(normalizedExp) || t38.isOptionalMemberExpression(normalizedExp) ? ensureOptionalForMemberChain(normalizedExp) : normalizedExp;
4241
- if (isReactValidDependencyExpr(safeExp)) {
4242
- return t38.cloneNode(safeExp, true);
4243
- }
4244
- return t38.identifier(rootName);
4245
- }
4246
- return null;
4247
- }
4248
- function normalizeSourcedDependency(exp) {
4249
- if (t38.isIdentifier(exp)) {
4250
- return t38.identifier(exp.name);
4251
- }
4252
- if (t38.isMemberExpression(exp) || t38.isOptionalMemberExpression(exp)) {
4253
- const root = findRootIdentifier(exp);
4254
- if (!root) return null;
4255
- const safeExp = t38.isMemberExpression(exp) || t38.isOptionalMemberExpression(exp) ? ensureOptionalForMemberChain(exp) : exp;
4256
- if (isReactValidDependencyExpr(safeExp)) {
4257
- return t38.cloneNode(safeExp, true);
4258
- }
4259
- return t38.identifier(root.name);
4260
- }
4261
- return null;
4262
- }
4263
- function isReactValidDependencyExpr(node2) {
4264
- if (t38.isIdentifier(node2)) {
4265
- return true;
4266
- }
4267
- if (t38.isMemberExpression(node2) || t38.isOptionalMemberExpression(node2)) {
4268
- return isStaticMemberChain(node2);
4269
- }
4270
- return false;
4271
- }
4272
- function isStaticMemberChain(node2) {
4273
- let current = node2;
4274
- while (t38.isMemberExpression(current) || t38.isOptionalMemberExpression(current)) {
4275
- if (!current.computed && !t38.isIdentifier(current.property)) {
4276
- return false;
4277
- }
4278
- if (current.computed && !t38.isStringLiteral(current.property) && !t38.isNumericLiteral(current.property)) {
4279
- return false;
4280
- }
4281
- current = current.object;
4282
- }
4283
- return t38.isIdentifier(current);
4284
- }
4285
- function isBindingDeclaredInsideBoundary(binding, boundary) {
4286
- let current = binding.path;
4287
- while (current) {
4288
- if (current.node === boundary) {
4289
- return true;
4290
- }
4291
- current = current.parentPath;
4292
- }
4293
- return false;
4294
- }
4295
- function normalizeMemberForCallSite(path9, node2) {
4296
- const parent = path9.parentPath;
4297
- const isDirectCallee = !!parent && (parent.isCallExpression() && parent.node.callee === node2 || parent.isOptionalCallExpression() && parent.node.callee === node2);
4298
- if (!isDirectCallee) {
4299
- return node2;
4300
- }
4301
- if (!t38.isExpression(node2.object)) {
4302
- return node2;
4303
- }
4304
- return node2.object;
4305
- }
4306
- function ensureOptionalForMemberChain(node2) {
4307
- if (!hasTrailingMemberAccess(node2)) {
4308
- return node2;
4309
- }
4310
- if (t38.isOptionalMemberExpression(node2) && node2.optional) {
4311
- return node2;
4312
- }
4313
- const object = t38.cloneNode(node2.object, true);
4314
- const property = t38.cloneNode(node2.property, true);
4315
- return t38.optionalMemberExpression(object, property, node2.computed, true);
4316
- }
4317
- function hasTrailingMemberAccess(node2) {
4318
- return t38.isMemberExpression(node2.object) || t38.isOptionalMemberExpression(node2.object);
4319
- }
4320
- function isEligibleBindingSource(binding) {
4321
- if (binding.kind === "param") {
4322
- return false;
4323
- }
4324
- const bindingPath = binding.path;
4325
- const declaratorPath = getVariableDeclaratorPath(bindingPath);
4326
- const isReactiveVarBinding = !!declaratorPath && isReactiveBinding(declaratorPath.node);
4327
- const nodeInit = declaratorPath?.node.init;
4328
- const isReactiveApiCallVarBinding = !!declaratorPath && t38.isCallExpression(nodeInit) && t38.isIdentifier(nodeInit.callee) && reactiveStateApis.has(nodeInit.callee.name);
4329
- const isHookCallVarBinding = !!declaratorPath && t38.isCallExpression(nodeInit) && isHookLikeCallee(nodeInit.callee);
4330
- const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (t38.isArrowFunctionExpression(nodeInit) || t38.isFunctionExpression(nodeInit));
4331
- const isReactiveFunctionBinding = isFunctionBinding && (isReactiveBinding(declaratorPath?.node) || isReactiveBinding(bindingPath.node));
4332
- return isReactiveVarBinding || isReactiveApiCallVarBinding || isHookCallVarBinding || isReactiveFunctionBinding;
4333
- }
4334
- function isHookLikeCallee(callee) {
4335
- if (t38.isIdentifier(callee)) {
4336
- return callee.name.startsWith("use");
4337
- }
4338
- if (t38.isMemberExpression(callee) && !callee.computed && t38.isIdentifier(callee.property)) {
4339
- return callee.property.name.startsWith("use");
4340
- }
4341
- return false;
4342
- }
4343
- function traceBindingSource(binding, seen, depth) {
4344
- if (depth <= 0) return null;
4345
- const declaratorPath = getVariableDeclaratorPath(binding.path);
4346
- if (!declaratorPath || !declaratorPath.node.init) return null;
4347
- if (seen.has(declaratorPath.node)) return null;
4348
- seen.add(declaratorPath.node);
4349
- const { init } = declaratorPath.node;
4350
- return isExpressionSourcedFromEligibleBinding(init, declaratorPath.scope, seen, depth - 1);
4351
- }
4352
- function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
4353
- if (depth <= 0) return null;
4354
- if (t38.isIdentifier(exp)) {
4355
- const sourceBinding = scope.getBinding(exp.name);
4356
- if (!sourceBinding) return null;
4357
- if (isEligibleBindingSource(sourceBinding)) {
4358
- return exp;
4359
- }
4360
- return traceBindingSource(sourceBinding, seen, depth - 1);
4361
- }
4362
- if (t38.isMemberExpression(exp) || t38.isOptionalMemberExpression(exp)) {
4363
- const root = findRootIdentifier(exp);
4364
- if (!root) return null;
4365
- const sourceBinding = scope.getBinding(root.name);
4366
- if (!sourceBinding) return null;
4367
- if (isEligibleBindingSource(sourceBinding)) {
4368
- return t38.cloneNode(exp);
4369
- }
4370
- const sourcedRoot = traceBindingSource(sourceBinding, seen, depth - 1);
4371
- if (sourcedRoot) {
4372
- const rebuilt = rebuildMemberWithNewRoot(exp, sourcedRoot);
4373
- if (rebuilt) {
4374
- return rebuilt;
4375
- }
4376
- return t38.cloneNode(sourcedRoot, true);
4377
- }
4378
- }
4379
- return null;
4380
- }
4381
- function rebuildMemberWithNewRoot(node2, nextRoot) {
4382
- const replacedObject = (() => {
4383
- if (t38.isIdentifier(node2.object)) {
4384
- return t38.cloneNode(nextRoot, true);
4385
- }
4386
- if (t38.isMemberExpression(node2.object) || t38.isOptionalMemberExpression(node2.object)) {
4387
- return rebuildMemberWithNewRoot(node2.object, nextRoot);
4388
- }
4389
- return null;
4390
- })();
4391
- if (!replacedObject) {
4392
- return null;
4393
- }
4394
- const property = t38.cloneNode(node2.property, true);
4395
- if (t38.isMemberExpression(node2)) {
4396
- return t38.memberExpression(
4397
- replacedObject,
4398
- property,
4399
- node2.computed
4400
- );
4401
- }
4402
- return t38.optionalMemberExpression(
4403
- replacedObject,
4404
- property,
4405
- node2.computed,
4406
- node2.optional
4407
- );
4408
- }
4409
- return t38.arrayExpression(Array.from(deps.values()));
4410
- }
4411
- function getDependencyKey(exp) {
4412
- if (t38.isIdentifier(exp)) {
4413
- return exp.name;
4414
- }
4415
- if (t38.isMemberExpression(exp) || t38.isOptionalMemberExpression(exp)) {
4416
- const objectKey = getDependencyKey(exp.object);
4417
- const opt = exp.optional ? "?" : "";
4418
- if (!exp.computed && t38.isIdentifier(exp.property)) {
4419
- return `${objectKey}${opt}.${exp.property.name}`;
4420
- }
4421
- if (t38.isStringLiteral(exp.property) || t38.isNumericLiteral(exp.property)) {
4422
- return `${objectKey}${opt}[${JSON.stringify(exp.property.value)}]`;
4423
- }
4424
- return `${objectKey}${opt}[*]`;
4425
- }
4426
- return exp.type;
4427
- }
4428
- function isNestedMemberObject(path9) {
4429
- const parent = path9.parentPath;
4430
- if (!parent) return false;
4431
- if (parent.isMemberExpression() || parent.isOptionalMemberExpression()) {
4432
- return parent.node.object === path9.node;
4433
- }
4434
- return false;
4435
- }
4436
- function isReactiveBinding(node) {
4437
- if (!node) return false;
4438
- return !!getScriptNodeMeta(node)?.is_reactive;
4704
+ return t42.arrayExpression(Array.from(deps.values()));
4439
4705
  }
4440
4706
 
4441
4707
  // src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
@@ -4451,7 +4717,7 @@ function resolveAnalysisOnlyAdapter(ctx) {
4451
4717
  if (!isVueApiReference(path9, apiName)) {
4452
4718
  return;
4453
4719
  }
4454
- if (t39.isCallExpression(node)) {
4720
+ if (t43.isCallExpression(node)) {
4455
4721
  resolveCallNode(path9, adapter, ctx);
4456
4722
  } else {
4457
4723
  replaceIdName(node, adapter.target);
@@ -4461,11 +4727,11 @@ function resolveAnalysisOnlyAdapter(ctx) {
4461
4727
  };
4462
4728
  }
4463
4729
  function getApiName(node) {
4464
- const isCallNode = t39.isCallExpression(node);
4730
+ const isCallNode = t43.isCallExpression(node);
4465
4731
  let apiName = "";
4466
- if (t39.isIdentifier(node)) {
4732
+ if (t43.isIdentifier(node)) {
4467
4733
  apiName = node.name;
4468
- } else if (isCallNode && t39.isIdentifier(node.callee)) {
4734
+ } else if (isCallNode && t43.isIdentifier(node.callee)) {
4469
4735
  apiName = node.callee.name;
4470
4736
  }
4471
4737
  return apiName;
@@ -4475,7 +4741,7 @@ function resolveCallNode(path9, adapter, ctx) {
4475
4741
  const { arguments: args } = node;
4476
4742
  if (!args.length) return;
4477
4743
  const fn = args[0];
4478
- if (!t39.isArrowFunctionExpression(fn) && !t39.isFunctionExpression(fn)) {
4744
+ if (!t43.isArrowFunctionExpression(fn) && !t43.isFunctionExpression(fn)) {
4479
4745
  return;
4480
4746
  }
4481
4747
  const fnPath = path9.get("arguments")[0];
@@ -4507,7 +4773,7 @@ function isVueImportBinding(binding) {
4507
4773
  return false;
4508
4774
  }
4509
4775
  const parent = bindingPath.parentPath?.node;
4510
- if (!parent || !t39.isImportDeclaration(parent)) {
4776
+ if (!parent || !t43.isImportDeclaration(parent)) {
4511
4777
  return false;
4512
4778
  }
4513
4779
  const source = parent.source.value.toLowerCase();
@@ -4575,7 +4841,7 @@ function isSkip(path9) {
4575
4841
  }
4576
4842
 
4577
4843
  // src/core/transform/sfc/script/syntax-processor/process/resolve-element-ref.ts
4578
- import * as t40 from "@babel/types";
4844
+ import * as t44 from "@babel/types";
4579
4845
  function resolveElementRef(ctx) {
4580
4846
  return {
4581
4847
  CallExpression(path9) {
@@ -4593,14 +4859,14 @@ function resolveElementRef(ctx) {
4593
4859
  }
4594
4860
  if (isCompRefBindings) {
4595
4861
  const varDeclaratorPath = getVariableDeclaratorPath(path9)?.node;
4596
- if (!t40.isIdentifier(varDeclaratorPath?.id)) {
4862
+ if (!t44.isIdentifier(varDeclaratorPath?.id)) {
4597
4863
  return;
4598
4864
  }
4599
4865
  const varName = varDeclaratorPath.id.name;
4600
4866
  const compRef = refBindings.componentRefs[varName];
4601
4867
  if (!compRef) return;
4602
4868
  }
4603
- node.arguments[0] = t40.identifier("null");
4869
+ node.arguments[0] = t44.identifier("null");
4604
4870
  resolveTypeParameters(ctx, path9);
4605
4871
  replaceCallName(node, REACT_API_MAP.useRef);
4606
4872
  recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useRef);
@@ -4625,27 +4891,27 @@ function resolveTypeParameters(ctx, path9) {
4625
4891
  const compBindingMeta = refBindings.componentRefs[idName];
4626
4892
  if (!node.typeParameters && (domBindingMeta || compBindingMeta)) {
4627
4893
  const type = compBindingMeta ? "any" : domBindingMeta.htmlType;
4628
- node.typeParameters = t40.tsTypeParameterInstantiation([t40.tsTypeReference(t40.identifier(type))]);
4894
+ node.typeParameters = t44.tsTypeParameterInstantiation([t44.tsTypeReference(t44.identifier(type))]);
4629
4895
  }
4630
4896
  }
4631
4897
  function resolveRefValueToCurrent(path9) {
4632
4898
  const { node } = path9;
4633
- if (node.computed || !t40.isIdentifier(node.property) || node.property.name !== "value") {
4899
+ if (node.computed || !t44.isIdentifier(node.property) || node.property.name !== "value") {
4634
4900
  return;
4635
4901
  }
4636
4902
  const rootPath = findRootVariablePath(path9);
4637
- if (!rootPath?.node || !t40.isCallExpression(rootPath.node.init) || !isCalleeNamed(rootPath.node.init, REACT_API_MAP.useRef)) {
4903
+ if (!rootPath?.node || !t44.isCallExpression(rootPath.node.init) || !isCalleeNamed(rootPath.node.init, REACT_API_MAP.useRef)) {
4638
4904
  return;
4639
4905
  }
4640
4906
  const rootId = findRootIdentifier(node);
4641
- if (!t40.isIdentifier(node.object) || node.object.name !== rootId?.name) {
4907
+ if (!t44.isIdentifier(node.object) || node.object.name !== rootId?.name) {
4642
4908
  return;
4643
4909
  }
4644
4910
  node.property.name = "current";
4645
4911
  }
4646
4912
 
4647
4913
  // src/core/transform/sfc/script/syntax-processor/process/resolve-expression-memo.ts
4648
- import * as t41 from "@babel/types";
4914
+ import * as t45 from "@babel/types";
4649
4915
  function resolveExprMemo(ctx, ast) {
4650
4916
  const isScriptFile = ctx.inputType !== "sfc";
4651
4917
  return {
@@ -4657,11 +4923,11 @@ function resolveExprMemo(ctx, ast) {
4657
4923
  if (!atComponentOrHookRoot(path9, ast.program, isScriptFile)) {
4658
4924
  return false;
4659
4925
  }
4660
- if (!t41.isVariableDeclaration(path9.parent) || path9.parent.kind !== "const") {
4926
+ if (!t45.isVariableDeclaration(path9.parent) || path9.parent.kind !== "const") {
4661
4927
  return false;
4662
4928
  }
4663
- if (t41.isFunction(init)) return false;
4664
- if (t41.isCallExpression(init) && t41.isIdentifier(init.callee) && init.callee.name.startsWith("use")) {
4929
+ if (t45.isFunction(init)) return false;
4930
+ if (t45.isCallExpression(init) && t45.isIdentifier(init.callee) && init.callee.name.startsWith("use")) {
4665
4931
  return false;
4666
4932
  }
4667
4933
  return true;
@@ -4674,21 +4940,22 @@ function resolveExprMemo(ctx, ast) {
4674
4940
  const useMemoCall = createUseMemo(initPath.node, deps);
4675
4941
  initPath.replaceWith(useMemoCall);
4676
4942
  setScriptNodeMeta(node, { is_reactive: true, reactive_type: "indirect" });
4943
+ recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useMemo);
4677
4944
  }
4678
4945
  };
4679
4946
  }
4680
4947
 
4681
4948
  // src/core/transform/sfc/script/syntax-processor/process/resolve-lint-rules.ts
4682
- import * as t42 from "@babel/types";
4949
+ import * as t46 from "@babel/types";
4683
4950
  function resolveLintRules(ctx, ast) {
4684
4951
  const inScriptFile = ctx.inputType !== "sfc";
4685
4952
  return {
4686
4953
  CallExpression(path9) {
4687
4954
  const { node, parentPath } = path9;
4688
- if (!t42.isIdentifier(node.callee)) return;
4955
+ if (!t46.isIdentifier(node.callee)) return;
4689
4956
  const { name: callName } = node.callee;
4690
- const addLog = (t48) => {
4691
- logger.error(t48, {
4957
+ const addLog = (t52) => {
4958
+ logger.error(t52, {
4692
4959
  file: ctx.filename,
4693
4960
  source: ctx.scriptData.source,
4694
4961
  loc: node.loc
@@ -4733,7 +5000,7 @@ function resolveLintRules(ctx, ast) {
4733
5000
 
4734
5001
  // src/core/transform/sfc/script/syntax-processor/process/resolve-provide.ts
4735
5002
  import { generate as generate2 } from "@babel/generator";
4736
- import * as t43 from "@babel/types";
5003
+ import * as t47 from "@babel/types";
4737
5004
  function resolveProvide(ctx) {
4738
5005
  if (ctx.inputType === "style") return {};
4739
5006
  return {
@@ -4765,13 +5032,13 @@ function findOrCreateCtxProvider(root) {
4765
5032
  function assignProviderValue(target, key, value) {
4766
5033
  const getRawExp = (exp) => {
4767
5034
  if (!exp) return "''";
4768
- if (t43.isStringLiteral(exp)) {
5035
+ if (t47.isStringLiteral(exp)) {
4769
5036
  return JSON.stringify(exp.value);
4770
5037
  }
4771
- if (t43.isNumericLiteral(exp)) {
5038
+ if (t47.isNumericLiteral(exp)) {
4772
5039
  return exp.value.toString();
4773
5040
  }
4774
- if (t43.isIdentifier(exp)) {
5041
+ if (t47.isIdentifier(exp)) {
4775
5042
  return exp.name;
4776
5043
  }
4777
5044
  try {
@@ -4787,16 +5054,16 @@ function assignProviderValue(target, key, value) {
4787
5054
  }
4788
5055
 
4789
5056
  // src/core/transform/sfc/script/syntax-processor/process/resolve-rename-adapter.ts
4790
- import * as t44 from "@babel/types";
5057
+ import * as t48 from "@babel/types";
4791
5058
  function resolveRenameAdapter(ctx) {
4792
5059
  return {
4793
5060
  "CallExpression|Identifier"(path9) {
4794
5061
  const node = path9.node;
4795
- const isCallNode = t44.isCallExpression(node);
5062
+ const isCallNode = t48.isCallExpression(node);
4796
5063
  let apiName = "";
4797
- if (t44.isIdentifier(node)) {
5064
+ if (t48.isIdentifier(node)) {
4798
5065
  apiName = node.name;
4799
- } else if (isCallNode && t44.isIdentifier(node.callee)) {
5066
+ } else if (isCallNode && t48.isIdentifier(node.callee)) {
4800
5067
  apiName = node.callee.name;
4801
5068
  }
4802
5069
  if (!apiName) {
@@ -4858,7 +5125,7 @@ function isVueImportBinding2(binding) {
4858
5125
  return false;
4859
5126
  }
4860
5127
  const parent = bindingPath.parentPath?.node;
4861
- if (!parent || !t44.isImportDeclaration(parent)) {
5128
+ if (!parent || !t48.isImportDeclaration(parent)) {
4862
5129
  return false;
4863
5130
  }
4864
5131
  const source = parent.source.value.toLowerCase();
@@ -4995,15 +5262,15 @@ function isRouterLinkBooleanCustomProp(prop) {
4995
5262
  }
4996
5263
 
4997
5264
  // src/core/transform/sfc/template/shared/prop-ir-utils.ts
4998
- import * as t46 from "@babel/types";
5265
+ import * as t50 from "@babel/types";
4999
5266
 
5000
5267
  // src/shared/string-code-types.ts
5001
5268
  import { parseExpression as parseExpression3 } from "@babel/parser";
5002
- import * as t45 from "@babel/types";
5269
+ import * as t49 from "@babel/types";
5003
5270
  var strCodeTypes = {
5004
- isIdentifier: isIdentifier24,
5271
+ isIdentifier: isIdentifier28,
5005
5272
  isSimpleExpression,
5006
- isStringLiteral: isStringLiteral12
5273
+ isStringLiteral: isStringLiteral13
5007
5274
  };
5008
5275
  function isSimpleExpression(code, excludeVar = false) {
5009
5276
  let node;
@@ -5012,38 +5279,38 @@ function isSimpleExpression(code, excludeVar = false) {
5012
5279
  } catch {
5013
5280
  return false;
5014
5281
  }
5015
- if (t45.isLiteral(node)) {
5282
+ if (t49.isLiteral(node)) {
5016
5283
  return true;
5017
5284
  }
5018
- if (!excludeVar && t45.isIdentifier(node)) {
5285
+ if (!excludeVar && t49.isIdentifier(node)) {
5019
5286
  return true;
5020
5287
  }
5021
- if (t45.isMemberExpression(node)) {
5022
- return isSimpleExpression(node.object) && t45.isIdentifier(node.property);
5288
+ if (t49.isMemberExpression(node)) {
5289
+ return isSimpleExpression(node.object) && t49.isIdentifier(node.property);
5023
5290
  }
5024
- if (t45.isObjectExpression(node) || t45.isArrayExpression(node)) {
5291
+ if (t49.isObjectExpression(node) || t49.isArrayExpression(node)) {
5025
5292
  return false;
5026
5293
  }
5027
- if (t45.isCallExpression(node) || t45.isAssignmentExpression(node)) {
5294
+ if (t49.isCallExpression(node) || t49.isAssignmentExpression(node)) {
5028
5295
  return false;
5029
5296
  }
5030
- if (t45.isBinaryExpression(node) || t45.isUnaryExpression(node)) {
5297
+ if (t49.isBinaryExpression(node) || t49.isUnaryExpression(node)) {
5031
5298
  return true;
5032
5299
  }
5033
5300
  return false;
5034
5301
  }
5035
- function isIdentifier24(code) {
5302
+ function isIdentifier28(code) {
5036
5303
  try {
5037
5304
  const node = parseExpression3(code);
5038
- return t45.isIdentifier(node);
5305
+ return t49.isIdentifier(node);
5039
5306
  } catch {
5040
5307
  return false;
5041
5308
  }
5042
5309
  }
5043
- function isStringLiteral12(code) {
5310
+ function isStringLiteral13(code) {
5044
5311
  try {
5045
5312
  const node = parseExpression3(code);
5046
- return t45.isStringLiteral(node);
5313
+ return t49.isStringLiteral(node);
5047
5314
  } catch {
5048
5315
  return false;
5049
5316
  }
@@ -5185,23 +5452,23 @@ function resolvePropAsBabelExp(ir, ctx) {
5185
5452
  const mergedItems = value.merge;
5186
5453
  const setNameIdentifier = (target, valueName) => {
5187
5454
  target.content = valueName;
5188
- target.ast = t46.jsxIdentifier(valueName);
5455
+ target.ast = t50.jsxIdentifier(valueName);
5189
5456
  };
5190
- const setValueExpression = (target, content, isStringLiteral13) => {
5457
+ const setValueExpression = (target, content, isStringLiteral14) => {
5191
5458
  target.content = content;
5192
- target.ast = resolveStringExpr(content, ctx, isStringLiteral13);
5459
+ target.ast = resolveStringExpr(content, ctx, isStringLiteral14);
5193
5460
  };
5194
5461
  const createRuntimeCall = (fnName, args) => {
5195
5462
  const fnArgs = args.filter(Boolean).join(",");
5196
5463
  return `${fnName}(${fnArgs})`;
5197
5464
  };
5198
- const applyRuntimeExpression = (expression, setName = false, nameIdentifier, isStringLiteral13) => {
5465
+ const applyRuntimeExpression = (expression, setName = false, nameIdentifier, isStringLiteral14) => {
5199
5466
  if (setName && nameIdentifier) {
5200
5467
  setNameIdentifier(nameExp, nameIdentifier);
5201
5468
  }
5202
5469
  const dir = ADAPTER_RULES.runtime.dir;
5203
5470
  recordImport(ctx, dir.package, dir.target);
5204
- setValueExpression(value.babelExp, expression, isStringLiteral13);
5471
+ setValueExpression(value.babelExp, expression, isStringLiteral14);
5205
5472
  };
5206
5473
  if (ir.isKeyLessVBind) {
5207
5474
  const dirKeyless = ADAPTER_RULES.runtime.dirKeyless;
@@ -5356,26 +5623,16 @@ function injectStyleScopeAttribute(node, ctx) {
5356
5623
  return;
5357
5624
  }
5358
5625
  let hasScopeId = false;
5359
- let hasClassOrId = false;
5360
5626
  for (const prop of node.props) {
5361
- if (prop.type === NodeTypes3.ATTRIBUTE) {
5362
- if (prop.name === scopeId) {
5363
- hasScopeId = true;
5364
- break;
5365
- }
5366
- if (getHasClassOrId(prop.name)) {
5367
- hasClassOrId = true;
5368
- break;
5369
- }
5627
+ if (prop.type !== NodeTypes3.ATTRIBUTE) {
5628
+ continue;
5370
5629
  }
5371
- if (prop.type === NodeTypes3.DIRECTIVE && prop.arg?.type === NodeTypes3.SIMPLE_EXPRESSION) {
5372
- if (getHasClassOrId(prop.arg.content)) {
5373
- hasClassOrId = true;
5374
- break;
5375
- }
5630
+ if (prop.name === scopeId) {
5631
+ hasScopeId = true;
5632
+ break;
5376
5633
  }
5377
5634
  }
5378
- if (hasScopeId || !hasClassOrId) return;
5635
+ if (hasScopeId) return;
5379
5636
  const attr = {
5380
5637
  type: NodeTypes3.ATTRIBUTE,
5381
5638
  name: scopeId,
@@ -5385,9 +5642,6 @@ function injectStyleScopeAttribute(node, ctx) {
5385
5642
  };
5386
5643
  node.props.push(attr);
5387
5644
  }
5388
- function getHasClassOrId(ns) {
5389
- return isClassAttr(ns) || ns === "id";
5390
- }
5391
5645
 
5392
5646
  // src/core/transform/sfc/template/shared/prop-merge-utils.ts
5393
5647
  function mergePropsIR(ctx, oldAttr, newAttr) {
@@ -5635,12 +5889,12 @@ function resolvePropertyIR(propsIR, ir, ctx, nodeIR, isDynamic = false) {
5635
5889
  content = propsIR.value.content = parseStyleString(content);
5636
5890
  }
5637
5891
  if (isDynamic) {
5638
- const isStringLiteral13 = strCodeTypes.isStringLiteral(content);
5639
- if (isStringLiteral13) {
5892
+ const isStringLiteral14 = strCodeTypes.isStringLiteral(content);
5893
+ if (isStringLiteral14) {
5640
5894
  content = normalizeString(content);
5641
5895
  propsIR.value.content = content;
5642
5896
  }
5643
- propsIR.value.isStringLiteral = isStringLiteral13;
5897
+ propsIR.value.isStringLiteral = isStringLiteral14;
5644
5898
  }
5645
5899
  const existing = findSameProp(nodeIR.props, propsIR);
5646
5900
  if (existing) {
@@ -5945,27 +6199,15 @@ function applyValueModifiers(valueExp, modifiers) {
5945
6199
  }
5946
6200
 
5947
6201
  // src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-on.ts
5948
- import * as t47 from "@babel/types";
6202
+ import * as t51 from "@babel/types";
5949
6203
  function resolveVOn(directive, ir, ctx, nodeIR) {
5950
6204
  const arg = directive.arg;
5951
6205
  const exp = directive.exp;
5952
6206
  const modifiers = directive.modifiers.map((item) => item.content);
5953
- const captureIndex = modifiers.findIndex((modifier) => modifier === "capture");
5954
- let eventName = normalizeVOnEventName(arg.content);
5955
- let handler = resolveSpecialExpression(exp.content.trim(), ctx);
5956
- if (captureIndex > -1) {
5957
- eventName = modifiers[captureIndex] ? `${eventName}Capture` : eventName;
5958
- modifiers.splice(captureIndex, 1);
5959
- }
5960
- let originalVueEventName = "";
5961
- if (modifiers.length) {
5962
- originalVueEventName = `${arg.content}.${modifiers.join(".")}`;
5963
- } else {
5964
- const expr = stringToExpr(handler);
5965
- if (!t47.isFunctionExpression(expr) && !t47.isArrowFunctionExpression(expr) && !t47.isIdentifier(expr)) {
5966
- handler = `() => {${handler}}`;
5967
- }
5968
- }
6207
+ const captureIndex = resolveCaptureModifier(modifiers);
6208
+ const eventName = resolveEventName(arg.content, captureIndex);
6209
+ const handler = resolveHandler(exp.content.trim(), ctx, modifiers);
6210
+ const originalVueEventName = modifiers.length ? `${arg.content}.${modifiers.join(".")}` : "";
5969
6211
  const eventIR = createPropsIR(directive.rawName, eventName, handler);
5970
6212
  eventIR.type = 3 /* EVENT */;
5971
6213
  eventIR.isStatic = arg.isStatic;
@@ -5980,11 +6222,45 @@ function resolveVOn(directive, ir, ctx, nodeIR) {
5980
6222
  }
5981
6223
  nodeIR.props.push(eventIR);
5982
6224
  }
6225
+ function resolveCaptureModifier(modifiers) {
6226
+ const captureIndex = modifiers.findIndex((modifier) => modifier === "capture");
6227
+ if (captureIndex > -1) {
6228
+ modifiers.splice(captureIndex, 1);
6229
+ }
6230
+ return captureIndex;
6231
+ }
6232
+ function resolveEventName(rawEventName, captureIndex) {
6233
+ let eventName = normalizeVOnEventName(rawEventName);
6234
+ if (captureIndex > -1) {
6235
+ eventName = `${eventName}Capture`;
6236
+ }
6237
+ return eventName;
6238
+ }
5983
6239
  function normalizeVOnEventName(rawEventName) {
5984
6240
  const segments = rawEventName.split(/[:-]/g).map((segment) => segment.trim()).filter(Boolean);
5985
6241
  const normalized = segments.map((segment) => capitalize(camelCase(segment))).join("");
5986
6242
  return `on${normalized}`;
5987
6243
  }
6244
+ function resolveHandler(handlerContent, ctx, modifiers) {
6245
+ let handler = resolveSpecialExpression(handlerContent, ctx);
6246
+ if (modifiers.length) {
6247
+ return handler;
6248
+ }
6249
+ const expr = stringToExpr(handler);
6250
+ if (isConsoleCall(expr)) {
6251
+ return "() => {}";
6252
+ }
6253
+ if (!isFnReference(expr)) {
6254
+ handler = `() => {${handler}}`;
6255
+ }
6256
+ return handler;
6257
+ }
6258
+ function isConsoleCall(expr) {
6259
+ return t51.isCallExpression(expr) && t51.isMemberExpression(expr.callee) && t51.isIdentifier(expr.callee.object) && expr.callee.object.name === "console";
6260
+ }
6261
+ function isFnReference(expr) {
6262
+ return t51.isIdentifier(expr) || t51.isMemberExpression(expr) || t51.isFunction(expr);
6263
+ }
5988
6264
 
5989
6265
  // src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-show.ts
5990
6266
  function resolveVShow(directive, ir, ctx, nodeIR) {
@@ -6336,7 +6612,7 @@ function transform(ast, ctx, options) {
6336
6612
  }
6337
6613
 
6338
6614
  // package.json
6339
- var version = "1.6.2";
6615
+ var version = "1.7.0";
6340
6616
  var bin = {
6341
6617
  vureact: "./bin/vureact.js"
6342
6618
  };
@@ -6950,7 +7226,7 @@ var CompilationContext = class {
6950
7226
  }
6951
7227
  create() {
6952
7228
  return {
6953
- fileId: "",
7229
+ fileId: Date.now().toString(),
6954
7230
  source: "",
6955
7231
  filename: "",
6956
7232
  imports: /* @__PURE__ */ new Map(),