bestax-migrate 2.40.0 → 2.41.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.
Files changed (48) hide show
  1. package/README.md +1 -1
  2. package/dist/sources/_shared/bestax-floor.d.ts +49 -0
  3. package/dist/sources/_shared/bestax-floor.d.ts.map +1 -1
  4. package/dist/sources/_shared/bestax-floor.js +84 -0
  5. package/dist/sources/_shared/bestax-import.d.ts +16 -1
  6. package/dist/sources/_shared/bestax-import.d.ts.map +1 -1
  7. package/dist/sources/_shared/bestax-import.js +67 -2
  8. package/dist/sources/_shared/bestax-release.d.ts +27 -0
  9. package/dist/sources/_shared/bestax-release.d.ts.map +1 -0
  10. package/dist/sources/_shared/bestax-release.js +79 -0
  11. package/dist/sources/_shared/deps-common.d.ts +11 -9
  12. package/dist/sources/_shared/deps-common.d.ts.map +1 -1
  13. package/dist/sources/_shared/deps-common.js +25 -11
  14. package/dist/sources/_shared/imports.d.ts +30 -1
  15. package/dist/sources/_shared/imports.d.ts.map +1 -1
  16. package/dist/sources/_shared/imports.js +67 -0
  17. package/dist/sources/_shared/jsx-utils.d.ts +8 -0
  18. package/dist/sources/_shared/jsx-utils.d.ts.map +1 -1
  19. package/dist/sources/_shared/jsx-utils.js +13 -0
  20. package/dist/sources/bloomer/deps.d.ts +2 -3
  21. package/dist/sources/bloomer/deps.d.ts.map +1 -1
  22. package/dist/sources/bloomer/deps.js +9 -9
  23. package/dist/sources/bloomer/mapping.d.ts +0 -10
  24. package/dist/sources/bloomer/mapping.d.ts.map +1 -1
  25. package/dist/sources/bloomer/mapping.js +2 -13
  26. package/dist/sources/bloomer/transform.d.ts +3 -2
  27. package/dist/sources/bloomer/transform.d.ts.map +1 -1
  28. package/dist/sources/bloomer/transform.js +44 -35
  29. package/dist/sources/bulma-classes/deps.d.ts +2 -2
  30. package/dist/sources/bulma-classes/deps.js +2 -2
  31. package/dist/sources/bulma-classes/html.js +1 -1
  32. package/dist/sources/rbx/deps.d.ts +2 -3
  33. package/dist/sources/rbx/deps.d.ts.map +1 -1
  34. package/dist/sources/rbx/deps.js +9 -9
  35. package/dist/sources/rbx/index.d.ts.map +1 -1
  36. package/dist/sources/rbx/index.js +6 -0
  37. package/dist/sources/rbx/transform.d.ts +3 -2
  38. package/dist/sources/rbx/transform.d.ts.map +1 -1
  39. package/dist/sources/rbx/transform.js +100 -54
  40. package/dist/sources/react-bulma-components/deps.d.ts +2 -2
  41. package/dist/sources/react-bulma-components/deps.d.ts.map +1 -1
  42. package/dist/sources/react-bulma-components/deps.js +10 -9
  43. package/dist/sources/react-bulma-components/transform.d.ts +3 -2
  44. package/dist/sources/react-bulma-components/transform.d.ts.map +1 -1
  45. package/dist/sources/react-bulma-components/transform.js +47 -47
  46. package/dist/types.d.ts +4 -3
  47. package/dist/types.d.ts.map +1 -1
  48. package/package.json +6 -6
@@ -7,8 +7,9 @@
7
7
  * 2. per-element: structural special → rename → responsive flattening →
8
8
  * component prop map → universal helper props → badge/tooltip wrapping
9
9
  * 3. rewrite imports: drop rbx, add one merged bestax-bulma import; keep a
10
- * trimmed rbx import (with a TODO) only for components that have no
11
- * bestax equivalent (Generic, Tile, List, …)
10
+ * trimmed rbx import (with a TODO) only for what another TODO left
11
+ * using it, such as a component with no bestax equivalent (Generic,
12
+ * Tile, List, …)
12
13
  *
13
14
  * Anything unsafe gets a `// TODO(bestax-migrate)` comment on the enclosing
14
15
  * statement plus an entry in the run report.
@@ -20,15 +21,16 @@
20
21
  * not a rename.
21
22
  */
22
23
  import { BADGE_PROPS, MAPPING, TOOLTIP_PROPS, UNIVERSAL_PROPS, resolveMapping, } from './mapping.js';
23
- import { addTodo, attributesOf, findAttr, forgetJsxParens, jsxNameParts, literalValueOf, removeAttr, renameElement, reprintDirectives, } from '../_shared/jsx-utils.js';
24
+ import { addTodo, attributesOf, findAttr, forgetJsxParens, jsxNameParts, literalValueOf, removeAttr, renameElement, replaceChain, reprintDirectives, } from '../_shared/jsx-utils.js';
24
25
  import { applyBackgroundColor } from '../_shared/background-props.js';
