sinwan-compiler 0.2.2 → 0.2.4

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.
@@ -0,0 +1,34 @@
1
+ /**
2
+ * SinwanJS Compiler — Auto `cc` wrapping
3
+ *
4
+ * Detects top-level exported functions that look like components (uppercase
5
+ * name, 0–1 params, return JSX) and wraps them with `cc(...)` so the reactive
6
+ * analyzer treats them as components and the runtime gives them a component
7
+ * instance + displayName.
8
+ *
9
+ * This lets plain `export function App()` / `export const App = () => <div/>`
10
+ * work as Sinwan components without an explicit `cc(...)` call, matching the
11
+ * ergonomics of React function components while preserving Sinwan's explicit
12
+ * reactivity model (the compiler still only auto-wraps JSX expressions that
13
+ * read tracked reactive sources).
14
+ *
15
+ * Detection is conservative on purpose:
16
+ * - Only exported bindings are considered (named or default export).
17
+ * - The binding name must start with an uppercase letter (component naming
18
+ * convention). Anonymous default-exported function declarations are also
19
+ * accepted since they are conventionally components.
20
+ * - The function must have 0 or 1 parameters and must lexically return JSX
21
+ * (a JSXElement/JSXFragment in a return statement or arrow body).
22
+ * - Functions already wrapped in `cc(...)` (or an alias) are skipped to keep
23
+ * the transform idempotent.
24
+ *
25
+ * If any wrapping is performed and `cc` is not already imported from
26
+ * `sinwan` / `sinwan/component`, an `import { cc } from "sinwan/component"` is
27
+ * prepended so the subsequent reactive-wrap pass detects the components.
28
+ */
29
+ import * as t from "@babel/types";
30
+ /**
31
+ * Mutates the AST, wrapping exported component-like functions with `cc(...)`.
32
+ * Returns `true` if any wrapping was performed.
33
+ */
34
+ export declare function autoWrapComponents(ast: t.Node, filename?: string): boolean;