Unverified Commit 0f9f442b authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Consolidate server actions transform errors into `emit_error` function (#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.
parent 086f715c
...@@ -4063,6 +4063,7 @@ dependencies = [ ...@@ -4063,6 +4063,7 @@ dependencies = [
"either", "either",
"fxhash", "fxhash",
"hex", "hex",
"indoc",
"lazy_static", "lazy_static",
"modularize_imports", "modularize_imports",
"once_cell", "once_cell",
......
...@@ -19,6 +19,7 @@ easy-error = "1.0.0" ...@@ -19,6 +19,7 @@ easy-error = "1.0.0"
either = "1" either = "1"
fxhash = "0.2.1" fxhash = "0.2.1"
hex = "0.4.3" hex = "0.4.3"
indoc = { workspace = true }
once_cell = { workspace = true } once_cell = { workspace = true }
pathdiff = { workspace = true } pathdiff = { workspace = true }
regex = "1.5" regex = "1.5"
......
x Server Actions must be async functions x Server Actions must be async functions.
|
,-[input.js:3:1] ,-[input.js:3:1]
2 | 2 |
3 | export function foo() {} 3 | export function foo() {}
......
x The "use server" directive must be at the top of the file, and cannot be wrapped in parentheses. x The "use server" directive must be at the top of the file, and cannot be wrapped in parentheses.
|
,-[input.js:2:1] ,-[input.js:2:1]
1 | import 'react' 1 | import 'react'
2 | ;('use sevrer') 2 | ;('use sevrer')
......
x "use cache" functions must be async functions. x "use cache" functions must be async functions.
|
,-[input.js:3:1] ,-[input.js:3:1]
2 | 2 |
3 | export default function () {} 3 | export default function () {}
...@@ -6,6 +7,7 @@ ...@@ -6,6 +7,7 @@
4 | export function foo() {} 4 | export function foo() {}
`---- `----
x "use cache" functions must be async functions. x "use cache" functions must be async functions.
|
,-[input.js:4:1] ,-[input.js:4:1]
3 | export default function () {} 3 | export default function () {}
4 | export function foo() {} 4 | export function foo() {}
...@@ -13,6 +15,7 @@ ...@@ -13,6 +15,7 @@
5 | export const bar = () => {} 5 | export const bar = () => {}
`---- `----
x "use cache" functions must be async functions. x "use cache" functions must be async functions.
|
,-[input.js:5:1] ,-[input.js:5:1]
4 | export function foo() {} 4 | export function foo() {}
5 | export const bar = () => {} 5 | export const bar = () => {}
...@@ -20,6 +23,7 @@ ...@@ -20,6 +23,7 @@
6 | export const baz = 42 6 | export const baz = 42
`---- `----
x Only async functions are allowed to be exported in a "use cache" file. x Only async functions are allowed to be exported in a "use cache" file.
|
,-[input.js:6:1] ,-[input.js:6:1]
5 | export const bar = () => {} 5 | export const bar = () => {}
6 | export const baz = 42 6 | export const baz = 42
......
x "use cache" functions must be async functions. x "use cache" functions must be async functions.
|
,-[input.js:1:1] ,-[input.js:1:1]
1 | ,-> export default function () { 1 | ,-> export default function () {
2 | | 'use cache' 2 | | 'use cache'
3 | `-> } 3 | `-> }
`---- `----
x "use cache" functions must be async functions. x "use cache" functions must be async functions.
|
,-[input.js:5:1] ,-[input.js:5:1]
4 | 4 |
5 | export function foo() { 5 | export function foo() {
...@@ -12,6 +14,7 @@ ...@@ -12,6 +14,7 @@
6 | 'use cache' 6 | 'use cache'
`---- `----
x "use cache" functions must be async functions. x "use cache" functions must be async functions.
|
,-[input.js:9:1] ,-[input.js:9:1]
8 | 8 |
9 | ,-> export const bar = () => { 9 | ,-> export const bar = () => {
......
x Server Actions must be async functions x Server Actions must be async functions.
|
,-[input.js:7:1] ,-[input.js:7:1]
6 | 6 |
7 | export function bar() {} 7 | export function bar() {}
......
x Only async functions are allowed to be exported in a "use server" file. x Only async functions are allowed to be exported in a "use server" file.
|
,-[input.js:3:1] ,-[input.js:3:1]
2 | 2 |
3 | export const x = 1 3 | export const x = 1
......
x Only async functions are allowed to be exported in a "use server" file. x Only async functions are allowed to be exported in a "use server" file.
|
,-[input.js:3:1] ,-[input.js:3:1]
2 | 2 |
3 | ,-> export default class Component { 3 | ,-> export default class Component {
......
x Only async functions are allowed to be exported in a "use server" file. x Only async functions are allowed to be exported in a "use server" file.
|
,-[input.js:3:1] ,-[input.js:3:1]
2 | 2 |
3 | export * from 'foo' 3 | export * from 'foo'
......
x Server Actions must be async functions. x Server Actions must be async functions.
|
,-[input.js:3:1] ,-[input.js:3:1]
2 | 2 |
3 | export default () => {} 3 | export default () => {}
......
x Server Actions must be async functions. x Server Actions must be async functions.
|
,-[input.js:1:1] ,-[input.js:1:1]
1 | ,-> const foo = () => { 1 | ,-> const foo = () => {
2 | | 'use server' 2 | | 'use server'
......
x The "use server" directive must be at the top of the function body. x The "use server" directive must be at the top of the function body.
|
,-[input.js:10:1] ,-[input.js:10:1]
9 | // prettier-ignore 9 | // prettier-ignore
10 | 'use server' 10 | 'use server'
......
x The "use server" directive must be at the top of the file. x The "use server" directive must be at the top of the file.
|
,-[input.js:4:1] ,-[input.js:4:1]
3 | // prettier-ignore 3 | // prettier-ignore
4 | 'use server' 4 | 'use server'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment