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

SX: change imports/exports to allow composability #1352

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/babel-plugin-transform-sx-tailwind/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This has a positive impact on the final bundle size because the huge Tailwind de
```diff
import React from 'react';
- import { tailwind } from '@adeira/sx-tailwind';
+ import * as sx from '@adeira/sx';
+ import sx from '@adeira/sx';

export default function Example() {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function Example(): Node {

// @flow
import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
export default function Example(): Node {
return (
<span className={__styles_3xIUAp('flex', 'h-3', 'w-3')}>
Expand Down Expand Up @@ -127,7 +127,7 @@ export default function Example(): Node {

// @flow
import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
export default function Example(): Node {
return (
<>
Expand Down Expand Up @@ -186,7 +186,7 @@ export default function Example(): Node {

// @flow
import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
export default function Example(): Node {
return (
<div className={__styles_BKbxA('text-white', 'bg-black')}>
Expand Down Expand Up @@ -272,7 +272,7 @@ const styles = 'Here I am';

// @flow
import type { Element } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
export default function Example(): Element<'button'> {
return (
<button
Expand Down Expand Up @@ -315,7 +315,7 @@ exports[`transform SX Tailwind sx-already-imported.js: sx-already-imported.js 1`

import type { Node } from 'react';
import { tailwind } from '@adeira/sx-tailwind';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function Example(): Node {
return (
Expand All @@ -341,7 +341,7 @@ const styles = sx.create({

// @flow
import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
export default function Example(): Node {
return (
<div>
Expand Down Expand Up @@ -416,7 +416,7 @@ const styles = create({

// @flow
import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
import { create } from '@adeira/sx';
export default function Example(): Node {
return (
Expand Down Expand Up @@ -490,7 +490,7 @@ export default function Example(): Element<'button'> {

// @flow
import type { Element } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
export default function Example(): Element<'button'> {
return (
<button
Expand Down Expand Up @@ -574,7 +574,7 @@ export default function Example(): Element<'button'> {

// @flow
import type { Element } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
export default function Example(): Element<'button'> {
return (
<button
Expand Down Expand Up @@ -659,7 +659,7 @@ export default function Example(): Node {

// @flow
import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
export default function Example(): Node {
return (
<>
Expand Down Expand Up @@ -742,7 +742,7 @@ export default function Example(): Element<'button'> {

// @flow
import type { Element } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
export default function Example(): Element<'button'> {
return (
<button
Expand Down Expand Up @@ -799,7 +799,7 @@ export default function Example(): Element<'button'> {

// @flow
import type { Element } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
export default function Example(): Element<'button'> {
return (
<button
Expand Down Expand Up @@ -849,7 +849,7 @@ export default function Example(): Node {

// @flow
import React, { type Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
export default function Example(): Node {
return <div className={__styles_3noU6Y('text-black', 'bg-white')}>Lorem lipsum</div>;
}
Expand Down Expand Up @@ -892,7 +892,7 @@ export default function Example(): Node {

// @flow
import React, { type Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
export default function Example(): Node {
const darkMode = true;
return (
Expand Down Expand Up @@ -947,7 +947,7 @@ exports[`transform SX Tailwind template-literal-expression.js: template-literal-

