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

JSX transforms #3

Merged
merged 8 commits into from
Aug 7, 2018
Merged

JSX transforms #3

merged 8 commits into from
Aug 7, 2018

Conversation

danielberndt
Copy link
Collaborator

@danielberndt danielberndt commented Aug 5, 2018

This PR adds support for the <glamorous.Div> transforms. It uses the react-html-attributes package for identifying all valid html attributes on an component and considers all other attributes as styling properties.

  • gathers styling information into css property
  • uses react-html-attributes to distinguish html from css properties
  • add option flag to assume the presence of emotion-babel-plugin

@TejasQ
Copy link
Owner

TejasQ commented Aug 6, 2018

Awesome! Let's review and merge this as soon as #2 is merged.

@TejasQ
Copy link
Owner

TejasQ commented Aug 6, 2018

@danielberndt let's get this merged too 🚀

@danielberndt danielberndt changed the title [wip] JSX transforms JSX transforms Aug 6, 2018
@danielberndt danielberndt force-pushed the jsx branch 2 times, most recently from a16d1db to 96dda76 Compare August 6, 2018 15:59
@danielberndt
Copy link
Collaborator Author

I just added the withBabelPlugin option flag for you to review :)

index.js Outdated
const stylesArguments = [];
let classNameAttr = null;
let originalCssValue;
const newAttrs = jsxAttrs.filter(attr => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name newAttrs a bit more descriptively?

index.js Outdated
let newImports = [];
let useDefaultImport = false;
let emotionImports = {};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on what features are needed, we potentially need to import the default export or css or cx from react-emotion.
These imports are added to the code here

index.js Outdated
@@ -101,30 +180,45 @@ module.exports = function(babel) {
}

// use "styled" as new default import, only if there's no such variable in use yet
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this comment is not up to date anymore. I'll fix it

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielberndt looking forward to it

@danielberndt
Copy link
Collaborator Author

new update is in :)

index.js Outdated
@@ -47,7 +47,7 @@ module.exports = function(babel) {
const stylesArguments = [];
let classNameAttr = null;
let originalCssValue;
const newAttrs = jsxAttrs.filter(attr => {
const transformedJsxAttrs = jsxAttrs.filter(attr => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be a pain! But transformedJsxAttrs => transformed from what? A little

/**
  * this does this
  */

would be helpful

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we can merge it 🚀

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries :) Update is in.

Copy link
Owner

@TejasQ TejasQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So beautiful. The last few documentation finishing touches to polish it off and then we merge merge merge 🔥

README.md Outdated
@@ -19,6 +19,21 @@ You'll need to use [`babel-codemod`](https://github.com/square/babel-codemod) to

This will put you fully in emotion-land.

### Options

you may also pass a `--plugin-options` argument to the `babel-codemod` command. Here are the available options:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-you
+You

README.md Outdated

- **`withBabelPlugin=true`**

assumes that your emotion setup includes the [emotion-babel-plugin](https://github.com/emotion-js/emotion/tree/master/packages/babel-plugin-emotion). Without this option, `<glamorous.Div marginTop={5}/>` gets translated to `<div className={css({marginTop: 5})}>`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-assumes
+Tells the plugin

README.md Outdated

- **`preact=true`**

Uses `import styled from preact-emotion` instead of `import styled from react-emotion`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-from preact-emotion
+from "preact-emotion"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all done!

@TejasQ TejasQ merged commit c63628f into TejasQ:master Aug 7, 2018
@TejasQ
Copy link
Owner

TejasQ commented Aug 7, 2018

@danielberndt you rock so hard it's unreal. ⛰

@TejasQ
Copy link
Owner

TejasQ commented Aug 7, 2018

I think you should go over here and tell everyone what's available now. 😉

@danielberndt
Copy link
Collaborator Author

Haha, good point! Done 👍

@danielberndt danielberndt deleted the jsx branch August 7, 2018 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants