Skip to content

Commit

Permalink
Add support for spread attributes (patch) (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppeg authored and nkzawa committed Jan 20, 2017
1 parent c9b08d1 commit 8b71c70
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const STYLE_COMPONENT_ID = 'styleId'
const STYLE_COMPONENT_CSS = 'css'

export default function ({types: t}) {
const isGlobalEl = el => el.attributes.some(attr => (
attr.name.name === GLOBAL_ATTRIBUTE
const isGlobalEl = el => el.attributes.some(({name}) => (
name && name.name === GLOBAL_ATTRIBUTE
))

const isStyledJsx = ({node: el}) => (
Expand Down Expand Up @@ -93,8 +93,11 @@ export default function ({types: t}) {
name !== STYLE_COMPONENT &&
name.charAt(0) !== name.charAt(0).toUpperCase()
) {
for (const attr of el.attributes) {
if (attr.name === MARKUP_ATTRIBUTE || attr.name.name === MARKUP_ATTRIBUTE) {
for (const {name} of el.attributes) {
if (!name) {
continue
}
if (name === MARKUP_ATTRIBUTE || name.name === MARKUP_ATTRIBUTE) {
// avoid double attributes
return
}
Expand Down
6 changes: 5 additions & 1 deletion test/fixtures/multiple-jsx.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const attrs = {
id: 'test'
}

const Test1 = () => (
<div>
<span>test</span>
<span {...attrs} data-test="test">test</span>
<Component />
<style jsx>{`
span {
Expand Down
6 changes: 5 additions & 1 deletion test/fixtures/multiple-jsx.out.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import _JSXStyle from "styled-jsx/style";
const attrs = {
id: 'test'
};

const Test1 = () => <div data-jsx={1535297024}>
<span data-jsx={1535297024}>test</span>
<span {...attrs} data-test="test" data-jsx={1535297024}>test</span>
<Component />
<_JSXStyle styleId={1535297024} css={"span[data-jsx=\"1535297024\"] {color: red;}"} />
</div>;
Expand Down

0 comments on commit 8b71c70

Please sign in to comment.