import React, { type Node } from 'react';
import { tailwind } from '@adeira/sx-tailwind';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function Example(): Node {
return <div className={\`\${tailwind('px-4')} \${styles('customStyle')}\`}>Lorem lipsum</div>;
Expand All @@ -961,7 +961,7 @@ const styles = sx.create({

// @flow
import React, { type Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
export default function Example(): Node {
return <div className={\`\${__styles_4ozVnl('px-4')} \${styles('customStyle')}\`}>Lorem lipsum</div>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import type { Node } from 'react';
import { tailwind } from '@adeira/sx-tailwind';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function Example(): Node {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import React, { type Node } from 'react';
import { tailwind } from '@adeira/sx-tailwind';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function Example(): Node {
return <div className={`${tailwind('px-4')} ${styles('customStyle')}`}>Lorem lipsum</div>;
Expand Down
4 changes: 2 additions & 2 deletions src/babel-plugin-transform-sx-tailwind/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = function sxTailwindBabelPlugin() /*: any */ {
}
});

const sxImport = template.ast(`import * as sx from '@adeira/sx'`);
const sxImport = template.ast(`import sx from '@adeira/sx'`);
path.replaceWith(sxImport);
}
},
Expand Down Expand Up @@ -100,7 +100,7 @@ module.exports = function sxTailwindBabelPlugin() /*: any */ {
type === 'ImportDeclaration' &&
source.value === '@adeira/sx' &&
Array.isArray(specifiers) &&
specifiers[0].type === 'ImportNamespaceSpecifier'
specifiers[0].type === 'ImportDefaultSpecifier'
) {
a.push(index);
}
Expand Down
6 changes: 3 additions & 3 deletions src/eslint-plugin-sx/docs/rules/no-unused-stylesheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This rule aims to find unused SX stylesheet definitions.
Examples of **incorrect** code for this rule:

```jsx
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function MyComponent() {
return null;
Expand All @@ -20,7 +20,7 @@ const styles = sx.create({
```

```jsx
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function MyComponent() {
return <div className={styles('aaa')} />;
Expand All @@ -36,7 +36,7 @@ const styles = sx.create({
Examples of **correct** code for this rule:

```jsx
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function MyComponent() {
return <div className={styles('aaa')} />;
Expand Down
2 changes: 1 addition & 1 deletion src/eslint-plugin-sx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"jest-docblock": "^26.0.0"
},
"peerDependencies": {
"@adeira/sx": "^0.20.0"
"@adeira/sx": "^0.21.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`reports correct lines and columns: SX function "styles" was not used anywhere in the "className" JSX attribute. 1`] = `
" 1 |
2 | import * as sx from '@adeira/sx';
2 | import sx from '@adeira/sx';
> 3 | const styles = sx.create({
| ^^^^^^^^^^^^^^^^^^^^
> 4 | aaa: {
Expand All @@ -17,7 +17,7 @@ exports[`reports correct lines and columns: SX function "styles" was not used an
`;

exports[`reports correct lines and columns: Unknown stylesheet used: bbb (not defined anywhere) 1`] = `
" 2 | import * as sx from '@adeira/sx';
" 2 | import sx from '@adeira/sx';
3 | export default function TestComponent() {
> 4 | return <div className={styles('bbb')} />
| ^^^^^
Expand All @@ -27,7 +27,7 @@ exports[`reports correct lines and columns: Unknown stylesheet used: bbb (not de
`;

exports[`reports correct lines and columns: Unused stylesheet: aaa (defined via "styles" variable) 1`] = `
" 2 | import * as sx from '@adeira/sx';
" 2 | import sx from '@adeira/sx';
3 | const styles = sx.create({
> 4 | aaa: {
| ^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`normalizes indent correctly 1`] = `
"
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
const styles = sx.create({
aaa: {
color: blue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { Node } from 'react';
import * as tada from '@adeira/sx';
import tada from '@adeira/sx';

export default function MyComponent(): Node {
// Should be:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @see https://github.com/adeira/universe/pull/1323
*/

import * as sx from '@adeira/sx';
import sx from '@adeira/sx';
import type { Node } from 'react'; // keep the import order exactly like this (first SX, second React)

export default function Navbar(): Node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function MyComponent(): Node {
// $FlowExpectedError[incompatible-call] - yadada is not defined in the stylesheet below
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function MyComponent(): Node {
return <div className={styles('aaa')} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function MyComponent(): Node {
return <div className={styles2('bbb')} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function Navbar(): Node {
// "styles" is essentially unused here since it's not used in "className"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function MyComponent(): Node {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

import type { Node } from 'react';
import * as tada from '@adeira/sx'; // eslint-disable-line no-unused-vars
import tada from '@adeira/sx'; // eslint-disable-line no-unused-vars

export default function MyComponent(): Node {
return styles('ok');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

import type { Node } from 'react';
import * as tada from '@adeira/sx';
import tada from '@adeira/sx';

export default function MyComponent(): Node {
return <div className={styles('aaa')} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function MyComponent(): Node {
// $FlowExpectedError[incompatible-call] wrong on purpose (see below)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function MyComponent(): Node {
// $FlowExpectedError[incompatible-call] for testing purposes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function MyComponent(): Node {
return <div className={styles('aaa')} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function MyComponent(): Node {
return <div className={styles('aaa')} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function MyComponent(): Node {
return <div className={styles('aaa')} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { Node } from 'react';
import * as sx from '@adeira/sx';
import sx from '@adeira/sx';

export default function MyComponent(): Node {
return <div className={styles('aaa')} />;
Expand Down
Loading