Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const LookupSetup: Record<
// 1. Pre-scanning code to determine which kinds to look for (before AST parsing)
// 2. Deriving the plugin's transform code filter
export const KindDetectionPatterns: Record<LookupKind, RegExp> = {
ServerFn: /\.handler\s*\(/,
ServerFn: /\bcreateServerFn\b|\.\s*handler\s*\(/,
Middleware: /createMiddleware/,
IsomorphicFn: /createIsomorphicFn/,
ServerOnlyFn: /createServerOnlyFn/,
Expand Down
33 changes: 32 additions & 1 deletion packages/start-plugin-core/tests/compiler.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from 'vitest'
import {
detectKindsInCode,
StartCompiler,
detectKindsInCode,
} from '../src/start-compiler-plugin/compiler'
import type {
LookupConfig,
Expand Down Expand Up @@ -201,6 +201,37 @@ describe('detectKindsInCode', () => {
expect(detectKindsInCode(code4, 'client')).toEqual(new Set(['ServerFn']))
})

test('handles whitespace between . and handler (reformatted code)', () => {
// When Vite/Babel reformats code, the dot can end up on a previous line
const code1 = `fn.\nhandler(() => {})`
const code2 = `fn.\n handler(() => {})`
const code3 = `fn. \n handler(() => {})`

expect(detectKindsInCode(code1, 'client')).toEqual(new Set(['ServerFn']))
expect(detectKindsInCode(code2, 'client')).toEqual(new Set(['ServerFn']))
expect(detectKindsInCode(code3, 'client')).toEqual(new Set(['ServerFn']))
})

test('detects createServerFn() call directly', () => {
// The pattern should match createServerFn() calls, not just .handler()
const code = `
import { createServerFn } from '@tanstack/react-start'
const fn = createServerFn()
`
expect(detectKindsInCode(code, 'client')).toEqual(new Set(['ServerFn']))
})

test('does not false positive on similar function names', () => {
// Only exact createServerFn( should match, not variations
const code = `
const fn = createServerFnExample()
const fn2 = createServerFnLike()
const fn3 = mycreateServerFn()
const fn4 = _createServerFn()
`
expect(detectKindsInCode(code, 'client')).toEqual(new Set())
})

test('does not false positive on similar names', () => {
const code = `
const myCreateServerFn = () => {}
Expand Down
Loading