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

feat: Support top-level await #18772

Merged
merged 5 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions flow-server/src/main/resources/vite.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ export const vaadinConfig: UserConfigFn = (env) => {
outDir: buildOutputFolder,
emptyOutDir: devBundle,
assetsDir: 'VAADIN/build',
target: ["esnext", "safari15"],
rollupOptions: {
input: {
indexhtml: projectIndexHtml,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@JsModule("./importdir.js")
@JsModule("./bad.ts")
@JsModule("./testfile.css.js")
@JsModule("./toplevelawait-main.js")
@CssImport(value = "./cssimport-textfield.css", themeFor = "vaadin-text-field")
@CssImport(value = "./cssimport.css")
public class MainView extends Div {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,10 @@ public void importFromDirectoryWorks() {
public void bootstrapTsCanBeModified() {
Assert.assertEquals(1L, executeScript("return window.bootstrapMod"));
}

@Test
public void toplevelAwaitWorks() {
Assert.assertEquals("This is the value set in other.js",
executeScript("return window.topLevelAwaitValue"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@JsModule("@testscope/map")
@JsModule("package-outside-npm/index.js")
@JsModule("package2-outside-npm/index.js")
@JsModule("./toplevelawait-main.js")
@CssImport("./image.css")
public class MainView extends Div {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,15 @@ public void applicationHasThemeAndAssets() {
Assert.assertEquals(200, size.getWidth());
Assert.assertEquals(200, size.getHeight());
}

@Test
public void toplevelAwaitWorks() {
getDriver().get(getRootURL());
waitForDevServer();
String value = waitUntil(driver -> (String) executeScript(
"return window.topLevelAwaitValue"));

Assert.assertEquals("This is the value set in other.js", value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import './toplevelawait-other.js';

window.topLevelAwaitValue = window.othervalue;
console.log('The value set in other is: ' + window.topLevelAwaitValue);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

let res;
const promise = new Promise((resolve, reject) => {
res = resolve;
});

setTimeout(() => {
window.othervalue = "This is the value set in other.js";
res();
}, 500);


await promise;
Loading