Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 861 Bytes

plugin-syntax-top-level-await.md

File metadata and controls

49 lines (36 loc) · 861 Bytes
Error in user YAML: (<unknown>): found character that cannot start any token while scanning for the next token at line 2 column 8
---
id: babel-plugin-syntax-top-level-await
title: @babel/plugin-syntax-top-level-await
sidebar_label: syntax-top-level-await
---

Syntax only

This plugin only enables parsing of this feature. Babel doesn't support transforming top-level await, but you can use Rollup's experimentalTopLevelAwait or webpack@5's experiments.topLevelAwait options.

const val = await promise;

export { val };

Installation

npm install --save-dev @babel/plugin-syntax-top-level-await

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["@babel/plugin-syntax-top-level-await"]
}

Via CLI

babel --plugins @babel/plugin-syntax-top-level-await script.js

Via Node API

require("@babel/core").transform("code", {
  plugins: ["@babel/plugin-syntax-top-level-await"],
});