bestax-migrate 2.3.0 → 2.3.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.
@@ -60,6 +60,13 @@ export type LiteralValue = {
60
60
  } | {
61
61
  kind: 'expression';
62
62
  };
63
+ /**
64
+ * An attribute as the author wrote it, for a TODO that removes it. A dynamic
65
+ * value may be the only reference keeping an import alive, so the message has
66
+ * to carry it -- otherwise the destination is recoverable only from git.
67
+ * Returns '' if the printer cannot render the node.
68
+ */
69
+ export declare function attrSource(j: JSCodeshift, attr: any): string;
63
70
  /** Extract the literal value of a JSX attribute, if it has one. */
64
71
  export declare function literalValueOf(attr: any): LiteralValue;
65
72
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"jsx-utils.d.ts","sourceRoot":"","sources":["../../../src/sources/_shared/jsx-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAMpD,MAAM,WAAW,gBAAgB;IAC/B,CAAC,EAAE,WAAW,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,aAAa,GAAG,SAAS,CAAC;IACrC,2EAA2E;IAC3E,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACtB,8EAA8E;IAC9E,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B;;;;OAIG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAClC;;;;OAIG;IACH,SAAS,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,MAAM,EAAE,GA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AAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,GAAG,CAK1E;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CACrB,GAAG,EAAE,gBAAgB,EACrB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,IAAI,CAgDN;AAED,uEAAuE;AACvE,wBAAgB,YAAY,CAC1B,CAAC,EAAE,WAAW,EACd,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,KAAK,EAAE,GAAG,EAAE,EACZ,QAAQ,EAAE,GAAG,EAAE,EACf,WAAW,UAAQ,GAClB,GAAG,CAsBL"}
@@ -54,6 +54,20 @@ export function addAttr(element, attr) {
54
54
  element.openingElement.attributes = element.openingElement.attributes ?? [];
55
55
  element.openingElement.attributes.push(attr);
56
56
  }
57
+ /**
58
+ * An attribute as the author wrote it, for a TODO that removes it. A dynamic
59
+ * value may be the only reference keeping an import alive, so the message has
60
+ * to carry it -- otherwise the destination is recoverable only from git.
61
+ * Returns '' if the printer cannot render the node.
62
+ */
63
+ export function attrSource(j, attr) {
64
+ try {
65
+ return j(attr).toSource();
66
+ }
67
+ catch {
68
+ return '';
69
+ }
70
+ }
57
71
  /** Extract the literal value of a JSX attribute, if it has one. */
