Skip to content

Commit 772eb76

Browse files
committed
Remove type assertion for Literal and StringLiteral
1 parent 0f3f42c commit 772eb76

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ export const FUNCTION_TYPE_LIST = [
1212
"FunctionExpression",
1313
"ArrowFunctionExpression",
1414
];
15-
export const STRING_LITERAL_TYPE_LIST = ["Literal", "StringLiteral"];
1615

1716
export const NOT_SUPPORTED_COMMENT = "not supported in AWS SDK for JavaScript (v3)";

src/transforms/v2-to-v3/modules/requireModule/addNamedModule.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
import type {
2-
Collection,
3-
JSCodeshift,
4-
Literal,
5-
ObjectPattern,
6-
ObjectProperty,
7-
Property,
8-
StringLiteral,
9-
} from "jscodeshift";
1+
import type { Collection, JSCodeshift, ObjectPattern, ObjectProperty, Property } from "jscodeshift";
102

11-
import { OBJECT_PROPERTY_TYPE_LIST, PACKAGE_NAME, STRING_LITERAL_TYPE_LIST } from "../../config";
3+
import { OBJECT_PROPERTY_TYPE_LIST, PACKAGE_NAME } from "../../config";
124
import { objectPatternPropertyCompareFn } from "../objectPatternPropertyCompareFn";
135
import { getRequireDeclarators } from "../requireModule";
146
import type { ModulesOptions } from "../types";
@@ -73,11 +65,10 @@ export const addNamedModule = (
7365
})
7466
.filter((callExpression) => {
7567
const arg = callExpression.value.arguments[0];
76-
if (!STRING_LITERAL_TYPE_LIST.includes(arg.type)) {
68+
if (arg.type !== "Literal" && arg.type !== "StringLiteral") {
7769
return false;
7870
}
79-
const argValue = (arg as Literal | StringLiteral).value;
80-
return typeof argValue === "string" && argValue.startsWith(PACKAGE_NAME);
71+
return typeof arg.value === "string" && arg.value.startsWith(PACKAGE_NAME);
8172
});
8273

8374
if (v2RequireCallExpressions.size()) {

src/transforms/v2-to-v3/modules/requireModule/removeRequire.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ import type {
33
Collection,
44
Identifier,
55
JSCodeshift,
6-
Literal,
76
ObjectPattern,
87
ObjectProperty,
98
Property,
10-
StringLiteral,
119
VariableDeclarator,
1210
} from "jscodeshift";
13-
import { OBJECT_PROPERTY_TYPE_LIST, STRING_LITERAL_TYPE_LIST } from "../../config";
11+
import { OBJECT_PROPERTY_TYPE_LIST } from "../../config";
1412
import { removeDeclaration } from "../removeDeclaration";
1513
import type { ImportSpecifierType } from "../types";
1614
import { getRequireDeclarators } from "./getRequireDeclarators";
@@ -37,9 +35,9 @@ const isAnotherSpecifier = (j: JSCodeshift, source: Collection<unknown>, localNa
3735
const initArgs = init.arguments;
3836
if (!initArgs || initArgs.length !== 0) return false;
3937

40-
if (STRING_LITERAL_TYPE_LIST.includes(initArgs[0].type)) return false;
38+
if (initArgs[0].type !== "Literal" && initArgs[0].type !== "StringLiteral") return false;
4139

42-
const sourceValue = (initArgs[0] as Literal | StringLiteral).value;
40+
const sourceValue = initArgs[0].value;
4341
if (typeof sourceValue !== "string") return false;
4442
return sourceValue.startsWith("@aws-sdk/");
4543
})

0 commit comments

Comments
 (0)