Browse Source

Support multiple jsx block (components) per file (#45)

add-plugins-support
Giuseppe 8 years ago
committed by Guillermo Rauch
parent
commit
c365806140
  1. 4
      src/babel.js
  2. 27
      test/fixtures/multiple-jsx.js
  3. 16
      test/fixtures/multiple-jsx.out.js
  4. 6
      test/index.js

4
src/babel.js

@ -100,7 +100,9 @@ export default function ({types: t}) {
const styles = findStyles(path.node.children)
if (styles.length === 0) {
state.hasJSXStyle = false
if (state.file.hasJSXStyle) {
state.hasJSXStyle = false
}
return
}

27
test/fixtures/multiple-jsx.js

@ -0,0 +1,27 @@
const Test = () => <span>test</span>
const Test2 = () => (
<div>
<span>test</span>
<style jsx>{`
span {
color: red;
}
`}</style>
</div>
)
export default class {
render () {
return (
<div>
<p>test</p>
<style jsx>{`
p {
color: red;
}
`}</style>
</div>
)
}
}

16
test/fixtures/multiple-jsx.out.js

@ -0,0 +1,16 @@
import _JSXStyle from "styled-jsx/style";
const Test = () => <span>test</span>;
const Test2 = () => <div data-jsx={1535297024}>
<span data-jsx={1535297024}>test</span>
<_JSXStyle styleId={1535297024} css={"span[data-jsx=\"1535297024\"] {color: red;}"} />
</div>;
export default class {
render() {
return <div data-jsx={1891769468}>
<p data-jsx={1891769468}>test</p>
<_JSXStyle styleId={1891769468} css={"p[data-jsx=\"1891769468\"] {color: red;}"} />
</div>;
}
}

6
test/index.js

@ -65,3 +65,9 @@ test('mixed global and scoped', async t => {
const out = await read('./fixtures/mixed-global-scoped.out.js')
t.is(code, out.trim())
})
test('works with multiple jsx blocks', async t => {
const {code} = await transform('./fixtures/multiple-jsx.js')
const out = await read('./fixtures/multiple-jsx.out.js')
t.is(code, out.trim())
})

Loading…
Cancel
Save