1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:17:35 +00:00

LibJS: Allow anonymous functions as default exports

This requires a special case with names as the default function is
supposed to have a unique name ("*default*" in our case) but when
checked should have name "default".
This commit is contained in:
davidot 2022-09-02 00:46:37 +02:00 committed by Linus Groh
parent 0fc67ffd62
commit 9f661d20f7
5 changed files with 79 additions and 19 deletions

View file

@ -0,0 +1,26 @@
try {
f();
} catch (e) {
if (!(e instanceof ReferenceError)) throw e;
if (!e.message.includes("bindingUsedInFunction")) throw e;
}
let bindingUsedInFunction = 0;
const immediateResult = f();
const immediateName = f.name + "";
import f from "./anon-func-decl-default-export.mjs";
export default function () {
return bindingUsedInFunction++;
}
const postImportResult = f();
const postImportName = f.name + "";
export const passed =
immediateResult === 0 &&
postImportResult === 1 &&
bindingUsedInFunction === 2 &&
immediateName === "default" &&
postImportName === "default";