import { transform } from '../test-utils';
describe('rule hoisting', () => {
it('should hoist to the top of the module', () => {
const actual = transform(`
import '@compiled/react';
const Component = () => (
<>
hello world
hello world
>
);
`);
expect(actual).toMatchInlineSnapshot(`
"import * as React from "react";
import { ax, ix, CC, CS } from "@compiled/react/runtime";
const _2 = "._1wyb1tcg{font-size:24px}";
const _ = "._1wyb1fwx{font-size:12px}";
const Component = () => (
<>
{[_]}
{hello world
}
{[_2]}
{hello world
}
>
);
"
`);
});
it('should reuse rules already hoisted', () => {
const actual = transform(`
import '@compiled/react';
const Component = () => (
<>
hello world
hello world
>
);
`);
expect(actual).toMatchInlineSnapshot(`
"import * as React from "react";
import { ax, ix, CC, CS } from "@compiled/react/runtime";
const _ = "._1wyb1fwx{font-size:12px}";
const Component = () => (
<>
{[_]}
{hello world
}
{[_]}
{hello world
}
>
);
"
`);
});
});