@junnyontop-pixel/neo-app 1.1.13 → 1.1.15
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/NeoParser.js +14 -3
- package/compiler/index.js +24 -18
- package/package.json +1 -1
- package/src/App.js +5 -4
package/compiler/NeoParser.js
CHANGED
|
@@ -5,7 +5,7 @@ export class NeoParser {
|
|
|
5
5
|
if (scriptMatch) scriptContent = scriptMatch[1].trim();
|
|
6
6
|
|
|
7
7
|
// 태그 블록만 추출하기 위해 스크립트 제외
|
|
8
|
-
const cleanSource = source.replace(/@Script\s*\{[\s\S]*?\}/, "").trim();
|
|
8
|
+
const cleanSource = source.replace(/@Script\s*\{[\s\S]*?\}/, "").trim();
|
|
9
9
|
|
|
10
10
|
const root = this.parseRecursive(cleanSource);
|
|
11
11
|
return { root, scriptContent };
|
|
@@ -64,8 +64,19 @@ export class NeoParser {
|
|
|
64
64
|
const childNode = this.parseRecursive(remainingText.substring(childMatch.index));
|
|
65
65
|
if (childNode) {
|
|
66
66
|
node.children.push(childNode);
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
|
|
68
|
+
// 자식 노드의 끝 지점을 찾아서 다음 검색 위치를 조정
|
|
69
|
+
let braceCount = 1;
|
|
70
|
+
let i = remainingText.indexOf('{', childMatch.index) + 1;
|
|
71
|
+
|
|
72
|
+
while (braceCount > 0 && i < remainingText.length) {
|
|
73
|
+
if (remainingText[i] === '{') braceCount++;
|
|
74
|
+
else if (remainingText[i] === '}') braceCount--;
|
|
75
|
+
i++;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 정규식의 다음 검색 시작 위치를 자식 노드가 끝난 지점(i)으로 옮겨줘
|
|
79
|
+
childRegex.lastIndex = i;
|
|
69
80
|
}
|
|
70
81
|
}
|
|
71
82
|
|
package/compiler/index.js
CHANGED
|
@@ -22,24 +22,30 @@ try {
|
|
|
22
22
|
|
|
23
23
|
// 3. 코드 생성 함수 (재귀 구조)
|
|
24
24
|
function generateCode(node, indent = " ") {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
$
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
25
|
+
|
|
26
|
+
const textNode = node.innerHtml
|
|
27
|
+
? `\`${node.innerHtml.replace(/\$(\w+)/g, '${state.$1}')}\``
|
|
28
|
+
: null;
|
|
29
|
+
|
|
30
|
+
const childrenCode = node.children
|
|
31
|
+
.map(child => generateCode(child, indent + " "))
|
|
32
|
+
.join(',\n');
|
|
33
|
+
|
|
34
|
+
const allChildren = [textNode, childrenCode].filter(Boolean).join(',\n');
|
|
35
|
+
|
|
36
|
+
// 이벤트들을 객체 문자열로 변환
|
|
37
|
+
const eventProps = Object.entries(node.events).map(([evt, action]) => {
|
|
38
|
+
const propName = `on${evt.charAt(0).toUpperCase() + evt.slice(1)}`;
|
|
39
|
+
// $count -> state.count로 치환
|
|
40
|
+
let processedAction = action.replace(/\$(\w+)/g, 'state.$1');
|
|
41
|
+
return `${propName}: () => { ${processedAction} }`;
|
|
42
|
+
}).join(`,\n${indent} `);
|
|
43
|
+
|
|
44
|
+
return `${indent}h('${node.tag}', {
|
|
45
|
+
${indent} id: '${node.id}',
|
|
46
|
+
${indent} style: ${JSON.stringify(node.styles)}${eventProps ? ',\n' + indent + ' ' + eventProps : ''}
|
|
47
|
+
${indent}}, [${allChildren ? '\n' + allChildren + '\n' + indent : ''}])`;
|
|
48
|
+
}
|
|
43
49
|
|
|
44
50
|
// render 함수 생성 부분
|
|
45
51
|
const finalJS = `
|
package/package.json
CHANGED
package/src/App.js
CHANGED
|
@@ -6,9 +6,10 @@ export default function render(state) {
|
|
|
6
6
|
if (state.title === undefined) state.title = "hello, neo";
|
|
7
7
|
|
|
8
8
|
return h('button', {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
innerHTML: `인사하기`,
|
|
9
|
+
id: 'Btn',
|
|
10
|
+
style: {},
|
|
12
11
|
onClick: () => { sayHello( }
|
|
13
|
-
|
|
12
|
+
}, [
|
|
13
|
+
`인사하기`
|
|
14
|
+
]);
|
|
14
15
|
}
|