File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
src/zimscraperlib/rewriting Expand file tree Collapse file tree 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]:
186186 # As the rule will match first, it will prevent next rule matching `import` to
187187 # be apply to `async import`.
188188 (re .compile (r"async\s+import\s*\(" ), m2str (lambda x : x )),
189+ (re .compile (r"[^$.]\bimport\s*\([^)]*\)\s*\{" ), m2str (lambda x : x )),
189190 # esm dynamic import, if found, mark as module
190191 (
191192 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:
271271import { Z } from "../../../path.js";
272272
273273B = await import(somefile);
274+
275+ class X {
276+ import(a, b, c) {
277+ await import (somefile);
278+ }
279+ }
274280""" ,
275281 expected = """
276282import * from "../../../example.com/file.js"
@@ -282,6 +288,12 @@ def wrap_import(text: str) -> str:
282288import { Z } from "../../path.js";
283289
284290B = 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+ }
285297""" ,
286298 ),
287299 ImportTestContent (
@@ -341,6 +353,7 @@ def test_import_rewrite(rewrite_import_content: ImportTestContent):
341353 "a.window.x = 5" ,
342354 " postMessage({'a': 'b'})" ,
343355 "simport(5);" ,
356+ "import(e) {" ,
344357 "a.import(5);" ,
345358 "$import(5);" ,
346359 "async import(val) { ... }" ,
You can’t perform that action at this time.
0 commit comments