Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite: add ignore regex for import rewriting #164

Merged
merged 1 commit into from Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions dist/sw.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/wombat.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/wombatWorkers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@webrecorder/wabac",
"version": "2.17.1",
"version": "2.17.2",
"main": "index.js",
"type": "module",
"license": "AGPL-3.0-or-later",
Expand Down
2 changes: 2 additions & 0 deletions src/rewrite/jsrewriter.js
Expand Up @@ -126,6 +126,8 @@ const createJSRules = () => {
// ignore 'async import', custom function
[/async\s+import\s*\(/, x => x],

[/[^$.]\bimport\s*\([^)]*\)\s*\{/, x => x],

// esm dynamic import, if found, mark as module
[/[^$.]\bimport\s*\(/, replaceImport("import", "____wb_rewrite_import__")]
];
Expand Down
20 changes: 20 additions & 0 deletions test/rewriteJS.js
Expand Up @@ -176,6 +176,22 @@ test(rewriteJS,
"await ____wb_rewrite_import__ (null, somefile);"
);

// dynamic import rewrite (non-module)
test(rewriteJS, `\
class X {
import(a, b, c) {
await import (somefile);
}
}`, `\
class X {
import(a, b, c) {
await ____wb_rewrite_import__ (null, somefile);
}
}`
);




// import/export module rewrite
test(rewriteJSImport, `\
Expand Down Expand Up @@ -294,6 +310,10 @@ test(rewriteJS, "a.import(5);");

test(rewriteJS, "$import(5);");

test(rewriteJS, " import() {");

test(rewriteJS, " import(a, b, c) {");

test(rewriteJS, "async import(val) { ... }");

test(rewriteJSImport, "\
Expand Down