Skip to content

Commit

Permalink
update new expression dynamic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
souporserious committed Oct 10, 2024
1 parent cb60f68 commit 72697ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-humans-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renoun': patch
---

Makes sure to update `Collection` new expressions with the related dynamic import.
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import type { Project, CallExpression } from 'ts-morph'
import type { Project, NewExpression } from 'ts-morph'
import tsMorph from 'ts-morph'

export function getCollectionCallExpressions(project: Project) {
const collectionSourceFile = project.createSourceFile(
'__collection.ts',
`import { collection } from 'renoun/collections';`
`import { Collection } from 'renoun/collections';`
)
const allCollections: CallExpression[] = []
const allCollections: NewExpression[] = []

collectionSourceFile
.getFirstDescendantByKindOrThrow(tsMorph.SyntaxKind.Identifier)
.findReferencesAsNodes()
.forEach((node) => {
const callExpression = node.getParentOrThrow()
if (tsMorph.Node.isCallExpression(callExpression)) {
const [firstArgument] = callExpression.getArguments()
const newExpression = node.getParentOrThrow()

if (tsMorph.Node.isObjectLiteralExpression(firstArgument)) {
allCollections.push(callExpression)
}
if (tsMorph.Node.isNewExpression(newExpression)) {
allCollections.push(newExpression)
}
})

Expand Down

0 comments on commit 72697ee

Please sign in to comment.