Skip to content

Commit

Permalink
Workaround rollup-plugin-dts bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed May 8, 2024
1 parent a8ae5d7 commit cecfb45
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/babel-traverse/src/visitors.ts
Expand Up @@ -28,6 +28,12 @@ export function isExplodedVisitor(
return visitor?._exploded;
}

// We need to name this function `explode$1` because otherwise rollup-plugin-dts
// will generate a `namespace traverse { var explode: typeof explode; }` when
// bundling @babel/traverse's index.d.ts.
// TODO: Just call it `explode` once https://github.com/Swatinem/rollup-plugin-dts/issues/307
// is fixed.
export { explode$1 as explode };
/**
* explode() will take a visitor object with all of the various shorthands
* that we support, and validates & normalizes it into a common format, ready
Expand All @@ -43,7 +49,7 @@ export function isExplodedVisitor(
* * `enter` and `exit` functions are wrapped in arrays, to ease merging of
* visitors
*/
export function explode<S>(visitor: Visitor<S>): ExplodedVisitor<S> {
function explode$1<S>(visitor: Visitor<S>): ExplodedVisitor<S> {
if (isExplodedVisitor(visitor)) return visitor;
// @ts-expect-error `visitor` will be cast to ExplodedVisitor by this function
visitor._exploded = true;
Expand All @@ -65,7 +71,7 @@ export function explode<S>(visitor: Visitor<S>): ExplodedVisitor<S> {
}

// verify data structure
verify(visitor);
verify$1(visitor);

// make sure there's no __esModule type since this is because we're using loose mode
// and it sets __esModule to be enumerable on all modules :(
Expand Down Expand Up @@ -157,7 +163,13 @@ export function explode<S>(visitor: Visitor<S>): ExplodedVisitor<S> {
return visitor as ExplodedVisitor;
}

export function verify(visitor: Visitor) {
// We need to name this function `verify$1` because otherwise rollup-plugin-dts
// will generate a `namespace traverse { var verify: typeof verify; }` when
// bundling @babel/traverse's index.d.ts.
// TODO: Just call it `verify` once https://github.com/Swatinem/rollup-plugin-dts/issues/307
// is fixed.
export { verify$1 as verify };
function verify$1(visitor: Visitor) {
// @ts-expect-error _verified is not defined on non-verified Visitor.
// TODO: unify _verified and _exploded.
if (visitor._verified) return;
Expand Down Expand Up @@ -237,7 +249,7 @@ export function merge(
const mergedVisitor: ExplodedVisitor = {};

for (let i = 0; i < visitors.length; i++) {
const visitor = explode(visitors[i]);
const visitor = explode$1(visitors[i]);
const state = states[i];

let topVisitor: ExplVisitNode<unknown, Node> = visitor;
Expand Down

0 comments on commit cecfb45

Please sign in to comment.