-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request: Syntactic carve-out for @@
-decorators for design-time space
#433
Comments
It wouldn’t be legal syntax as-is - what would a carve out do? Separately, i don’t think anything that lacks runtime semantics but still would end up being loaded in browsers and node is a good idea - we already have comments for that. |
We don't currently have a formal syntax carveout for
I don't disagree. The "treat it as a comment" part of my message above was mostly along the same lines as the existing "types as comments" discussion. It's not something I would strongly push for. |
If this were to go forward, what about the following syntax: @ignore:someDecorator foo = 123
// or
@:someDecorator foo = 123 where |
I've been convinced by others that something like |
Early on in the life of the Decorators proposal, I had discussed with some stakeholders at the time about the possibility of introducing a syntactic carve-out for "design-time only" decorators that are handled purely by build tools (i.e., TypeScript, Babel, Flow, esbuild, etc.). While such a carve-out has been discussed, it has never been formalized.
This syntactic carve-out would be roughly the same syntax proposed for Decorator:
The motivation behind this is to allow build tools to leverage decorator-like syntax to affect emit behavior without needing to use heuristics to distinguish between decorators that have runtime behavior and those that have design-time behavior. Design-time decorators could also, in theory, be applied to other declarations that currently are not valid decoration targets, such as functions, parameters, object literals, variable declarations, etc., without impacting any future proposals that might introduce runtime decorators.
For example (none of these are concrete asks, but more of a sketch of possible outcomes):
Without design-time decorators, tools are reduced to using comments (such as TypeScript's support for
/** @deprecated */
).It would be up to the build tool in question to determine how to handle the syntax, but ECMA-262 would consider the above a syntax error. Alternatively, ECMA-262 could permit parsing the above syntax but treat it as something akin to a comment. The goal of the syntax carve-out would be to inform future proposals so as to avoid ambiguities between new syntax proposed for ECMA-262 and syntax used by build tools. Essentially, this is similar to the de facto carve out for
:
in certain contexts to allow for type annotations in ECMAScript-based languages like Flow and TypeScript, and possible future adoption of type annotations in ECMAScript.The text was updated successfully, but these errors were encountered: