sinwan-compiler 0.0.0 → 0.2.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mohammed Ben Cheikh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # sinwan-compiler
2
+
3
+ Shared compiler core for the SinwanJS framework. Provides the JSX transform, the project-wide reactive-prop analyzer, and the dev/HMR cache used by both the Bun and Vite plugins.
4
+
5
+ ## Documentation
6
+
7
+ See the [`docs/`](docs/) folder:
8
+
9
+ - [Overview](docs/README.md)
10
+ - [Analyzer](docs/analyzer.md)
11
+ - [Transform](docs/transform.md)
12
+ - [CLI](docs/cli.md)
13
+ - [Plugins](docs/plugins.md)
14
+ - [API reference](docs/api.md)
15
+ - [Architecture](docs/architecture.md)
16
+
17
+ ## Quick start
18
+
19
+ ```bash
20
+ bunx sinwan-compiler analyze ./src ./.sinwan/reactive-props.json
21
+ ```
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ bun add -d sinwan-compiler
27
+ ```
@@ -0,0 +1,103 @@
1
+ /**
2
+ * SinwanJS Compiler — Project-wide reactive prop analyzer.
3
+ *
4
+ * Scans a project for JSX/TSX files, builds a global component call graph,
5
+ * and computes which exported component props are actually reactive across
6
+ * modules. The result is written to a JSON metadata file consumed by the
7
+ * per-file transform.
8
+ */
9
+ import * as t from "@babel/types";
10
+ import { type ReactiveScope, type CallSite } from "./reactive-wrap";
11
+ export type ImportInfo = {
12
+ source: string;
13
+ importedName: string;
14
+ };
15
+ export type ImportedCallSite = {
16
+ caller: t.Function;
17
+ source: string;
18
+ name: string;
19
+ props: {
20
+ name: string;
21
+ value: t.Expression;
22
+ }[];
23
+ /** Spread expressions forwarded to the child. */
24
+ spreads: t.Expression[];
25
+ };
26
+ export type ModuleAnalysis = {
27
+ filePath: string;
28
+ imports: Map<string, ImportInfo>;
29
+ exports: Map<string, t.Function>;
30
+ defaultExport: t.Function | null;
31
+ componentFunctions: Set<t.Function>;
32
+ localScopes: Map<t.Function, ReactiveScope>;
33
+ localCallGraph: Map<t.Function, CallSite[]>;
34
+ importedCallSites: ImportedCallSite[];
35
+ };
36
+ export type ProjectAnalysis = {
37
+ modules: Map<string, ModuleAnalysis>;
38
+ reactiveProps: Map<string, Map<string, Set<string>>>;
39
+ };
40
+ export type WorkspacesConfig = string | string[] | {
41
+ file?: string;
42
+ include?: string[];
43
+ };
44
+ export type AnalyzeOptions = {
45
+ /** Project root directory to scan. */
46
+ root: string;
47
+ /** Output file path for the metadata JSON. */
48
+ outFile: string;
49
+ /** File extensions to scan. */
50
+ extensions?: string[];
51
+ /** Custom import resolver: returns absolute file path or null. */
52
+ resolve?: (source: string, fromFile: string) => string | null;
53
+ /** Path to tsconfig.json used to resolve path aliases. */
54
+ tsConfigPath?: string;
55
+ /** Path to bunfig.toml used to resolve Bun aliases. */
56
+ bunfigPath?: string;
57
+ /** Workspace package discovery: path to a workspace file, list of package paths/globs, or both. */
58
+ workspaces?: WorkspacesConfig;
59
+ };
60
+ export declare function analyzeModule(code: string, filePath: string): ModuleAnalysis;
61
+ export declare function loadWorkspacePackages(workspaces: WorkspacesConfig, root: string): string[];
62
+ export declare function analyzeProject(options: {
63
+ root: string;
64
+ extensions?: string[];
65
+ resolve?: (source: string, fromFile: string) => string | null;
66
+ files?: Record<string, string>;
67
+ tsConfigPath?: string;
68
+ bunfigPath?: string;
69
+ workspaces?: WorkspacesConfig;
70
+ }): ProjectAnalysis;
71
+ export declare class AnalyzerCache {
72
+ root: string;
73
+ extensions: string[];
74
+ tsConfigPath?: string;
75
+ bunfigPath?: string;
76
+ workspaces?: WorkspacesConfig;
77
+ cachePath?: string;
78
+ resolve: (source: string, fromFile: string) => string | null;
79
+ modules: Map<string, ModuleAnalysis>;
80
+ reactiveProps: Map<string, Map<string, Set<string>>>;
81
+ private importers;
82
+ constructor(options: {
83
+ root: string;
84
+ extensions?: string[];
85
+ tsConfigPath?: string;
86
+ bunfigPath?: string;
87
+ workspaces?: WorkspacesConfig;
88
+ resolve?: (source: string, fromFile: string) => string | null;
89
+ cachePath?: string;
90
+ });
91
+ update(filePath: string, code: string): void;
92
+ remove(filePath: string): void;
93
+ save(): void;
94
+ private restore;
95
+ private addImporters;
96
+ private removeImporters;
97
+ private ensureAnalyzed;
98
+ private collectAffected;
99
+ private recomputeFor;
100
+ private recompute;
101
+ }
102
+ export declare function analyze(options: AnalyzeOptions): void;
103
+ export declare function loadMetadata(filePath: string): Map<string, Map<string, Set<string>>>;