Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with css`` inside object with numerical keys #170

Closed
steadicat opened this issue Nov 10, 2017 · 2 comments
Closed

Error with css`` inside object with numerical keys #170

steadicat opened this issue Nov 10, 2017 · 2 comments
Assignees
Labels
babel-plugin bug 🐛 Issue is a confirmed bug

Comments

@steadicat
Copy link

Do you want to request a feature or report a bug?

Bug.

What is the current behavior?

The following code:

const FONT_SIZE_STYLES = {
  '11': css`font-size: 11px;`,
  '12': css`font-size: 12px;`,
  '13': css`font-size: 13px;`,
  '14': css`font-size: 14px;`,
  '15': css`font-size: 15px;`,
  '16': css`font-size: 16px;`,
  '17': css`font-size: 17px;`,
  '18': css`font-size: 18px;`,
  '20': css`font-size: 20px;`,
  '22': css`font-size: 22px;`,
  '24': css`font-size: 24px;`,
  '26': css`font-size: 26px;`,
  '28': css`font-size: 28px;`,
  '32': css`font-size: 32px;`,
};

gives the following error:

Error in ./src/ui/components/core/Text.js
Syntax error: Couldn't determine the class name for CSS template literal. Ensure that it's either:
- Assigned to a variable
- Is an object property
- Is a prop in a JSX element


  12 | 
  13 | const FONT_SIZE_STYLES = {
> 14 |   '11': css`font-size: 11px;`,
     |         ^
  15 |   '12': css`font-size: 12px;`,
  16 |   '13': css`font-size: 13px;`,
  17 |   '14': css`font-size: 14px;`,

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.

What is the expected behavior?

It should work fine. If a class name can't be inferred, Linaria should just use a hash.

BTW, is there any way to disable inferring class names and just using hashes? I would like this in production. I couldn't find a mention of it in the docs.

@zamotany
Copy link
Contributor

BTW, is there any way to disable inferring class names and just using hashes? I would like this in production. I couldn't find a mention of it in the docs.

Not really. And we will probably never allow this, since we are debating internally to switch to hash generation based on absolute filename instead o creating a hash based on the style content.

@steadicat
Copy link
Author

we are debating internally to switch to hash generation based on absolute filename

What I mean is hiding the variable name from the production class names, no matter how the hash is generated. Why isn’t this allowed? Would save bytes as well as prevent leaking of internal names to production HTML and CSS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
babel-plugin bug 🐛 Issue is a confirmed bug
Projects
None yet
Development

No branches or pull requests

3 participants