This code generates an error when I run it with node v6.9.2
var req = {}
[\'foo\', \'bar\'].forEach(prop => {
console.log(\"prop: \" + prop)
});
Automatic semicolon insertion has turned
var req = {}
['foo', 'bar']
into
var req = {}['foo', 'bar']
and of course {}
doesn't contain a 'bar'
property (because 'foo', 'bar'
evaluates to 'bar'
).
(undefined).forEach(...)
gets evaluated, which then leads to the error that you're seeing.
If you're relying on ASI, it's common practice to prefix lines beginning with []
or ()
with a semicolon:
var req = {}
;['foo', 'bar']