Skip to content

Resolve #2191: Add spaces after return and yield if necessary - #2194

Merged
lukastaegert merged 1 commit into
masterfrom
missing-space
May 16, 2018
Merged

Resolve #2191: Add spaces after return and yield if necessary#2194
lukastaegert merged 1 commit into
masterfrom
missing-space

Conversation

@lukastaegert

Copy link
Copy Markdown
Member

After some deliberation, this is the lowest impact fix I could come up with to resolve #2191. Basically as far as I am aware, this issue can only arise for return statements and yield expressions when there is no space between the keyword and the subsequent expression and the nested expression changes due to some simplification.

E.g. return!1||true -> return true.

For await expressions this is not an issue as operator precedence is different here (await!1||true is equivalent to (await !1) || true)

The solution is to insert a space if the argument of the return statement starts directly after the last letter of return, similarly for yield.

@lukastaegert
lukastaegert requested a review from guybedford May 16, 2018 13:23

@guybedford guybedford left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. If other cases crop up we can handle them similarly too.

this.argument.render(code, options);
if (this.argument.start === this.start + 5 /* 'yield'.length */) {
code.prependLeft(this.start + 5, ' ');
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we try and preserve handling of return!x style cases though here?

@kzc

kzc commented May 16, 2018

Copy link
Copy Markdown
Contributor

Are any operators affected by this expression simplification spacing issue as well?

  • typeof
  • await
  • void
  • delete
  • in
  • instanceof

@lukastaegert

Copy link
Copy Markdown
Member Author

Operator precedence says it is not necessary. This situation can only occur if to the right side of the operator, there is an expression that can be simplified.

The only expressions (for now) that can be simplified are logical, conditional and sequence expressions. All of those bind weaker than the operators you listed.

But yes, this issue could crop up again in the future if we extend value inlining/simplification enough.

@lukastaegert

Copy link
Copy Markdown
Member Author

@guybedford Thanks for the quick reviews on these ones!

@kzc

kzc commented May 16, 2018

Copy link
Copy Markdown
Contributor

Operator precedence says it is not necessary. This situation can only occur if to the right side of the operator, there is an expression that can be simplified.

Are parens ever dropped for simplified expressions? If so, that could be an issue.

@lukastaegert
lukastaegert merged commit 4e8435c into master May 16, 2018
@lukastaegert

Copy link
Copy Markdown
Member Author

Released as 0.59.1

@lukastaegert lukastaegert added this to the 0.59.1 milestone May 16, 2018
@lukastaegert

Copy link
Copy Markdown
Member Author

Are parens ever dropped for simplified expressions? If so, that could be an issue

If the parent contains parens, those will always be retained. In some situations, this can lead to double parens but this is usually not an issue.

@lukastaegert
lukastaegert deleted the missing-space branch May 21, 2018 16:43
calebeby referenced this pull request in Pigmice2733/scouting-frontend May 30, 2018
This Pull Request updates dependency [rollup](https://github.com/rollup/rollup) from `v0.59.0` to `v0.59.4`



<details>
<summary>Release Notes</summary>

### [`v0.59.4`](https://github.com/rollup/rollup/blob/master/CHANGELOG.md#&#8203;0594)
[Compare Source](rollup/rollup@v0.59.3...v0.59.4)
*2018-05-28*
* Fix performance regression when many return statements are used ([#&#8203;2218](`https://github.com/rollup/rollup/pull/2218`))

---

### [`v0.59.3`](https://github.com/rollup/rollup/blob/master/CHANGELOG.md#&#8203;0593)
[Compare Source](rollup/rollup@v0.59.2...v0.59.3)
*2018-05-24*
* Fix reassignment tracking for constructor parameters ([#&#8203;2214](`https://github.com/rollup/rollup/pull/2214`))

---

### [`v0.59.2`](https://github.com/rollup/rollup/blob/master/CHANGELOG.md#&#8203;0592)
[Compare Source](rollup/rollup@v0.59.1...v0.59.2)
*2018-05-21*
* Fix reassignment tracking in for-in loops ([#&#8203;2205](`https://github.com/rollup/rollup/pull/2205`))

---

### [`v0.59.1`](https://github.com/rollup/rollup/blob/master/CHANGELOG.md#&#8203;0591)
[Compare Source](rollup/rollup@v0.59.0...v0.59.1)
*2018-05-16*
* Fix infinite recursion when determining literal values of circular structures ([#&#8203;2193](`https://github.com/rollup/rollup/pull/2193`))
* Fix invalid code when simplifying expressions without spaces ([#&#8203;2194](`https://github.com/rollup/rollup/pull/2194`))

---

</details>




---

This PR has been generated by [Renovate Bot](https://renovatebot.com).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rollup produces invalid code (from some valid code produced by babel-minify)

3 participants