@junnyontop-pixel/neo-app 1.1.7 → 1.1.8
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 +10 -10
- package/core/NeoCore.js +19 -10
- package/package.json +1 -1
- package/src/App.js +4 -4
package/compiler/index.js
CHANGED
|
@@ -14,38 +14,38 @@ if (!inputFile) {
|
|
|
14
14
|
const source = fs.readFileSync(inputFile, 'utf8');
|
|
15
15
|
const { root, scriptContent } = NeoParser.parse(source);
|
|
16
16
|
|
|
17
|
+
// compiler/index.js 내부 generateCode 함수 수정
|
|
18
|
+
|
|
17
19
|
function generateCode(node, indent = " ") {
|
|
18
|
-
// 자식 노드들을 재귀적으로 호출하며 들여쓰기를 한 단계 더 깊게(indent + " ") 적용합니다.
|
|
19
20
|
const childrenCode = node.children
|
|
20
21
|
.map(child => generateCode(child, indent + " "))
|
|
21
22
|
.join(',\n');
|
|
22
23
|
|
|
23
|
-
// 이벤트 처리 로직 (보내주신 로직 유지)
|
|
24
24
|
const eventProps = {};
|
|
25
25
|
for (const [evt, action] of Object.entries(node.events)) {
|
|
26
26
|
const propName = `on${evt.charAt(0).toUpperCase() + evt.slice(1)}`;
|
|
27
27
|
let processedAction = action;
|
|
28
28
|
|
|
29
|
-
// 단순 연산(++) 대응
|
|
30
29
|
if (action.includes('++')) processedAction = `state.${action}`;
|
|
31
30
|
|
|
32
|
-
// 괄호 자동 보정
|
|
33
31
|
if (processedAction.includes('(') && !processedAction.includes(')')) {
|
|
34
32
|
processedAction += ')';
|
|
35
33
|
}
|
|
36
|
-
|
|
34
|
+
// Proxy가 있으므로 renderApp() 호출은 빼도 됩니다.
|
|
35
|
+
eventProps[propName] = `() => { ${processedAction} }`;
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
const eventString = Object.entries(eventProps)
|
|
40
39
|
.map(([k, v]) => `${k}: ${v}`)
|
|
41
40
|
.join(', ');
|
|
42
41
|
|
|
43
|
-
//
|
|
42
|
+
// 💡 innerHtml을 innerHTML(대문자)로 변경!
|
|
43
|
+
// index.js의 generateCode 함수 리턴 부분
|
|
44
44
|
return `${indent}h('${node.tag}', {
|
|
45
|
-
${indent} id: '${node.id}',
|
|
46
|
-
${indent} style: ${JSON.stringify(node.styles)},
|
|
47
|
-
${indent}
|
|
48
|
-
${indent}}, [${childrenCode ? '\n' + childrenCode + '\n' + indent : ''}])`;
|
|
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 : ''}])`;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
// compiler/index.js 내부
|
package/core/NeoCore.js
CHANGED
|
@@ -23,29 +23,38 @@ export class NeoCore {
|
|
|
23
23
|
|
|
24
24
|
// 가상 노드를 실제 DOM 요소로 변환하는 함수
|
|
25
25
|
export function h(tag, props, children = []) {
|
|
26
|
+
// 1. 태그 생성
|
|
26
27
|
const el = document.createElement(tag);
|
|
27
28
|
|
|
28
|
-
//
|
|
29
|
+
// 2. 속성 설정
|
|
29
30
|
if (props.id) el.id = props.id;
|
|
30
31
|
if (props.style) Object.assign(el.style, props.style);
|
|
31
32
|
|
|
32
|
-
//
|
|
33
|
-
|
|
33
|
+
// 💡 [수정] 대소문자 문제 해결: innerHTML과 innerHtml 둘 다 지원
|
|
34
|
+
const content = props.innerHTML || props.innerHtml;
|
|
35
|
+
if (content !== undefined) {
|
|
36
|
+
el.innerHTML = content;
|
|
37
|
+
}
|
|
34
38
|
|
|
35
|
-
//
|
|
39
|
+
// 3. 이벤트 연결
|
|
36
40
|
Object.keys(props).forEach(key => {
|
|
37
41
|
if (key.startsWith('on') && typeof props[key] === 'function') {
|
|
38
|
-
const eventType = key.toLowerCase().substring(2);
|
|
42
|
+
const eventType = key.toLowerCase().substring(2);
|
|
39
43
|
el.addEventListener(eventType, props[key]);
|
|
40
44
|
}
|
|
41
45
|
});
|
|
42
46
|
|
|
43
|
-
//
|
|
44
|
-
children.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
// 4. 자식 요소 추가 (배열 중첩 및 텍스트 노드 대응 강화)
|
|
48
|
+
const flattenChildren = Array.isArray(children) ? children.flat() : [children];
|
|
49
|
+
|
|
50
|
+
flattenChildren.forEach(child => {
|
|
51
|
+
if (child === null || child === undefined) return;
|
|
52
|
+
|
|
53
|
+
if (child instanceof HTMLElement) {
|
|
48
54
|
el.appendChild(child);
|
|
55
|
+
} else {
|
|
56
|
+
// 숫자나 문자열 등은 텍스트 노드로 변환하여 추가
|
|
57
|
+
el.appendChild(document.createTextNode(String(child)));
|
|
49
58
|
}
|
|
50
59
|
});
|
|
51
60
|
|
package/package.json
CHANGED
package/src/App.js
CHANGED