ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 25

 

  Главная      Manuals     ECMA-262 (12th Edition) ECMAScript 2021 Language Specification

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     23      24      25      26     ..

 

 

 

ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 25

 

 

SingleEscapeCharacter
DecimalDigit

x

u

HexEscapeSequence

 

::

x

 

HexDigit

 

HexDigit

UnicodeEscapeSequence

 

::

u

 

Hex4Digits

u{

 

CodePoint

 

}

Hex4Digits

 

::

HexDigit

 

HexDigit

 

HexDigit

 

HexDigit

The definition of the nonterminal 

HexDigit

 is given in 

12.8.3

SourceCharacter

 is defined in 

11.1

.

NOTE 2

A string literal stands for a value of the String type. The String value (SV) of the literal is described in terms of String
values contributed by the various parts of the string literal. As part of this process, some Unicode code points within
the string literal are interpreted as having a 

mathematical value

 (MV), as described below or in 

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).

<LF> and <CR> cannot appear in a string literal, except as part of a 

LineContinuation

 to produce

the empty code points sequence. The proper way to include either in the String value of a string
literal is to use an escape sequence such as 

\n

\n

 or 

\u000A

\u000A

.

12.8.4.1  Static Semantics: SV

291

The SV of 

CharacterEscapeSequence

 

::

 

SingleEscapeCharacter

 is the String value consisting of the code unit

whose value is determined by the 

SingleEscapeCharacter

 according to 

Table 36

.

Table 36: String Single Character Escape Sequences

Escape Sequence Code Unit Value

Unicode Character Name

Symbol

\b

\b

0x0008

0x0008

BACKSPACE

<BS>

\t

\t

0x0009

0x0009

CHARACTER TABULATION <HT>

\n

\n

0x000A

0x000A

LINE FEED (LF)

<LF>

\v

\v

0x000B

0x000B

LINE TABULATION

<VT>

\f

\f

0x000C

0x000C

FORM FEED (FF)

<FF>

\r

\r

0x000D

0x000D

CARRIAGE RETURN (CR)

<CR>

\"

\"

0x0022

0x0022

QUOTATION MARK

""

\'

\'

0x0027

0x0027

APOSTROPHE

''

\\

\\

0x005C

0x005C

REVERSE SOLIDUS

\\

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 

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 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

.

NOTE 1

A regular expression literal is an input element that is converted to a RegExp object (see 

22.2

)

each time the literal is evaluated. Two regular expression literals in a program evaluate to regular
expression objects that never compare as 

===

===

 to each other even if the two literals' contents are

identical. A RegExp object may also be created at runtime by 

new RegExp

new RegExp

 or calling the

RegExp 

constructor

 as a function (see 

22.2.3

).

12.8.4.2  Static Semantics: MV

12.8.5  Regular Expression Literals

292

The productions below describe the syntax for a regular expression literal and are used by the input element scanner
to find the end of the regular expression literal. The source text comprising the 

RegularExpressionBody

 and the 

RegularExpressionFlags

 are subsequently parsed again using the more stringent ECMAScript Regular Expression

grammar (

22.2.1

).

An implementation may extend the ECMAScript Regular Expression grammar defined in 

22.2.1

, but it must not

extend the 

RegularExpressionBody

 and 

RegularExpressionFlags

 productions defined below or the productions used by

these productions.

RegularExpressionLiteral

 

::

/

 

RegularExpressionBody

 

/

 

RegularExpressionFlags

RegularExpressionBody

 

::

RegularExpressionFirstChar

 

RegularExpressionChars

RegularExpressionChars

 

::

[empty]

RegularExpressionChars

 

RegularExpressionChar

RegularExpressionFirstChar

 

::

RegularExpressionNonTerminator

 but not one of 

*

 or 

\

 or 

/

 or 

