【问题标题】:How do I get rid of "Nested comment." error thrown by JSLint?如何摆脱“嵌套评论”。 JSLint 抛出的错误?
【发布时间】:2013-01-22 11:45:10
【问题描述】:

在以下示例中:

    <!--[if lt IE 9]>
    <script src="./js/lib/modernizr.custom.js"></script>
    <![endif]-->

JSLint 在最后一行抛出一个错误,说“嵌套注释。”。我似乎无法在 Internet 上找到“修复”此问题的方法。谁有解决办法?

【问题讨论】:

    标签: internet-explorer conditional jslint


    【解决方案1】:

    在我看来,这似乎是 JSLint 中的一个错误(或者可能是一个疏忽)。处理HTML cmets的代码如下:

    // ...
    case '<!--':
        length = line;
        for (;;) {
            i = source_row.indexOf('--');
            if (i >= 0) {
                break;
            }
            i = source_row.indexOf('<!'); // This line causes the problem
            if (i >= 0) {
                stop_at('nested_comment', line, character + i);
            }
            if (!next_line()) {
                stop_at('unclosed_comment', length, c);
            }
        }
        // ...
    

    基本上,当 JSLint 遇到打开的注释标记 (&lt;!--) 时,它会遍历源代码的行,直到遇到关闭的注释标记 (--&gt;,上面的 sn-p 中没有显示)。如果在该迭代期间它在评论的任何一行的任何地方遇到字符串&lt;!,它将引发您所看到的“嵌套评论”错误。

    不幸的是,除了不使用 JSLint 进行标记验证(无论如何我通常会推荐)之外,实际上没有办法解决这个问题。我会看看能不能找到修复它的好方法,然后提交补丁。

    【讨论】:

      猜你喜欢
      • 2020-10-19
      • 1970-01-01
      • 1970-01-01
      • 2023-02-24
      • 1970-01-01
      • 2019-08-28
      • 2021-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多