atom / language-javascript

JavaScript language package for Atom
Other
194 stars 235 forks source link

Js For of loop error in atom #596

Open axe-z opened 6 years ago

axe-z commented 6 years ago

Simple, latest version 1.30

for loop, the for of autocompletes (without any added snippets) this:

for (variable of iterable) {

}

always f...s me up later.

should be for (LET variable of iterable) {

}

chfritz commented 6 years ago
for (i in [1,2,3]) console.log(i)

seems to work just fine. Aren't variables that are declared without let/const implicitly lets?

Arcanemagus commented 6 years ago

@chfritz This issue is about the for...of snippet in Atom.

Your example is a for...in. And for your own reference if you don't use var, let, or const the variable is declared in the global scope, generally a very bad idea 😉.

axe-z commented 6 years ago

It's not a huge deal anyway, but the for IN is ok(var), regular for loop too :

for (var variable in object) { if (object.hasOwnProperty(variable)) {

} } && for (var i = 0; i < array.length; i++) { array[i] }

Might also be time to use the LET keyword ! I always, for no good reason mind you... , wake up and figure out the variable's missing after a few seconds of debugging.and YES, I've created my own snippet by now, but still, this should be an easy fix.

fd-rey commented 5 years ago

I've the same issue, for...of is creating code that produces ReferenceError. I think that a possible solution could be modify this file: https://github.com/atom/language-javascript/blob/master/snippets/language-javascript.cson

setting this line 'for of': 'prefix': 'forof' 'body': 'for (${1:variable} of ${2:iterable}) {\n\t$3\n}'

to this one (add var before the variable) 'for of': 'prefix': 'forof' 'body': 'for (var ${1:variable} of ${2:iterable}) {\n\t$3\n}'

axe-z commented 5 years ago

left for vscode. Never thought I would. ( this was not the main reason of course )