注释可以是单行或多行。多行注释不能嵌套。
Comments can be either single or multi-line. Multi-line comments cannot nest.
因为单行注释可以包含除换行符码点之外的任何 Unicode 码点,并且由于一般规则是 token 总是尽可能长的,单行注释总是由从 // 标记到行尾的所有码点组成。然而,行尾的行终止符不被认为是单行注释的一部分; 它被词法单独识别,并成为语法输入元素流的一部分。这一点非常重要,因为它意味着单行注释的存在或不存在不会影响自动分号插入的过程 (见 11.9)。
Because a single-line comment can contain any Unicode code point except a LineTerminator code point, and because of the general rule that a token is always as long as possible, a single-line comment always consists of all code points from the // marker to the end of the line. However, the LineTerminator at the end of the line is not considered to be part of the single-line comment; it is recognized separately by the lexical grammar and becomes part of the stream of input elements for the syntactic grammar. This point is very important, because it implies that the presence or absence of single-line comments does not affect the process of automatic semicolon insertion (see 11.9).
注释的行为就像空格,会被丢弃,除了如果一个多行注释包含一个行终止符码点,那么为了通过语法进行解析,整个注释被认为是一个行终止符。
Comments behave like white space and are discarded except that, if a MultiLineComment contains a line terminator code point, then the entire comment is considered to be a LineTerminator for purposes of parsing by the syntactic grammar.
Syntax
Comment ::
MultiLineComment
SingleLineComment
MultiLineComment ::
/* MultiLineCommentCharsopt */
MultiLineCommentChars ::
MultiLineNotAsteriskChar MultiLineCommentCharsopt
* PostAsteriskCommentChars__opt
PostAsteriskCommentChars ::
MultiLineNotForwardSlashOrAsteriskChar MultiLineCommentCharsopt
* PostAsteriskCommentChars__opt
MultiLineNotAsteriskChar ::
SourceCharacter but not *
MultiLineNotForwardSlashOrAsteriskChar ::
SourceCharacter but not one of / or *
SingleLineComment ::
// SingleLineCommentChars__opt
SingleLineCommentChars ::
SingleLineCommentChar SingleLineCommentChars__opt
SingleLineCommentChar ::
SourceCharacter but not LineTerminator
这里 opt 是 optional 的意思,就是可选的意思。
