bestax-migrate 2.40.1 → 2.41.1

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 (53) 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 +50 -1
  15. package/dist/sources/_shared/imports.d.ts.map +1 -1
  16. package/dist/sources/_shared/imports.js +121 -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/_shared/props.d.ts +13 -0
  21. package/dist/sources/_shared/props.d.ts.map +1 -1
  22. package/dist/sources/_shared/props.js +36 -0
  23. package/dist/sources/bloomer/deps.d.ts +2 -3
  24. package/dist/sources/bloomer/deps.d.ts.map +1 -1
  25. package/dist/sources/bloomer/deps.js +9 -9
  26. package/dist/sources/bloomer/mapping.d.ts +3 -22
  27. package/dist/sources/bloomer/mapping.d.ts.map +1 -1
  28. package/dist/sources/bloomer/mapping.js +5 -45
  29. package/dist/sources/bloomer/transform.d.ts +3 -2
  30. package/dist/sources/bloomer/transform.d.ts.map +1 -1
  31. package/dist/sources/bloomer/transform.js +50 -39
  32. package/dist/sources/bulma-classes/deps.d.ts +2 -2
  33. package/dist/sources/bulma-classes/deps.js +2 -2
  34. package/dist/sources/rbx/deps.d.ts +2 -3
  35. package/dist/sources/rbx/deps.d.ts.map +1 -1
  36. package/dist/sources/rbx/deps.js +9 -9
  37. package/dist/sources/rbx/index.d.ts.map +1 -1
  38. package/dist/sources/rbx/index.js +6 -0
  39. package/dist/sources/rbx/mapping.d.ts +8 -0
  40. package/dist/sources/rbx/mapping.d.ts.map +1 -1
  41. package/dist/sources/rbx/mapping.js +53 -0
  42. package/dist/sources/rbx/transform.d.ts +3 -2
  43. package/dist/sources/rbx/transform.d.ts.map +1 -1
  44. package/dist/sources/rbx/transform.js +162 -72
  45. package/dist/sources/react-bulma-components/deps.d.ts +2 -2
  46. package/dist/sources/react-bulma-components/deps.d.ts.map +1 -1
  47. package/dist/sources/react-bulma-components/deps.js +10 -9
  48. package/dist/sources/react-bulma-components/transform.d.ts +3 -2
  49. package/dist/sources/react-bulma-components/transform.d.ts.map +1 -1
  50. package/dist/sources/react-bulma-components/transform.js +46 -63
  51. package/dist/types.d.ts +4 -3
  52. package/dist/types.d.ts.map +1 -1
  53. package/package.json +6 -6
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * package.json migration for an app that styled plain markup with Bulma:
3
- * bestax-bulma comes in, and nothing goes out. Pure data-in/data-out: no
4
- * package manager is ever invoked.
3
+ * bestax-bulma comes in, and nothing goes out. No package manager is ever
4
+ * invoked.
5
5
  *
6
6
  * Under the default `--css keep` the app's styling stack is left as it is:
7
7
  * converted elements render the same classes, which the app's own Bulma
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * package.json migration: swap rbx for @allxsmith/bestax-bulma and clear out
3
- * the stylesheet dependencies rbx dragged in with it. Pure data-in/data-out —
4
- * the CLI owns file IO, and no package manager is ever invoked (the report
5
- * tells the user to install).
3
+ * the stylesheet dependencies rbx dragged in with it. No package manager is
4
+ * ever invoked (the report tells the user to install).
6
5
  *
7
6
  * This is the step with the biggest visible payoff for an rbx app. Unlike
8
7
  * react-bulma-components, which peer-depends on Bulma and lets the app pick a
