Skip to content

Commit 9b5f1b8

Browse files
authored
Fix operation migration runtime error when dynamic import is found (#395)
* Set up test * Fix dynamic import not having called function name * Add changeset
1 parent 89ea619 commit 9b5f1b8

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

.changeset/slick-bugs-sin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@eddeee888/gcg-operation-location-migration': patch
3+
---
4+
5+
Fix an issue where dynamic import function does not have an identifier and will cause runtime error
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file is not supposed to have any component or graphql docs
2+
// This is testing that codemod can handle files with dynamic imports
3+
import('node:console').then();

packages/operation-location-migration/src/preset.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,13 @@ export const preset: Types.OutputPreset<TypedPresetConfig> = {
221221
.getDescendantsOfKind(SyntaxKind.CallExpression)
222222
.forEach((callExpression) => {
223223
const calledFunctionName = callExpression
224-
.getFirstDescendantByKindOrThrow(SyntaxKind.Identifier)
225-
.getText();
224+
.getFirstDescendantByKind(SyntaxKind.Identifier)
225+
?.getText();
226+
227+
if (!calledFunctionName) {
228+
return;
229+
}
230+
226231
if (
227232
hooksToReplace[calledFunctionName] &&
228233
fileMetadata.functionsToReplace[calledFunctionName]

0 commit comments

Comments
 (0)