LibJS: Implement the import assertions proposal

The hard part of parsing them in import statements and calls was already
done so this is just removing some check which threw before on
assertions. And filtering the assertions based on the result of a new
host hook.
This commit is contained in:
davidot 2022-01-27 02:44:03 +01:00 committed by Linus Groh
commit f568939568
Notes: sideshowbarker 2024-07-17 21:26:19 +09:00
11 changed files with 270 additions and 83 deletions

View file

@ -9,14 +9,14 @@ function validTestModule(filename) {
}
}
function expectModulePassed(filename) {
function expectModulePassed(filename, options = undefined) {
validTestModule(filename);
let moduleLoaded = false;
let moduleResult = null;
let thrownError = null;
import(filename)
import(filename, options)
.then(result => {
moduleLoaded = true;
moduleResult = result;
@ -130,6 +130,11 @@ describe("testing behavior", () => {
test("expectModulePassed works", () => {
expectModulePassed("./single-const-export.mjs");
});
test("can call expectModulePassed with options", () => {
expectModulePassed("./single-const-export.mjs", { key: "value" });
expectModulePassed("./single-const-export.mjs", { key1: "value1", key2: "value2" });
});
});
describe("in- and exports", () => {
@ -173,6 +178,10 @@ describe("in- and exports", () => {
"Invalid or ambiguous export entry 'default'"
);
});
test("can import with (useless) assertions", () => {
expectModulePassed("./import-with-assertions.mjs");
});
});
describe("loops", () => {

View file

@ -0,0 +1,4 @@
import * as self from "./import-with-assertions.mjs" assert { "key": "value", key2: "value2", default: "shouldwork" };
import "./import-with-assertions.mjs" assert { "key": "value", key2: "value2", default: "shouldwork" };
export { passed } from "./module-with-default.mjs" assert { "key": "value", key2: "value2", default: "shouldwork" };