Skip to content

Commit 64f1f38

Browse files
authored
Use 'not supported' constant for early return (#846)
1 parent 2615e01 commit 64f1f38

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

.changeset/four-badgers-care.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"aws-sdk-js-codemod": patch
3+
---
4+
5+
Use 'not supported' constant for early return

src/transforms/v2-to-v3/apis/addNotSupportedClientComments.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Collection, JSCodeshift } from "jscodeshift";
22

3-
import { FUNCTION_TYPE_LIST, S3 } from "../config";
3+
import { FUNCTION_TYPE_LIST, NOT_SUPPORTED_COMMENT, S3 } from "../config";
44
import { ClientIdentifier } from "../types";
55
import { getClientApiCallExpression } from "./getClientApiCallExpression";
66
import { getClientWaiterCallExpression } from "./getClientWaiterCallExpression";
@@ -29,11 +29,7 @@ export const addNotSupportedClientComments = (
2929

3030
if (FUNCTION_TYPE_LIST.includes(args[args.length - 1].type)) {
3131
const comments = callExpression.node.comments || [];
32-
comments.push(
33-
j.commentLine(
34-
" Waiters with callbacks are not supported in AWS SDK for JavaScript (v3)."
35-
)
36-
);
32+
comments.push(j.commentLine(` Waiters with callbacks are ${NOT_SUPPORTED_COMMENT}.`));
3733
comments.push(
3834
j.commentLine(
3935
" Please convert to `await client.waitFor(state, params).promise()`, and re-run aws-sdk-js-codemod."
@@ -68,9 +64,7 @@ export const addNotSupportedClientComments = (
6864
if (FUNCTION_TYPE_LIST.includes(args[args.length - 1].type)) {
6965
const comments = callExpression.node.comments || [];
7066
comments.push(
71-
j.commentLine(
72-
` ${apiDescription} with callbacks are not supported in AWS SDK for JavaScript (v3).`
73-
)
67+
j.commentLine(` ${apiDescription} with callbacks are ${NOT_SUPPORTED_COMMENT}.`)
7468
);
7569
comments.push(
7670
j.commentLine(

src/transforms/v2-to-v3/config/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ export const FUNCTION_TYPE_LIST = [
1313
"ArrowFunctionExpression",
1414
];
1515
export const STRING_LITERAL_TYPE_LIST = ["Literal", "StringLiteral"];
16+
17+
export const NOT_SUPPORTED_COMMENT = "not supported in AWS SDK for JavaScript (v3)";

src/transforms/v2-to-v3/transformer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
getClientNamesFromGlobal,
2626
getClientNamesRecord,
2727
} from "./client-names";
28-
import { S3 } from "./config";
28+
import { NOT_SUPPORTED_COMMENT, S3 } from "./config";
2929
import { addClientModules, getGlobalNameFromModule, getImportType, removeModules } from "./modules";
3030
import { removeTypesFromTSQualifiedName, replaceTSTypeReference } from "./ts-type";
3131
import {
@@ -70,7 +70,7 @@ const transformer = async (file: FileInfo, api: API) => {
7070
addNotSupportedClientComments(j, source, { v2ClientName, clientIdentifiers });
7171
}
7272

73-
if (source.toSource() !== file.source) {
73+
if (source.toSource().includes(NOT_SUPPORTED_COMMENT)) {
7474
return source.toSource();
7575
}
7676

0 commit comments

Comments
 (0)