Closed Bug 1607050 Opened 4 years ago Closed 4 years ago

Parse "await" as an identifier in class fields

Categories

(Core :: JavaScript Engine, defect, P1)

72 Branch
defect

Tracking

()

RESOLVED FIXED
mozilla74
Tracking Status
firefox74 --- fixed

People

(Reporter: nicolo.ribaudo, Assigned: nicolo.ribaudo)

Details

Attachments

(1 file, 1 obsolete file)

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36

Steps to reproduce:

This is code in a script context:

async () => class { x = await }

Is should be correctly parsed because the proposal uses ~Await to signal that "await" represents an identifier:
FieldDefinition[Yield, Await]:
ClassElementName[?Yield, ?Await] Initializer[In, ~Yield, ~Await]opt


I have never contributed to SpiderMonkey before, but I would like to fix this bug if no one is already working on it.

Actual results:

It throws "SyntaxError: await is a reserved identifier"

Expected results:

It should be correctly parsed

Good catch! I should have spotted this when I removed the YieldHandling parameter in https://phabricator.services.mozilla.com/D53638. :-)

In case you need any pointers, the initialiser expression is parsed here and await handling is implemented through the RAII class AutoAwaitIsKeyword. https://searchfox.org/mozilla-central/source can help to navigate through the source tree.

Assignee: nobody → nicolo.ribaudo
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true

The ParserBase::awaitIsKeyword function was originally designed to be
used to check if "await" should be parsed as an identifier or as the
beginning of an AwaitExpression. It has a role identical to the
[?Await] production parameter used in the specification.

The ParserBase::awaitIsKeyword function was originally designed to be
used to check if "await" should be parsed as an identifier or as the
beginning of an AwaitExpression. It has a role identical to the
[?Await] production parameter used in the specification.

Parse await as an identifier in fields initializers

The proposal specifies class fields as follows:
FieldDefinition[Yield, Await]:
ClassElementName[?Yield, ?Await] Initializer[In, ~Yield, ~Await]opt

This means that await should be parsed according to the context
where the class is defined, while they should always be parsed as
identifiers inside initializers.

Currently also yield parsing is broken, but the ~Yield parameter is
handled differently from ~Await and it is fixed by
https://phabricator.services.mozilla.com/D53638

Attachment #9118721 - Attachment description: Bug 1607050 - Part 2: Consistently use 'awaitIsKeyword' to parse "await" → Bug 1607050 - Part 2: Parse await as an identifier in fields initializers
Priority: -- → P1
Attachment #9118721 - Attachment description: Bug 1607050 - Part 2: Parse await as an identifier in fields initializers → Bug 1607050 - Parse await as an identifier in fields initializers
Attachment #9118720 - Attachment is obsolete: true
Pushed by nerli@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/1de45bb038fc
Parse await as an identifier in fields initializers r=anba
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla74
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: