1
1
// https://github.com/justin-schroeder/arrow-js/blob/31c1861075aabe29b67620b58a33c7fecb209c8f/src/html.ts#L166C1-L166C23
2
2
const delimiter = '➳❍'
3
- const bookend = '❍⇚'
4
3
const delimiterComment = `<!--${ delimiter } -->`
4
+
5
+ //FIXME: Don't really need to handle
6
+ const bookend = '❍⇚'
5
7
const bookendComment = `<!--${ bookend } -->`
6
8
9
+ const eventRegex = / ( @ ) ( \w + ) = [ " ' ] $ /
10
+
7
11
export function renderToString ( template ) {
8
12
const isT = 'isT' in template
9
13
@@ -17,41 +21,55 @@ export function renderToString(template) {
17
21
18
22
let htmlString = renderResult [ 0 ]
19
23
const expressions = renderResult [ 1 ]
20
- if ( expressions . length > 0 ) {
21
- expressions . forEach ( expressionInstance => {
22
- const isExpressionReactive = expressionInstance && expressionInstance . e
23
- const isExpressionPartial = isExpressionReactive . isT
24
-
25
- if ( ! isExpressionReactive ) {
26
- htmlString = htmlString . replace ( delimiterComment , expressionInstance ( ) )
27
- return
28
- }
24
+ const evntsOnIndex = [ ]
25
+ let index = - 1
29
26
30
- if ( isExpressionPartial ) {
31
- htmlString = htmlString . replace (
32
- delimiterComment ,
33
- renderToString ( expressionInstance . e )
34
- )
35
- return
36
- }
27
+ if ( ! expressions . length ) return htmlString
37
28
38
- const watcherReturn = expressionInstance . e ( )
29
+ return htmlString . replace (
30
+ new RegExp ( delimiterComment , 'g' ) ,
31
+ ( ...matchers ) => {
32
+ const str = matchers [ 0 ]
33
+ const matchedAt = matchers [ 1 ]
34
+ const matchedString = matchers [ 2 ]
35
+ index += 1
39
36
40
- if (
41
- typeof watcherReturn !== 'object' &&
42
- typeof watcherReturn !== 'function'
43
- ) {
44
- htmlString = htmlString . replace ( delimiterComment , watcherReturn )
45
- return
37
+ const beforeDelim = matchedString . slice ( 0 , matchedAt )
38
+ const immediatelyFollowed = eventRegex . test ( beforeDelim )
39
+ if ( immediatelyFollowed ) {
40
+ return str
46
41
}
42
+ return interpolateExpressions ( str , expressions [ index ] )
43
+ }
44
+ )
45
+ }
47
46
48
- if ( watcherReturn && watcherReturn . isT ) {
49
- const _nestedHtmlString = renderToString ( watcherReturn )
50
- htmlString = htmlString . replace ( delimiterComment , _nestedHtmlString )
51
- return
52
- }
53
- } )
47
+ function interpolateExpressions ( htmlString , expressionInstance ) {
48
+ const isExpressionReactive = expressionInstance && expressionInstance . e
49
+ const isExpressionPartial = isExpressionReactive . isT
50
+
51
+ if ( ! isExpressionReactive ) {
52
+ return htmlString . replace ( delimiterComment , expressionInstance ( ) )
53
+ }
54
+
55
+ if ( isExpressionPartial ) {
56
+ return htmlString . replace (
57
+ delimiterComment ,
58
+ renderToString ( expressionInstance . e )
59
+ )
54
60
}
55
61
56
- return htmlString
62
+ const watcherReturn = expressionInstance . e ( )
63
+
64
+ if (
65
+ typeof watcherReturn !== 'object' &&
66
+ typeof watcherReturn !== 'function'
67
+ ) {
68
+ return htmlString . replace ( delimiterComment , watcherReturn )
69
+ }
70
+
71
+ if ( watcherReturn && watcherReturn . isT ) {
72
+ const _nestedHtmlString = renderToString ( watcherReturn )
73
+ return htmlString . replace ( delimiterComment , _nestedHtmlString )
74
+ }
57
75
}
0 commit comments