imxc 0.6.8 → 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 +109 -8
- package/dist/init.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),
|
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/templates/custom.js
CHANGED
package/dist/templates/index.js
CHANGED