question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS tagged template literals don't self close

See original GitHub issue

Before 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:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ankithkondacommented, Sep 21, 2018

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

sep-21-2018 10-52-53

VSCode: 1.27.2 vscode-styled-components: 0.0.21

package.json -

"polished": "^1.9.3",
"styled-components": "^3.4.2"

VSCode settings:

{
  "terminal.integrated.shell.osx": "/bin/zsh",
  "terminal.integrated.fontFamily": "Roboto mono for Powerline",
  "workbench.iconTheme": "vscode-icons",
  "editor.renderIndentGuides": false,
  "guides.enabled": false,
  "gitlens.keymap": "alternate",
  "gitlens.advanced.messages": {
    "suppressShowKeyBindingsNotice": true
  },
  "window.zoomLevel": 1,
  "editor.formatOnSave": true,
  "[javascript]": {
    "editor.formatOnSave": false
  },
  "eslint.autoFixOnSave": true,
  "eslint.alwaysShowStatus": true,
  "editor.minimap.enabled": false,
  "window.title": " ",
  "emeraldwalk.runonsave": {
    "commands": [
      {
        "match": "\\.php$",
        "cmd": "prettier ${file} --write"
      }
    ]
  }
}

0reactions
michaelgmcdcommented, Jul 31, 2019

Closing this since there is a decent workaround and vscode’s fix should suffice.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found