Commit b07ad39
module: detect ESM syntax by trying to recompile as SourceTextModule
Instead of using an async function wrapper, just try compiling code with
unknown module format as SourceTextModule when it cannot be compiled
as CJS and the error message indicates that it's worth a retry. If
it can be parsed as SourceTextModule then it's considered ESM.
Also, move shouldRetryAsESM() to C++ completely so that
we can reuse it in the CJS module loader for require(esm).
Drive-by: move methods that don't belong to ContextifyContext
out as static methods and move GetHostDefinedOptions to
ModuleWrap.
PR-URL: #52413
Backport-PR-URL: #56927
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Refs: #526971 parent 132a5c1 commit b07ad39Copy full SHA for b07ad39
File tree
Expand file treeCollapse file tree
7 files changed
+303
-339
lines changedOpen diff view settings
Filter options
- lib/internal/modules
- esm
- src
Expand file treeCollapse file tree
7 files changed
+303
-339
lines changedOpen diff view settings
Collapse file
lib/internal/modules/esm/get_format.js
Copy file name to clipboardExpand all lines: lib/internal/modules/esm/get_format.js+2-2Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
114 | 114 | |
115 | 115 | |
116 | 116 | |
117 | | - |
| 117 | + |
118 | 118 | |
119 | 119 | |
120 | 120 | |
| ||
158 | 158 | |
159 | 159 | |
160 | 160 | |
161 | | - |
| 161 | + |
162 | 162 | |
163 | 163 | |
164 | 164 | |
|
Collapse file
lib/internal/modules/helpers.js
Copy file name to clipboardExpand all lines: lib/internal/modules/helpers.js-34Lines changed: 0 additions & 34 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
19 | 19 | |
20 | 20 | |
21 | 21 | |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | 22 | |
32 | 23 | |
33 | 24 | |
| ||
338 | 329 | |
339 | 330 | |
340 | 331 | |
341 | | - |
342 | | - |
343 | | - |
344 | | - |
345 | | - |
346 | | - |
347 | | - |
348 | | - |
349 | | - |
350 | | - |
351 | | - |
352 | | - |
353 | | - |
354 | | - |
355 | | - |
356 | | - |
357 | | - |
358 | | - |
359 | | - |
360 | | - |
361 | | - |
362 | | - |
363 | | - |
364 | | - |
365 | 332 | |
366 | 333 | |
367 | 334 | |
| ||
396 | 363 | |
397 | 364 | |
398 | 365 | |
399 | | - |
400 | 366 | |
401 | 367 | |
402 | 368 | |
|
Collapse file
lib/internal/modules/run_main.js
Copy file name to clipboardExpand all lines: lib/internal/modules/run_main.js+16-10Lines changed: 16 additions & 10 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
1 | 1 | |
2 | 2 | |
3 | 3 | |
| 4 | + |
4 | 5 | |
| 6 | + |
5 | 7 | |
6 | 8 | |
7 | 9 | |
| ||
155 | 157 | |
156 | 158 | |
157 | 159 | |
158 | | - |
| 160 | + |
159 | 161 | |
160 | 162 | |
161 | 163 | |
162 | 164 | |
163 | 165 | |
164 | 166 | |
165 | 167 | |
| 168 | + |
166 | 169 | |
167 | 170 | |
168 | 171 | |
169 | 172 | |
170 | | - |
171 | | - |
172 | | - |
173 | | - |
174 | | - |
175 | | - |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | + |
176 | 182 | |
177 | | - |
178 | | - |
179 | 183 | |
180 | 184 | |
181 | 185 | |
| ||
186 | 190 | |
187 | 191 | |
188 | 192 | |
189 | | - |
| 193 | + |
| 194 | + |
| 195 | + |
190 | 196 | |
191 | 197 | |
192 | 198 | |
|
Collapse file
+92-30Lines changed: 92 additions & 30 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
102 | 102 | |
103 | 103 | |
104 | 104 | |
105 | | - |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
106 | 114 | |
107 | | - |
| 115 | + |
108 | 116 | |
109 | 117 | |
110 | 118 | |
| ||
134 | 142 | |
135 | 143 | |
136 | 144 | |
137 | | - |
| 145 | + |
138 | 146 | |
139 | 147 | |
140 | 148 | |
| ||
143 | 151 | |
144 | 152 | |
145 | 153 | |
146 | | - |
| 154 | + |
| 155 | + |
147 | 156 | |
148 | | - |
| 157 | + |
149 | 158 | |
150 | 159 | |
151 | 160 | |
152 | 161 | |
153 | 162 | |
154 | 163 | |
155 | 164 | |
| 165 | + |
| 166 | + |
| 167 | + |
156 | 168 | |
157 | 169 | |
158 | 170 | |
159 | | - |
| 171 | + |
160 | 172 | |
161 | 173 | |
162 | 174 | |
| ||
189 | 201 | |
190 | 202 | |
191 | 203 | |
192 | | - |
| 204 | + |
| 205 | + |
| 206 | + |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | + |
| 211 | + |
193 | 212 | |
| 213 | + |
194 | 214 | |
195 | 215 | |
196 | 216 | |
197 | | - |
| 217 | + |
198 | 218 | |
199 | 219 | |
200 | 220 | |
201 | | - |
202 | 221 | |
203 | | - |
204 | | - |
205 | | - |
206 | | - |
207 | | - |
208 | | - |
209 | | - |
210 | | - |
211 | | - |
212 | | - |
213 | | - |
214 | | - |
215 | | - |
216 | | - |
217 | | - |
218 | | - |
219 | | - |
220 | | - |
221 | | - |
| 222 | + |
| 223 | + |
| 224 | + |
| 225 | + |
| 226 | + |
| 227 | + |
| 228 | + |
| 229 | + |
| 230 | + |
| 231 | + |
222 | 232 | |
223 | 233 | |
224 | 234 | |
| ||
231 | 241 | |
232 | 242 | |
233 | 243 | |
234 | | - |
235 | | - |
| 244 | + |
| 245 | + |
| 246 | + |
236 | 247 | |
237 | 248 | |
238 | 249 | |
| ||
275 | 286 | |
276 | 287 | |
277 | 288 | |
| 289 | + |
| 290 | + |
| 291 | + |
| 292 | + |
| 293 | + |
| 294 | + |
| 295 | + |
| 296 | + |
| 297 | + |
| 298 | + |
| 299 | + |
| 300 | + |
| 301 | + |
| 302 | + |
| 303 | + |
| 304 | + |
| 305 | + |
| 306 | + |
| 307 | + |
| 308 | + |
| 309 | + |
| 310 | + |
| 311 | + |
| 312 | + |
| 313 | + |
| 314 | + |
| 315 | + |
| 316 | + |
| 317 | + |
| 318 | + |
| 319 | + |
| 320 | + |
| 321 | + |
| 322 | + |
| 323 | + |
| 324 | + |
| 325 | + |
| 326 | + |
| 327 | + |
| 328 | + |
| 329 | + |
| 330 | + |
| 331 | + |
| 332 | + |
| 333 | + |
| 334 | + |
| 335 | + |
| 336 | + |
| 337 | + |
| 338 | + |
| 339 | + |
278 | 340 | |
279 | 341 | |
280 | 342 | |
|
Collapse file
+20-1Lines changed: 20 additions & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
3 | 3 | |
4 | 4 | |
5 | 5 | |
6 | | - |
| 6 | + |
7 | 7 | |
| 8 | + |
8 | 9 | |
9 | 10 | |
| 11 | + |
10 | 12 | |
11 | 13 | |
12 | 14 | |
| ||
68 | 70 | |
69 | 71 | |
70 | 72 | |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
71 | 90 | |
72 | 91 | |
73 | 92 | |
|
0 commit comments