jashkenas / jashkenas/coffeescript
Bug: own-of outside for-condition
- Dominant language
- CoffeeScript
- Stars
- 16.6k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
>Choose one: is this a bug report or feature request?
This is likely a bug/oversight.
I apologize if this came up before. There's roughly 400 search results for `own of`.
[Demo](https://coffeescript.org/v2/#try:for%20own%20k%20of%20obj%0A%20%20do%20something%0A%20%20%0Aif%20own%20k%20of%20obj%0A%20%20do%20something%0A)
Currently `own k of obj` works differently from what I'd expect, which would be the same as it behaves inside a for-loop condition. Instead the `own` keyword is treated like a regular identifier.
### Input Code
```coffee
for own k of obj
do something
if own k of obj
do something
```
### Expected Behavior
```js
var k,
hasProp = {}.hasOwnProperty;
for (k in obj) {
if (!hasProp.call(obj, k)) continue;
something();
}
if(hasProp.call(obj, k)) {
something();
}
```
### Current Behavior
```js
var k,
hasProp = {}.hasOwnProperty;
for (k in obj) {
if (!hasProp.call(obj, k)) continue;
something();
}
if (own(k in obj)) {
something();
}
```
### Possible Solution
Change compilation output.
### Context
>How has this issue affected you?
Runtime errors.
### Environment
* CoffeeScript version: v2.3.2
* Node.js version: any
Contributor guide
Research direction
Start by compiling the reported CoffeeScript input containing `for own k of obj` and `if own k of obj`, then compare the output with the expected and current JavaScript shown in the issue. Trace how `own` is handled in a for-condition versus an ordinary conditional, and consider the issue complete when the conditional produces the expected own-property check without changing the existing loop behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- coffeescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100