@fictjs/compiler 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.cjs +413 -171
  2. package/dist/index.js +413 -171
  3. package/package.json +3 -2
package/dist/index.cjs CHANGED
@@ -14384,6 +14384,9 @@ function pathToString(path) {
14384
14384
 
14385
14385
  // src/ir/build-hir.ts
14386
14386
  var destructuringTempCounter = 0;
14387
+ var getLoc = (node) => {
14388
+ return node?.loc ?? null;
14389
+ };
14387
14390
  function normalizeVarKind(kind) {
14388
14391
  return kind === "const" || kind === "let" || kind === "var" ? kind : "let";
14389
14392
  }
@@ -14453,7 +14456,8 @@ function buildHIR(ast) {
14453
14456
  functions.push(
14454
14457
  convertFunction(name, stmt.params, stmt.body.body, {
14455
14458
  noMemo: programNoMemo,
14456
- directives: stmt.body.directives
14459
+ directives: stmt.body.directives,
14460
+ loc: getLoc(stmt)
14457
14461
  })
14458
14462
  );
14459
14463
  continue;
@@ -14466,7 +14470,8 @@ function buildHIR(ast) {
14466
14470
  functions.push(
14467
14471
  convertFunction(name, decl.params, decl.body.body, {
14468
14472
  noMemo: programNoMemo,
14469
- directives: decl.body.directives
14473
+ directives: decl.body.directives,
14474
+ loc: getLoc(decl)
14470
14475
  })
14471
14476
  );
14472
14477
  postamble.push({ kind: "ExportFunction", name });
@@ -14484,9 +14489,11 @@ function buildHIR(ast) {
14484
14489
  const hasExpressionBody = isArrow && !t.isBlockStatement(body);
14485
14490
  const fnHIR = t.isBlockStatement(body) ? convertFunction(name, params, body.body, {
14486
14491
  noMemo: programNoMemo,
14487
- directives: body.directives
14492
+ directives: body.directives,
14493
+ loc: getLoc(v.init ?? v)
14488
14494
  }) : convertFunction(name, params, [t.returnStatement(body)], {
14489
- noMemo: programNoMemo
14495
+ noMemo: programNoMemo,
14496
+ loc: getLoc(v.init ?? v)
14490
14497
  });
14491
14498
  fnHIR.meta = { ...fnHIR.meta ?? {}, fromExpression: true, isArrow, hasExpressionBody };
14492
14499
  functions.push(fnHIR);
@@ -14511,7 +14518,8 @@ function buildHIR(ast) {
14511
14518
  functions.push(
14512
14519
  convertFunction(name, decl.params, decl.body.body, {
14513
14520
  noMemo: programNoMemo,
14514
- directives: decl.body.directives
14521
+ directives: decl.body.directives,
14522
+ loc: getLoc(decl)
14515
14523
  })
14516
14524
  );
14517
14525
  postamble.push({ kind: "ExportDefault", name });
@@ -14536,13 +14544,15 @@ function buildHIR(ast) {
14536
14544
  const hasExpressionBody = isArrow && !t.isBlockStatement(body);
14537
14545
  const fnHIR = t.isBlockStatement(body) ? convertFunction(name, params, body.body, {
14538
14546
  noMemo: programNoMemo,
14539
- directives: body.directives
14547
+ directives: body.directives,
14548
+ loc: getLoc(decl.init ?? decl)
14540
14549
  }) : convertFunction(
14541
14550
  name,
14542
14551
  params,
14543
14552
  [t.returnStatement(body)],
14544
14553
  {
14545
- noMemo: programNoMemo
14554
+ noMemo: programNoMemo,
14555
+ loc: getLoc(decl.init ?? decl)
14546
14556
  }
14547
14557
  );
14548
14558
  fnHIR.meta = { ...fnHIR.meta ?? {}, fromExpression: true, isArrow, hasExpressionBody };
@@ -15050,11 +15060,12 @@ function convertFunction(name, params, body, options) {
15050
15060
  name,
15051
15061
  params: paramIds,
15052
15062
  blocks,
15053
- meta: hasNoMemo ? { noMemo: true } : void 0
15063
+ meta: hasNoMemo ? { noMemo: true } : void 0,
15064
+ loc: options?.loc ?? null
15054
15065
  };
15055
15066
  }
15056
15067
  function convertStatementsToHIRFunction(name, statements) {
15057
- return convertFunction(name, [], statements);
15068
+ return convertFunction(name, [], statements, { loc: getLoc(statements[0]) });
15058
15069
  }
15059
15070
  function convertAssignmentValue(expr) {
15060
15071
  const right = convertExpression(expr.right);
@@ -15552,14 +15563,16 @@ function processStatement(stmt, bb, jumpTarget, ctx) {
15552
15563
  return bb;
15553
15564
  }
15554
15565
  function convertExpression(node) {
15555
- if (t.isIdentifier(node)) return { kind: "Identifier", name: node.name };
15566
+ const loc = getLoc(node);
15567
+ if (t.isIdentifier(node)) return { kind: "Identifier", name: node.name, loc };
15556
15568
  if (t.isStringLiteral(node) || t.isNumericLiteral(node) || t.isBooleanLiteral(node) || t.isNullLiteral(node))
15557
- return { kind: "Literal", value: node.value ?? null };
15569
+ return { kind: "Literal", value: node.value ?? null, loc };
15558
15570
  if (t.isCallExpression(node)) {
15559
15571
  const call = {
15560
15572
  kind: "CallExpression",
15561
15573
  callee: convertExpression(node.callee),
15562
- arguments: node.arguments.map((arg) => t.isExpression(arg) ? convertExpression(arg) : void 0).filter(Boolean)
15574
+ arguments: node.arguments.map((arg) => t.isExpression(arg) ? convertExpression(arg) : void 0).filter(Boolean),
15575
+ loc
15563
15576
  };
15564
15577
  return call;
15565
15578
  }
@@ -15574,7 +15587,8 @@ function convertExpression(node) {
15574
15587
  object,
15575
15588
  property,
15576
15589
  computed: node.computed,
15577
- optional: node.optional ?? true
15590
+ optional: node.optional ?? true,
15591
+ loc
15578
15592
  };
15579
15593
  return optionalMember;
15580
15594
  }
@@ -15583,7 +15597,8 @@ function convertExpression(node) {
15583
15597
  object,
15584
15598
  property,
15585
15599
  computed: node.computed,
15586
- optional: false
15600
+ optional: false,
15601
+ loc
15587
15602
  };
15588
15603
  return member;
15589
15604
  }
@@ -15592,7 +15607,8 @@ function convertExpression(node) {
15592
15607
  kind: "BinaryExpression",
15593
15608
  operator: node.operator,
15594
15609
  left: convertExpression(node.left),
15595
- right: convertExpression(node.right)
15610
+ right: convertExpression(node.right),
15611
+ loc
15596
15612
  };
15597
15613
  return bin;
15598
15614
  }
@@ -15601,7 +15617,8 @@ function convertExpression(node) {
15601
15617
  kind: "UnaryExpression",
15602
15618
  operator: node.operator,
15603
15619
  argument: convertExpression(node.argument),
15604
- prefix: node.prefix
15620
+ prefix: node.prefix,
15621
+ loc
15605
15622
  };
15606
15623
  return un;
15607
15624
  }
@@ -15610,7 +15627,8 @@ function convertExpression(node) {
15610
15627
  kind: "LogicalExpression",
15611
15628
  operator: node.operator,
15612
15629
  left: convertExpression(node.left),
15613
- right: convertExpression(node.right)
15630
+ right: convertExpression(node.right),
15631
+ loc
15614
15632
  };
15615
15633
  return log;
15616
15634
  }
@@ -15619,7 +15637,8 @@ function convertExpression(node) {
15619
15637
  kind: "ConditionalExpression",
15620
15638
  test: convertExpression(node.test),
15621
15639
  consequent: convertExpression(node.consequent),
15622
- alternate: convertExpression(node.alternate)
15640
+ alternate: convertExpression(node.alternate),
15641
+ loc
15623
15642
  };
15624
15643
  return cond;
15625
15644
  }
@@ -15631,12 +15650,14 @@ function convertExpression(node) {
15631
15650
  if (t.isSpreadElement(el)) {
15632
15651
  return {
15633
15652
  kind: "SpreadElement",
15634
- argument: convertExpression(el.argument)
15653
+ argument: convertExpression(el.argument),
15654
+ loc: getLoc(el)
15635
15655
  };
15636
15656
  }
15637
15657
  if (t.isExpression(el)) return convertExpression(el);
15638
15658
  return void 0;
15639
- }).filter(Boolean)
15659
+ }).filter(Boolean),
15660
+ loc
15640
15661
  };
