Skip to content

Commit c489d7d

Browse files
committed
Use STRING_LITERAL_TYPE_LIST in removeRequireProperty and requireModule/addNamedModule
1 parent ab1c82e commit c489d7d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/transforms/v2-to-v3/modules/removeRequireProperty.ts

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

3+
import { STRING_LITERAL_TYPE_LIST } from "../config";
34
import { getRequireDeclaratorsWithProperty } from "./getRequireDeclaratorsWithProperty";
45
import { removeDeclaration } from "./removeDeclaration";
56

@@ -45,8 +46,8 @@ export const removeRequireProperty = (
4546

4647
const args = object.arguments;
4748
if (args.length !== 1) return true;
48-
if (args[0].type !== "Literal") return true;
49-
if (args[0].value !== sourceValue) return true;
49+
if (!STRING_LITERAL_TYPE_LIST.includes(args[0].type)) return true;
50+
if ((args[0] as Literal).value !== sourceValue) return true;
5051

5152
const property = init.property;
5253
if (property.type !== "Identifier") return true;

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

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

3-
import { OBJECT_PROPERTY_TYPE_LIST, PACKAGE_NAME } from "../../config";
3+
import { OBJECT_PROPERTY_TYPE_LIST, PACKAGE_NAME, STRING_LITERAL_TYPE_LIST } from "../../config";
44
import { getRequireDeclarators } from "../getRequireDeclarators";
55
import { getRequireProperty } from "../getRequireProperty";
66
import { objectPatternPropertyCompareFn } from "../objectPatternPropertyCompareFn";
@@ -75,7 +75,7 @@ export const addNamedModule = (
7575
const args = init.arguments;
7676
if (!args) return false;
7777
if (args.length !== 1) return false;
78-
if (args[0].type !== "Literal") return false;
78+
if (!STRING_LITERAL_TYPE_LIST.includes(args[0].type)) return true;
7979
if (typeof args[0].value !== "string") return false;
8080
if (!args[0].value.startsWith(PACKAGE_NAME)) return false;
8181

@@ -93,7 +93,7 @@ export const addNamedModule = (
9393

9494
const args = object.arguments;
9595
if (args.length !== 1) return false;
96-
if (args[0].type !== "Literal") return false;
96+
if (!STRING_LITERAL_TYPE_LIST.includes(args[0].type)) return true;
9797
if (args[0].value !== PACKAGE_NAME) return false;
9898

9999
return true;

0 commit comments

Comments
 (0)