12.8.1 Null литерал
Синтаксис
NullLiteral ::
null
12.8.2 Boolean литерал
Синтаксис
true
false
12.8.3 Числовые литералы
Синтаксис
_
NonDecimalIntegerLiteral [+Sep]
NonDecimalIntegerLiteral [+Sep] BigIntLiteralSuffix
NonZeroDigit DecimalDigits [+Sep] opt BigIntLiteralSuffix
NonZeroDigit NumericLiteralSeparator DecimalDigits [+Sep] BigIntLiteralSuffix
NonDecimalIntegerLiteral [Sep] ::
BinaryIntegerLiteral [?Sep]
OctalIntegerLiteral [?Sep]
HexIntegerLiteral [?Sep]
n
DecimalIntegerLiteral . DecimalDigits [+Sep] opt ExponentPart [+Sep] opt
. DecimalDigits [+Sep] ExponentPart [+Sep] opt
DecimalIntegerLiteral ExponentPart [+Sep] opt
0
NonZeroDigit NumericLiteralSeparator opt DecimalDigits [+Sep]
DecimalDigits [Sep] ::
DecimalDigits [?Sep] DecimalDigit
[+Sep] DecimalDigits [+Sep] NumericLiteralSeparator DecimalDigit
DecimalDigit :: одно из
0 1 2 3 4 5 6 7 8 9
NonZeroDigit :: одно из
1 2 3 4 5 6 7 8 9
ExponentPart [Sep] ::
ExponentIndicator SignedInteger [?Sep]
ExponentIndicator :: один из
e E
SignedInteger [Sep] ::
DecimalDigits [?Sep]
+ DecimalDigits [?Sep]
— DecimalDigits [?Sep]
BinaryIntegerLiteral [Sep] ::
0b BinaryDigits [?Sep]
0B BinaryDigits [?Sep]
BinaryDigits [Sep] ::
BinaryDigits [?Sep] BinaryDigit
[+Sep] BinaryDigits [+Sep] NumericLiteralSeparator BinaryDigit
BinaryDigit :: одно из
0 1
OctalIntegerLiteral [Sep] ::
0o OctalDigits [?Sep]
0O OctalDigits [?Sep]
OctalDigits [Sep] ::
OctalDigits [?Sep] OctalDigit
[+Sep] OctalDigits [+Sep] NumericLiteralSeparator OctalDigit
LegacyOctalIntegerLiteral OctalDigit
NonOctalDecimalIntegerLiteral ::
LegacyOctalLikeDecimalIntegerLiteral NonOctalDigit
NonOctalDecimalIntegerLiteral DecimalDigit
LegacyOctalLikeDecimalIntegerLiteral ::
LegacyOctalLikeDecimalIntegerLiteral OctalDigit
OctalDigit :: одно из
0 1 2 3 4 5 6 7
NonOctalDigit :: одно из
8 9
HexIntegerLiteral [Sep] ::
0x HexDigits [?Sep]
0X HexDigits [?Sep]
HexDigits [Sep] ::
[+Sep] HexDigits [+Sep] NumericLiteralSeparator HexDigit
HexDigit :: одно из
0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F
SourceCharacter, следующий сразу за NumericLiteral, не должен быть IdentifierStart или DecimalDigit.
Например: 3in — это ошибка, а не два входных элемента 3 и in.
12.8.3.1 Статическая семантика: Ранние Ошибки
NumericLiteral :: LegacyOctalIntegerLiteral
DecimalIntegerLiteral :: NonOctalDecimalIntegerLiteral
- Это синтаксическая ошибка, если исходный код, соответствующий этому продукту, является кодом строгого режима.
Примечание
В коде нестрогого режима этот синтаксис является Legacy (Наследие).
12.8.3.2 Статическая семантика: Математическое значение. MV — mathematical value
Числовой литерал обозначает значение типа Number или типа BigInt.
- Математическое значение из NumericLiteral :: DecimalLiteral является математическим значением для DecimalLiteral.
- Математическое значение из NonDecimalIntegerLiteral :: BinaryIntegerLiteral является математическим значением для BinaryIntegerLiteral.
- Математическое значение из NonDecimalIntegerLiteral :: OctalIntegerLiteral является математическим значением для OctalIntegerLiteral.
- Математическое значение из NonDecimalIntegerLiteral :: HexIntegerLiteral является математическим значением для HexIntegerLiteral.
- Математическое значение из DecimalLiteral :: DecimalIntegerLiteral . является математическим значением для DecimalIntegerLiteral.
- Математическое значение из DecimalLiteral :: DecimalIntegerLiteral . DecimalDigits является математическим значением для DecimalIntegerLiteral plus (the MV of DecimalDigits × 10—n), где n — это количество кодовых точек в DecimalDigits, исключая все вхождения для NumericLiteralSeparator.
- Математическое значение из DecimalLiteral :: DecimalIntegerLiteral . ExponentPart is the MV of DecimalIntegerLiteral × 10e, where e is the MV of ExponentPart.
- Математическое значение из DecimalLiteral :: DecimalIntegerLiteral . DecimalDigits ExponentPart is (the MV of DecimalIntegerLiteral plus (the MV of DecimalDigits × 10—n)) × 10e, where n is the number of code points in DecimalDigits, excluding all occurrences of NumericLiteralSeparator and e is the MV of ExponentPart.
- Математическое значение из DecimalLiteral :: . DecimalDigits is the MV of DecimalDigits × 10—n, where n is the number of code points in DecimalDigits, excluding all occurrences of NumericLiteralSeparator.
- Математическое значение из DecimalLiteral :: . DecimalDigits ExponentPart is the MV of DecimalDigits × 10e — n, where n is the number of code points in DecimalDigits, excluding all occurrences of NumericLiteralSeparator, and e is the MV of ExponentPart.
- Математическое значение из DecimalLiteral :: DecimalIntegerLiteral is the MV of DecimalIntegerLiteral.
- Математическое значение из DecimalLiteral :: DecimalIntegerLiteral ExponentPart is the MV of DecimalIntegerLiteral × 10e, where e is the MV of ExponentPart.
- Математическое значение из DecimalIntegerLiteral :: 0 is 0.
- Математическое значение из DecimalIntegerLiteral :: NonZeroDigit is the MV of NonZeroDigit.
- Математическое значение из DecimalIntegerLiteral :: NonZeroDigit NumericLiteralSeparatoropt DecimalDigits is (the MV of NonZeroDigit × 10n) plus the MV of DecimalDigits, where n is the number of code points in DecimalDigits, excluding all occurrences of NumericLiteralSeparator.
- Математическое значение из DecimalDigits :: DecimalDigit is the MV of DecimalDigit.
- Математическое значение из DecimalDigits :: DecimalDigits DecimalDigit is (the MV of DecimalDigits × 10) plus the MV of DecimalDigit.
- Математическое значение из DecimalDigits :: DecimalDigits NumericLiteralSeparator DecimalDigit is (the MV of DecimalDigits × 10) plus the MV of DecimalDigit.
- Математическое значение из ExponentPart :: ExponentIndicator SignedInteger is the MV of SignedInteger.
- Математическое значение из SignedInteger :: DecimalDigits is the MV of DecimalDigits.
- Математическое значение из SignedInteger :: + DecimalDigits is the MV of DecimalDigits.
- Математическое значение из SignedInteger :: — DecimalDigits is the negative of the MV of DecimalDigits.
- Математическое значение из DecimalDigit :: 0 or of HexDigit :: 0 or of OctalDigit :: 0 or of LegacyOctalEscapeSequence :: 0 or of BinaryDigit :: 0 is 0.
- Математическое значение из DecimalDigit :: 1 or of NonZeroDigit :: 1 or of HexDigit :: 1 or of OctalDigit :: 1 or of BinaryDigit :: 1 is 1.
- Математическое значение из DecimalDigit :: 2 or of NonZeroDigit :: 2 or of HexDigit :: 2 or of OctalDigit :: 2 is 2.
- Математическое значение из DecimalDigit :: 3 or of NonZeroDigit :: 3 or of HexDigit :: 3 or of OctalDigit :: 3 is 3.
- Математическое значение из DecimalDigit :: 4 or of NonZeroDigit :: 4 or of HexDigit :: 4 or of OctalDigit :: 4 is 4.
- Математическое значение из DecimalDigit :: 5 or of NonZeroDigit :: 5 or of HexDigit :: 5 or of OctalDigit :: 5 is 5.
- Математическое значение из DecimalDigit :: 6 or of NonZeroDigit :: 6 or of HexDigit :: 6 or of OctalDigit :: 6 is 6.
- Математическое значение из DecimalDigit :: 7 or of NonZeroDigit :: 7 or of HexDigit :: 7 or of OctalDigit :: 7 is 7.
- Математическое значение из DecimalDigit :: 8 or of NonZeroDigit :: 8 or of NonOctalDigit :: 8 or of HexDigit :: 8 is 8.
- Математическое значение из DecimalDigit :: 9 or of NonZeroDigit :: 9 or of NonOctalDigit :: 9 or of HexDigit :: 9 is 9.
- Математическое значение из HexDigit :: a or of HexDigit :: A is 10.
- Математическое значение из HexDigit :: b or of HexDigit :: B is 11.
- Математическое значение из HexDigit :: c or of HexDigit :: C is 12.
- Математическое значение из HexDigit :: d or of HexDigit :: D is 13.
- Математическое значение из HexDigit :: e or of HexDigit :: E is 14.
- Математическое значение из HexDigit :: f or of HexDigit :: F is 15.
- Математическое значение из BinaryIntegerLiteral :: 0b BinaryDigits is the MV of BinaryDigits.
- Математическое значение из BinaryIntegerLiteral :: 0B BinaryDigits is the MV of BinaryDigits.
- Математическое значение из BinaryDigits :: BinaryDigit is the MV of BinaryDigit.
- Математическое значение из BinaryDigits :: BinaryDigits BinaryDigit is (the MV of BinaryDigits × 2) plus the MV of BinaryDigit.
- Математическое значение из BinaryDigits :: BinaryDigits NumericLiteralSeparator BinaryDigit is (the MV of BinaryDigits × 2) plus the MV of BinaryDigit.
- Математическое значение из OctalIntegerLiteral :: 0o OctalDigits is the MV of OctalDigits.
- Математическое значение из OctalIntegerLiteral :: 0O OctalDigits is the MV of OctalDigits.
- Математическое значение из OctalDigits :: OctalDigit is the MV of OctalDigit.
- Математическое значение из OctalDigits :: OctalDigits OctalDigit is (the MV of OctalDigits × 8) plus the MV of OctalDigit.
- Математическое значение из OctalDigits :: OctalDigits NumericLiteralSeparator OctalDigit is (the MV of OctalDigits × 8) plus the MV of OctalDigit.
- Математическое значение из LegacyOctalIntegerLiteral :: 0 OctalDigit is the MV of OctalDigit.
- Математическое значение из LegacyOctalIntegerLiteral :: LegacyOctalIntegerLiteral OctalDigit is (the MV of LegacyOctalIntegerLiteral times 8) plus the MV of OctalDigit.
- Математическое значение из NonOctalDecimalIntegerLiteral :: 0 NonOctalDigit is the MV of NonOctalDigit.
- Математическое значение из NonOctalDecimalIntegerLiteral :: LegacyOctalLikeDecimalIntegerLiteral NonOctalDigit is (the MV of LegacyOctalLikeDecimalIntegerLiteral times 10) plus the MV of NonOctalDigit.
- Математическое значение из NonOctalDecimalIntegerLiteral :: NonOctalDecimalIntegerLiteral DecimalDigit is (the MV of NonOctalDecimalIntegerLiteral times 10) plus the MV of DecimalDigit.
- Математическое значение из LegacyOctalLikeDecimalIntegerLiteral :: 0 OctalDigit is the MV of OctalDigit.
- Математическое значение из LegacyOctalLikeDecimalIntegerLiteral :: LegacyOctalLikeDecimalIntegerLiteral OctalDigit is (the MV of LegacyOctalLikeDecimalIntegerLiteral times 10) plus the MV of OctalDigit.
- Математическое значение из HexIntegerLiteral :: 0x HexDigits is the MV of HexDigits.
- Математическое значение из HexIntegerLiteral :: 0X HexDigits is the MV of HexDigits.
- Математическое значение из HexDigits :: HexDigit is the MV of HexDigit.
- Математическое значение из HexDigits :: HexDigits HexDigit is (the MV of HexDigits × 16) plus the MV of HexDigit.
- Математическое значение из HexDigits :: HexDigits NumericLiteralSeparator HexDigit is (the MV of HexDigits × 16) plus the MV of HexDigit.
12.8.3.3 Статическая семантика: Числовое значение (NumericValue)
NumericLiteral :: DecimalLiteral
RoundMVResult(MV of DecimalLiteral).
NumericLiteral :: NonDecimalIntegerLiteral
𝔽(MV of NonDecimalIntegerLiteral).
NumericLiteral :: LegacyOctalIntegerLiteral
𝔽(MV of LegacyOctalIntegerLiteral).
NumericLiteral :: NonDecimalIntegerLiteral BigIntLiteralSuffix
the BigInt value that represents the MV ofDecimalBigIntegerLiteral :: 0 BigIntLiteralSuffix
0ℤ.
DecimalBigIntegerLiteral :: NonZeroDigit BigIntLiteralSuffix
the BigInt value that represents the MV ofDecimalBigIntegerLiteral ::NonZeroDigit DecimalDigits BigIntLiteralSuffixNonZeroDigit NumericLiteralSeparator DecimalDigits BigIntLiteralSuffix
DecimalDigits, excluding all occurrences of NumericLiteralSeparator.
Let n be the number of code points inNonZeroDigit × 10n) plus the MV of DecimalDigits.
Let mv be (the MV ofℤ(mv).
Return
12.8.4 Строковые литералы
Строковый литерал — это 0 или более кодовых точек Unicode, заключенных в одинарные или двойные кавычки. Кодовые точки Unicode также могут быть представлены escape-последовательностью. Все кодовые точки могут появляться буквально в строковом литерале, за исключением кодовых точек закрывающей кавычки, U+005C (REVERSE SOLIDUS), U+000D (CARRIAGE RETURN) и U+000A (LINE FEED). Любые кодовые точки могут появляться в виде escape-последовательности. Строковые литералы оцениваются как строковые значения ECMAScript. При генерации этих строковых значений кодовые точки Unicode кодируются в кодировке UTF-16, как определено в разделе 11.1.1. Кодовые точки, принадлежащие базовой многоязычной плоскости, кодируются как один элемент кодовой единицы строки. Все остальные кодовые точки кодируются как два элемента кодовой единицы строки.
Синтаксис строкового литерала
"
DoubleStringCharacters opt "
'
SingleStringCharacters opt '
DoubleStringCharacter DoubleStringCharacters opt
SingleStringCharacter SingleStringCharacters opt
SourceCharacter но не один из « или \ или LineTerminator
<LS>
<PS>
SourceCharacter но не один из ‘ или \ или LineTerminator
<LS>
<PS>
0 [lookahead ∉ DecimalDigit]
SingleEscapeCharacter :: один из
‘ » \ b f n r t v
SourceCharacter но не один из EscapeCharacter или LineTerminator
x
u
0 [lookahead ∈ { 8, 9 }]
NonZeroOctalDigit [lookahead ∉ OctalDigit]
ZeroToThree OctalDigit [lookahead ∉ OctalDigit]
ZeroToThree OctalDigit OctalDigit
OctalDigit но не 0
ZeroToThree :: один из
0 1 2 3
FourToSeven :: один из
4 5 6 7
NonOctalDecimalEscapeSequence :: один из
8 9
u{ CodePoint }
Hex4Digits ::
HexDigit HexDigit HexDigit HexDigit
Определение нетерминального HexDigit дано в разделе 12.8.3. SourceCharacter определен в разделе 11.1.
<LF> и <CR> не могут появляться в строковом литерале, кроме как как часть LineContinuation для создания пустой последовательности кодовых точек. Правильный способ включить любое из значений String строкового литерала — использовать escape-последовательность, например \n или \u000A.
12.8.4.1 Статическая семантика: Ранние Ошибки
EscapeSequence :: LegacyOctalEscapeSequence
EscapeSequence :: NonOctalDecimalEscapeSequence
- Это синтаксическая ошибка, если исходный код, соответствующий этому продукту, является кодом строгого режима.
В нестрогом коде это синтаксис Legacy.
Строковые литералы могут предшествовать директиве Use Strict, которая переводит включающий код в строгий режим, и реализации должны позаботиться о соблюдении вышеуказанных правил для таких литералов. Например, следующий исходный текст содержит синтаксическую ошибку:
function invalid() { "\7"; "use strict"; }
12.8.4.2 Статическая семантика: Строковые значения. SV — String values
Строковый литерал обозначает значение типа String. SV создаёт строковые значения (String Values) для строковых литералов посредством рекурсивного применения к различным частям строкового литерала. В рамках этого процесса некоторые кодовые точки Unicode в строковом литерале интерпретируются как имеющие математическое значение, как описано ниже или в разделе 12.8.3.
- The SV of StringLiteral :: » » is the empty String.
- The SV of StringLiteral :: ‘ ‘ is the empty String.
- The SV of DoubleStringCharacters :: DoubleStringCharacter DoubleStringCharacters is the string-concatenation of the SV of DoubleStringCharacter and the SV of DoubleStringCharacters.
- The SV of SingleStringCharacters :: SingleStringCharacter SingleStringCharacters is the string-concatenation of the SV of SingleStringCharacter and the SV of SingleStringCharacters.
- The SV of DoubleStringCharacter :: SourceCharacter but not one of » or \ or LineTerminator is the result of performing UTF16EncodeCodePoint on the code point value of SourceCharacter.
- The SV of DoubleStringCharacter :: <LS> is the String value consisting of the code unit 0x2028 (LINE SEPARATOR).
- The SV of DoubleStringCharacter :: <PS> is the String value consisting of the code unit 0x2029 (PARAGRAPH SEPARATOR).
- The SV of DoubleStringCharacter :: LineContinuation is the empty String.
- The SV of SingleStringCharacter :: SourceCharacter but not one of ‘ or \ or LineTerminator is the result of performing UTF16EncodeCodePoint on the code point value of SourceCharacter.
- The SV of SingleStringCharacter :: <LS> is the String value consisting of the code unit 0x2028 (LINE SEPARATOR).
- The SV of SingleStringCharacter :: <PS> is the String value consisting of the code unit 0x2029 (PARAGRAPH SEPARATOR).
- The SV of SingleStringCharacter :: LineContinuation is the empty String.
- The SV of EscapeSequence :: 0 is the String value consisting of the code unit 0x0000 (NULL).
- The SV of CharacterEscapeSequence :: SingleEscapeCharacter is the String value consisting of the code unit whose value is determined by the SingleEscapeCharacter according to Table 40.
Escape Sequence (Последовательность побега) | Code Unit Value ( Значение Кодовой Единицы) | Unicode Character Name (Имя символа Юникода) | Symbol (Символ) |
---|---|---|---|
\b | 0x0008 | BACKSPACE | <BS> |
\t | 0x0009 | CHARACTER TABULATION | <HT> |
\n | 0x000A | LINE FEED (LF) | <LF> |
\v | 0x000B | LINE TABULATION | <VT> |
\f | 0x000C | FORM FEED (FF) | <FF> |
\r | 0x000D | CARRIAGE RETURN (CR) | <CR> |
\» | 0x0022 | QUOTATION MARK | « |
\’ | 0x0027 | APOSTROPHE | ‘ |
\\ | 0x005C | REVERSE SOLIDUS | \ |
Таблица 40: Последовательности перехода из одного символа в строку
- The SV of NonEscapeCharacter :: SourceCharacter but not one of EscapeCharacter or LineTerminator is the result of performing UTF16EncodeCodePoint on the code point value of SourceCharacter.
- The SV of EscapeSequence :: LegacyOctalEscapeSequence is the String value consisting of the code unit whose value is the MV of LegacyOctalEscapeSequence.
- The SV of NonOctalDecimalEscapeSequence :: 8 is the String value consisting of the code unit 0x0038 (DIGIT EIGHT).
- The SV of NonOctalDecimalEscapeSequence :: 9 is the String value consisting of the code unit 0x0039 (DIGIT NINE).
- The SV of HexEscapeSequence :: x HexDigit HexDigit is the String value consisting of the code unit whose value is the MV of HexEscapeSequence.
- The SV of Hex4Digits :: HexDigit HexDigit HexDigit HexDigit is the String value consisting of the code unit whose value is the MV of Hex4Digits.
- The SV of UnicodeEscapeSequence :: u{ CodePoint } is the result of performing UTF16EncodeCodePoint on the MV of CodePoint.
- The SV of TemplateEscapeSequence :: 0 is the String value consisting of the code unit 0x0000 (NULL).
12.8.4.3 Статическая семантика: MV
- The MV of LegacyOctalEscapeSequence :: ZeroToThree OctalDigit is (8 times the MV of ZeroToThree) plus the MV of OctalDigit.
- The MV of LegacyOctalEscapeSequence :: FourToSeven OctalDigit is (8 times the MV of FourToSeven) plus the MV of OctalDigit.
- The MV of LegacyOctalEscapeSequence :: ZeroToThree OctalDigit OctalDigit is (64 (that is, 82) times the MV of ZeroToThree) plus (8 times the MV of the first OctalDigit) plus the MV of the second OctalDigit.
- The MV of ZeroToThree :: 0 is 0.
- The MV of ZeroToThree :: 1 is 1.
- The MV of ZeroToThree :: 2 is 2.
- The MV of ZeroToThree :: 3 is 3.
- The MV of FourToSeven :: 4 is 4.
- The MV of FourToSeven :: 5 is 5.
- The MV of FourToSeven :: 6 is 6.
- The MV of FourToSeven :: 7 is 7.
- The MV of HexEscapeSequence :: x HexDigit HexDigit is (16 times the MV of the first HexDigit) plus the MV of the second HexDigit.
- The MV of Hex4Digits :: HexDigit HexDigit HexDigit HexDigit is (0x1000 × the MV of the first HexDigit) plus (0x100 × the MV of the second HexDigit) plus (0x10 × the MV of the third HexDigit) plus the MV of the fourth HexDigit.
12.8.5 Литералы регулярных выражений
Примечание 1
Литерал регулярного выражения — это входной элемент, который преобразуется в объект RegExp (смотри раздел 22.2) каждый раз, когда вычисляется литерал. Два литерала регулярного выражения в программе оценивают объекты регулярного выражения, которые никогда не сравниваются как === друг с другом, даже если содержимое двух литералов идентично. Объект RegExp также может быть создан во время выполнения с помощью new RegExp
или вызова конструктора RegExp как функции (смотри раздел 22.2.3).
Приведенные ниже инструкции описывают синтаксис литерала регулярного выражения и используются сканером входных элементов для поиска конца литерала регулярного выражения. Исходный текст, содержащий RegularExpressionBody и RegularExpressionFlags, впоследствии снова анализируется с использованием более строгой грамматики регулярных выражений ECMAScript (22.2.1).
Реализация может расширять грамматику регулярных выражений ECMAScript, определенную в 22.2.1, но она не должна расширять продукты RegularExpressionBody и RegularExpressionFlags, определенные ниже, или продукты, используемые этими продуктами.
Синтаксис литерала регулярного выражения
/ RegularExpressionBody / RegularExpressionFlags
RegularExpressionFirstChar RegularExpressionChars
[empty]
RegularExpressionChars RegularExpressionChar
RegularExpressionNonTerminator но не одно из * или \ или / или [
RegularExpressionBackslashSequence
RegularExpressionNonTerminator но не одно из \ или / или [
RegularExpressionBackslashSequence
RegularExpressionBackslashSequence ::
\ RegularExpressionNonTerminator
RegularExpressionNonTerminator ::
SourceCharacter но не LineTerminator
[ RegularExpressionClassChars ]
RegularExpressionClassChars ::
[empty]
RegularExpressionClassChars RegularExpressionClassChar
RegularExpressionNonTerminator но не один из ] или \
RegularExpressionBackslashSequence
[empty]
RegularExpressionFlags IdentifierPart
Литералы регулярных выражений не могут быть пустыми; вместо представления пустого литерала регулярного выражения последовательность кодовых единиц // начинает однострочный комментарий. Чтобы указать пустое регулярное выражение, используйте: /(?:)/.
12.8.5.1 Статическая семантика: ранние ошибки
RegularExpressionFlags :: RegularExpressionFlags IdentifierPart
- Это синтаксическая ошибка, если IdentifierPart содержит escape-последовательность Unicode.
12.8.5.2 Статическая семантика: BodyText
RegularExpressionLiteral :: / RegularExpressionBody / RegularExpressionFlags
1. Верните исходный текст, который был распознан как RegularExpressionBody.
12.8.5.3 Статическая семантика: FlagText
RegularExpressionLiteral :: / RegularExpressionBody / RegularExpressionFlags
1. Верните исходный текст, который был распознан как RegularExpressionFlags.
12.8.6 Лексические компоненты литерала Шаблона
Синтаксис
Template ::
` TemplateCharacters opt `
TemplateHead ::
` TemplateCharacters opt ${
} TemplateCharacters opt ${
TemplateTail ::
} TemplateCharacters opt `
TemplateCharacter TemplateCharacters opt
$ [lookahead ≠ {]
SourceCharacter но не один из ` или \ или $ или LineTerminator
0 [lookahead ∉ DecimalDigit]
DecimalDigit но не 0
x [ lookahead ∉ HexDigit ]
x HexDigit [ lookahead ∉ HexDigit ]
u [ lookahead ∉ HexDigit ] [ lookahead ≠ { ]
u HexDigit [ lookahead ∉ HexDigit ]
u HexDigit HexDigit [ lookahead ∉ HexDigit ]
u HexDigit HexDigit HexDigit [ lookahead ∉ HexDigit ]
u { [ lookahead ∉ HexDigit ]
u { NotCodePoint [ lookahead ∉ HexDigit ]
u { CodePoint [ lookahead ∉ HexDigit ] [ lookahead ≠ } ]
NotCodePoint ::
HexDigits [~Sep] но только если математическое значение из HexDigits > 0x10FFFF
CodePoint ::
HexDigits [~Sep] но только если математическое значение из HexDigits ≤ 0x10FFFF
TemplateSubstitutionTail используется альтернативной лексической целью InputElementTemplateTail.
12.8.6.1 Статическая семантика: Шаблонное Значение. TV — Template Value
Компонент литерала шаблона интерпретируется шаблонным значением (TV- Template Value) как значение типа String. TV используется для создания индексированных компонентов объекта шаблона (в просторечии значений шаблона). На телевидении escape-последовательности заменяются кодовыми единицами UTF-16 кодовой точки Unicode, представленной escape-последовательностью.
- Значение Шаблона из NoSubstitutionTemplate :: ` ` является пустой строкой String.
- Значение Шаблона из TemplateHead :: ` ${ является пустой строкой String.
- Значение Шаблона из TemplateMiddle :: } ${ является пустой строкой String.
- Значение Шаблона из TemplateTail :: } ` является пустой строкой String.
- Значение Шаблона из TemplateCharacters :: TemplateCharacter TemplateCharacters является undefined, если либо Значение Шаблона из TemplateCharacter является undefined или Значение Шаблона из TemplateCharacters является undefined. В противном случае это является конкатенацией строк Значения Шаблона из TemplateCharacter и Значения Шаблона из TemplateCharacters.
- Значение Шаблона из TemplateCharacter :: SourceCharacter но не один из ` или \ или $ или LineTerminator является результатом выполнения UTF16EncodeCodePoint для значения кодовой точки из SourceCharacter.
- Значение Шаблона из TemplateCharacter :: $ является строковым значением, состоящим из кодовой единицы 0x0024 (DOLLAR SIGN — ЗНАК ДОЛЛАРА).
- Значение Шаблона из TemplateCharacter :: \ TemplateEscapeSequence является SV (String values) из TemplateEscapeSequence.
- Значение Шаблона из TemplateCharacter :: \ NotEscapeSequence является undefined.
- Значение Шаблона из TemplateCharacter :: LineTerminatorSequence является TRV (template raw values) из LineTerminatorSequence.
- Значение Шаблона из LineContinuation :: \ LineTerminatorSequence является пустой строкой String.
12.8.6.2 Статическая семантика: Исходные Значения Шаблона. TRV — template raw values
Компонент литерала шаблона интерпретируется TRV как значение типа String. TRV используется для создания необработанных компонентов объекта-шаблона (в просторечии — необработанных значений шаблона). TRV похож на TV с той разницей, что в TRV escape-последовательности интерпретируются так, как они появляются в литерале.
- The TRV of NoSubstitutionTemplate :: ` ` is the empty String.
- The TRV of TemplateHead :: ` ${ is the empty String.
- The TRV of TemplateMiddle :: } ${ is the empty String.
- The TRV of TemplateTail :: } ` is the empty String.
- The TRV of TemplateCharacters :: TemplateCharacter TemplateCharacters is the string-concatenation of the TRV of TemplateCharacter and the TRV of TemplateCharacters.
- The TRV of TemplateCharacter :: SourceCharacter but not one of ` or \ or $ or LineTerminator is the result of performing UTF16EncodeCodePoint on the code point value of SourceCharacter.
- The TRV of TemplateCharacter :: $ is the String value consisting of the code unit 0x0024 (DOLLAR SIGN).
- The TRV of TemplateCharacter :: \ TemplateEscapeSequence is the string-concatenation of the code unit 0x005C (REVERSE SOLIDUS) and the TRV of TemplateEscapeSequence.
- The TRV of TemplateCharacter :: \ NotEscapeSequence is the string-concatenation of the code unit 0x005C (REVERSE SOLIDUS) and the TRV of NotEscapeSequence.
- The TRV of TemplateEscapeSequence :: 0 is the String value consisting of the code unit 0x0030 (DIGIT ZERO).
- The TRV of NotEscapeSequence :: 0 DecimalDigit is the string-concatenation of the code unit 0x0030 (DIGIT ZERO) and the TRV of DecimalDigit.
- The TRV of NotEscapeSequence :: x [lookahead ∉ HexDigit] is the String value consisting of the code unit 0x0078 (LATIN SMALL LETTER X).
- The TRV of NotEscapeSequence :: x HexDigit [lookahead ∉ HexDigit] is the string-concatenation of the code unit 0x0078 (LATIN SMALL LETTER X) and the TRV of HexDigit.
- The TRV of NotEscapeSequence :: u [lookahead ∉ HexDigit] [lookahead ≠ {] is the String value consisting of the code unit 0x0075 (LATIN SMALL LETTER U).
- The TRV of NotEscapeSequence :: u HexDigit [lookahead ∉ HexDigit] is the string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U) and the TRV of HexDigit.
- The TRV of NotEscapeSequence :: u HexDigit HexDigit [lookahead ∉ HexDigit] is the string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U), the TRV of the first HexDigit, and the TRV of the second HexDigit.
- The TRV of NotEscapeSequence :: u HexDigit HexDigit HexDigit [lookahead ∉ HexDigit] is the string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U), the TRV of the first HexDigit, the TRV of the second HexDigit, and the TRV of the third HexDigit.
- The TRV of NotEscapeSequence :: u { [lookahead ∉ HexDigit] is the string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U) and the code unit 0x007B (LEFT CURLY BRACKET).
- The TRV of NotEscapeSequence :: u { NotCodePoint [lookahead ∉ HexDigit] is the string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U), the code unit 0x007B (LEFT CURLY BRACKET), and the TRV of NotCodePoint.
- The TRV of NotEscapeSequence :: u { CodePoint [lookahead ∉ HexDigit] [lookahead ≠ }] is the string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U), the code unit 0x007B (LEFT CURLY BRACKET), and the TRV of CodePoint.
- The TRV of DecimalDigit :: one of 0 1 2 3 4 5 6 7 8 9 is the result of performing UTF16EncodeCodePoint on the single code point matched by this production.
- The TRV of CharacterEscapeSequence :: NonEscapeCharacter is the SV of NonEscapeCharacter.
- The TRV of SingleEscapeCharacter :: one of ‘ » \ b f n r t v is the result of performing UTF16EncodeCodePoint on the single code point matched by this production.
- The TRV of HexEscapeSequence :: x HexDigit HexDigit is the string-concatenation of the code unit 0x0078 (LATIN SMALL LETTER X), the TRV of the first HexDigit, and the TRV of the second HexDigit.
- The TRV of UnicodeEscapeSequence :: u Hex4Digits is the string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U) and the TRV of Hex4Digits.
- The TRV of UnicodeEscapeSequence :: u{ CodePoint } is the string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U), the code unit 0x007B (LEFT CURLY BRACKET), the TRV of CodePoint, and the code unit 0x007D (RIGHT CURLY BRACKET).
- The TRV of Hex4Digits :: HexDigit HexDigit HexDigit HexDigit is the string-concatenation of the TRV of the first HexDigit, the TRV of the second HexDigit, the TRV of the third HexDigit, and the TRV of the fourth HexDigit.
- The TRV of HexDigits :: HexDigits HexDigit is the string-concatenation of the TRV of HexDigits and the TRV of HexDigit.
- The TRV of HexDigit :: one of 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F is the result of performing UTF16EncodeCodePoint on the single code point matched by this production.
- The TRV of LineContinuation :: \ LineTerminatorSequence is the string-concatenation of the code unit 0x005C (REVERSE SOLIDUS) and the TRV of LineTerminatorSequence.
- The TRV of LineTerminatorSequence :: <LF> is the String value consisting of the code unit 0x000A (LINE FEED).
- The TRV of LineTerminatorSequence :: <CR> is the String value consisting of the code unit 0x000A (LINE FEED).
- The TRV of LineTerminatorSequence :: <LS> is the String value consisting of the code unit 0x2028 (LINE SEPARATOR).
- The TRV of LineTerminatorSequence :: <PS> is the String value consisting of the code unit 0x2029 (PARAGRAPH SEPARATOR).
- The TRV of LineTerminatorSequence :: <CR> <LF> is the String value consisting of the code unit 0x000A (LINE FEED).
TV (template value) исключает кодовые единицы LineContinuation, в то время как TRV (template raw value) включает их. <CR><LF> и <CR>LineTerminatorSequence нормализованы до <LF> как для TV, так и для TRV. Явная последовательность TemplateEscapeSequence необходима для включения последовательности <CR> или <CR><LF>.
Информационные ссылки
ECMAScript | Язык ECMAScript: лексическая грамматика
Стандарт ECMAScript — Раздел «12.8 Literals» — https://tc39.es/ecma262/#sec-ecmascript-language-lexical-grammar-literals