@@ -32,7 +32,7 @@ export const fetchSync = () => {
32
32
console .log (getText ());
33
33
};
34
34
35
- // ✅
35
+ // ✅ Define all variables within isolated function's scope
36
36
export const fetchSync = () => {
37
37
const getText = makeSynchronous (async () => {
38
38
const url = ' https://example.com' ; // Variable defined within function scope
@@ -42,23 +42,8 @@ export const fetchSync = () => {
42
42
43
43
console .log (getText ());
44
44
};
45
- ```
46
-
47
- ``` js
48
- import makeSynchronous from ' make-synchronous' ;
49
-
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
45
61
- // ✅
46
+ // ✅ Alternative: Pass as parameter
62
47
export const fetchSync = () => {
63
48
const getText = makeSynchronous (async (url ) => { // Variable passed as parameter
64
49
const res = await fetch (url);
@@ -68,6 +53,7 @@ export const fetchSync = () => {
68
53
console .log (getText (' https://example.com' ));
69
54
};
70
55
```
56
+ ```
71
57
72
58
```js
73
59
const foo = 'hi';
@@ -85,36 +71,6 @@ function abc() {
85
71
}
86
72
```
87
73
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
-
118
74
## Options
119
75
120
76
Type: ` object `
@@ -258,10 +214,21 @@ createLambda({
258
214
```
259
215
260
216
``` js
217
+ // ✅ All globals used are explicitly allowed
261
218
makeSynchronous (async () => {
262
219
console .log (' Starting...' ); // ✅ Allowed global
263
220
const response = await fetch (' https://api.example.com' ); // ✅ Allowed global
264
221
const url = new URL (response .url ); // ✅ Allowed global
265
222
return response .text ();
266
223
});
224
+
225
+ makeSynchronous (async () => {
226
+ const response = await fetch (' https://api.example.com' , { // ✅ Allowed global
227
+ headers: {
228
+ ' Authorization' : ` Bearer ${ process .env .API_TOKEN } ` // ❌ 'process' is not in allowed globals
229
+ }
230
+ });
231
+ const url = new URL (response .url ); // ✅ Allowed global
232
+ return response .text ();
233
+ });
267
234
```
0 commit comments