1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
import { run } from '@linaria/babel-preset/__utils__/strategy-tester';
import dedent from 'dedent';
describe('shaker', () => {
run(__dirname, require('../src').default, (transpile) => {
it('should work with wildcard imports', async () => {
const { code, metadata } = await transpile(
dedent`
import { css } from "@linaria/core";
import * as mod from "@linaria/babel-preset/__fixtures__/complex-component";
const color = mod["whiteColor"];
export const square = css\`
${'${mod.Title}'} {
color: ${'${color}'};
}
\`;
`
);
expect(code).toMatchSnapshot();
expect(metadata).toMatchSnapshot();
});
it('should work with wildcard reexports', async () => {
const { code, metadata } = await transpile(
dedent`
import { css } from "@linaria/core";
import { foo1 } from "../__fixtures__/reexports";
export const square = css\`
color: ${'${foo1}'};
\`;
`
);
expect(code).toMatchSnapshot();
expect(metadata).toMatchSnapshot();
});
it('should interpolate imported components', async () => {
const { code, metadata } = await transpile(
dedent`
import { css } from "@linaria/core";
import { Title } from "@linaria/babel-preset/__fixtures__/complex-component";
export const square = css\`
${'${Title}'} {
color: red;
}
\`;
`
);
expect(code).toMatchSnapshot();
expect(metadata).toMatchSnapshot();
});
it('should interpolate imported variables', async () => {
const { code, metadata } = await transpile(
dedent`
import { css } from "@linaria/core";
import { whiteColor } from "@linaria/babel-preset/__fixtures__/complex-component";
export const square = css\`
color: ${'${whiteColor}'}
\`;
`
);
expect(code).toMatchSnapshot();
expect(metadata).toMatchSnapshot();
});
it('evaluates typescript enums', async () => {
const { code, metadata } = await transpile(
dedent`
import { styled } from '@linaria/react';
enum Colors {
BLUE = '#27509A'
}
export const Title = styled.h1\`
color: ${'${Colors.BLUE}'};
\`;
`,
(config) => ({
...config,
presets: ['@babel/preset-typescript', ...(config.presets ?? [])],
filename: 'source.ts',
})
);
expect(code).toMatchSnapshot();
expect(metadata).toMatchSnapshot();
});
});
});
|