Skip to content

Commit

Permalink
Remove check for require global identifier (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Oct 17, 2023
1 parent 52b7c9c commit a01e797
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-panthers-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": patch
---

Remove check for require global identifier
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Collection, JSCodeshift, ObjectPattern, ObjectProperty, Property } from "jscodeshift";

import { OBJECT_PROPERTY_TYPE_LIST } from "../../config";
import { getDefaultLocalName } from "../../utils";
import { getRequireDeclarator } from "../getRequireDeclarator";
import { getRequireDeclarators } from "../getRequireDeclarators";
import { getRequireDeclaratorsWithIdentifier } from "../getRequireDeclaratorsWithIdentifier";
import { getRequireProperty } from "../getRequireProperty";
import { objectPatternPropertyCompareFn } from "../objectPatternPropertyCompareFn";
import { ClientModulesOptions, ImportSpecifierOptions } from "../types";
Expand All @@ -18,7 +16,6 @@ export const addClientNamedModule = (
options;
const localName = options.localName ?? importedName;

const defaultLocalName = getDefaultLocalName(v2ClientLocalName);
const clientObjectProperty = getRequireProperty(j, { importedName, localName });
const existingRequires = getRequireDeclarators(j, source, v3ClientPackageName);

Expand Down Expand Up @@ -46,21 +43,6 @@ export const addClientNamedModule = (
return;
}

const requireDeclaratorsWithIdentifier = getRequireDeclaratorsWithIdentifier(j, source, {
identifierName: defaultLocalName,
sourceValue: v3ClientPackageName,
});

if (requireDeclaratorsWithIdentifier && requireDeclaratorsWithIdentifier.nodes().length > 0) {
requireDeclaratorsWithIdentifier.at(0).insertAfter(
j.variableDeclarator(j.objectPattern([clientObjectProperty]), {
type: "Identifier",
name: defaultLocalName,
})
);
return;
}

if (existingRequireProperties.length > 0) {
const firstRequireProperties = (existingRequireProperties[0].id as ObjectPattern).properties;
firstRequireProperties.push(clientObjectProperty);
Expand Down

0 comments on commit a01e797

Please sign in to comment.