Skip to content

Commit 8f47a2f

Browse files
committed
Fix @babel/traverse import to work in non ESM environments
1 parent c5f032a commit 8f47a2f

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

.changeset/seven-plants-occur.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-docgen': patch
3+
---
4+
5+
Fix @babel/traverse import to work in non ESM environments

packages/react-docgen/src/FileState.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import type { HubInterface, Scope, Visitor } from '@babel/traverse';
2-
import traverse, { NodePath } from '@babel/traverse';
2+
import babelTraverse, { NodePath } from '@babel/traverse';
33
import type { File, Node, Program } from '@babel/types';
44
import type { Importer, ImportPath } from './importer/index.js';
55
import babelParse from './babelParser.js';
66
import type { TransformOptions } from '@babel/core';
77

8+
// Workaround while babel is not a proper ES module
9+
const traverse = babelTraverse.default ?? babelTraverse;
10+
811
export default class FileState {
912
opts: TransformOptions;
1013
path: NodePath<Program>;
@@ -85,6 +88,6 @@ export default class FileState {
8588
* Traverse the current file
8689
*/
8790
traverse(visitors: Visitor, state?: unknown): void {
88-
traverse.default(this.ast, visitors, this.scope, state);
91+
traverse(this.ast, visitors, this.scope, state);
8992
}
9093
}

pnpm-lock.yaml

Lines changed: 30 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)