developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8.04k stars 362 forks source link

Babel transform syntax error: Unable to handle nested super.prop usage #835

Open DyncMark opened 3 years ago

DyncMark commented 3 years ago

[os]:

[error log]:


$ microbundle
(babel plugin) SyntaxError: /Users/chudong/workBench/xxxxx/src/tracks/microphone_audio_track.ts: Unable to handle nested super.prop usage
  42 |         return new Promise(async (resolve, reject) => {
  43 |             if (unClose) {
> 44 |                 super.setEnabled(enabled);
     |                 ^^^^^^^^^^^^^^^^
  45 |                 resolve();
  46 |                 return;
  47 |             }
SyntaxError: /Users/chudong/workBench/xxxxx/src/tracks/microphone_audio_track.ts: Unable to handle nested super.prop usage
  42 |         return new Promise(async (resolve, reject) => {
  43 |             if (unClose) {
> 44 |                 super.setEnabled(enabled);
     |                 ^^^^^^^^^^^^^^^^
  45 |                 resolve();
  46 |                 return;
  47 |             }
    at File.buildCodeFrameError (/Users/chudong/workBench/xxxxx/node_modules/@babel/core/lib/transformation/file/file.js:240:12)
    at NodePath.buildCodeFrameError (/Users/chudong/workBench/xxxxx/node_modules/@babel/traverse/lib/path/index.js:138:21)
    at hoistFunctionEnvironment (/Users/chudong/workBench/xxxxx/node_modules/@babel/traverse/lib/path/conversion.js:194:27)
    at NodePath.arrowFunctionToExpression (/Users/chudong/workBench/xxxxx/node_modules/@babel/traverse/lib/path/conversion.js:105:23)
    at PluginPass.ArrowFunctionExpression (/Users/chudong/workBench/xxxxx/node_modules/@babel/preset-modules/lib/plugins/transform-async-arrows-in-class/index.js:37:14)
    at newFn (/Users/chudong/workBench/xxxxx/node_modules/@babel/traverse/lib/visitors.js:175:21)
    at NodePath._call (/Users/chudong/workBench/xxxxx/node_modules/@babel/traverse/lib/path/context.js:55:20)
    at NodePath.call (/Users/chudong/workBench/xxxxx/node_modules/@babel/traverse/lib/path/context.js:42:17)
    at NodePath.visit (/Users/chudong/workBench/xxxxx/node_modules/@babel/traverse/lib/path/context.js:92:31)
    at TraversalContext.visitQueue (/Users/chudong/workBench/xxxxx/node_modules/@babel/traverse/lib/context.js:116:16)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
developit commented 3 years ago

Interesting! This is actually a bug in @babel/preset-modules.

Here's the bug reproduced in the Babel repl.

I've opened babel/preset-modules#31 to track getting a fix in.

In the meantime, the quick fix is to not use an async function as a promise initializer (which is generally not recommended anyway, since doing so actually swallows errors!).