Template literals are enclosed in quotes by default
Describe the bug
For LWC playground, if you paste the code it just encloses quotes around template variables in html. Even after removal on save it adds the quotes and fails with error.
[!] (plugin rollup-plugin-lwc-compiler) Error: LWC1034: Ambiguous attribute value for:each="{objectColumns}". If you want to make it a valid identifier you should remove the surrounding quotes for:each={objectColumns}. If you want to make it a string you should escape it for:each="\{objectColumns}".
HTML snippet for the above error:
<thead>
<tr>
<template for:each="{objectColumns}" for:item="column">
<th key="{column.label}">{column.label}</th>
</template>
</tr>
</thead>
Link to the blitz that caused the error
https://stackblitz.com/edit/salesforce-lwc-band2a?file=src%2Fmodules%2Fx%2Fcounter%2Fcounter.html
Steps to reproduce
Paste the html and try to compile
<thead>
<tr>
<template for:each="{objectColumns}" for:item="column">
<th key="{column.label}">{column.label}</th>
</template>
</tr>
</thead>
Expected behavior
it should not enclose quotes around template variables and should look like as below
<thead>
<tr>
<template **for:each={objectColumns}** for:item="column">
<th key="{column.label}">{column.label}</th>
</template>
</tr>
</thead>
Parity with Local
- [X] I have run the project in my local machine and I could not reproduce the issue.
Screenshots
No response
Platform
Browser name = Chrome
Full version = 115.0.0.0
Major version = 115
navigator.appName = Netscape
navigator.userAgent = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36
performance.memory = {
"totalJSHeapSize": 156245153,
"usedJSHeapSize": 143163381,
"jsHeapSizeLimit": 4294705152
}
Hash = ba0db7b1
Additional context
No response
hi :wave: thanks for opening this issue!
This is happening because of the automatic formatting being applied to html files.
You can disable this behaviour by creating a .vscode/settings.json file with the following content:
{
"editor.formatOnSave": false
}
feel free to open another issue if there is anything else we can help with!