coffeescript icon indicating copy to clipboard operation
coffeescript copied to clipboard

Bug: own-of outside for-condition

Open Inve1951 opened this issue 5 years ago • 0 comments

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

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

for own k of obj
  do something
  
if own k of obj
  do something

Expected Behavior

var k,
  hasProp = {}.hasOwnProperty;

for (k in obj) {
  if (!hasProp.call(obj, k)) continue;
  something();
}

if(hasProp.call(obj, k)) {
  something();
}

Current Behavior

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

Inve1951 avatar Jan 16 '19 19:01 Inve1951