Repository: un-ts/eslint-plugin-import-x (ts)

Issue:
dynamic-import-chunkname: `Cannot read properties of undefined (reading 'range')`
I'm trying to migrate from import to import-x and I got this error:

```js
TypeError: Cannot read properties of undefined (reading 'range')
Occurred while linting ~/libs/util-hooks/src/lib/useAbortSignal.ts:29
Rule: "import-x/dynamic-import-chunkname"
    at SourceCode.getCommentsBefore (~/node_modules/eslint/lib/languages/js/source-code/token-store/index.js:684:16)
    at run (~/node_modules/eslint-plugin-import-x/lib/rules/dynamic-import-chunkname.js:55:48)
    at CallExpression (~/node_modules/eslint-plugin-import-x/lib/rules/dynamic-import-chunkname.js:180:17)
    at ruleErrorHandler (~/node_modules/eslint/lib/linter/linter.js:1310:33)
    at ~/node_modules/eslint/lib/linter/safe-emitter.js:45:46
    at Array.forEach (<anonymous>)
    at Object.emit (~/node_modules/eslint/lib/linter/safe-emitter.js:45:26)
    at NodeEventGenerator.applySelector (~/node_modules/eslint/lib/linter/node-event-generator.js:171:17)
    at NodeEventGenerator.applySelectors (~/node_modules/eslint/lib/linter/node-event-generator.js:227:10)
    at NodeEventGenerator.enterNode (~/node_modules/eslint/lib/linter/node-event-generator.js:241:8)
```

This is because this extra line that was added during the TS migration:

```diff

            CallExpression(node) {
                if (node.callee.type !== 'Import' &&
+                   'name' in node.callee &&
                    !importFunctions.includes(node.callee.name)) {
                    return;
                }
                run(node, node.arguments[0]);
            },
```

If I remove it, the linting succeeds.

The `node.callee` in question looks like this:

```js

{
  a: <ref *1> {
    type: 'MemberExpression',
    computed: false,
    object: {
      type: 'Identifier',
      decorators: [],
      name: 'unsubscribe',
      optional: false,
      typeAnnotation: undefined,
      range: [Array],
      loc: [Object],
      parent: [Circular *1]
    },
    optional: false,
    property: {
      type: 'Identifier',
      decorators: [],
      name: 'abort',
      optional: false,
      typeAnnotation: undefined,
      range: [Array],
      loc: [Object],
      parent: [Circular *1]
    },
    range: [ 1115, 1132 ],
    loc: { end: [Object], start: [Object] },
    parent: {
      type: 'CallExpression',
      arguments: [],
      callee: [Circular *1],
      optional: false,
      typeArguments: undefined,
      range: [Array],
      loc: [Object],
      parent: [Object]
    }
  }
}
```

and the source code being linted is:

```ts
import { useSyncExternalStore } from "use-sync-external-store/shim";

export default function useAbortSignal(signal: AbortSignal): boolean {
  return useSyncExternalStore(
    (callback: () => void) => {
      const unsubscribe = new AbortController();
      signal.addEventListener("abort", callback, {
        signal: unsubscribe.signal,
        once: true,
      });
      return () => {
        unsubscribe.abort();
      };
    },
    () => signal.aborted,
  );
}
```

Pull request:
fix: rule `dynamic-import-chunkname` crash due to ts migration
close #345
<!-- ELLIPSIS_HIDDEN -->


----

> [!IMPORTANT]
> Fix crash in `dynamic-import-chunkname` rule by improving dynamic import checks and add a new TypeScript test case.
> 
>   - **Bug Fixes**:
>     - Fix crash in `dynamic-import-chunkname` rule in `dynamic-import-chunkname.ts` by improving handling of dynamic import checks when certain properties are missing.
>   - **Tests**:
>     - Add new valid TypeScript test case in `dynamic-import-chunkname.spec.ts` for dynamic import chunk name validation.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=un-ts%2Feslint-plugin-import-x&utm_source=github&utm_medium=referral)<sup> for dd22dba6995897826e9287e11f26ac4830426cd6. You can [customize](https://app.ellipsis.dev/un-ts/settings/summaries) this summary. It will automatically update as commits are pushed.</sup>

----


<!-- ELLIPSIS_HIDDEN -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **Bug Fixes**
	- Improved handling of dynamic import checks to better support cases where certain properties may be missing.
- **Tests**
	- Added a new valid TypeScript test case for dynamic import chunk name validation, enhancing test coverage.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Patch:
diff --git a/.changeset/pink-readers-design.md b/.changeset/pink-readers-design.md
new file mode 100644
index 00000000..ba3c51e0
--- /dev/null
+++ b/.changeset/pink-readers-design.md
@@ -0,0 +1,5 @@
+---
+"eslint-plugin-import-x": patch
+---
+
+fix: rule `dynamic-import-chunkname` crash due to ts migration
diff --git a/src/rules/dynamic-import-chunkname.ts b/src/rules/dynamic-import-chunkname.ts
index bf4e6544..6fa2bff9 100644
--- a/src/rules/dynamic-import-chunkname.ts
+++ b/src/rules/dynamic-import-chunkname.ts
@@ -232,8 +232,8 @@ export default createRule<[Options?], MessageId>({
         if (
           // @ts-expect-error - legacy parser type
           node.callee.type !== 'Import' &&
-          'name' in node.callee &&
-          !importFunctions.includes(node.callee.name)
+          (!('name' in node.callee) ||
+            !importFunctions.includes(node.callee.name))
         ) {
           return
         }


Test patch:
diff --git a/test/rules/dynamic-import-chunkname.spec.ts b/test/rules/dynamic-import-chunkname.spec.ts
index f7343363..d5db2feb 100644
--- a/test/rules/dynamic-import-chunkname.spec.ts
+++ b/test/rules/dynamic-import-chunkname.spec.ts
@@ -1136,6 +1136,26 @@ describe('TypeScript', () => {
           )`,
         options,
       },
+      {
+        code: `import { useSyncExternalStore } from "use-sync-external-store/shim";
+
+export default function useAbortSignal(signal: AbortSignal): boolean {
+  return useSyncExternalStore(
+    (callback: () => void) => {
+      const unsubscribe = new AbortController();
+      signal.addEventListener("abort", callback, {
+        signal: unsubscribe.signal,
+        once: true,
+      });
+      return () => {
+        unsubscribe.abort();
+      };
+    },
+    () => signal.aborted,
+  );
+}`,
+        options,
+      },
     ],
     invalid: [
       {