From 0d9f351c8912cdcf7b0cf4813d140d6dec78fa7a Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Tue, 28 May 2024 19:01:25 +0200 Subject: [PATCH] fix: Handle cyclical reference to current file (#83) Closes #82 --- hook.js | 9 +++++++++ test/fixtures/cyclical-self.mjs | 8 ++++++++ test/hook/cyclical-self.mjs | 4 ++++ 3 files changed, 21 insertions(+) create mode 100644 test/fixtures/cyclical-self.mjs create mode 100644 test/hook/cyclical-self.mjs diff --git a/hook.js b/hook.js index 79a2e5b..5bea2b9 100644 --- a/hook.js +++ b/hook.js @@ -253,6 +253,15 @@ function createHook (meta) { return url } + // If the file is referencing itself, we need to skip adding the iitm search params + if (url.url === parentURL) { + return { + url: url.url, + shortCircuit: true, + format: url.format + } + } + specifiers.set(url.url, specifier) return { diff --git a/test/fixtures/cyclical-self.mjs b/test/fixtures/cyclical-self.mjs new file mode 100644 index 0000000..cabcb57 --- /dev/null +++ b/test/fixtures/cyclical-self.mjs @@ -0,0 +1,8 @@ +// File generated from our OpenAPI spec by Stainless. +import * as BatchesAPI from './cyclical-self.mjs' +export class Batches {} +export class BatchesPage {} +(function (Batches) { + Batches.BatchesPage = BatchesAPI.BatchesPage +// eslint-disable-next-line no-class-assign +})(Batches || (Batches = {})) diff --git a/test/hook/cyclical-self.mjs b/test/hook/cyclical-self.mjs new file mode 100644 index 0000000..4e40613 --- /dev/null +++ b/test/hook/cyclical-self.mjs @@ -0,0 +1,4 @@ +import { Batches, BatchesPage } from '../fixtures/cyclical-self.mjs' +import { strictEqual } from 'assert' + +strictEqual(Batches.BatchesPage, BatchesPage)