-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forbid
this
and arguments
in server functions
- Loading branch information
1 parent
8a22b33
commit ed06a67
Showing
10 changed files
with
440 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
crates/next-custom-transforms/tests/errors/server-actions/server-graph/22/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
async function a() { | ||
'use cache' | ||
// this is not allowed here | ||
this.foo() | ||
// arguments is not allowed here | ||
console.log(arguments) | ||
|
||
const b = async () => { | ||
// this is not allowed here | ||
this.foo() | ||
// arguments is not allowed here | ||
console.log(arguments) | ||
} | ||
|
||
function c() { | ||
// this is allowed here | ||
this.foo() | ||
// arguments is allowed here | ||
console.log(arguments) | ||
|
||
const d = () => { | ||
// this is allowed here | ||
this.foo() | ||
// arguments is allowed here | ||
console.log(arguments) | ||
} | ||
|
||
const e = async () => { | ||
'use server' | ||
// this is not allowed here | ||
this.foo() | ||
// arguments is not allowed here | ||
console.log(arguments) | ||
} | ||
} | ||
} | ||
|
||
export const api = { | ||
result: null, | ||
product: { | ||
async fetch() { | ||
'use cache' | ||
|
||
// this is not allowed here | ||
this.result = await fetch('https://example.com').then((res) => res.json()) | ||
// arguments is not allowed here | ||
console.log(arguments) | ||
}, | ||
}, | ||
} |
55 changes: 55 additions & 0 deletions
55
crates/next-custom-transforms/tests/errors/server-actions/server-graph/22/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ /* __next_internal_action_entry_do_not_use__ {"006a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0","8069348c79fce073bae2f70f139565a2fda1c74c74":"$$RSC_SERVER_CACHE_2","80951c375b4a6a6e89d67b743ec5808127cfde405d":"$$RSC_SERVER_CACHE_1"} */ import { registerServerReference } from "private-next-rsc-server-reference"; | ||
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; | ||
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; | ||
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = async function e() { | ||
// this is not allowed here | ||
this.foo(); | ||
// arguments is not allowed here | ||
console.log(arguments); | ||
}; | ||
export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function a() { | ||
// this is not allowed here | ||
this.foo(); | ||
// arguments is not allowed here | ||
console.log(arguments); | ||
const b = async ()=>{ | ||
// this is not allowed here | ||
this.foo(); | ||
// arguments is not allowed here | ||
console.log(arguments); | ||
}; | ||
function c() { | ||
// this is allowed here | ||
this.foo(); | ||
// arguments is allowed here | ||
console.log(arguments); | ||
const d = ()=>{ | ||
// this is allowed here | ||
this.foo(); | ||
// arguments is allowed here | ||
console.log(arguments); | ||
}; | ||
const e = registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); | ||
} | ||
}); | ||
Object.defineProperty($$RSC_SERVER_CACHE_1, "name", { | ||
"value": "a", | ||
"writable": false | ||
}); | ||
var a = registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null); | ||
export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "8069348c79fce073bae2f70f139565a2fda1c74c74", 0, /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ async function fetch1() { | ||
// this is not allowed here | ||
this.result = await fetch('https://example.com').then((res)=>res.json()); | ||
// arguments is not allowed here | ||
console.log(arguments); | ||
}); | ||
Object.defineProperty($$RSC_SERVER_CACHE_2, "name", { | ||
"value": "fetch", | ||
"writable": false | ||
}); | ||
export const api = { | ||
result: null, | ||
product: { | ||
fetch: registerServerReference($$RSC_SERVER_CACHE_2, "8069348c79fce073bae2f70f139565a2fda1c74c74", null) | ||
} | ||
}; |
63 changes: 63 additions & 0 deletions
63
crates/next-custom-transforms/tests/errors/server-actions/server-graph/22/output.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
x "use cache" functions can not use `this`. | ||
| | ||
,-[input.js:4:1] | ||
3 | // this is not allowed here | ||
4 | this.foo() | ||
: ^^^^ | ||
5 | // arguments is not allowed here | ||
`---- | ||
x "use cache" functions can not use `arguments`. | ||
| | ||
,-[input.js:6:1] | ||
5 | // arguments is not allowed here | ||
6 | console.log(arguments) | ||
: ^^^^^^^^^ | ||
`---- | ||
x "use cache" functions can not use `this`. | ||
| | ||
,-[input.js:10:1] | ||
9 | // this is not allowed here | ||
10 | this.foo() | ||
: ^^^^ | ||
11 | // arguments is not allowed here | ||
`---- | ||
x "use cache" functions can not use `arguments`. | ||
| | ||
,-[input.js:12:1] | ||
11 | // arguments is not allowed here | ||
12 | console.log(arguments) | ||
: ^^^^^^^^^ | ||
13 | } | ||
`---- | ||
x Server Actions can not use `this`. | ||
| | ||
,-[input.js:31:1] | ||
30 | // this is not allowed here | ||
31 | this.foo() | ||
: ^^^^ | ||
32 | // arguments is not allowed here | ||
`---- | ||
x Server Actions can not use `arguments`. | ||
| | ||
,-[input.js:33:1] | ||
32 | // arguments is not allowed here | ||
33 | console.log(arguments) | ||
: ^^^^^^^^^ | ||
34 | } | ||
`---- | ||
x "use cache" functions can not use `this`. | ||
| | ||
,-[input.js:45:1] | ||
44 | // this is not allowed here | ||
45 | this.result = await fetch('https://example.com').then((res) => res.json()) | ||
: ^^^^ | ||
46 | // arguments is not allowed here | ||
`---- | ||
x "use cache" functions can not use `arguments`. | ||
| | ||
,-[input.js:47:1] | ||
46 | // arguments is not allowed here | ||
47 | console.log(arguments) | ||
: ^^^^^^^^^ | ||
48 | }, | ||
`---- |
29 changes: 29 additions & 0 deletions
29
crates/next-custom-transforms/tests/errors/server-actions/server-graph/23/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use cache' | ||
|
||
// not exported! | ||
async function a() { | ||
// this is allowed here | ||
this.foo() | ||
// arguments is allowed here | ||
console.log(arguments) | ||
|
||
const b = async () => { | ||
'use server' | ||
// this is not allowed here | ||
this.foo() | ||
// arguments is not allowed here | ||
console.log(arguments) | ||
} | ||
} | ||
|
||
export const obj = { | ||
foo() { | ||
return 42 | ||
}, | ||
bar() { | ||
// this is allowed here | ||
this.foo() | ||
// arguments is allowed here | ||
console.log(arguments) | ||
}, | ||
} |
28 changes: 28 additions & 0 deletions
28
crates/next-custom-transforms/tests/errors/server-actions/server-graph/23/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* __next_internal_action_entry_do_not_use__ {"006a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; | ||
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; | ||
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; | ||
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = async function b() { | ||
// this is not allowed here | ||
this.foo(); | ||
// arguments is not allowed here | ||
console.log(arguments); | ||
}; | ||
// not exported! | ||
async function a() { | ||
// this is allowed here | ||
this.foo(); | ||
// arguments is allowed here | ||
console.log(arguments); | ||
const b = registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); | ||
} | ||
export const obj = { | ||
foo () { | ||
return 42; | ||
}, | ||
bar () { | ||
// this is allowed here | ||
this.foo(); | ||
// arguments is allowed here | ||
console.log(arguments); | ||
} | ||
}; |
Oops, something went wrong.