Commit 4c50826
vm: support using the default loader to handle dynamic import()
This patch adds support for using
`vm.constants.USE_MAIN_CONTEXT_DEFAULT_LOADER` as
`importModuleDynamically` in all APIs that take the option
except `vm.SourceTextModule`. This allows users to have a shortcut
to support dynamic import() in the compiled code without missing
the compilation cache if they don't need customization of the
loading process. We emit an experimental warning when the
`import()` is actually handled by the default loader through
this option instead of requiring `--experimental-vm-modules`.
In addition this refactors the documentation for
`importModuleDynamically` and adds a dedicated section for it
with examples.
`vm.SourceTextModule` is not supported in this patch because
it needs additional refactoring to handle `initializeImportMeta`,
which can be done in a follow-up.
PR-URL: #51244
Fixes: #51154
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>1 parent af6b5b1 commit 4c50826Copy full SHA for 4c50826
File tree
Expand file treeCollapse file tree
15 files changed
+596
-193
lines changedOpen diff view settings
Filter options
- doc/api
- lib
- internal
- bootstrap/switches
- modules
- cjs
- esm
- process
- source_map
- src
- test
- es-module
- parallel
- tools/doc
Expand file treeCollapse file tree
15 files changed
+596
-193
lines changedOpen diff view settings
Collapse file
+310-106Lines changed: 310 additions & 106 deletions
- Display the source diff
- Display the rich diff
Large diffs are not rendered by default.
Collapse file
lib/internal/bootstrap/switches/is_main_thread.js
Copy file name to clipboardExpand all lines: lib/internal/bootstrap/switches/is_main_thread.js-1Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
294 | 294 | |
295 | 295 | |
296 | 296 | |
297 | | - |
298 | 297 | |
299 | 298 | |
300 | 299 | |
|
Collapse file
lib/internal/modules/cjs/loader.js
Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js+5-13Lines changed: 5 additions & 13 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | | - |
56 | 55 | |
57 | 56 | |
58 | 57 | |
| ||
114 | 113 | |
115 | 114 | |
116 | 115 | |
117 | | - |
118 | 116 | |
119 | 117 | |
120 | 118 | |
| ||
125 | 123 | |
126 | 124 | |
127 | 125 | |
128 | | - |
129 | | - |
130 | | - |
131 | | - |
132 | 126 | |
133 | | - |
| 127 | + |
| 128 | + |
| 129 | + |
134 | 130 | |
135 | 131 | |
136 | 132 | |
| ||
1257 | 1253 | |
1258 | 1254 | |
1259 | 1255 | |
1260 | | - |
1261 | | - |
1262 | | - |
1263 | | - |
1264 | | - |
1265 | | - |
| 1256 | + |
| 1257 | + |
1266 | 1258 | |
1267 | 1259 | |
1268 | 1260 | |
|
Collapse file
lib/internal/modules/esm/translators.js
Copy file name to clipboardExpand all lines: lib/internal/modules/esm/translators.js+7-7Lines changed: 7 additions & 7 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
15 | 15 | |
16 | 16 | |
17 | 17 | |
18 | | - |
19 | 18 | |
20 | 19 | |
21 | 20 | |
| ||
59 | 58 | |
60 | 59 | |
61 | 60 | |
62 | | - |
| 61 | + |
| 62 | + |
| 63 | + |
63 | 64 | |
64 | 65 | |
65 | 66 | |
| ||
206 | 207 | |
207 | 208 | |
208 | 209 | |
209 | | - |
210 | | - |
211 | | - |
| 210 | + |
| 211 | + |
212 | 212 | |
213 | 213 | |
214 | 214 | |
| ||
226 | 226 | |
227 | 227 | |
228 | 228 | |
229 | | - |
230 | | - |
| 229 | + |
| 230 | + |
231 | 231 | |
232 | 232 | |
233 | 233 | |
|
Collapse file
lib/internal/modules/esm/utils.js
Copy file name to clipboardExpand all lines: lib/internal/modules/esm/utils.js+44-27Lines changed: 44 additions & 27 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
4 | 4 | |
5 | 5 | |
6 | 6 | |
7 | | - |
8 | 7 | |
9 | 8 | |
10 | 9 | |
| ||
14 | 13 | |
15 | 14 | |
16 | 15 | |
17 | | - |
| 16 | + |
| 17 | + |
18 | 18 | |
| 19 | + |
19 | 20 | |
20 | 21 | |
21 | 22 | |
| ||
28 | 29 | |
29 | 30 | |
30 | 31 | |
31 | | - |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
32 | 37 | |
33 | 38 | |
34 | 39 | |
35 | 40 | |
36 | 41 | |
| 42 | + |
| 43 | + |
| 44 | + |
37 | 45 | |
38 | 46 | |
39 | 47 | |
| ||
145 | 153 | |
146 | 154 | |
147 | 155 | |
148 | | - |
149 | | - |
| 156 | + |
| 157 | + |
| 158 | + |
| 159 | + |
150 | 160 | |
151 | 161 | |
152 | 162 | |
| ||
158 | 168 | |
159 | 169 | |
160 | 170 | |
161 | | - |
162 | | - |
163 | | - |
164 | | - |
165 | | - |
166 | | - |
167 | | - |
168 | | - |
169 | | - |
170 | | - |
171 | | - |
172 | | - |
173 | | - |
174 | | - |
175 | | - |
176 | | - |
177 | | - |
178 | | - |
179 | | - |
180 | | - |
181 | 171 | |
182 | 172 | |
183 | 173 | |
| ||
191 | 181 | |
192 | 182 | |
193 | 183 | |
| 184 | + |
| 185 | + |
| 186 | + |
| 187 | + |
| 188 | + |
| 189 | + |
| 190 | + |
| 191 | + |
| 192 | + |
| 193 | + |
| 194 | + |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | + |
194 | 199 | |
195 | 200 | |
196 | 201 | |
197 | 202 | |
198 | 203 | |
199 | 204 | |
| 205 | + |
200 | 206 | |
201 | 207 | |
202 | 208 | |
203 | | - |
| 209 | + |
| 210 | + |
| 211 | + |
| 212 | + |
| 213 | + |
| 214 | + |
| 215 | + |
| 216 | + |
| 217 | + |
| 218 | + |
| 219 | + |
| 220 | + |
| 221 | + |
204 | 222 | |
205 | 223 | |
206 | 224 | |
| ||
273 | 291 | |
274 | 292 | |
275 | 293 | |
276 | | - |
277 | 294 | |
278 | 295 | |
279 | 296 | |
|
Collapse file
lib/internal/modules/helpers.js
Copy file name to clipboardExpand all lines: lib/internal/modules/helpers.js+28-7Lines changed: 28 additions & 7 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
23 | 23 | |
24 | 24 | |
25 | 25 | |
26 | | - |
| 26 | + |
| 27 | + |
27 | 28 | |
28 | 29 | |
29 | 30 | |
| 31 | + |
30 | 32 | |
31 | 33 | |
32 | 34 | |
33 | 35 | |
34 | 36 | |
35 | 37 | |
| 38 | + |
36 | 39 | |
37 | 40 | |
38 | 41 | |
| ||
288 | 291 | |
289 | 292 | |
290 | 293 | |
291 | | - |
292 | | - |
| 294 | + |
| 295 | + |
| 296 | + |
| 297 | + |
| 298 | + |
| 299 | + |
293 | 300 | |
294 | | - |
295 | | - |
296 | | - |
| 301 | + |
| 302 | + |
| 303 | + |
297 | 304 | |
298 | | - |
| 305 | + |
| 306 | + |
| 307 | + |
| 308 | + |
| 309 | + |
| 310 | + |
| 311 | + |
| 312 | + |
| 313 | + |
| 314 | + |
| 315 | + |
| 316 | + |
| 317 | + |
| 318 | + |
| 319 | + |
299 | 320 | |
300 | 321 | |
301 | 322 | |
|
Collapse file
lib/internal/process/pre_execution.js
Copy file name to clipboardExpand all lines: lib/internal/process/pre_execution.js+17-9Lines changed: 17 additions & 9 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
67 | 67 | |
68 | 68 | |
69 | 69 | |
70 | | - |
71 | 70 | |
72 | 71 | |
73 | 72 | |
74 | 73 | |
75 | 74 | |
76 | 75 | |
77 | 76 | |
78 | | - |
79 | | - |
80 | | - |
81 | | - |
82 | | - |
83 | | - |
84 | | - |
| 77 | + |
| 78 | + |
| 79 | + |
85 | 80 | |
86 | | - |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
87 | 95 | |
88 | 96 | |
89 | 97 | |
|
Collapse file
lib/internal/source_map/source_map_cache.js
Copy file name to clipboardExpand all lines: lib/internal/source_map/source_map_cache.js+3-5Lines changed: 3 additions & 5 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
107 | 107 | |
108 | 108 | |
109 | 109 | |
110 | | - |
111 | | - |
112 | | - |
113 | | - |
| 110 | + |
| 111 | + |
| 112 | + |
114 | 113 | |
115 | | - |
116 | 114 | |
117 | 115 | |
118 | 116 | |
|
0 commit comments