最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JS parser and short-circuited arrow function - Stack Overflow

programmeradmin2浏览0评论

Why does the JS parser require grouping parens after an (empty) arrow-function short-circuit?

Seems like the arrow-function syntax should be detected as an irreducible token.

This code:

( someFunc || ()=>{} )()

Generates a syntax error:

Uncaught SyntaxError: Malformed arrow function parameter list

The fix is to add grouping parens, but I don't understand why:

( someFunc || (()=>{}) )()

I'd also be curious to see what code the parser is seeing this as. In other words, what code would you need to write to generate that exact error. It's not doing a lookahead, clearly, so it's choking somewhere between the || and the closing grouping paren (antepenultimate char).

发布评论

评论列表(0)

  1. 暂无评论