@bamboocss/extractor 1.12.1 → 1.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.cts +303 -0
- package/dist/index.d.mts +303 -0
- package/package.json +2 -2
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { BindingElement, CallExpression, EnumDeclaration, Expression, FunctionDeclaration, GetAccessorDeclaration, Identifier, JsxAttribute, JsxOpeningElement, JsxSelfClosingElement, JsxSpreadAttribute, Node, ParameterDeclaration, PropertyAssignment, ShorthandPropertyAssignment, SourceFile, TaggedTemplateExpression, VariableDeclaration } from "ts-morph";
|
|
2
|
+
import { EvaluateOptions as EvaluateOptions$1 } from "ts-evaluator";
|
|
3
|
+
|
|
4
|
+
//#region src/box-factory.d.ts
|
|
5
|
+
interface WithNode {
|
|
6
|
+
node: Node;
|
|
7
|
+
stack: Node[];
|
|
8
|
+
}
|
|
9
|
+
interface ObjectType extends WithNode {
|
|
10
|
+
type: 'object';
|
|
11
|
+
value: EvaluatedObjectResult;
|
|
12
|
+
isEmpty?: boolean;
|
|
13
|
+
}
|
|
14
|
+
type LiteralKind = 'array' | 'string' | 'number' | 'boolean' | 'null' | 'undefined';
|
|
15
|
+
interface LiteralType extends WithNode {
|
|
16
|
+
type: 'literal';
|
|
17
|
+
value: PrimitiveType;
|
|
18
|
+
kind: LiteralKind;
|
|
19
|
+
}
|
|
20
|
+
interface MapType extends WithNode {
|
|
21
|
+
type: 'map';
|
|
22
|
+
value: MapTypeValue;
|
|
23
|
+
}
|
|
24
|
+
interface ArrayType extends WithNode {
|
|
25
|
+
type: 'array';
|
|
26
|
+
value: BoxNode[];
|
|
27
|
+
}
|
|
28
|
+
interface UnresolvableType extends WithNode {
|
|
29
|
+
type: 'unresolvable';
|
|
30
|
+
}
|
|
31
|
+
interface ConditionalType extends WithNode {
|
|
32
|
+
type: 'conditional';
|
|
33
|
+
whenTrue: BoxNode;
|
|
34
|
+
whenFalse: BoxNode;
|
|
35
|
+
}
|
|
36
|
+
/** -> Jsx boolean attribute <Box flex /> */
|
|
37
|
+
interface EmptyInitializerType extends WithNode {
|
|
38
|
+
type: 'empty-initializer';
|
|
39
|
+
}
|
|
40
|
+
type BoxNodeDefinition = ObjectType | LiteralType | MapType | ArrayType | UnresolvableType | ConditionalType | EmptyInitializerType;
|
|
41
|
+
type BoxNode = BoxNodeObject | BoxNodeLiteral | BoxNodeMap | BoxNodeArray | BoxNodeUnresolvable | BoxNodeConditional | BoxNodeEmptyInitializer;
|
|
42
|
+
type MapTypeValue = Map<string, BoxNode>;
|
|
43
|
+
declare abstract class BoxNodeType$1<Definition extends BoxNodeDefinition = BoxNodeDefinition> {
|
|
44
|
+
readonly type: Definition['type'];
|
|
45
|
+
private readonly stack;
|
|
46
|
+
private readonly node;
|
|
47
|
+
constructor(definition: Definition);
|
|
48
|
+
getNode(): Node;
|
|
49
|
+
getStack(): Node[];
|
|
50
|
+
getRange: () => {
|
|
51
|
+
startPosition: number;
|
|
52
|
+
startLineNumber: number;
|
|
53
|
+
startColumn: number;
|
|
54
|
+
endPosition: number;
|
|
55
|
+
endLineNumber: number;
|
|
56
|
+
endColumn: number;
|
|
57
|
+
};
|
|
58
|
+
toJSON(): {
|
|
59
|
+
type: Definition["type"];
|
|
60
|
+
value: any;
|
|
61
|
+
node: string;
|
|
62
|
+
line: number;
|
|
63
|
+
column: number;
|
|
64
|
+
endLineNumber: number;
|
|
65
|
+
endColumn: number;
|
|
66
|
+
};
|
|
67
|
+
toString(): string;
|
|
68
|
+
}
|
|
69
|
+
declare class BoxNodeObject extends BoxNodeType$1<ObjectType> {
|
|
70
|
+
value: ObjectType['value'];
|
|
71
|
+
isEmpty: ObjectType['isEmpty'];
|
|
72
|
+
constructor(definition: ObjectType);
|
|
73
|
+
}
|
|
74
|
+
declare class BoxNodeLiteral extends BoxNodeType$1<LiteralType> {
|
|
75
|
+
value: LiteralType['value'];
|
|
76
|
+
kind: LiteralType['kind'];
|
|
77
|
+
constructor(definition: LiteralType);
|
|
78
|
+
}
|
|
79
|
+
declare class BoxNodeMap extends BoxNodeType$1<MapType> {
|
|
80
|
+
value: MapType['value'];
|
|
81
|
+
spreadConditions?: BoxNodeConditional[];
|
|
82
|
+
constructor(definition: MapType);
|
|
83
|
+
isRecipe: () => boolean;
|
|
84
|
+
}
|
|
85
|
+
declare class BoxNodeArray extends BoxNodeType$1<ArrayType> {
|
|
86
|
+
value: ArrayType['value'];
|
|
87
|
+
constructor(definition: ArrayType);
|
|
88
|
+
}
|
|
89
|
+
declare class BoxNodeUnresolvable extends BoxNodeType$1<UnresolvableType> {}
|
|
90
|
+
declare class BoxNodeConditional extends BoxNodeType$1<ConditionalType> {
|
|
91
|
+
whenTrue: ConditionalType['whenTrue'];
|
|
92
|
+
whenFalse: ConditionalType['whenFalse'];
|
|
93
|
+
constructor(definition: ConditionalType);
|
|
94
|
+
}
|
|
95
|
+
declare class BoxNodeEmptyInitializer extends BoxNodeType$1<EmptyInitializerType> {}
|
|
96
|
+
declare const isBoxNode: (value: unknown) => value is BoxNode;
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/types.d.ts
|
|
99
|
+
type PrimitiveType = string | number | boolean | null | undefined;
|
|
100
|
+
interface LiteralObject {
|
|
101
|
+
[key: string]: any;
|
|
102
|
+
}
|
|
103
|
+
type SingleLiteralValue = PrimitiveType | LiteralObject;
|
|
104
|
+
type LiteralValue = SingleLiteralValue | SingleLiteralValue[];
|
|
105
|
+
interface EvaluatedObjectResult {
|
|
106
|
+
[key: string]: LiteralValue;
|
|
107
|
+
}
|
|
108
|
+
interface ExtractedFunctionInstance {
|
|
109
|
+
name: string;
|
|
110
|
+
kind: 'call-expression';
|
|
111
|
+
fromNode: () => CallExpression;
|
|
112
|
+
box: BoxNodeArray;
|
|
113
|
+
}
|
|
114
|
+
interface ExtractedTaggedTemplateInstance {
|
|
115
|
+
name: string;
|
|
116
|
+
kind: 'tagged-template';
|
|
117
|
+
fromNode: () => TaggedTemplateExpression;
|
|
118
|
+
box: BoxNodeLiteral;
|
|
119
|
+
}
|
|
120
|
+
interface ExtractedFunctionResult {
|
|
121
|
+
kind: 'function';
|
|
122
|
+
nodesByProp: Map<string, BoxNode[]>;
|
|
123
|
+
queryList: Array<ExtractedFunctionInstance | ExtractedTaggedTemplateInstance>;
|
|
124
|
+
}
|
|
125
|
+
interface ExtractedComponentInstance {
|
|
126
|
+
name: string;
|
|
127
|
+
fromNode: () => JsxOpeningElement | JsxSelfClosingElement | CallExpression;
|
|
128
|
+
box: BoxNodeMap;
|
|
129
|
+
}
|
|
130
|
+
interface ExtractedComponentResult {
|
|
131
|
+
kind: 'component';
|
|
132
|
+
nodesByProp: Map<string, BoxNode[]>;
|
|
133
|
+
queryList: ExtractedComponentInstance[];
|
|
134
|
+
}
|
|
135
|
+
type ExtractResultItem = ExtractedComponentResult | ExtractedFunctionResult;
|
|
136
|
+
type ExtractResultByName = Map<string, ExtractResultItem>;
|
|
137
|
+
interface MatchTagArgs {
|
|
138
|
+
tagName: string;
|
|
139
|
+
tagNode: JsxOpeningElement | JsxSelfClosingElement | CallExpression;
|
|
140
|
+
isFactory: boolean;
|
|
141
|
+
}
|
|
142
|
+
interface MatchPropArgs {
|
|
143
|
+
propName: string;
|
|
144
|
+
propNode: JsxAttribute | PropertyAssignment | ShorthandPropertyAssignment | GetAccessorDeclaration | undefined;
|
|
145
|
+
}
|
|
146
|
+
interface MatchFnArgs {
|
|
147
|
+
fnName: string;
|
|
148
|
+
fnNode: CallExpression;
|
|
149
|
+
}
|
|
150
|
+
interface MatchFnArguments {
|
|
151
|
+
argNode: Node;
|
|
152
|
+
index: number;
|
|
153
|
+
}
|
|
154
|
+
interface MatchFnPropArgs {
|
|
155
|
+
propName: string;
|
|
156
|
+
propNode: PropertyAssignment | ShorthandPropertyAssignment | GetAccessorDeclaration;
|
|
157
|
+
}
|
|
158
|
+
interface FunctionMatchers {
|
|
159
|
+
matchFn: (element: MatchFnArgs) => boolean;
|
|
160
|
+
matchArg: (arg: Pick<MatchFnArgs, 'fnName' | 'fnNode'> & MatchFnArguments) => boolean;
|
|
161
|
+
matchProp: (prop: Pick<MatchFnArgs, 'fnName' | 'fnNode'> & MatchFnPropArgs) => boolean;
|
|
162
|
+
}
|
|
163
|
+
interface ComponentMatchers {
|
|
164
|
+
matchTag: (element: MatchTagArgs) => boolean;
|
|
165
|
+
matchProp: (prop: Pick<MatchTagArgs, 'tagName' | 'tagNode'> & MatchPropArgs) => boolean;
|
|
166
|
+
}
|
|
167
|
+
interface MatchTaggedTemplateArgs {
|
|
168
|
+
fnName: string;
|
|
169
|
+
taggedTemplateNode: TaggedTemplateExpression;
|
|
170
|
+
}
|
|
171
|
+
type MatchTaggedTemplate = (tag: MatchTaggedTemplateArgs) => boolean;
|
|
172
|
+
interface BoxContext {
|
|
173
|
+
getEvaluateOptions?: (node: Expression, stack: Node[]) => Omit<EvaluateOptions, 'node' | 'policy'> | void;
|
|
174
|
+
canEval?: (node: Expression, stack: Node[]) => boolean;
|
|
175
|
+
tokens?: {
|
|
176
|
+
view: {
|
|
177
|
+
get: (path: string, fallback?: string | number) => string | undefined;
|
|
178
|
+
getVar: (path: string, fallback?: string | number) => string | undefined;
|
|
179
|
+
};
|
|
180
|
+
isTokenFn?: (fnName: string) => boolean;
|
|
181
|
+
};
|
|
182
|
+
flags?: {
|
|
183
|
+
skipEvaluate?: boolean;
|
|
184
|
+
skipTraverseFiles?: boolean;
|
|
185
|
+
skipConditions?: boolean;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
type EvaluateOptions = Omit<EvaluateOptions$1, 'node' | 'policy'>;
|
|
189
|
+
type ExtractOptions = BoxContext & {
|
|
190
|
+
ast: SourceFile;
|
|
191
|
+
components?: ComponentMatchers;
|
|
192
|
+
functions?: FunctionMatchers;
|
|
193
|
+
taggedTemplates?: {
|
|
194
|
+
matchTaggedTemplate: MatchTaggedTemplate;
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/to-box-node.d.ts
|
|
199
|
+
declare function toBoxNode<Value extends PrimitiveType>(value: Value, node: Node, stack: Node[]): BoxNodeLiteral;
|
|
200
|
+
declare function toBoxNode<Value extends EvaluatedObjectResult>(value: Value, node: Node, stack: Node[]): BoxNodeObject;
|
|
201
|
+
declare function toBoxNode<Value extends PrimitiveType[]>(value: Value, node: Node, stack: Node[]): BoxNodeLiteral[];
|
|
202
|
+
declare function toBoxNode<Value extends BoxNode | BoxNode[]>(value: Value, node: Node, stack: Node[]): Value;
|
|
203
|
+
declare function toBoxNode<Value extends LiteralValue>(value: Value, node: Node, stack: Node[]): Value extends unknown[] ? BoxNodeLiteral : Value extends PrimitiveType ? BoxNodeLiteral : BoxNodeObject;
|
|
204
|
+
declare function toBoxNode<Value extends PrimitiveType | BoxNode>(value: Value, node: Node, stack: Node[]): BoxNodeLiteral;
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/box.d.ts
|
|
207
|
+
declare const box: {
|
|
208
|
+
object(value: EvaluatedObjectResult, node: Node, stack: Node[]): BoxNodeObject;
|
|
209
|
+
literal(value: PrimitiveType, node: Node, stack: Node[]): BoxNodeLiteral;
|
|
210
|
+
map(value: MapTypeValue, node: Node, stack: Node[]): BoxNodeMap;
|
|
211
|
+
array(value: BoxNode[], node: Node, stack: Node[]): BoxNodeArray;
|
|
212
|
+
conditional(whenTrue: BoxNode, whenFalse: BoxNode, node: Node, stack: Node[]): BoxNodeConditional;
|
|
213
|
+
from: typeof toBoxNode;
|
|
214
|
+
objectToMap: (value: Record<string, unknown>, node: Node, stack: Node[]) => BoxNodeMap;
|
|
215
|
+
emptyObject: (node: Node, stack: Node[]) => BoxNodeObject;
|
|
216
|
+
emptyInitializer: (node: Node, stack: Node[]) => BoxNodeEmptyInitializer;
|
|
217
|
+
unresolvable: (node: Node, stack: Node[]) => BoxNodeUnresolvable;
|
|
218
|
+
fallback(node: BoxNode): BoxNode;
|
|
219
|
+
/**
|
|
220
|
+
* box.type === “object” -> object that was resolved using ts-evaluator, most likely from a
|
|
221
|
+
* complex condition OR a simple CallExpression eval result, we don’t have access to individual
|
|
222
|
+
* AST nodes here so we need the distinction
|
|
223
|
+
*/
|
|
224
|
+
isObject(value: BoxNode | undefined): value is BoxNodeObject;
|
|
225
|
+
isLiteral(value: BoxNode | undefined): value is BoxNodeLiteral;
|
|
226
|
+
/**
|
|
227
|
+
* box.type === “map” -> basically any object that was statically analyzable, we store each
|
|
228
|
+
* prop + value in a Map
|
|
229
|
+
*/
|
|
230
|
+
isMap(value: BoxNode | undefined): value is BoxNodeMap;
|
|
231
|
+
isRecipe(value: BoxNode | undefined): value is BoxNodeMap;
|
|
232
|
+
isArray(value: BoxNode | undefined): value is BoxNodeArray;
|
|
233
|
+
isUnresolvable(value: BoxNode | undefined): value is BoxNodeUnresolvable;
|
|
234
|
+
isConditional(value: BoxNode | undefined): value is BoxNodeConditional;
|
|
235
|
+
isEmptyInitializer(value: BoxNode | undefined): value is BoxNodeEmptyInitializer;
|
|
236
|
+
isNumberLiteral(node: BoxNode | undefined): node is BoxNodeLiteral;
|
|
237
|
+
hasValue: (node: BoxNode | undefined) => node is BoxNodeLiteral | BoxNodeObject | BoxNodeMap | BoxNodeArray;
|
|
238
|
+
};
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/call-expression.d.ts
|
|
241
|
+
type MatchProp$1 = (prop: MatchFnPropArgs) => boolean;
|
|
242
|
+
type MatchArg = (prop: MatchFnArgs & MatchFnArguments) => boolean;
|
|
243
|
+
declare const extractCallExpressionArguments: (node: CallExpression, ctx: BoxContext, matchProp?: MatchProp$1, matchArg?: MatchArg) => BoxNodeArray;
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region src/extract.d.ts
|
|
246
|
+
declare const extract: ({
|
|
247
|
+
ast,
|
|
248
|
+
...ctx
|
|
249
|
+
}: ExtractOptions) => ExtractResultByName;
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/find-identifier-value-declaration.d.ts
|
|
252
|
+
declare function getDeclarationFor(node: Identifier, stack: Node[], ctx: BoxContext): VariableDeclaration | ParameterDeclaration | FunctionDeclaration | EnumDeclaration | BindingElement | undefined;
|
|
253
|
+
declare function findIdentifierValueDeclaration(identifier: Identifier, stack: Node[], ctx: BoxContext, visitedsWithStack?: WeakMap<Node, Node[]>): ReturnType<typeof getDeclarationFor> | undefined;
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/get-node-range.d.ts
|
|
256
|
+
declare const getNodeRange: (node: Node) => {
|
|
257
|
+
startPosition: number;
|
|
258
|
+
startLineNumber: number;
|
|
259
|
+
startColumn: number;
|
|
260
|
+
endPosition: number;
|
|
261
|
+
endLineNumber: number;
|
|
262
|
+
endColumn: number;
|
|
263
|
+
};
|
|
264
|
+
type NodeRange = ReturnType<typeof getNodeRange>;
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/jsx-attribute.d.ts
|
|
267
|
+
declare const extractJsxAttribute: (jsxAttribute: JsxAttribute, ctx: BoxContext) => BoxNode | undefined;
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region src/jsx-element-props.d.ts
|
|
270
|
+
declare const extractJsxElementProps: (node: JsxOpeningElement | JsxSelfClosingElement, ctx: BoxContext) => {
|
|
271
|
+
name: string;
|
|
272
|
+
props: Map<string, BoxNode>;
|
|
273
|
+
};
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/maybe-box-node.d.ts
|
|
276
|
+
type MaybeBoxNodeReturn = BoxNode | undefined;
|
|
277
|
+
declare function maybeBoxNode(node: Node, stack: Node[], ctx: BoxContext, matchProp?: (prop: MatchFnPropArgs) => boolean): MaybeBoxNodeReturn;
|
|
278
|
+
declare const maybeIdentifierValue: (identifier: Identifier, _stack: Node[], ctx: BoxContext) => BoxNode;
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/jsx-spread-attribute.d.ts
|
|
281
|
+
type MatchProp = (prop: MatchFnPropArgs | MatchPropArgs) => boolean;
|
|
282
|
+
declare const extractJsxSpreadAttributeValues: (node: JsxSpreadAttribute, ctx: BoxContext, matchProp: MatchProp) => MaybeBoxNodeReturn;
|
|
283
|
+
//#endregion
|
|
284
|
+
//#region src/unbox.d.ts
|
|
285
|
+
type BoxNodeType = BoxNode | BoxNode[] | undefined;
|
|
286
|
+
type CacheMap = WeakMap<BoxNode, Unboxed>;
|
|
287
|
+
interface UnboxContext {
|
|
288
|
+
path: string[];
|
|
289
|
+
parent: BoxNode | undefined;
|
|
290
|
+
cache: CacheMap;
|
|
291
|
+
/** @example <ColorBox color={unresolvableIdentifier ? "light.100" : "dark.200" } /> */
|
|
292
|
+
conditions: LiteralObject[];
|
|
293
|
+
/** @example <ColorBox {...(someCondition && { color: "blue.100" })} /> */
|
|
294
|
+
spreadConditions: LiteralObject[];
|
|
295
|
+
}
|
|
296
|
+
interface Unboxed {
|
|
297
|
+
raw: LiteralObject;
|
|
298
|
+
conditions: LiteralObject[];
|
|
299
|
+
spreadConditions: LiteralObject[];
|
|
300
|
+
}
|
|
301
|
+
declare const unbox: (node: BoxNodeType, ctx?: Pick<UnboxContext, "cache">) => Unboxed;
|
|
302
|
+
//#endregion
|
|
303
|
+
export { type BoxContext, type BoxNode, BoxNodeArray, BoxNodeConditional, BoxNodeEmptyInitializer, BoxNodeLiteral, BoxNodeMap, BoxNodeObject, BoxNodeUnresolvable, type EvaluateOptions, type ExtractOptions, type ExtractResultByName, type ExtractResultItem, type ExtractedComponentInstance, type ExtractedComponentResult, type ExtractedFunctionInstance, type ExtractedFunctionResult, type NodeRange, type PrimitiveType, type Unboxed, box, extract, extractCallExpressionArguments, extractJsxAttribute, extractJsxElementProps, extractJsxSpreadAttributeValues, findIdentifierValueDeclaration, isBoxNode, maybeBoxNode, maybeIdentifierValue, unbox };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { BindingElement, CallExpression, EnumDeclaration, Expression, FunctionDeclaration, GetAccessorDeclaration, Identifier, JsxAttribute, JsxOpeningElement, JsxSelfClosingElement, JsxSpreadAttribute, Node, ParameterDeclaration, PropertyAssignment, ShorthandPropertyAssignment, SourceFile, TaggedTemplateExpression, VariableDeclaration } from "ts-morph";
|
|
2
|
+
import { EvaluateOptions as EvaluateOptions$1 } from "ts-evaluator";
|
|
3
|
+
|
|
4
|
+
//#region src/box-factory.d.ts
|
|
5
|
+
interface WithNode {
|
|
6
|
+
node: Node;
|
|
7
|
+
stack: Node[];
|
|
8
|
+
}
|
|
9
|
+
interface ObjectType extends WithNode {
|
|
10
|
+
type: 'object';
|
|
11
|
+
value: EvaluatedObjectResult;
|
|
12
|
+
isEmpty?: boolean;
|
|
13
|
+
}
|
|
14
|
+
type LiteralKind = 'array' | 'string' | 'number' | 'boolean' | 'null' | 'undefined';
|
|
15
|
+
interface LiteralType extends WithNode {
|
|
16
|
+
type: 'literal';
|
|
17
|
+
value: PrimitiveType;
|
|
18
|
+
kind: LiteralKind;
|
|
19
|
+
}
|
|
20
|
+
interface MapType extends WithNode {
|
|
21
|
+
type: 'map';
|
|
22
|
+
value: MapTypeValue;
|
|
23
|
+
}
|
|
24
|
+
interface ArrayType extends WithNode {
|
|
25
|
+
type: 'array';
|
|
26
|
+
value: BoxNode[];
|
|
27
|
+
}
|
|
28
|
+
interface UnresolvableType extends WithNode {
|
|
29
|
+
type: 'unresolvable';
|
|
30
|
+
}
|
|
31
|
+
interface ConditionalType extends WithNode {
|
|
32
|
+
type: 'conditional';
|
|
33
|
+
whenTrue: BoxNode;
|
|
34
|
+
whenFalse: BoxNode;
|
|
35
|
+
}
|
|
36
|
+
/** -> Jsx boolean attribute <Box flex /> */
|
|
37
|
+
interface EmptyInitializerType extends WithNode {
|
|
38
|
+
type: 'empty-initializer';
|
|
39
|
+
}
|
|
40
|
+
type BoxNodeDefinition = ObjectType | LiteralType | MapType | ArrayType | UnresolvableType | ConditionalType | EmptyInitializerType;
|
|
41
|
+
type BoxNode = BoxNodeObject | BoxNodeLiteral | BoxNodeMap | BoxNodeArray | BoxNodeUnresolvable | BoxNodeConditional | BoxNodeEmptyInitializer;
|
|
42
|
+
type MapTypeValue = Map<string, BoxNode>;
|
|
43
|
+
declare abstract class BoxNodeType$1<Definition extends BoxNodeDefinition = BoxNodeDefinition> {
|
|
44
|
+
readonly type: Definition['type'];
|
|
45
|
+
private readonly stack;
|
|
46
|
+
private readonly node;
|
|
47
|
+
constructor(definition: Definition);
|
|
48
|
+
getNode(): Node;
|
|
49
|
+
getStack(): Node[];
|
|
50
|
+
getRange: () => {
|
|
51
|
+
startPosition: number;
|
|
52
|
+
startLineNumber: number;
|
|
53
|
+
startColumn: number;
|
|
54
|
+
endPosition: number;
|
|
55
|
+
endLineNumber: number;
|
|
56
|
+
endColumn: number;
|
|
57
|
+
};
|
|
58
|
+
toJSON(): {
|
|
59
|
+
type: Definition["type"];
|
|
60
|
+
value: any;
|
|
61
|
+
node: string;
|
|
62
|
+
line: number;
|
|
63
|
+
column: number;
|
|
64
|
+
endLineNumber: number;
|
|
65
|
+
endColumn: number;
|
|
66
|
+
};
|
|
67
|
+
toString(): string;
|
|
68
|
+
}
|
|
69
|
+
declare class BoxNodeObject extends BoxNodeType$1<ObjectType> {
|
|
70
|
+
value: ObjectType['value'];
|
|
71
|
+
isEmpty: ObjectType['isEmpty'];
|
|
72
|
+
constructor(definition: ObjectType);
|
|
73
|
+
}
|
|
74
|
+
declare class BoxNodeLiteral extends BoxNodeType$1<LiteralType> {
|
|
75
|
+
value: LiteralType['value'];
|
|
76
|
+
kind: LiteralType['kind'];
|
|
77
|
+
constructor(definition: LiteralType);
|
|
78
|
+
}
|
|
79
|
+
declare class BoxNodeMap extends BoxNodeType$1<MapType> {
|
|
80
|
+
value: MapType['value'];
|
|
81
|
+
spreadConditions?: BoxNodeConditional[];
|
|
82
|
+
constructor(definition: MapType);
|
|
83
|
+
isRecipe: () => boolean;
|
|
84
|
+
}
|
|
85
|
+
declare class BoxNodeArray extends BoxNodeType$1<ArrayType> {
|
|
86
|
+
value: ArrayType['value'];
|
|
87
|
+
constructor(definition: ArrayType);
|
|
88
|
+
}
|
|
89
|
+
declare class BoxNodeUnresolvable extends BoxNodeType$1<UnresolvableType> {}
|
|
90
|
+
declare class BoxNodeConditional extends BoxNodeType$1<ConditionalType> {
|
|
91
|
+
whenTrue: ConditionalType['whenTrue'];
|
|
92
|
+
whenFalse: ConditionalType['whenFalse'];
|
|
93
|
+
constructor(definition: ConditionalType);
|
|
94
|
+
}
|
|
95
|
+
declare class BoxNodeEmptyInitializer extends BoxNodeType$1<EmptyInitializerType> {}
|
|
96
|
+
declare const isBoxNode: (value: unknown) => value is BoxNode;
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/types.d.ts
|
|
99
|
+
type PrimitiveType = string | number | boolean | null | undefined;
|
|
100
|
+
interface LiteralObject {
|
|
101
|
+
[key: string]: any;
|
|
102
|
+
}
|
|
103
|
+
type SingleLiteralValue = PrimitiveType | LiteralObject;
|
|
104
|
+
type LiteralValue = SingleLiteralValue | SingleLiteralValue[];
|
|
105
|
+
interface EvaluatedObjectResult {
|
|
106
|
+
[key: string]: LiteralValue;
|
|
107
|
+
}
|
|
108
|
+
interface ExtractedFunctionInstance {
|
|
109
|
+
name: string;
|
|
110
|
+
kind: 'call-expression';
|
|
111
|
+
fromNode: () => CallExpression;
|
|
112
|
+
box: BoxNodeArray;
|
|
113
|
+
}
|
|
114
|
+
interface ExtractedTaggedTemplateInstance {
|
|
115
|
+
name: string;
|
|
116
|
+
kind: 'tagged-template';
|
|
117
|
+
fromNode: () => TaggedTemplateExpression;
|
|
118
|
+
box: BoxNodeLiteral;
|
|
119
|
+
}
|
|
120
|
+
interface ExtractedFunctionResult {
|
|
121
|
+
kind: 'function';
|
|
122
|
+
nodesByProp: Map<string, BoxNode[]>;
|
|
123
|
+
queryList: Array<ExtractedFunctionInstance | ExtractedTaggedTemplateInstance>;
|
|
124
|
+
}
|
|
125
|
+
interface ExtractedComponentInstance {
|
|
126
|
+
name: string;
|
|
127
|
+
fromNode: () => JsxOpeningElement | JsxSelfClosingElement | CallExpression;
|
|
128
|
+
box: BoxNodeMap;
|
|
129
|
+
}
|
|
130
|
+
interface ExtractedComponentResult {
|
|
131
|
+
kind: 'component';
|
|
132
|
+
nodesByProp: Map<string, BoxNode[]>;
|
|
133
|
+
queryList: ExtractedComponentInstance[];
|
|
134
|
+
}
|
|
135
|
+
type ExtractResultItem = ExtractedComponentResult | ExtractedFunctionResult;
|
|
136
|
+
type ExtractResultByName = Map<string, ExtractResultItem>;
|
|
137
|
+
interface MatchTagArgs {
|
|
138
|
+
tagName: string;
|
|
139
|
+
tagNode: JsxOpeningElement | JsxSelfClosingElement | CallExpression;
|
|
140
|
+
isFactory: boolean;
|
|
141
|
+
}
|
|
142
|
+
interface MatchPropArgs {
|
|
143
|
+
propName: string;
|
|
144
|
+
propNode: JsxAttribute | PropertyAssignment | ShorthandPropertyAssignment | GetAccessorDeclaration | undefined;
|
|
145
|
+
}
|
|
146
|
+
interface MatchFnArgs {
|
|
147
|
+
fnName: string;
|
|
148
|
+
fnNode: CallExpression;
|
|
149
|
+
}
|
|
150
|
+
interface MatchFnArguments {
|
|
151
|
+
argNode: Node;
|
|
152
|
+
index: number;
|
|
153
|
+
}
|
|
154
|
+
interface MatchFnPropArgs {
|
|
155
|
+
propName: string;
|
|
156
|
+
propNode: PropertyAssignment | ShorthandPropertyAssignment | GetAccessorDeclaration;
|
|
157
|
+
}
|
|
158
|
+
interface FunctionMatchers {
|
|
159
|
+
matchFn: (element: MatchFnArgs) => boolean;
|
|
160
|
+
matchArg: (arg: Pick<MatchFnArgs, 'fnName' | 'fnNode'> & MatchFnArguments) => boolean;
|
|
161
|
+
matchProp: (prop: Pick<MatchFnArgs, 'fnName' | 'fnNode'> & MatchFnPropArgs) => boolean;
|
|
162
|
+
}
|
|
163
|
+
interface ComponentMatchers {
|
|
164
|
+
matchTag: (element: MatchTagArgs) => boolean;
|
|
165
|
+
matchProp: (prop: Pick<MatchTagArgs, 'tagName' | 'tagNode'> & MatchPropArgs) => boolean;
|
|
166
|
+
}
|
|
167
|
+
interface MatchTaggedTemplateArgs {
|
|
168
|
+
fnName: string;
|
|
169
|
+
taggedTemplateNode: TaggedTemplateExpression;
|
|
170
|
+
}
|
|
171
|
+
type MatchTaggedTemplate = (tag: MatchTaggedTemplateArgs) => boolean;
|
|
172
|
+
interface BoxContext {
|
|
173
|
+
getEvaluateOptions?: (node: Expression, stack: Node[]) => Omit<EvaluateOptions, 'node' | 'policy'> | void;
|
|
174
|
+
canEval?: (node: Expression, stack: Node[]) => boolean;
|
|
175
|
+
tokens?: {
|
|
176
|
+
view: {
|
|
177
|
+
get: (path: string, fallback?: string | number) => string | undefined;
|
|
178
|
+
getVar: (path: string, fallback?: string | number) => string | undefined;
|
|
179
|
+
};
|
|
180
|
+
isTokenFn?: (fnName: string) => boolean;
|
|
181
|
+
};
|
|
182
|
+
flags?: {
|
|
183
|
+
skipEvaluate?: boolean;
|
|
184
|
+
skipTraverseFiles?: boolean;
|
|
185
|
+
skipConditions?: boolean;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
type EvaluateOptions = Omit<EvaluateOptions$1, 'node' | 'policy'>;
|
|
189
|
+
type ExtractOptions = BoxContext & {
|
|
190
|
+
ast: SourceFile;
|
|
191
|
+
components?: ComponentMatchers;
|
|
192
|
+
functions?: FunctionMatchers;
|
|
193
|
+
taggedTemplates?: {
|
|
194
|
+
matchTaggedTemplate: MatchTaggedTemplate;
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/to-box-node.d.ts
|
|
199
|
+
declare function toBoxNode<Value extends PrimitiveType>(value: Value, node: Node, stack: Node[]): BoxNodeLiteral;
|
|
200
|
+
declare function toBoxNode<Value extends EvaluatedObjectResult>(value: Value, node: Node, stack: Node[]): BoxNodeObject;
|
|
201
|
+
declare function toBoxNode<Value extends PrimitiveType[]>(value: Value, node: Node, stack: Node[]): BoxNodeLiteral[];
|
|
202
|
+
declare function toBoxNode<Value extends BoxNode | BoxNode[]>(value: Value, node: Node, stack: Node[]): Value;
|
|
203
|
+
declare function toBoxNode<Value extends LiteralValue>(value: Value, node: Node, stack: Node[]): Value extends unknown[] ? BoxNodeLiteral : Value extends PrimitiveType ? BoxNodeLiteral : BoxNodeObject;
|
|
204
|
+
declare function toBoxNode<Value extends PrimitiveType | BoxNode>(value: Value, node: Node, stack: Node[]): BoxNodeLiteral;
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/box.d.ts
|
|
207
|
+
declare const box: {
|
|
208
|
+
object(value: EvaluatedObjectResult, node: Node, stack: Node[]): BoxNodeObject;
|
|
209
|
+
literal(value: PrimitiveType, node: Node, stack: Node[]): BoxNodeLiteral;
|
|
210
|
+
map(value: MapTypeValue, node: Node, stack: Node[]): BoxNodeMap;
|
|
211
|
+
array(value: BoxNode[], node: Node, stack: Node[]): BoxNodeArray;
|
|
212
|
+
conditional(whenTrue: BoxNode, whenFalse: BoxNode, node: Node, stack: Node[]): BoxNodeConditional;
|
|
213
|
+
from: typeof toBoxNode;
|
|
214
|
+
objectToMap: (value: Record<string, unknown>, node: Node, stack: Node[]) => BoxNodeMap;
|
|
215
|
+
emptyObject: (node: Node, stack: Node[]) => BoxNodeObject;
|
|
216
|
+
emptyInitializer: (node: Node, stack: Node[]) => BoxNodeEmptyInitializer;
|
|
217
|
+
unresolvable: (node: Node, stack: Node[]) => BoxNodeUnresolvable;
|
|
218
|
+
fallback(node: BoxNode): BoxNode;
|
|
219
|
+
/**
|
|
220
|
+
* box.type === “object” -> object that was resolved using ts-evaluator, most likely from a
|
|
221
|
+
* complex condition OR a simple CallExpression eval result, we don’t have access to individual
|
|
222
|
+
* AST nodes here so we need the distinction
|
|
223
|
+
*/
|
|
224
|
+
isObject(value: BoxNode | undefined): value is BoxNodeObject;
|
|
225
|
+
isLiteral(value: BoxNode | undefined): value is BoxNodeLiteral;
|
|
226
|
+
/**
|
|
227
|
+
* box.type === “map” -> basically any object that was statically analyzable, we store each
|
|
228
|
+
* prop + value in a Map
|
|
229
|
+
*/
|
|
230
|
+
isMap(value: BoxNode | undefined): value is BoxNodeMap;
|
|
231
|
+
isRecipe(value: BoxNode | undefined): value is BoxNodeMap;
|
|
232
|
+
isArray(value: BoxNode | undefined): value is BoxNodeArray;
|
|
233
|
+
isUnresolvable(value: BoxNode | undefined): value is BoxNodeUnresolvable;
|
|
234
|
+
isConditional(value: BoxNode | undefined): value is BoxNodeConditional;
|
|
235
|
+
isEmptyInitializer(value: BoxNode | undefined): value is BoxNodeEmptyInitializer;
|
|
236
|
+
isNumberLiteral(node: BoxNode | undefined): node is BoxNodeLiteral;
|
|
237
|
+
hasValue: (node: BoxNode | undefined) => node is BoxNodeLiteral | BoxNodeObject | BoxNodeMap | BoxNodeArray;
|
|
238
|
+
};
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/call-expression.d.ts
|
|
241
|
+
type MatchProp$1 = (prop: MatchFnPropArgs) => boolean;
|
|
242
|
+
type MatchArg = (prop: MatchFnArgs & MatchFnArguments) => boolean;
|
|
243
|
+
declare const extractCallExpressionArguments: (node: CallExpression, ctx: BoxContext, matchProp?: MatchProp$1, matchArg?: MatchArg) => BoxNodeArray;
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region src/extract.d.ts
|
|
246
|
+
declare const extract: ({
|
|
247
|
+
ast,
|
|
248
|
+
...ctx
|
|
249
|
+
}: ExtractOptions) => ExtractResultByName;
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/find-identifier-value-declaration.d.ts
|
|
252
|
+
declare function getDeclarationFor(node: Identifier, stack: Node[], ctx: BoxContext): VariableDeclaration | ParameterDeclaration | FunctionDeclaration | EnumDeclaration | BindingElement | undefined;
|
|
253
|
+
declare function findIdentifierValueDeclaration(identifier: Identifier, stack: Node[], ctx: BoxContext, visitedsWithStack?: WeakMap<Node, Node[]>): ReturnType<typeof getDeclarationFor> | undefined;
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/get-node-range.d.ts
|
|
256
|
+
declare const getNodeRange: (node: Node) => {
|
|
257
|
+
startPosition: number;
|
|
258
|
+
startLineNumber: number;
|
|
259
|
+
startColumn: number;
|
|
260
|
+
endPosition: number;
|
|
261
|
+
endLineNumber: number;
|
|
262
|
+
endColumn: number;
|
|
263
|
+
};
|
|
264
|
+
type NodeRange = ReturnType<typeof getNodeRange>;
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/jsx-attribute.d.ts
|
|
267
|
+
declare const extractJsxAttribute: (jsxAttribute: JsxAttribute, ctx: BoxContext) => BoxNode | undefined;
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region src/jsx-element-props.d.ts
|
|
270
|
+
declare const extractJsxElementProps: (node: JsxOpeningElement | JsxSelfClosingElement, ctx: BoxContext) => {
|
|
271
|
+
name: string;
|
|
272
|
+
props: Map<string, BoxNode>;
|
|
273
|
+
};
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/maybe-box-node.d.ts
|
|
276
|
+
type MaybeBoxNodeReturn = BoxNode | undefined;
|
|
277
|
+
declare function maybeBoxNode(node: Node, stack: Node[], ctx: BoxContext, matchProp?: (prop: MatchFnPropArgs) => boolean): MaybeBoxNodeReturn;
|
|
278
|
+
declare const maybeIdentifierValue: (identifier: Identifier, _stack: Node[], ctx: BoxContext) => BoxNode;
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/jsx-spread-attribute.d.ts
|
|
281
|
+
type MatchProp = (prop: MatchFnPropArgs | MatchPropArgs) => boolean;
|
|
282
|
+
declare const extractJsxSpreadAttributeValues: (node: JsxSpreadAttribute, ctx: BoxContext, matchProp: MatchProp) => MaybeBoxNodeReturn;
|
|
283
|
+
//#endregion
|
|
284
|
+
//#region src/unbox.d.ts
|
|
285
|
+
type BoxNodeType = BoxNode | BoxNode[] | undefined;
|
|
286
|
+
type CacheMap = WeakMap<BoxNode, Unboxed>;
|
|
287
|
+
interface UnboxContext {
|
|
288
|
+
path: string[];
|
|
289
|
+
parent: BoxNode | undefined;
|
|
290
|
+
cache: CacheMap;
|
|
291
|
+
/** @example <ColorBox color={unresolvableIdentifier ? "light.100" : "dark.200" } /> */
|
|
292
|
+
conditions: LiteralObject[];
|
|
293
|
+
/** @example <ColorBox {...(someCondition && { color: "blue.100" })} /> */
|
|
294
|
+
spreadConditions: LiteralObject[];
|
|
295
|
+
}
|
|
296
|
+
interface Unboxed {
|
|
297
|
+
raw: LiteralObject;
|
|
298
|
+
conditions: LiteralObject[];
|
|
299
|
+
spreadConditions: LiteralObject[];
|
|
300
|
+
}
|
|
301
|
+
declare const unbox: (node: BoxNodeType, ctx?: Pick<UnboxContext, "cache">) => Unboxed;
|
|
302
|
+
//#endregion
|
|
303
|
+
export { type BoxContext, type BoxNode, BoxNodeArray, BoxNodeConditional, BoxNodeEmptyInitializer, BoxNodeLiteral, BoxNodeMap, BoxNodeObject, BoxNodeUnresolvable, type EvaluateOptions, type ExtractOptions, type ExtractResultByName, type ExtractResultItem, type ExtractedComponentInstance, type ExtractedComponentResult, type ExtractedFunctionInstance, type ExtractedFunctionResult, type NodeRange, type PrimitiveType, type Unboxed, box, extract, extractCallExpressionArguments, extractJsxAttribute, extractJsxElementProps, extractJsxSpreadAttributeValues, findIdentifierValueDeclaration, isBoxNode, maybeBoxNode, maybeIdentifierValue, unbox };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/extractor",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.3",
|
|
4
4
|
"description": "The css extractor for css bamboo",
|
|
5
5
|
"homepage": "https://bamboo-css.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"ts-evaluator": "1.2.0",
|
|
37
37
|
"ts-morph": "28.0.0",
|
|
38
|
-
"@bamboocss/shared": "1.12.
|
|
38
|
+
"@bamboocss/shared": "1.12.3"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsdown src/index.ts --format=cjs,esm --shims --dts",
|