javascript reduce doesn't work with arrow function
Opened this issue · 5 comments
This line
@[0, 1, 2].reduce((a, b) => a + b)
throws this
ReferenceError: Problem while rendering template at line 19, character 0.
Original message: Problem while rendering template at line 19, character 0.
Original message: a is not defined.
Context:
18 | <div class="value">
> 19 | @[0, 1, 2].reduce((a, b) => a)
20 | </div>
.
Context:
at eval (eval at <anonymous> ([cut]/node_modules/vash/runtime.js:308:26), <anonymous>:342:72)
at linked ([cut]/node_modules/vash/runtime.js:348:14)
at [cut]/node_modules/vash/lib/helpers/layout.js:232:5
at Object.vash.loadFile ([cut]/node_modules/vash/lib/helpers/layout.js:68:11)
at Helpers.helpers.include ([cut]/node_modules/vash/lib/helpers/layout.js:230:8)
at eval (eval at <anonymous> ([cut]/node_modules/vash/runtime.js:308:26), <anonymous>:91:33)
at Helpers.helpers.block ([cut]/node_modules/vash/lib/helpers/layout.js:253:5)
at eval (eval at <anonymous> ([cut]/node_modules/vash/runtime.js:308:26), <anonymous>:61:33)
at [cut]/node_modules/vash/lib/helpers/layout.js:197:5
at Object.vash.loadFile ([cut]/node_modules/vash/lib/helpers/layout.js:68:11)
at Helpers.helpers.extend ([cut]/node_modules/vash/lib/helpers/layout.js:188:8)
at eval (eval at <anonymous> ([cut]/node_modules/vash/runtime.js:308:26), <anonymous>:10:33)
at linked ([cut]/node_modules/vash/runtime.js:348:14)
at [cut]/node_modules/vash/lib/helpers/layout.js:80:22
at Object.vash.loadFile ([cut]/node_modules/vash/lib/helpers/layout.js:68:11)
at View.vash.renderFile.vash.__express [as engine] ([cut]/node_modules/vash/lib/helpers/layout.js:76:8)
at View.render ([cut]/node_modules/express/lib/view.js:126:8)
at tryRender ([cut]/node_modules/express/lib/application.js:639:10)
at EventEmitter.render ([cut]/node_modules/express/lib/application.js:591:3)
at ServerResponse.render ([cut]/node_modules/express/lib/response.js:960:7)
at [cut]/app.js:98:6
at Layer.handle [as handle_request] ([cut]/node_modules/express/lib/router/layer.js:95:5)
at next ([cut]/node_modules/express/lib/router/route.js:131:13)
at [cut]/app.js:93:3
at [cut]/node_modules/mongoose/lib/query.js:2257:18
at process._tickDomainCallback (node.js:438:9)
while this
@[0, 1, 2].reduce(function(a, b) { return a + b })
works.
node@v5.9.1
vash@0.12.1
This is special syntax of ECMAScript 6. Like several web browsers, vash doesn't support ES6 yet.
I am aware of that and I am asking this because @[0, 1, 2].map(i => i + 1)
works perfectly.
I believe the problem is that vash is "optimizing" out the nested parens because it doesn't know about arrow functions.
I don't plan to add official ES2015 support to vash at this time.
Yep, that's okay, I was just wondering.
I don't plan to add official ES2015 support to vash at this time.
@kirbysayshi would you mind contributions for it though?
I feel it's very bad when sometimes arrow functions work, sometimes not... that's the recipe for wasting hundreds of hours not knowing what to fix.