Skip to content

Commit

Permalink
Consolidate server actions transform errors into emit_error function (
Browse files Browse the repository at this point in the history
#72811)

This improves maintainability and readability by decluttering the server actions transforms implementation, dedupes a few error messages, and consistently uses periods and trailing newlines for all error messages.

The same approach is already used for the React Server Components transforms.
  • Loading branch information
unstubbable authored Nov 15, 2024
1 parent 086f715 commit 0f9f442
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 198 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/next-custom-transforms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ easy-error = "1.0.0"
either = "1"
fxhash = "0.2.1"
hex = "0.4.3"
indoc = { workspace = true }
once_cell = { workspace = true }
pathdiff = { workspace = true }
regex = "1.5"
Expand Down
423 changes: 227 additions & 196 deletions crates/next-custom-transforms/src/transforms/server_actions.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
x Server Actions must be async functions
x Server Actions must be async functions.
|
,-[input.js:3:1]
2 |
3 | export function foo() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
x The "use server" directive must be at the top of the file, and cannot be wrapped in parentheses.
|
,-[input.js:2:1]
1 | import 'react'
2 | ;('use sevrer')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
x "use cache" functions must be async functions.
|
,-[input.js:3:1]
2 |
3 | export default function () {}
: ^^^^^^^^^^^^^^
4 | export function foo() {}
`----
x "use cache" functions must be async functions.
|
,-[input.js:4:1]
3 | export default function () {}
4 | export function foo() {}
: ^^^
5 | export const bar = () => {}
`----
x "use cache" functions must be async functions.
|
,-[input.js:5:1]
4 | export function foo() {}
5 | export const bar = () => {}
: ^^^^^^^^
6 | export const baz = 42
`----
x Only async functions are allowed to be exported in a "use cache" file.
|
,-[input.js:6:1]
5 | export const bar = () => {}
6 | export const baz = 42
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
x "use cache" functions must be async functions.
|
,-[input.js:1:1]
1 | ,-> export default function () {
2 | | 'use cache'
3 | `-> }
`----
x "use cache" functions must be async functions.
|
,-[input.js:5:1]
4 |
5 | export function foo() {
: ^^^
6 | 'use cache'
`----
x "use cache" functions must be async functions.
|
,-[input.js:9:1]
8 |
9 | ,-> export const bar = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
x Server Actions must be async functions
x Server Actions must be async functions.
|
,-[input.js:7:1]
6 |
7 | export function bar() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
x Only async functions are allowed to be exported in a "use server" file.
|
,-[input.js:3:1]
2 |
3 | export const x = 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
x Only async functions are allowed to be exported in a "use server" file.
|
,-[input.js:3:1]
2 |
3 | ,-> export default class Component {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
x Only async functions are allowed to be exported in a "use server" file.
|
,-[input.js:3:1]
2 |
3 | export * from 'foo'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
x Server Actions must be async functions.
|
,-[input.js:3:1]
2 |
3 | export default () => {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
x Server Actions must be async functions.
|
,-[input.js:1:1]
1 | ,-> const foo = () => {
2 | | 'use server'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
x The "use server" directive must be at the top of the function body.
|
,-[input.js:10:1]
9 | // prettier-ignore
10 | 'use server'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
x The "use server" directive must be at the top of the file.
|
,-[input.js:4:1]
3 | // prettier-ignore
4 | 'use server'
Expand Down

0 comments on commit 0f9f442

Please sign in to comment.