Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Commit

Permalink
fix: correctly handle style props
Browse files Browse the repository at this point in the history
  • Loading branch information
z0al committed Nov 29, 2020
1 parent a67767d commit 5873ac9
Show file tree
Hide file tree
Showing 15 changed files with 279 additions and 137 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"eslint-plugin-prettier": "^3.1.4",
"jest-expo": "^39.0.0",
"json.macro": "^1.3.0",
"prettier": "^2.2.0",
"prettier": "^2.2.1",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-native": "^0.63.3",
Expand All @@ -74,7 +74,7 @@
"rimraf": "^3.0.2",
"semantic-release": "^17.3.0",
"ts-node": "^9.0.0",
"type-fest": "^0.20.1",
"type-fest": "^0.20.2",
"typescript": "^4.1.2"
},
"peerDependencies": {
Expand Down
40 changes: 32 additions & 8 deletions src/__tests__/__snapshots__/samples.test.ts.snap.android
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { View } from 'react-native';
const Button = () => (
<View
{...{
style: _styles._default,
style: [_styles._default],
}}
/>
);
Expand Down Expand Up @@ -87,7 +87,7 @@ const _styles = _StyleSheet.create({
});

console.log({
style: _styles._default,
style: [_styles._default],
});


Expand Down Expand Up @@ -147,7 +147,7 @@ import { Text } from 'react-native';
const Heading = ({ text }) => (
<Text
{...{
style: _styles._default,
style: [_styles._default],
}}
>
{text}
Expand Down Expand Up @@ -224,17 +224,17 @@ export default function App() {
return (
<SafeAreaView
{...{
style: _styles._default,
style: [_styles._default],
}}
>
<Pressable
{...{
style: _styles._default2,
style: [_styles._default2],
}}
>
<Text
{...{
style: _styles._default3,
style: [_styles._default3],
}}
>
Press me
Expand Down Expand Up @@ -278,10 +278,34 @@ const bgWhite = 'bg-white';
const buttonStyle = [bgWhite, 'text-black'];
const inputStyle = [bgWhite, 'text-black'];
console.log({
style: _styles._default,
style: [_styles._default],
});
console.log({
style: _styles._default2,
style: [_styles._default2],
});


`;

exports[`babel-plugin-macros 8. babel-plugin-macros: 8. babel-plugin-macros 1`] = `

import styled from '../../build/module/macro.js';

console.log(styled(['bg-black', 'selectable']))

↓ ↓ ↓ ↓ ↓ ↓

import { StyleSheet as _StyleSheet } from 'react-native';

const _styles = _StyleSheet.create({
_default: {
backgroundColor: 'black',
},
});

console.log({
selectable: true,
style: [_styles._default],
});


Expand Down
40 changes: 32 additions & 8 deletions src/__tests__/__snapshots__/samples.test.ts.snap.ios
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { View } from 'react-native';
const Button = () => (
<View
{...{
style: _styles._default,
style: [_styles._default],
}}
/>
);
Expand Down Expand Up @@ -87,7 +87,7 @@ const _styles = _StyleSheet.create({
});

console.log({
style: _styles._default,
style: [_styles._default],
});


Expand Down Expand Up @@ -147,7 +147,7 @@ import { Text } from 'react-native';
const Heading = ({ text }) => (
<Text
{...{
style: _styles._default,
style: [_styles._default],
}}
>
{text}
Expand Down Expand Up @@ -224,17 +224,17 @@ export default function App() {
return (
<SafeAreaView
{...{
style: _styles._default,
style: [_styles._default],
}}
>
<Pressable
{...{
style: _styles._default2,
style: [_styles._default2],
}}
>
<Text
{...{
style: _styles._default3,
style: [_styles._default3],
}}
>
Press me
Expand Down Expand Up @@ -278,10 +278,34 @@ const bgWhite = 'bg-white';
const buttonStyle = [bgWhite, 'text-black'];
const inputStyle = [bgWhite, 'text-black'];
console.log({
style: _styles._default,
style: [_styles._default],
});
console.log({
style: _styles._default2,
style: [_styles._default2],
});


`;

exports[`babel-plugin-macros 8. babel-plugin-macros: 8. babel-plugin-macros 1`] = `

import styled from '../../build/module/macro.js';

console.log(styled(['bg-black', 'selectable']))

↓ ↓ ↓ ↓ ↓ ↓

import { StyleSheet as _StyleSheet } from 'react-native';

const _styles = _StyleSheet.create({
_default: {
backgroundColor: 'black',
},
});

console.log({
selectable: true,
style: [_styles._default],
});


Expand Down
40 changes: 32 additions & 8 deletions src/__tests__/__snapshots__/samples.test.ts.snap.node
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { View } from 'react-native';
const Button = () => (
<View
{...{
style: _styles._default,
style: [_styles._default],
}}
/>
);
Expand Down Expand Up @@ -87,7 +87,7 @@ const _styles = _StyleSheet.create({
});

console.log({
style: _styles._default,
style: [_styles._default],
});


Expand Down Expand Up @@ -147,7 +147,7 @@ import { Text } from 'react-native';
const Heading = ({ text }) => (
<Text
{...{
style: _styles._default,
style: [_styles._default],
}}
>
{text}
Expand Down Expand Up @@ -224,17 +224,17 @@ export default function App() {
return (
<SafeAreaView
{...{
style: _styles._default,
style: [_styles._default],
}}
>
<Pressable
{...{
style: _styles._default2,
style: [_styles._default2],
}}
>
<Text
{...{
style: _styles._default3,
style: [_styles._default3],
}}
>
Press me
Expand Down Expand Up @@ -278,10 +278,34 @@ const bgWhite = 'bg-white';
const buttonStyle = [bgWhite, 'text-black'];
const inputStyle = [bgWhite, 'text-black'];
console.log({
style: _styles._default,
style: [_styles._default],
});
console.log({
style: _styles._default2,
style: [_styles._default2],
});


`;

exports[`babel-plugin-macros 8. babel-plugin-macros: 8. babel-plugin-macros 1`] = `

import styled from '../../build/module/macro.js';

console.log(styled(['bg-black', 'selectable']))

↓ ↓ ↓ ↓ ↓ ↓

import { StyleSheet as _StyleSheet } from 'react-native';

const _styles = _StyleSheet.create({
_default: {
backgroundColor: 'black',
},
});

console.log({
selectable: true,
style: [_styles._default],
});


Expand Down
40 changes: 32 additions & 8 deletions src/__tests__/__snapshots__/samples.test.ts.snap.web
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { View } from 'react-native';
const Button = () => (
<View
{...{
style: _styles._default,
style: [_styles._default],
}}
/>
);
Expand Down Expand Up @@ -87,7 +87,7 @@ const _styles = _StyleSheet.create({
});

console.log({
style: _styles._default,
style: [_styles._default],
});


Expand Down Expand Up @@ -147,7 +147,7 @@ import { Text } from 'react-native';
const Heading = ({ text }) => (
<Text
{...{
style: _styles._default,
style: [_styles._default],
}}
>
{text}
Expand Down Expand Up @@ -224,17 +224,17 @@ export default function App() {
return (
<SafeAreaView
{...{
style: _styles._default,
style: [_styles._default],
}}
>
<Pressable
{...{
style: _styles._default2,
style: [_styles._default2],
}}
>
<Text
{...{
style: _styles._default3,
style: [_styles._default3],
}}
>
Press me
Expand Down Expand Up @@ -278,10 +278,34 @@ const bgWhite = 'bg-white';
const buttonStyle = [bgWhite, 'text-black'];
const inputStyle = [bgWhite, 'text-black'];
console.log({
style: _styles._default,
style: [_styles._default],
});
console.log({
style: _styles._default2,
style: [_styles._default2],
});


`;

exports[`babel-plugin-macros 8. babel-plugin-macros: 8. babel-plugin-macros 1`] = `

import styled from '../../build/module/macro.js';

console.log(styled(['bg-black', 'selectable']))

↓ ↓ ↓ ↓ ↓ ↓

import { StyleSheet as _StyleSheet } from 'react-native';

const _styles = _StyleSheet.create({
_default: {
backgroundColor: 'black',
},
});

console.log({
selectable: true,
style: [_styles._default],
});


Expand Down
5 changes: 5 additions & 0 deletions src/__tests__/samples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,10 @@ pluginTester({
console.log(styled(buttonStyle))
console.log(styled(inputStyle))
`,
`
import styled from '${macroPath}';
console.log(styled(['bg-black', 'selectable']))
`,
],
});

0 comments on commit 5873ac9

Please sign in to comment.