@junnyontop-pixel/neo-app 1.1.3 → 1.1.5

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.
@@ -1,52 +1,82 @@
1
1
  export class NeoParser {
2
- static parse(code) {
3
- // 1. @Script 블록 추출 로직 개선
4
- // 괄호를 포함해서 캡처한 뒤, 앞뒤 껍데기만 날리는 방식이 가장 안전합니다.
5
- const scriptMatch = code.match(/@Script\s*\{([\s\S]*?)\}(?=\s*@|$)/);
2
+ static parse(source) {
3
+ const lines = source.split('\n');
4
+ let root = null;
6
5
  let scriptContent = "";
7
-
6
+ const stack = [];
7
+
8
+ // 1. 스크립트 영역 추출 (@Script { ... })
9
+ const scriptMatch = source.match(/@Script\s*\{([\s\S]*?)\}/);
8
10
  if (scriptMatch) {
9
11
  scriptContent = scriptMatch[1].trim();
10
- // 만약 사용자가 적은 마지막 } 가 잘려 나갔다면 복구하거나,
11
- // 원본에서 블록 전체를 가져오는 로직으로 보강
12
12
  }
13
13
 
14
- // 2. UI 요소 추출 (이 부분은 동일)
15
- const uiCode = code.replace(/@Script\s*\{[\s\S]*?\}\s*/, "");
16
- const tokenRegex = /(@\w+:\w+)|(Innerhtml:\s*".*?")|(Style\([\s\S]*?\))|(Event\([\s\S]*?\))|(\{)|(\})/g;
17
- const tokens = uiCode.match(tokenRegex);
18
-
19
- const stack = [];
20
- let root = null;
14
+ // 2. 태그 파싱
15
+ const tagRegex = /@(\w+):(\w+)\s*\{/g;
16
+ let match;
17
+ const tags = [];
18
+
19
+ // 소스에서 태그 블록들을 찾아내기 위한 단순화된 로직
20
+ const tokens = source.split(/(@\w+:\w+\s*\{)/).filter(t => t.trim());
21
21
 
22
22
  tokens.forEach(token => {
23
- if (token.startsWith('@')) {
24
- const [_, id, tag] = token.match(/@(\w+):(\w+)/);
25
- const node = { id, tag, innerHtml: "", styles: {}, events: {}, children: [] };
26
- if (stack.length > 0) stack[stack.length - 1].children.push(node);
27
- else if (!root) root = node;
23
+ const tagMatch = token.match(/@(\w+):(\w+)\s*\{/);
24
+
25
+ if (tagMatch) {
26
+ const node = {
27
+ id: tagMatch[1],
28
+ tag: tagMatch[2],
29
+ styles: {},
30
+ events: {},
31
+ innerHtml: "",
32
+ children: []
33
+ };
34
+
35
+ // Style 추출 (안전 장치 추가)
36
+ const styleMatch = token.match(/Style\((.*?)\)/s);
37
+ if (styleMatch && styleMatch[1]) {
38
+ node.styles = this.parseKV(styleMatch[1]);
39
+ }
40
+
41
+ // Event 추출 (안전 장치 추가)
42
+ const eventMatch = token.match(/Event\((.*?)\)/s);
43
+ if (eventMatch && eventMatch[1]) {
44
+ node.events = this.parseKV(eventMatch[1]);
45
+ }
46
+
47
+ // Innerhtml 추출
48
+ const htmlMatch = token.match(/Innerhtml:\s*"(.*?)"/);
49
+ if (htmlMatch) {
50
+ node.innerHtml = htmlMatch[1];
51
+ }
52
+
53
+ if (!root) {
54
+ root = node;
55
+ } else {
56
+ stack[stack.length - 1].children.push(node);
57
+ }
28
58
  stack.push(node);
29
- } else if (token === '}') {
30
- stack.pop();
31
- } else if (token.startsWith('Innerhtml')) {
32
- stack[stack.length - 1].innerHtml = token.match(/"(.*?)"/)[1];
33
- } else if (token.startsWith('Style')) {
34
- stack[stack.length - 1].styles = this.parseKV(token.match(/Style\((.*?)\)/)[1]);
35
- } else if (token.startsWith('Event')) {
36
- stack[stack.length - 1].events = this.parseKV(token.match(/Event\((.*?)\)/)[1]);
59
+ }
60
+
61
+ if (token.includes('}')) {
62
+ const closeCount = (token.match(/\}/g) || []).length;
63
+ for (let i = 0; i < closeCount; i++) {
64
+ if (stack.length > 0) stack.pop();
65
+ }
37
66
  }
38
67
  });
39
68
 
40
69
  return { root, scriptContent };
41
70
  }
42
71
 
43
- static parseKV(str) {
72
+ static parseKV(kvString) {
73
+ if (!kvString || !kvString.trim()) return {};
44
74
  const obj = {};
45
- str.split(';').forEach(line => {
46
- const [k, v] = line.split(':').map(s => s?.trim());
47
- if (k && v) {
48
- const camelK = k.replace(/-([a-z])/g, g => g[1].toUpperCase());
49
- obj[camelK] = v;
75
+ const pairs = kvString.split(';');
76
+ pairs.forEach(pair => {
77
+ if (pair.includes(':')) {
78
+ const [key, value] = pair.split(':').map(s => s.trim());
79
+ if (key && value) obj[key] = value;
50
80
  }
51
81
  });
52
82
  return obj;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@junnyontop-pixel/neo-app",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "나만의 커스텀 프레임워크 Neo",
5
5
  "main": "core/NeoCore.js",
6
6
  "type": "module",
7
7
  "bin": {
8
- "neoc": "./compiler/index.js",
9
- "neoc-init": "./scripts/init.js"
8
+ "neoc": "compiler/index.js",
9
+ "neoc-init": "scripts/init.js"
10
10
  },
11
11
  "files": [
12
12
  "compiler",
package/src/App.js CHANGED
@@ -4,13 +4,12 @@ import { h } from '@junnyontop-pixel/neo-app/core/NeoCore.js';
4
4
 
5
5
  // [User Script]
6
6
  function sayHello() {
7
- alert("안녕하세요!");
8
- }
7
+ alert("안녕하세요!");
9
8
 
10
9
  export default function render(state) {
11
10
  return h('button', {
12
11
  id: 'Btn',
13
12
  style: {},
14
- innerHtml: `인사하기`, onClick: () => { sayHello() }
13
+ innerHtml: ``
15
14
  }, []);
16
15
  }