File tree 2 files changed +14
-0
lines changed
src/zimscraperlib/rewriting
2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -186,6 +186,7 @@ def create_js_rules() -> list[TransformationRule]:
186
186
# As the rule will match first, it will prevent next rule matching `import` to
187
187
# be apply to `async import`.
188
188
(re .compile (r"async\s+import\s*\(" ), m2str (lambda x : x )),
189
+ (re .compile (r"[^$.]\bimport\s*\([^)]*\)\s*\{" ), m2str (lambda x : x )),
189
190
# esm dynamic import, if found, mark as module
190
191
(
191
192
re .compile (r"[^$.]\bimport\s*\(" ),
Original file line number Diff line number Diff line change @@ -271,6 +271,12 @@ def wrap_import(text: str) -> str:
271
271
import { Z } from "../../../path.js";
272
272
273
273
B = await import(somefile);
274
+
275
+ class X {
276
+ import(a, b, c) {
277
+ await import (somefile);
278
+ }
279
+ }
274
280
""" ,
275
281
expected = """
276
282
import * from "../../../example.com/file.js"
@@ -282,6 +288,12 @@ def wrap_import(text: str) -> str:
282
288
import { Z } from "../../path.js";
283
289
284
290
B = await ____wb_rewrite_import__(import.meta.url, somefile);
291
+
292
+ class X {
293
+ import(a, b, c) {
294
+ await ____wb_rewrite_import__ (import.meta.url, somefile);
295
+ }
296
+ }
285
297
""" ,
286
298
),
287
299
ImportTestContent (
@@ -341,6 +353,7 @@ def test_import_rewrite(rewrite_import_content: ImportTestContent):
341
353
"a.window.x = 5" ,
342
354
" postMessage({'a': 'b'})" ,
343
355
"simport(5);" ,
356
+ "import(e) {" ,
344
357
"a.import(5);" ,
345
358
"$import(5);" ,
346
359
"async import(val) { ... }" ,
You can’t perform that action at this time.
0 commit comments