Skip to content

Commit f63ed09

Browse files
committed
ast transform fix
1 parent 5039c35 commit f63ed09

File tree

9 files changed

+35
-20
lines changed

9 files changed

+35
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-router-devtools",
33
"description": "Devtools for React Router - debug, trace, find hydration errors, catch bugs and inspect server/client data with react-router-devtools",
44
"author": "Alem Tuzlak",
5-
"version": "5.0.0",
5+
"version": "5.0.1",
66
"license": "MIT",
77
"keywords": [
88
"react-router",

src/vite/plugin.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
197197
},
198198
},
199199
{
200-
name: "react-router-devtools-inject-context",
200+
name: "react-router-devtools:inject-context",
201201
apply(config) {
202202
return shouldInject(config.mode, includeDevtools)
203203
},
@@ -211,7 +211,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
211211
},
212212
},
213213
{
214-
name: "react-router-devtools-data-function-augment",
214+
name: "react-router-devtools:data-function-augment",
215215
apply(config) {
216216
return shouldInject(config.mode, includeServer)
217217
},
@@ -226,7 +226,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
226226
},
227227
{
228228
enforce: "pre",
229-
name: "react-router-devtools-custom-server",
229+
name: "react-router-devtools:custom-server",
230230
apply(config) {
231231
// Custom server is only needed in development for piping events to the client
232232
return config.mode === "development"

src/vite/utils/data-functions-augment.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe("transform", () => {
6464
expect(removeWhitespace(result.code)).toStrictEqual(expected)
6565
})
6666

67-
it("should transform the loader export when it's re-exported from another file", () => {
67+
it("should transform the loader export when it's re-exported from another file and remove empty export declaration", () => {
6868
const result = augmentDataFetchingFunctions(
6969
`
7070
export { loader } from "./loader.js";
@@ -76,7 +76,7 @@ describe("transform", () => {
7676
import { withLoaderWrapper as _withLoaderWrapper } from "react-router-devtools/server";
7777
import { loader as _loader } from "./loader.js";
7878
export const loader = _withLoaderWrapper(_loader, "test");
79-
export {} from "./loader.js";
79+
8080
`)
8181
expect(removeWhitespace(result.code)).toStrictEqual(expected)
8282
})
@@ -242,7 +242,7 @@ describe("transform", () => {
242242
expect(removeWhitespace(result.code)).toStrictEqual(expected)
243243
})
244244

245-
it("should transform the client action export when it's re-exported from another file", () => {
245+
it("should transform the client action export when it's re-exported from another file and remove empty export declaration", () => {
246246
const result = augmentDataFetchingFunctions(
247247
`
248248
export { clientLoader } from "./clientLoader.js";
@@ -254,7 +254,6 @@ describe("transform", () => {
254254
import { withClientLoaderWrapper as _withClientLoaderWrapper } from "react-router-devtools/client";
255255
import { clientLoader as _clientLoader } from "./clientLoader.js";
256256
export const clientLoader = _withClientLoaderWrapper(_clientLoader, "test");
257-
export {} from "./clientLoader.js";
258257
`)
259258
expect(removeWhitespace(result.code)).toStrictEqual(expected)
260259
})
@@ -347,7 +346,7 @@ describe("transform", () => {
347346
expect(removeWhitespace(result.code)).toStrictEqual(expected)
348347
})
349348

350-
it("should transform the action export when it's re-exported from another file", () => {
349+
it("should transform the action export when it's re-exported from another file and remove empty export declaration", () => {
351350
const result = augmentDataFetchingFunctions(
352351
`
353352
export { action } from "./action.js";
@@ -359,7 +358,6 @@ describe("transform", () => {
359358
import { withActionWrapper as _withActionWrapper } from "react-router-devtools/server";
360359
import { action as _action } from "./action.js";
361360
export const action = _withActionWrapper(_action, "test");
362-
export {} from "./action.js";
363361
`)
364362
expect(removeWhitespace(result.code)).toStrictEqual(expected)
365363
})
@@ -487,7 +485,7 @@ describe("transform", () => {
487485
expect(removeWhitespace(result.code)).toStrictEqual(expected)
488486
})
489487

490-
it("should transform the client action export when it's re-exported from another file", () => {
488+
it("should transform the client action export when it's re-exported from another file and remove empty export declaration", () => {
491489
const result = augmentDataFetchingFunctions(
492490
`
493491
export { clientAction } from "./clientAction.js";
@@ -499,7 +497,6 @@ describe("transform", () => {
499497
import { withClientActionWrapper as _withClientActionWrapper } from "react-router-devtools/client";
500498
import { clientAction as _clientAction } from "./clientAction.js";
501499
export const clientAction = _withClientActionWrapper(_clientAction, "test");
502-
export {} from "./clientAction.js";
503500
`)
504501
expect(removeWhitespace(result.code)).toStrictEqual(expected)
505502
})

src/vite/utils/data-functions-augment.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ const transform = (ast: ParseResult<Babel.File>, routeId: string) => {
124124
)
125125

126126
path.replaceWith(t.exportNamedDeclaration(null, remainingSpecifiers, path.node.source))
127+
128+
const newRemainingSpecifiers = path.node.specifiers.length
129+
if (newRemainingSpecifiers === 0) {
130+
path.remove()
131+
}
127132
})
128133
} else if (binding?.path.isFunctionDeclaration()) {
129134
// Replace the function declaration with a wrapped version

src/vite/utils/inject-context.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe("transform", () => {
6464
expect(removeWhitespace(result.code)).toStrictEqual(expected)
6565
})
6666

67-
it("should transform the loader export when it's re-exported from another file", () => {
67+
it("should transform the loader export when it's re-exported from another file and remove empty export declaration", () => {
6868
const result = injectContext(
6969
`
7070
export { loader } from "./loader.js";
@@ -76,7 +76,6 @@ describe("transform", () => {
7676
import { withLoaderContextWrapper as _withLoaderContextWrapper } from "react-router-devtools/context";
7777
import { loader as _loader } from "./loader.js";
7878
export const loader = _withLoaderContextWrapper(_loader, "test");
79-
export {} from "./loader.js";
8079
`)
8180
expect(removeWhitespace(result.code)).toStrictEqual(expected)
8281
})
@@ -196,7 +195,7 @@ describe("transform", () => {
196195
expect(removeWhitespace(result.code)).toStrictEqual(expected)
197196
})
198197

199-
it("should transform the client loader export when it's re-exported from another file", () => {
198+
it("should transform the client loader export when it's re-exported from another file and remove empty export declaration", () => {
200199
const result = injectContext(
201200
`
202201
export { clientLoader } from "./clientLoader.js";
@@ -208,7 +207,6 @@ describe("transform", () => {
208207
import { withClientLoaderContextWrapper as _withClientLoaderContextWrapper } from "react-router-devtools/context";
209208
import { clientLoader as _clientLoader } from "./clientLoader.js";
210209
export const clientLoader = _withClientLoaderContextWrapper(_clientLoader, "test");
211-
export {} from "./clientLoader.js";
212210
`)
213211
expect(removeWhitespace(result.code)).toStrictEqual(expected)
214212
})
@@ -274,7 +272,7 @@ describe("transform", () => {
274272
expect(removeWhitespace(result.code)).toStrictEqual(expected)
275273
})
276274

277-
it("should transform the action export when it's re-exported from another file", () => {
275+
it("should transform the action export when it's re-exported from another file and remove empty export declaration", () => {
278276
const result = injectContext(
279277
`
280278
export { action } from "./action.js";
@@ -286,7 +284,6 @@ describe("transform", () => {
286284
import { withActionContextWrapper as _withActionContextWrapper } from "react-router-devtools/context";
287285
import { action as _action } from "./action.js";
288286
export const action = _withActionContextWrapper(_action, "test");
289-
export {} from "./action.js";
290287
`)
291288
expect(removeWhitespace(result.code)).toStrictEqual(expected)
292289
})
@@ -406,7 +403,7 @@ describe("transform", () => {
406403
expect(removeWhitespace(result.code)).toStrictEqual(expected)
407404
})
408405

409-
it("should transform the clientAction export when it's re-exported from another file", () => {
406+
it("should transform the clientAction export when it's re-exported from another file and remove empty export declaration", () => {
410407
const result = injectContext(
411408
`
412409
export { clientAction } from "./clientAction.js";
@@ -418,7 +415,6 @@ describe("transform", () => {
418415
import { withClientActionContextWrapper as _withClientActionContextWrapper } from "react-router-devtools/context";
419416
import { clientAction as _clientAction } from "./clientAction.js";
420417
export const clientAction = _withClientActionContextWrapper(_clientAction, "test");
421-
export {} from "./clientAction.js";
422418
`)
423419
expect(removeWhitespace(result.code)).toStrictEqual(expected)
424420
})

src/vite/utils/inject-context.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ const transform = (ast: ParseResult<Babel.File>, routeId: string) => {
108108
)
109109

110110
path.replaceWith(t.exportNamedDeclaration(null, remainingSpecifiers, path.node.source))
111+
112+
const newRemainingSpecifiers = path.node.specifiers.length
113+
if (newRemainingSpecifiers === 0) {
114+
path.remove()
115+
}
111116
})
112117
} else if (binding?.path.isFunctionDeclaration()) {
113118
// Replace the function declaration with a wrapped version
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const action = () => {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const NoteEditor = () =>{ return <div /> }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
import { NoteEditor } from './__note-editor'
3+
4+
export { action } from './__note-editor.server'
5+
6+
export async function loader({ request }: any) {
7+
return {}
8+
}
9+
10+
export default NoteEditor

0 commit comments

Comments
 (0)