25
26
  import { applyPropAction, applyUniversalProps } from '../_shared/props.js';
26
27
  import { applyTextColor } from '../_shared/text-color-props.js';
27
28
  import { enforcePolymorphicProps } from '../_shared/polymorphic.js';
28
29
  import { askForModalName } from '../_shared/modal-name.js';
29
- import { BESTAX, bestaxValueLocals, buildBestaxImport, carryPrunedComments, placeBestaxImport, seedBestaxImport, } from '../_shared/bestax-import.js';
30
+ import { BESTAX, bestaxValueLocals, buildBestaxImport, carryPrunedComments, noteRetainedImport, placeBestaxImport, seedBestaxImport, } from '../_shared/bestax-import.js';
30
31
  import { rewriteStylesheetImports } from '../_shared/css-imports.js';
31
- import { collectBoundNames, makeAliasRegistry, makeReserve, nameOf, prefersTabs, resolvesToBinding, } from '../_shared/imports.js';
32
+ import { bestaxFloorFor, classNameWaitsFor, heldForRelease, releaseHoldMessage, makeReferenceHold, } from '../_shared/bestax-floor.js';
33
+ import { collectBoundNames, flatReExportTarget, makeAliasRegistry, makeDestructuringPlan, makeReserve, nameOf, prefersTabs, resolvesToBinding, } from '../_shared/imports.js';
32
34
  import { flattenResponsiveProps, RESPONSIVE_KINDS } from './responsive.js';
33
35
  import { runSpecial } from './specials.js';
34
36
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -51,6 +53,9 @@ export default function transform(fileInfo, api, options = {}) {
51
53
  overrides: new WeakMap(),
52
54
  dirty: false,
53
55
  };
56
+ // The oldest bestax-bulma release this file can count on, for the targets
57
+ // in CLASSNAME_SINCE (`_shared/bestax-floor.ts`).
58
+ const bestaxFloor = bestaxFloorFor(fileInfo.path, options.bestaxPackages, options.deps);
54
59
  // ---- 1. Collect rbx imports -------------------------------------------
55
60
  /** local identifier → imported rbx name ('*' for namespace imports). */
56
61
  const imports = new Map();
