Skip to content

Commit 0f5c9d7

Browse files
ci: apply automated fixes
1 parent 99c1058 commit 0f5c9d7

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

packages/router-plugin/src/core/code-splitter/compilers.ts

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,9 @@ export function compileCodeSplitReferenceRoute(
531531
modified = true
532532

533533
// Track which variable declarations we've already processed to avoid duplicate processing
534-
const processedVarDecls = new Set<babel.NodePath<t.VariableDeclaration>>()
534+
const processedVarDecls = new Set<
535+
babel.NodePath<t.VariableDeclaration>
536+
>()
535537

536538
sharedModuleLevelIdents.forEach((identName) => {
537539
const binding = programPath.scope.getBinding(identName)
@@ -545,7 +547,8 @@ export function compileCodeSplitReferenceRoute(
545547
bindingPath.parentPath?.isVariableDeclaration() &&
546548
bindingPath.parentPath.parentPath?.isProgram()
547549
) {
548-
const varDecl = bindingPath.parentPath as babel.NodePath<t.VariableDeclaration>
550+
const varDecl =
551+
bindingPath.parentPath as babel.NodePath<t.VariableDeclaration>
549552

550553
// Only export const/let declarations (not imports or functions)
551554
if (
@@ -566,7 +569,10 @@ export function compileCodeSplitReferenceRoute(
566569
const localDeclarators: Array<t.VariableDeclarator> = []
567570

568571
declarators.forEach((declarator) => {
569-
if (t.isIdentifier(declarator.id) && sharedModuleLevelIdents.has(declarator.id.name)) {
572+
if (
573+
t.isIdentifier(declarator.id) &&
574+
sharedModuleLevelIdents.has(declarator.id.name)
575+
) {
570576
sharedDeclarators.push(declarator)
571577
knownExportedIdents.add(declarator.id.name)
572578
opts.sharedExports?.add(declarator.id.name)
@@ -576,17 +582,35 @@ export function compileCodeSplitReferenceRoute(
576582
})
577583

578584
// Replace with split declarations
579-
if (sharedDeclarators.length > 0 && localDeclarators.length > 0) {
585+
if (
586+
sharedDeclarators.length > 0 &&
587+
localDeclarators.length > 0
588+
) {
580589
// Both shared and local declarators
581-
const localVarDecl = t.variableDeclaration(varDecl.node.kind, localDeclarators)
582-
const sharedVarDecl = t.variableDeclaration(varDecl.node.kind, sharedDeclarators)
583-
const exportDecl = t.exportNamedDeclaration(sharedVarDecl, [])
590+
const localVarDecl = t.variableDeclaration(
591+
varDecl.node.kind,
592+
localDeclarators,
593+
)
594+
const sharedVarDecl = t.variableDeclaration(
595+
varDecl.node.kind,
596+
sharedDeclarators,
597+
)
598+
const exportDecl = t.exportNamedDeclaration(
599+
sharedVarDecl,
600+
[],
601+
)
584602

585603
varDecl.replaceWithMultiple([localVarDecl, exportDecl])
586604
} else if (sharedDeclarators.length > 0) {
587605
// All declarators are shared
588-
const sharedVarDecl = t.variableDeclaration(varDecl.node.kind, sharedDeclarators)
589-
const exportDecl = t.exportNamedDeclaration(sharedVarDecl, [])
606+
const sharedVarDecl = t.variableDeclaration(
607+
varDecl.node.kind,
608+
sharedDeclarators,
609+
)
610+
const exportDecl = t.exportNamedDeclaration(
611+
sharedVarDecl,
612+
[],
613+
)
590614
varDecl.replaceWith(exportDecl)
591615
}
592616
} else {

packages/router-plugin/tests/code-splitter/test-files/react/shared-destructuring.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { apiUrl } = cfg
77
export const Route = createFileRoute('/test')({
88
loader: async () => {
99
// Uses the destructured binding
10-
return fetch(apiUrl).then(r => r.json())
10+
return fetch(apiUrl).then((r) => r.json())
1111
},
1212
component: TestComponent,
1313
})

packages/router-plugin/tests/code-splitter/test-files/react/shared-partial-declarators.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { createFileRoute } from '@tanstack/react-router'
33
// Multiple declarators in same statement
44
// Only 'shared' is used by both loader and component
55
// 'a' is only used in component, should NOT be exported
6-
const a = 1, shared = new Map()
6+
const a = 1,
7+
shared = new Map()
78

89
export const Route = createFileRoute('/test')({
910
loader: async () => {

packages/router-plugin/tests/code-splitter/test-files/solid/shared-destructuring.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { apiUrl } = cfg
77
export const Route = createFileRoute('/test')({
88
loader: async () => {
99
// Uses the destructured binding
10-
return fetch(apiUrl).then(r => r.json())
10+
return fetch(apiUrl).then((r) => r.json())
1111
},
1212
component: TestComponent,
1313
})

packages/router-plugin/tests/code-splitter/test-files/solid/shared-partial-declarators.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { createFileRoute } from '@tanstack/solid-router'
33
// Multiple declarators in same statement
44
// Only 'shared' is used by both loader and component
55
// 'a' is only used in component, should NOT be exported
6-
const a = 1, shared = new Map()
6+
const a = 1,
7+
shared = new Map()
78

89
export const Route = createFileRoute('/test')({
910
loader: async () => {

0 commit comments

Comments
 (0)