@barefootjs/cli 0.30.0 → 0.30.2

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 (2) hide show
  1. package/dist/index.js +106 -27
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -3374,13 +3374,13 @@ function csrSubstituteOnce(value2, env) {
3374
3374
  const recordSubstitution = (start2, end2, sub2) => {
3375
3375
  splices.push({ start: start2 - OFFSET, end: end2 - OFFSET, text: `(${sub2.replacement})` });
3376
3376
  };
3377
- const collectBindingNames4 = (name2, out) => {
3377
+ const collectBindingNames5 = (name2, out) => {
3378
3378
  if (ts4.isIdentifier(name2)) out.add(name2.text);
3379
3379
  else if (ts4.isObjectBindingPattern(name2)) {
3380
- for (const el of name2.elements) collectBindingNames4(el.name, out);
3380
+ for (const el of name2.elements) collectBindingNames5(el.name, out);
3381
3381
  } else if (ts4.isArrayBindingPattern(name2)) {
3382
3382
  for (const el of name2.elements) {
3383
- if (!ts4.isOmittedExpression(el)) collectBindingNames4(el.name, out);
3383
+ if (!ts4.isOmittedExpression(el)) collectBindingNames5(el.name, out);
3384
3384
  }
3385
3385
  }
3386
3386
  };
@@ -3388,7 +3388,7 @@ function csrSubstituteOnce(value2, env) {
3388
3388
  for (const stmt2 of block.statements) {
3389
3389
  if (ts4.isVariableStatement(stmt2)) {
3390
3390
  for (const decl of stmt2.declarationList.declarations) {
3391
- collectBindingNames4(decl.name, out);
3391
+ collectBindingNames5(decl.name, out);
3392
3392
  }
3393
3393
  } else if (ts4.isFunctionDeclaration(stmt2) && stmt2.name) {
3394
3394
  out.add(stmt2.name.text);
@@ -3431,7 +3431,7 @@ function csrSubstituteOnce(value2, env) {
3431
3431
  }
3432
3432
  if (ts4.isArrowFunction(node) || ts4.isFunctionExpression(node)) {
3433
3433
  const bound = /* @__PURE__ */ new Set();
3434
- for (const p of node.parameters) collectBindingNames4(p.name, bound);
3434
+ for (const p of node.parameters) collectBindingNames5(p.name, bound);
3435
3435
  if (node.body && ts4.isBlock(node.body)) {
3436
3436
  collectBlockDeclarations(node.body, bound);
3437
3437
  }
@@ -4961,17 +4961,94 @@ var init_html_template = __esm({
4961
4961
 
4962
4962
  // ../jsx/src/prop-rewrite.ts
4963
4963
  import ts5 from "typescript";
4964
+ function collectBindingNames(name2, out) {
4965
+ if (ts5.isIdentifier(name2)) {
4966
+ out.add(name2.text);
4967
+ return;
4968
+ }
4969
+ for (const el of name2.elements) {
4970
+ if (ts5.isBindingElement(el)) collectBindingNames(el.name, out);
4971
+ }
4972
+ }
4973
+ function scopeFrameOf(n) {
4974
+ if (ts5.isFunctionLike(n)) {
4975
+ const frame = /* @__PURE__ */ new Set();
4976
+ for (const p of n.parameters) collectBindingNames(p.name, frame);
4977
+ if ((ts5.isFunctionExpression(n) || ts5.isFunctionDeclaration(n)) && n.name) frame.add(n.name.text);
4978
+ return frame.size > 0 ? frame : null;
4979
+ }
4980
+ if (ts5.isBlock(n)) {
4981
+ const frame = /* @__PURE__ */ new Set();
4982
+ for (const st of n.statements) {
4983
+ if (ts5.isVariableStatement(st)) {
4984
+ for (const d of st.declarationList.declarations) collectBindingNames(d.name, frame);
4985
+ } else if (ts5.isFunctionDeclaration(st) && st.name) {
4986
+ frame.add(st.name.text);
4987
+ }
4988
+ }
4989
+ return frame.size > 0 ? frame : null;
4990
+ }
4991
+ if (ts5.isCatchClause(n) && n.variableDeclaration) {
4992
+ const frame = /* @__PURE__ */ new Set();
4993
+ collectBindingNames(n.variableDeclaration.name, frame);
4994
+ return frame.size > 0 ? frame : null;
4995
+ }
4996
+ return null;
4997
+ }
4998
+ function walkWithScope(root2, visit3) {
4999
+ const scopeStack = [];
5000
+ const isShadowed = (name2) => scopeStack.some((frame) => frame.has(name2));
5001
+ function rec(n, parent2) {
5002
+ const frame = scopeFrameOf(n);
5003
+ if (frame) scopeStack.push(frame);
5004
+ if (ts5.isIdentifier(n)) visit3(n, parent2, isShadowed(n.text));
5005
+ ts5.forEachChild(n, (child) => rec(child, n));
5006
+ if (frame) scopeStack.pop();
5007
+ }
5008
+ rec(root2);
5009
+ }
5010
+ function isNonValuePosition(n, parent2) {
5011
+ if (!parent2) return false;
5012
+ if (ts5.isPropertyAssignment(parent2) && parent2.name === n) return true;
5013
+ if (ts5.isPropertyAccessExpression(parent2) && parent2.name === n) return true;
5014
+ if (ts5.isQualifiedName(parent2) && parent2.right === n) return true;
5015
+ if ((ts5.isParameter(parent2) || ts5.isVariableDeclaration(parent2) || ts5.isBindingElement(parent2)) && parent2.name === n) return true;
5016
+ if (ts5.isTypeReferenceNode(parent2)) return true;
5017
+ return false;
5018
+ }
4964
5019
  function collectAstPropRefs(node, propNames, out) {
4965
- function visit3(n, parent2) {
4966
- if (ts5.isIdentifier(n) && propNames.has(n.text)) {
4967
- if (parent2 && ts5.isPropertyAssignment(parent2) && parent2.name === n) return;
4968
- if (parent2 && ts5.isShorthandPropertyAssignment(parent2) && parent2.name === n) return;
4969
- if (parent2 && ts5.isPropertyAccessExpression(parent2) && parent2.name === n) return;
4970
- out.add(n.text);
5020
+ walkWithScope(node, (n, parent2, shadowed) => {
5021
+ if (shadowed || !propNames.has(n.text)) return;
5022
+ if (parent2 && ts5.isShorthandPropertyAssignment(parent2) && parent2.name === n) return;
5023
+ if (isNonValuePosition(n, parent2)) return;
5024
+ out.add(n.text);
5025
+ });
5026
+ }
5027
+ function applyScopedPropRefRewrite(text, propRefs) {
5028
+ const prefix2 = "(";
5029
+ const sf = ts5.createSourceFile("__bf_prop_rewrite.ts", `${prefix2}${text}
5030
+ )`, ts5.ScriptTarget.Latest, true);
5031
+ const parseDiagnostics = sf.parseDiagnostics;
5032
+ if (parseDiagnostics && parseDiagnostics.length > 0) return null;
5033
+ const edits = [];
5034
+ walkWithScope(sf, (n, parent2, shadowed) => {
5035
+ if (shadowed || !propRefs.has(n.text)) return;
5036
+ if (isNonValuePosition(n, parent2)) return;
5037
+ const start2 = n.getStart(sf) - prefix2.length;
5038
+ const end2 = n.getEnd() - prefix2.length;
5039
+ if (start2 < 0 || end2 > text.length) return;
5040
+ if (parent2 && ts5.isShorthandPropertyAssignment(parent2) && parent2.name === n) {
5041
+ edits.push({ start: start2, end: end2, replacement: `${n.text}: ${PROPS_PARAM}.${n.text}` });
5042
+ return;
4971
5043
  }
4972
- ts5.forEachChild(n, (child) => visit3(child, n));
5044
+ edits.push({ start: start2, end: end2, replacement: `${PROPS_PARAM}.${n.text}` });
5045
+ });
5046
+ if (edits.length === 0) return text;
5047
+ let result2 = text;
5048
+ for (const edit of edits.sort((a, b) => b.start - a.start)) {
5049
+ result2 = result2.slice(0, edit.start) + edit.replacement + result2.slice(edit.end);
4973
5050
  }
4974
- visit3(node);
5051
+ return result2;
4975
5052
  }
4976
5053
  function applyRegexPropRefRewrite(text, propRefs) {
4977
5054
  const { protect, restore } = createTemplateAwareStringProtector();
@@ -4998,7 +5075,7 @@ function rewriteBarePropRefs(text, node, propNames, extraPropRefs) {
4998
5075
  }
4999
5076
  }
5000
5077
  if (foundPropRefs.size === 0) return void 0;
5001
- return applyRegexPropRefRewrite(text, foundPropRefs);
5078
+ return applyScopedPropRefRewrite(text, foundPropRefs) ?? applyRegexPropRefRewrite(text, foundPropRefs);
5002
5079
  }
5003
5080
  var init_prop_rewrite = __esm({
5004
5081
  "../jsx/src/prop-rewrite.ts"() {
@@ -12630,19 +12707,19 @@ function attrValueText(value2) {
12630
12707
  }
12631
12708
  return out.join(" ");
12632
12709
  }
12633
- function collectBindingNames(name2, out) {
12710
+ function collectBindingNames2(name2, out) {
12634
12711
  if (ts11.isIdentifier(name2)) {
12635
12712
  out.add(name2.text);
12636
12713
  return;
12637
12714
  }
12638
12715
  for (const el of name2.elements) {
12639
- if (ts11.isBindingElement(el)) collectBindingNames(el.name, out);
12716
+ if (ts11.isBindingElement(el)) collectBindingNames2(el.name, out);
12640
12717
  }
12641
12718
  }
12642
12719
  function collectPreambleDeclaredNames(stmt, out) {
12643
12720
  if (ts11.isVariableStatement(stmt)) {
12644
12721
  for (const decl of stmt.declarationList.declarations) {
12645
- collectBindingNames(decl.name, out);
12722
+ collectBindingNames2(decl.name, out);
12646
12723
  }
12647
12724
  } else if (ts11.isFunctionDeclaration(stmt) && stmt.name) {
12648
12725
  out.add(stmt.name.text);
@@ -13035,6 +13112,7 @@ function parseTemplateLiteral(expr, ctx2) {
13035
13112
  }
13036
13113
  function tryResolveTemplateSpanFromConst(expr, ctx2) {
13037
13114
  if (ts11.isIdentifier(expr)) {
13115
+ if (ctx2.loopParams.has(expr.text)) return null;
13038
13116
  const constInfo = findLocalConst(expr.text, ctx2.analyzer);
13039
13117
  if (!constInfo) return null;
13040
13118
  const ast = parseConstInitializer(constInfo);
@@ -13046,6 +13124,7 @@ function tryResolveTemplateSpanFromConst(expr, ctx2) {
13046
13124
  }
13047
13125
  if (ts11.isElementAccessExpression(expr)) {
13048
13126
  if (!ts11.isIdentifier(expr.expression)) return null;
13127
+ if (ctx2.loopParams.has(expr.expression.text)) return null;
13049
13128
  const constInfo = findLocalConst(expr.expression.text, ctx2.analyzer);
13050
13129
  if (!constInfo) return null;
13051
13130
  const ast = parseConstInitializer(constInfo);
@@ -18938,7 +19017,7 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
18938
19017
  const isConst = (stmt.declarationList.flags & ts15.NodeFlags.Const) !== 0;
18939
19018
  if (!isConst) return NO2("map-callback preamble declares a mutable binding (let/var)");
18940
19019
  for (const decl of stmt.declarationList.declarations) {
18941
- collectBindingNames2(decl.name, declaredNames);
19020
+ collectBindingNames3(decl.name, declaredNames);
18942
19021
  if (!decl.initializer) {
18943
19022
  return NO2("map-callback preamble has a declaration with no initializer");
18944
19023
  }
@@ -18961,14 +19040,14 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
18961
19040
  for (const declared of declaredNames) freeNames.delete(declared);
18962
19041
  return { lazySafe: true, facts: { declaredNames, freeNames } };
18963
19042
  }
18964
- function collectBindingNames2(name2, out) {
19043
+ function collectBindingNames3(name2, out) {
18965
19044
  if (ts15.isIdentifier(name2)) {
18966
19045
  out.add(name2.text);
18967
19046
  return;
18968
19047
  }
18969
19048
  for (const element of name2.elements) {
18970
19049
  if (ts15.isOmittedExpression(element)) continue;
18971
- collectBindingNames2(element.name, out);
19050
+ collectBindingNames3(element.name, out);
18972
19051
  }
18973
19052
  }
18974
19053
  function findImpureNode(root2, primableNames) {
@@ -22814,18 +22893,18 @@ function isJsxLike(expr) {
22814
22893
  }
22815
22894
  function collectArrowParamNames(arrow) {
22816
22895
  const names = /* @__PURE__ */ new Set();
22817
- for (const p of arrow.parameters) collectBindingNames3(p.name, names);
22896
+ for (const p of arrow.parameters) collectBindingNames4(p.name, names);
22818
22897
  return names;
22819
22898
  }
22820
- function collectBindingNames3(name2, out) {
22899
+ function collectBindingNames4(name2, out) {
22821
22900
  const push = Array.isArray(out) ? (n) => out.push(n) : (n) => out.add(n);
22822
22901
  if (ts18.isIdentifier(name2)) {
22823
22902
  push(name2.text);
22824
22903
  } else if (ts18.isObjectBindingPattern(name2)) {
22825
- name2.elements.forEach((el) => collectBindingNames3(el.name, out));
22904
+ name2.elements.forEach((el) => collectBindingNames4(el.name, out));
22826
22905
  } else if (ts18.isArrayBindingPattern(name2)) {
22827
22906
  name2.elements.forEach((el) => {
22828
- if (!ts18.isOmittedExpression(el)) collectBindingNames3(el.name, out);
22907
+ if (!ts18.isOmittedExpression(el)) collectBindingNames4(el.name, out);
22829
22908
  });
22830
22909
  }
22831
22910
  }
@@ -22834,12 +22913,12 @@ function collectFreeIdentifiers(arrow) {
22834
22913
  const bound = [];
22835
22914
  for (const p of arrow.parameters) {
22836
22915
  const names = [];
22837
- collectBindingNames3(p.name, names);
22916
+ collectBindingNames4(p.name, names);
22838
22917
  bound.push(...names);
22839
22918
  }
22840
22919
  function pushBindings(name2) {
22841
22920
  const names = [];
22842
- collectBindingNames3(name2, names);
22921
+ collectBindingNames4(name2, names);
22843
22922
  bound.push(...names);
22844
22923
  return names;
22845
22924
  }
@@ -22937,7 +23016,7 @@ function collectModuleScopeNames(sourceFile) {
22937
23016
  if (ts18.isFunctionDeclaration(stmt) && stmt.name) names.add(stmt.name.text);
22938
23017
  else if (ts18.isClassDeclaration(stmt) && stmt.name) names.add(stmt.name.text);
22939
23018
  else if (ts18.isVariableStatement(stmt)) {
22940
- for (const decl of stmt.declarationList.declarations) collectBindingNames3(decl.name, names);
23019
+ for (const decl of stmt.declarationList.declarations) collectBindingNames4(decl.name, names);
22941
23020
  } else if (ts18.isImportDeclaration(stmt) && stmt.importClause) {
22942
23021
  const ic = stmt.importClause;
22943
23022
  if (ic.name) names.add(ic.name.text);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/cli",
3
- "version": "0.30.0",
3
+ "version": "0.30.2",
4
4
  "description": "CLI for agent-driven UI component discovery and scaffolding",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -29,11 +29,11 @@
29
29
  "dependencies": {
30
30
  "esbuild": "^0.25.0",
31
31
  "typescript": "^5.0.0",
32
- "@barefootjs/client": "0.30.0",
33
- "@barefootjs/shared": "0.30.0"
32
+ "@barefootjs/client": "0.30.2",
33
+ "@barefootjs/shared": "0.30.2"
34
34
  },
35
35
  "devDependencies": {
36
- "@barefootjs/jsx": "0.30.0",
36
+ "@barefootjs/jsx": "0.30.2",
37
37
  "@types/node": "^22.0.0",
38
38
  "@happy-dom/global-registrator": "^20.0.11",
39
39
  "happy-dom": "^20.0.11"