15641
15662
  return arr;
15642
15663
  }
@@ -15647,7 +15668,8 @@ function convertExpression(node) {
15647
15668
  if (t.isSpreadElement(prop)) {
15648
15669
  return {
15649
15670
  kind: "SpreadElement",
15650
- argument: convertExpression(prop.argument)
15671
+ argument: convertExpression(prop.argument),
15672
+ loc: getLoc(prop)
15651
15673
  };
15652
15674
  }
15653
15675
  if (t.isObjectMethod(prop)) {
@@ -15664,7 +15686,8 @@ function convertExpression(node) {
15664
15686
  return {
15665
15687
  kind: "Property",
15666
15688
  key: keyExpr2,
15667
- value: convertExpression(fnExpr)
15689
+ value: convertExpression(fnExpr),
15690
+ loc: getLoc(prop)
15668
15691
  };
15669
15692
  }
15670
15693
  if (!t.isObjectProperty(prop) || prop.computed) return void 0;
@@ -15674,9 +15697,12 @@ function convertExpression(node) {
15674
15697
  return {
15675
15698
  kind: "Property",
15676
15699
  key: keyExpr,
15677
- value: convertExpression(prop.value)
15700
+ value: convertExpression(prop.value),
15701
+ shorthand: prop.shorthand && t.isIdentifier(prop.value),
15702
+ loc: getLoc(prop)
15678
15703
  };
15679
- }).filter(Boolean)
15704
+ }).filter(Boolean),
15705
+ loc
15680
15706
  };
15681
15707
  return obj;
15682
15708
  }
@@ -15689,38 +15715,42 @@ function convertExpression(node) {
15689
15715
  if (t.isJSXText(child)) {
15690
15716
  const text = child.value;
15691
15717
  if (text.trim()) {
15692
- children.push({ kind: "text", value: text });
15718
+ children.push({ kind: "text", value: text, loc: getLoc(child) });
15693
15719
  }
15694
15720
  } else if (t.isJSXExpressionContainer(child)) {
15695
15721
  if (!t.isJSXEmptyExpression(child.expression)) {
15696
15722
  children.push({
15697
15723
  kind: "expression",
15698
- value: convertExpression(child.expression)
15724
+ value: convertExpression(child.expression),
15725
+ loc: getLoc(child)
15699
15726
  });
15700
15727
  }
15701
15728
  } else if (t.isJSXElement(child)) {
15702
15729
  children.push({
15703
15730
  kind: "element",
15704
- value: convertJSXElement(child)
15731
+ value: convertJSXElement(child),
15732
+ loc: getLoc(child)
15705
15733
  });
15706
15734
  } else if (t.isJSXFragment(child)) {
15707
15735
  for (const fragChild of child.children) {
15708
15736
  if (t.isJSXText(fragChild)) {
15709
15737
  const text = fragChild.value;
15710
15738
  if (text.trim()) {
15711
- children.push({ kind: "text", value: text });
15739
+ children.push({ kind: "text", value: text, loc: getLoc(fragChild) });
15712
15740
  }
15713
15741
  } else if (t.isJSXExpressionContainer(fragChild)) {
15714
15742
  if (!t.isJSXEmptyExpression(fragChild.expression)) {
15715
15743
  children.push({
15716
15744
  kind: "expression",
15717
- value: convertExpression(fragChild.expression)
15745
+ value: convertExpression(fragChild.expression),
15746
+ loc: getLoc(fragChild)
15718
15747
  });
15719
15748
  }
15720
15749
  } else if (t.isJSXElement(fragChild)) {
15721
15750
  children.push({
15722
15751
  kind: "element",
15723
- value: convertJSXElement(fragChild)
15752
+ value: convertJSXElement(fragChild),
15753
+ loc: getLoc(fragChild)
15724
15754
  });
15725
15755
  }
15726
15756
  }
@@ -15728,24 +15758,27 @@ function convertExpression(node) {
15728
15758
  }
15729
15759
  return {
15730
15760
  kind: "JSXElement",
15731
- tagName: { kind: "Identifier", name: "Fragment" },
15761
+ tagName: { kind: "Identifier", name: "Fragment", loc: getLoc(node) },
15732
15762
  isComponent: true,
15733
15763
  attributes: [],
15734
- children
15764
+ children,
15765
+ loc: getLoc(node)
15735
15766
  };
15736
15767
  }
15737
15768
  if (t.isArrowFunctionExpression(node)) {
15738
15769
  if (t.isBlockStatement(node.body)) {
15739
15770
  const nested = convertFunction(void 0, node.params, node.body.body, {
15740
15771
  noMemo: hasNoMemoDirectiveInStatements(node.body.body),
15741
- directives: node.body.directives
15772
+ directives: node.body.directives,
15773
+ loc: getLoc(node)
15742
15774
  });
15743
15775
  const arrow = {
15744
15776
  kind: "ArrowFunction",
15745
15777
  params: nested.params,
15746
15778
  body: nested.blocks,
15747
15779
  isExpression: false,
15748
- isAsync: node.async
15780
+ isAsync: node.async,
15781
+ loc
15749
15782
  };
15750
15783
  return arrow;
15751
15784
  } else {
@@ -15756,7 +15789,8 @@ function convertExpression(node) {
15756
15789
  ).flat(),
15757
15790
  body: convertExpression(node.body),
15758
15791
  isExpression: true,
15759
- isAsync: node.async
15792
+ isAsync: node.async,
15793
+ loc
15760
15794
  };
15761
15795
  return arrow;
15762
15796
  }
@@ -15764,14 +15798,16 @@ function convertExpression(node) {
15764
15798
  if (t.isFunctionExpression(node)) {
15765
15799
  const nested = convertFunction(void 0, node.params, node.body.body, {
15766
15800
  noMemo: hasNoMemoDirectiveInStatements(node.body.body),
15767
- directives: node.body.directives
15801
+ directives: node.body.directives,
15802
+ loc: getLoc(node)
15768
15803
  });
15769
15804
  const fn = {
15770
15805
  kind: "FunctionExpression",
15771
15806
  name: node.id?.name ?? "",
15772
15807
  params: nested.params,
15773
15808
  body: nested.blocks,
15774
- isAsync: node.async
15809
+ isAsync: node.async,
15810
+ loc
15775
15811
  };
15776
15812
  return fn;
15777
15813
  }
@@ -15780,7 +15816,8 @@ function convertExpression(node) {
15780
15816
  kind: "AssignmentExpression",
15781
15817
  operator: node.operator,
15782
15818
  left: convertExpression(node.left),
15783
- right: convertExpression(node.right)
15819
+ right: convertExpression(node.right),
15820
+ loc
15784
15821
  };
15785
15822
  return assign;
15786
15823
  }
@@ -15789,7 +15826,8 @@ function convertExpression(node) {
15789
15826
  kind: "UpdateExpression",
15790
15827
  operator: node.operator,
15791
15828
  argument: convertExpression(node.argument),
15792
- prefix: node.prefix
15829
+ prefix: node.prefix,
15830
+ loc
15793
15831
  };
15794
15832
  return update;
15795
15833
  }
@@ -15797,34 +15835,39 @@ function convertExpression(node) {
15797
15835
  const template = {
15798
15836
  kind: "TemplateLiteral",
15799
15837
  quasis: node.quasis.map((q) => q.value.cooked ?? q.value.raw),
15800
- expressions: node.expressions.map((e) => convertExpression(e))
15838
+ expressions: node.expressions.map((e) => convertExpression(e)),
15839
+ loc
15801
15840
  };
15802
15841
  return template;
15803
15842
  }
15804
15843
  if (t.isAwaitExpression(node)) {
15805
15844
  return {
15806
15845
  kind: "AwaitExpression",
15807
- argument: convertExpression(node.argument)
15846
+ argument: convertExpression(node.argument),
15847
+ loc
15808
15848
  };
15809
15849
  }
