bestax-migrate 2.1.1 → 2.1.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.
@@ -1 +1 @@
1
- {"version":3,"file":"specials.d.ts","sourceRoot":"","sources":["../../../src/sources/react-bulma-components/specials.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAUL,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AAIxB,MAAM,WAAW,aAAa;IAC5B,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yEAAyE;IACzE,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AA+xBD,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,gBAAgB,EACrB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,EAClB,OAAO,EAAE,GAAG,GACX,aAAa,CAIf;AAED,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAGjE,CAAC"}
1
+ {"version":3,"file":"specials.d.ts","sourceRoot":"","sources":["../../../src/sources/react-bulma-components/specials.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAUL,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AAIxB,MAAM,WAAW,aAAa;IAC5B,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yEAAyE;IACzE,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AA21BD,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,gBAAgB,EACrB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,EAClB,OAAO,EAAE,GAAG,GACX,aAAa,CAIf;AAED,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAGjE,CAAC"}
@@ -153,24 +153,68 @@ const SPECIALS = {
153
153
  addTodo(ctx, path, 'prop:remove', '`remove` has a dynamic value; this can render as either a Button or a Delete cross — split the branch by hand');
154
154
  return {};
155
155
  },
156
- /** Heading → Title / SubTitle / plain `.heading` paragraph. */
156
+ /**
157
+ * Heading → Title / SubTitle / plain `.heading` paragraph, matching RBC's
158
+ * `title: !subtitle && !heading` / `subtitle: subtitle` — the *value* of
159
+ * each prop picks the target, not merely whether it was passed. Any
160
+ * statically-known literal resolves to a fixed truthiness at codemod time
161
+ * (a bare prop and `heading={true}`/`heading="heading"` are all truthy;
162
+ * `heading={false}`/`heading=""`/`heading={0}` are falsy and equivalent to
163
+ * the prop being absent), exactly as RBC evaluates the prop at runtime —
164
+ * this mirrors the Button `remove` handler so the two don't contradict each
165
+ * other on string/number literals. Only a genuine expression can't be
166
+ * resolved: it's left in place with a TODO and a conservative
167
+ * (Title/SubTitle, never the structural plain-element rewrite) fallback so
168
+ * the branch can be split by hand. The subtitle class is applied
169
+ * independently of heading in RBC, so a dynamic `subtitle` blocks the
170
+ * structural `heading` collapse — collapsing would silently drop it.
171
+ */
157
172
  heading(ctx, path, element) {
158
173
  const headingAttr = findAttr(element, 'heading');
159
- if (headingAttr) {
174
+ const subtitleAttr = findAttr(element, 'subtitle');
175
+ const headingLit = headingAttr ? literalValueOf(headingAttr) : undefined;
176
+ const subtitleLit = subtitleAttr ? literalValueOf(subtitleAttr) : undefined;
177
+ const headingDynamic = headingLit?.kind === 'expression';
178
+ const subtitleDynamic = subtitleLit?.kind === 'expression';
179
+ // A resolvable literal (boolean/string/number) collapses to its runtime
180
+ // truthiness; an expression stays dynamic.
181
+ const headingTruthy = !!headingLit && headingLit.kind !== 'expression' && !!headingLit.value;
182
+ const subtitleTruthy = !!subtitleLit && subtitleLit.kind !== 'expression' && !!subtitleLit.value;
183
+ // Dynamic values can't be resolved to a target: leave the prop on the
184
+ // element (so its expression survives for hand-splitting) plus a TODO.
185
+ if (subtitleDynamic) {
186
+ addTodo(ctx, path, 'prop:subtitle', '`subtitle` has a dynamic value; pick between Title / SubTitle by hand');
187
+ }
188
+ if (headingDynamic) {
189
+ addTodo(ctx, path, 'prop:heading', '`heading` has a dynamic value; when truthy it renders a plain `<p className="heading">` instead of Title/SubTitle — resolve by hand');
190
+ }
191
+ // A truthy literal `heading` collapses to a plain `.heading` paragraph —
192
+ // but only when `subtitle` isn't a dynamic value the collapse would drop.
193
+ // A truthy *literal* `subtitle` is safe to collapse: RBC applies its class
194
+ // independently, so it rides along on the paragraph as `heading subtitle`
195
+ // (dropping it would be the same silent loss the dynamic guard prevents).
196
+ if (headingTruthy && !subtitleDynamic) {
160
197
  removeAttr(element, headingAttr);
161
- const className = mergeClassName(ctx, path, element, 'heading', 'Heading');
198
+ const className = mergeClassName(ctx, path, element, subtitleTruthy ? 'heading subtitle' : 'heading', 'Heading');
162
199
  const rest = stripModifierProps(ctx, path, attributesOf(element).filter(a => !['size', 'weight', 'spaced', 'subtitle'].includes(a.name.name)), 'Heading');
163
200
  const replacement = plainElement(ctx.j, 'p', className, rest, element.children ?? []);
164
201
  path.replace(replacement);
165
202
  ctx.dirty = true;
166
203
  return { replaced: true };
167
204
  }
168
- const subtitleAttr = findAttr(element, 'subtitle');
169
- if (subtitleAttr) {
205
+ // A resolvable literal `heading` that didn't collapse (falsy, or truthy
206
+ // but blocked by a dynamic subtitle) behaves as if the prop were absent —
207
+ // drop it. A dynamic `heading` stays put (its TODO is already filed above).
208
+ if (headingLit && !headingDynamic) {
209
+ removeAttr(element, headingAttr);
210
+ ctx.dirty = true;
211
+ }
212
+ if (subtitleLit && !subtitleDynamic) {
170
213
  removeAttr(element, subtitleAttr);
171
214
  ctx.dirty = true;
172
- return { target: 'SubTitle' };
215
+ return { target: subtitleTruthy ? 'SubTitle' : 'Title' };
173
216
  }
217
+ // Dynamic subtitle (attr kept) or no subtitle → conservative Title.
174
218
  return { target: 'Title' };
175
219
  },
176
220
  'level-side'(ctx, path, element) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bestax-migrate",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "Codemods for migrating existing React apps from other Bulma libraries to @allxsmith/bestax-bulma",
5
5
  "type": "module",
6
6
  "bin": {