@next/codemod 16.3.0-preview.9 → 16.3.1-canary.0
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
|
@@ -5,6 +5,17 @@ const parser_1 = require("../lib/parser");
|
|
|
5
5
|
// Route Segment Config name and the only value this codemod strips.
|
|
6
6
|
const CONFIG_NAME = 'prefetch';
|
|
7
7
|
const TARGET_VALUE = 'partial';
|
|
8
|
+
const GENERATED_GUIDE_COMMENT = 'See: https://nextjs.org/docs/app/guides/adopting-partial-prefetching';
|
|
9
|
+
function isGeneratedGuideComment(comment) {
|
|
10
|
+
return comment.value.trim() === GENERATED_GUIDE_COMMENT;
|
|
11
|
+
}
|
|
12
|
+
function removeGeneratedGuideComment(node) {
|
|
13
|
+
for (const target of [node, node.declaration]) {
|
|
14
|
+
if (!target?.comments)
|
|
15
|
+
continue;
|
|
16
|
+
target.comments = target.comments.filter((comment) => !isGeneratedGuideComment(comment));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
8
19
|
// Unwrap `'partial' as const` / `'partial' satisfies T` so the value guard
|
|
9
20
|
// still matches when the export is annotated.
|
|
10
21
|
function unwrap(j, node) {
|
|
@@ -40,7 +51,7 @@ function stripTargetDeclarators(j, declaration) {
|
|
|
40
51
|
// leading comments to the next statement (or the previous one when the
|
|
41
52
|
// removed statement is last) so they survive the removal.
|
|
42
53
|
function preserveLeadingComments(path) {
|
|
43
|
-
const comments = path.node.comments?.filter((comment) => comment.leading);
|
|
54
|
+
const comments = path.node.comments?.filter((comment) => comment.leading && !isGeneratedGuideComment(comment));
|
|
44
55
|
if (!comments?.length) {
|
|
45
56
|
return;
|
|
46
57
|
}
|
|
@@ -88,6 +99,7 @@ function transformer(file, _api) {
|
|
|
88
99
|
declaration.declarations.some((decl) => isTargetPrefetch(j, decl)));
|
|
89
100
|
})
|
|
90
101
|
.forEach((path) => {
|
|
102
|
+
removeGeneratedGuideComment(path.node);
|
|
91
103
|
const declaration = path.node.declaration;
|
|
92
104
|
const remaining = stripTargetDeclarators(j, declaration);
|
|
93
105
|
// Remove the whole export only when nothing else was declared with it.
|
|
@@ -146,6 +158,7 @@ function transformer(file, _api) {
|
|
|
146
158
|
return path.node.declarations.some((decl) => isTargetPrefetch(j, decl));
|
|
147
159
|
})
|
|
148
160
|
.forEach((path) => {
|
|
161
|
+
removeGeneratedGuideComment(path.node);
|
|
149
162
|
const remaining = stripTargetDeclarators(j, path.node);
|
|
150
163
|
if (remaining === 0) {
|
|
151
164
|
preserveLeadingComments(path);
|