@@ -146,9 +151,7 @@ export default function transform(fileInfo, api, options = {}) {
146
151
  /**
147
152
  * Locals a re-export names. Pruning the declaration that binds one of them
148
153
  * (`const { Header } = Card; export { Header };`) leaves the specifier
149
- * pointing at nothing, so those declarations are kept: the value-reference
150
- * pass rewrites their initialiser to the bestax component, and the export
151
- * goes on re-exporting the same member.
154
+ * pointing at nothing, so those declarations are kept.
152
155
  */
153
156
  const reExported = new Set();
154
157
  root.find(j.ExportSpecifier).forEach(p => {
@@ -157,20 +160,19 @@ export default function transform(fileInfo, api, options = {}) {
157
160
  reExported.add(local.name);
158
161
  });
159
162
  // ---- 1b. Resolve `const { Item } = Card` destructuring -----------------
163
+ const destructurings = makeDestructuringPlan(ctx);
160
164
  root.find(j.VariableDeclarator).forEach(path => {
161
165
  const node = path.node;
162
166
  if (node.id?.type !== 'ObjectPattern' || node.init?.type !== 'Identifier')
163
167
  return;
164
168
  const base = node.init.name;
165
- const baseAlias = aliasAt(base, path);
166
- const imported = imports.get(base) ?? baseAlias?.join('.');
167
- if (!imported || imported === '*')
168
- return;
169
- if (!imports.has(base) && !baseAlias)
170
- return;
171
- const basePath = imports.has(base)
169
+ // By binding: a parameter named like the import is the caller's object.
170
+ const fromImport = imports.has(base) && resolvesToBinding(path, base, programScope);
171
+ const basePath = fromImport
172
172
  ? [imports.get(base)]
173
- : baseAlias;
173
+ : aliasAt(base, path);
174
+ if (!basePath || basePath[0] === '*')
175
+ return;
174
176
  let allResolved = true;
175
177
  for (const prop of node.id.properties) {
176
178
  if ((prop.type === 'ObjectProperty' || prop.type === 'Property') &&
@@ -200,24 +202,32 @@ export default function transform(fileInfo, api, options = {}) {
200
202
  allResolved = false;
201
203
  }
202
204
  }
203
- const exportsAnAlias = node.id.properties.some((prop) => (prop.type === 'ObjectProperty' || prop.type === 'Property') &&
205
+ // The names re-exported as they are. One the value-reference pass writes
206
+ // as bestax's own flat name needs no declaration.
207
+ const reExports = node.id.properties
208
+ .filter((prop) => (prop.type === 'ObjectProperty' || prop.type === 'Property') &&
204
209
  prop.value?.type === 'Identifier' &&
205
- reExported.has(prop.value.name));
206
- if (allResolved && !exportsAnAlias) {
207
- const declaration = path.parent;
208
- if (declaration?.node?.type === 'VariableDeclaration' &&
209
- declaration.node.declarations.length === 1) {
210
- declaration.prune();
211
- }
212
- else {
213
- path.prune();
214
- }
215
- ctx.dirty = true;
210
+ reExported.has(prop.value.name) &&
211
+ !flatReExportTarget(resolveMapping([...basePath, nameOf(prop.key)])))
212
+ .map((prop) => `\`${prop.value.name}\``);
213
+ if (allResolved && reExports.length === 0) {
214
+ destructurings.prune(path, basePath[0]);
216
215
  }
217
216
  else {
218
- addTodo(ctx, path, 'imports', `could not resolve every name destructured from \`${base}\`; migrate the leftovers by hand`);
217
+ destructurings.keep(path, basePath[0], allResolved
218
+ ? `kept for the re-export of ${reExports.join(', ')}; migrate that first`
219
+ : `could not resolve every name destructured from \`${base}\`; migrate the leftovers by hand`);
219
220
  }
220
221
  });
222
+ /**
223
+ * Whether an element `heldForRelease` names stays rbx's. One reached
224
+ * through an alias destructured from its root converts all the same, with
225
+ * the TODO, since that declaration goes with the other names destructured
226
+ * beside it.
227
+ */
228
+ function heldStays(path, head) {
229
+ return aliasAt(head, path) === undefined;
230
+ }
221
231
  /** Resolve a JSX name into a canonical rbx component path, or null. */
222
232
  function resolveJsxPath(name, at) {
223
233
  const parts = jsxNameParts(name);
@@ -280,6 +290,8 @@ export default function transform(fileInfo, api, options = {}) {
280
290
  }
281
291
  return null;
282
292
  };
293
+ // 1b's decisions land here, before the bindings below are read.
294
+ destructurings.settle();
283
295
  // ---- 1c. Collect local bindings so new imports never collide -----------
284
296
  const bound = collectBoundNames(j, root, RBX);
285
297
  // Seed the reserved set with the local names of rbx imports that CANNOT be
@@ -300,8 +312,12 @@ export default function transform(fileInfo, api, options = {}) {
300
312
  // `partial`, but `<Icon.Unknown>` retains it), and when the local name
301
313
  // differs from the imported one that retained binding can collide with a
302
314
  // bestax local for a completely different component. An unaliased import
303
- // is safe: its name already means the same component on both sides.
304
- if (!entry || entry.status === 'todo' || local !== imported) {
315
+ // is safe: its name already means the same component on both sides. A
316
+ // root a kept destructuring names (1b) is retained already.
317
+ if (!entry ||
318
+ entry.status === 'todo' ||
319
+ local !== imported ||
320
+ ctx.retained.has(imported)) {
305
321
  bound.add(local);
306
322
  }
307
323
  }
@@ -315,14 +331,20 @@ export default function transform(fileInfo, api, options = {}) {
315
331
  // Scanned rather than reserved wholesale: adding every partial root to
316
332
  // `bound` would alias them in every file that uses one, whether or not
317
333
  // anything is actually retained.
334
+ // An element the release keeps rbx's (`heldForRelease`, `heldStays`)
335
+ // retains its root too.
318
336
  root.find(j.JSXElement).forEach(path => {
319
337
  const head = jsxNameParts(path.node.openingElement.name)?.[0];
320
338
  if (!head || !imports.has(head))
321
339
  return;
322
340
  const parts = resolveJsxPath(path.node.openingElement.name, path);
323
341
  const mapping = parts ? resolveMapping(parts) : undefined;
324
- if (!mapping || mapping.status === 'todo')
342
+ if (!mapping ||
343
+ mapping.status === 'todo' ||
344
+ (heldStays(path, head) &&
345
+ heldForRelease(path.node, mapping.target, bestaxFloor))) {
325
346
  bound.add(head);
347
+ }
326
348
  });
327
349
  // The same root can be retained by a VALUE chain -- `const X = Icon.Unknown`
328
350
  // -- which only the value-reference pass discovers, after `reserve` has
@@ -356,8 +378,12 @@ export default function transform(fileInfo, api, options = {}) {
356
378
  }
357
379
  }
358
380
  const mapping = resolveMapping(chain);
359
- if (!mapping || mapping.status === 'todo')
381
+ // A chain the release keeps rbx's (`holdReference`) retains it too.
382
+ if (!mapping ||
383
+ mapping.status === 'todo' ||
384
+ (mapping.target && classNameWaitsFor(mapping.target, bestaxFloor))) {
360
385
  bound.add(head);
386
+ }
361
387
  });
362
388
  ctx.reserve = makeReserve(ctx, bound);
363
389
  const bestaxImportState = seedBestaxImport(ctx, root);
@@ -465,6 +491,15 @@ export default function transform(fileInfo, api, options = {}) {
465
491
  target = override;
466
492
  if (!target)
467
493
  return;
494
+ const held = heldForRelease(element, target, bestaxFloor);
495
+ if (held) {
496
+ const stays = jsxHead !== undefined && heldStays(path, jsxHead);
497
+ addTodo(ctx, path, `component:${dotted}`, releaseHoldMessage(target, held, stays ? 'rbx' : undefined));
498
+ if (stays) {
499
+ ctx.retained.add(rbxPath[0]);
500
+ return;
501
+ }
502
+ }
468
503
  // Rename to the bestax name, aliasing the import root on collision.
469
504
  const [targetRoot, ...targetRest] = target.split('.');
470
505
  const localTarget = [ctx.reserve(targetRoot), ...targetRest].join('.');
@@ -528,6 +563,15 @@ export default function transform(fileInfo, api, options = {}) {
528
563
  // generic "referenced as a value" branch, emitting a spurious TODO and
529
564
  // marking the root retained when it was not.
530
565
  const handledValueRefs = new WeakSet();
566
+ // A reference to a target that waits for a release stays rbx's, retaining
567
+ // its root, unless it is reached through an alias, whose declaration goes
568
+ // with the names destructured beside it (`heldStays`).
569
+ const holdReference = makeReferenceHold(ctx, bestaxFloor, 'rbx', imported => {
570
+ if (imported === '*')
571
+ namespaceStillReferenced = true;
572
+ else
573
+ ctx.retained.add(imported);
574
+ });
531
575
  root.find(j.Identifier).forEach(path => {
532
576
  // find(Identifier) also matches JSXIdentifier (a subtype) — JSX names
533
577
  // were already handled by the element walker above.
@@ -535,6 +579,8 @@ export default function transform(fileInfo, api, options = {}) {
535
579
  return;
536
580
  if (handledValueRefs.has(path.node))
537
581
  return;
582
+ if (destructurings.kept.has(path.node))
583
+ return;
538
584
  const name = path.node.name;
539
585
  // A name bound by `const { Footer } = Card` is in `aliases`, not
540
586
  // `imports` — and the destructuring pass has already deleted the
@@ -586,11 +632,9 @@ export default function transform(fileInfo, api, options = {}) {
586
632
  return;
587
633
  const exportedName = nameOf(parentNode.exported ?? parentNode.local);
588
634
  const mapping = aliasPath ? resolveMapping(aliasPath) : MAPPING[imported];
589
- if (mapping &&
590
- mapping.status !== 'todo' &&
591
- mapping.target &&
592
- !mapping.target.includes('.')) {
593
- const local = ctx.reserve(mapping.target);
635
+ const flat = flatReExportTarget(mapping);
636
+ if (flat) {
637
+ const local = ctx.reserve(flat);
594
638
  // Replace the node: recast reprints a specifier whose identifiers were
595
639
  // swapped in place in its original shorthand form, dropping the `as`.
596
640
  path.parent.replace(j.exportSpecifier.from({
@@ -640,8 +684,10 @@ export default function transform(fileInfo, api, options = {}) {
640
684
  outer.node.property?.type === 'Identifier') {
641
685
  memberPath.push(nameOf(outer.node.property));
642
686
  const next = outer.parent;
687
+ // Not into `[…]`, which the rebuilt chain would drop.
643
688
  if (next?.node?.type === 'MemberExpression' &&
644
- next.node.object === outer.node) {
689
+ next.node.object === outer.node &&
690
+ !next.node.computed) {
645
691
  outer = next;
646
692
  }
647
693
  else {
@@ -654,6 +700,9 @@ export default function transform(fileInfo, api, options = {}) {
654
700
  memberMapping.status !== 'todo' &&
655
701
  memberMapping.target &&
656
702
  !memberMapping.special) {
703
+ if (holdReference(outer, memberMapping.target, imported, !!aliasPath)) {
704
+ return;
705
+ }
657
706
  if (memberMapping.target === dotted) {
658
707
  if (isNamespace) {
659
708
  // `rbx.Button` → `Button`: the namespace prefix has to go, so
@@ -665,7 +714,7 @@ export default function transform(fileInfo, api, options = {}) {
665
714
  for (const part of rest) {
666
715
  rebuilt = j.memberExpression(rebuilt, j.identifier(part));
667
716
  }
668
- outer.replace(rebuilt);
717
+ replaceChain(outer, rebuilt, handledValueRefs);
669
718
  ctx.dirty = true;
670
719
  return;
671
720
  }
@@ -680,7 +729,7 @@ export default function transform(fileInfo, api, options = {}) {
680
729
  for (const part of aliasRest) {
681
730
  rebuilt = j.memberExpression(rebuilt, j.identifier(part));
682
731
  }
683
- outer.replace(rebuilt);
732
+ replaceChain(outer, rebuilt, handledValueRefs);
684
733
  ctx.dirty = true;
685
734
  return;
686
735
  }
@@ -696,7 +745,7 @@ export default function transform(fileInfo, api, options = {}) {
696
745
  if (!memberMapping.target.includes('.')) {
697
746
  // Flat target (Column.Group → Columns): swap the whole chain.
698
747
  const local = ctx.reserve(memberMapping.target);
699
- outer.replace(j.identifier(local));
748
+ replaceChain(outer, j.identifier(local), handledValueRefs);
700
749
  ctx.dirty = true;
701
750
  return;
702
751
  }
@@ -709,7 +758,7 @@ export default function transform(fileInfo, api, options = {}) {
709
758
  for (const part of targetRest) {
710
759
  rebuilt = j.memberExpression(rebuilt, j.identifier(part));
711
760
  }
712
- outer.replace(rebuilt);
761
+ replaceChain(outer, rebuilt, handledValueRefs);
713
762
  ctx.dirty = true;
714
763
  return;
715
764
  }
@@ -742,6 +791,11 @@ export default function transform(fileInfo, api, options = {}) {
742
791
  shorthandMapping.status !== 'todo' &&
743
792
  shorthandMapping.target &&
744
793
  !shorthandMapping.special) {
794
+ if (holdReference(path, shorthandMapping.target, imported, !!aliasPath)) {
795
+ handledValueRefs.add(parentNode.key);
796
+ handledValueRefs.add(parentNode.value);
797
+ return;
798
+ }
745
799
  const [root, ...rest] = shorthandMapping.target.split('.');
746
800
  const local = ctx.reserve(root);
747
801
  let value = j.identifier(local);
@@ -778,6 +832,8 @@ export default function transform(fileInfo, api, options = {}) {
778
832
  mapping.status !== 'todo' &&
779
833
  mapping.target &&
780
834
  !mapping.special) {
835
+ if (holdReference(path, mapping.target, imported, !!aliasPath))
836
+ return;
781
837
  const [root, ...rest] = mapping.target.split('.');
782
838
  const local = ctx.reserve(root);
783
839
  if (rest.length > 0) {
@@ -804,7 +860,6 @@ export default function transform(fileInfo, api, options = {}) {
804
860
  });
805
861
  // ---- 3. Rewrite imports -----------------------------------------------
806
862
  if (imports.size > 0) {
807
- const retainedNames = [...ctx.retained].sort((a, b) => a.localeCompare(b));
808
863
  const bestaxImport = buildBestaxImport(ctx, bestaxImportState);
809
864
  let inserted = false;
810
865
  // A retained rbx specifier must never collide with a bestax import local
@@ -840,16 +895,7 @@ export default function transform(fileInfo, api, options = {}) {
840
895
  }
841
896
  if (keepSpecifiers.length > 0) {
842
897
  node.specifiers = keepSpecifiers;
843
- // Only when named/namespace bindings are being retained. An import
844
- // kept solely for a broken default binding has no names to list, and
845
- // already carries its own "rbx has no default export" TODO.
846
- if (retainedNames.length > 0) {
847
- node.comments = node.comments ?? [];
848
- const text = ` TODO(bestax-migrate): ${retainedNames.join(', ')} ${retainedNames.length === 1 ? 'has' : 'have'} no bestax-bulma equivalent yet — migrate and remove this import`;
849
- if (!node.comments.some((c) => c.value === text)) {
850
- node.comments.push(j.commentLine(text, true, false));
851
- }
852
- }
898
+ noteRetainedImport(ctx, path, ctx.retained);
853
899
  }
854
900
  else {
855
901
  carryPrunedComments(node, path, bestaxImportState.existing?.node ?? bestaxImport);
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * package.json migration: swap react-bulma-components for
3
3
  * @allxsmith/bestax-bulma, move Bulma to v1, and replace the dead node-sass
4
- * with dart-sass. Pure data-in/data-out — the CLI owns file IO, and no
5
- * package manager is ever invoked (the report tells the user to install).
4
+ * with dart-sass. No package manager is ever invoked (the report tells the
5
+ * user to install).
6
6
  */
7
7
  import type { DependenciesUpdate } from '../../types.js';
8
8
  export declare const updateDependencies: DependenciesUpdate;
@@ -1 +1 @@
1
- {"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../../../src/sources/react-bulma-components/deps.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAUzD,eAAO,MAAM,kBAAkB,EAAE,kBAuChC,CAAC"}
1
+ {"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../../../src/sources/react-bulma-components/deps.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAUzD,eAAO,MAAM,kBAAkB,EAAE,kBAwChC,CAAC"}
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * package.json migration: swap react-bulma-components for
3
3
  * @allxsmith/bestax-bulma, move Bulma to v1, and replace the dead node-sass
4
- * with dart-sass. Pure data-in/data-out — the CLI owns file IO, and no
5
- * package manager is ever invoked (the report tells the user to install).
4
+ * with dart-sass. No package manager is ever invoked (the report tells the
5
+ * user to install).
6
6
  */
7
7
  import { DEP_SECTIONS, addBestax, moveBulmaToV1, openManifest, replaceNodeSass, reportPeerRanges, } from '../_shared/deps-common.js';
8
8
  export const updateDependencies = (filePath, pkg, collector, options) => {
@@ -17,14 +17,15 @@ export const updateDependencies = (filePath, pkg, collector, options) => {
17
17
  manifest.note(`removed react-bulma-components from ${name}`);
18
18
  }
19
19
  }
20
- // The transform deliberately RETAINS imports for components with no bestax
21
- // equivalent (Element, Tile) so a partially migrated app still runs.
22
- // Removing the package from the manifest strands exactly those imports once
23
- // the user runs the install the report asks for, so say so rather than
24
- // letting them find out at build time. rbx has carried this warning since
25
- // it shipped; this source retains imports the same way and did not.
20
+ // Files can still import the library after the run: a trimmed import the
21
+ // transform kept, so a partially migrated app still runs, one it couldn't
22
+ // rewrite, a file it couldn't parse or doesn't read (`.vue`, `.astro`).
23
+ // Removing the package from the manifest strands those imports once the
24
+ // user runs the install the report asks for, so say so rather than letting
25
+ // them find out at build time. rbx has carried this warning since it
26
+ // shipped; this source retains imports the same way and did not.
26
27
  if (removedSource && options.sourceStillImported) {
27
- manifest.report('deps', 'react-bulma-components was removed from package.json, but some files still import it for components with no bestax equivalent — resolve those `TODO(bestax-migrate)` imports before installing, or re-add react-bulma-components until you have');
28
+ manifest.report('deps', 'react-bulma-components was removed from package.json, but some files still import it, and installing would leave those imports unresolved: migrate every remaining import of react-bulma-components (the ones the codemod kept are marked `TODO(bestax-migrate)`) before installing, or re-add react-bulma-components until you have');
28
29
  }
29
30
  addBestax(manifest);
30
31
  moveBulmaToV1(manifest, options.bulmaReferenced);
@@ -7,8 +7,9 @@
7
7
  * 2. per-element: structural special → rename → responsive flattening →
8
8
  * component prop map → universal modifier props
9
9
  * 3. rewrite imports: drop RBC, add one merged bestax-bulma import; keep a
10
- * trimmed RBC import (with a TODO) only for components that have no
11
- * bestax equivalent (Element, Tile)
10
+ * trimmed RBC import (with a TODO) only for what another TODO left
11
+ * using it, such as a component with no bestax equivalent (Element,
12
+ * Tile)
12
13
  *
13
14
  * Anything unsafe gets a `// TODO(bestax-migrate)` comment on the enclosing
14
15
  * statement plus an entry in the run report.
@@ -1 +1 @@
1
- {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/sources/react-bulma-components/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAyCvD,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,GAAG,EACR,OAAO,GAAE,gBAAqB,GAC7B,MAAM,GAAG,SAAS,CAuxBpB"}
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/sources/react-bulma-components/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AA6CvD,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,GAAG,EACR,OAAO,GAAE,gBAAqB,GAC7B,MAAM,GAAG,SAAS,CAmxBpB"}
@@ -7,23 +7,24 @@
7
7
  * 2. per-element: structural special → rename → responsive flattening →
8
8
  * component prop map → universal modifier props
9
9
  * 3. rewrite imports: drop RBC, add one merged bestax-bulma import; keep a
10
- * trimmed RBC import (with a TODO) only for components that have no
11
- * bestax equivalent (Element, Tile)
10
+ * trimmed RBC import (with a TODO) only for what another TODO left
11
+ * using it, such as a component with no bestax equivalent (Element,
12
+ * Tile)
12
13
  *
13
14
  * Anything unsafe gets a `// TODO(bestax-migrate)` comment on the enclosing
14
15
  * statement plus an entry in the run report.
15
16
  */
16
17
  import { MAPPING, UNIVERSAL_PROPS, resolveMapping } from './mapping.js';
17
- import { addTodo, attributesOf, forgetJsxParens, jsxNameParts, renameElement, reprintDirectives, } from '../_shared/jsx-utils.js';
18
+ import { addTodo, attributesOf, forgetJsxParens, jsxNameParts, renameElement, replaceChain, reprintDirectives, } from '../_shared/jsx-utils.js';
18
19
  import { applyBackgroundColor } from '../_shared/background-props.js';
19
20
  import { applyPropAction, applyUniversalProps } from '../_shared/props.js';
20
21
  import { applyTextColor } from '../_shared/text-color-props.js';
21
22
  import { enforcePolymorphicProps } from '../_shared/polymorphic.js';
22
23
  import { keepBaseDisplay } from '../_shared/display.js';
23
24
  import { askForModalName } from '../_shared/modal-name.js';
24
- import { bestaxValueLocals, buildBestaxImport, carryPrunedComments, placeBestaxImport, seedBestaxImport, } from '../_shared/bestax-import.js';
25
+ import { bestaxValueLocals, buildBestaxImport, carryPrunedComments, noteRetainedImport, placeBestaxImport, seedBestaxImport, } from '../_shared/bestax-import.js';
25
26
  import { rewriteStylesheetImports } from '../_shared/css-imports.js';
26
- import { collectBoundNames, makeAliasRegistry, makeReserve, nameOf, prefersTabs, resolvesToBinding, } from '../_shared/imports.js';
27
+ import { collectBoundNames, flatReExportTarget, makeAliasRegistry, makeDestructuringPlan, makeReserve, nameOf, prefersTabs, resolvesToBinding, } from '../_shared/imports.js';
27
28
  import { applyColorVariant } from './color-variant.js';
28
29
  import { flattenResponsiveProps } from './responsive.js';
29
30
  import { RESPONSIVE_KINDS, runSpecial } from './specials.js';
@@ -111,9 +112,7 @@ export default function transform(fileInfo, api, options = {}) {
111
112
  /**
112
113
  * Locals a re-export names. Pruning the declaration that binds one of them
113
114
  * (`const { Header } = Card; export { Header };`) leaves the specifier
114
- * pointing at nothing, so those declarations are kept: the value-reference
115
- * pass rewrites their initialiser to the bestax component, and the export
116
- * goes on re-exporting the same member.
115
+ * pointing at nothing, so those declarations are kept.
117
116
  */
118
117
  const reExported = new Set();
119
118
  root.find(j.ExportSpecifier).forEach(p => {
@@ -122,20 +121,19 @@ export default function transform(fileInfo, api, options = {}) {
122
121
  reExported.add(local.name);
123
122
  });
124
123
  // ---- 1b. Resolve `const { Input, Field: F } = Form` destructuring -----
124
+ const destructurings = makeDestructuringPlan(ctx);
125
125
  root.find(j.VariableDeclarator).forEach(path => {
126
126
  const node = path.node;
127
127
  if (node.id?.type !== 'ObjectPattern' || node.init?.type !== 'Identifier')
128
128
  return;
129
129
  const base = node.init.name;
130
- const baseAlias = aliasAt(base, path);
131
- const imported = imports.get(base) ?? baseAlias?.join('.');
132
- if (!imported || imported === '*')
133
- return;
134
- if (!imports.has(base) && !baseAlias)
135
- return;
136
- const basePath = imports.has(base)
130
+ // By binding: a parameter named like the import is the caller's object.
131
+ const fromImport = imports.has(base) && resolvesToBinding(path, base, programScope);
132
+ const basePath = fromImport
137
133
  ? [imports.get(base)]
138
- : baseAlias;
134
+ : aliasAt(base, path);
135
+ if (!basePath || basePath[0] === '*')
136
+ return;
139
137
  let allResolved = true;
140
138
  for (const prop of node.id.properties) {
141
139
  if ((prop.type === 'ObjectProperty' || prop.type === 'Property') &&
@@ -165,22 +163,21 @@ export default function transform(fileInfo, api, options = {}) {
165
163
  allResolved = false;
166
164
  }
167
165
  }
168
- const exportsAnAlias = node.id.properties.some((prop) => (prop.type === 'ObjectProperty' || prop.type === 'Property') &&
166
+ // The names re-exported as they are. One the value-reference pass writes
167
+ // as bestax's own flat name needs no declaration.
168
+ const reExports = node.id.properties
169
+ .filter((prop) => (prop.type === 'ObjectProperty' || prop.type === 'Property') &&
169
170
  prop.value?.type === 'Identifier' &&
170
- reExported.has(prop.value.name));
171
- if (allResolved && !exportsAnAlias) {
172
- const declaration = path.parent;
173
- if (declaration?.node?.type === 'VariableDeclaration' &&
174
- declaration.node.declarations.length === 1) {
175
- declaration.prune();
176
- }
177
- else {
178
- path.prune();
179
- }
180
- ctx.dirty = true;
171
+ reExported.has(prop.value.name) &&
172
+ !flatReExportTarget(resolveMapping([...basePath, nameOf(prop.key)])))
173
+ .map((prop) => `\`${prop.value.name}\``);
174
+ if (allResolved && reExports.length === 0) {
175
+ destructurings.prune(path, basePath[0]);
181
176
  }
182
177
  else {
183
- addTodo(ctx, path, 'imports', `could not resolve every name destructured from \`${base}\`; migrate the leftovers by hand`);
178
+ destructurings.keep(path, basePath[0], allResolved
179
+ ? `kept for the re-export of ${reExports.join(', ')}; migrate that first`
180
+ : `could not resolve every name destructured from \`${base}\`; migrate the leftovers by hand`);
184
181
  }
185
182
  });
186
183
  /** Resolve a JSX name into a canonical RBC component path, or null. */
@@ -204,6 +201,8 @@ export default function transform(fileInfo, api, options = {}) {
204
201
  return [imported, ...rest];
205
202
  }
206
203
  ctx.resolve = resolveJsxPath;
204
+ // 1b's decisions land here, before the bindings below are read.
205
+ destructurings.settle();
207
206
  // ---- 1c. Collect local bindings so new imports never collide -----------
208
207
  // A file may already bind names like `Field` or `Control` (components,
209
208
  // variables, function params); importing the bestax component under the
@@ -224,8 +223,12 @@ export default function transform(fileInfo, api, options = {}) {
224
223
  // `partial`, but `<Icon.Unknown>` retains it), and when the local name
225
224
  // differs from the imported one that retained binding can collide with a
226
225
  // bestax local for a completely different component. An unaliased import
227
- // is safe: its name already means the same component on both sides.
228
- if (!entry || entry.status === 'todo' || local !== imported) {
226
+ // is safe: its name already means the same component on both sides. A
227
+ // root a kept destructuring names (1b) is retained already.
228
+ if (!entry ||
229
+ entry.status === 'todo' ||
230
+ local !== imported ||
231
+ ctx.retained.has(imported)) {
229
232
  bound.add(local);
230
233
  }
231
234
  }
@@ -383,6 +386,8 @@ export default function transform(fileInfo, api, options = {}) {
383
386
  return;
384
387
  if (handledValueRefs.has(path.node))
385
388
  return;
389
+ if (destructurings.kept.has(path.node))
390
+ return;
386
391
  const name = path.node.name;
387
392
  // A name bound by `const { Field } = Form` lives in `aliases`, not
388
393
  // `imports`, and the destructuring pass has already deleted the
@@ -436,11 +441,9 @@ export default function transform(fileInfo, api, options = {}) {
436
441
  return;
437
442
  const exportedName = nameOf(parentNode.exported ?? parentNode.local);
438
443
  const mapping = aliasPath ? resolveMapping(aliasPath) : MAPPING[imported];
439
- if (mapping &&
440
- mapping.status !== 'todo' &&
441
- mapping.target &&
442
- !mapping.target.includes('.')) {
443
- const local = ctx.reserve(mapping.target);
444
+ const flat = flatReExportTarget(mapping);
445
+ if (flat) {
446
+ const local = ctx.reserve(flat);
444
447
  // Replace the node: recast reprints a specifier whose identifiers were
445
448
  // swapped in place in its original shorthand form, dropping the `as`.
446
449
  path.parent.replace(j.exportSpecifier.from({
@@ -490,8 +493,10 @@ export default function transform(fileInfo, api, options = {}) {
490
493
  outer.node.property?.type === 'Identifier') {
491
494
  memberPath.push(nameOf(outer.node.property));
492
495
  const next = outer.parent;
496
+ // Not into `[…]`, which the rebuilt chain would drop.
493
497
  if (next?.node?.type === 'MemberExpression' &&
494
- next.node.object === outer.node) {
498
+ next.node.object === outer.node &&
499
+ !next.node.computed) {
495
500
  outer = next;
496
501
  }
497
502
  else {
@@ -515,7 +520,7 @@ export default function transform(fileInfo, api, options = {}) {
515
520
  for (const part of rest) {
516
521
  rebuilt = j.memberExpression(rebuilt, j.identifier(part));
517
522
  }
518
- outer.replace(rebuilt);
523
+ replaceChain(outer, rebuilt, handledValueRefs);
519
524
  ctx.dirty = true;
520
525
  return;
521
526
  }
@@ -531,7 +536,7 @@ export default function transform(fileInfo, api, options = {}) {
531
536
  for (const part of aliasRest) {
532
537
  rebuilt = j.memberExpression(rebuilt, j.identifier(part));
533
538
  }
534
- outer.replace(rebuilt);
539
+ replaceChain(outer, rebuilt, handledValueRefs);
535
540
  ctx.dirty = true;
536
541
  return;
537
542
  }
@@ -547,7 +552,7 @@ export default function transform(fileInfo, api, options = {}) {
547
552
  if (!memberMapping.target.includes('.')) {
548
553
  // Flat target (Icon.Text → IconText): swap the whole chain.
549
554
  const local = ctx.reserve(memberMapping.target);
550
- outer.replace(j.identifier(local));
555
+ replaceChain(outer, j.identifier(local), handledValueRefs);
551
556
  ctx.dirty = true;
552
557
  return;
553
558
  }
@@ -560,7 +565,7 @@ export default function transform(fileInfo, api, options = {}) {
560
565
  for (const part of targetRest) {
561
566
  rebuilt = j.memberExpression(rebuilt, j.identifier(part));
562
567
  }
563
- outer.replace(rebuilt);
568
+ replaceChain(outer, rebuilt, handledValueRefs);
564
569
  ctx.dirty = true;
565
570
  return;
566
571
  }
@@ -654,7 +659,6 @@ export default function transform(fileInfo, api, options = {}) {
654
659
  });
655
660
  // ---- 3. Rewrite imports -----------------------------------------------
656
661
  if (imports.size > 0) {
657
- const retainedNames = [...ctx.retained].sort((a, b) => a.localeCompare(b));
658
662
  const bestaxImport = buildBestaxImport(ctx, bestaxImportState);
659
663
  let inserted = false;
660
664
  // A retained RBC specifier must never collide with a bestax import local
@@ -681,11 +685,7 @@ export default function transform(fileInfo, api, options = {}) {
681
685
  }
682
686
  if (keepSpecifiers.length > 0) {
683
687
  node.specifiers = keepSpecifiers;
684
- node.comments = node.comments ?? [];
685
- const text = ` TODO(bestax-migrate): ${retainedNames.join(', ')} ${retainedNames.length === 1 ? 'has' : 'have'} no bestax-bulma equivalent yet — migrate and remove this import`;
686
- if (!node.comments.some((c) => c.value === text)) {
687
- node.comments.push(j.commentLine(text, true, false));
688
- }
688
+ noteRetainedImport(ctx, path, ctx.retained);
689
689
  }
690
690
  else {
691
691
  carryPrunedComments(node, path, bestaxImportState.existing?.node ?? bestaxImport);