15810
15850
  if (t.isNewExpression(node)) {
15811
15851
  return {
15812
15852
  kind: "NewExpression",
15813
15853
  callee: convertExpression(node.callee),
15814
- arguments: node.arguments.map((arg) => t.isExpression(arg) ? convertExpression(arg) : void 0).filter(Boolean)
15854
+ arguments: node.arguments.map((arg) => t.isExpression(arg) ? convertExpression(arg) : void 0).filter(Boolean),
15855
+ loc
15815
15856
  };
15816
15857
  }
15817
15858
  if (t.isSequenceExpression(node)) {
15818
15859
  return {
15819
15860
  kind: "SequenceExpression",
15820
- expressions: node.expressions.map((e) => convertExpression(e))
15861
+ expressions: node.expressions.map((e) => convertExpression(e)),
15862
+ loc
15821
15863
  };
15822
15864
  }
15823
15865
  if (t.isYieldExpression(node)) {
15824
15866
  return {
15825
15867
  kind: "YieldExpression",
15826
15868
  argument: node.argument ? convertExpression(node.argument) : null,
15827
- delegate: node.delegate
15869
+ delegate: node.delegate,
15870
+ loc
15828
15871
  };
15829
15872
  }
15830
15873
  if (t.isOptionalCallExpression(node)) {
@@ -15832,7 +15875,8 @@ function convertExpression(node) {
15832
15875
  kind: "OptionalCallExpression",
15833
15876
  callee: convertExpression(node.callee),
15834
15877
  arguments: node.arguments.map((arg) => t.isExpression(arg) ? convertExpression(arg) : void 0).filter(Boolean),
15835
- optional: node.optional
15878
+ optional: node.optional,
15879
+ loc
15836
15880
  };
15837
15881
  }
15838
15882
  if (t.isTaggedTemplateExpression(node)) {
@@ -15844,8 +15888,10 @@ function convertExpression(node) {
15844
15888
  quasis: node.quasi.quasis.map((q) => q.value.cooked ?? q.value.raw),
15845
15889
  expressions: node.quasi.expressions.map(
15846
15890
  (e) => convertExpression(e)
15847
- )
15848
- }
15891
+ ),
15892
+ loc: getLoc(node.quasi)
15893
+ },
15894
+ loc
15849
15895
  };
15850
15896
  }
15851
15897
  if (t.isClassExpression(node)) {
@@ -15853,17 +15899,18 @@ function convertExpression(node) {
15853
15899
  kind: "ClassExpression",
15854
15900
  name: node.id?.name,
15855
15901
  superClass: node.superClass ? convertExpression(node.superClass) : void 0,
15856
- body: node.body.body
15902
+ body: node.body.body,
15857
15903
  // Store as Babel AST for now
15904
+ loc
15858
15905
  };
15859
15906
  }
15860
15907
  if (t.isThisExpression(node)) {
15861
- return { kind: "ThisExpression" };
15908
+ return { kind: "ThisExpression", loc };
15862
15909
  }
15863
15910
  if (t.isSuper(node)) {
15864
- return { kind: "SuperExpression" };
15911
+ return { kind: "SuperExpression", loc };
15865
15912
  }
15866
- const fallback = { kind: "Literal", value: void 0 };
15913
+ const fallback = { kind: "Literal", value: void 0, loc };
15867
15914
  return fallback;
15868
15915
  }
15869
15916
  function convertJSXElement(node) {
@@ -15874,7 +15921,7 @@ function convertJSXElement(node) {
15874
15921
  const name = opening.name.name;
15875
15922
  const firstChar = name[0];
15876
15923
  if (firstChar && firstChar === firstChar.toUpperCase()) {
15877
- tagName = { kind: "Identifier", name };
15924
+ tagName = { kind: "Identifier", name, loc: getLoc(opening.name) };
15878
15925
  isComponent = true;
15879
15926
  } else {
15880
15927
  tagName = name;
@@ -15892,20 +15939,22 @@ function convertJSXElement(node) {
15892
15939
  name: "",
15893
15940
  value: null,
15894
15941
  isSpread: true,
15895
- spreadExpr: convertExpression(attr.argument)
15942
+ spreadExpr: convertExpression(attr.argument),
15943
+ loc: getLoc(attr)
15896
15944
  });
15897
15945
  } else if (t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name)) {
15898
15946
  let value = null;
15899
15947
  if (attr.value) {
15900
15948
  if (t.isStringLiteral(attr.value)) {
15901
- value = { kind: "Literal", value: attr.value.value };
15949
+ value = { kind: "Literal", value: attr.value.value, loc: getLoc(attr.value) };
15902
15950
  } else if (t.isJSXExpressionContainer(attr.value) && !t.isJSXEmptyExpression(attr.value.expression)) {
15903
15951
  value = convertExpression(attr.value.expression);
15904
15952
  }
15905
15953
  }
15906
15954
  attributes.push({
15907
15955
  name: attr.name.name,
15908
- value
15956
+ value,
15957
+ loc: getLoc(attr)
15909
15958
  });
15910
15959
  }
15911
15960
  }
