imxc 0.6.7 → 0.6.9
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 +110 -9
- package/dist/init.js +1 -1
- package/dist/ir.d.ts +1 -1
- package/dist/lowering.js +1 -1
- package/dist/templates/custom.js +1 -1
- package/dist/templates/hotreload.js +1 -1
- package/dist/templates/index.js +1 -1
- package/package.json +1 -1
package/dist/emitter.js
CHANGED
|
@@ -30,20 +30,121 @@ function cppPropType(t) {
|
|
|
30
30
|
}
|
|
31
31
|
return t;
|
|
32
32
|
}
|
|
33
|
+
function unwrapOuterParens(expr) {
|
|
34
|
+
let current = expr.trim();
|
|
35
|
+
while (current.startsWith('(') && current.endsWith(')')) {
|
|
36
|
+
let depth = 0;
|
|
37
|
+
let balanced = true;
|
|
38
|
+
for (let i = 0; i < current.length; i++) {
|
|
39
|
+
const ch = current[i];
|
|
40
|
+
if (ch === '(') {
|
|
41
|
+
depth++;
|
|
42
|
+
}
|
|
43
|
+
else if (ch === ')') {
|
|
44
|
+
depth--;
|
|
45
|
+
if (depth < 0) {
|
|
46
|
+
balanced = false;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
if (depth === 0 && i < current.length - 1) {
|
|
50
|
+
balanced = false;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!balanced || depth !== 0) {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
current = current.slice(1, -1).trim();
|
|
59
|
+
}
|
|
60
|
+
return current;
|
|
61
|
+
}
|
|
62
|
+
function findTopLevelTernary(expr) {
|
|
63
|
+
let depthParen = 0;
|
|
64
|
+
let depthBracket = 0;
|
|
65
|
+
let depthBrace = 0;
|
|
66
|
+
let inString = false;
|
|
67
|
+
let stringQuote = '';
|
|
68
|
+
let question = -1;
|
|
69
|
+
for (let i = 0; i < expr.length; i++) {
|
|
70
|
+
const ch = expr[i];
|
|
71
|
+
const prev = i > 0 ? expr[i - 1] : '';
|
|
72
|
+
if (inString) {
|
|
73
|
+
if (ch === stringQuote && prev !== '\\') {
|
|
74
|
+
inString = false;
|
|
75
|
+
stringQuote = '';
|
|
76
|
+
}
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (ch === '"' || ch === '\'') {
|
|
80
|
+
inString = true;
|
|
81
|
+
stringQuote = ch;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (ch === '(') {
|
|
85
|
+
depthParen++;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (ch === ')') {
|
|
89
|
+
depthParen--;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (ch === '[') {
|
|
93
|
+
depthBracket++;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (ch === ']') {
|
|
97
|
+
depthBracket--;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (ch === '{') {
|
|
101
|
+
depthBrace++;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (ch === '}') {
|
|
105
|
+
depthBrace--;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (depthParen !== 0 || depthBracket !== 0 || depthBrace !== 0) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (ch === '?' && question === -1) {
|
|
112
|
+
question = i;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (ch === ':' && question !== -1) {
|
|
116
|
+
return { question, colon: i };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
function isStringLiteral(expr) {
|
|
122
|
+
const trimmed = expr.trim();
|
|
123
|
+
return trimmed.startsWith('"') && trimmed.endsWith('"');
|
|
124
|
+
}
|
|
125
|
+
function isCharPtrExpression(expr) {
|
|
126
|
+
const trimmed = unwrapOuterParens(expr);
|
|
127
|
+
if (isStringLiteral(trimmed) || trimmed.endsWith('.c_str()')) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
const ternary = findTopLevelTernary(trimmed);
|
|
131
|
+
if (!ternary) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
const whenTrue = trimmed.slice(ternary.question + 1, ternary.colon).trim();
|
|
135
|
+
const whenFalse = trimmed.slice(ternary.colon + 1).trim();
|
|
136
|
+
return isCharPtrExpression(whenTrue) && isCharPtrExpression(whenFalse);
|
|
137
|
+
}
|
|
33
138
|
/**
|
|
34
139
|
* Ensure a string expression is a const char*.
|
|
35
140
|
* String literals (quoted) are already const char*.
|
|
36
141
|
* Expressions like props.title (std::string) need .c_str().
|
|
37
142
|
*/
|
|
38
143
|
function asCharPtr(expr) {
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
if (expr.endsWith('.c_str()'))
|
|
44
|
-
return expr;
|
|
45
|
-
// Expression — assume std::string, add .c_str()
|
|
46
|
-
return `${expr}.c_str()`;
|
|
144
|
+
const trimmed = expr.trim();
|
|
145
|
+
if (isCharPtrExpression(trimmed))
|
|
146
|
+
return trimmed;
|
|
147
|
+
return `(${trimmed}).c_str()`;
|
|
47
148
|
}
|
|
48
149
|
/**
|
|
49
150
|
* For directBind emitters: if the valueExpr references a bound prop (pointer),
|
|
@@ -1648,7 +1749,7 @@ function emitText(node, lines, indent) {
|
|
|
1648
1749
|
function emitButton(node, lines, indent, depth) {
|
|
1649
1750
|
emitLocComment(node.loc, 'Button', lines, indent);
|
|
1650
1751
|
const title = asCharPtr(node.title);
|
|
1651
|
-
const disabledArg = node.disabled ?
|
|
1752
|
+
const disabledArg = node.disabled !== undefined ? `, {}, ${node.disabled}` : '';
|
|
1652
1753
|
const pressedVar = node.action.length > 0 ? nextWidgetTemp('button_pressed') : undefined;
|
|
1653
1754
|
const resultVar = emitBoolWidgetCall(`imx::renderer::button(${title}${disabledArg})`, node.item, lines, indent, pressedVar);
|
|
1654
1755
|
if (node.action.length > 0 && resultVar) {
|
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.
|
|
42
|
+
console.log(' GIT_TAG v0.6.9');
|
|
43
43
|
console.log(' )');
|
|
44
44
|
console.log(' FetchContent_MakeAvailable(imx)');
|
|
45
45
|
console.log(' include(ImxCompile)');
|
package/dist/ir.d.ts
CHANGED
package/dist/lowering.js
CHANGED
|
@@ -1045,7 +1045,7 @@ function lowerButton(attrs, rawAttrs, body, ctx, loc) {
|
|
|
1045
1045
|
if (onPressExpr) {
|
|
1046
1046
|
action = extractActionStatements(onPressExpr, ctx);
|
|
1047
1047
|
}
|
|
1048
|
-
const disabled = attrs['disabled']
|
|
1048
|
+
const disabled = attrs['disabled'];
|
|
1049
1049
|
const style = attrs['style'];
|
|
1050
1050
|
const item = lowerItemInteraction(attrs, rawAttrs, ctx);
|
|
1051
1051
|
body.push({ kind: 'button', title, action, disabled, style, item, loc });
|
package/dist/templates/custom.js
CHANGED
package/dist/templates/index.js
CHANGED