Skip to content

Commit

Permalink
fix(core): remove unnecessary spread operators from css and cx (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anber committed Apr 11, 2021
1 parent 75f5d8d commit 50ea2d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
7 changes: 7 additions & 0 deletions packages/core/__tests__/cx.test.ts
@@ -0,0 +1,7 @@
import { cx } from '../src';

it('should filter falsy values', () => {
expect(cx('1', 'test', false, '2', 0, '', null, undefined, '3')).toBe(
'1 test 2 3'
);
});
14 changes: 9 additions & 5 deletions packages/core/src/css.ts
@@ -1,11 +1,15 @@
import type { CSSProperties } from './CSSProperties';
import type { StyledMeta } from './StyledMeta';

export default function css(
_strings: TemplateStringsArray,
..._exprs: Array<string | number | CSSProperties | StyledMeta>
): string {
type CSS = (
strings: TemplateStringsArray,
...exprs: Array<string | number | CSSProperties | StyledMeta>
) => string;

const css: CSS = () => {
throw new Error(
'Using the "css" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly.'
);
}
};

export default css;
10 changes: 7 additions & 3 deletions packages/core/src/cx.ts
@@ -1,5 +1,9 @@
export type ClassName = string | false | void | null | 0;

export default function cx(...classNames: ClassName[]): string {
return classNames.filter(Boolean).join(' ');
}
type CX = (...classNames: ClassName[]) => string;

const cx: CX = function cx() {
return Array.prototype.slice.call(arguments).filter(Boolean).join(' ');
};

export default cx;

0 comments on commit 50ea2d5

Please sign in to comment.