@@ -1 +1 @@
1
- {"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../../../src/sources/rbx/deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAwBzD,eAAO,MAAM,kBAAkB,EAAE,kBAgGhC,CAAC"}
1
+ {"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../../../src/sources/rbx/deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAwBzD,eAAO,MAAM,kBAAkB,EAAE,kBAiGhC,CAAC"}
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * package.json migration: swap rbx for @allxsmith/bestax-bulma and clear out
3
- * the stylesheet dependencies rbx dragged in with it. Pure data-in/data-out —
4
- * the CLI owns file IO, and no package manager is ever invoked (the report
5
- * tells the user to install).
3
+ * the stylesheet dependencies rbx dragged in with it. No package manager is
4
+ * ever invoked (the report tells the user to install).
6
5
  *
7
6
  * This is the step with the biggest visible payoff for an rbx app. Unlike
8
7
  * react-bulma-components, which peer-depends on Bulma and lets the app pick a
@@ -66,13 +65,14 @@ export const updateDependencies = (filePath, pkg, collector, options) => {
66
65
  // rbx pinned Bulma 0.7.5 as a direct dependency, so the bump almost always
67
66
  // fires.
68
67
  const bulma = moveBulmaToV1(manifest, options.bulmaReferenced);
69
- // The transform deliberately keeps a trimmed rbx import for components
70
- // with no bestax equivalent (Tile, Generic, List, …) so a partially
71
- // migrated app still runs. Removing the package from the manifest strands
72
- // exactly those imports once the user runs the install the report asks for,
73
- // so say so rather than letting them find out at build time.
68
+ // Files can still import rbx after the run: a trimmed import the transform
69
+ // kept, so a partially migrated app still runs, one it couldn't rewrite, a
70
+ // file it couldn't parse or doesn't read (`.vue`, `.astro`). Removing the
71
+ // package from the manifest strands those imports once the user runs the
72
+ // install the report asks for, so say so rather than letting them find out
73
+ // at build time.
74
74
  if (removed.includes('rbx') && options.sourceStillImported) {
75
- manifest.report('deps', 'rbx 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 rbx until you have');
75
+ manifest.report('deps', 'rbx was removed from package.json, but some files still import it, and installing would leave those imports unresolved: migrate every remaining import of rbx (the ones the codemod kept are marked `TODO(bestax-migrate)`) before installing, or re-add rbx until you have');
76
76
  }
77
77
  // The headline result: rbx pinned Bulma 0.7.5 as a DIRECT dependency, so
78
78
  // removing rbx is what frees the app to choose its own Bulma version.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sources/rbx/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAKtD,eAAO,MAAM,GAAG,EAAE,eAMjB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sources/rbx/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAMtD,eAAO,MAAM,GAAG,EAAE,eAWjB,CAAC"}
@@ -1,9 +1,15 @@
1
+ import { readBestaxPackages } from '../_shared/bestax-floor.js';
1
2
  import transform from './transform.js';
2
3
  import { transformStyles } from './styles.js';
3
4
  import { updateDependencies } from './deps.js';
4
5
  export const rbx = {
5
6
  name: 'rbx',
6
7
  label: 'rbx (v2) → @allxsmith/bestax-bulma',
8
+ // Which bestax-bulma each package gets, for `Pagination.Ellipsis`'s
9
+ // className.
10
+ analyzeProject: targets => ({
11
+ bestaxPackages: readBestaxPackages(targets),
12
+ }),
7
13
  transform,
8
14
  transformStyles,
9
15
  updateDependencies,
@@ -34,6 +34,14 @@ export declare const AS_OK: PropAction;
34
34
  * would silently produce a type error rather than a TODO.
35
35
  */
36
36
  export declare const UNIVERSAL_PROPS: Record<string, PropAction>;
37
+ /**
38
+ * The Bulma class one of the universal helpers above stood for, written on
39
+ * a target that takes no helper props (`HELPERLESS_TARGETS` in
40
+ * `_shared/props.ts`) or named in its TODO. `value` is the helper's literal
41
+ * value, undefined when it is dynamic; `textColor` and `backgroundColor` are
42
+ * left to their own passes, which flag them on these targets.
43
+ */
44
+ export declare function helperClassHint(name: string, value: string | number | boolean | undefined): string | null;
37
45
  /** rbx badge helper props → bestax `<Badge>` props. */
38
46
  export declare const BADGE_PROPS: Record<string, string | null>;
39
47
  /** rbx tooltip helper props → bestax `<Tooltip>` props. */
@@ -1 +1 @@
1
- {"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../../../src/sources/rbx/mapping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAoBnE;;;;;;;;GAQG;AACH,eAAO,MAAM,KAAK,EAAE,UAAe,CAAC;AAEpC;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CA4CtD,CAAC;AAEF,uDAAuD;AACvD,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAOrD,CAAC;AAEF,2DAA2D;AAC3D,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAQvD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAShE,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CA2tBpD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CA2FhD,CAAC;AAEF,sDAAsD;AACtD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,gBAAgB,GAAG,SAAS,CAM3E"}
1
+ {"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../../../src/sources/rbx/mapping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAoBnE;;;;;;;;GAQG;AACH,eAAO,MAAM,KAAK,EAAE,UAAe,CAAC;AAEpC;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CA4CtD,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAC3C,MAAM,GAAG,IAAI,CA8Cf;AAED,uDAAuD;AACvD,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAOrD,CAAC;AAEF,2DAA2D;AAC3D,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAQvD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAShE,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CA2tBpD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CA2FhD,CAAC;AAEF,sDAAsD;AACtD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,gBAAgB,GAAG,SAAS,CAM3E"}
@@ -87,6 +87,59 @@ export const UNIVERSAL_PROPS = {
87
87
  todo: `\`innerRef\` has no counterpart; rename it to \`ref\` if this target forwards one, otherwise move it onto a wrapping element you control (${DOCS}/api)`,
88
88
  },
89
89
  };
90
+ /**
91
+ * The Bulma class one of the universal helpers above stood for, written on
92
+ * a target that takes no helper props (`HELPERLESS_TARGETS` in
93
+ * `_shared/props.ts`) or named in its TODO. `value` is the helper's literal
94
+ * value, undefined when it is dynamic; `textColor` and `backgroundColor` are
95
+ * left to their own passes, which flag them on these targets.
96
+ */
97
+ export function helperClassHint(name, value) {
98
+ const v = typeof value === 'string' || typeof value === 'number'
99
+ ? String(value)
100
+ : undefined;
101
+ switch (name) {
102
+ case 'textAlign':
103
+ return `has-text-${v ?? '<alignment>'}`;
104
+ case 'textTransform':
105
+ return `is-${v ?? '<transform>'}`;
106
+ case 'textWeight':
107
+ return `has-text-weight-${v ?? '<weight>'}`;
108
+ case 'textSize':
109
+ return `is-size-${v ?? '<size>'}`;
110
+ case 'pull':
111
+ return `is-pulled-${v ?? '<side>'}`;
112
+ case 'italic':
113
+ return 'is-italic';
114
+ case 'clearfix':
115
+ return 'is-clearfix';
116
+ case 'clipped':
117
+ return 'is-clipped';
118
+ case 'overlay':
119
+ return 'is-overlay';
120
+ case 'hidden':
121
+ return 'is-hidden';
122
+ case 'invisible':
123
+ return 'is-invisible';
124
+ case 'srOnly':
125
+ return 'is-sr-only';
126
+ // Bulma v1 removed `is-marginless` and `is-paddingless`; these do their job.
127
+ case 'marginless':
128
+ return 'm-0';
129
+ case 'paddingless':
130
+ return 'p-0';
131
+ case 'radiusless':
132
+ return 'is-radiusless';
133
+ case 'shadowless':
134
+ return 'is-shadowless';
135
+ case 'unselectable':
136
+ return 'is-unselectable';
137
+ case 'relative':
138
+ return 'is-relative';
139
+ default:
140
+ return null;
141
+ }
142
+ }
90
143
  /** rbx badge helper props → bestax `<Badge>` props. */
91
144
  export const BADGE_PROPS = {
92
145
  badge: 'content',
@@ -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.
@@ -1 +1 @@
1
- {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/sources/rbx/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAuDvD,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,GAAG,EACR,OAAO,GAAE,gBAAqB,GAC7B,MAAM,GAAG,SAAS,CA4+BpB"}
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/sources/rbx/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AA6EvD,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,GAAG,EACR,OAAO,GAAE,gBAAqB,GAC7B,MAAM,GAAG,SAAS,CA+lCpB"}
@@ -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.
@@ -19,16 +20,17 @@
19
20
  * `Tooltip` components. So `<Button tooltip="hi" />` is a wrapping rewrite,
20
21
  * not a rename.
21
22
  */
22
- 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';
23
+ import { BADGE_PROPS, MAPPING, TOOLTIP_PROPS, UNIVERSAL_PROPS, helperClassHint, resolveMapping, } from './mapping.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
- import { applyPropAction, applyUniversalProps } from '../_shared/props.js';
26
+ import { HELPERLESS_TARGETS, NO_CLASSNAME_TARGETS, applyPropAction, applyUniversalProps, mergeClass, } 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, releaseRaise, makeReferenceHold, } from '../_shared/bestax-floor.js';
33
+ import { collectBoundNames, flatReExportTarget, keptForExport, makeAliasRegistry, makeDestructuringPlan, makeReserve, nameOf, namesNoLocal, prefersTabs, reExportedLocals, 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();
@@ -143,34 +148,21 @@ export default function transform(fileInfo, api, options = {}) {
143
148
  // against the binding it actually resolves to rather than matched by name.
144
149
  const programScope = root.find(j.Program).paths()[0]?.scope;
145
150
  const { register: registerAlias, aliasAt, anyAlias } = makeAliasRegistry();
146
- /**
147
- * Locals a re-export names. Pruning the declaration that binds one of them
148
- * (`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.
152
- */
153
- const reExported = new Set();
154
- root.find(j.ExportSpecifier).forEach(p => {
155
- const local = p.node.local ?? p.node.exported;
156
- if (local?.type === 'Identifier')
157
- reExported.add(local.name);
158
- });
151
+ const reExported = reExportedLocals(j, root);
159
152
  // ---- 1b. Resolve `const { Item } = Card` destructuring -----------------
153
+ const destructurings = makeDestructuringPlan(ctx);
160
154
  root.find(j.VariableDeclarator).forEach(path => {
161
155
  const node = path.node;
162
156
  if (node.id?.type !== 'ObjectPattern' || node.init?.type !== 'Identifier')
163
157
  return;
164
158
  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)
159
+ // By binding: a parameter named like the import is the caller's object.
160
+ const fromImport = imports.has(base) && resolvesToBinding(path, base, programScope);
161
+ const basePath = fromImport
172
162
  ? [imports.get(base)]
173
- : baseAlias;
163
+ : aliasAt(base, path);
164
+ if (!basePath || basePath[0] === '*')
165
+ return;
174
166
  let allResolved = true;
175
167
  for (const prop of node.id.properties) {
176
168
  if ((prop.type === 'ObjectProperty' || prop.type === 'Property') &&
@@ -200,24 +192,23 @@ export default function transform(fileInfo, api, options = {}) {
200
192
  allResolved = false;
201
193
  }
202
194
  }
203
- const exportsAnAlias = node.id.properties.some((prop) => (prop.type === 'ObjectProperty' || prop.type === 'Property') &&
204
- 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;
216
- }
217
- else {
218
- addTodo(ctx, path, 'imports', `could not resolve every name destructured from \`${base}\`; migrate the leftovers by hand`);
219
- }
195
+ const kept = allResolved
196
+ ? keptForExport(path, basePath, reExported, resolveMapping)
197
+ : `could not resolve every name destructured from \`${base}\`; migrate the leftovers by hand`;
198
+ if (kept)
199
+ destructurings.keep(path, basePath[0], kept);
200
+ else
201
+ destructurings.prune(path, basePath[0]);
220
202
  });
203
+ /**
204
+ * Whether an element `heldForRelease` names stays rbx's. One reached
205
+ * through an alias destructured from its root converts all the same, with
206
+ * the TODO, since that declaration goes with the other names destructured
207
+ * beside it.
208
+ */
209
+ function heldStays(path, head) {
210
+ return aliasAt(head, path) === undefined;
211
+ }
221
212
  /** Resolve a JSX name into a canonical rbx component path, or null. */
222
213
  function resolveJsxPath(name, at) {
223
214
  const parts = jsxNameParts(name);
@@ -280,6 +271,8 @@ export default function transform(fileInfo, api, options = {}) {
280
271
  }
281
272
  return null;
282
273
  };
274
+ // 1b's decisions land here, before the bindings below are read.
275
+ destructurings.settle();
283
276
  // ---- 1c. Collect local bindings so new imports never collide -----------
284
277
  const bound = collectBoundNames(j, root, RBX);
285
278
  // Seed the reserved set with the local names of rbx imports that CANNOT be
@@ -300,8 +293,12 @@ export default function transform(fileInfo, api, options = {}) {
300
293
  // `partial`, but `<Icon.Unknown>` retains it), and when the local name
301
294
  // differs from the imported one that retained binding can collide with a
302
295
  // 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) {
296
+ // is safe: its name already means the same component on both sides. A
297
+ // root a kept destructuring names (1b) is retained already.
298
+ if (!entry ||
299
+ entry.status === 'todo' ||
300
+ local !== imported ||
301
+ ctx.retained.has(imported)) {
305
302
  bound.add(local);
306
303
  }
307
304
  }
@@ -315,14 +312,20 @@ export default function transform(fileInfo, api, options = {}) {
315
312
  // Scanned rather than reserved wholesale: adding every partial root to
316
313
  // `bound` would alias them in every file that uses one, whether or not
317
314
  // anything is actually retained.
315
+ // An element the release keeps rbx's (`heldForRelease`, `heldStays`)
316
+ // retains its root too.
318
317
  root.find(j.JSXElement).forEach(path => {
319
318
  const head = jsxNameParts(path.node.openingElement.name)?.[0];
320
319
  if (!head || !imports.has(head))
321
320
  return;
322
321
  const parts = resolveJsxPath(path.node.openingElement.name, path);
323
322
  const mapping = parts ? resolveMapping(parts) : undefined;
324
- if (!mapping || mapping.status === 'todo')
323
+ if (!mapping ||
324
+ mapping.status === 'todo' ||
325
+ (heldStays(path, head) &&
326
+ heldForRelease(path.node, mapping.target, bestaxFloor))) {
325
327
  bound.add(head);
328
+ }
326
329
  });
327
330
  // The same root can be retained by a VALUE chain -- `const X = Icon.Unknown`
328
331
  // -- which only the value-reference pass discovers, after `reserve` has
@@ -356,8 +359,12 @@ export default function transform(fileInfo, api, options = {}) {
356
359
  }
357
360
  }
358
361
  const mapping = resolveMapping(chain);
359
- if (!mapping || mapping.status === 'todo')
362
+ // A chain the release keeps rbx's (`holdReference`) retains it too.
363
+ if (!mapping ||
364
+ mapping.status === 'todo' ||
365
+ (mapping.target && classNameWaitsFor(mapping.target, bestaxFloor))) {
360
366
  bound.add(head);
367
+ }
361
368
  });
362
369
  ctx.reserve = makeReserve(ctx, bound);
363
370
  const bestaxImportState = seedBestaxImport(ctx, root);
@@ -465,6 +472,76 @@ export default function transform(fileInfo, api, options = {}) {
465
472
  target = override;
466
473
  if (!target)
467
474
  return;
475
+ const held = heldForRelease(element, target, bestaxFloor);
476
+ if (held) {
477
+ const stays = jsxHead !== undefined && heldStays(path, jsxHead);
478
+ addTodo(ctx, path, `component:${dotted}`, releaseHoldMessage(target, held, stays ? 'rbx' : undefined));
479
+ if (stays) {
480
+ ctx.retained.add(rbxPath[0]);
481
+ return;
482
+ }
483
+ }
484
+ // Targets that extend only React's HTML attributes take none of rbx's
485
+ // universal helpers, so each becomes the Bulma class it stood for, as
486
+ // bloomer's do. Where no `className` can carry it, each is named in a
487
+ // TODO instead: on a target that takes no props at all, and below the
488
+ // release a CLASSNAME_SINCE target keeps its own class beside a
489
+ // `className` from, where the `className` would replace that class.
490
+ const noProps = NO_CLASSNAME_TARGETS.has(target);
491
+ if (HELPERLESS_TARGETS.has(target) || noProps) {
492
+ const since = classNameWaitsFor(target, bestaxFloor);
493
+ // Why a class can't be written, and what to do about it.
494
+ const refusal = (what) => noProps
495
+ ? `bestax \`${target}\` takes no props at all, so ${what} cannot be set on it: wrap it, or restyle by hand`
496
+ : since
497
+ ? `${releaseRaise(target, since)}, so ${what} isn't set on it: declare \`@allxsmith/bestax-bulma\` at \`^${since}\` or later and re-run, or restyle by hand`
498
+ : undefined;
499
+ const takesNone = `bestax \`${target}\` takes no Bulma helper props (it extends only React's HTML attributes)`;
500
+ // A spread after the `className`, or anywhere when there is none, can
501
+ // carry a `className` of its own that replaces the class written here.
502
+ const attributes = element.openingElement.attributes ?? [];
503
+ const classAt = attributes.indexOf(findAttr(element, 'className'));
504
+ const spread = attributes.some((a, i) => a.type === 'JSXSpreadAttribute' && i > classAt);
505
+ for (const attr of [...attributesOf(element)]) {
506
+ const name = attr.name.name;
507
+ if (handled.has(name))
508
+ continue;
509
+ if (name === 'responsive') {
510
+ removeAttr(element, attr);
511
+ handled.add(name);
512
+ addTodo(ctx, path, 'prop:responsive', refusal('the classes `responsive` stood for') ??
513
+ `${takesNone}; add the classes \`responsive\` stood for to \`className\` by hand`);
514
+ continue;
515
+ }
516
+ const literal = literalValueOf(attr);
517
+ const cls = helperClassHint(name, literal.kind === 'expression' ? undefined : literal.value);
518
+ if (!cls)
519
+ continue;
520
+ removeAttr(element, attr);
521
+ handled.add(name);
522
+ // A falsy literal wrote no class in rbx; nothing to carry.
523
+ if (literal.kind !== 'expression' && !literal.value)
524
+ continue;
525
+ const refused = refusal(`the \`${cls}\` class this became`);
526
+ if (refused) {
527
+ addTodo(ctx, path, `prop:${name}`, refused);
528
+ }
529
+ else if (literal.kind === 'expression') {
530
+ addTodo(ctx, path, `prop:${name}`, `${takesNone}; add the \`${cls}\` class to \`className\` by hand, wherever its value set it`);
531
+ }
532
+ else if (cls.includes('<')) {
533
+ // A placeholder (`is-pulled-<side>`): the helper took a value and
534
+ // was given none, so there is no class to write.
535
+ addTodo(ctx, path, `prop:${name}`, `${takesNone}, and \`${name}\` carries no value here; add the \`${cls}\` class it takes to \`className\` by hand, with the value you meant`);
536
+ }
537
+ else if (spread) {
538
+ addTodo(ctx, path, `prop:${name}`, `${takesNone}; add the \`${cls}\` class to the \`className\` its spread may carry, by hand`);
539
+ }
540
+ else {
541
+ mergeClass(ctx, path, element, cls, name);
542
+ }
543
+ }
544
+ }
468
545
  // Rename to the bestax name, aliasing the import root on collision.
469
546
  const [targetRoot, ...targetRest] = target.split('.');
470
547
  const localTarget = [ctx.reserve(targetRoot), ...targetRest].join('.');
@@ -528,6 +605,15 @@ export default function transform(fileInfo, api, options = {}) {
528
605
  // generic "referenced as a value" branch, emitting a spurious TODO and
529
606
  // marking the root retained when it was not.
530
607
  const handledValueRefs = new WeakSet();
608
+ // A reference to a target that waits for a release stays rbx's, retaining
609
+ // its root, unless it is reached through an alias, whose declaration goes
610
+ // with the names destructured beside it (`heldStays`).
611
+ const holdReference = makeReferenceHold(ctx, bestaxFloor, 'rbx', imported => {
612
+ if (imported === '*')
613
+ namespaceStillReferenced = true;
614
+ else
615
+ ctx.retained.add(imported);
616
+ });
531
617
  root.find(j.Identifier).forEach(path => {
532
618
  // find(Identifier) also matches JSXIdentifier (a subtype) — JSX names
533
619
  // were already handled by the element walker above.
@@ -535,6 +621,8 @@ export default function transform(fileInfo, api, options = {}) {
535
621
  return;
536
622
  if (handledValueRefs.has(path.node))
537
623
  return;
624
+ if (destructurings.kept.has(path.node))
625
+ return;
538
626
  const name = path.node.name;
539
627
  // A name bound by `const { Footer } = Card` is in `aliases`, not
540
628
  // `imports` — and the destructuring pass has already deleted the
@@ -564,6 +652,10 @@ export default function transform(fileInfo, api, options = {}) {
564
652
  // runtime, so it is not a value use of the namespace at all.
565
653
  if (parentType === 'TSQualifiedName')
566
654
  return;
655
+ // A public name (`export { Card as Header }`) or a name in
656
+ // `export { Header } from './other'` binds nothing here.
657
+ if (namesNoLocal(path))
658
+ return;
567
659
  // A namespace binding in a real value position. `rbx.Button` is still a
568
660
  // mappable component reference, so fall through to the member-expression
569
661
  // branch below with an empty prefix (the namespace itself is not part of
@@ -582,15 +674,11 @@ export default function transform(fileInfo, api, options = {}) {
582
674
  // target keeps the public name (\`export { SubTitle as Subtitle }\`), a
583
675
  // dotted one cannot be re-exported under a member name and is flagged.
584
676
  if (parentType === 'ExportSpecifier') {
585
- if (parentNode.local !== path.node)
586
- return;
587
677
  const exportedName = nameOf(parentNode.exported ?? parentNode.local);
588
678
  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);
679
+ const flat = flatReExportTarget(mapping);
680
+ if (flat) {
681
+ const local = ctx.reserve(flat);
594
682
  // Replace the node: recast reprints a specifier whose identifiers were
595
683
  // swapped in place in its original shorthand form, dropping the `as`.
596
684
  path.parent.replace(j.exportSpecifier.from({
@@ -640,8 +728,10 @@ export default function transform(fileInfo, api, options = {}) {
640
728
  outer.node.property?.type === 'Identifier') {
641
729
  memberPath.push(nameOf(outer.node.property));
642
730
  const next = outer.parent;
731
+ // Not into `[…]`, which the rebuilt chain would drop.
643
732
  if (next?.node?.type === 'MemberExpression' &&
644
- next.node.object === outer.node) {
733
+ next.node.object === outer.node &&
734
+ !next.node.computed) {
645
735
  outer = next;
646
736
  }
647
737
  else {
@@ -654,6 +744,9 @@ export default function transform(fileInfo, api, options = {}) {
654
744
  memberMapping.status !== 'todo' &&
655
745
  memberMapping.target &&
656
746
  !memberMapping.special) {
747
+ if (holdReference(outer, memberMapping.target, imported, !!aliasPath)) {
748
+ return;
749
+ }
657
750
  if (memberMapping.target === dotted) {
658
751
  if (isNamespace) {
659
752
  // `rbx.Button` → `Button`: the namespace prefix has to go, so
@@ -665,7 +758,7 @@ export default function transform(fileInfo, api, options = {}) {
665
758
  for (const part of rest) {
666
759
  rebuilt = j.memberExpression(rebuilt, j.identifier(part));
667
760
  }
668
- outer.replace(rebuilt);
761
+ replaceChain(outer, rebuilt, handledValueRefs);
669
762
  ctx.dirty = true;
670
763
  return;
671
764
  }
@@ -680,7 +773,7 @@ export default function transform(fileInfo, api, options = {}) {
680
773
  for (const part of aliasRest) {
681
774
  rebuilt = j.memberExpression(rebuilt, j.identifier(part));
682
775
  }
683
- outer.replace(rebuilt);
776
+ replaceChain(outer, rebuilt, handledValueRefs);
684
777
  ctx.dirty = true;
685
778
  return;
686
779
  }
@@ -696,7 +789,7 @@ export default function transform(fileInfo, api, options = {}) {
696
789
  if (!memberMapping.target.includes('.')) {
697
790
  // Flat target (Column.Group → Columns): swap the whole chain.
698
791
  const local = ctx.reserve(memberMapping.target);
699
- outer.replace(j.identifier(local));
792
+ replaceChain(outer, j.identifier(local), handledValueRefs);
700
793
  ctx.dirty = true;
701
794
  return;
702
795
  }
@@ -709,7 +802,7 @@ export default function transform(fileInfo, api, options = {}) {
709
802
  for (const part of targetRest) {
710
803
  rebuilt = j.memberExpression(rebuilt, j.identifier(part));
711
804
  }
712
- outer.replace(rebuilt);
805
+ replaceChain(outer, rebuilt, handledValueRefs);
713
806
  ctx.dirty = true;
714
807
  return;
715
808
  }
@@ -742,6 +835,11 @@ export default function transform(fileInfo, api, options = {}) {
742
835
  shorthandMapping.status !== 'todo' &&
743
836
  shorthandMapping.target &&
744
837
  !shorthandMapping.special) {
838
+ if (holdReference(path, shorthandMapping.target, imported, !!aliasPath)) {
839
+ handledValueRefs.add(parentNode.key);
840
+ handledValueRefs.add(parentNode.value);
841
+ return;
842
+ }
745
843
  const [root, ...rest] = shorthandMapping.target.split('.');
746
844
  const local = ctx.reserve(root);
747
845
  let value = j.identifier(local);
@@ -778,6 +876,8 @@ export default function transform(fileInfo, api, options = {}) {
778
876
  mapping.status !== 'todo' &&
779
877
  mapping.target &&
780
878
  !mapping.special) {
879
+ if (holdReference(path, mapping.target, imported, !!aliasPath))
880
+ return;
781
881
  const [root, ...rest] = mapping.target.split('.');
782
882
  const local = ctx.reserve(root);
783
883
  if (rest.length > 0) {
@@ -804,7 +904,6 @@ export default function transform(fileInfo, api, options = {}) {
804
904
  });
805
905
  // ---- 3. Rewrite imports -----------------------------------------------
806
906
  if (imports.size > 0) {
807
- const retainedNames = [...ctx.retained].sort((a, b) => a.localeCompare(b));
808
907
  const bestaxImport = buildBestaxImport(ctx, bestaxImportState);
809
908
  let inserted = false;
810
909
  // A retained rbx specifier must never collide with a bestax import local
@@ -840,16 +939,7 @@ export default function transform(fileInfo, api, options = {}) {
840
939
  }
841
940
  if (keepSpecifiers.length > 0) {
842
941
  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
- }
942
+ noteRetainedImport(ctx, path, ctx.retained);
853
943
  }
854
944
  else {
855
945
  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"}