@junnyontop-pixel/neo-app 1.1.5 → 1.1.6
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/compiler/index.js +17 -11
- package/package.json +1 -1
- package/src/App.js +1 -1
package/compiler/index.js
CHANGED
|
@@ -14,32 +14,38 @@ if (!inputFile) {
|
|
|
14
14
|
const source = fs.readFileSync(inputFile, 'utf8');
|
|
15
15
|
const { root, scriptContent } = NeoParser.parse(source);
|
|
16
16
|
|
|
17
|
-
function generateCode(node) {
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
function generateCode(node, indent = " ") {
|
|
18
|
+
// 자식 노드들을 재귀적으로 호출하며 들여쓰기를 한 단계 더 깊게(indent + " ") 적용합니다.
|
|
19
|
+
const childrenCode = node.children
|
|
20
|
+
.map(child => generateCode(child, indent + " "))
|
|
21
|
+
.join(',\n');
|
|
22
|
+
|
|
23
|
+
// 이벤트 처리 로직 (보내주신 로직 유지)
|
|
20
24
|
const eventProps = {};
|
|
21
25
|
for (const [evt, action] of Object.entries(node.events)) {
|
|
22
26
|
const propName = `on${evt.charAt(0).toUpperCase() + evt.slice(1)}`;
|
|
23
|
-
|
|
24
27
|
let processedAction = action;
|
|
28
|
+
|
|
29
|
+
// 단순 연산(++) 대응
|
|
25
30
|
if (action.includes('++')) processedAction = `state.${action}`;
|
|
26
31
|
|
|
32
|
+
// 괄호 자동 보정
|
|
27
33
|
if (processedAction.includes('(') && !processedAction.includes(')')) {
|
|
28
34
|
processedAction += ')';
|
|
29
35
|
}
|
|
30
|
-
|
|
31
|
-
eventProps[propName] = `() => { ${processedAction} }`;
|
|
36
|
+
eventProps[propName] = `() => { ${processedAction}; renderApp(); }`; // renderApp() 호출 추가로 화면 갱신 유도
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
const eventString = Object.entries(eventProps)
|
|
35
40
|
.map(([k, v]) => `${k}: ${v}`)
|
|
36
41
|
.join(', ');
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
// 템플릿 리터럴을 사용하여 들여쓰기가 적용된 문자열 생성
|
|
44
|
+
return `${indent}h('${node.tag}', {
|
|
45
|
+
${indent} id: '${node.id}',
|
|
46
|
+
${indent} style: ${JSON.stringify(node.styles)},
|
|
47
|
+
${indent} innerHtml: \`${node.innerHtml.replace(/\$(\w+)/g, '${state.$1}')}\`${eventString ? ',\n' + indent + ' ' + eventString : ''}
|
|
48
|
+
${indent}}, [${childrenCode ? '\n' + childrenCode + '\n' + indent : ''}])`;
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
// compiler/index.js 내부
|
package/package.json
CHANGED