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

await at module top level workaround #8

Open
sidewayss opened this issue Oct 24, 2024 · 0 comments
Open

await at module top level workaround #8

sidewayss opened this issue Oct 24, 2024 · 0 comments
Labels
2029 Wait until 2029 to do it

Comments

@sidewayss
Copy link
Owner

sidewayss commented Oct 24, 2024

This issue is a reminder for 2029 to either:

  • remove the noAwait code that supports the lack of the await at module top level.
  • or kick the can down the road another few years.

Quite to my surprise, I came up with a way to work around this limitation while maintaining external template files and not totally butchering the code. The main consequence for users is that if they need to access the layout of the element during page load, they need to wait for BaseElement.promises[element].

The workaround doesn't use async or await, so it's widely compatible. Still, it's more code and it's a bit convoluted, so removing it is a good plan. The template files are tiny, so fetching them synchronously is not much of a bottleneck.

Unfortunately, this is a compiler issue, not a run-time issue, and this try/catch block throws an uncatchable exception (using input-num as an example):

let template, noAwait;
try {
    template = await getTemplate("number");
} catch {
    template = "number";
    noAwait  = true;
}

So the await code has to disappear completely in order to work on iOS/Safari 14, for example. Instead the code now looks like this:

const
template = "number",
noAwait  = true;

The 2029 replacement is:

template = await getTemplate("number");

Where noAwait is never declared.

@sidewayss sidewayss added the 2029 Wait until 2029 to do it label Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2029 Wait until 2029 to do it
Projects
None yet
Development

No branches or pull requests

1 participant