[

RegularExpressionBackslashSequence
RegularExpressionClass

RegularExpressionChar

 

::

RegularExpressionNonTerminator

 but not one of 

\

 or 

/

 or 

[

RegularExpressionBackslashSequence
RegularExpressionClass

RegularExpressionBackslashSequence

 

::

\

 

RegularExpressionNonTerminator

RegularExpressionNonTerminator

 

::

SourceCharacter

 but not 

LineTerminator

RegularExpressionClass

 

::

[

 

RegularExpressionClassChars

 

]

RegularExpressionClassChars

 

::

[empty]

RegularExpressionClassChars

 

RegularExpressionClassChar

RegularExpressionClassChar

 

::

RegularExpressionNonTerminator

 but not one of 

]

 or 

\

RegularExpressionBackslashSequence

RegularExpressionFlags

 

::

[empty]

Syntax

293

RegularExpressionFlags

 

IdentifierPart

NOTE 2

RegularExpressionFlags

 

::

 

RegularExpressionFlags

 

IdentifierPart

It is a Syntax Error if 

IdentifierPart

 contains a Unicode escape sequence.

RegularExpressionLiteral

 

::

 

/

 

RegularExpressionBody

 

/

 

RegularExpressionFlags

1.  Return the source text that was recognized as 

RegularExpressionBody

.

RegularExpressionLiteral

 

::

 

/

 

RegularExpressionBody

 

/

 

RegularExpressionFlags

1.  Return the source text that was recognized as 

RegularExpressionFlags

.

Template

 

::

NoSubstitutionTemplate
TemplateHead

NoSubstitutionTemplate

 

::

`

 

TemplateCharacters

opt

 

`

TemplateHead

 

::

`

 

TemplateCharacters

opt

 

${

TemplateSubstitutionTail

 

::

TemplateMiddle
TemplateTail

TemplateMiddle

 

::

}

 

TemplateCharacters

opt

 

${

TemplateTail

 

::

}

 

TemplateCharacters

opt

 

`

TemplateCharacters

 

::

TemplateCharacter

 

TemplateCharacters

opt

Regular expression literals may not be empty; instead of representing an empty regular
expression literal, the code unit sequence 

//

//

 starts a single-line comment. To specify an empty

regular expression, use: 

/(?:)/

/(?:)/

.

12.8.5.1  Static Semantics: Early Errors

12.8.5.2  Static Semantics: BodyText

12.8.5.3  Static Semantics: FlagText

12.8.6  Template Literal Lexical Components

Syntax

294

TemplateCharacter

 

::

$

 [lookahead 

 

{

]

\

 

EscapeSequence

\

 

NotEscapeSequence

LineContinuation
LineTerminatorSequence
SourceCharacter

 but not one of 

`

 or 

\

 or 

$

 or 

LineTerminator

NotEscapeSequence

 

::

0

 

DecimalDigit

DecimalDigit

 but not 

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]

 but only if MV of 

HexDigits

 > 0x10FFFF

CodePoint

 

::

HexDigits

[~Sep]

 but only if MV of 

HexDigits

 

 0x10FFFF

A conforming implementation must not use the extended definition of 

EscapeSequence

 described in 

B.1.2

 when parsing

TemplateCharacter

.

NOTE

A template literal component is interpreted as a sequence of Unicode code points. The Template Value (TV) of a literal
component is described in terms of String values (

SV

12.8.4

) contributed by the various parts of the template literal

component. As part of this process, some Unicode code points within the template component are interpreted as
having a 

mathematical value

 (MV

12.8.3

). In determining a TV, escape sequences are replaced by the UTF-16 code

unit(s) of the Unicode code point represented by the escape sequence. The Template Raw Value (TRV) is similar to a
Template Value with the difference that in TRVs escape sequences are interpreted literally.

The TV and TRV of 

NoSubstitutionTemplate

 

::

 

`

 

`

 is the empty String.

The TV and TRV of 

TemplateHead

 

::

 

`

 

${

 is the empty String.

The TV and TRV of 

TemplateMiddle

 

::

 

}

 

${

 is the empty String.

The TV and TRV of 

TemplateTail

 

::

 

}

 

`

 is the empty String.

The TV of 

TemplateCharacters

 

::

 

TemplateCharacter

 

TemplateCharacters

 is 

undefined

 if either the TV of 

TemplateCharacter

 is 

undefined

 or the TV of 

TemplateCharacters

 is 

undefined

. Otherwise, it is the 

string-

TemplateSubstitutionTail

 is used by the 

InputElementTemplateTail

 alternative lexical goal.

12.8.6.1  Static Semantics: TV and TRV

295

concatenation

 of the TV of 

TemplateCharacter

 and the TV of 

TemplateCharacters

.

The TV 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 TV of 

TemplateCharacter

 

::

 

$

 is the String value consisting of the code unit 0x0024 (DOLLAR SIGN).

The TV of 

TemplateCharacter

 

::

 

\

 

EscapeSequence

 is the 

SV

 of 

EscapeSequence

.

The TV of 

TemplateCharacter

 

::

 

\

 

NotEscapeSequence

 is 

undefined

.

The TV of 

TemplateCharacter

 

::

 

LineTerminatorSequence

 is the TRV of 

LineTerminatorSequence

.

The TV of 

LineContinuation

 

::

 

\

 

LineTerminatorSequence

 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

 

::

 

\

 

EscapeSequence

 is the 

string-concatenation

 of the code unit 0x005C

(REVERSE SOLIDUS) and the TRV of 

EscapeSequence

.

The TRV of 

TemplateCharacter

 

::

 

\

 

NotEscapeSequence

 is the 

string-concatenation

 of the code unit 0x005C

(REVERSE SOLIDUS) and the TRV of 

NotEscapeSequence

.

The TRV of 

EscapeSequence

 

::

 

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

296

(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 thir

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).

NOTE

Most ECMAScript statements and declarations must be terminated with a semicolon. Such semicolons may always
appear explicitly in the source text. For convenience, however, such semicolons may be omitted from the source text in
certain situations. These situations are described by saying that semicolons are automatically inserted into the source
code token stream in those situations.

In the following rules, “token” means the actual recognized lexical token determined using the current lexical 

goal

symbol

 as described in clause 

12

.

There are three basic rules of semicolon insertion:

1.  When, as the source text is parsed from left to right, a token (called the 

offending token

) is encountered that is

not allowed by any production of the grammar, then a semicolon is automatically inserted before the offending
token if one or more of the following conditions is true:

TV excludes the code units of 

LineContinuation

 while TRV includes them. <CR><LF> and <CR> 

LineTerminatorSequence

s are normalized to <LF> for both TV and TRV. An explicit 

EscapeSequence

is needed to include a <CR> or <CR><LF> sequence.

12.9  Automatic Semicolon Insertion

12.9.1  Rules of Automatic Semicolon Insertion

297

The offending token is separated from the previous token by at least one 

LineTerminator

.

The offending token is 

}}

.

The previous token is 

))

 and the inserted semicolon would then be parsed as the terminating semicolon

of a do-while statement (

14.7.2

).

2.  When, as the source text is parsed from left to right, the end of the input stream of tokens is encountered and

the parser is unable to parse the input token stream as a single instance of the goal nonterminal, then a
semicolon is automatically inserted at the end of the input stream.

3.  When, as the source text is parsed from left to right, a token is encountered that is allowed by some production

of the grammar, but the production is a 

restricted production

 and the token would be the first token for a

terminal or nonterminal immediately following the annotation “[no 

LineTerminator

 here]” within the restricted

production (and therefore such a token is called a restricted token), and the restricted token is separated from
the previous token by at least one 

LineTerminator

, then a semicolon is automatically inserted before the

restricted token.

However, there is an additional overriding condition on the preceding rules: a semicolon is never inserted
automatically if the semicolon would then be parsed as an empty statement or if that semicolon would become one of
the two semicolons in the header of a 

for

for

 statement (see 

14.7.4

).

298

NOTE

This section is non-normative.

The source

The following are the only restricted productions in the grammar:

UpdateExpression

[Yield, Await]

 

:

LeftHandSideExpression

[?Yield, ?Await]

 [no 

LineTerminator

 here]  

++

LeftHandSideExpression

[?Yield, ?Await]

 [no 

LineTerminator

 here]  

--

ContinueStatement

[Yield, Await]

 

:

continue

 

;

continue

 [no 

LineTerminator

 here]  

LabelIdentifier

[?Yield, ?Await]

 

;

BreakStatement

[Yield, Await]

 

:

break

 

;

break

 [no 

LineTerminator

 here]  

LabelIdentifier

[?Yield, ?Await]

 

;

ReturnStatement

[Yield, Await]

 

:

return

 

;

return

 [no 

LineTerminator

 here]  

Expression

[+In, ?Yield, ?Await]

 

;

ThrowStatement

[Yield, Await]

 

:

throw

 [no 

LineTerminator

 here]  

Expression

[+In, ?Yield, ?Await]

 

;

ArrowFunction

[In, Yield, Await]

 

:

ArrowParameters

[?Yield, ?Await]

 [no 

LineTerminator

 here]  

=>

 

ConciseBody

[?In]

YieldExpression

[In, Await]

 

:

yield

yield

 [no 

LineTerminator

 here]  

AssignmentExpression

[?In, +Yield, ?Await]

yield

 [no 

LineTerminator

 here]  

*

 

AssignmentExpression

[?In, +Yield, ?Await]

The practical effect of these restricted productions is as follows:

When a 

++

++

 or 

--

--

 token is encountered where the parser would treat it as a postfix

operator, and at least one 

LineTerminator

 occurred between the preceding token and the

++

++

 or 

--

--

 token, then a semicolon is automatically inserted before the 

++

++

 or 

--

--

 token.

When a 

continue

continue

break

break

return

return

throw

throw

, or 

yield

yield

 token is encountered and a 

LineTerminator

 is encountered before the next token, a semicolon is automatically inserted

after the 

continue

continue

break

break

return

return

throw

throw

, or 

yield

yield

 token.

The resulting practical advice to ECMAScript programmers is:

A postfix 

++

++

 or 

--

--

 operator should appear on the same line as its operand.

An 

Expression

 in a 

return

return

 or 

throw

throw

 statement or an 

AssignmentExpression

 in a 

yield

yield

expression should start on the same line as the 

return

return

throw

throw

, or 

yield

yield

 token.

LabelIdentifier

 in a 

break

break

 or 

continue

continue

 statement should be on the same line as the

break

break

 or 

continue

continue

 token.

12.9.2  Examples of Automatic Semicolon Insertion

299

NOTE 1

NOTE 2

AsyncGeneratorMethod

 

:

 

async

 

*

 

PropertyName

 

(

 

UniqueFormalParameters

 

)

 

{

 

AsyncGeneratorBody

 

}

It is a Syntax Error if 

HasDirectSuper

 of 

AsyncGeneratorMethod

 is 

true

.

It is a Syntax Error if 

UniqueFormalParameters

 

Contains

 

YieldExpression

 is 

true

.

It is a Syntax Error if 

UniqueFormalParameters

 

Contains

 

AwaitExpression

 is 

true

.

It is a Syntax Error if 

FunctionBodyContainsUseStrict

 of 

AsyncGeneratorBody

 is 

true

 and 

IsSimpleParameterList

of 

UniqueFormalParameters

 is 

false

.

It is a Syntax Error if any element of the 

BoundNames

 of 

UniqueFormalParameters

 also occurs in the

LexicallyDeclaredNames

 of 

AsyncGeneratorBody

.

AsyncGeneratorDeclaration

 

:

async

 

function

 

*

 

BindingIdentifier

 

(

 

FormalParameters

 

)

 

{

 

AsyncGeneratorBody

 

}

async

 

function

 

*

 

(

 

FormalParameters

 

)

 

{

 

AsyncGeneratorBody

 

}

AsyncGeneratorExpression

 

:

async

 

function

 

*

 

BindingIdentifier

opt

 

(

 

FormalParameters

 

)

 

{

 

AsyncGeneratorBody

 

}

If the source code matching 

FormalParameters

 is 

strict mode code

, the Early Error rules for

UniqueFormalParameters

 

:

 

FormalParameters

 are applied.

If 

BindingIdentifier

 is present and the source code matching 

BindingIdentifier

 is 

strict mode code

, it is a Syntax

Error if the 

StringValue

 of 

BindingIdentifier

 is 

"eval"

 or 

"arguments"

.

It is a Syntax Error if 

FunctionBodyContainsUseStrict

 of 

AsyncGeneratorBody

 is 

true

 and 

IsSimpleParameterList

of 

FormalParameters

 is 

false

.

It is a Syntax Error if any element of the 

BoundNames

 of 

FormalParameters

 also occurs in the

LexicallyDeclaredNames

 of 

AsyncGeneratorBody

.

It is a Syntax Error if 

FormalParameters

 

Contains

 

YieldExpression

 is 

true

.

It is a Syntax Error if 

FormalParameters

 

Contains

 

AwaitExpression

 is 

true

.

It is a Syntax Error if 

FormalParameters

 

Contains

 

SuperProperty

 is 

true

.

It is a Syntax Error if 

AsyncGeneratorBody

 

Contains

 

SuperProperty

 is 

true

.

It is a Syntax Error if 

FormalParameters

 

Contains

 

SuperCall

 is 

true

.

It is a Syntax Error if 

AsyncGeneratorBody

 

Contains

 

SuperCall

 is 

true

.

With parameters 

functionObject

 and 

argumentsList

 (a 

List

).

AsyncGeneratorBody

 

:

 

FunctionBody

1.  Perform ? 

FunctionDeclarationInstantiation

(

functionObject

argumentsList

).

2.  Let 

generator

 be ? 

OrdinaryCreateFromConstructor

(

functionObject

,

YieldExpression

 and 

AwaitExpression

 cannot be used within the 

FormalParameters

 of an async

generator function because any expressions that are part of 

FormalParameters

 are evaluated before

the resulting async generator object is in a resumable state.

Abstract operations

 relating to async generator objects are defined in 

27.6.3

.

15.6.1  Static Semantics: Early Errors

15.6.2  Runtime Semantics: EvaluateAsyncGeneratorBody

409

"%AsyncGeneratorFunction.prototype.prototype%"

, « [[AsyncGeneratorState]], [[AsyncGeneratorContext]],

[[AsyncGeneratorQueue]], [[GeneratorBrand]] »).

3.  Set 

generator

.[[GeneratorBrand]] to 

empty

.

4.  Perform ! 

AsyncGeneratorStart

(

generator

FunctionBody

).

5.  Return 

Completion

 { [[Type]]: 

return

, [[Value]]: 

generator

, [[Target]]: 

empty

 }.

With parameter 

scope

.

AsyncGeneratorDeclaration

 

:

 

async

 

function

 

*

 

BindingIdentifier

 

(

 

FormalParameters

 

)

 

{

 

AsyncGeneratorBody

 

}

1.  Let 

name

 be 

StringValue

 of 

BindingIdentifier

.

2.  Let 

sourceText

 be the source text matched by 

AsyncGeneratorDeclaration

.

3.  Let 

F

 be ! 

OrdinaryFunctionCreate

(

%AsyncGeneratorFunction.prototype%

sourceText

FormalParameters

AsyncGeneratorBody

non-lexical-this

scope

).

4.  Perform ! 

SetFunctionName

(

F

name

).

5.  Let 

prototype

 be ! 

OrdinaryObjectCreate

(

%AsyncGeneratorFunction.prototype.prototype%

).

6.  Perform ! 

DefinePropertyOrThrow

(

F

"prototype"

, PropertyDescriptor { [[Value]]: 

prototype

, [[Writable]]: 

true

,

[[Enumerable]]: 

false

, [[Configurable]]: 

false

 }).

7.  Return 

F

.

AsyncGeneratorDeclaration

 

:

 

async

 

function

 

*

 

(

 

FormalParameters

 

)

 

{

 

AsyncGeneratorBody

 

}

1.  Let 

sourceText

 be the source text matched by 

AsyncGeneratorDeclaration

.

2.  Let 

F

 be 

OrdinaryFunctionCreate

(

%AsyncGeneratorFunction.prototype%

sourceText

FormalParameters

AsyncGeneratorBody

non-lexical-this

scope

).

3.  Perform 

SetFunctionName

(

F

"default"

).

4.  Let 

prototype

 be ! 

OrdinaryObjectCreate

(

%AsyncGeneratorFunction.prototype.prototype%

).

5.  Perform 

DefinePropertyOrThrow

(

F

"prototype"

, PropertyDescriptor { [[Value]]: 

prototype

, [[Writable]]: 

true

,

[[Enumerable]]: 

false

, [[Configurable]]: 

false

 }).

6.  Return 

F

.

NOTE

With optional parameter 

name

.

AsyncGeneratorExpression

 

:

 

async

 

function

 

*

 

(

 

FormalParameters

 

)

 

{

 

AsyncGeneratorBody

 

}

1.  If 

name

 is not present, set 

name

 to 

""

.

2.  Let 

scope

 be the LexicalEnvironment of the 

running execution context

.

3.  Let 

sourceText

 be the source text matched by 

AsyncGeneratorExpression

.

4.  Let 

closure

 be ! 

OrdinaryFunctionCreate

(

%AsyncGeneratorFunction.prototype%

sourceText

FormalParameters

AsyncGeneratorBody

non-lexical-this

scope

).

5.  Perform 

SetFunctionName

(

closure

name

).

An anonymous 

AsyncGeneratorDeclaration

 can only occur as part of an 

export default

export default

declaration.

15.6.3  Runtime Semantics: InstantiateAsyncGeneratorFunctionObject

15.6.4  Runtime Semantics: InstantiateAsyncGeneratorFunctionExpression

410

6.  Let 

prototype

 be ! 

OrdinaryObjectCreate

(

%AsyncGeneratorFunction.prototype.prototype%

).

7.  Perform ! 

DefinePropertyOrThrow

(

closure

"prototype"

, PropertyDescriptor { [[Value]]: 

prototype

, [[Writable]]:

true

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }).

8.  Return 

closure

.

AsyncGeneratorExpression

 

:

 

async

 

function

 

*

 

BindingIdentifier

 

(

 

FormalParameters

 

)

 

{

 

AsyncGeneratorBody

 

}

1. 

Assert

name

 is not present.

2.  Set 

name

 to 

StringValue

 of 

BindingIdentifier

.

3.  Let 

scope

 be the 

running execution context

's LexicalEnvironment.

4.  Let 

funcEnv

 be ! 

NewDeclarativeEnvironment

(

scope

).

5.  Perform ! 

funcEnv

.CreateImmutableBinding(

name

false

).

6.  Let 

sourceText

 be the source text matched by 

AsyncGeneratorExpression

.

7.  Let 

closure

 be ! 

OrdinaryFunctionCreate

(

%AsyncGeneratorFunction.prototype%

sourceText

FormalParameters

AsyncGeneratorBody

non-lexical-this

funcEnv

).

8.  Perform ! 

SetFunctionName

(

closure

name

).

9.  Let 

prototype

 be ! 

OrdinaryObjectCreate

(

%AsyncGeneratorFunction.prototype.prototype%

).

10.  Perform ! 

DefinePropertyOrThrow

(

closure

"prototype"

, PropertyDescriptor { [[Value]]: 

prototype

, [[Writable]]:

true

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }).

11.  Perform ! 

funcEnv

.InitializeBinding(

name

closure

).

12.  Return 

closure

.

NOTE

AsyncGeneratorExpression

 

:

 

async

 

function

 

*

 

BindingIdentifier

opt

 

(

 

FormalParameters

 

)

 

{

 

AsyncGeneratorBody

 

}

1.  Return 

InstantiateAsyncGeneratorFunctionExpression

 of 

AsyncGeneratorExpression

.

ClassDeclaration

[Yield, Await, Default]

 

:

class

 

BindingIdentifier

[?Yield, ?Await]

 

ClassTail

[?Yield, ?Await]

[+Default]

 

class

 

ClassTail

[?Yield, ?Await]

ClassExpression

[Yield, Await]

 

:

class

 

BindingIdentifier

[?Yield, ?Await]

opt

 

ClassTail

[?Yield, ?Await]

ClassTail

[Yield, Await]

 

:

ClassHeritage

[?Yield, ?Await]

opt

 

{

 

ClassBody

[?Yield, ?Await]

opt

 

}

The 

BindingIdentifier

 in an 

AsyncGeneratorExpression

 can be referenced from inside the 

AsyncGeneratorExpression

's 

AsyncGeneratorBody

 to allow the generator code to call itself

recursively. However, unlike in an 

AsyncGeneratorDeclaration

, the 

BindingIdentifier

 in an 

AsyncGeneratorExpression

 cannot be referenced from and does not affect the scope enclosing the 

AsyncGeneratorExpression

.

15.6.5  Runtime Semantics: Evaluation

15.7  Class Definitions

Syntax

411

ClassHeritage

[Yield, Await]

 

:

extends

 

LeftHandSideExpression

[?Yield, ?Await]

ClassBody

[Yield, Await]

 

:

ClassElementList

[?Yield, ?Await]

ClassElementList

[Yield, Await]

 

:

ClassElement

[?Yield, ?Await]

ClassElementList

[?Yield, ?Await]

 

ClassElement

[?Yield, ?Await]

ClassElement

[Yield, Await]

 

:

MethodDefinition

[?Yield, ?Await]

static

 

MethodDefinition

[?Yield, ?Await]

;

NOTE

ClassTail

 

:

 

ClassHeritage

opt

 

{

 

ClassBody

 

}

It is a Syntax Error if 

ClassHeritage

 is not present and the following algorithm evaluates to 

true

:

1.  Let 

constructor

 be 

ConstructorMethod

 of 

ClassBody

.

2.  If 

constructor

 is 

empty

, return 

false

.

3.  Return 

HasDirectSuper

 of 

constructor

.

ClassBody

 

:

 

ClassElementList

It is a Syntax Error if 

PrototypePropertyNameList

 of 

ClassElementList

 contains more than one occurrence of

"constructor"

.

ClassElement

 

:

 

MethodDefinition

It is a Syntax Error if 

PropName

 of 

MethodDefinition

 is not 

"constructor"

 and 

HasDirectSuper

 of 

MethodDefinition

 is 

true

.

It is a Syntax Error if 

PropName

 of 

MethodDefinition

 is 

"constructor"

 and 

SpecialMethod

 of 

MethodDefinition

 is

true

.

ClassElement

 

:

 

static

 

MethodDefinition

It is a Syntax Error if 

HasDirectSuper

 of 

MethodDefinition

 is 

true

.

It is a Syntax Error if 

PropName

 of 

MethodDefinition

 is 

"prototype"

.

ClassElement

 

:

 

MethodDefinition

1.  If 

PropName

 of 

MethodDefinition

 is 

"constructor"

, return 

ConstructorMethod

.

2.  Return 

NonConstructorMethod

.

A class definition is always 

strict mode code

.

15.7.1  Static Semantics: Early Errors

15.7.2  Static Semantics: ClassElementKind

412

ClassElement

 

:

 

static

 

MethodDefinition

1.  Return 

NonConstructorMethod

.

ClassElement

 

:

 

;

1.  Return 

empty

.

ClassElementList

 

:

 

ClassElement

1.  If 

ClassElementKind

 of 

ClassElement

 is 

ConstructorMethod

, return 

ClassElement

.

2.  Return 

empty

.

ClassElementList

 

:

 

ClassElementList

 

ClassElement

1.  Let 

head

 be 

ConstructorMethod

 of 

ClassElementList

.

2.  If 

head

 is not 

empty

, return 

head

.

3.  If 

ClassElementKind

 of 

ClassElement

 is 

ConstructorMethod

, return 

ClassElement

.

4.  Return 

empty

.

NOTE

ClassElement

 

:

 

MethodDefinition

1.  Return 

false

.

ClassElement

 

:

 

static

 

MethodDefinition

1.  Return 

true

.

ClassElement

 

:

 

;

1.  Return 

false

.

ClassElementList

 

:

 

ClassElement

1.  If 

ClassElementKind

 of 

ClassElement

 is 

NonConstructorMethod

, then

a.  Return a 

List

 whose sole element is 

ClassElement

.

2.  Return a new empty 

List

.

ClassElementList

 

:

 

ClassElementList

 

ClassElement

1.  Let 

list

 be 

NonConstructorMethodDefinitions

 of 

ClassElementList

.

2.  If 

ClassElementKind

 of 

ClassElement

 is 

NonConstructorMethod

, then

a.  Append 

ClassElement

 to the end of 

list

.

3.  Return 

list

.

Early Error rules ensure that there is only one method definition named 

"constructor"

 and that it

is not an 

accessor property

 or generator definition.

15.7.3  Static Semantics: ConstructorMethod

15.7.4  Static Semantics: IsStatic

15.7.5  Static Semantics: NonConstructorMethodDefinitions

413

ClassElementList

 

:

 

ClassElement

1.  If 

PropName

 of 

ClassElement

 is 

empty

, return a new empty 

List

.

2.  If 

IsStatic

 of 

ClassElement

 is 

true

, return a new empty 

List

.

3.  Return a 

List

 whose sole element is 

PropName

 of 

ClassElement

.

ClassElementList

 

:

 

ClassElementList

 

ClassElement

1.  Let 

list

 be 

PrototypePropertyNameList

 of 

ClassElementList

.

2.  If 

PropName

 of 

ClassElement

 is 

empty

, return 

list

.

3.  If 

IsStatic

 of 

ClassElement

 is 

true

, return 

list

.

4.  Append 

PropName

 of 

ClassElement

 to the end of 

list

.

5.  Return 

list

.

With parameters 

classBinding

 and 

className

.

ClassTail

 

:

 

ClassHeritage

opt

 

{

 

ClassBody

opt

 

}

1.  Let 

env

 be the LexicalEnvironment of the 

running execution context

.

2.  Let 

classScope

 be 

NewDeclarativeEnvironment

(

env

).

3.  If 

classBinding

 is not 

undefined

, then

a.  Perform 

classScope

.CreateImmutableBinding(

classBinding

true

).

4.  If 

ClassHeritage

opt

 is not present, then

a.  Let 

protoParent

 be 

%Object.prototype%

.

b.  Let 

constructorParent

 be 

%Function.prototype%

.

5.  Else,

a.  Set the 

running execution context

's LexicalEnvironment to 

classScope

.

b.  Let 

superclassRef

 be the result of evaluating 

ClassHeritage

.

c.  Set the 

running execution context

's LexicalEnvironment to 

env

.

d.  Let 

superclass

 be ? 

GetValue

(

superclassRef

).

e.  If 

superclass

 is 

null

, then

i.  Let 

protoParent

 be 

null

.

ii.  Let 

constructorParent

 be 

%Function.prototype%

.

f.  Else if 

IsConstructor

(

superclass

) is 

false

, throw a 

TypeError

 exception.

g.  Else,

i.  Let 

protoParent

 be ? 

Get

(

superclass

"prototype"

).

ii.  If 

Type

(

protoParent

) is neither Object nor Null, throw a 

TypeError

 exception.

iii.  Let 

constructorParent

 be 

superclass

.

6.  Let 

proto

 be ! 

OrdinaryObjectCreate

(

protoParent

).

7.  If 

ClassBody

opt

 is not present, let 

constructor

 be 

empty

.

8.  Else, let 

constructor

 be 

ConstructorMethod

 of 

ClassBody

.

9.  Set the 

running execution context

's LexicalEnvironment to 

classScope

.

10.  If 

constructor

 is 

empty

, then

a.  Let 

steps

 be the algorithm steps defined in 

Default Constructor Functions

.

b.  Let 

F

 be ! 

CreateBuiltinFunction

(

steps

, 0, 

className

, « [[ConstructorKind]], [[SourceText]] », 

empty

,

constructorParent

).

15.7.6  Static Semantics: PrototypePropertyNameList

15.7.7  Runtime Semantics: ClassDefinitionEvaluation

414

11.  Else,

a.  Let 

constructorInfo

 be ! 

DefineMethod

 of 

constructor

 with arguments 

proto

 and 

constructorParent

.

b.  Let 

F

 be 

constructorInfo

.[[Closure]].

c.  Perform ! 

MakeClassConstructor

(

F

).

d.  Perform ! 

SetFunctionName

(

F

className

).

12.  Perform ! 

MakeConstructor

(

F

false

proto

).

13.  If 

ClassHeritage

opt

 is present, set 

F

.[[ConstructorKind]] to 

derived

.

14.  Perform ! 

CreateMethodProperty

(

proto

"constructor"

F

).

15.  If 

ClassBody

opt

 is not present, let 

methods

 be a new empty 

List

.

16.  Else, let 

methods

 be 

NonConstructorMethodDefinitions

 of 

ClassBody

.

17.  For each 

ClassElement

 

m

 of 

methods

, do

a.  If 

IsStatic

 of 

m

 is 

false

, then

i.  Let 

status

 be 

PropertyDefinitionEvaluation

 of 

m

 with arguments 

proto

 and 

false

.

b.  Else,

i.  Let 

status

 be 

PropertyDefinitionEvaluation

 of 

m

 with arguments 

F

 and 

false

.

c.  If 

status

 is an 

abrupt completion

, then

i.  Set the 

running execution context

's LexicalEnvironment to 

env

.

ii.  Return 

Completion

(

status

).

18.  Set the 

running execution context

's LexicalEnvironment to 

env

.

19.  If 

classBinding

 is not 

undefined

, then

a.  Perform 

classScope

.InitializeBinding(

classBinding

F

).

20.  Return 

F

.

When a Default 

Constructor

 Function is called with zero or more arguments which form the rest parameter ...

args

, the

following steps are taken:

1.  If NewTarget is 

undefined

, throw a 

TypeError

 exception.

2.  Let 

F

 be the 

active function object

.

3.  If 

F

.[[ConstructorKind]] is 

derived

, then

a.  NOTE: This branch behaves similarly to 

constructor(...args) { super(...args); }

constructor(...args) { super(...args); }

.

The most notable distinction is that while the aforementioned ECMAScript source text observably calls
the 

@@iterator

 method on 

%Array.prototype%

%Array.prototype%

, a Default 

Constructor

 Function does not.

b.  Let 

func

 be ! 

F

.[[GetPrototypeOf]]().

c.  If 

IsConstructor

(

func

) is 

false

, throw a 

TypeError

 exception.

d.  Return ? 

Construct

(

func

args

, NewTarget).

4.  Else,

a.  NOTE: This branch behaves similarly to 

constructor() {}

constructor() {}

.

b.  Return ? 

OrdinaryCreateFromConstructor

(NewTarget, 

"%Object.prototype%"

).

The 

"length"

 property of a default 

constructor

 function is 

+0

𝔽

.

ClassDeclaration

 

:

 

class

 

BindingIdentifier

 

ClassTail

1.  Let 

className

 be 

StringValue

 of 

BindingIdentifier

.

2.  Let 

value

 be ? 

ClassDefinitionEvaluation

 of 

ClassTail

 with arguments 

className

 and 

className

.

15.7.7.1  Default Constructor Functions

15.7.8  Runtime Semantics: BindingClassDeclarationEvaluation

415

 

 

 

 

 

 

 

Content      ..     23      24      25      26     ..