-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of local functions in
"use cache"
modules
- Loading branch information
1 parent
8c401f6
commit 9f374de
Showing
5 changed files
with
117 additions
and
17 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
21 changes: 19 additions & 2 deletions
21
crates/next-custom-transforms/tests/fixture/server-actions/server/34/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 |
---|---|---|
@@ -1,5 +1,22 @@ | ||
'use cache' | ||
|
||
export async function foo() {} | ||
const bar = async () => {} | ||
const foo = async () => { | ||
return 'foo' | ||
} | ||
|
||
export { bar } | ||
|
||
async function bar() { | ||
return 'bar' | ||
} | ||
|
||
// Should not be wrapped in $$cache__. | ||
const qux = async function qux() { | ||
return 'qux' | ||
} | ||
|
||
const baz = async function () { | ||
return qux() + 'baz' | ||
} | ||
|
||
export { foo, baz } |
23 changes: 18 additions & 5 deletions
23
crates/next-custom-transforms/tests/fixture/server-actions/server/34/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 |
---|---|---|
@@ -1,8 +1,21 @@ | ||
/* __next_internal_action_entry_do_not_use__ {"3128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0","951c375b4a6a6e89d67b743ec5808127cfde405d":"$$RSC_SERVER_CACHE_1"} */ import { registerServerReference } from "private-next-rsc-server-reference"; | ||
/* __next_internal_action_entry_do_not_use__ {"12a8d21b6362b4cc8f5b15560525095bc48dba80":"$$RSC_SERVER_CACHE_3","3128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0","951c375b4a6a6e89d67b743ec5808127cfde405d":"$$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 var $$RSC_SERVER_CACHE_0 = $$cache__("default", "3128060c414d59f8552e4788b846c0d2b7f74743", async function foo() {}); | ||
export var foo = registerServerReference($$RSC_SERVER_CACHE_0, "3128060c414d59f8552e4788b846c0d2b7f74743", null); | ||
export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "951c375b4a6a6e89d67b743ec5808127cfde405d", async function() {}); | ||
const bar = registerServerReference($$RSC_SERVER_CACHE_1, "951c375b4a6a6e89d67b743ec5808127cfde405d", null); | ||
export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "3128060c414d59f8552e4788b846c0d2b7f74743", async function() { | ||
return 'foo'; | ||
}); | ||
const foo = registerServerReference($$RSC_SERVER_CACHE_0, "3128060c414d59f8552e4788b846c0d2b7f74743", null); | ||
export { bar }; | ||
export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "951c375b4a6a6e89d67b743ec5808127cfde405d", async function bar() { | ||
return 'bar'; | ||
}); | ||
var bar = registerServerReference($$RSC_SERVER_CACHE_1, "951c375b4a6a6e89d67b743ec5808127cfde405d", null); | ||
// Should not be wrapped in $$cache__. | ||
const qux = async function qux() { | ||
return 'qux'; | ||
}; | ||
export var $$RSC_SERVER_CACHE_3 = $$cache__("default", "12a8d21b6362b4cc8f5b15560525095bc48dba80", async function $$RSC_SERVER_CACHE_2() { | ||
return qux() + 'baz'; | ||
}); | ||
const baz = registerServerReference($$RSC_SERVER_CACHE_3, "12a8d21b6362b4cc8f5b15560525095bc48dba80", null); | ||
export { foo, baz }; |
12 changes: 12 additions & 0 deletions
12
crates/next-custom-transforms/tests/fixture/server-actions/server/45/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,12 @@ | ||
'use cache' | ||
|
||
// Expect no error here, this is allowed to be sync because it's not exported. | ||
function Foo() { | ||
const v = Math.random() | ||
console.log(v) | ||
return v | ||
} | ||
|
||
export async function bar() { | ||
return <Foo /> | ||
} |
13 changes: 13 additions & 0 deletions
13
crates/next-custom-transforms/tests/fixture/server-actions/server/45/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,13 @@ | ||
/* __next_internal_action_entry_do_not_use__ {"3128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_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"; | ||
// Expect no error here, this is allowed to be sync because it's not exported. | ||
function Foo() { | ||
const v = Math.random(); | ||
console.log(v); | ||
return v; | ||
} | ||
export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "3128060c414d59f8552e4788b846c0d2b7f74743", async function bar() { | ||
return <Foo/>; | ||
}); | ||
export var bar = registerServerReference($$RSC_SERVER_CACHE_0, "3128060c414d59f8552e4788b846c0d2b7f74743", null); |