Skip to content

littledan/proposal-comma-separated-fields

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Comma separated field declarations

Champion: Yehuda Katz

First draft author: Daniel Ehrenberg

Description

In a class declaration, you can define multiple fields separated by ;. In this proposal, you can use , to separate closely related field declarations, which would share decorators and static. For example:

class C {
  @reader #x, #y;
}

Risks

The grouping of the decorator and static with fields is unclear, especially in conjunction with initializers. For example, in

class C {
  @reader #x = 1 + 2 + 3 + 4,
    #y = 5;
}

Here, there are two competing readings: Either a reader could be created for just #x, or it can be created for #x as well as #y.

In code review threads for implementing this feature, a number of people had the reading that it would apply to only one of the comma-separated items, rather than both of them.

Implementation status

There is a PR for this feature in Babel, but it has not landed, awaiting more clarity from TC39.

This sort of feature was considered for TypeScript but delayed to ensure there wouldn't be a conflict with JavaScript.

About

Comma separated field declarations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages