From 41ac4468de8a1e6d25571d5d22e81a1a68f29e08 Mon Sep 17 00:00:00 2001 From: Joel M Date: Mon, 28 Dec 2020 18:47:55 +0900 Subject: [PATCH] fix(v2): allow async/await in live code editor (#3954) * transforming async functions is not implemented by buble, so just bypassing it would relieve the pain for now --- .../src/custom-buble.js | 20 +++++++++++++++++++ .../src/index.js | 5 +---- 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 packages/docusaurus-theme-live-codeblock/src/custom-buble.js diff --git a/packages/docusaurus-theme-live-codeblock/src/custom-buble.js b/packages/docusaurus-theme-live-codeblock/src/custom-buble.js new file mode 100644 index 000000000000..879349fa0c4c --- /dev/null +++ b/packages/docusaurus-theme-live-codeblock/src/custom-buble.js @@ -0,0 +1,20 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// fork of Buble which removes Buble's large dependency and weighs in +// at a smaller size of ~51kB +// https://github.com/FormidableLabs/react-live#what-bundle-size-can-i-expect +const {transform, features: bubleFeatures} = require('@philpl/buble'); + +// This file is designed to mimic what's written in +// https://github.com/kitten/buble/blob/mini/src/index.js, with custom transforms options, +// so that webpack can consume it correctly. +exports.features = bubleFeatures; + +exports.transform = function customTransform(source, options) { + return transform(source, {...options, transforms: {asyncAwait: false}}); +}; diff --git a/packages/docusaurus-theme-live-codeblock/src/index.js b/packages/docusaurus-theme-live-codeblock/src/index.js index fb41c912414e..d222af3d252a 100644 --- a/packages/docusaurus-theme-live-codeblock/src/index.js +++ b/packages/docusaurus-theme-live-codeblock/src/index.js @@ -19,10 +19,7 @@ module.exports = function () { return { resolve: { alias: { - // fork of Buble which removes Buble's large dependency and weighs in - // at a smaller size of ~51kB - // https://github.com/FormidableLabs/react-live#what-bundle-size-can-i-expect - buble: '@philpl/buble', + buble: path.resolve(__dirname, './custom-buble.js'), }, }, };