Skip to content

Commit

Permalink
Remove variable check for createIsomorphicFn and envOnly functions. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
EskiMojo14 authored Dec 9, 2024
1 parent 586cc7d commit ba80869
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 44 deletions.
13 changes: 3 additions & 10 deletions packages/start-vite-plugin/src/compilers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,6 @@ function buildEnvOnlyCallExpressionHandler(env: 'client' | 'server') {
if (debug)
console.info(`Handling ${env}Only call expression:`, path.toString())

if (!path.parentPath.isVariableDeclarator()) {
throw new Error(`${env}Only() functions must be assigned to a variable!`)
}

if (opts.env === env) {
// extract the inner function from the call expression
const innerInputExpression = path.node.arguments[0]
Expand Down Expand Up @@ -619,11 +615,6 @@ function handleCreateIsomorphicFnCallExpression(
rootCallExpression.toString(),
)

// Check if the call is assigned to a variable
if (!rootCallExpression.parentPath.isVariableDeclarator()) {
throw new Error('createIsomorphicFn must be assigned to a variable!')
}

const callExpressionPaths = {
client: null as babel.NodePath<t.CallExpression> | null,
server: null as babel.NodePath<t.CallExpression> | null,
Expand Down Expand Up @@ -653,7 +644,9 @@ function handleCreateIsomorphicFnCallExpression(
!callExpressionPaths[method as keyof typeof callExpressionPaths],
)
) {
const variableId = rootCallExpression.parentPath.node.id
const variableId = rootCallExpression.parentPath.isVariableDeclarator()
? rootCallExpression.parentPath.node.id
: null
console.warn(
'createIsomorphicFn called without a client or server implementation!',
'This will result in a no-op function.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,6 @@ describe('createIsomorphicFn compiles correctly', async () => {
})
}).toThrowError()
})
test('should be assigned to a variable', () => {
expect(() => {
compileStartOutput({
env: 'client',
code: `
import { createIsomorphicFn } from '@tanstack/start'
createIsomorphicFn()`,
root: './test-files',
filename: 'no-fn.ts',
})
}).toThrowError()
})
test('should warn to console if no implementations provided', () => {
compileStartOutput({
env: 'client',
Expand Down
22 changes: 0 additions & 22 deletions packages/start-vite-plugin/tests/envOnly/envOnly.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,4 @@ describe('envOnly functions compile correctly', async () => {
})
}).toThrowError()
})
test('should be assigned to a variable', () => {
expect(() => {
compileStartOutput({
env: 'server',
code: `
import { serverOnly } from '@tanstack/start'
serverOnly()`,
root: './test-files',
filename: 'no-fn.ts',
})
}).toThrowError()
expect(() => {
compileStartOutput({
env: 'client',
code: `
import { clientOnly } from '@tanstack/start'
clientOnly()`,
root: './test-files',
filename: 'no-fn.ts',
})
}).toThrowError()
})
})

0 comments on commit ba80869

Please sign in to comment.