Feature Request: Option to allow duplicate Labels
gabeklein opened this issue · comments
Right now, as per 13.13.2 in ECMAScript 2016 Spec the following code will raise an exception in conversion to AST within Babylon.
LabeledStatment: {
LabeledStatement: //of same name
{}
}
I propose to add a flag in parserOpts
to permit this repetition. Babel plugins could take advantage of the syntax, when not bottlenecked by this restriction, to write DSL's structured as markup.
An example use case
Transformable HTML/React or CSS markup
// Note that this would be outside the scope of an Iteration Statement
div: {
div: {
span: "Hello"
span: "World"
}
div: {
}
}
Duplicate Label exception not withstanding, this is perfectly legal ECMAScript code. With minor modification to Babylon, to simply suppress the exception given proper flag, a considerable potential can be opened up for babel transforms to create useful constructs.
I have forked Babylon with two branches option_allow_duplicate_labels
and plugin_allow_duplicate_labels
to demonstrate how through either method, the allowance may be included.
I appreciate your feedback.
Hey @gabeklein! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.
If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.
@gabeklein, thanks for the request! Sorry but it's not our intention to deviate from the spec! I know there's been an exception for JSX/types though. If you want a change then it would have to be a TC39 proposal by a champion at Stage 0 at least. We're not interested in adding other syntax to core even as an option.
I would suggest forking the parser if you need this yourself. We have a few languages that do that which use Babel