Skip to content

Disable Annex B by default in @babel/parser #10986

@nicolo-ribaudo

Description

@nicolo-ribaudo

Feature Request

From the Annex B introduction in the spec:

This annex describes various legacy features and other characteristics of web browser based ECMAScript implementations. All of the language features and behaviours specified in this annex have one or more undesirable characteristics and in the absence of legacy usage would be removed from this specification. However, the usage of these features by large numbers of existing web pages means that web browsers must continue to support them. The specifications in this annex define the requirements for interoperable implementations of these legacy features.

These features are not considered part of the core ECMAScript language. Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code. ECMAScript implementations are discouraged from implementing these features unless the implementation is part of a web browser or is required to run the same legacy ECMAScript code that web browsers encounter.

Most of the Annex B features are only used by legacy code, which probably isn't using Babel. Modern code is discouraged from using them, and browsers can't remove them because of the "don't break the web" constraint.

Well, we can break things 😛

Supporting Annex B features by default means that, by default, we are not compliant with the non-Annex B parts of the spec. For example, this code should fail but Annex B makes it valid (source):

try {} catch (err) { for (var err of [2]) {} }

I propose to add a new parser plugin, annexb, and only parse those "features" when it is enabled.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions