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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Babel crash when spreading an await inside function parameters #14364

Closed
1 task
Colisan opened this issue Mar 16, 2022 · 2 comments
Closed
1 task

[Bug]: Babel crash when spreading an await inside function parameters #14364

Colisan opened this issue Mar 16, 2022 · 2 comments
Labels
i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@Colisan
Copy link

Colisan commented Mar 16, 2022

馃捇

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

I'm using the Babel CLI on the .js file generated by https://github.com/vuejs/devtools/blob/main/packages/shell-electron/src/backend.js once Webpack have been run. The resulting source file contains this :

  async notifyComponentUpdate(instance = null) {
    if (!this.enabled || !this.hasPermission(shared_utils_1.PluginPermission.COMPONENTS)) return;

    if (instance) {
      this.ctx.hook.emit(shared_utils_1.HookEvents.COMPONENT_UPDATED, ...(await this.backendApi.transformCall(shared_utils_1.HookEvents.COMPONENT_UPDATED, instance)));
    } else {
      this.ctx.hook.emit(shared_utils_1.HookEvents.COMPONENT_UPDATED);
    }
  }

Which crashes Babel with the following error :

Error: D:\git\devtools\packages\shell-electron\build\backend.js: Expected type "Expression" with option undefined, but instead got "SpreadElement".
    at assert (D:\git\devtools\node_modules\@babel\types\lib\asserts\generated\index.js:311:11)
    at Object.assertExpression (D:\git\devtools\node_modules\@babel\types\lib\asserts\generated\index.js:1308:3)
    at Emitter.Ep.explodeExpression (D:\git\devtools\node_modules\regenerator-transform\lib\emit.js:700:7)
    at explodeViaTempVar (D:\git\devtools\node_modules\regenerator-transform\lib\emit.js:743:23)
    at D:\git\devtools\node_modules\regenerator-transform\lib\emit.js:815:18
    at Array.map (<anonymous>)
    at Emitter.Ep.explodeExpression (D:\git\devtools\node_modules\regenerator-transform\lib\emit.js:814:28)
    at Emitter.Ep.explodeStatement (D:\git\devtools\node_modules\regenerator-transform\lib\emit.js:340:12)
    at D:\git\devtools\node_modules\regenerator-transform\lib\emit.js:323:12
    at Array.forEach (<anonymous>) {
  code: 'BABEL_TRANSFORM_ERROR'
}

When I modify emit.js to log the expr variable, I have :

Node {
  type: 'SpreadElement',
  start: 12927,
  end: 13022,
  loc: SourceLocation {
    start: Position { line: 526, column: 70, index: 12927 },
    end: Position { line: 526, column: 165, index: 13022 },
    filename: undefined,
    identifierName: undefined
  },
  argument: {
    type: 'YieldExpression',
    argument: Node {
      type: 'CallExpression',
      start: 12937,
      end: 13021,
      loc: [SourceLocation],
      callee: [Node],
      arguments: [Array],
      leadingComments: undefined,
      innerComments: undefined,
      trailingComments: undefined
    },
    delegate: false,
    trailingComments: [],
    leadingComments: [],
    innerComments: []
  },
  leadingComments: undefined,
  innerComments: undefined,
  trailingComments: undefined
}

Configuration file name

No response

Configuration

The commang I run is simply :

npx babel ./shell-electron/build/backend.js -o ./shell-electron/build/backend-babel.js --presets=@babel/preset-env

Current and expected behavior

Babel CLI crashes and don't output the new file. But when I change the js to :

  async notifyComponentUpdate(instance = null) {
    if (!this.enabled || !this.hasPermission(shared_utils_1.PluginPermission.COMPONENTS)) return;

    if (instance) {
      let t = await this.backendApi.transformCall(shared_utils_1.HookEvents.COMPONENT_UPDATED, instance);
      this.ctx.hook.emit(shared_utils_1.HookEvents.COMPONENT_UPDATED, ...t);
    } else {
      this.ctx.hook.emit(shared_utils_1.HookEvents.COMPONENT_UPDATED);
    }
  }

It don't crash anymore. Modifying the outputted file by hand is not a production-proof workflow though, and it'd be better if Babel could be run on it naturally.

Environment

npx envinfo --preset babel

  System:
    OS: Windows 10 10.0.19044
  Binaries:
    Node: 16.13.2 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD

Possible solution

No response

Additional context

No response

@Colisan Colisan changed the title [Bug]: [Bug]: Babel crash when spreading an await inside function parameters Mar 16, 2022
@JLHwung
Copy link
Contributor

JLHwung commented Mar 16, 2022

Duplicate of #12690.

It is an upstream issue tracked in facebook/regenerator#397

@JLHwung JLHwung closed this as completed Mar 16, 2022
@babel-bot
Copy link
Collaborator

Hey @Colisan! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jun 16, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants