Skip to content

Commit

Permalink
fix: return early if nothing detected, close #9
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 25, 2021
1 parent d9caa35 commit a941fd0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/core/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export function transform(code: string, id: string, { matchRE, imports }: Transf
.forEach(i => matched.delete(i.trim()))
}

// nothing matched, skip
if (!matched.size)
return null

const modules: Record<string, ImportInfo[]> = {}

// group by module name
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/non-target.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
useNonTarget()
2 changes: 1 addition & 1 deletion test/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('transform', () => {
for (const file of files) {
it(file, async() => {
const fixture = await fs.readFile(resolve(root, file), 'utf-8')
expect(transform(fixture, file, options).code).toMatchSnapshot()
expect(transform(fixture, file, options)?.code ?? fixture).toMatchSnapshot()
})
}
})
Expand Down

0 comments on commit a941fd0

Please sign in to comment.