-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
Pre-RFC: Support one hbs comment format instead of two? #504
Comments
The We have a few options:
I personally am in favor of the first and third (I don't think the deprecation on its own is very good ergonomics). |
Would it make sense to deprecate handlebars comments altogether in favor of HTML comments? I realize Handlebars comments are removed, but it seems like HTML comments would be possible to remove as well in the same way, I wasn’t sure why we needed both options. |
Hmm, I don't think so @pzuraq. There is actually (sometimes) value in emitting HTML comments (e.g. for instructions when inspecting the DOM). In addition, it would be a bit of an uphill battle from a SemVer perspective (since it would be a breaking change to stop emitting HTML comments). |
I checked https://github.com/ember-learn/guides-source for usage patterns using |
I'm not as convinced of the value of emitting HTML comments, you could make the same argument about JS comments, but we still minify and remove them for production builds. I think in most cases, they represent extra bytes without extra value. Definitely agree that it's a much harder change from a SemVer perspective though. Probably something that would have to be done in time, so I agree this is probably better to tackle first either way. |
@pzuraq When I teach others about handlebars, I explain "use html comments if you want them in the build, use handlebars comments if you want them stripped out". Just wanted to give you context of how some people understand them. |
@kellyselden totally understand the difference, and how we teach it. I just haven't personally come across a use case where I actually wanted people to read HTML comments (where I also wouldn't want them to be able to read JavaScript comments). I guess I feel like this is something that should be handled by a Handlebars/HTML minifier in production builds, rather than by a language level feature that requires us to teach people more things. Edit: If anyone has use cases that demonstrate the value here, I'd love to surface them, would be good to know! 😄 |
@pzuraq - I totally agree that an HBS minifier should remove HTML comments, however this is a bit of a different thing (its completely opt-in by adding/using a minifier). |
HTML comments are also sometimes very useful semantically, because they let you wrap lines in an editor without adding a newline and therefore white space to the rendered output. As weird as that behavior is, it's also one I've needed to rely on several times. |
I always assumed that {{! quick single line comment }}
<My Component
@someArg={{this.thingy}} {{! some comment about arg}}
/>
{{!--
Long
Multiline
Comment
--}} |
Not trying to side track - but if we're going to clean up comment behaviour, I'd LOVE to be able to wrap a comment in a comment - or rather comment out code which has a comment somewhere in it: {{!--
<p>Some stuff</p>
{{!-- <p>Some stuff</p> --}}
<p>Some stuff</p>
--}} I often have to resort just deleting code which I want to comment out when debugging and that's just not safe at all... :( |
@lougreenwood I haven't tested this, but I always assumed one was a single-line comment, and the other a multi-line comment; therefore you could nest single-line inside a multi-line comment. {{!--
<p>Some stuff</p>
{{! <p>Some stuff</p> }}
<p>Some stuff</p>
--}} I always end up writing code like this while refactoring in other languages. /*
const foo = 'bar';
// const bar = 'foo';
const foobar = 'hello world';
*/ I am good for preferring one over the other, but I don't see the value of removing it if one is a single-line comment, and the other a multi-line comment. |
I think the third approach mentioned by @rwjblue is the best way forward. |
Thank you @GavinJoyce for opening this discussion. I've wondered for some time why there were two syntaxes for multi-line comments, I was not alone ^^. I'm okay to help / pair on opening a RFC for @rwjblue's third option. As it is a handlebars.js feature, I'm not sure where the deprecation would have to be issued though.
This feature is supported today thanks to the two syntaxes: |
I'm closing this due to inactivity. This doesn't mean that the idea presented here is invalid, but that, unfortunately, nobody has taken the effort to spearhead it and bring it to completion. Please feel free to advocate for it if you believe that this is still worth pursuing. Thanks! |
We currently support two
.hbs
comment syntaxes:Here's the AST output for both:
https://astexplorer.net/#/gist/e39b9bed0d6d7ce03d7c00a371cf016f/8ac50f526ebf1f68866ed31e387349d2cab4d559
Is there a reason to support both syntaxes? If not, perhaps we should open an RFC to deprecate one?
The text was updated successfully, but these errors were encountered: