imxc 0.6.10 → 0.6.12

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/init.js CHANGED
@@ -39,7 +39,7 @@ export function addToProject(projectDir) {
39
39
  console.log(' include(FetchContent)');
40
40
  console.log(' FetchContent_Declare(imx');
41
41
  console.log(' GIT_REPOSITORY https://github.com/bgocumlu/imx.git');
42
- console.log(' GIT_TAG v0.6.10');
42
+ console.log(' GIT_TAG v0.6.12');
43
43
  console.log(' )');
44
44
  console.log(' FetchContent_MakeAvailable(imx)');
45
45
  console.log(' include(ImxCompile)');
@@ -5,6 +5,7 @@ import type { IRComponent, IRStateSlot } from './ir.js';
5
5
  interface LoweringContext {
6
6
  stateVars: Map<string, IRStateSlot>;
7
7
  setterMap: Map<string, string>;
8
+ localAliases: Map<string, ts.Expression>;
8
9
  propsParam: string | null;
9
10
  propsFieldTypes: Map<string, string | 'callback'>;
10
11
  externalInterfaces?: Map<string, Map<string, string | 'callback'>>;
package/dist/lowering.js CHANGED
@@ -62,6 +62,7 @@ export function lowerComponent(parsed, validation, externalInterfaces) {
62
62
  const ctx = {
63
63
  stateVars,
64
64
  setterMap,
65
+ localAliases: new Map(),
65
66
  propsParam,
66
67
  propsFieldTypes,
67
68
  externalInterfaces,
@@ -73,6 +74,7 @@ export function lowerComponent(parsed, validation, externalInterfaces) {
73
74
  // Find return statement and lower its JSX
74
75
  const body = [];
75
76
  if (func.body) {
77
+ collectLocalAliases(func.body, ctx);
76
78
  const returnStmt = func.body.statements.find(ts.isReturnStatement);
77
79
  if (returnStmt && returnStmt.expression) {
78
80
  lowerJsxExpression(returnStmt.expression, body, ctx);
@@ -87,6 +89,25 @@ export function lowerComponent(parsed, validation, externalInterfaces) {
87
89
  body,
88
90
  };
89
91
  }
92
+ function collectLocalAliases(body, ctx) {
93
+ for (const stmt of body.statements) {
94
+ if (ts.isReturnStatement(stmt)) {
95
+ return;
96
+ }
97
+ if (!ts.isVariableStatement(stmt)) {
98
+ continue;
99
+ }
100
+ if ((stmt.declarationList.flags & ts.NodeFlags.Const) === 0) {
101
+ continue;
102
+ }
103
+ for (const decl of stmt.declarationList.declarations) {
104
+ if (!ts.isIdentifier(decl.name) || !decl.initializer) {
105
+ continue;
106
+ }
107
+ ctx.localAliases.set(decl.name.text, decl.initializer);
108
+ }
109
+ }
110
+ }
90
111
  function normalizePropTypeText(typeText) {
91
112
  const trimmed = typeText.trim().replace(/\s*\|\s*undefined$/, '');
92
113
  if (trimmed === 'number')
@@ -209,6 +230,10 @@ export function exprToCpp(node, ctx) {
209
230
  if (ctx.stateVars.has(name)) {
210
231
  return `${name}.get()`;
211
232
  }
233
+ const alias = ctx.localAliases.get(name);
234
+ if (alias) {
235
+ return exprToCpp(alias, ctx);
236
+ }
212
237
  if (name === 'resetLayout') {
213
238
  return 'imx_reset_layout';
214
239
  }
@@ -223,6 +248,12 @@ export function exprToCpp(node, ctx) {
223
248
  return `${obj}.size()`;
224
249
  return `${obj}.${prop}`;
225
250
  }
251
+ // Element access (e.g., items[0], props.items[i])
252
+ if (ts.isElementAccessExpression(node)) {
253
+ const obj = exprToCpp(node.expression, ctx);
254
+ const arg = node.argumentExpression ? exprToCpp(node.argumentExpression, ctx) : '';
255
+ return `${obj}[${arg}]`;
256
+ }
226
257
  // Parenthesized expression
227
258
  if (ts.isParenthesizedExpression(node)) {
228
259
  return `(${exprToCpp(node.expression, ctx)})`;
@@ -1264,6 +1295,9 @@ function inferExprType(expr, ctx) {
1264
1295
  const slot = ctx.stateVars.get(expr.text);
1265
1296
  if (slot)
1266
1297
  return slot.type;
1298
+ const alias = ctx.localAliases.get(expr.text);
1299
+ if (alias)
1300
+ return inferExprType(alias, ctx);
1267
1301
  }
1268
1302
  // Property access: props.name -> look up field type if available
1269
1303
  if (ts.isPropertyAccessExpression(expr)) {
@@ -428,7 +428,7 @@ set(FETCHCONTENT_QUIET OFF)
428
428
  FetchContent_Declare(
429
429
  imx
430
430
  GIT_REPOSITORY https://github.com/bgocumlu/imx.git
431
- GIT_TAG v0.6.10
431
+ GIT_TAG v0.6.12
432
432
  GIT_SHALLOW TRUE
433
433
  GIT_PROGRESS TRUE
434
434
  )
@@ -313,7 +313,7 @@ set(FETCHCONTENT_QUIET OFF)
313
313
  FetchContent_Declare(
314
314
  imx
315
315
  GIT_REPOSITORY https://github.com/bgocumlu/imx.git
316
- GIT_TAG v0.6.10
316
+ GIT_TAG v0.6.12
317
317
  GIT_SHALLOW TRUE
318
318
  GIT_PROGRESS TRUE
319
319
  )
@@ -402,7 +402,7 @@ set(FETCHCONTENT_QUIET OFF)
402
402
  FetchContent_Declare(
403
403
  imx
404
404
  GIT_REPOSITORY ${repoUrl}
405
- GIT_TAG v0.6.10
405
+ GIT_TAG v0.6.12
406
406
  GIT_SHALLOW TRUE
407
407
  GIT_PROGRESS TRUE
408
408
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imxc",
3
- "version": "0.6.10",
3
+ "version": "0.6.12",
4
4
  "description": "Compiler for IMX — compiles React-like .tsx to native Dear ImGui C++",
5
5
  "type": "module",
6
6
  "bin": {
@@ -15,7 +15,7 @@
15
15
  "test:watch": "vitest",
16
16
  "prepublishOnly": "npm run build"
17
17
  },
18
- "keywords": ["imgui", "react", "tsx", "native", "gui", "compiler", "codegen"],
18
+ "keywords": ["imgui", "react", "tsx", "native", "gui", "compiler", "codegen"],
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
21
  "typescript": "^5.8.0"