imxc 0.6.5 → 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.5');
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
@@ -242,10 +242,10 @@ export function exprToCpp(node, ctx) {
242
242
  const leftIsString = ts.isStringLiteral(node.left) || ts.isNoSubstitutionTemplateLiteral(node.left) || inferExprType(node.left, ctx) === 'string';
243
243
  const rightIsString = ts.isStringLiteral(node.right) || ts.isNoSubstitutionTemplateLiteral(node.right) || inferExprType(node.right, ctx) === 'string';
244
244
  if (leftIsString && !rightIsString) {
245
- return `(std::string(${left}) + std::to_string(${right})).c_str()`;
245
+ return `std::string(${left}) + std::to_string(${right})`;
246
246
  }
247
247
  if (!leftIsString && rightIsString) {
248
- return `(std::to_string(${left}) + std::string(${right})).c_str()`;
248
+ return `std::to_string(${left}) + std::string(${right})`;
249
249
  }
250
250
  }
251
251
  return `${left} ${op} ${right}`;
@@ -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': {
@@ -1164,12 +1218,14 @@ function lowerTextElement(node, body, ctx, loc) {
1164
1218
  break;
1165
1219
  case 'string':
1166
1220
  format += '%s';
1167
- // String literals and ternaries of literals are already const char*
1168
- if (cppExpr.startsWith('"') || isCharPtrExpression(expr)) {
1221
+ // String literals, literal-only ternaries, and pre-converted char* values
1222
+ // should be passed through unchanged. Other string expressions stay as
1223
+ // std::string until this point and need a single .c_str().
1224
+ if (cppExpr.startsWith('"') || cppExpr.endsWith('.c_str()') || isCharPtrExpression(expr)) {
1169
1225
  args.push(cppExpr);
1170
1226
  }
1171
1227
  else {
1172
- args.push(`${cppExpr}.c_str()`);
1228
+ args.push(`(${cppExpr}).c_str()`);
1173
1229
  }
1174
1230
  break;
1175
1231
  default:
@@ -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.5
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.5
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.5
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.5",
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": {