jashkenas / jashkenas/coffeescript
Proposal: pre-compile "obj{ a, b }" to "(({a,b})->{a,b})(obj)" to create a copy of "obj" with only properties "a" and "b"
- Dominant language
- CoffeeScript
- Stars
- 16.6k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
1. It's feature request.
2. Description:
it's a very common pattern when you need to pickup only some properties from object
and to do this people usually use such constructs:
### Input Code
```coffee
obj1 = a:1, b:2, c:3
obj2 = ( ({a,b}) -> {a,b} ) obj1
```
### Possible Solution
would be nice to have an "operator" like this:
```coffee
obj1 = a:1, b:2, c:3
obj2 = obj1{ a, b }
```
as we can do
```coffee
obj1 = a:1, b:2, c:3
{ a, b } = obj1
obj2 = { a, b }
```
but it destruct local variables "a" and "b"
or
```coffee
obj1 = a:1, b:2, c:3
obj2 = ( ({a,b}) -> {a,b} ) obj1
```
that way is safe but looks ugly )
Thank you!
Contributor guide
Research direction
The issue provides input and proposed CoffeeScript examples but names no files, tests, or compiler entry points. Start by locating the parser and compiler paths for object literals and destructuring, then determine the syntax and semantics needed for obj{ a, b }. Done means the proposal has an agreed implementation scope and corresponding compiler tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- coffeescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100