@react-spectrum/codemods 0.1.0 → 0.1.2-nightly.5022

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.
@@ -499,6 +499,14 @@ exports.changes = {
499
499
  newValue: 'white'
500
500
  }
501
501
  }
502
+ },
503
+ {
504
+ description: 'Remove inner anchor element if used (legacy API)',
505
+ reason: 'Updated API',
506
+ function: {
507
+ name: 'updateLegacyLink',
508
+ args: {}
509
+ }
502
510
  }
503
511
  ]
504
512
  },
@@ -663,6 +663,28 @@ function updateAvatarSize(path) {
663
663
  }
664
664
  }
665
665
  }
666
+ /**
667
+ * Handles the legacy `Link` API where an `a` tag or custom router component could be used within a `Link` component.
668
+ * Removes the inner component and moves its attributes to the `Link` component.
669
+ */
670
+ function updateLegacyLink(path) {
671
+ let missingOuterHref = t.isJSXElement(path.node) && !path.node.openingElement.attributes.some((attr) => t.isJSXAttribute(attr) && attr.name.name === 'href');
672
+ if (missingOuterHref) {
673
+ let innerLink = path.node.children.find((child) => t.isJSXElement(child) && t.isJSXIdentifier(child.openingElement.name));
674
+ if (innerLink && t.isJSXElement(innerLink)) {
675
+ let innerAttributes = innerLink.openingElement.attributes;
676
+ let outerAttributes = path.node.openingElement.attributes;
677
+ innerAttributes.forEach((attr) => {
678
+ outerAttributes.push(attr);
679
+ });
680
+ if (t.isJSXIdentifier(innerLink.openingElement.name) &&
681
+ innerLink.openingElement.name.name !== 'a') {
682
+ (0, utils_1.addComment)(path.node, ' TODO(S2-upgrade): You may have been using a custom link component here. You\'ll need to update this manually.');
683
+ }
684
+ path.node.children = innerLink.children;
685
+ }
686
+ }
687
+ }
666
688
  exports.functionMap = {
667
689
  updatePropNameAndValue,
668
690
  updatePropValueAndAddNewProp,
@@ -681,5 +703,6 @@ exports.functionMap = {
681
703
  convertDimensionValueToPx,
682
704
  updatePlacementToSingleValue,
683
705
  removeComponentIfWithinParent,
684
- updateAvatarSize
706
+ updateAvatarSize,
707
+ updateLegacyLink
685
708
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-spectrum/codemods",
3
- "version": "0.1.0",
3
+ "version": "0.1.2-nightly.5022+b4093dfef",
4
4
  "main": "dist/index.js",
5
5
  "source": "src/index.ts",
6
6
  "bin": "dist/index.js",
@@ -24,8 +24,8 @@
24
24
  "@babel/parser": "^7.24.5",
25
25
  "@babel/traverse": "^7.24.5",
26
26
  "@babel/types": "^7.24.5",
27
- "@react-spectrum/s2": "^0.3.0",
28
- "@react-types/shared": "^3.24.0",
27
+ "@react-spectrum/s2": "0.3.2-nightly.5022+b4093dfef",
28
+ "@react-types/shared": "3.0.0-nightly.3094+b4093dfef",
29
29
  "@types/node": "^20",
30
30
  "boxen": "^5.1.2",
31
31
  "build": "^0.1.4",
@@ -47,5 +47,5 @@
47
47
  "publishConfig": {
48
48
  "access": "public"
49
49
  },
50
- "gitHead": "faf0e18467231422cb7a06eb92a74d04e271f1e8"
50
+ "gitHead": "b4093dfef3eff0e5fe60d00c53fe2478b96e662f"
51
51
  }