Skip to content

Commit c0ee5a0

Browse files
authored
Merge pull request #34 from byondrnd/babel-plugin-limit-tsx
babel plugin limit to tsx
2 parents e000401 + b40ae89 commit c0ee5a0

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

.changeset/thirty-humans-reply.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@byondxr/babel-plugin": patch
3+
---
4+
5+
babel plugin lmit to tsx

packages/babel-plugin/src/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { writeFileSync } from 'fs'
22
import { addNamed } from '@babel/helper-module-imports'
33
import * as t from '@babel/types'
4-
import type { NodePath, PluginObj, PluginPass } from '@babel/core'
4+
import type { BabelFile, NodePath, PluginObj, PluginPass } from '@babel/core'
55
import { dataComponentExcludes, dataComponentImportSourceExcludesRegex } from './data-component-excludes'
66

77
type Import = {
@@ -244,20 +244,32 @@ const writeLog = () => {
244244
console.warn(stringified)
245245
writeFileSync('byondxr-babel-plugin.log', stringified)
246246
}
247+
const filterFiles = (file: BabelFile) => {
248+
return /\.tsx$/.test(file.opts.filename || '')
249+
}
247250
const plugin = (): PluginObj<Options> => {
248251
return {
249252
name: 'byondxr-babel-plugin',
250-
pre() {
253+
pre(file) {
254+
if (!filterFiles(file)) {
255+
return
256+
}
251257
this.actualImports = new Map()
252258
},
253259
visitor: {
254260
Program: {
255261
enter(p, state) {
262+
if (!filterFiles(state.file)) {
263+
return
264+
}
256265
p.traverse<Options>(componentVisitor.visitor, state)
257266
},
258267
},
259268
},
260269
post(file) {
270+
if (!filterFiles(file)) {
271+
return
272+
}
261273
if (!logFinished && file.opts.filename) {
262274
if (!filesEnteredMap.get(file.opts.filename)) {
263275
filesEnteredMap.set(file.opts.filename, true)

0 commit comments

Comments
 (0)