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

javascript - How can you trigger the "What the hell is this?" JSLint message? - Stack Overflow

programmeradmin0浏览0评论

JSLint has some interesting messages, such as eval is evil. when you use an eval statement, and Weird relation. when comparing two literals, e.g. 1 == 2.

I was looking through a list of the JSLint messages, and noticed this one at the bottom of the list:

What the hell is this?

I looked through the JSLint source and found this code:

if (stack.length === 0) {
    error("What the hell is this?", nexttoken);
}

I have been trying for a while, unsuccessfully, to write code that triggers this. Nothing I have read about JSLint talks about this error message, why it exists, or what causes it. I've briefly inspected the code, but I can't really understand what the stack is, how it is populated or what could cause it to be empty.

Can somebody write a code sample that will cause JSLint to scream What the hell is this? or explain what prevents this from happening?

JSLint has some interesting messages, such as eval is evil. when you use an eval statement, and Weird relation. when comparing two literals, e.g. 1 == 2.

I was looking through a list of the JSLint messages, and noticed this one at the bottom of the list:

What the hell is this?

I looked through the JSLint source and found this code:

if (stack.length === 0) {
    error("What the hell is this?", nexttoken);
}

I have been trying for a while, unsuccessfully, to write code that triggers this. Nothing I have read about JSLint talks about this error message, why it exists, or what causes it. I've briefly inspected the code, but I can't really understand what the stack is, how it is populated or what could cause it to be empty.

Can somebody write a code sample that will cause JSLint to scream What the hell is this? or explain what prevents this from happening?

Share Improve this question edited Dec 3, 2011 at 17:33 Peter Olson asked Oct 11, 2011 at 17:17 Peter OlsonPeter Olson 143k49 gold badges208 silver badges248 bronze badges 5
  • 1 I don't have such code... but examining the snippet you posted I suspect that JSLint uses an internal stack with some (predefined?) size and only displays this message when that stack is empty where it shouldn't (checking XML)... this message only occurs if somewhere along the way a JSLint bug leads to an empty stack while the rest of the function believes there is a nested token to handle... – Yahia Commented Oct 11, 2011 at 17:29
  • 3 Maybe it is an error which should/can never occur... just a thought. – Felix Kling Commented Oct 11, 2011 at 17:30
  • I'd say there's a decent chance that it was written for internal use when developing the tool. If it encountered some condition it wasn't expecting, it output that message and the developer would investigate further. Just a guess. – riwalk Commented Oct 11, 2011 at 17:33
  • 6 Holy crap. How can someone who writes code like that tell me how to write good code? :( – user166390 Commented Oct 11, 2011 at 17:39
  • 2 @pst jshint.com ;) – Alex Turpin Commented Oct 11, 2011 at 17:43
Add a comment  | 

2 Answers 2

Reset to default 16

It looks a lot like a "can't happen" check (a form of defensive programming). If so, there might not be any way to trigger it in practice.

Looks like the error message is no longer there in the message list or source code.

发布评论

评论列表(0)

  1. 暂无评论