-
Notifications
You must be signed in to change notification settings - Fork 411
Expand file tree
/
Copy pathtypes.ts
More file actions
171 lines (144 loc) · 3.58 KB
/
types.ts
File metadata and controls
171 lines (144 loc) · 3.58 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import type {
Aliases,
Node,
Expression,
TaggedTemplateExpression,
} from '@babel/types';
import type { TransformOptions } from '@babel/core';
import type { NodePath } from '@babel/traverse';
import type { VisitorKeys } from '@babel/types';
import type { StyledMeta } from '../StyledMeta';
import { Preprocessor } from '../types';
export type JSONValue = string | number | boolean | JSONObject | JSONArray;
export interface JSONObject {
[x: string]: JSONValue;
}
export interface JSONArray extends Array<JSONValue> {}
export type Serializable = JSONArray | JSONObject;
export enum ValueType {
COMPONENT,
LAZY,
FUNCTION,
VALUE,
}
export type Value = Function | StyledMeta | string | number;
export type ValueCache = Map<Expression | string, Value>;
export type ComponentValue = {
kind: ValueType.COMPONENT;
ex: NodePath<Expression> | Expression | string;
};
export type LazyValue = {
kind: ValueType.LAZY;
ex: NodePath<Expression> | Expression | string;
originalEx: NodePath<Expression> | Expression | string;
};
export type FunctionValue = {
kind: ValueType.FUNCTION;
ex: any;
};
export type EvaluatedValue = {
kind: ValueType.VALUE;
value: Value;
};
export type ExpressionValue =
| ComponentValue
| LazyValue
| FunctionValue
| EvaluatedValue;
export type TemplateExpression = {
styled?: { component: any };
path: NodePath<TaggedTemplateExpression>;
expressionValues: ExpressionValue[];
};
type Rules = {
[selector: string]: {
className: string;
displayName: string;
cssText: string;
start: Location | null | undefined;
};
};
type Replacements = Array<{
original: {
start: Location;
end: Location;
};
length: number;
}>;
type Dependencies = string[];
export type State = {
queue: TemplateExpression[];
rules: Rules;
replacements: Replacements;
index: number;
dependencies: Dependencies;
file: {
opts: {
cwd: string;
root: string;
filename: string;
};
metadata: {
localName?: string;
linaria?: {
rules: Rules;
replacements: Replacements;
dependencies: Dependencies;
};
};
};
};
export type Evaluator = (
filename: string,
options: StrictOptions,
text: string,
only: string[] | null
) => [string, Map<string, string[]> | null];
export type EvalRule = {
test?: RegExp | ((path: string) => boolean);
action: Evaluator | 'ignore' | string;
};
type ClassNameFn = (hash: string, title: string) => string;
export type StrictOptions = {
classNameSlug?: string | ClassNameFn;
injectStyleTags: { preprocessor: Preprocessor } | true | false;
displayName: boolean;
evaluate: boolean;
ignore?: RegExp;
babelOptions: TransformOptions;
rules: EvalRule[];
};
export type Location = {
line: number;
column: number;
};
type AllNodes = { [T in Node['type']]: Extract<Node, { type: T }> };
declare module '@babel/types' {
type VisitorKeys = {
[T in keyof AllNodes]: Extract<
keyof AllNodes[T],
{
[Key in keyof AllNodes[T]]: AllNodes[T][Key] extends
| Node
| Node[]
| null
? Key
: never;
}[keyof AllNodes[T]]
>;
};
}
declare module '@babel/core' {
namespace types {
const VISITOR_KEYS: { [T in keyof VisitorKeys]: VisitorKeys[T][] };
const ALIAS_KEYS: {
[T in Node['type']]: {
[K in keyof Aliases]: AllNodes[T] extends Aliases[K] ? K : never;
}[keyof Aliases][];
};
const FLIPPED_ALIAS_KEYS: {
[T in keyof Aliases]: Aliases[T]['type'][];
};
function shallowEqual(actual: object, expected: object): boolean;
}
}