CSS tagged template literals don't self close
See original GitHub issueBefore VS Code v1.27, the following would happen when creating a CSS tagged template literal (note that this issue happens with styled components, or any tagged template literal function name that triggers CSS highlighting):
const foo = css
// press the tickmark (`) key
const foo = css`|` // cursor is in the middle of two tickmarks, and the literal is self-closing
Now, this is what happens:
const foo = css
// press the tickmark (`) key
const foo = css`| // cursor is after the first tickmark, and it is not self closing
// press the tickmark (`) key to close the literal
const foo = css``|` // two tickmarks are inserted and the cursor is after the second one
I can confirm that this does not happen with any other names, for example this still works:
const foo = html
// press the tickmark (`) key
const foo = html`|` // cursor is in the middle of two tickmarks, and the literal is self-closing
I’m not sure where to file this issue, I would think that it’s related to the CSS language detection part of the plugin, but I can confirm that it only happens with CSS-highlighted tagged template literals, and also only when this plugin is enabled.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:5 (4 by maintainers)
Top Results From Across the Web
javascript - Problem with tagged template strings and closure
Basically, if not to go in details, I use tagged template literal to temporarily change the _mode property on thread instance. So the...
Read more >Tagged Template Literals - The Magic Behind Styled ...
We already know that template literals don't have to return strings, so how about creating a simple example of a tagged template that ......
Read more >Template literals (Template strings) - JavaScript | MDN
Template literals are literals delimited with backtick (`) characters, allowing for multi-line strings, string interpolation with embedded ...
Read more >Template Literals | CSS-Tricks
The Template Literal, introduced in ES6, is a new way to create a string. With it comes new features that allow us more...
Read more >Template literals should not be nested - SonarSource Rules
TypeScript static code analysis. Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your TYPESCRIPT code.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Can confirm, I though it was the styled components extension, but after messing around with extensions a bit more, the problem is with vscode-language-babel. e.g. -
When you type in the templet literal quote marks, it adds 1 but doesn’t seem to recognise it, and then when you try and complete it, vscode adds one more at the end, so you end up with 3
VSCode: 1.27.2 vscode-styled-components: 0.0.21
package.json -
VSCode settings:
Closing this since there is a decent workaround and vscode’s fix should suffice.