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

Function fixes #323

Merged
merged 7 commits into from
Feb 2, 2023
Merged

Function fixes #323

merged 7 commits into from
Feb 2, 2023

Conversation

edemaine
Copy link
Collaborator

@edemaine edemaine commented Feb 2, 2023

The following changes are in separate commits for easier review:

  • Allow suffixed expressions and statements in more places
    • Same-line body of arrow functions (fixes Coffeescript bug: postfix if #308)
    • JSX braced expressions and children
    • But not e.g. in try expression which wants postfix to be outside, and do expression which needs to treat while postfix as something completely different.
    • This is how this PR started, but then I ran into a zillion other bugs along the way...
  • Forbid while/until as beginning of implicit calls
    • Matches existing behavior of for
    • Otherwise conflicts with postfix while/until notation
    • For example, x while y; got treated as a call x(while y {}) before
  • Allow semicolon-separated lines in one-line =>
    • For example, => x; y, matching existing behavior for ->
    • Previously lots of weird special cases for FatArrowBody
    • Now just one case for no brace wrapping and then the usual BracedBlock
  • Fix implicit return in else clause
    • Wasn't working when semicolon was inserted between then and else.
    • Improve AST so this is less brittle.
    • For example, -> if x then y else z wasn't returning z
  • Fix more cases of no implicit return via semicolon
    • -> x while y; was still returning
  • Wrap top-level anonymous function expressions in parens
    • Otherwise JS complains: SyntaxError: Function statements require a function name

@edemaine edemaine temporarily deployed to build February 2, 2023 19:37 — with GitHub Actions Inactive
@@ -78,6 +78,7 @@ uncacheable = new Set [
"NestedJSXChildExpression"
"NestedObject"
"NestedPropertyDefinitions"
"NonSingleBracedBlock"
"NonSuppressedTrailingMemberExpressions"
"ObjectLiteral"
"PopIndent"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably also add PostfixedExpression to no-cache rules since AssignmentExpression and ExtendedExpression are no-cache.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. I added PostfixedExpression and PostfixedStatement.

@STRd6
Copy link
Contributor

STRd6 commented Feb 2, 2023

Nice! Great work cleaning up those edge cases, lots of great fixes here!

@edemaine edemaine temporarily deployed to build February 2, 2023 20:27 — with GitHub Actions Inactive
@edemaine edemaine merged commit b8ae42e into main Feb 2, 2023
@edemaine edemaine deleted the suffixed branch February 2, 2023 20:28
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.

Coffeescript bug: postfix if
2 participants