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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declarations and ThrowStatement in an IfStatement within DoExpression breaks compilation #5080

Closed
phpnode opened this issue Jan 9, 2017 · 2 comments · Fixed by #5693
Closed
Labels
Has PR i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue Spec: Do Expressions

Comments

@phpnode
Copy link
Contributor

phpnode commented Jan 9, 2017

Input Code

let x = 100;

let a = do {
  if(x > 10) {
    true;
  } else {
    let a = 123; // does not compile
    throw "nope"; // does not compile
  }
};

Example in the REPL

Babel Configuration (.babelrc, package.json, cli command)

Using es2015 and stage-0

Expected Behavior

It should wrap the body in an IIFE.

Current Behavior

It doesn't think that an IIFE is required but when the plugin tries to get the completion record for the relevant if statement it finds undefined and passes that to either the consequent or alternate of a ConditionalExpression, which throws:

Property alternate of ConditionalExpression expected node to be of a type ["Expression"] but instead got undefined

Possible Solution

Detect this scenario and wrap in an IIFE, or add a helper that turns throw e into _throw(e) and hoist + rename declarations.

@babel-bot
Copy link
Collaborator

Hey @phpnode! 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.

@jridgewell
Copy link
Member

Fixed by #5693.

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 4, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Has PR i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue Spec: Do Expressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants