Skip to content

Commit 26a09b0

Browse files
committed
fix: use 'as string' typecast for identifier.name
1 parent daa8990 commit 26a09b0

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

src/transforms/v2-to-v3/modules/importEqualsModule/getImportSpecifiers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const getImportSpecifiers = (
1010
const importSpecifiers = new Set<ImportSpecifierType>();
1111

1212
getImportEqualsDeclarations(j, source, path).forEach((importEqualsDeclaration) => {
13-
importSpecifiers.add({ localName: importEqualsDeclaration.value.id.name });
13+
importSpecifiers.add({ localName: importEqualsDeclaration.value.id.name as string });
1414
});
1515

1616
return Array.from(importSpecifiers);

src/transforms/v2-to-v3/modules/importEqualsModule/removeImportEquals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const isAnotherSpecifier = (j: JSCodeshift, source: Collection<unknown>, localNa
77

88
export const removeImportEquals = (j: JSCodeshift, source: Collection<unknown>) =>
99
getImportEqualsDeclarations(j, source).forEach((importEqualsDeclaration) => {
10-
const localName = importEqualsDeclaration.value.id.name;
10+
const localName = importEqualsDeclaration.value.id.name as string;
1111
const identifiers = source.find(j.Identifier, { name: localName });
1212

1313
// Either the identifier is the only occurence on the page.

src/transforms/v2-to-v3/modules/importModule/getImportSpecifiers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ export const getImportSpecifiers = (
1414
for (const specifier of specifiers) {
1515
switch (specifier.type) {
1616
case "ImportSpecifier": {
17-
const importedName = specifier.imported.name;
17+
const importedName = specifier.imported.name as string;
1818
importSpecifiers.add({
1919
importedName,
20-
localName: specifier.local?.name || importedName,
20+
localName: specifier.local?.name as string || importedName,
2121
});
2222
break;
2323
}
2424
case "ImportNamespaceSpecifier":
2525
case "ImportDefaultSpecifier": {
2626
if (specifier.local) {
27-
importSpecifiers.add({ localName: specifier.local.name });
27+
importSpecifiers.add({ localName: specifier.local.name as string });
2828
}
2929
break;
3030
}

src/transforms/v2-to-v3/modules/importModule/removeImport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const removeImport = (j: JSCodeshift, source: Collection<unknown>) =>
1818
getImportDeclarations(j, source).forEach((importDeclaration) => {
1919
importDeclaration.value.specifiers = (importDeclaration.value.specifiers || []).filter(
2020
(specifier) => {
21-
const localName = specifier.local?.name;
21+
const localName = specifier.local?.name as string;
2222
if (!localName) {
2323
return true;
2424
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@ export const importSpecifierCompareFn = (
99
specifier2: ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier
1010
) => {
1111
if (specifier1.type === "ImportSpecifier" && specifier2.type === "ImportSpecifier") {
12-
return specifier1.imported.name.localeCompare(specifier2.imported.name);
12+
const specifier1ImportedName = specifier1.imported.name as string;
13+
const specifier2ImportedName = specifier2.imported.name as string;
14+
return specifier1ImportedName.localeCompare(specifier2ImportedName);
1315
}
1416

17+
const specifier1LocalName = specifier1.local?.name as string;
18+
const specifier2LocalName = specifier2.local?.name as string;
19+
1520
if (
1621
specifier1.type === "ImportDefaultSpecifier" &&
1722
specifier2.type === "ImportDefaultSpecifier"
1823
) {
1924
if (specifier1.local && specifier2.local)
20-
return specifier1.local.name.localeCompare(specifier2.local.name);
25+
return specifier1LocalName.localeCompare(specifier2LocalName);
2126
return 0;
2227
}
2328

@@ -26,7 +31,7 @@ export const importSpecifierCompareFn = (
2631
specifier2.type === "ImportNamespaceSpecifier"
2732
) {
2833
if (specifier1.local && specifier2.local)
29-
return specifier1.local.name.localeCompare(specifier2.local.name);
34+
return specifier1LocalName.localeCompare(specifier2LocalName);
3035
return 0;
3136
}
3237

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {
22
ObjectProperty,
33
Property,
44
PropertyPattern,
5+
RestElement,
56
RestProperty,
67
SpreadProperty,
78
SpreadPropertyPattern,
@@ -13,6 +14,7 @@ export type ObjectPatternProperty =
1314
| SpreadPropertyPattern
1415
| SpreadProperty
1516
| ObjectProperty
17+
| RestElement
1618
| RestProperty;
1719

1820
export const objectPatternPropertyCompareFn = (
@@ -26,7 +28,9 @@ export const objectPatternPropertyCompareFn = (
2628
return 0;
2729
}
2830
if (property1.key.type === "Identifier" && property2.key.type === "Identifier") {
29-
return property1.key.name.localeCompare(property2.key.name);
31+
const property1KeyName = property1.key.name as string;
32+
const property2KeyName = property2.key.name as string;
33+
return property1KeyName.localeCompare(property2KeyName);
3034
}
3135
return 0;
3236
};

0 commit comments

Comments
 (0)