diff options
Diffstat (limited to 'examples/macros/matchInFile.tsx')
-rw-r--r-- | examples/macros/matchInFile.tsx | 87 |
1 files changed, 84 insertions, 3 deletions
diff --git a/examples/macros/matchInFile.tsx b/examples/macros/matchInFile.tsx index a73f7ee8b..1f5c20fb3 100644 --- a/examples/macros/matchInFile.tsx +++ b/examples/macros/matchInFile.tsx @@ -1,8 +1,11 @@ // macro code -export function matchInFile(callExpression) { +export function matchInFile(callExpression: BunAST.CallExpression) { const [filePathNode, matcherNode] = callExpression.arguments; - const filePath: string = filePathNode.get(); - const matcher: RegExp = matcherNode.get(); + let filePath: string; + filePath = filePathNode.get(); + + let matcher: RegExp; + matcher = matcherNode.get(); const file: string = Bun.readFile(Bun.cwd + filePath); return ( @@ -18,3 +21,81 @@ export function matchInFile(callExpression) { </array> ); } + +export declare namespace BunAST { + export abstract class ASTNode { + constructor(...args: any); + } + + export interface ASTElement< + P = any, + T extends string | JSXElementConstructor<any> = + | string + | JSXElementConstructor<any> + > { + type: T; + props: P; + key: Key | null; + } + + export abstract class Expression extends ASTNode {} + + export abstract class CallExpression extends Expression { + arguments: AnyExpression[]; + name: string; + target: AnyExpression; + } + + export abstract class StringExpression extends Expression { + get(): string; + value: string; + } + + export interface StringExpressionElementProps { + value: string; + } + + export type StringExpressionElement = ASTElement< + StringExpressionElementProps, + StringExpression + >; + + export abstract class RegExpExpression extends Expression { + get(): RegExp; + + flags: string; + pattern: string; + raw: string; + } + + export type AnyExpression = + | CallExpression + | StringExpression + | RegExpExpression; +} + +declare global { + namespace JSX { + interface Element extends BunAST.ASTElement<any, BunAST.AnyExpression> {} + interface ElementClass extends BunAST.Expression {} + interface ElementAttributesProperty { + props: {}; + } + interface ElementChildrenAttribute { + children: {}; + } + + // // We can't recurse forever because `type` can't be self-referential; + // // let's assume it's reasonable to do a single React.lazy() around a single React.memo() / vice-versa + // type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent<infer T> + // ? T extends React.MemoExoticComponent<infer U> | React.LazyExoticComponent<infer U> + // ? ReactManagedAttributes<U, P> + // : ReactManagedAttributes<T, P> + // : ReactManagedAttributes<C, P>; + + interface IntrinsicElements { + // HTML + string: BunAST.StringExpressionElement; + } + } +} |