Merge pull request #1079 from lightpanda-io/dynamic_import_caching

Dynamic import caching
This commit is contained in:
Karl Seguin
2025-09-24 09:23:16 +08:00
committed by GitHub
8 changed files with 204 additions and 201 deletions

View File

@@ -0,0 +1,19 @@
<!DOCTYPE html>
<script src="../../testing.js"></script>
<script id=dynamic_import type=module>
const promise1 = new Promise((resolve) => {
Promise.all([
import('./import.js'),
import('./import.js'),
import('./import2.js'),
]).then(resolve);
});
testing.async(promise1, (res) => {
testing.expectEqual('hello', res[0].greeting);
testing.expectEqual('hello', res[1].greeting);
testing.expectEqual('world', res[2].greeting);
})
</script>

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<script src="../../testing.js"></script>
<script id=import type=module>
import * as im from './import.js';
testing.expectEqual('hello', im.greeting);
</script>
<script id=cached type=module>
// hopefully cached, who knows, no real way to assert this
// but at least it works.
import * as im from './import.js';
testing.expectEqual('hello', im.greeting);
</script>

View File

@@ -0,0 +1,2 @@
let greeting = 'hello';
export {greeting as 'greeting'};

View File

@@ -0,0 +1,2 @@
let greeting = 'world';
export {greeting as 'greeting'};

View File

@@ -93,7 +93,7 @@
}
async function async(promise, cb) {
const script_id = document.currentScript.id;
const script_id = document.currentScript ? document.currentScript.id : '<script id is unavailable in browsers>';
const stack = new Error().stack;
this._captured = {script_id: script_id, stack: stack};
const value = await promise;