Visual Studio Code 片段无效的控制字符

Gur*_*bot 4 code-snippets visual-studio-code

我有以下用户片段:

{
/*
    // Place your snippets for JavaScript React here. Each snippet is defined under a snippet name and has a prefix, body and 
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
    // same ids are connected.
    // Example:
    "Print to console": {
        "prefix": "log",
        "body": [
            "console.log('$1');",
            "$2"
        ],
        "description": "Log output to console"
    }
*/
    "Small comment": {
        "prefix": "//=",
        "body": [
            "// ===================================",
            "// ${1:COMMENT}",
            "// ==================================="
        ],
        "description": "Small comment"
    }
}
Run Code Online (Sandbox Code Playgroud)

我在第二个正文行上收到以下错误:

Invalid characters in string. Control characters must be escaped.

我认为这${1:somestring}是一个有效的占位符。我在构建这个片段时做错了什么?

Mr *_*uck 12

我刚刚在寻找答案时发现了这个问题,我使用了代码片段生成器,因此假设每个的格式都是相同的,但没想到我粘贴了其中包含选项卡的代码。

删除制表符并使用空格代替格式化为我修复了它。

希望这可以帮助。:)

  • 您不必删除制表符,您可以在字符串中使用“\t” (8认同)