Giter VIP home page Giter VIP logo

babel-plugin-polished's Introduction

babel-plugin-polished

Compile away polished helpers.

Example

In

import * as polished from 'polished';

let value = polished.clearFix();

Out

let value = {
  '&::after': {
    clear: 'both',
    content: '',
    display: 'table'
  }
};

Installation

$ npm install babel-plugin-polished

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["polished"]
}

Via CLI

$ babel --plugins polished script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["polished"]
});

babel-plugin-polished's People

Contributors

jamiebuilds avatar kitten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

babel-plugin-polished's Issues

Issues when integrating with istanbul

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.

Support dynamic values

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.

Plugin does not transform instances of a method when an argument is a non literal

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.

Confirmation of expected outcome from using this package

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?

Method does not exist: hideVisually

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.

Method does not exist: math

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

Plugin is incorrectly parsing intentional null values.

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.

Effectiveness of Library

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)};
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.