Commit d648fff
Bartek Wrona
Add Closure compiler support for ESM dynamic imports
Closure compiler runs before the MODULARIZE async wrapper is applied,
so it sees `await import('node:xyz')` outside an async function and
fails to parse it.
Work around this by:
1. Before Closure: Replace `await import('node:xyz')` with placeholder
variables like `__EMSCRIPTEN_PRIVATE_AWAIT_IMPORT_xyz__`
2. Generate externs for the placeholders so Closure doesn't error on
undeclared variables
3. After Closure: Restore placeholders to `(await import('node:xyz'))`
with parentheses to handle cases where Closure inlines the variable
into expressions like `placeholder.method()`
This follows the same pattern as the existing
`__EMSCRIPTEN_PRIVATE_MODULE_EXPORT_NAME_SUBSTITUTION__` mechanism.1 parent 1efd494 commit d648fff
1 file changed
+37
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2322 | 2322 | | |
2323 | 2323 | | |
2324 | 2324 | | |
2325 | | - | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
| 2346 | + | |
| 2347 | + | |
| 2348 | + | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
| 2360 | + | |
| 2361 | + | |
2326 | 2362 | | |
2327 | 2363 | | |
2328 | 2364 | | |
| |||
0 commit comments