是否可以在es6 Template-String中添加注释? [英] Is it possible to have a comment inside a es6 Template-String?

查看:200
本文介绍了是否可以在es6 Template-String中添加注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个多线es6模板字符串来描述,例如请求的一些URL参数:

Let's say we have a multiline es6 Template-String to describe e.g. some URL params for a request:

const fields = `
    id,
    message,
    created_time,
    permalink_url,
    type
`;

有没有办法在反引号模板字符串中添加注释?喜欢:

Is there any way to have comments inside that backtick Template-String? Like:

const fields = `
    // post id
    id,
    // post status/message
    message,
    // .....
    created_time,
    permalink_url,
    type
`;


推荐答案

不。

该语法有效,但只返回包含 \ n // post id \ nid 的字符串,而不是删除评论并创建没有它们的字符串。

That syntax is valid, but will just return a string containing \n// post id\nid, rather than removing the comments and creating a string without them.

如果你看一下规范的§11.8.6,您可以看到在反引号分隔符之间识别的唯一标记是 TemplateCharacters ,接受转义序列,换行符和普通字符。在§A.1 SourceCharacter 被定义为任何Unicode点(除了11.8.6中排除的那些)。

If you look at §11.8.6 of the spec, you can see that the only token recognized between the backtick delimiters is TemplateCharacters, which accepts escape sequences, line breaks, and normal characters. In §A.1, SourceCharacter is defined to be any Unicode point (except the ones excluded in 11.8.6).

这篇关于是否可以在es6 Template-String中添加注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