imxc 0.6.6 → 0.6.7

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/emitter.js CHANGED
@@ -1346,8 +1346,14 @@ function emitBeginContainer(node, lines, indent) {
1346
1346
  }
1347
1347
  case 'ID': {
1348
1348
  const scope = node.props['scope'] ?? '""';
1349
- if (scope.startsWith('"')) {
1350
- lines.push(`${indent}ImGui::PushID(${scope});`);
1349
+ const scopeType = node.props['_scopeType'] ?? (scope.startsWith('"') ? 'string' : 'number');
1350
+ if (scopeType === 'string') {
1351
+ if (scope.startsWith('"') || scope.endsWith('.c_str()')) {
1352
+ lines.push(`${indent}ImGui::PushID(${scope});`);
1353
+ }
1354
+ else {
1355
+ lines.push(`${indent}ImGui::PushID((${scope}).c_str());`);
1356
+ }
1351
1357
  }
1352
1358
  else {
1353
1359
  lines.push(`${indent}ImGui::PushID(static_cast<int>(${scope}));`);
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.6');
42
+ console.log(' GIT_TAG v0.6.7');
43
43
  console.log(' )');
44
44
  console.log(' FetchContent_MakeAvailable(imx)');
45
45
  console.log(' include(ImxCompile)');
package/dist/lowering.js CHANGED
@@ -316,6 +316,54 @@ export function exprToCpp(node, ctx) {
316
316
  // Fallback: use text representation
317
317
  return node.getText();
318
318
  }
319
+ function isStringLikeExpr(expr, ctx) {
320
+ if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr) || ts.isTemplateExpression(expr)) {
321
+ return true;
322
+ }
323
+ if (ts.isConditionalExpression(expr)) {
324
+ return isStringLikeExpr(expr.whenTrue, ctx) || isStringLikeExpr(expr.whenFalse, ctx);
325
+ }
326
+ if (ts.isBinaryExpression(expr) && expr.operatorToken.kind === ts.SyntaxKind.PlusToken) {
327
+ return isStringLikeExpr(expr.left, ctx) || isStringLikeExpr(expr.right, ctx)
328
+ || inferExprType(expr.left, ctx) === 'string'
329
+ || inferExprType(expr.right, ctx) === 'string';
330
+ }
331
+ return inferExprType(expr, ctx) === 'string';
332
+ }
333
+ function coerceExprToCppString(expr, ctx) {
334
+ if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr)) {
335
+ return JSON.stringify(expr.text);
336
+ }
337
+ if (ts.isConditionalExpression(expr)) {
338
+ const condition = exprToCpp(expr.condition, ctx);
339
+ const whenTrue = coerceExprToCppString(expr.whenTrue, ctx);
340
+ const whenFalse = coerceExprToCppString(expr.whenFalse, ctx);
341
+ return `${condition} ? ${whenTrue} : ${whenFalse}`;
342
+ }
343
+ const cppExpr = exprToCpp(expr, ctx);
344
+ if (isStringLikeExpr(expr, ctx)) {
345
+ return cppExpr.startsWith('"') ? `std::string(${cppExpr})` : cppExpr;
346
+ }
347
+ if (inferExprType(expr, ctx) === 'bool') {
348
+ return `${cppExpr} ? std::string("true") : std::string("false")`;
349
+ }
350
+ return `std::to_string(${cppExpr})`;
351
+ }
352
+ function normalizeIdScopeAttrs(attrs, rawAttrs, ctx) {
353
+ const normalized = { ...attrs };
354
+ const scopeExpr = rawAttrs.get('scope');
355
+ if (!scopeExpr)
356
+ return normalized;
357
+ if (isStringLikeExpr(scopeExpr, ctx)) {
358
+ normalized['scope'] = coerceExprToCppString(scopeExpr, ctx);
359
+ normalized['_scopeType'] = 'string';
360
+ }
361
+ else {
362
+ normalized['scope'] = exprToCpp(scopeExpr, ctx);
363
+ normalized['_scopeType'] = 'number';
364
+ }
365
+ return normalized;
366
+ }
319
367
  function stmtToCpp(stmt, ctx) {
320
368
  if (ts.isExpressionStatement(stmt)) {
321
369
  return exprToCpp(stmt.expression, ctx) + ';';
@@ -444,8 +492,11 @@ function lowerJsxElement(node, body, ctx) {
444
492
  }
445
493
  if (isHostComponent(name)) {
446
494
  const def = HOST_COMPONENTS[name];
447
- const attrs = getAttributes(node.openingElement.attributes, ctx);
495
+ let attrs = getAttributes(node.openingElement.attributes, ctx);
448
496
  const rawAttrs = getRawAttributes(node.openingElement.attributes);
497
+ if (name === 'ID') {
498
+ attrs = normalizeIdScopeAttrs(attrs, rawAttrs, ctx);
499
+ }
449
500
  if (name === 'Table') {
450
501
  lowerTableElement(node, body, ctx, attrs, rawAttrs, getLoc(node, ctx));
451
502
  return;
@@ -630,8 +681,11 @@ function lowerJsxSelfClosing(node, body, ctx) {
630
681
  }
631
682
  return;
632
683
  }
633
- const attrs = getAttributes(node.attributes, ctx);
684
+ let attrs = getAttributes(node.attributes, ctx);
634
685
  const rawAttrs = getRawAttributes(node.attributes);
686
+ if (name === 'ID') {
687
+ attrs = normalizeIdScopeAttrs(attrs, rawAttrs, ctx);
688
+ }
635
689
  const loc = getLoc(node, ctx);
636
690
  switch (name) {
637
691
  case 'Table': {
@@ -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.6
431
+ GIT_TAG v0.6.7
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.6
316
+ GIT_TAG v0.6.7
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.6
405
+ GIT_TAG v0.6.7
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.6",
3
+ "version": "0.6.7",
4
4
  "description": "Compiler for IMX — compiles React-like .tsx to native Dear ImGui C++",
5
5
  "type": "module",
6
6
  "bin": {