Skip to content

Commit b4b9dc0

Browse files
ci: apply automated fixes
1 parent a11f578 commit b4b9dc0

File tree

1 file changed

+52
-28
lines changed

1 file changed

+52
-28
lines changed

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

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,19 @@ export function compileCodeSplitReferenceRoute(
167167
}
168168

169169
// Helper to collect all identifiers referenced by a node
170-
const collectReferencedIdentifiers = (propPath: babel.NodePath<t.ObjectProperty>): Set<string> => {
170+
const collectReferencedIdentifiers = (
171+
propPath: babel.NodePath<t.ObjectProperty>,
172+
): Set<string> => {
171173
const identifiers = new Set<string>()
172174
const valuePath = propPath.get('value')
173175

174176
// If the value is an identifier, we need to follow it to its definition
175177
const pathsToAnalyze: Array<babel.NodePath> = []
176178

177179
if (valuePath.isIdentifier()) {
178-
const binding = programPath.scope.getBinding(valuePath.node.name)
180+
const binding = programPath.scope.getBinding(
181+
valuePath.node.name,
182+
)
179183
if (binding) {
180184
pathsToAnalyze.push(binding.path)
181185
}
@@ -184,7 +188,7 @@ export function compileCodeSplitReferenceRoute(
184188
}
185189

186190
// Traverse each path to find all referenced identifiers
187-
pathsToAnalyze.forEach(analyzePath => {
191+
pathsToAnalyze.forEach((analyzePath) => {
188192
analyzePath.traverse({
189193
Identifier(idPath) {
190194
// Only collect identifiers that are references (not declarations)
@@ -254,20 +258,22 @@ export function compileCodeSplitReferenceRoute(
254258
if (!t.isIdentifier(propPath.node.key)) return
255259

256260
const key = propPath.node.key.name
257-
const willBeSplit = findIndexForSplitNode(key) !== -1 && SPLIT_NODES_CONFIG.has(key as any)
261+
const willBeSplit =
262+
findIndexForSplitNode(key) !== -1 &&
263+
SPLIT_NODES_CONFIG.has(key as any)
258264

259265
const idents = collectReferencedIdentifiers(propPath)
260266

261267
if (willBeSplit) {
262-
idents.forEach(id => splitPropertyIdents.add(id))
268+
idents.forEach((id) => splitPropertyIdents.add(id))
263269
} else {
264-
idents.forEach(id => nonSplitPropertyIdents.add(id))
270+
idents.forEach((id) => nonSplitPropertyIdents.add(id))
265271
}
266272
},
267273
})
268274

269275
// Find shared identifiers that need to be exported
270-
splitPropertyIdents.forEach(ident => {
276+
splitPropertyIdents.forEach((ident) => {
271277
if (nonSplitPropertyIdents.has(ident)) {
272278
sharedModuleLevelIdents.add(ident)
273279
}
@@ -890,7 +896,11 @@ export function compileCodeSplitVirtualRoute(
890896
VariableDeclaration(varDeclPath) {
891897
// Only process top-level const/let declarations
892898
if (!varDeclPath.parentPath.isProgram()) return
893-
if (varDeclPath.node.kind !== 'const' && varDeclPath.node.kind !== 'let') return
899+
if (
900+
varDeclPath.node.kind !== 'const' &&
901+
varDeclPath.node.kind !== 'let'
902+
)
903+
return
894904

895905
varDeclPath.node.declarations.forEach((declarator) => {
896906
if (!t.isIdentifier(declarator.id)) return
@@ -908,17 +918,25 @@ export function compileCodeSplitVirtualRoute(
908918

909919
// Check if this variable is used by the split node
910920
// If it is, it might be shared with non-split parts and should be imported
911-
const isUsedBySplitNode = intendedSplitNodes.values().next().value &&
912-
Object.values(trackedNodesToSplitByType).some(tracked => {
921+
const isUsedBySplitNode =
922+
intendedSplitNodes.values().next().value &&
923+
Object.values(trackedNodesToSplitByType).some((tracked) => {
913924
if (!tracked?.node) return false
914925
let isUsed = false
915-
babel.traverse(tracked.node, {
916-
Identifier(idPath) {
917-
if (idPath.isReferencedIdentifier() && idPath.node.name === varName) {
918-
isUsed = true
919-
}
920-
}
921-
}, programPath.scope)
926+
babel.traverse(
927+
tracked.node,
928+
{
929+
Identifier(idPath) {
930+
if (
931+
idPath.isReferencedIdentifier() &&
932+
idPath.node.name === varName
933+
) {
934+
isUsed = true
935+
}
936+
},
937+
},
938+
programPath.scope,
939+
)
922940
return isUsed
923941
})
924942

@@ -935,21 +953,25 @@ export function compileCodeSplitVirtualRoute(
935953
VariableDeclaration(varDeclPath) {
936954
if (!varDeclPath.parentPath.isProgram()) return
937955

938-
const declaratorsToKeep = varDeclPath.node.declarations.filter((declarator) => {
939-
if (!t.isIdentifier(declarator.id)) return true
940-
const varName = declarator.id.name
956+
const declaratorsToKeep = varDeclPath.node.declarations.filter(
957+
(declarator) => {
958+
if (!t.isIdentifier(declarator.id)) return true
959+
const varName = declarator.id.name
941960

942-
if (sharedVariablesToImport.includes(varName)) {
943-
importedSharedIdents.add(varName)
944-
return false // Remove this declarator
945-
}
946-
return true
947-
})
961+
if (sharedVariablesToImport.includes(varName)) {
962+
importedSharedIdents.add(varName)
963+
return false // Remove this declarator
964+
}
965+
return true
966+
},
967+
)
948968

949969
if (declaratorsToKeep.length === 0) {
950970
// Remove the entire variable declaration
951971
varDeclPath.remove()
952-
} else if (declaratorsToKeep.length < varDeclPath.node.declarations.length) {
972+
} else if (
973+
declaratorsToKeep.length < varDeclPath.node.declarations.length
974+
) {
953975
// Update with remaining declarators
954976
varDeclPath.node.declarations = declaratorsToKeep
955977
}
@@ -962,7 +984,9 @@ export function compileCodeSplitVirtualRoute(
962984
Array.from(importedSharedIdents).map((name) =>
963985
t.importSpecifier(t.identifier(name), t.identifier(name)),
964986
),
965-
t.stringLiteral(removeSplitSearchParamFromFilename(opts.filename)),
987+
t.stringLiteral(
988+
removeSplitSearchParamFromFilename(opts.filename),
989+
),
966990
)
967991
programPath.unshiftContainer('body', importDecl)
968992

0 commit comments

Comments
 (0)