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

Bug: multiline object literal requires braces in post-loops #5299

Open
Inve1951 opened this issue Feb 7, 2020 · 1 comment
Open

Bug: multiline object literal requires braces in post-loops #5299

Inve1951 opened this issue Feb 7, 2020 · 1 comment

Comments

@Inve1951
Copy link
Contributor

Inve1951 commented Feb 7, 2020

Choose one: is this a bug report or feature request?

A bit of both.

Input Code

#try

use k, v for k, v of 
  k: v

While this also applies to

use k, v for x in  # or `from`
  k: v

# and

use k, v while     # or `until`
  k: v

i don't see any point in supporting that.

Expected Behavior

# (shortened)
for (k in {k: v}) {
  use(k, v);
}

Current Behavior

[stdin]:2:1: error: unexpected indentation
  k: v
^^

Workaround

use k, v for k, v of \
  k: v \
  a: b \
  x: y

# or

use k, v for k, v of {
  k: v
  a: b
  x: y
}

Possible Solution

Add implicit line continuation support for objects in eof for-of loop headers.
The logic used in function calls might be reusable.

Context

Ran into this a couple of times expecting the compiler to accept it.

Environment

  • CoffeeScript version: v2.5.1
  • Node.js version: any



    Btw, do you call this an implicit object? What's the term generally used for omitting object braces?
@ljluestc
Copy link

ljluestc commented Sep 9, 2023

If you want to achieve this behavior in CoffeeScript, you can use explicit line continuation with a backslash \ or enclose the object in curly braces {} as you've mentioned in the workaround.

Here's your code with explicit line continuation using backslashes:

#try
use k, v for k, v of \
  k: v

And here's the same code with explicit curly braces:

#try
use k, v for k, v of {
  k: v
}

As for your question about terminology, what you're referring to as "implicit objects" or "omitting object braces" in CoffeeScript is essentially CoffeeScript's syntax for creating objects without using explicit braces. It's part of CoffeeScript's syntactic sugar for creating objects and can be considered a form of implicit object declaration. There's no widely standardized terminology for this specific syntax, but it's often referred to as "object literals" or "object shorthand" in the context of CoffeeScript and JavaScript.

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

No branches or pull requests

2 participants