@planningcenter/tapestry-migration-cli 2.4.0-rc.4 → 2.4.0-rc.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planningcenter/tapestry-migration-cli",
3
- "version": "2.4.0-rc.4",
3
+ "version": "2.4.0-rc.5",
4
4
  "description": "CLI tool for Tapestry migrations",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -51,5 +51,5 @@
51
51
  "publishConfig": {
52
52
  "access": "public"
53
53
  },
54
- "gitHead": "aa40507b01cc6ea8c044aac697970f5bcc93fda2"
54
+ "gitHead": "f90b3a7efefc3e67294eb7f0bf44376bae282949"
55
55
  }
@@ -132,6 +132,20 @@ export default function Test() {
132
132
  expect(result).toContain('href="/page3"') // Should remain unchanged
133
133
  })
134
134
 
135
+ it("should handle target={'_blank'} format", () => {
136
+ const input = `
137
+ import { Link } from "@planningcenter/tapestry-react"
138
+
139
+ export default function Test() {
140
+ return <Link href="/external" target={'_blank'}>External Link</Link>
141
+ }
142
+ `.trim()
143
+
144
+ const result = applyTransform(input)
145
+ expect(result).toContain("external")
146
+ expect(result).not.toContain("target={'_blank'}")
147
+ })
148
+
135
149
  it("should handle dynamic target values", () => {
136
150
  const input = `
137
151
  import { Link } from "@planningcenter/tapestry-react"
@@ -32,7 +32,28 @@ describe("hasAttributeValue", () => {
32
32
  expect(condition(element)).toBe(false)
33
33
  })
34
34
 
35
- it("should return false for expression values", () => {
35
+ it("should return true for expression with string literal", () => {
36
+ const condition = hasAttributeValue("target", "_blank")
37
+ const element = createJSXElement(" target={'_blank'}")
38
+
39
+ expect(condition(element)).toBe(true)
40
+ })
41
+
42
+ it("should return true for expression with double quotes", () => {
43
+ const condition = hasAttributeValue("target", "_blank")
44
+ const element = createJSXElement(' target={"_blank"}')
45
+
46
+ expect(condition(element)).toBe(true)
47
+ })
48
+
49
+ it("should return false for expression with different value", () => {
50
+ const condition = hasAttributeValue("target", "_blank")
51
+ const element = createJSXElement(" target={'_self'}")
52
+
53
+ expect(condition(element)).toBe(false)
54
+ })
55
+
56
+ it("should return false for complex expression values", () => {
36
57
  const condition = hasAttributeValue("onClick", "handleClick")
37
58
  const element = createJSXElement(" onClick={handleClick}")
38
59
 
@@ -4,6 +4,7 @@ import { TransformCondition } from "../types"
4
4
 
5
5
  /**
6
6
  * Helper function to create a condition that checks for an attribute with a specific value
7
+ * Handles both string literals and expressions with string literals
7
8
  */
8
9
  export function hasAttributeValue(
9
10
  attributeName: string,
@@ -11,13 +12,30 @@ export function hasAttributeValue(
11
12
  ): TransformCondition {
12
13
  return (element: JSXElement) => {
13
14
  const attributes = element.openingElement.attributes || []
14
- return attributes.some(
15
- (attr) =>
15
+ return attributes.some((attr) => {
16
+ const hasAttribute =
16
17
  attr.type === "JSXAttribute" &&
17
18
  attr.name?.type === "JSXIdentifier" &&
18
- attr.name.name === attributeName &&
19
- attr.value?.type === "StringLiteral" &&
20
- attr.value.value === value
21
- )
19
+ attr.name.name === attributeName
20
+
21
+ if (!hasAttribute) {
22
+ return false
23
+ }
24
+
25
+ // Handle string literal: attribute="value"
26
+ if (attr.value?.type === "StringLiteral") {
27
+ return attr.value.value === value
28
+ }
29
+
30
+ // Handle expression: attribute={"value"} or attribute={'value'}
31
+ if (attr.value?.type === "JSXExpressionContainer") {
32
+ const { expression } = attr.value
33
+ if (expression.type === "StringLiteral") {
34
+ return expression.value === value
35
+ }
36
+ }
37
+
38
+ return false
39
+ })
22
40
  }
23
41
  }