@@ -5,7 +5,7 @@ export class NeoParser {
55 if ( scriptMatch ) scriptContent = scriptMatch [ 1 ] . trim ( ) ;
66
77 // 태그 블록만 추출하기 위해 스크립트 제외
8- const cleanSource = source . replace ( / @ S c r i p t \s * \{ [ \s \S ] * ?\} / , "" ) . trim ( ) ;
8+ const cleanSource = source . replace ( / @ S c r i p t \s * \{ [ \s \S ] * ?\} / , "" ) . trim ( ) ;
99
1010 const root = this . parseRecursive ( cleanSource ) ;
1111 return { root, scriptContent } ;
@@ -39,21 +39,23 @@ export class NeoParser {
3939
4040 const blockContent = text . substring ( startIndex , endIndex - 1 ) ;
4141
42+ const contentWithoutChildren = blockContent . replace ( / @ \w + : \w + \s * \{ [ \s \S ] * ?\} / g, "" ) ;
43+
4244 // 1. 블록 내부에서 속성 추출 (Innerhtml, Style, Event)
4345 // 줄바꿈과 대소문자를 무시하고 " " 사이의 값을 정확히 가져옴
44- const htmlMatch = blockContent . match ( / I n n e r h t m l : \s * " ( [ \s \S ] * ?) " / i) ;
46+ const htmlMatch = blockContent . match ( / i n n e r H T M L : \s * " ( [ \s \S ] * ?) " / i) ;
4547 if ( htmlMatch ) node . innerHtml = htmlMatch [ 1 ] . trim ( ) ;
4648
4749 const styleMatch = blockContent . match ( / S t y l e \( ( [ \s \S ] * ?) \) / i) ;
4850 if ( styleMatch ) node . styles = this . parseKV ( styleMatch [ 1 ] ) ;
4951
50- const eventMatch = blockContent . match ( / E v e n t \( ( [ \s \S ] * ?) \) / i) ;
52+ const eventMatch = contentWithoutChildren . match ( / E v e n t \( ( [ \s \S ] * ?) \) / i) ;
5153 if ( eventMatch ) node . events = this . parseKV ( eventMatch [ 1 ] ) ;
5254
5355 // 2. 자식 노드 재귀적 탐색
5456 // 본인의 속성 정의 부분을 제외한 나머지 텍스트에서 자식 탐색
5557 const remainingText = blockContent
56- . replace ( / I n n e r h t m l : \s * " [ \s \S ] * ?" / i, "" )
58+ . replace ( / i n n e r H T M L : \s * " [ \s \S ] * ?" / i, "" )
5759 . replace ( / S t y l e \( .* ?\) / si, "" )
5860 . replace ( / E v e n t \( .* ?\) / si, "" ) ;
5961
@@ -64,8 +66,19 @@ export class NeoParser {
6466 const childNode = this . parseRecursive ( remainingText . substring ( childMatch . index ) ) ;
6567 if ( childNode ) {
6668 node . children . push ( childNode ) ;
67- // 중복 탐색 방지를 위해 인덱스 건너뛰기 로직 생략 (현재 구조 최적화)
68- break ; // 예시용 단일 자식 우선 처리, 실제론 루프 최적화 필요
69+
70+ // 자식 노드의 끝 지점을 찾아서 다음 검색 위치를 조정
71+ let braceCount = 1 ;
72+ let i = remainingText . indexOf ( '{' , childMatch . index ) + 1 ;
73+
74+ while ( braceCount > 0 && i < remainingText . length ) {
75+ if ( remainingText [ i ] === '{' ) braceCount ++ ;
76+ else if ( remainingText [ i ] === '}' ) braceCount -- ;
77+ i ++ ;
78+ }
79+
80+ // 정규식의 다음 검색 시작 위치를 자식 노드가 끝난 지점(i)으로 옮겨줘
81+ childRegex . lastIndex = i ;
6982 }
7083 }
7184
0 commit comments