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.

Variables don't work in template strings

See original GitHub issue

When you use a template in your tagged template string css, the browserify transform breaks.

var aColor = '#fff'

var css = sf`.some-class {
  background-color: ${aColor};
}`
CssSyntaxError: /Users/bret/repos/hyperamp/renderer/index.js:3:2: Unknown word while parsing file: /Users/bret/repos/hyperamp/renderer/index.js

  1 | .some-class {
  2 |   background-color: ,;
> 3 | }[object Object]
    |  ^

I started down the road of correcting the in-node implementation, but we are going to have to statically analyze the template string during the transform somehow. I’m not too familiar with this kind of thing. Any ideas?

https://github.com/bcomnes/sheetify/commit/112d7b77448da8f7d73bdbf9bba52171ecab329b

This is related to https://github.com/stackcss/sheetify/issues/54 but specific to the way template variables are busted right now vs how :host gets used.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
yoshuawuytscommented, Nov 16, 2016

Should be fixed in 6.0.1 which has the latest static-eval - holler if something’s not working as expected

1reaction
ahdinosaurcommented, Oct 2, 2016

i wrote my thoughts on sheetify static evaluation in https://github.com/stackcss/sheetify/issues/54#issuecomment-247816150. meanwhile support for template strings has been merged into static-eval: https://github.com/substack/static-eval/pull/13. 🍍

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 strings not working [duplicate] - Stack Overflow
All that is inside a string, is literal. You're writing the variable ${name} inside the normal quotes, so it will be printed literal....
Read more >
Template Literals Not Working - Medium
If you are using JavaScript's new template literal syntax in a JSP page it might not work as expected. That's because JSP and...
Read more >
Understanding Template Literals in JavaScript - DigitalOcean
Template literals are a new form of making strings… ... Entire expressions can be interpolated, not just variables, such as in this example ......
Read more >
Template Strings - TypeScript Deep Dive - Gitbook
Another common use case is when you want to generate some string out of some static strings + some variables. For this you...
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