Skip to content

[experiment] Hack build to produce top level let bindings #52928

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import cmdLineOptions from "./scripts/build/options.mjs";
import { buildProject, cleanProject, watchProject } from "./scripts/build/projects.mjs";
import { localBaseline, localRwcBaseline, refBaseline, refRwcBaseline, runConsoleTests } from "./scripts/build/tests.mjs";
import { Debouncer, Deferred, exec, getDiffTool, getDirSize, memoize, needsUpdate, readJson } from "./scripts/build/utils.mjs";
import assert from "assert";

const glob = util.promisify(_glob);

Expand Down Expand Up @@ -215,6 +216,22 @@ function createBundler(entrypoint, outfile, taskOptions = {}) {
];
}

options.plugins = (options.plugins ?? []).concat({
name: "var-to-let",
setup: (build) => {
build.onEnd(async () => {
let contents = await fs.promises.readFile(outfile, "utf-8");
// Replace top-level vars with let
const old = contents;
contents = contents.replace(/^var /gm, "let ");
// Fix enum emit which assumes var
contents = contents.replace(/^\}\)\(\w+ \|\| \{\}\);/gm, "})({});");
assert(old !== contents);
await fs.promises.writeFile(outfile, contents);
});
},
});

return options;
});

Expand Down