11// macro code
2- export function matchInFile ( callExpression ) {
2+ export function matchInFile ( callExpression : BunAST . CallExpression ) {
33 const [ filePathNode , matcherNode ] = callExpression . arguments ;
4- const filePath : string = filePathNode . get ( ) ;
5- const matcher : RegExp = matcherNode . get ( ) ;
4+ let filePath : string ;
5+ filePath = filePathNode . get ( ) ;
6+
7+ let matcher : RegExp ;
8+ matcher = matcherNode . get ( ) ;
69 const file : string = Bun . readFile ( Bun . cwd + filePath ) ;
710
811 return (
@@ -18,3 +21,81 @@ export function matchInFile(callExpression) {
1821 </ array >
1922 ) ;
2023}
24+
25+ export declare namespace BunAST {
26+ export abstract class ASTNode {
27+ constructor ( ...args : any ) ;
28+ }
29+
30+ export interface ASTElement <
31+ P = any ,
32+ T extends string | JSXElementConstructor < any > =
33+ | string
34+ | JSXElementConstructor < any >
35+ > {
36+ type : T ;
37+ props : P ;
38+ key : Key | null ;
39+ }
40+
41+ export abstract class Expression extends ASTNode { }
42+
43+ export abstract class CallExpression extends Expression {
44+ arguments : AnyExpression [ ] ;
45+ name : string ;
46+ target : AnyExpression ;
47+ }
48+
49+ export abstract class StringExpression extends Expression {
50+ get ( ) : string ;
51+ value : string ;
52+ }
53+
54+ export interface StringExpressionElementProps {
55+ value : string ;
56+ }
57+
58+ export type StringExpressionElement = ASTElement <
59+ StringExpressionElementProps ,
60+ StringExpression
61+ > ;
62+
63+ export abstract class RegExpExpression extends Expression {
64+ get ( ) : RegExp ;
65+
66+ flags : string ;
67+ pattern : string ;
68+ raw : string ;
69+ }
70+
71+ export type AnyExpression =
72+ | CallExpression
73+ | StringExpression
74+ | RegExpExpression ;
75+ }
76+
77+ declare global {
78+ namespace JSX {
79+ interface Element extends BunAST . ASTElement < any , BunAST . AnyExpression > { }
80+ interface ElementClass extends BunAST . Expression { }
81+ interface ElementAttributesProperty {
82+ props : { } ;
83+ }
84+ interface ElementChildrenAttribute {
85+ children : { } ;
86+ }
87+
88+ // // We can't recurse forever because `type` can't be self-referential;
89+ // // let's assume it's reasonable to do a single React.lazy() around a single React.memo() / vice-versa
90+ // type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent<infer T>
91+ // ? T extends React.MemoExoticComponent<infer U> | React.LazyExoticComponent<infer U>
92+ // ? ReactManagedAttributes<U, P>
93+ // : ReactManagedAttributes<T, P>
94+ // : ReactManagedAttributes<C, P>;
95+
96+ interface IntrinsicElements {
97+ // HTML
98+ string : BunAST . StringExpressionElement ;
99+ }
100+ }
101+ }
0 commit comments