From cecfb45b433c5ef6314a2ef10b3181812e8e2665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Wed, 8 May 2024 14:21:27 +0200 Subject: [PATCH] Workaround rollup-plugin-dts bug --- packages/babel-traverse/src/visitors.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/babel-traverse/src/visitors.ts b/packages/babel-traverse/src/visitors.ts index 0e8facf33d2c..b2799b663bdf 100644 --- a/packages/babel-traverse/src/visitors.ts +++ b/packages/babel-traverse/src/visitors.ts @@ -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 @@ -43,7 +49,7 @@ export function isExplodedVisitor( * * `enter` and `exit` functions are wrapped in arrays, to ease merging of * visitors */ -export function explode(visitor: Visitor): ExplodedVisitor { +function explode$1(visitor: Visitor): ExplodedVisitor { if (isExplodedVisitor(visitor)) return visitor; // @ts-expect-error `visitor` will be cast to ExplodedVisitor by this function visitor._exploded = true; @@ -65,7 +71,7 @@ export function explode(visitor: Visitor): ExplodedVisitor { } // 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 :( @@ -157,7 +163,13 @@ export function explode(visitor: Visitor): ExplodedVisitor { 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; @@ -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 = visitor;