@@ -32,7 +32,7 @@ export const fetchSync = () => {
3232 console .log (getText ());
3333};
3434
35- // ✅
35+ // ✅ Define all variables within isolated function's scope
3636export const fetchSync = () => {
3737 const getText = makeSynchronous (async () => {
3838 const url = ' https://example.com' ; // Variable defined within function scope
@@ -42,23 +42,8 @@ export const fetchSync = () => {
4242
4343 console .log (getText ());
4444};
45- ```
46-
47- ``` js
48- import makeSynchronous from ' make-synchronous' ;
4945
50- export const fetchSync = () => {
51- const url = ' https://example.com' ;
52-
53- const getText = makeSynchronous (async () => {
54- const res = await fetch (url); // ❌ 'url' is not defined in isolated function scope
55- return res .text ();
56- });
57-
58- console .log (getText ());
59- };
60-
61- // ✅
46+ // ✅ Alternative: Pass as parameter
6247export const fetchSync = () => {
6348 const getText = makeSynchronous (async (url ) => { // Variable passed as parameter
6449 const res = await fetch (url);
@@ -68,6 +53,7 @@ export const fetchSync = () => {
6853 console .log (getText (' https://example.com' ));
6954};
7055```
56+ ```
7157
7258```js
7359const foo = 'hi';
@@ -85,36 +71,6 @@ function abc() {
8571}
8672```
8773
88- ``` js
89- const foo = ' hi' ;
90-
91- /** @isolated */
92- const abc = () => {
93- return foo .slice (); // ❌ 'foo' is not defined in isolated function scope
94- };
95-
96- // ✅
97- /** @isolated */
98- const abc = () => {
99- const foo = ' hi' ; // Variable defined within function scope
100- return foo .slice ();
101- };
102- ```
103-
104- ``` js
105- import makeSynchronous from ' make-synchronous' ;
106-
107- export const fetchSync = () => {
108- const getText = makeSynchronous (async () => {
109- console .log (' Starting...' ); // ✅ Global variables are allowed by default
110- const res = await fetch (' https://example.com' ); // ✅ Global variables are allowed by default
111- return res .text ();
112- });
113-
114- console .log (getText ());
115- };
116- ```
117-
11874## Options
11975
12076Type: ` object `
@@ -258,10 +214,21 @@ createLambda({
258214```
259215
260216``` js
217+ // ✅ All globals used are explicitly allowed
261218makeSynchronous (async () => {
262219 console .log (' Starting...' ); // ✅ Allowed global
263220 const response = await fetch (' https://api.example.com' ); // ✅ Allowed global
264221 const url = new URL (response .url ); // ✅ Allowed global
265222 return response .text ();
266223});
224+
225+ makeSynchronous (async () => {
226+ const response = await fetch (' https://api.example.com' , {
227+ headers: {
228+ ' Authorization' : ` Bearer ${ process .env .API_TOKEN } ` // ❌ 'process' is not in allowed globals
229+ }
230+ });
231+ const url = new URL (response .url );
232+ return response .text ();
233+ });
267234```
0 commit comments