jashkenas / jashkenas/coffeescript

In Operator - IndexOf

Open
#5,481 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
CoffeeScript
Stars
16.6k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

The In Operator seems to have been broken for a while...

```coffee
if 'github.com' in "https://github.com/jashkenas/coffeescript/issues/5481"
alert 'Found'
```

Does not work (using the version on https://coffeescript.org/)

It renders to
```
var indexOf = [].indexOf;

if (indexOf.call("https://github.com/jashkenas/coffeescript/issues/5481", 'github.com') >= 0) {
alert('found');:
}
```
Which doesn´t work:
```
indexOf.call("https://github.com/jashkenas/coffeescript/issues/5481", 'github.com')
-1
```
```
indexOf.call('github.com', "https://github.com/jashkenas/coffeescript/issues/5481")
-1
```
This works though
```
"https://github.com/jashkenas/coffeescript/issues/5481".indexOf('github.com')
37
```

That´s in chrome, not sure when indexOf.call is kinda broken

Contributor guide

Open the contributing guide

Research direction

Reproduce the CoffeeScript `in` expression from the issue and inspect the compiler path that emits `indexOf.call` for it. Compare the generated JavaScript with direct string `indexOf`; done means the example detects `github.com` correctly without breaking array containment behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
coffeescript, javascript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.