You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To comment out code chunks within HTML tagged template literals, you can use one of the following semantics:
${''/* ... */}, backtick (`) can be included in the chunk,
${'' && ` ... `}, backtick (`) included in the chunk DOES give error!
Note: Many thanks to TC39 members who provided me the above semantics!
Example
import{LitElement,html}from'lit';import{customElement,property}from'lit/decorators.js';
@customElement('my-element')exportclassmyElementextendsLitElement{
@property()fruit='apple';
@property()price=15;render(){returnhtml`<p>This is an ${this.fruit}!</p><p>It costs ${this.price} cents.</p><p>The condition of the fruit is ${this.fruitCondition}</p><!-- NO, it does NOT give an error. --><p>The colour of the fruit is ${fruitColour}</p><!-- YES, it DOES give an error as expected. --><hr><p>The colour of the fruit is ${''/*fruitColour*/}</p>${''/* <p>The colour of the fruit is ${fruitColour}</p> <p>The taste of the fruit is ${fruitTaste}</p> */}<hr><p>The size of the fruit is ${''&&`fruitSize`}</p>${''&&` <p>The size of the fruit is ${fruitSize}</p> <p>The weight of the fruit is ${fruitWeight}<p> `}<hr>${''/* <p>This is a backtick(`)</p> */}${''&&` <p>This is a backtick(`)</p> `}<!-- YES, it DOES give an error! --> `;}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
To comment out code chunks within HTML tagged template literals, you can use one of the following semantics:
${''/* ... */}
, backtick (`) can be included in the chunk,${'' && ` ... `}
, backtick (`) included in the chunk DOES give error!Note: Many thanks to TC39 members who provided me the above semantics!
Example
Beta Was this translation helpful? Give feedback.
All reactions