Skip to content
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

/* */ comments don't work in inline functions #7456

Open
DetachHead opened this issue Apr 14, 2022 · 8 comments
Open

/* */ comments don't work in inline functions #7456

DetachHead opened this issue Apr 14, 2022 · 8 comments
Labels
feature request PRs welcome we're not going to spend any time on this, but we'll accept pull requests
Milestone

Comments

@DetachHead
Copy link

Describe the bug

"Expected }" syntax error when attempting to use /* comments
image

Reproduction

<button on:click="{() => {} /* asdf */}" />

Logs

No response

System Info

System:
    OS: Windows 10 10.0.19042
    CPU: (6) x64 Intel(R) Core(TM) i5-8600 CPU @ 3.10GHz    
    Memory: 2.71 GB / 15.78 GB
  Binaries:
    Node: 16.9.1 - C:\Program Files\nodejs\node.EXE
    npm: 7.24.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 99.0.4844.84
    Edge: Spartan (44.19041.1266.0), Chromium (99.0.1150.55)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    svelte: ^3.47.0 => 3.47.0

Severity

annoyance

@DetachHead DetachHead changed the title comments don't work in inline functions /* comments don't work in inline functions Apr 14, 2022
@DetachHead DetachHead changed the title /* comments don't work in inline functions /* */ comments don't work in inline functions Apr 14, 2022
@Prinzhorn
Copy link
Contributor

Prinzhorn commented Apr 14, 2022

I'm not saying this should or shouldn't work, but the comment is not inside your function. It works inside the function, e.g.

<button on:click="{() => {/* asdf */}}" />

I'm not an expert on the Svelte syntax definition, but to me everything inside the outer curly brackets needs to be a single JavaScript expression. And comments are not part of the JavaScript expression. So what you've posted is the same as doing this:

<script>
	let name = 'world';
</script>

<h1>Hello {name /* asdf */}!</h1>

which equally doesn't work.

The docs always talk about "JavaScript expressions" when talking about what comes inside the curly brackets. And comments aren't expressions.

@DetachHead
Copy link
Author

the way i see it comments should have no impact on the code whatsoever. so if an expression has a comment after it, it should still be considered an expression

@Mlocik97
Copy link
Contributor

Mlocik97 commented Apr 24, 2022

So you thing:

<input type="number /* this is input for age */ ">hello</input>

should work too? Actually you can't put comment everywhere in HTML or JS too... like in middle of regex or attribute... So I disagree that "you can put comment everywhere"... but I actually agree that having ability to add comments inside expressions would be nice.

@KotlinIsland
Copy link

@Mlocik97 In your example that is not a Javascript context expression, so a javascript comment should not work, so...

Some flavors of regex supports comments: regex comments

html supports comments:

<input input="number /* this is input for age */ "><!--this is a comment-->hello</input>

The comment is not stating that Javascript comment syntax should work in every possible context, it's only stating that it should be valid for expressions to be able to be prepended/appended with comments.

@Mlocik97
Copy link
Contributor

Mlocik97 commented Apr 24, 2022

yeah, you put that HTML comment outside of attribute value... so tell me...

<input type="number <!-- doesn't work either -->">hello</input>

I didn't said it's expression, but I'm just arguing against "you can put comment everywhere", or resp. "the way i see it comments should have no impact on the code whatsoever.", even tho it has nothing to do if it's allowed at specific place such as expression.

Another possible way is put IIFE in expression, and pass comments inside it. As it was already mentoyed here.

Still I'm ofc for this feature request.

@DetachHead
Copy link
Author

DetachHead commented Apr 25, 2022

By "comments should have no impact on the code" I didn't mean html comments should work in JavaScript or anything like that, all I meant is that whether or not some JavaScript code is considered a valid expression shouldn't be effected by whether or not there's a valid JavaScript comment in the code. just linke in plain html:

<!-- no error -->
<button onclick="foo() /*asdf*/">asdf</button>

@Mlocik97
Copy link
Contributor

 By "comments should have no impact on the code" I didn't mean html comments should work in JavaScript or anything like that,

I was not talking about it as well...

@jrmoynihan
Copy link

What is the use-case for needing a comment inside of an inline function? What problem does that solve?

@Rich-Harris Rich-Harris added the PRs welcome we're not going to spend any time on this, but we'll accept pull requests label Apr 2, 2024
@Rich-Harris Rich-Harris added this to the one day milestone Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request PRs welcome we're not going to spend any time on this, but we'll accept pull requests
Projects
None yet
Development

No branches or pull requests

7 participants