@next/codemod 15.0.0-canary.18 → 15.0.0-canary.182

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.
@@ -0,0 +1,344 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TARGET_PROP_NAMES = exports.TARGET_NAMED_EXPORTS = exports.TARGET_ROUTE_EXPORTS = exports.NEXTJS_ENTRY_FILES = void 0;
4
+ exports.isFunctionType = isFunctionType;
5
+ exports.isMatchedFunctionExported = isMatchedFunctionExported;
6
+ exports.determineClientDirective = determineClientDirective;
7
+ exports.isPromiseType = isPromiseType;
8
+ exports.turnFunctionReturnTypeToAsync = turnFunctionReturnTypeToAsync;
9
+ exports.insertReactUseImport = insertReactUseImport;
10
+ exports.generateUniqueIdentifier = generateUniqueIdentifier;
11
+ exports.isFunctionScope = isFunctionScope;
12
+ exports.findClosetParentFunctionScope = findClosetParentFunctionScope;
13
+ exports.getFunctionPathFromExportPath = getFunctionPathFromExportPath;
14
+ exports.wrapParentheseIfNeeded = wrapParentheseIfNeeded;
15
+ exports.insertCommentOnce = insertCommentOnce;
16
+ exports.getVariableDeclaratorId = getVariableDeclaratorId;
17
+ exports.NEXTJS_ENTRY_FILES = /([\\/]|^)(page|layout|route|default)\.(t|j)sx?$/;
18
+ exports.TARGET_ROUTE_EXPORTS = new Set([
19
+ 'GET',
20
+ 'POST',
21
+ 'PUT',
22
+ 'PATCH',
23
+ 'DELETE',
24
+ 'OPTIONS',
25
+ 'HEAD',
26
+ ]);
27
+ exports.TARGET_NAMED_EXPORTS = new Set([
28
+ // For page and layout
29
+ 'generateMetadata',
30
+ 'generateViewport',
31
+ ...exports.TARGET_ROUTE_EXPORTS,
32
+ ]);
33
+ exports.TARGET_PROP_NAMES = new Set(['params', 'searchParams']);
34
+ function isFunctionType(type) {
35
+ return (type === 'FunctionDeclaration' ||
36
+ type === 'FunctionExpression' ||
37
+ type === 'ArrowFunctionExpression');
38
+ }
39
+ function isMatchedFunctionExported(path, j) {
40
+ const matchedFunctionNameFilter = (idName) => exports.TARGET_NAMED_EXPORTS.has(idName);
41
+ const directNamedExport = j(path).closest(j.ExportNamedDeclaration, {
42
+ declaration: {
43
+ type: 'FunctionDeclaration',
44
+ id: {
45
+ name: matchedFunctionNameFilter,
46
+ },
47
+ },
48
+ });
49
+ if (directNamedExport.size() > 0) {
50
+ return true;
51
+ }
52
+ // Check for default export (`export default function() {}`)
53
+ const isDefaultExport = j(path).closest(j.ExportDefaultDeclaration).size() > 0;
54
+ if (isDefaultExport) {
55
+ return true;
56
+ }
57
+ // Look for named export elsewhere in the file (`export { <named> }`)
58
+ const root = j(path).closestScope().closest(j.Program);
59
+ const isNamedExport = root
60
+ .find(j.ExportNamedDeclaration, {
61
+ specifiers: [
62
+ {
63
+ type: 'ExportSpecifier',
64
+ exported: {
65
+ name: matchedFunctionNameFilter,
66
+ },
67
+ },
68
+ ],
69
+ })
70
+ .size() > 0;
71
+ // Look for variable export but still function, e.g. `export const <named> = function() {}`,
72
+ // also check if variable is a function or arrow function
73
+ const isVariableExport = root
74
+ .find(j.ExportNamedDeclaration, {
75
+ declaration: {
76
+ declarations: [
77
+ {
78
+ type: 'VariableDeclarator',
79
+ id: {
80
+ type: 'Identifier',
81
+ name: matchedFunctionNameFilter,
82
+ },
83
+ init: {
84
+ type: isFunctionType,
85
+ },
86
+ },
87
+ ],
88
+ },
89
+ })
90
+ .size() > 0;
91
+ if (isVariableExport)
92
+ return true;
93
+ return isNamedExport;
94
+ }
95
+ // directive is not parsed into AST, so we need to manually find it
96
+ // by going through the tokens. Use the 1st string token as the directive
97
+ function determineClientDirective(root, j) {
98
+ const { program } = root.get().node;
99
+ const directive = program.directives[0];
100
+ if (j.Directive.check(directive)) {
101
+ return directive.value.value === 'use client';
102
+ }
103
+ return false;
104
+ }
105
+ function isPromiseType(typeAnnotation) {
106
+ return (typeAnnotation.type === 'TSTypeReference' &&
107
+ typeAnnotation.typeName.name === 'Promise');
108
+ }
109
+ function turnFunctionReturnTypeToAsync(node, j) {
110
+ if (j.FunctionDeclaration.check(node) ||
111
+ j.FunctionExpression.check(node) ||
112
+ j.ArrowFunctionExpression.check(node)) {
113
+ if (node.returnType) {
114
+ const returnTypeAnnotation = node.returnType.typeAnnotation;
115
+ const isReturnTypePromise = isPromiseType(returnTypeAnnotation);
116
+ // Turn <return type> to Promise<return type>
117
+ // e.g. () => { slug: string } to () => Promise<{ slug: string }>
118
+ // e.g. Anything to Promise<Anything>
119
+ if (!isReturnTypePromise) {
120
+ if (node.returnType &&
121
+ j.TSTypeAnnotation.check(node.returnType) &&
122
+ (j.TSTypeReference.check(node.returnType.typeAnnotation) ||
123
+ j.TSUnionType.check(node.returnType.typeAnnotation) ||
124
+ j.TSTypePredicate.check(node.returnType.typeAnnotation))) {
125
+ // Change the return type to Promise<void>
126
+ node.returnType.typeAnnotation = j.tsTypeReference(j.identifier('Promise'),
127
+ // @ts-ignore ignore the super strict type checking on the type annotation
128
+ j.tsTypeParameterInstantiation([returnTypeAnnotation]));
129
+ }
130
+ }
131
+ }
132
+ }
133
+ }
134
+ function insertReactUseImport(root, j) {
135
+ const hasReactUseImport = root
136
+ .find(j.ImportSpecifier, {
137
+ imported: {
138
+ type: 'Identifier',
139
+ name: 'use',
140
+ },
141
+ })
142
+ .size() > 0;
143
+ if (!hasReactUseImport) {
144
+ const reactImportDeclaration = root.find(j.ImportDeclaration, {
145
+ source: {
146
+ value: 'react',
147
+ },
148
+ // Skip the type only react imports
149
+ importKind: 'value',
150
+ });
151
+ if (reactImportDeclaration.size() > 0) {
152
+ const importNode = reactImportDeclaration.get().node;
153
+ // Add 'use' to existing 'react' import declaration
154
+ importNode.specifiers.push(j.importSpecifier(j.identifier('use')));
155
+ }
156
+ else {
157
+ // Final all type imports to 'react'
158
+ if (reactImportDeclaration.size() > 0) {
159
+ reactImportDeclaration
160
+ .get()
161
+ .node.specifiers.push(j.importSpecifier(j.identifier('use')));
162
+ }
163
+ else {
164
+ // Add new import declaration for 'react' and 'use'
165
+ root
166
+ .get()
167
+ .node.program.body.unshift(j.importDeclaration([j.importSpecifier(j.identifier('use'))], j.literal('react')));
168
+ }
169
+ }
170
+ }
171
+ }
172
+ function findSubScopeArgumentIdentifier(path, j, argName) {
173
+ const defCount = j(path).find(j.Identifier, { name: argName }).size();
174
+ return defCount > 0;
175
+ }
176
+ function generateUniqueIdentifier(defaultIdName, path, j) {
177
+ let idName = defaultIdName;
178
+ let idNameSuffix = 0;
179
+ while (findSubScopeArgumentIdentifier(path, j, idName)) {
180
+ idName = defaultIdName + idNameSuffix;
181
+ idNameSuffix++;
182
+ }
183
+ const propsIdentifier = j.identifier(idName);
184
+ return propsIdentifier;
185
+ }
186
+ function isFunctionScope(path, j) {
187
+ if (!path)
188
+ return false;
189
+ const node = path.node;
190
+ // Check if the node is a function (declaration, expression, or arrow function)
191
+ return (j.FunctionDeclaration.check(node) ||
192
+ j.FunctionExpression.check(node) ||
193
+ j.ArrowFunctionExpression.check(node));
194
+ }
195
+ function findClosetParentFunctionScope(path, j) {
196
+ let parentFunctionPath = path.scope.path;
197
+ while (parentFunctionPath && !isFunctionScope(parentFunctionPath, j)) {
198
+ parentFunctionPath = parentFunctionPath.parent;
199
+ }
200
+ return parentFunctionPath;
201
+ }
202
+ function getFunctionNodeFromBinding(bindingPath, idName, j, root) {
203
+ const bindingNode = bindingPath.node;
204
+ if (j.FunctionDeclaration.check(bindingNode) ||
205
+ j.FunctionExpression.check(bindingNode) ||
206
+ j.ArrowFunctionExpression.check(bindingNode)) {
207
+ return bindingPath;
208
+ }
209
+ else if (j.VariableDeclarator.check(bindingNode)) {
210
+ const init = bindingNode.init;
211
+ // If the initializer is a function (arrow or function expression), record it
212
+ if (j.FunctionExpression.check(init) ||
213
+ j.ArrowFunctionExpression.check(init)) {
214
+ return bindingPath.get('init');
215
+ }
216
+ }
217
+ else if (j.Identifier.check(bindingNode)) {
218
+ const variablePath = root.find(j.VariableDeclaration, {
219
+ // declarations, each is VariableDeclarator
220
+ declarations: [
221
+ {
222
+ // VariableDeclarator
223
+ type: 'VariableDeclarator',
224
+ // id is Identifier
225
+ id: {
226
+ type: 'Identifier',
227
+ name: idName,
228
+ },
229
+ },
230
+ ],
231
+ });
232
+ if (variablePath.size()) {
233
+ const variableDeclarator = variablePath.get()?.node?.declarations?.[0];
234
+ if (j.VariableDeclarator.check(variableDeclarator)) {
235
+ const init = variableDeclarator.init;
236
+ if (j.FunctionExpression.check(init) ||
237
+ j.ArrowFunctionExpression.check(init)) {
238
+ return variablePath.get('declarations', 0, 'init');
239
+ }
240
+ }
241
+ }
242
+ const functionDeclarations = root.find(j.FunctionDeclaration, {
243
+ id: {
244
+ name: idName,
245
+ },
246
+ });
247
+ if (functionDeclarations.size()) {
248
+ return functionDeclarations.get();
249
+ }
250
+ }
251
+ return undefined;
252
+ }
253
+ function getFunctionPathFromExportPath(exportPath, j, root, namedExportFilter) {
254
+ // Default export
255
+ if (j.ExportDefaultDeclaration.check(exportPath.node)) {
256
+ const { declaration } = exportPath.node;
257
+ if (declaration) {
258
+ if (j.FunctionDeclaration.check(declaration) ||
259
+ j.FunctionExpression.check(declaration) ||
260
+ j.ArrowFunctionExpression.check(declaration)) {
261
+ return exportPath.get('declaration');
262
+ }
263
+ else if (j.Identifier.check(declaration)) {
264
+ const idName = declaration.name;
265
+ if (!namedExportFilter(idName))
266
+ return;
267
+ const exportBinding = exportPath.scope.getBindings()[idName]?.[0];
268
+ if (exportBinding) {
269
+ return getFunctionNodeFromBinding(exportBinding, idName, j, root);
270
+ }
271
+ }
272
+ }
273
+ }
274
+ else if (
275
+ // Named exports
276
+ j.ExportNamedDeclaration.check(exportPath.node)) {
277
+ const namedExportPath = exportPath;
278
+ // extract the named exports, name specifiers, and default specifiers
279
+ const { declaration, specifiers } = namedExportPath.node;
280
+ if (declaration) {
281
+ if (j.VariableDeclaration.check(declaration)) {
282
+ const { declarations } = declaration;
283
+ for (const decl of declarations) {
284
+ if (j.VariableDeclarator.check(decl) && j.Identifier.check(decl.id)) {
285
+ const idName = decl.id.name;
286
+ if (!namedExportFilter(idName))
287
+ return;
288
+ // get bindings for each variable declarator
289
+ const exportBinding = namedExportPath.scope.getBindings()[idName]?.[0];
290
+ if (exportBinding) {
291
+ return getFunctionNodeFromBinding(exportBinding, idName, j, root);
292
+ }
293
+ }
294
+ }
295
+ }
296
+ else if (j.FunctionDeclaration.check(declaration) ||
297
+ j.FunctionExpression.check(declaration) ||
298
+ j.ArrowFunctionExpression.check(declaration)) {
299
+ const funcName = declaration.id?.name;
300
+ if (!namedExportFilter(funcName))
301
+ return;
302
+ return namedExportPath.get('declaration');
303
+ }
304
+ }
305
+ if (specifiers) {
306
+ for (const specifier of specifiers) {
307
+ if (j.ExportSpecifier.check(specifier)) {
308
+ const idName = specifier.local.name;
309
+ if (!namedExportFilter(idName))
310
+ return;
311
+ const exportBinding = namedExportPath.scope.getBindings()[idName]?.[0];
312
+ if (exportBinding) {
313
+ return getFunctionNodeFromBinding(exportBinding, idName, j, root);
314
+ }
315
+ }
316
+ }
317
+ }
318
+ }
319
+ return undefined;
320
+ }
321
+ function wrapParentheseIfNeeded(hasChainAccess, j, expression) {
322
+ return hasChainAccess ? j.parenthesizedExpression(expression) : expression;
323
+ }
324
+ function insertCommentOnce(node, j, comment) {
325
+ if (node.comments) {
326
+ const hasComment = node.comments.some((commentNode) => commentNode.value === comment);
327
+ if (hasComment) {
328
+ return false;
329
+ }
330
+ }
331
+ node.comments = [j.commentBlock(comment), ...(node.comments || [])];
332
+ return true;
333
+ }
334
+ function getVariableDeclaratorId(path, j) {
335
+ const parent = path.parentPath;
336
+ if (j.VariableDeclarator.check(parent.node)) {
337
+ const id = parent.node.id;
338
+ if (j.Identifier.check(id)) {
339
+ return id;
340
+ }
341
+ }
342
+ return undefined;
343
+ }
344
+ //# sourceMappingURL=utils.js.map
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
3
4
  function transformer(file, api) {
4
5
  const j = api.jscodeshift;
5
6
  const root = j(file.source);
@@ -56,5 +57,4 @@ function transformer(file, api) {
56
57
  }
57
58
  return root.toSource();
58
59
  }
