Skip to content

Commit

Permalink
feat: Support top-level await (#18772)
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- committed Feb 21, 2024
1 parent ebce9a4 commit 1da4e65
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 0 deletions.
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;

0 comments on commit 1da4e65

Please sign in to comment.