imxc 0.6.12 → 0.6.13
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 +9 -0
- package/dist/init.js +1 -1
- package/dist/ir.d.ts +6 -1
- package/dist/lowering.js +34 -3
- 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
|
@@ -589,6 +589,9 @@ function emitNode(node, lines, depth) {
|
|
|
589
589
|
emitLocComment(node.loc, 'OpenPopup', lines, indent);
|
|
590
590
|
lines.push(`${indent}imx::renderer::open_popup(${node.id});`);
|
|
591
591
|
break;
|
|
592
|
+
case 'guard_return':
|
|
593
|
+
emitGuardReturn(node, lines, indent);
|
|
594
|
+
break;
|
|
592
595
|
case 'conditional':
|
|
593
596
|
emitConditional(node, lines, indent, depth);
|
|
594
597
|
break;
|
|
@@ -1960,6 +1963,12 @@ function emitCursor(node, lines, indent) {
|
|
|
1960
1963
|
emitLocComment(node.loc, 'Cursor', lines, indent);
|
|
1961
1964
|
lines.push(`${indent}imx::renderer::set_cursor_pos(${emitFloat(node.x)}, ${emitFloat(node.y)});`);
|
|
1962
1965
|
}
|
|
1966
|
+
function emitGuardReturn(node, lines, indent) {
|
|
1967
|
+
emitLocComment(node.loc, 'return null guard', lines, indent);
|
|
1968
|
+
lines.push(`${indent}if (${node.condition}) {`);
|
|
1969
|
+
lines.push(`${indent}${INDENT}return;`);
|
|
1970
|
+
lines.push(`${indent}}`);
|
|
1971
|
+
}
|
|
1963
1972
|
function emitConditional(node, lines, indent, depth) {
|
|
1964
1973
|
if (node.loc) {
|
|
1965
1974
|
lines.push(`${indent}// ${node.loc.file}:${node.loc.line} conditional`);
|
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.13');
|
|
43
43
|
console.log(' )');
|
|
44
44
|
console.log(' FetchContent_MakeAvailable(imx)');
|
|
45
45
|
console.log(' include(ImxCompile)');
|
package/dist/ir.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface IRPropParam {
|
|
|
37
37
|
name: string;
|
|
38
38
|
type: string | 'callback';
|
|
39
39
|
}
|
|
40
|
-
export type IRNode = IRBeginContainer | IREndContainer | IRText | IRButton | IRTextInput | IRCheckbox | IRSeparator | IRSpacing | IRDummy | IRSameLine | IRNewLine | IRCursor | IRBeginPopup | IREndPopup | IROpenPopup | IRConditional | IRListMap | IRCustomComponent | IRMenuItem | IRBeginTable | IREndTable | IRBeginTableRow | IREndTableRow | IRBeginTableCell | IREndTableCell | IRBeginTreeNode | IREndTreeNode | IRBeginCollapsingHeader | IREndCollapsingHeader | IRSliderFloat | IRSliderInt | IRDragFloat | IRDragInt | IRCombo | IRInputInt | IRInputFloat | IRColorEdit | IRListBox | IRProgressBar | IRTooltip | IRShortcut | IRDockLayout | IRNativeWidget | IRBulletText | IRLabelText | IRSelectable | IRRadio | IRInputTextMultiline | IRColorPicker | IRColorEdit3 | IRColorPicker3 | IRPlotLines | IRPlotHistogram | IRImage | IRDrawLine | IRDrawRect | IRDrawCircle | IRDrawText | IRDrawBezierCubic | IRDrawBezierQuadratic | IRDrawPolyline | IRDrawConvexPolyFilled | IRDrawNgon | IRDrawNgonFilled | IRDrawTriangle | IRInputFloatN | IRInputIntN | IRDragFloatN | IRDragIntN | IRSliderFloatN | IRSliderIntN | IRSmallButton | IRArrowButton | IRInvisibleButton | IRImageButton | IRVSliderFloat | IRVSliderInt | IRSliderAngle | IRBeginCombo | IREndCombo | IRBullet | IRBeginListBox | IREndListBox;
|
|
40
|
+
export type IRNode = IRBeginContainer | IREndContainer | IRText | IRButton | IRTextInput | IRCheckbox | IRSeparator | IRSpacing | IRDummy | IRSameLine | IRNewLine | IRCursor | IRBeginPopup | IREndPopup | IROpenPopup | IRGuardReturn | IRConditional | IRListMap | IRCustomComponent | IRMenuItem | IRBeginTable | IREndTable | IRBeginTableRow | IREndTableRow | IRBeginTableCell | IREndTableCell | IRBeginTreeNode | IREndTreeNode | IRBeginCollapsingHeader | IREndCollapsingHeader | IRSliderFloat | IRSliderInt | IRDragFloat | IRDragInt | IRCombo | IRInputInt | IRInputFloat | IRColorEdit | IRListBox | IRProgressBar | IRTooltip | IRShortcut | IRDockLayout | IRNativeWidget | IRBulletText | IRLabelText | IRSelectable | IRRadio | IRInputTextMultiline | IRColorPicker | IRColorEdit3 | IRColorPicker3 | IRPlotLines | IRPlotHistogram | IRImage | IRDrawLine | IRDrawRect | IRDrawCircle | IRDrawText | IRDrawBezierCubic | IRDrawBezierQuadratic | IRDrawPolyline | IRDrawConvexPolyFilled | IRDrawNgon | IRDrawNgonFilled | IRDrawTriangle | IRInputFloatN | IRInputIntN | IRDragFloatN | IRDragIntN | IRSliderFloatN | IRSliderIntN | IRSmallButton | IRArrowButton | IRInvisibleButton | IRImageButton | IRVSliderFloat | IRVSliderInt | IRSliderAngle | IRBeginCombo | IREndCombo | IRBullet | IRBeginListBox | IREndListBox;
|
|
41
41
|
export interface IRBeginContainer {
|
|
42
42
|
kind: 'begin_container';
|
|
43
43
|
tag: 'Window' | 'View' | 'Indent' | 'TextWrap' | 'Row' | 'Column' | 'DockSpace' | 'MainMenuBar' | 'MenuBar' | 'Menu' | 'TabBar' | 'TabItem' | 'Theme' | 'DockLayout' | 'DockSplit' | 'DockPanel' | 'Modal' | 'Group' | 'ID' | 'StyleColor' | 'StyleVar' | 'DragDropSource' | 'DragDropTarget' | 'Canvas' | 'Disabled' | 'Child' | 'Font' | 'ContextMenu' | 'MultiSelect';
|
|
@@ -211,6 +211,11 @@ export interface IROpenPopup {
|
|
|
211
211
|
id: string;
|
|
212
212
|
loc?: SourceLoc;
|
|
213
213
|
}
|
|
214
|
+
export interface IRGuardReturn {
|
|
215
|
+
kind: 'guard_return';
|
|
216
|
+
condition: string;
|
|
217
|
+
loc?: SourceLoc;
|
|
218
|
+
}
|
|
214
219
|
export interface IRConditional {
|
|
215
220
|
kind: 'conditional';
|
|
216
221
|
condition: string;
|
package/dist/lowering.js
CHANGED
|
@@ -75,9 +75,18 @@ export function lowerComponent(parsed, validation, externalInterfaces) {
|
|
|
75
75
|
const body = [];
|
|
76
76
|
if (func.body) {
|
|
77
77
|
collectLocalAliases(func.body, ctx);
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
for (const stmt of func.body.statements) {
|
|
79
|
+
const guard = lowerTopLevelGuardReturn(stmt, ctx);
|
|
80
|
+
if (guard) {
|
|
81
|
+
body.push(guard);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (ts.isReturnStatement(stmt)) {
|
|
85
|
+
if (stmt.expression) {
|
|
86
|
+
lowerJsxExpression(stmt.expression, body, ctx);
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
81
90
|
}
|
|
82
91
|
}
|
|
83
92
|
return {
|
|
@@ -89,6 +98,28 @@ export function lowerComponent(parsed, validation, externalInterfaces) {
|
|
|
89
98
|
body,
|
|
90
99
|
};
|
|
91
100
|
}
|
|
101
|
+
function lowerTopLevelGuardReturn(stmt, ctx) {
|
|
102
|
+
if (!ts.isIfStatement(stmt) || !statementReturnsNullish(stmt.thenStatement)) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
kind: 'guard_return',
|
|
107
|
+
condition: exprToCpp(stmt.expression, ctx),
|
|
108
|
+
loc: getLoc(stmt, ctx),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function statementReturnsNullish(stmt) {
|
|
112
|
+
if (ts.isReturnStatement(stmt)) {
|
|
113
|
+
return isNullishReturnExpression(stmt.expression);
|
|
114
|
+
}
|
|
115
|
+
if (ts.isBlock(stmt) && stmt.statements.length === 1 && ts.isReturnStatement(stmt.statements[0])) {
|
|
116
|
+
return isNullishReturnExpression(stmt.statements[0].expression);
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
function isNullishReturnExpression(expr) {
|
|
121
|
+
return !expr || expr.kind === ts.SyntaxKind.NullKeyword || expr.kind === ts.SyntaxKind.UndefinedKeyword;
|
|
122
|
+
}
|
|
92
123
|
function collectLocalAliases(body, ctx) {
|
|
93
124
|
for (const stmt of body.statements) {
|
|
94
125
|
if (ts.isReturnStatement(stmt)) {
|
package/dist/templates/custom.js
CHANGED
package/dist/templates/index.js
CHANGED