|
1 | 1 | import { writeFileSync } from 'fs'
|
2 | 2 | import { addNamed } from '@babel/helper-module-imports'
|
3 | 3 | 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' |
5 | 5 | import { dataComponentExcludes, dataComponentImportSourceExcludesRegex } from './data-component-excludes'
|
6 | 6 |
|
7 | 7 | type Import = {
|
@@ -244,20 +244,32 @@ const writeLog = () => {
|
244 | 244 | console.warn(stringified)
|
245 | 245 | writeFileSync('byondxr-babel-plugin.log', stringified)
|
246 | 246 | }
|
| 247 | +const filterFiles = (file: BabelFile) => { |
| 248 | + return /\.tsx$/.test(file.opts.filename || '') |
| 249 | +} |
247 | 250 | const plugin = (): PluginObj<Options> => {
|
248 | 251 | return {
|
249 | 252 | name: 'byondxr-babel-plugin',
|
250 |
| - pre() { |
| 253 | + pre(file) { |
| 254 | + if (!filterFiles(file)) { |
| 255 | + return |
| 256 | + } |
251 | 257 | this.actualImports = new Map()
|
252 | 258 | },
|
253 | 259 | visitor: {
|
254 | 260 | Program: {
|
255 | 261 | enter(p, state) {
|
| 262 | + if (!filterFiles(state.file)) { |
| 263 | + return |
| 264 | + } |
256 | 265 | p.traverse<Options>(componentVisitor.visitor, state)
|
257 | 266 | },
|
258 | 267 | },
|
259 | 268 | },
|
260 | 269 | post(file) {
|
| 270 | + if (!filterFiles(file)) { |
| 271 | + return |
| 272 | + } |
261 | 273 | if (!logFinished && file.opts.filename) {
|
262 | 274 | if (!filesEnteredMap.get(file.opts.filename)) {
|
263 | 275 | filesEnteredMap.set(file.opts.filename, true)
|
|
0 commit comments