imxc 0.2.0 → 0.3.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/dist/compile.d.ts +10 -0
- package/dist/compile.js +169 -0
- package/dist/components.js +249 -1
- package/dist/diagnostics.d.ts +5 -0
- package/dist/diagnostics.js +23 -0
- package/dist/emitter.d.ts +3 -3
- package/dist/emitter.js +814 -84
- package/dist/index.js +31 -111
- package/dist/init.js +144 -17
- package/dist/ir.d.ts +157 -3
- package/dist/lowering.d.ts +1 -0
- package/dist/lowering.js +400 -63
- package/dist/validator.js +3 -5
- package/dist/watch.d.ts +4 -0
- package/dist/watch.js +66 -0
- package/package.json +2 -2
package/dist/validator.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import { HOST_COMPONENTS
|
|
2
|
+
import { HOST_COMPONENTS } from './components.js';
|
|
3
3
|
import { extractImports } from './parser.js';
|
|
4
4
|
function err(sf, node, msg) {
|
|
5
5
|
const { line, character } = sf.getLineAndCharacterOfPosition(node.getStart());
|
|
@@ -113,10 +113,8 @@ function validateJsxElement(node, sf, customComponents, errors) {
|
|
|
113
113
|
function validateJsxTag(tagName, node, sf, customComponents, errors) {
|
|
114
114
|
if (!ts.isIdentifier(tagName))
|
|
115
115
|
return;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
errors.push(err(sf, node, `Unknown component: <${name}>`));
|
|
119
|
-
}
|
|
116
|
+
// Host components and imported custom components are validated.
|
|
117
|
+
// Unknown elements are treated as native widgets (validated by TypeScript + C++ linker).
|
|
120
118
|
}
|
|
121
119
|
function validateJsxAttributes(attrs, tagName, sf, errors) {
|
|
122
120
|
if (!ts.isIdentifier(tagName))
|
package/dist/watch.d.ts
ADDED
package/dist/watch.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { compile } from './compile.js';
|
|
4
|
+
/**
|
|
5
|
+
* Discover all .tsx files in a directory (recursive).
|
|
6
|
+
*/
|
|
7
|
+
function discoverTsxFiles(dir) {
|
|
8
|
+
const results = [];
|
|
9
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
10
|
+
for (const entry of entries) {
|
|
11
|
+
const fullPath = path.join(dir, entry.name);
|
|
12
|
+
if (entry.isDirectory()) {
|
|
13
|
+
results.push(...discoverTsxFiles(fullPath));
|
|
14
|
+
}
|
|
15
|
+
else if (entry.isFile() && entry.name.endsWith('.tsx')) {
|
|
16
|
+
results.push(fullPath);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return results;
|
|
20
|
+
}
|
|
21
|
+
function runCompile(watchDir, outputDir) {
|
|
22
|
+
const files = discoverTsxFiles(watchDir);
|
|
23
|
+
if (files.length === 0) {
|
|
24
|
+
console.log('[watch] No .tsx files found in ' + watchDir);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const start = performance.now();
|
|
28
|
+
const result = compile(files, outputDir);
|
|
29
|
+
const elapsed = Math.round(performance.now() - start);
|
|
30
|
+
if (result.success) {
|
|
31
|
+
console.log(`[watch] ${result.componentCount} component(s) compiled in ${elapsed}ms`);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
result.errors.forEach(e => console.error(e));
|
|
35
|
+
console.log(`[watch] compilation failed (${elapsed}ms)`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Start watching a directory for .tsx changes and recompile on change.
|
|
40
|
+
*/
|
|
41
|
+
export function startWatch(watchDir, outputDir) {
|
|
42
|
+
console.log(`[watch] watching ${watchDir} for .tsx changes...`);
|
|
43
|
+
console.log(`[watch] output: ${outputDir}`);
|
|
44
|
+
console.log('[watch] press Ctrl+C to stop\n');
|
|
45
|
+
// Initial compile
|
|
46
|
+
runCompile(watchDir, outputDir);
|
|
47
|
+
// Debounce timer
|
|
48
|
+
let debounceTimer = null;
|
|
49
|
+
const watcher = fs.watch(watchDir, { recursive: true }, (_event, filename) => {
|
|
50
|
+
if (!filename || !filename.endsWith('.tsx'))
|
|
51
|
+
return;
|
|
52
|
+
// Debounce: wait 100ms after last change before recompiling
|
|
53
|
+
if (debounceTimer)
|
|
54
|
+
clearTimeout(debounceTimer);
|
|
55
|
+
debounceTimer = setTimeout(() => {
|
|
56
|
+
console.log(`\n[watch] change detected: ${filename}`);
|
|
57
|
+
runCompile(watchDir, outputDir);
|
|
58
|
+
}, 100);
|
|
59
|
+
});
|
|
60
|
+
// Clean shutdown on Ctrl+C
|
|
61
|
+
process.on('SIGINT', () => {
|
|
62
|
+
console.log('\n[watch] stopped.');
|
|
63
|
+
watcher.close();
|
|
64
|
+
process.exit(0);
|
|
65
|
+
});
|
|
66
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "imxc",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Compiler for
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Compiler for IMX — compiles React-like .tsx to native Dear ImGui C++",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"imxc": "dist/index.js"
|