59
- exports.default = transformer;
60
60
  //# sourceMappingURL=metadata-to-viewport-export.js.map
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
3
4
  const path_1 = require("path");
4
5
  const camelCase = (value) => {
5
6
  const val = value.replace(/[-_\s.]+(.)?/g, (_match, chr) => chr ? chr.toUpperCase() : '');
@@ -14,11 +15,10 @@ function transformer(file, api, options) {
14
15
  (node.type === 'BlockStatement' &&
15
16
  j(node)
16
17
  .find(j.ReturnStatement)
17
- .some((path) => { var _a; return ((_a = path.value.argument) === null || _a === void 0 ? void 0 : _a.type) === 'JSXElement'; }));
18
+ .some((path) => path.value.argument?.type === 'JSXElement'));
18
19
  const hasRootAsParent = (path) => {
19
- var _a;
20
20
  const program = path.parentPath.parentPath.parentPath.parentPath.parentPath;
21
- return !program || ((_a = program === null || program === void 0 ? void 0 : program.value) === null || _a === void 0 ? void 0 : _a.type) === 'Program';
21
+ return !program || program?.value?.type === 'Program';
22
22
  };
23
23
  const nameFunctionComponent = (path) => {
24
24
  const node = path.value;
@@ -62,5 +62,4 @@ function transformer(file, api, options) {
62
62
  root.find(j.ExportDefaultDeclaration).forEach(nameFunctionComponent);
63
63
  return hasModifications ? root.toSource(options) : null;
64
64
  }
65
- exports.default = transformer;
66
65
  //# sourceMappingURL=name-default-component.js.map
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
+ // It might insert extra parnes for JSX components
3
+ // x-ref: https://github.com/facebook/jscodeshift/issues/534
2
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.default = transformer;
3
6
  function transformer(file, api) {
4
7
  const j = api.jscodeshift.withParser('tsx');
5
8
  const $j = j(file.source);
@@ -68,11 +71,10 @@ function transformer(file, api) {
68
71
  // Add only unique props to <Link> (skip duplicate props)
69
72
  const linkPropNames = $link
70
73
  .get('attributes')
71
- .value.map((linkProp) => { var _a; return (_a = linkProp === null || linkProp === void 0 ? void 0 : linkProp.name) === null || _a === void 0 ? void 0 : _a.name; });
74
+ .value.map((linkProp) => linkProp?.name?.name);
72
75
  const uniqueProps = [];
73
76
  props.forEach((anchorProp) => {
74
- var _a;
75
- if (!linkPropNames.includes((_a = anchorProp === null || anchorProp === void 0 ? void 0 : anchorProp.name) === null || _a === void 0 ? void 0 : _a.name)) {
77
+ if (!linkPropNames.includes(anchorProp?.name?.name)) {
76
78
  uniqueProps.push(anchorProp);
77
79
  }
78
80
  });
@@ -86,5 +88,4 @@ function transformer(file, api) {
86
88
  })
87
89
  .toSource();
88
90
  }
89
- exports.default = transformer;
90
91
  //# sourceMappingURL=new-link.js.map
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = void 0;
7
+ var index_1 = require("./lib/async-request-api/index");
8
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(index_1).default; } });
9
+ //# sourceMappingURL=next-async-request-api.js.map
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
4
+ function transformer(file, api) {
5
+ const j = api.jscodeshift;
6
+ const root = j(file.source);
7
+ // Find the import declaration for 'next/dynamic'
8
+ const dynamicImportDeclaration = root.find(j.ImportDeclaration, {
9
+ source: { value: 'next/dynamic' },
10
+ });
11
+ // If the import declaration is found
12
+ if (dynamicImportDeclaration.size() > 0) {
13
+ const importDecl = dynamicImportDeclaration.get(0).node;
14
+ const dynamicImportName = importDecl.specifiers?.[0]?.local?.name;
15
+ if (!dynamicImportName) {
16
+ return file.source;
17
+ }
18
+ // Find call expressions where the callee is the imported 'dynamic'
19
+ root
20
+ .find(j.CallExpression, {
21
+ callee: { name: dynamicImportName },
22
+ })
23
+ .forEach((path) => {
24
+ const arrowFunction = path.node.arguments[0];
25
+ // Ensure the argument is an ArrowFunctionExpression
26
+ if (arrowFunction && arrowFunction.type === 'ArrowFunctionExpression') {
27
+ const importCall = arrowFunction.body;
28
+ // Ensure the parent of the import call is a CallExpression with a .then
29
+ if (importCall &&
30
+ importCall.type === 'CallExpression' &&
31
+ importCall.callee.type === 'MemberExpression' &&
32
+ 'name' in importCall.callee.property &&
33
+ importCall.callee.property.name === 'then') {
34
+ const thenFunction = importCall.arguments[0];
35
+ // handle case of block statement case `=> { return mod.Component }`
36
+ // transform to`=> { return { default: mod.Component } }`
37
+ if (thenFunction &&
38
+ thenFunction.type === 'ArrowFunctionExpression' &&
39
+ thenFunction.body.type === 'BlockStatement') {
40
+ const returnStatement = thenFunction.body.body[0];
41
+ // Ensure the body of the arrow function has a return statement with a MemberExpression
42
+ if (returnStatement &&
43
+ returnStatement.type === 'ReturnStatement' &&
44
+ returnStatement.argument?.type === 'MemberExpression') {
45
+ returnStatement.argument = j.objectExpression([
46
+ j.property('init', j.identifier('default'), returnStatement.argument),
47
+ ]);
48
+ }
49
+ }
50
+ // handle case `=> mod.Component`
51
+ // transform to`=> ({ default: mod.Component })`
52
+ if (thenFunction &&
53
+ thenFunction.type === 'ArrowFunctionExpression' &&
54
+ thenFunction.body.type === 'MemberExpression') {
55
+ thenFunction.body = j.objectExpression([
56
+ j.property('init', j.identifier('default'), thenFunction.body),
57
+ ]);
58
+ }
59
+ }
60
+ }
61
+ });
62
+ }
63
+ return root.toSource();
64
+ }
65
+ //# sourceMappingURL=next-dynamic-access-named-export.js.map
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
3
4
  const path_1 = require("path");
