archives

« Bugzilla Issues Index

#4097 — Editorial issues in 12.1.1 Static Semantics: Early Errors


1. The first item in second paragraph:

IdentifierReference[Yield] : yield
BindingIdentifier[Yield] : yield
LabelIdentifier[Yield] : yield

It is a Syntax Error if this production has a [Yield] parameter.

is redundant because yield is not a production when a [Yield] parameter is present.


2. The third paragraph:

IdentifierReference[Yield] : Identifier
BindingIdentifier[Yield] : Identifier
LabelIdentifier[Yield] : Identifier
It is a Syntax Error if this production has a [Yield] parameter and StringValue of Identifier is "yield".

is redundant because Identifier's StringValue cannot be "yield".

The NOTE below states:

> StringValue of IdentifierName normalizes any Unicode escape sequences in IdentifierName hence such escapes cannot be used to write an Identifier whose code point sequence is the same as a ReservedWord.

This two implies that "although Identifier can have the same code point sequence as a ReservedWord, but it cannot be achieved through Unicode escape", which is not true.


(In reply to Bei Zhang from comment #0)
> 1. The first item in second paragraph:
>
> IdentifierReference[Yield] : yield
> BindingIdentifier[Yield] : yield
> LabelIdentifier[Yield] : yield
>
> It is a Syntax Error if this production has a [Yield] parameter.
>
> is redundant because yield is not a production when a [Yield] parameter is
> present.

agreed


>
>
> 2. The third paragraph:
>
> IdentifierReference[Yield] : Identifier
> BindingIdentifier[Yield] : Identifier
> LabelIdentifier[Yield] : Identifier
> It is a Syntax Error if this production has a [Yield] parameter and
> StringValue of Identifier is "yield".
>
> is redundant because Identifier's StringValue cannot be "yield".

It can, in non-strict code, if the IdentifierName that Identifier derives contains Unicode escape sequences. Note that the 2nd bullet item of the following rules for Identifier explicitly permit that. this is because prior to ES6 'yield' was not a reserved word so valid identifiers could have been 'yield' written with escape sequences.


>
> The NOTE below states:
>
> > StringValue of IdentifierName normalizes any Unicode escape sequences in IdentifierName hence such escapes cannot be used to write an Identifier whose code point sequence is the same as a ReservedWord.
>
> This two implies that "although Identifier can have the same code point
> sequence as a ReservedWord, but it cannot be achieved through Unicode
> escape", which is not true.

How do you arrive at that conclusion? What the note says is exactly what the two early error rules for Identifier is enforcing.


It conflicts with 11.6:

> All interpretations of IdentifierName within this specification are based upon
> their actual code points regardless of whether or not an escape sequence was used
> to contribute any particular code point.


(In reply to Bei Zhang from comment #2)
> It conflicts with 11.6:
>
> > All interpretations of IdentifierName within this specification are based upon
> > their actual code points regardless of whether or not an escape sequence was used
> > to contribute any particular code point.

The definition of StringValue for Identifier name is the normative specification language that makes the 11.6 statement operative.

StringValue for IdentifierName replaces Unicode escape sequences with the equivalent code points (actually code unit sequences). The use of Unicode escapes does not effect IdentifierName Stringvalue comparisons.

The grammar rule
Identifer : IdentifierName but not ReservedWrod

does a lexical match of of the source code of IdentifierName against the ReservedWord's, not a StringValue comparison. So v\u0061r is first parsed as an Identifier.

The 2nd Identifier early error rule in 12.1.1 then use a StringValue comparison to determine that v\u0061r has the same StringValue as "var" triggering a syntax error.

'yield' is a special case which is why it is excluded from the 2nd Identifier early error rule. In non-strict code that is outside of a generator function 'yield' is a valid identifier. The early error rule for IdentifierReference : Identifier (etc.) make sure that 'yield' containing Unicode escapes doesn't pass as an Identifier in those generator function contexts.


If I understand correctly, is this the case that

var var

is a grammar error and

var v\u0061r

is an early error?

function* a() {
yield
}

is a generator declaration with a yield expression and

function* a() {
\u0079ield
}

is an early error?


(In reply to Bei Zhang from comment #4)
> If I understand correctly, is this the case that
>
>

yes, those all look correct.


When I read section 11.6, I would assume that any two IdentifierNames are the same in every way in syntactic rules of the the spec. I'm under-informed that there are "exceptions" to this rule later on in section 12.1.1.

We shall state in section 11.6 that the rule:

> All interpretations of IdentifierName within this specification are based upon their actual code points regardless of whether or not an escape sequence was used to contribute any particular code point.

can be overruled by section 12.1.1. As a spec reader, when reading 11.6, I was not informed that rules in 11.6 exists and, in fact, discriminate the interpretation of IdentifierNames.


fixed in rev35 editor's draft


The paragraph in 11.6 that is giving you trouble is actually about Unicode canonical equivalence rather than the use of escape sequences. I eliminated the parenthetical phrase and upate the result of that paragraph so it now reads:

Two /IdentifierName/ that are canonically equivalent according to the Unicode standard are /not/ equal unless, after replacement of each /UnicodeEscapeSequence/, they are represented by the exact same sequence of code points.


fixed in rev35