58
72
  export function literalValueOf(attr) {
59
73
  if (attr.value == null)
@@ -162,7 +176,16 @@ export function addTodo(ctx, path, rule, message) {
162
176
  /^Export(Named|Default)Declaration$/.test(statement.parent.node.type)) {
163
177
  statement = statement.parent;
164
178
  }
165
- const text = ` TODO(bestax-migrate): ${message}`;
179
+ // A `//` comment ends at the first newline, so any line break inside the
180
+ // message would leave the rest of it as bare code and the file unparseable.
181
+ // Messages quote source text -- an attribute value, a tag name -- and JSX
182
+ // permits a newline inside both, so this is folded here rather than at each
183
+ // of the callers that interpolate one.
184
+ //
185
+ // Line terminators only. Collapsing all whitespace rewrote the very thing
186
+ // the quote exists to preserve: `href="/a b"` came back as `href="/a b"`,
187
+ // a different URL.
188
+ const text = ` TODO(bestax-migrate): ${message.replace(/[\r\n\u2028\u2029]+/g, ' ').trim()}`;
166
189
  if (statement) {
167
190
  const node = statement.node;
168
191
  node.comments = node.comments ?? [];
@@ -0,0 +1,92 @@
1
+ /**
2
+ * bestax's DOM props follow `as`: an element's attributes are the attributes
3
+ * of whatever `as` renders, and a few components narrow `as` to a literal
4
+ * union of the elements Bulma's markup allows there. Every source library
5
+ * this package migrates from is looser — rbx and react-bulma-components take
6
+ * any tag, bloomer took any `tag` — so a faithful prop-for-prop rename emits
7
+ * shapes that do not compile against the library:
8
+ *
9
+ * - an `as` naming an element the bestax component does not offer;
10
+ * - an `href` beside an `as` that is not an `<a>`;
11
+ * - an `href` on a component that declares none at any `as`;
12
+ * - `target` and its siblings on an element, or a component, without them.
13
+ *
14
+ * All are dropped with a TODO rather than carried, because carrying them
15
+ * hands the user a project that does not typecheck, which is the one thing a
16
+ * codemod must not do.
17
+ *
18
+ * What that costs differs by case, and each TODO says so. Dropping an `href`
19
+ * or a `target` costs nothing the source had: they sat on a `<span>` or a
20
+ * `<div>`, where no browser acts on them. Dropping an `as` does change the
21
+ * element — every source here rendered the tag it was given, and bestax
22
+ * renders its own instead — so that TODO names the tag to restore rather than
23
+ * claiming nothing moved.
24
+ *
25
+ * Source-agnostic: what it knows is bestax's side of the rename, so all three
26
+ * sources run it over every element after their prop passes.
27
+ */
28
+ import type { ASTPath } from 'jscodeshift';
29
+ import { type TransformContext } from './jsx-utils.js';
30
+ export declare const AS_UNIONS: Record<string, readonly string[]>;
31
+ /** The targets whose `as` this pass may believe. */
32
+ export declare function declaresAs(target: string): boolean;
33
+ /** The rows the type test holds to the library. */
34
+ export declare const HREF_TABLE: Record<string, string>;
35
+ export declare const AS_ANY_TARGETS: readonly string[];
36
+ /** The rows the type test holds to the library. */
37
+ export declare const TARGET_LINK_ATTR_TABLE: Record<string, readonly string[]>;
38
+ /**
39
+ * The intrinsic elements React types an `href` onto.
40
+ *
41
+ * Only relevant to plain markup. On a bestax component the anchor is the only
42
+ * `as` that keeps an `href`, because the components disagree about what they
43
+ * forward (see `ANCHOR` below) -- but a plain `<area href>` has no component
44
+ * in the way, and it is valid.
45
+ */
46
+ export declare const HREF_ELEMENTS: readonly string[];
47
+ /**
48
+ * The HTML half of `JSX.IntrinsicElements`, as of `@types/react` 19.
49
+ *
50
+ * Regenerate by reading the keys between `interface IntrinsicElements {` and
51
+ * the `// SVG` comment in `@types/react/index.d.ts`. `as-unions.test.ts`
52
+ * holds the link tables to this set, so it is checked rather than trusted.
53
+ *
54
+ * SVG is excluded deliberately: `SVGAttributes` declares `href`, `media` and
55
+ * `target`, so every SVG tag would join those rows. What that means for a
56
+ * plain rewrite is `tagRejectsHref`'s problem, not a reason to widen this.
57
+ */
58
+ export declare const HTML_INTRINSICS: readonly string[];
59
+ /**
60
+ * Whether a plain tag is known NOT to take an `href`.
61
+ *
62
+ * `HREF_ELEMENTS` is the HTML answer, and bloomer's `plainTag` can return any
63
+ * literal the source wrote -- including an SVG tag, where `SVGAttributes`
64
+ * declares `href`. Treating "not in the HTML list" as "takes no href" lost a
65
+ * working `href` off `<TabLink tag="use" href="#icon">`. An unrecognised tag
66
+ * is left alone: this pass removes attributes it can prove are dead, and it
67
+ * cannot prove that here.
68
+ */
69
+ export declare function tagRejectsHref(tag: string): boolean;
70
+ /** Whether `element` renders `attr` legally -- exported for the plain-markup path. */
71
+ export declare function elementTakesLinkAttr(name: string, element: string): boolean;
72
+ /** The link attributes, for callers that iterate them. */
73
+ export declare const LINK_ATTRS: readonly string[];
74
+ /** The rows the type test holds to React. */
75
+ export declare const LINK_ATTR_TABLE: Record<string, readonly string[]>;
76
+ /**
77
+ * The whole-element pass each source runs after its prop passes, once the
78
+ * bestax `target` and the final `as` are both known.
79
+ */
80
+ export declare function enforcePolymorphicProps(ctx: TransformContext, path: ASTPath<any>, element: any, target: string,
81
+ /**
82
+ * Whether a spread on this element could be carrying an `as`.
83
+ *
84
+ * Only where the SOURCE spells its element prop `as`, which is rbx alone.
85
+ * bloomer's is `tag` and react-bulma-components' is `renderAs`, and the
86
+ * rename only ever touches a literal attribute -- a `renderAs` key inside
87
+ * `{...rest}` never becomes an `as`. Guessing `true` everywhere let
88
+ * `<Button renderAs="span" {...rest} href="/x">` through untouched, which
89
+ * is the shape this pass exists to remove.
90
+ */
91
+ spreadCanCarryAs?: boolean): void;
92
+ //# sourceMappingURL=polymorphic.d.ts.map
@@ -0,0 +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;AAsF3E,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;AAuEpE,mDAAmD;AACnD,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAClD,CAAC;AAEpB;;;;;;;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,s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