styled-components / babel-plugin-polished Goto Github PK
View Code? Open in Web Editor NEWCompile polished helper functions at build time
License: MIT License
Compile polished helper functions at build time
License: MIT License
Tried some new functions from polish today with some errors... Here I downloaded and added a test to your plugin (btw, please add jest as dev dep.)
● polished › 2. math
SyntaxError: unknown: Method does not exist: math
> 1 | import { math } from 'polished';
| ^
2 |
3 | let a = math('12px + 12px')
44 |
45 | if (!value) {
> 46 | throw imported.buildCodeFrameError('Method does not exist: ' + importedName);
| ^
47 | }
{
title: "math",
code: `
import { math } from 'polished';
let a = math('12px + 12px')
`,
output: `
let a = '14px';
`
}
Related to: Corjen/gatsby-plugin-polished#1
The readme says "Compile away polished helpers" - can I just confirm that what this package does is strip-out/tree shake the polished helpers that I have not imported into my project?
Secondly, should the import in the 'In' code block be:
import { rem } from 'polished';
to fall in line with the example of how to import the polished helpers in the polished readme file?
Am very keen to make use of this plugin, but it doesn't do anything when added to my project.
I initially tried with babel 7 and then downgraded to 6 and it still did not work. Note, I tried polished
and babel-plugin-polished
as the values for the name in the .babelrc
(you have it both ways in the documentation on github and on your website).
// .babelrc
"plugins": [
["babel-plugin-styled-components", {
"displayName": true,
"ssr": true
}],
"babel-plugin-polished"
]
I also tried both ways of importing polished
at the top of a given file.
// component.js
import * as polished from 'polished';
// as well as
import { rgba } from 'polished';
No combination makes any difference to the transpiled code that is output.
Please can you assist? Cheers.
I'm curious just how effective this is and how it handles dynamic usage scenarios.
For example, can something like this be handled?
css`
${props => rgba(normalizeColor('border', props.theme), 0.2)};
`
We have some mixins that intentionally take null to skip values. For example position:
position('absolute', '20px', '20px', null, null)
The babel plugin is stripping these null values out incorrectly and causing it to be parsed as:
position('absolute', '20px', '20px')
Which results in the incorrect final CSS:
position: absolute;
top: 20px;
right: 20px;
bottom: 20px;
left: 20px;
It should be:
position: absolute;
top: 20px;
right: 20px;
I imagine this is impacting anywhere we use null
in this manner.
It's not my SO post, but this is essentially what I'm seeing: https://stackoverflow.com/questions/43940649/unexpected-node-type-error-sequenceexpression-with-jest
Essentially, istanbul
and polished
babel plugins don't play well with each other.
Here's out callstack:
SyntaxError: /next/app/components/FloatingActionButton/ui.tsx: Unexpected node type: SequenceExpression (This is an error on an internal node. Probably an internal error. Location has been estimated.)
28 | z-index: ${({ zIndex }) => zIndex || '2'};
29 | list-style-type: none;
> 30 | background-color: ${({ theme, active }) => (active ? rgba(theme.colors.white, 0.5) : theme.colors.transparent)};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31 | pointer-events: ${({ active }) => (active ? 'auto' : 'none')};
32 | -webkit-tap-highlight-color: ${({ theme }) => theme.colors.transparent};
33 |
at Array.filter (<anonymous>)
at Array.filter (<anonymous>)
Our workaround was to only use the plugin on env.prod
in the .babelrc
.
With the release of polished 1.9.0 a hideVisually
mixin was added. When using this plugin and trying to import and use hideVisually
I get the error:
Method does not exist: hideVisually
Without using the babel plugin hideVisually
is found and works OK so I think it has to do with this plugin.
I'll try to find the problem and submit a PR but I've never worked with a babel plugin before so I figured I should submit the issue in case a more experienced person sees an issue.
I have some utilities that are able to derive the literal value of something, even across modules. I'm thinking of packaging this up into its own module. Would you be interested in adopting this in this plugin? I'd be happy to make a PR for it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.