@next/codemod 15.5.1-canary.13 → 15.5.1-canary.15
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 +1 -1
- package/transforms/new-link.js +19 -14
package/package.json
CHANGED
package/transforms/new-link.js
CHANGED
|
@@ -8,9 +8,8 @@ const utils_1 = require("./lib/async-request-api/utils");
|
|
|
8
8
|
function transformer(file, _api) {
|
|
9
9
|
const j = (0, parser_1.createParserFromPath)(file.path);
|
|
10
10
|
const $j = j(file.source);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.forEach((path) => {
|
|
11
|
+
let hasChanges = false;
|
|
12
|
+
$j.find(j.ImportDeclaration, { source: { value: 'next/link' } }).forEach((path) => {
|
|
14
13
|
const defaultImport = j(path).find(j.ImportDefaultSpecifier);
|
|
15
14
|
if (defaultImport.size() === 0) {
|
|
16
15
|
return;
|
|
@@ -28,16 +27,16 @@ function transformer(file, _api) {
|
|
|
28
27
|
if ($link.size() === 0) {
|
|
29
28
|
return;
|
|
30
29
|
}
|
|
31
|
-
const $
|
|
32
|
-
.find(j.JSXAttribute, {
|
|
30
|
+
const $legacyBehaviorProps = $link.find(j.JSXAttribute, {
|
|
33
31
|
name: { type: 'JSXIdentifier', name: 'legacyBehavior' },
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
$
|
|
37
|
-
|
|
32
|
+
});
|
|
33
|
+
$legacyBehaviorProps.remove();
|
|
34
|
+
hasChanges ||= $legacyBehaviorProps.size() > 0;
|
|
35
|
+
const $passHrefProps = $link.find(j.JSXAttribute, {
|
|
38
36
|
name: { type: 'JSXIdentifier', name: 'passHref' },
|
|
39
|
-
})
|
|
40
|
-
|
|
37
|
+
});
|
|
38
|
+
$passHrefProps.remove();
|
|
39
|
+
hasChanges ||= $passHrefProps.size() > 0;
|
|
41
40
|
const linkChildrenNodes = $link.get('children');
|
|
42
41
|
// Text-only link children are already correct with the new behavior
|
|
43
42
|
// `next/link` would previously auto-wrap typeof 'string' children already
|
|
@@ -53,7 +52,7 @@ function transformer(file, _api) {
|
|
|
53
52
|
.value === 'a');
|
|
54
53
|
});
|
|
55
54
|
if ($childrenWithA.length === 0) {
|
|
56
|
-
if ($
|
|
55
|
+
if ($legacyBehaviorProps.length > 0) {
|
|
57
56
|
linkPath.node.children.unshift(j.jsxText('\n'), j.jsxExpressionContainer.from({
|
|
58
57
|
expression: j.jsxEmptyExpression.from({
|
|
59
58
|
comments: [
|
|
@@ -63,6 +62,7 @@ function transformer(file, _api) {
|
|
|
63
62
|
],
|
|
64
63
|
}),
|
|
65
64
|
}));
|
|
65
|
+
hasChanges = true;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
@@ -82,12 +82,17 @@ function transformer(file, _api) {
|
|
|
82
82
|
$link.get('attributes').value.push(...uniqueProps);
|
|
83
83
|
// Remove props from <a>
|
|
84
84
|
props.length = 0;
|
|
85
|
+
hasChanges = true;
|
|
85
86
|
}
|
|
86
87
|
const childrenProps = $childrenWithA.get('children');
|
|
87
88
|
$childrenWithA.replaceWith(childrenProps.value);
|
|
89
|
+
hasChanges = true;
|
|
88
90
|
}
|
|
89
91
|
});
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
+
});
|
|
93
|
+
if (hasChanges) {
|
|
94
|
+
return $j.toSource();
|
|
95
|
+
}
|
|
96
|
+
return file.source;
|
|
92
97
|
}
|
|
93
98
|
//# sourceMappingURL=new-link.js.map
|