@@ -15914,38 +15963,42 @@ function convertJSXElement(node) {
15914
15963
  if (t.isJSXText(child)) {
15915
15964
  const text = child.value;
15916
15965
  if (text.trim()) {
15917
- children.push({ kind: "text", value: text });
15966
+ children.push({ kind: "text", value: text, loc: getLoc(child) });
15918
15967
  }
15919
15968
  } else if (t.isJSXExpressionContainer(child)) {
15920
15969
  if (!t.isJSXEmptyExpression(child.expression)) {
15921
15970
  children.push({
15922
15971
  kind: "expression",
15923
- value: convertExpression(child.expression)
15972
+ value: convertExpression(child.expression),
15973
+ loc: getLoc(child)
15924
15974
  });
15925
15975
  }
15926
15976
  } else if (t.isJSXElement(child)) {
15927
15977
  children.push({
15928
15978
  kind: "element",
15929
- value: convertJSXElement(child)
15979
+ value: convertJSXElement(child),
15980
+ loc: getLoc(child)
15930
15981
  });
15931
15982
  } else if (t.isJSXFragment(child)) {
15932
15983
  for (const fragChild of child.children) {
15933
15984
  if (t.isJSXText(fragChild)) {
15934
15985
  const text = fragChild.value;
15935
15986
  if (text.trim()) {
15936
- children.push({ kind: "text", value: text });
15987
+ children.push({ kind: "text", value: text, loc: getLoc(fragChild) });
15937
15988
  }
15938
15989
  } else if (t.isJSXExpressionContainer(fragChild)) {
15939
15990
  if (!t.isJSXEmptyExpression(fragChild.expression)) {
15940
15991
  children.push({
15941
15992
  kind: "expression",
15942
- value: convertExpression(fragChild.expression)
15993
+ value: convertExpression(fragChild.expression),
15994
+ loc: getLoc(fragChild)
15943
15995
  });
15944
15996
  }
15945
15997
  } else if (t.isJSXElement(fragChild)) {
15946
15998
  children.push({
15947
15999
  kind: "element",
15948
- value: convertJSXElement(fragChild)
16000
+ value: convertJSXElement(fragChild),
16001
+ loc: getLoc(fragChild)
15949
16002
  });
15950
16003
  }
15951
16004
  }
@@ -15956,21 +16009,27 @@ function convertJSXElement(node) {
15956
16009
  tagName,
15957
16010
  isComponent,
15958
16011
  attributes,
15959
- children
16012
+ children,
16013
+ loc: getLoc(node)
15960
16014
  };
15961
16015
  }
15962
16016
  function convertJSXMemberExpr(node) {
15963
16017
  let object;
15964
16018
  if (t.isJSXIdentifier(node.object)) {
15965
- object = { kind: "Identifier", name: node.object.name };
16019
+ object = { kind: "Identifier", name: node.object.name, loc: getLoc(node.object) };
15966
16020
  } else {
15967
16021
  object = convertJSXMemberExpr(node.object);
15968
16022
  }
15969
16023
  return {
15970
16024
  kind: "MemberExpression",
15971
16025
  object,
15972
- property: { kind: "Identifier", name: node.property.name },
15973
- computed: false
16026
+ property: {
16027
+ kind: "Identifier",
16028
+ name: node.property.name,
16029
+ loc: getLoc(node.property)
16030
+ },
16031
+ computed: false,
16032
+ loc: getLoc(node)
15974
16033
  };
15975
16034
  }
15976
16035
 
@@ -18928,11 +18987,17 @@ function wrapInMemo(region, t2, declaredVars, ctx, bodyStatementsOverride, outpu
18928
18987
  if (uniqueOutputNames.length === 0) {
18929
18988
  ctx.helpersUsed.add("useEffect");
18930
18989
  ctx.needsCtx = true;
18931
- const effectCall = t2.callExpression(t2.identifier(RUNTIME_ALIASES.useEffect), [
18990
+ const effectCallArgs = [
18932
18991
  t2.identifier("__fictCtx"),
18933
- t2.arrowFunctionExpression([], t2.blockStatement(bodyStatements)),
18934
- t2.numericLiteral(reserveHookSlot(ctx))
18935
- ]);
18992
+ t2.arrowFunctionExpression([], t2.blockStatement(bodyStatements))
18993
+ ];
18994
+ {
18995
+ const slot = reserveHookSlot(ctx);
18996
+ if (slot >= 0) {
18997
+ effectCallArgs.push(t2.numericLiteral(slot));
18998
+ }
18999
+ }
19000
+ const effectCall = t2.callExpression(t2.identifier(RUNTIME_ALIASES.useEffect), effectCallArgs);
18936
19001
  statements.push(t2.expressionStatement(effectCall));
18937
19002
  } else {
18938
19003
  ctx.helpersUsed.add("useMemo");
@@ -18965,11 +19030,15 @@ function wrapInMemo(region, t2, declaredVars, ctx, bodyStatementsOverride, outpu
18965
19030
  };
18966
19031
  const returnObj = t2.objectExpression(uniqueOutputNames.map((name) => buildOutputProperty(name)));
18967
19032
  const memoBody = t2.blockStatement([...bodyStatements, t2.returnStatement(returnObj)]);
18968
- const memoCall = t2.callExpression(t2.identifier(RUNTIME_ALIASES.useMemo), [
19033
+ const slot = reserveHookSlot(ctx);
19034
+ const memoArgs = [
18969
19035
  t2.identifier("__fictCtx"),
18970
- t2.arrowFunctionExpression([], memoBody),
18971
- t2.numericLiteral(reserveHookSlot(ctx))
18972
- ]);
19036
+ t2.arrowFunctionExpression([], memoBody)
19037
+ ];
19038
+ if (slot >= 0) {
19039
+ memoArgs.push(t2.numericLiteral(slot));
19040
+ }
19041
+ const memoCall = t2.callExpression(t2.identifier(RUNTIME_ALIASES.useMemo), memoArgs);
18973
19042
  const regionVarName = `__region_${region.id}`;
18974
19043
  statements.push(
18975
19044
  t2.variableDeclaration("const", [t2.variableDeclarator(t2.identifier(regionVarName), memoCall)])
@@ -19026,7 +19095,10 @@ function wrapInMemo(region, t2, declaredVars, ctx, bodyStatementsOverride, outpu
19026
19095
  t2.callExpression(t2.identifier(RUNTIME_ALIASES.useEffect), [
19027
19096
  t2.identifier("__fictCtx"),
19028
19097
  t2.arrowFunctionExpression([], effectBody),
19029
- t2.numericLiteral(reserveHookSlot(ctx))
19098
+ (() => {
19099
+ const slot2 = reserveHookSlot(ctx);
19100
+ return slot2 >= 0 ? t2.numericLiteral(slot2) : t2.identifier("undefined");
19101
+ })()
19030
19102
  ])
19031
19103
  )
19032
19104
  );
@@ -19244,11 +19316,15 @@ function generateLazyConditionalMemo(region, orderedOutputs, bodyStatements, con
19244
19316
  ctx.helpersUsed.add("useMemo");
19245
19317
  ctx.needsCtx = true;
19246
19318
  const regionVarName = `__region_${region.id}`;
19247
- const memoCall = t2.callExpression(t2.identifier("__fictUseMemo"), [
19319
+ const slotForMemo = reserveHookSlot(ctx);
19320
+ const memoArgs = [
19248
19321
  t2.identifier("__fictCtx"),
19249
- t2.arrowFunctionExpression([], t2.blockStatement(memoBody)),
19250
- t2.numericLiteral(reserveHookSlot(ctx))
19251
- ]);
19322
+ t2.arrowFunctionExpression([], t2.blockStatement(memoBody))
19323
+ ];
19324
+ if (slotForMemo >= 0) {
19325
+ memoArgs.push(t2.numericLiteral(slotForMemo));
19326
+ }
19327
+ const memoCall = t2.callExpression(t2.identifier("__fictUseMemo"), memoArgs);
19252
19328
  statements.push(
19253
19329
  t2.variableDeclaration("const", [t2.variableDeclarator(t2.identifier(regionVarName), memoCall)])
19254
19330
  );
@@ -19270,6 +19346,9 @@ function generateLazyConditionalMemo(region, orderedOutputs, bodyStatements, con
19270
19346
  return statements;
19271
19347
  }
19272
19348
  function reserveHookSlot(ctx) {
19349
+ if (ctx.dynamicHookSlotDepth && ctx.dynamicHookSlotDepth > 0) {
19350
+ return -1;
19351
+ }
19273
19352
  const slot = ctx.nextHookSlot ?? 0;
19274
19353
  ctx.nextHookSlot = slot + 1;
19275
19354
  return slot;
@@ -19340,7 +19419,10 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
19340
19419
  t2.arrowFunctionExpression([], expr)
19341
19420
  ];
19342
19421
  if (inRegionMemo) {
19343
- args.push(t2.numericLiteral(reserveHookSlot(ctx)));
19422
+ const slot = reserveHookSlot(ctx);
19423
+ if (slot >= 0) {
19424
+ args.push(t2.numericLiteral(slot));
19425
+ }
19344
19426
  }
19345
19427
  ctx.helpersUsed.add("useMemo");
19346
19428
  ctx.needsCtx = true;
@@ -19855,6 +19937,17 @@ function deSSAJSXChild(child, t2) {
19855
19937
  // src/ir/codegen.ts
19856
19938
  var HOOK_SLOT_BASE = 1e3;
19857
19939
  var HOOK_NAME_PREFIX = "use";
19940
+ var cloneLoc = (loc) => loc === void 0 ? void 0 : loc === null ? null : {
19941
+ start: { ...loc.start },
19942
+ end: { ...loc.end },
19943
+ filename: loc.filename,
19944
+ identifierName: loc.identifierName
19945
+ };
19946
+ function setNodeLoc(node, loc) {
19947
+ if (loc === void 0) return node;
19948
+ node.loc = cloneLoc(loc) ?? null;
19949
+ return node;
19950
+ }
19858
19951
  function isHookName(name) {
19859
19952
  return !!name && name.startsWith(HOOK_NAME_PREFIX);
19860
19953
  }
@@ -19888,13 +19981,22 @@ function applyRegionToContext(ctx, region) {
19888
19981
  return prevRegion;
19889
19982
  }
19890
19983
  function reserveHookSlot2(ctx) {
19984
+ if (ctx.dynamicHookSlotDepth && ctx.dynamicHookSlotDepth > 0) {
19985
+ return -1;
19986
+ }
19891
19987
  const slot = ctx.nextHookSlot ?? HOOK_SLOT_BASE;
19892
19988
  ctx.nextHookSlot = slot + 1;
19893
19989
  return slot;
19894
19990
  }
19895
19991
  function expressionContainsJSX(expr) {
19992
+ if (Array.isArray(expr)) {
19993
+ return expr.some((item) => expressionContainsJSX(item));
19994
+ }
19896
19995
  if (!expr || typeof expr !== "object") return false;
19897
19996
  if (expr.kind === "JSXElement") return true;
19997
+ if (Array.isArray(expr.instructions)) {
19998
+ return expr.instructions.some((i) => expressionContainsJSX(i?.value ?? i));
19999
+ }
19898
20000
  switch (expr.kind) {
19899
20001
  case "CallExpression":
19900
20002
  if (expressionContainsJSX(expr.callee)) return true;
@@ -19907,10 +20009,29 @@ function expressionContainsJSX(expr) {
19907
20009
  return expressionContainsJSX(expr.test) || expressionContainsJSX(expr.consequent) || expressionContainsJSX(expr.alternate);
19908
20010
  case "ArrowFunction":
19909
20011
  return expressionContainsJSX(expr.body);
20012
+ case "FunctionExpression":
20013
+ if (Array.isArray(expr.body)) {
20014
+ return expr.body.some(
20015
+ (block) => block.instructions?.some((i) => expressionContainsJSX(i.value))
20016
+ );
20017
+ }
20018
+ return false;
19910
20019
  default:
19911
20020
  return false;
19912
20021
  }
19913
20022
  }
20023
+ function withNoMemoAndDynamicHooks(ctx, fn) {
20024
+ const prevNoMemo = ctx.noMemo;
20025
+ const prevDynamic = ctx.dynamicHookSlotDepth ?? 0;
20026
+ ctx.noMemo = true;
20027
+ ctx.dynamicHookSlotDepth = prevDynamic + 1;
20028
+ try {
20029
+ return fn();
20030
+ } finally {
20031
+ ctx.noMemo = prevNoMemo;
20032
+ ctx.dynamicHookSlotDepth = prevDynamic;
20033
+ }
20034
+ }
19914
20035
  function functionContainsJSX(fn) {
19915
20036
  for (const block of fn.blocks) {
19916
20037
  for (const instr of block.instructions) {
@@ -21009,18 +21130,25 @@ function lowerTrackedExpression(expr, ctx) {
21009
21130
  }
21010
21131
  function lowerInstruction(instr, ctx) {
21011
21132
  const { t: t2 } = ctx;
21133
+ const applyLoc = (stmt) => {
21134
+ if (!stmt) return stmt;
21135
+ const baseLoc = instr.loc ?? (instr.kind === "Assign" || instr.kind === "Expression" ? instr.value.loc : void 0);
21136
+ return setNodeLoc(stmt, baseLoc);
21137
+ };
21012
21138
  if (instr.kind === "Assign") {
21013
21139
  const baseName2 = deSSAVarName(instr.target.name);
21014
21140
  const isFunctionDecl = instr.value.kind === "FunctionExpression" && (instr.declarationKind === "function" || !instr.declarationKind && instr.value.name === baseName2);
21015
21141
  if (isFunctionDecl) {
21016
21142
  const loweredFn = lowerExpression(instr.value, ctx);
21017
21143
  if (t2.isFunctionExpression(loweredFn)) {
21018
- return t2.functionDeclaration(
21019
- t2.identifier(baseName2),
21020
- loweredFn.params,
21021
- loweredFn.body,
21022
- loweredFn.generator ?? false,
21023
- loweredFn.async ?? false
21144
+ return applyLoc(
21145
+ t2.functionDeclaration(
21146
+ t2.identifier(baseName2),
21147
+ loweredFn.params,
21148
+ loweredFn.body,
21149
+ loweredFn.generator ?? false,
21150
+ loweredFn.async ?? false
21151
+ )
21024
21152
  );
21025
21153
  }
21026
21154
  }
@@ -21035,12 +21163,16 @@ function lowerInstruction(instr, ctx) {
21035
21163
  ctx.memoVars?.add(baseName2);
21036
21164
  }
21037
21165
  if (declKind) {
21038
- return t2.variableDeclaration(declKind, [
21039
- t2.variableDeclarator(t2.identifier(baseName2), hookMember.member)
21040
- ]);
21166
+ return applyLoc(
21167
+ t2.variableDeclaration(declKind, [
21168
+ t2.variableDeclarator(t2.identifier(baseName2), hookMember.member)
21169
+ ])
21170
+ );
21041
21171
  }
21042
- return t2.expressionStatement(
21043
- t2.assignmentExpression("=", t2.identifier(baseName2), hookMember.member)
21172
+ return applyLoc(
21173
+ t2.expressionStatement(
21174
+ t2.assignmentExpression("=", t2.identifier(baseName2), hookMember.member)
21175
+ )
21044
21176
  );
21045
21177
  }
21046
21178
  if (instr.value.kind === "CallExpression" && instr.value.callee.kind === "Identifier" && isHookName(instr.value.callee.name)) {
@@ -21054,16 +21186,24 @@ function lowerInstruction(instr, ctx) {
21054
21186
  }
21055
21187
  }
21056
21188
  if (ctx.signalVars?.has(baseName2)) {
21057
- return t2.expressionStatement(
21058
- t2.callExpression(t2.identifier(baseName2), [lowerTrackedExpression(instr.value, ctx)])
21189
+ return applyLoc(
21190
+ t2.expressionStatement(
21191
+ t2.callExpression(t2.identifier(baseName2), [lowerTrackedExpression(instr.value, ctx)])
21192
+ )
21059
21193
  );
21060
21194
  }
21061
- return t2.expressionStatement(
21062
- t2.assignmentExpression("=", t2.identifier(baseName2), lowerTrackedExpression(instr.value, ctx))
21195
+ return applyLoc(
21196
+ t2.expressionStatement(
21197
+ t2.assignmentExpression(
21198
+ "=",
21199
+ t2.identifier(baseName2),
21200
+ lowerTrackedExpression(instr.value, ctx)
21201
+ )
21202
+ )
21063
21203
  );
21064
21204
  }
21065
21205
  if (instr.kind === "Expression") {
21066
- return t2.expressionStatement(lowerTrackedExpression(instr.value, ctx));
21206
+ return applyLoc(t2.expressionStatement(lowerTrackedExpression(instr.value, ctx)));
21067
21207
  }
21068
21208
  if (instr.kind === "Phi") {
21069
21209
  return null;
@@ -21072,6 +21212,9 @@ function lowerInstruction(instr, ctx) {
21072
21212
  }
21073
21213
  function lowerTerminator(block, ctx) {
21074
21214
  const { t: t2 } = ctx;
21215
+ const baseLoc = block.terminator.loc ?? // eslint-disable-next-line @typescript-eslint/no-explicit-any
21216
+ block.terminator.argument?.loc;
21217
+ const applyLoc = (stmts) => stmts.map((stmt) => setNodeLoc(stmt, baseLoc));
21075
21218
  switch (block.terminator.kind) {
21076
21219
  case "Return": {
21077
21220
  const prevRegion = ctx.currentRegion;
@@ -21084,14 +21227,14 @@ function lowerTerminator(block, ctx) {
21084
21227
  }
21085
21228
  ctx.inReturn = false;
21086
21229
  ctx.currentRegion = prevRegion;
21087
- return [t2.returnStatement(retExpr)];
21230
+ return applyLoc([t2.returnStatement(retExpr)]);
21088
21231
  }
21089
21232
  case "Throw":
21090
- return [t2.throwStatement(lowerTrackedExpression(block.terminator.argument, ctx))];
21233
+ return applyLoc([t2.throwStatement(lowerTrackedExpression(block.terminator.argument, ctx))]);
21091
21234
  case "Jump":
21092
- return [t2.expressionStatement(t2.stringLiteral(`jump ${block.terminator.target}`))];
21235
+ return applyLoc([t2.expressionStatement(t2.stringLiteral(`jump ${block.terminator.target}`))]);
21093
21236
  case "Branch":
21094
- return [
21237
+ return applyLoc([
21095
21238
  t2.ifStatement(
21096
21239
  lowerTrackedExpression(block.terminator.test, ctx),
21097
21240
  t2.blockStatement([
@@ -21101,9 +21244,9 @@ function lowerTerminator(block, ctx) {
21101
21244
  t2.expressionStatement(t2.stringLiteral(`goto ${block.terminator.alternate}`))
21102
21245
  ])
21103
21246
  )
21104
- ];
21247
+ ]);
21105
21248
  case "Switch":
21106
- return [
21249
+ return applyLoc([
21107
21250
  t2.switchStatement(
21108
21251
  lowerTrackedExpression(block.terminator.discriminant, ctx),
21109
21252
  block.terminator.cases.map(
@@ -21112,30 +21255,30 @@ function lowerTerminator(block, ctx) {
21112
21255
  ])
21113
21256
  )
21114
21257
  )
21115
- ];
21258
+ ]);
21116
21259
  case "ForOf": {
21117
21260
  const term = block.terminator;
21118
21261
  const varKind = term.variableKind ?? "const";
21119
21262
  const leftPattern = term.pattern ? term.pattern : t2.identifier(term.variable);
21120
- return [
21263
+ return applyLoc([
21121
21264
  t2.forOfStatement(
21122
21265
  t2.variableDeclaration(varKind, [t2.variableDeclarator(leftPattern)]),
21123
21266
  lowerExpression(term.iterable, ctx),
21124
21267
  t2.blockStatement([t2.expressionStatement(t2.stringLiteral(`body ${term.body}`))])
21125
21268
  )
21126
- ];
21269
+ ]);
21127
21270
  }
21128
21271
  case "ForIn": {
21129
21272
  const term = block.terminator;
21130
21273
  const varKind = term.variableKind ?? "const";
21131
21274
  const leftPattern = term.pattern ? term.pattern : t2.identifier(term.variable);
21132
- return [
21275
+ return applyLoc([
21133
21276
  t2.forInStatement(
21134
21277
  t2.variableDeclaration(varKind, [t2.variableDeclarator(leftPattern)]),
21135
21278
  lowerExpression(term.object, ctx),
21136
21279
  t2.blockStatement([t2.expressionStatement(t2.stringLiteral(`body ${term.body}`))])
21137
21280
  )
21138
- ];
21281
+ ]);
21139
21282
  }
21140
21283
  case "Try": {
21141
21284
  const term = block.terminator;
@@ -21151,20 +21294,20 @@ function lowerTerminator(block, ctx) {
21151
21294
  const finallyBlock = term.finallyBlock !== void 0 ? t2.blockStatement([
21152
21295
  t2.expressionStatement(t2.stringLiteral(`finally ${term.finallyBlock}`))
21153
21296
  ]) : null;
21154
- return [t2.tryStatement(tryBlock, catchClause, finallyBlock)];
21297
+ return applyLoc([t2.tryStatement(tryBlock, catchClause, finallyBlock)]);
21155
21298
  }
21156
21299
  case "Unreachable":
21157
- return [];
21300
+ return applyLoc([]);
21158
21301
  case "Break":
21159
- return [
21302
+ return applyLoc([
21160
21303
  t2.breakStatement(block.terminator.label ? t2.identifier(block.terminator.label) : null)
21161
- ];
21304
+ ]);
21162
21305
  case "Continue":
21163
- return [
21306
+ return applyLoc([
21164
21307
  t2.continueStatement(block.terminator.label ? t2.identifier(block.terminator.label) : null)
21165
- ];
21308
+ ]);
21166
21309
  default:
21167
- return [];
21310
+ return applyLoc([]);
21168
21311
  }
21169
21312
  }
21170
21313
  function attachHelperImports(ctx, body, t2) {
@@ -21303,7 +21446,7 @@ function lowerExpression(expr, ctx, isAssigned = false) {
21303
21446
  }
21304
21447
  ctx.expressionDepth = depth;
21305
21448
  try {
21306
- return lowerExpressionImpl(expr, ctx, isAssigned);
21449
+ return setNodeLoc(lowerExpressionImpl(expr, ctx, isAssigned), expr.loc);
21307
21450
  } finally {
21308
21451
  ctx.expressionDepth = depth - 1;
21309
21452
  }
@@ -21438,14 +21581,22 @@ function lowerExpressionImpl(expr, ctx, isAssigned = false) {
21438
21581
  const calleeIsMemoAccessor = !!calleeName && ctx.memoVars?.has(calleeName);
21439
21582
  const calleeIsSignalLike = !!calleeName && (ctx.signalVars?.has(calleeName) || ctx.storeVars?.has(calleeName));
21440
21583
  if (calleeIsMemoAccessor && !calleeIsSignalLike && expr.arguments.length > 0) {
21441
- const loweredArgs = expr.arguments.map((a) => lowerExpression(a, ctx));
21442
- return t2.callExpression(t2.callExpression(t2.identifier(calleeName), []), loweredArgs);
21584
+ const loweredArgs2 = expr.arguments.map((a) => lowerExpression(a, ctx));
21585
+ return t2.callExpression(t2.callExpression(t2.identifier(calleeName), []), loweredArgs2);
21443
21586
  }
21444
21587
  const lowerCallee = () => isIIFE ? withNonReactiveScope(ctx, () => lowerExpression(expr.callee, ctx)) : lowerExpression(expr.callee, ctx);
21445
- return t2.callExpression(
21446
- lowerCallee(),
21447
- expr.arguments.map((a) => lowerExpression(a, ctx))
21448
- );
21588
+ const isIteratingMethod = expr.callee.kind === "MemberExpression" && (expr.callee.property.kind === "Identifier" && ["map", "reduce", "forEach", "filter", "flatMap", "some", "every", "find"].includes(
21589
+ expr.callee.property.name
21590
+ ) || expr.callee.property.kind === "Literal" && ["map", "reduce", "forEach", "filter", "flatMap", "some", "every", "find"].includes(
21591
+ String(expr.callee.property.value)
21592
+ ));
21593
+ const loweredArgs = expr.arguments.map((a, idx) => {
21594
+ if (idx === 0 && isIteratingMethod && (a.kind === "ArrowFunction" || a.kind === "FunctionExpression")) {
21595
+ return withNoMemoAndDynamicHooks(ctx, () => lowerExpression(a, ctx));
21596
+ }
21597
+ return lowerExpression(a, ctx);
21598
+ });
21599
+ return t2.callExpression(lowerCallee(), loweredArgs);
21449
21600
  }
21450
21601
  case "MemberExpression":
21451
21602
  if (matchesListKeyPattern(expr, ctx)) {
@@ -22302,15 +22453,6 @@ function isStaticValue(expr) {
22302
22453
  if (!expr) return false;
22303
22454
  return expr.kind === "Literal";
22304
22455
  }
22305
- function isComponentLikeCallee(expr) {
22306
- if (expr.kind === "Identifier") {
22307
- return expr.name[0] === expr.name[0]?.toUpperCase();
22308
- }
22309
- if (expr.kind === "MemberExpression" || expr.kind === "OptionalMemberExpression") {
22310
- return isComponentLikeCallee(expr.object);
22311
- }
22312
- return false;
22313
- }
22314
22456
  function isLikelyTextExpression(expr, ctx) {
22315
22457
  let ok = true;
22316
22458
  const isReactiveIdentifier = (name) => {
@@ -22339,15 +22481,9 @@ function isLikelyTextExpression(expr, ctx) {
22339
22481
  ok = false;
22340
22482
  return;
22341
22483
  case "CallExpression":
22342
- case "OptionalCallExpression": {
22343
- if (isComponentLikeCallee(node.callee)) {
22344
- ok = false;
22345
- return;
22346
- }
22347
- visit(node.callee, true);
22348
- node.arguments.forEach((arg) => visit(arg));
22484
+ case "OptionalCallExpression":
22485
+ ok = false;
22349
22486
  return;
22350
- }
22351
22487
  case "MemberExpression":
22352
22488
  case "OptionalMemberExpression":
22353
22489
  visit(node.object, true);
@@ -22802,7 +22938,12 @@ function lowerIntrinsicElement(jsx, ctx) {
22802
22938
  t2.arrowFunctionExpression([], body)
22803
22939
  ];
22804
22940
  if (ctx.isComponentFn) {
22805
- memoArgs.push(t2.numericLiteral(reserveHookSlot2(ctx)));
22941
+ {
22942
+ const slot = reserveHookSlot2(ctx);
22943
+ if (slot >= 0) {
22944
+ memoArgs.push(t2.numericLiteral(slot));
22945
+ }
22946
+ }
22806
22947
  }
22807
22948
  return t2.callExpression(t2.callExpression(t2.identifier(RUNTIME_ALIASES.useMemo), memoArgs), []);
22808
22949
  }
@@ -23357,12 +23498,16 @@ function emitListChild(parentId, markerId, expr, statements, ctx) {
23357
23498
  const hoistedStatements = ctx.hoistedTemplateStatements;
23358
23499
  ctx.hoistedTemplates = prevHoistedTemplates;
23359
23500
  ctx.hoistedTemplateStatements = prevHoistedTemplateStatements;
23360
- if (isKeyed && (t2.isArrowFunctionExpression(callbackExpr) || t2.isFunctionExpression(callbackExpr))) {
23361
- const firstParam = callbackExpr.params[0];
23501
+ if (t2.isArrowFunctionExpression(callbackExpr) || t2.isFunctionExpression(callbackExpr)) {
23502
+ const [firstParam, secondParam] = callbackExpr.params;
23503
+ const overrides = {};
23362
23504
  if (t2.isIdentifier(firstParam)) {
23363
- const overrides = {
23364
- [firstParam.name]: () => t2.callExpression(t2.identifier(firstParam.name), [])
23365
- };
23505
+ overrides[firstParam.name] = () => t2.callExpression(t2.identifier(firstParam.name), []);
23506
+ }
23507
+ if (t2.isIdentifier(secondParam)) {
23508
+ overrides[secondParam.name] = () => t2.callExpression(t2.identifier(secondParam.name), []);
23509
+ }
23510
+ if (Object.keys(overrides).length > 0) {
23366
23511
  if (t2.isBlockStatement(callbackExpr.body)) {
23367
23512
  replaceIdentifiersWithOverrides(callbackExpr.body, overrides, t2, callbackExpr.type, "body");
23368
23513
  } else {
@@ -24256,10 +24401,9 @@ function lowerFunctionWithRegions(fn, ctx) {
24256
24401
  }
24257
24402
  }
24258
24403
  const params = finalParams;
24259
- const funcDecl = t2.functionDeclaration(
24260
- t2.identifier(fn.name ?? "fn"),
24261
- params,
24262
- t2.blockStatement(statements)
24404
+ const funcDecl = setNodeLoc(
24405
+ t2.functionDeclaration(t2.identifier(fn.name ?? "fn"), params, t2.blockStatement(statements)),
24406
+ fn.loc
24263
24407
  );
24264
24408
  ctx.needsCtx = prevNeedsCtx;
24265
24409
  ctx.shadowedNames = prevShadowed;
@@ -24348,10 +24492,44 @@ function isInsideNestedFunction(path) {
24348
24492
  function isInsideJSX(path) {
24349
24493
  return !!path.findParent((p) => p.isJSXElement?.() || p.isJSXFragment?.());
24350
24494
  }
24351
- function emitWarning(node, code, message, options, fileName) {
24352
- if (!options.onWarn) return;
24495
+ function parseSuppressionCodes(raw) {
24496
+ if (!raw) return void 0;
24497
+ const codes = raw.split(/[,\s]+/).map((c) => c.trim()).filter(Boolean);
24498
+ return codes.length > 0 ? new Set(codes) : void 0;
24499
+ }
24500
+ function parseSuppressions(comments) {
24501
+ if (!comments) return [];
24502
+ const suppressions = [];
24503
+ for (const comment of comments) {
24504
+ const match = comment.value.match(/fict-ignore(-next-line)?(?:\s+(.+))?/i);
24505
+ if (!match || !comment.loc) continue;
24506
+ suppressions.push({
24507
+ line: comment.loc.start.line,
24508
+ nextLine: !!match[1],
24509
+ codes: parseSuppressionCodes(match[2])
24510
+ });
24511
+ }
24512
+ return suppressions;
24513
+ }
24514
+ function shouldSuppressWarning(suppressions, code, line) {
24515
+ return suppressions.some((entry) => {
24516
+ const targetLine = entry.nextLine ? entry.line + 1 : entry.line;
24517
+ if (targetLine !== line) return false;
24518
+ if (!entry.codes || entry.codes.size === 0) return true;
24519
+ return entry.codes.has(code);
24520
+ });
24521
+ }
24522
+ function createWarningDispatcher(onWarn, suppressions) {
24523
+ if (!onWarn) return () => {
24524
+ };
24525
+ return (warning) => {
24526
+ if (shouldSuppressWarning(suppressions, warning.code, warning.line)) return;
24527
+ onWarn(warning);
24528
+ };
24529
+ }
24530
+ function emitWarning(node, code, message, warn, fileName) {
24353
24531
  const loc = node.loc?.start;
24354
- options.onWarn({
24532
+ warn({
24355
24533
  code,
24356
24534
  message,
24357
24535
  fileName,
@@ -24439,8 +24617,7 @@ function isDynamicPropertyAccess(node, t2) {
24439
24617
  if (!node.computed) return false;
24440
24618
  return !(t2.isStringLiteral(node.property) || t2.isNumericLiteral(node.property));
24441
24619
  }
24442
- function runWarningPass(programPath, stateVars, derivedVars, options, t2) {
24443
- const fileName = programPath.hub?.file?.opts?.filename || "<unknown>";
24620
+ function runWarningPass(programPath, stateVars, derivedVars, warn, fileName, t2) {
24444
24621
  const isStateRoot = (expr) => {
24445
24622
  const root = getRootIdentifier(expr, t2);
24446
24623
  return !!(root && stateVars.has(root.name));
@@ -24456,7 +24633,7 @@ function runWarningPass(programPath, stateVars, derivedVars, options, t2) {
24456
24633
  path.node,
24457
24634
  "FICT-M",
24458
24635
  "Direct mutation of nested property detected; use immutable update or $store helpers",
24459
- options,
24636
+ warn,
24460
24637
  fileName
24461
24638
  );
24462
24639
  if (isDynamicPropertyAccess(left, t2)) {
@@ -24464,7 +24641,7 @@ function runWarningPass(programPath, stateVars, derivedVars, options, t2) {
24464
24641
  path.node,
24465
24642
  "FICT-H",
24466
24643
  "Dynamic property access widens dependency tracking",
24467
- options,
24644
+ warn,
24468
24645
  fileName
24469
24646
  );
24470
24647
  }
@@ -24479,7 +24656,7 @@ function runWarningPass(programPath, stateVars, derivedVars, options, t2) {
24479
24656
  path.node,
24480
24657
  "FICT-M",
24481
24658
  "Direct mutation of nested property detected; use immutable update or $store helpers",
24482
- options,
24659
+ warn,
24483
24660
  fileName
24484
24661
  );
24485
24662
  if (isDynamicPropertyAccess(arg, t2)) {
@@ -24487,7 +24664,7 @@ function runWarningPass(programPath, stateVars, derivedVars, options, t2) {
24487
24664
  path.node,
24488
24665
  "FICT-H",
24489
24666
  "Dynamic property access widens dependency tracking",
24490
- options,
24667
+ warn,
24491
24668
  fileName
24492
24669
  );
24493
24670
  }
@@ -24503,7 +24680,7 @@ function runWarningPass(programPath, stateVars, derivedVars, options, t2) {
24503
24680
  path.node,
24504
24681
  "FICT-H",
24505
24682
  "Dynamic property access widens dependency tracking",
24506
- options,
24683
+ warn,
24507
24684
  fileName
24508
24685
  );
24509
24686
  }
@@ -24532,7 +24709,7 @@ function runWarningPass(programPath, stateVars, derivedVars, options, t2) {
24532
24709
  path.node,
24533
24710
  "FICT-R005",
24534
24711
  `Function captures reactive variable(s): ${Array.from(captured).join(", ")}. Pass them as parameters or memoize explicitly to avoid hidden dependencies.`,
24535
- options,
24712
+ warn,
24536
24713
  fileName
24537
24714
  );
24538
24715
  }
@@ -24563,7 +24740,7 @@ function runWarningPass(programPath, stateVars, derivedVars, options, t2) {
24563
24740
  path.node,
24564
24741
  "FICT-E001",
24565
24742
  "Effect has no reactive reads; it will run once. Consider removing $effect or adding dependencies.",
24566
- options,
24743
+ warn,
24567
24744
  fileName
24568
24745
  );
24569
24746
  }
@@ -24589,7 +24766,7 @@ function runWarningPass(programPath, stateVars, derivedVars, options, t2) {
24589
24766
  arg,
24590
24767
  "FICT-H",
24591
24768
  "State value passed to unknown function (black box); dependency tracking may be imprecise",
24592
- options,
24769
+ warn,
24593
24770
  fileName
24594
24771
  );
24595
24772
  break;
@@ -24605,7 +24782,7 @@ function runWarningPass(programPath, stateVars, derivedVars, options, t2) {
24605
24782
  path.node,
24606
24783
  "FICT-H",
24607
24784
  "Dynamic property access widens dependency tracking",
24608
- options,
24785
+ warn,
24609
24786
  fileName
24610
24787
  );
24611
24788
  }
@@ -24655,6 +24832,10 @@ function createHIREntrypointVisitor(t2, options) {
24655
24832
  Program: {
24656
24833
  exit(path) {
24657
24834
  const fileName = path.hub?.file?.opts?.filename || "<unknown>";
24835
+ const comments = path.hub?.file?.ast?.comments || [];
24836
+ const suppressions = parseSuppressions(comments);
24837
+ const warn = createWarningDispatcher(options.onWarn, suppressions);
24838
+ const optionsWithWarnings = { ...options, onWarn: warn };
24658
24839
  const isHookName2 = (name) => !!name && /^use[A-Z]/.test(name);
24659
24840
  const getFunctionName = (fnPath) => {
24660
24841
  return fnPath.isFunctionDeclaration() && fnPath.node.id ? fnPath.node.id.name : fnPath.isFunctionExpression() && fnPath.node.id ? fnPath.node.id.name : fnPath.parentPath.isVariableDeclarator() && t2.isIdentifier(fnPath.parentPath.node.id) && fnPath.parentPath.node.init === fnPath.node ? fnPath.parentPath.node.id.name : void 0;
@@ -24673,14 +24854,75 @@ function createHIREntrypointVisitor(t2, options) {
24673
24854
  return name && isComponentName(name) || isHookName2(name) || functionHasJSX(fnPath) || functionUsesStateLike(fnPath, t2);
24674
24855
  };
24675
24856
  const memoHasSideEffects = (fn) => {
24857
+ const pureCalls = new Set(
24858
+ Array.from(SAFE_FUNCTIONS).filter(
24859
+ (name) => !name.startsWith("console.") && name !== "Math.random"
24860
+ )
24861
+ );
24862
+ const effectfulCalls = /* @__PURE__ */ new Set([
24863
+ "$effect",
24864
+ "render",
24865
+ "fetch",
24866
+ "setTimeout",
24867
+ "setInterval",
24868
+ "clearTimeout",
24869
+ "clearInterval",
24870
+ "requestAnimationFrame",
24871
+ "cancelAnimationFrame"
24872
+ ]);
24873
+ const getCalleeName = (callee) => {
24874
+ if (t2.isIdentifier(callee)) return callee.name;
24875
+ if (t2.isMemberExpression(callee) && !callee.computed && t2.isIdentifier(callee.property) && t2.isIdentifier(callee.object)) {
24876
+ return `${callee.object.name}.${callee.property.name}`;
24877
+ }
24878
+ return null;
24879
+ };
24880
+ const mutatingMemberProps = /* @__PURE__ */ new Set([
24881
+ "push",
24882
+ "pop",
24883
+ "splice",
24884
+ "shift",
24885
+ "unshift",
24886
+ "sort",
24887
+ "reverse",
24888
+ "set",
24889
+ "add",
24890
+ "delete",
24891
+ "append",
24892
+ "appendChild",
24893
+ "remove",
24894
+ "removeChild",
24895
+ "setAttribute",
24896
+ "dispatchEvent",
24897
+ "replaceChildren",
24898
+ "replaceWith"
24899
+ ]);
24900
+ const isEffectfulCall = (node) => {
24901
+ const name = getCalleeName(node.callee);
24902
+ if (!name) return true;
24903
+ if (pureCalls.has(name)) return false;
24904
+ if (effectfulCalls.has(name)) return true;
24905
+ if (name.startsWith("console.") || name.startsWith("document.") || name.startsWith("window.")) {
24906
+ return true;
24907
+ }
24908
+ if (t2.isMemberExpression(node.callee) && !node.callee.computed && t2.isIdentifier(node.callee.property)) {
24909
+ const prop = node.callee.property.name;
24910
+ if (mutatingMemberProps.has(prop)) return true;
24911
+ if (t2.isIdentifier(node.callee.object) && (node.callee.object.name === "document" || node.callee.object.name === "window")) {
24912
+ return true;
24913
+ }
24914
+ }
24915
+ return false;
24916
+ };
24676
24917
  const checkNode = (node) => {
24677
24918
  if (!node) return false;
24678
24919
  if (t2.isAssignmentExpression(node) || t2.isUpdateExpression(node) || t2.isThrowStatement(node) || t2.isNewExpression(node)) {
24679
24920
  return true;
24680
24921
  }
24681
- if (t2.isCallExpression(node) && (t2.isIdentifier(node.callee) && node.callee.name === "$effect" || t2.isIdentifier(node.callee) && node.callee.name === "render")) {
24922
+ if (t2.isCallExpression(node) && isEffectfulCall(node)) {
24682
24923
  return true;
24683
24924
  }
24925
+ if (t2.isAwaitExpression(node)) return true;
24684
24926
  if (t2.isExpressionStatement(node)) return checkNode(node.expression);
24685
24927
  if (t2.isBlockStatement(node)) return node.body.some((stmt) => checkNode(stmt));
24686
24928
  if (t2.isReturnStatement(node)) return checkNode(node.argument);
@@ -24704,7 +24946,7 @@ function createHIREntrypointVisitor(t2, options) {
24704
24946
  fnPath.node,
24705
24947
  "FICT-C004",
24706
24948
  "Component has no return statement and will render nothing.",
24707
- options,
24949
+ warn,
24708
24950
  fileName
24709
24951
  );
24710
24952
  },
@@ -24722,7 +24964,7 @@ function createHIREntrypointVisitor(t2, options) {
24722
24964
  init,
24723
24965
  "FICT-C004",
24724
24966
  "Component has no return statement and will render nothing.",
24725
- options,
24967
+ warn,
24726
24968
  fileName
24727
24969
  );
24728
24970
  }
@@ -24772,7 +25014,7 @@ function createHIREntrypointVisitor(t2, options) {
24772
25014
  }
24773
25015
  }
24774
25016
  if (hasKey || hasUnknownSpread) return;
24775
- options.onWarn?.({
25017
+ warn({
24776
25018
  code: "FICT-J002",
24777
25019
  message: "Missing key prop in list rendering.",
24778
25020
  fileName,
@@ -24843,7 +25085,7 @@ function createHIREntrypointVisitor(t2, options) {
24843
25085
  fnPath.node,
24844
25086
  "FICT-C003",
24845
25087
  "Components should not be defined inside other components. Move this definition to module scope to preserve identity and performance.",
24846
- options,
25088
+ warn,
24847
25089
  fileName
24848
25090
  );
24849
25091
  },
@@ -24888,7 +25130,7 @@ function createHIREntrypointVisitor(t2, options) {
24888
25130
  callPath.node,
24889
25131
  "FICT-R004",
24890
25132
  "Reactive creation inside non-JSX control flow will not auto-dispose; wrap it in createScope/runInScope or move it into JSX-managed regions.",
24891
- options,
25133
+ warn,
24892
25134
  fileName
24893
25135
  );
24894
25136
  }
@@ -24923,7 +25165,7 @@ function createHIREntrypointVisitor(t2, options) {
24923
25165
  callPath.node.arguments.forEach((arg) => {
24924
25166
  if (t2.isIdentifier(arg) && stateVars.has(arg.name) && (!calleeId || !allowedStateCallees.has(calleeId))) {
24925
25167
  const loc = arg.loc?.start ?? callPath.node.loc?.start;
24926
- options.onWarn?.({
25168
+ warn({
24927
25169
  code: "FICT-S002",
24928
25170
  message: "State variable is passed as an argument; this passes a value snapshot and may escape component scope.",
24929
25171
  fileName,
@@ -24936,7 +25178,7 @@ function createHIREntrypointVisitor(t2, options) {
24936
25178
  const firstArg = callPath.node.arguments[0];
24937
25179
  if (firstArg && (t2.isArrowFunctionExpression(firstArg) || t2.isFunctionExpression(firstArg)) && memoHasSideEffects(firstArg)) {
24938
25180
  const loc = firstArg.loc?.start ?? callPath.node.loc?.start;
24939
- options.onWarn?.({
25181
+ warn({
24940
25182
  code: "FICT-M003",
24941
25183
  message: "Memo should not contain side effects.",
24942
25184
  fileName,
@@ -25041,10 +25283,10 @@ function createHIREntrypointVisitor(t2, options) {
25041
25283
  }
25042
25284
  });
25043
25285
  }
25044
- runWarningPass(path, stateVars, derivedVars, options, t2);
25286
+ runWarningPass(path, stateVars, derivedVars, warn, fileName, t2);
25045
25287
  const fileAst = t2.file(path.node);
25046
25288
  const hir = buildHIR(fileAst);
25047
- const lowered = lowerHIRWithRegions(hir, t2, options);
25289
+ const lowered = lowerHIRWithRegions(hir, t2, optionsWithWarnings);
25048
25290
  path.node.body = lowered.program.body;
25049
25291
  path.node.directives = lowered.program.directives;
25050
25292
  if (!process.env.FICT_SKIP_SCOPE_CRAWL) {