4
5
  const fs_1 = require("fs");
5
6
  function findAndReplaceProps(j, root, tagName) {
@@ -21,14 +22,12 @@ function findAndReplaceProps(j, root, tagName) {
21
22
  el.value.openingElement.name.type === 'JSXIdentifier' &&
22
23
  el.value.openingElement.name.name === tagName)
23
24
  .forEach((el) => {
24
- var _a;
25
25
  let layout = 'intrinsic';
26
26
  let objectFit = null;
27
27
  let objectPosition = null;
28
28
  let styleExpProps = [];
29
29
  let sizesAttr = null;
30
- const attributes = (_a = el.node.openingElement.attributes) === null || _a === void 0 ? void 0 : _a.filter((a) => {
31
- var _a, _b;
30
+ const attributes = el.node.openingElement.attributes?.filter((a) => {
32
31
  if (a.type !== 'JSXAttribute') {
33
32
  return true;
34
33
  }
@@ -51,11 +50,11 @@ function findAndReplaceProps(j, root, tagName) {
51
50
  return false;
52
51
  }
53
52
  if (a.name.name === 'style') {
54
- if (((_a = a.value) === null || _a === void 0 ? void 0 : _a.type) === 'JSXExpressionContainer' &&
53
+ if (a.value?.type === 'JSXExpressionContainer' &&
55
54
  a.value.expression.type === 'ObjectExpression') {
56
55
  styleExpProps = a.value.expression.properties;
57
56
  }
58
- else if (((_b = a.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer' &&
57
+ else if (a.value?.type === 'JSXExpressionContainer' &&
59
58
  a.value.expression.type === 'Identifier') {
60
59
  styleExpProps = [
61
60
  j.spreadElement(j.identifier(a.value.expression.name)),
@@ -208,9 +207,8 @@ function transformer(file, api, options) {
208
207
  source: { value: 'next/legacy/image' },
209
208
  })
210
209
  .forEach((imageImport) => {
211
- var _a, _b;
212
- const defaultSpecifier = (_a = imageImport.node.specifiers) === null || _a === void 0 ? void 0 : _a.find((node) => node.type === 'ImportDefaultSpecifier');
213
- const tagName = (_b = defaultSpecifier === null || defaultSpecifier === void 0 ? void 0 : defaultSpecifier.local) === null || _b === void 0 ? void 0 : _b.name;
210
+ const defaultSpecifier = imageImport.node.specifiers?.find((node) => node.type === 'ImportDefaultSpecifier');
211
+ const tagName = defaultSpecifier?.local?.name;
214
212
  imageImport.node.source = j.stringLiteral('next/image');
215
213
  if (tagName) {
216
214
  findAndReplaceProps(j, root, tagName);
@@ -220,7 +218,7 @@ function transformer(file, api, options) {
220
218
  // After: const Image = await import("next/image")
221
219
  root.find(j.AwaitExpression).forEach((awaitExp) => {
222
220
  const arg = awaitExp.value.argument;
223
- if ((arg === null || arg === void 0 ? void 0 : arg.type) === 'CallExpression' && arg.callee.type === 'Import') {
221
+ if (arg?.type === 'CallExpression' && arg.callee.type === 'Import') {
224
222
  if (arg.arguments[0].type === 'StringLiteral' &&
225
223
  arg.arguments[0].value === 'next/legacy/image') {
226
224
  arg.arguments[0] = j.stringLiteral('next/image');
@@ -230,14 +228,13 @@ function transformer(file, api, options) {
230
228
  // Before: const Image = require("next/legacy/image")
231
229
  // After: const Image = require("next/image")
232
230
  root.find(j.CallExpression).forEach((requireExp) => {
233
- var _a, _b, _c, _d, _e;
234
- if (((_b = (_a = requireExp === null || requireExp === void 0 ? void 0 : requireExp.value) === null || _a === void 0 ? void 0 : _a.callee) === null || _b === void 0 ? void 0 : _b.type) === 'Identifier' &&
231
+ if (requireExp?.value?.callee?.type === 'Identifier' &&
235
232
  requireExp.value.callee.name === 'require') {
236
233
  let firstArg = requireExp.value.arguments[0];
237
234
  if (firstArg &&
238
235
  firstArg.type === 'StringLiteral' &&
239
236
  firstArg.value === 'next/legacy/image') {
240
- const tagName = (_e = (_d = (_c = requireExp === null || requireExp === void 0 ? void 0 : requireExp.parentPath) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.id) === null || _e === void 0 ? void 0 : _e.name;
237
+ const tagName = requireExp?.parentPath?.value?.id?.name;
241
238
  if (tagName) {
242
239
  requireExp.value.arguments[0] = j.stringLiteral('next/image');
243
240
  findAndReplaceProps(j, root, tagName);
@@ -248,5 +245,4 @@ function transformer(file, api, options) {
248
245
  // TODO: do the same transforms for dynamic imports
249
246
  return root.toSource(options);
250
247
  }
251
- exports.default = transformer;
252
248
  //# sourceMappingURL=next-image-experimental.js.map
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
3
4
  function transformer(file, api, options) {
4
5
  const j = api.jscodeshift.withParser('tsx');
5
6
  const root = j(file.source);
@@ -16,7 +17,7 @@ function transformer(file, api, options) {
16
17
  // After: const Image = await import("next/legacy/image")
17
18
  root.find(j.AwaitExpression).forEach((awaitExp) => {
18
19
  const arg = awaitExp.value.argument;
19
- if ((arg === null || arg === void 0 ? void 0 : arg.type) === 'CallExpression' && arg.callee.type === 'Import') {
20
+ if (arg?.type === 'CallExpression' && arg.callee.type === 'Import') {
20
21
  if (arg.arguments[0].type === 'StringLiteral' &&
21
22
  arg.arguments[0].value === 'next/image') {
22
23
  arg.arguments[0] = j.stringLiteral('next/legacy/image');
@@ -36,7 +37,7 @@ function transformer(file, api, options) {
36
37
  // After: const Image = await import("next/image")
37
38
  root.find(j.AwaitExpression).forEach((awaitExp) => {
38
39
  const arg = awaitExp.value.argument;
39
- if ((arg === null || arg === void 0 ? void 0 : arg.type) === 'CallExpression' && arg.callee.type === 'Import') {
40
+ if (arg?.type === 'CallExpression' && arg.callee.type === 'Import') {
40
41
  if (arg.arguments[0].type === 'StringLiteral' &&
41
42
  arg.arguments[0].value === 'next/future/image') {
42
43
  arg.arguments[0] = j.stringLiteral('next/image');
@@ -46,8 +47,7 @@ function transformer(file, api, options) {
46
47
  // Before: const Image = require("next/image")
47
48
  // After: const Image = require("next/legacy/image")
48
49
  root.find(j.CallExpression).forEach((requireExp) => {
49
- var _a, _b;
50
- if (((_b = (_a = requireExp === null || requireExp === void 0 ? void 0 : requireExp.value) === null || _a === void 0 ? void 0 : _a.callee) === null || _b === void 0 ? void 0 : _b.type) === 'Identifier' &&
50
+ if (requireExp?.value?.callee?.type === 'Identifier' &&
51
51
  requireExp.value.callee.name === 'require') {
52
52
  let firstArg = requireExp.value.arguments[0];
53
53
  if (firstArg &&
@@ -60,8 +60,7 @@ function transformer(file, api, options) {
60
60
  // Before: const Image = require("next/future/image")
61
61
  // After: const Image = require("next/image")
62
62
  root.find(j.CallExpression).forEach((requireExp) => {
63
- var _a, _b;
64
- if (((_b = (_a = requireExp === null || requireExp === void 0 ? void 0 : requireExp.value) === null || _a === void 0 ? void 0 : _a.callee) === null || _b === void 0 ? void 0 : _b.type) === 'Identifier' &&
63
+ if (requireExp?.value?.callee?.type === 'Identifier' &&
65
64
  requireExp.value.callee.name === 'require') {
66
65
  let firstArg = requireExp.value.arguments[0];
67
66
  if (firstArg &&
@@ -75,5 +74,4 @@ function transformer(file, api, options) {
75
74
  // https://www.codeshiftcommunity.com/docs/import-manipulation/#replacerename-an-import-declaration
76
75
  return root.toSource(options);
77
76
  }
78
- exports.default = transformer;
79
77
  //# sourceMappingURL=next-image-to-legacy-image.js.map
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
3
4
  const importToChange = 'ImageResponse';
4
5
  function transformer(file, api) {
5
6
  const j = api.jscodeshift;
@@ -31,5 +32,4 @@ function transformer(file, api) {
31
32
  .toSource();
32
33
  return file.source;
33
34
  }
34
- exports.default = transformer;
35
35
  //# sourceMappingURL=next-og-import.js.map