bestax-migrate 2.3.3 → 2.3.5
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.
|
@@ -48,8 +48,6 @@ export declare function declaresAs(target: string): boolean;
|
|
|
48
48
|
/** The rows the type test holds to the library. */
|
|
49
49
|
export declare const HREF_TABLE: Record<string, string>;
|
|
50
50
|
export declare const AS_ANY_TARGETS: readonly string[];
|
|
51
|
-
/** The rows the type test holds to the library. */
|
|
52
|
-
export declare const TARGET_LINK_ATTR_TABLE: Record<string, readonly string[]>;
|
|
53
51
|
/**
|
|
54
52
|
* The intrinsic elements React types an `href` onto.
|
|
55
53
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polymorphic.d.ts","sourceRoot":"","sources":["../../../src/sources/_shared/polymorphic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AA0BxB,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"polymorphic.d.ts","sourceRoot":"","sources":["../../../src/sources/_shared/polymorphic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AA0BxB,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAkB,CAAC;AAkK3E;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,GACtB,UAAU,MAAM,GAAG,SAAS,EAC5B,eAAa,KACZ,MAmBF,CAAC;AAMF,oDAAoD;AACpD,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAElD;AAQD,mDAAmD;AACnD,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAW,CAAC;AAC1D,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAAuB,CAAC;AAkEpE;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAAkC,CAAC;AAE9E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAwH5C,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEnD;AASD,sFAAsF;AACtF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAG3E;AAED,0DAA0D;AAC1D,eAAO,MAAM,UAAU,EAAE,SAAS,MAAM,EAAoC,CAAC;AAE7E,6CAA6C;AAC7C,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAC1C,CAAC;AAqLrB;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,gBAAgB,EACrB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,EAClB,OAAO,EAAE,GAAG,EACZ,MAAM,EAAE,MAAM;AACd;;;;;;;;;GASG;AACH,gBAAgB,UAAQ,GACvB,IAAI,CAsEN"}
|
|
@@ -78,8 +78,7 @@ const AS_ANY = new Set(['Button', 'Menu.Item', 'Navbar.Item', 'Navbar.Link']);
|
|
|
78
78
|
* typechecking cannot answer the question on its own. `Level.Item` declares
|
|
79
79
|
* `href` on its props at every `as`, so `<Level.Item href="/x">` compiles --
|
|
80
80
|
* but it renders a <div> and forwards `href` only when the tag is an `<a>`
|
|
81
|
-
* (`
|
|
82
|
-
* runtime. A table built from the types alone calls that supported; it is the
|
|
81
|
+
* (`LevelItem`'s anchor branch), so the attribute is dropped at runtime. A table built from the types alone calls that supported; it is the
|
|
83
82
|
* same dead attribute this pass exists to remove.
|
|
84
83
|
*/
|
|
85
84
|
const HREF_OK = {
|
|
@@ -252,7 +251,7 @@ export const AS_ANY_TARGETS = [...AS_ANY].sort();
|
|
|
252
251
|
*
|
|
253
252
|
* They are excluded because the components disagree about what they forward,
|
|
254
253
|
* so no shared set is right. `Menu.Item` strips `href` unless the tag is an
|
|
255
|
-
* `<a>` or a custom component (`
|
|
254
|
+
* `<a>` or a custom component (`MenuItem`'s `isLinkLike` guard),
|
|
256
255
|
* while `Button` routes everything but `'button'` through its anchor path and
|
|
257
256
|
* would forward it. Keeping `href` beside `as="area"` therefore typechecks on
|
|
258
257
|
* both and does nothing on one of them, which is the silently-dead attribute
|
|
@@ -271,6 +270,20 @@ const ANCHOR = 'a';
|
|
|
271
270
|
* `<Navbar.Link as="span" target="_blank">`, which does not compile either --
|
|
272
271
|
* and the check has to run whether or not an `href` was there to start with,
|
|
273
272
|
* since that shape is just as invalid without one.
|
|
273
|
+
*
|
|
274
|
+
* bulma-ui answers the same question from the other side, in
|
|
275
|
+
* `bulma-ui/src/helpers/anchorAttrs.ts`: which attributes an `<a>` adds over any
|
|
276
|
+
* element, subtracted from React's types rather than listed. The two are NOT
|
|
277
|
+
* interchangeable and neither derives from the other -- that set is per
|
|
278
|
+
* ATTRIBUTE, this table is per attribute per ELEMENT, because a codemod meets
|
|
279
|
+
* tags a component never renders.
|
|
280
|
+
*
|
|
281
|
+
* They also do not always AGREE, which is worth stating rather than asserting
|
|
282
|
+
* away: this package strips `target` from `<Menu.Item as="span">` where the
|
|
283
|
+
* component forwards it, because the codemod removes what the element cannot use
|
|
284
|
+
* while `Menu.Item` withholds `href` alone. A change to either still wants a look
|
|
285
|
+
* at the other, and #682 put bulma-ui's copy in one place so there is a single
|
|
286
|
+
* thing to look at.
|
|
274
287
|
*/
|
|
275
288
|
const LINK_ATTR_ELEMENTS = {
|
|
276
289
|
target: ['a', 'area', 'base', 'form'],
|
|
@@ -291,26 +304,6 @@ const LINK_ATTR_ELEMENTS = {
|
|
|
291
304
|
// `rel` is deliberately absent: React declares it on `HTMLAttributes`, so it
|
|
292
305
|
// is valid on every intrinsic and there is nothing to remove. The same point
|
|
293
306
|
// `bulma-ui/src/__typetests__/polymorphic.tsx` makes about it.
|
|
294
|
-
/**
|
|
295
|
-
* The link attributes a target accepts, where its props do not follow `as`.
|
|
296
|
-
*
|
|
297
|
-
* Most components here either follow `as` (the element decides, above) or
|
|
298
|
-
* extend `AnchorHTMLAttributes` outright (`Pagination.*`, `Panel.Block`, so
|
|
299
|
-
* everything is fine). `Level.Item` is the exception that enumerates: it
|
|
300
|
-
* declares `href`, `target` and `rel` and nothing else, so `download`,
|
|
301
|
-
* `hrefLang`, `ping` and `referrerPolicy` are type errors there even at
|
|
302
|
-
* `as="a"`.
|
|
303
|
-
*
|
|
304
|
-
* A target absent from `HREF_OK` needs no row: a component that takes no
|
|
305
|
-
* `href` at any `as` takes none of its siblings either -- verified for
|
|
306
|
-
* `Card.FooterItem`, `Tabs.Item` and `Delete`, which is why this is derived
|
|
307
|
-
* from that table rather than being a second list to keep.
|
|
308
|
-
*/
|
|
309
|
-
const TARGET_LINK_ATTRS = {
|
|
310
|
-
'Level.Item': ['target'],
|
|
311
|
-
};
|
|
312
|
-
/** The rows the type test holds to the library. */
|
|
313
|
-
export const TARGET_LINK_ATTR_TABLE = TARGET_LINK_ATTRS;
|
|
314
307
|
/**
|
|
315
308
|
* The intrinsic elements React types an `href` onto.
|
|
316
309
|
*
|
|
@@ -565,22 +558,21 @@ function dropInertHref(ctx, path, element, target, literal, elementKnown) {
|
|
|
565
558
|
*/
|
|
566
559
|
function dropInertLinkAttrs(ctx, path, element, target, rendered) {
|
|
567
560
|
const carriesLinks = HREF_OK[target] !== undefined;
|
|
568
|
-
const declared = TARGET_LINK_ATTRS[target];
|
|
569
561
|
for (const name of LINK_ATTRS) {
|
|
570
|
-
//
|
|
571
|
-
//
|
|
572
|
-
//
|
|
573
|
-
//
|
|
574
|
-
//
|
|
575
|
-
//
|
|
576
|
-
//
|
|
577
|
-
//
|
|
578
|
-
//
|
|
562
|
+
// Two ways to refuse it, and which one decides the TODO's wording. The
|
|
563
|
+
// component refuses outright if it is no link at any `as`. Otherwise the
|
|
564
|
+
// ELEMENT decides — `Level.Item` declares `target` and forwards it only for
|
|
565
|
+
// an `<a>`, so `<Level.Item as="p" target="_blank">` would keep the same
|
|
566
|
+
// inert attribute this pass removes everywhere else, and the message has to
|
|
567
|
+
// say the `<p>` refused it rather than that the component did.
|
|
568
|
+
//
|
|
569
|
+
// There used to be a third way: a per-target table for a component that
|
|
570
|
+
// enumerated a SUBSET of the link attributes and was therefore narrower
|
|
571
|
+
// than its own element. Nothing is, since #672, so the table went with the
|
|
572
|
+
// branch that read it.
|
|
579
573
|
let rejectedBy = null;
|
|
580
574
|
if (!carriesLinks)
|
|
581
575
|
rejectedBy = 'component';
|
|
582
|
-
else if (declared && !declared.includes(name))
|
|
583
|
-
rejectedBy = 'component';
|
|
584
576
|
// A dynamic `as` leaves the element unknown, and guessing either way is
|
|
585
577
|
// worse than leaving it for the author.
|
|
586
578
|
else if (rendered !== undefined && !elementTakesLinkAttr(name, rendered))
|
|
@@ -594,9 +586,7 @@ function dropInertLinkAttrs(ctx, path, element, target, rendered) {
|
|
|
594
586
|
removeAttr(element, attr);
|
|
595
587
|
const because = rejectedBy === 'element'
|
|
596
588
|
? `\`${name}\` needs an element that takes it, and \`${target}\` renders a <${rendered}> here`
|
|
597
|
-
:
|
|
598
|
-
? `bestax \`${target}\` is not a link at any \`as\`, so it takes no \`${name}\` either`
|
|
599
|
-
: `bestax \`${target}\` declares its own props rather than taking the element's, and \`${name}\` is not among them`;
|
|
589
|
+
: `bestax \`${target}\` is not a link at any \`as\`, so it takes no \`${name}\` either`;
|
|
600
590
|
addTodo(ctx, path, `prop:${name}`, `${because} -- ${was ? `it read \`${was}\`; ` : ''}${remedyFor(target, rendered)}`);
|
|
601
591
|
ctx.dirty = true;
|
|
602
592
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bestax-migrate",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.5",
|
|
4
4
|
"description": "Codemods for migrating existing React apps from other Bulma libraries to @allxsmith/bestax-bulma",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"chalk": "^6.0.0",
|
|
39
39
|
"commander": "^15.0.0",
|
|
40
40
|
"jscodeshift": "^17.3.0",
|
|
41
|
-
"@allxsmith/bestax-bulma": "^5.15.
|
|
41
|
+
"@allxsmith/bestax-bulma": "^5.15.4"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@jest/globals": "^30.0.0",
|