Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Variable of array comprehension not defined #9

Closed
AluisioASG opened this issue Feb 28, 2015 · 21 comments · Fixed by #114
Closed

Variable of array comprehension not defined #9

AluisioASG opened this issue Feb 28, 2015 · 21 comments · Fixed by #114
Labels

Comments

@AluisioASG
Copy link

let a = [], b = [for (e of a) String(e)];

results in:

  1:12  error  b is defined but never used  no-unused-vars
  1:22  error  'e' is not defined           no-undef
  1:37  error  'e' is not defined           no-undef
@jeroencranendonk-wf
Copy link

Same for generator comprehensions.

@zdychacek
Copy link

Is there any plan to implement support for array/generator comprehensions?

It would be great ;)

Thanks for reply.

@sebmck
Copy link
Contributor

sebmck commented Apr 14, 2015

Not sure if it's possible because it'd require patching too much of escope
and I'm not sure if it'd be possible. Patches are welcome :)

On Tuesday, 14 April 2015, Ondřej Ždych notifications@github.com wrote:

Is there any plan to implement support for array/generator comprehensions?

It would be great ;)

Thanks for reply.


Reply to this email directly or view it on GitHub
#9 (comment).

Sebastian McKenzie

@hzoo hzoo added the escope label May 15, 2015
@hzoo
Copy link
Member

hzoo commented May 20, 2015

I guess this won't be too different from #72?

@KylePDavis
Copy link

For what it's worth, I've used this as a hack to work around this for now:

/*global cVar*///NOTE: "fix" linter errs for comprehension vars

@callumlocke
Copy link

@KylePDavis that helps, thanks

@hzoo
Copy link
Member

hzoo commented May 25, 2015

Hey everyone, does #114 fix your issues?

@KylePDavis
Copy link

Thanks, @hzoo, that does seem to fix the no-undef rule complaints but it also seems to trigger block-scoped-var complaints.

Example:

"use strict";
export default [for (i of global) String(i)];
//OR: (for (i of global) String(i));

Errors:

  2:21  error  "i" used outside of binding context  block-scoped-var
  2:41  error  "i" used outside of binding context  block-scoped-var

@hzoo
Copy link
Member

hzoo commented May 26, 2015

Ah dang I probably added the variable in the wrong scope.. (most likely just need to move it up a level?) or it's not that straightforward haha.

@hzoo
Copy link
Member

hzoo commented May 26, 2015

@KylePDavis yeah I'm not sure at the moment =/. I guess this is besides the point but if you are using babel (with let/const) which are already block scope then you wouldn't need the rule (block-scoped-var) anymore right? Or is there something else that it catches?

hzoo added a commit to hzoo/babel-eslint that referenced this issue Jun 3, 2015
@gaearon
Copy link
Member

gaearon commented Jun 3, 2015

f921efa works great for me, only no-unused-vars false-triggering now in my comprehensions code.

@hzoo
Copy link
Member

hzoo commented Jun 3, 2015

@gaearon Can you give me a code snippet that is failing for you? I can add no-unused-vars to the tests now.

@gaearon
Copy link
Member

gaearon commented Jun 3, 2015

function getFirstAtom(stores) {
  return new Map([
    for (store of stores)
      [store, undefined]
  ]);
}

getFirstAtom();

stores parameter is reported to be unused.

Thanks a lot for the effort! Your work saved me a lot of headache in the past few weeks.

@hzoo
Copy link
Member

hzoo commented Jun 3, 2015

Ah ok I didn't visit the node.right (stores in your case). Shouldn't be too hard to fix.

Awesome! It's be fun contributing and learning all this stuff (btw react-hot-loader has been great).

@hzoo
Copy link
Member

hzoo commented Jun 3, 2015

@gaearon See if the next commit fixes it hzoo@8e254b7.

@gaearon
Copy link
Member

gaearon commented Jun 3, 2015

@hzoo Works great. Thanks again.

@hzoo hzoo closed this as completed in #114 Jun 3, 2015
hzoo added a commit that referenced this issue Jun 3, 2015
support comprehensions (no-undef) - fixes #9
@zspecza
Copy link

zspecza commented Jul 14, 2015

Still getting this issue with the below snippet, more specifically the block-scoped-var

function entries(obj) {
  return (for (key of Object.keys(obj)) [key, obj[key]])
}

@callumlocke
Copy link

Are you sure you're on the latest version? I don't get this problem any
more.
On Tue, 14 Jul 2015 at 22:27, Declan de Wet notifications@github.com
wrote:

Still getting this issue with the below snippet

function entries(obj) {
return (for (key of Object.keys(obj)) [key, obj[key]])
}


Reply to this email directly or view it on GitHub
#9 (comment).

@zspecza
Copy link

zspecza commented Jul 14, 2015

@callumlocke yep:

@hzoo
Copy link
Member

hzoo commented Jul 14, 2015

@declandewet can you make a seperate issue for this? The original issue was for no-undef and this is for block-scoped-var/

@zspecza
Copy link

zspecza commented Jul 15, 2015

@hzoo #148 😄

nicolo-ribaudo pushed a commit to babel/babel that referenced this issue Nov 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants