1
- import { Node } from 'estree-walker' ;
2
1
import MagicString from 'magic-string' ;
3
2
import { walk } from 'svelte/compiler' ;
3
+ import { TemplateNode , Text } from 'svelte/types/compiler/interfaces' ;
4
+ import { Attribute , BaseDirective , BaseNode } from '../interfaces' ;
4
5
import { parseHtmlx } from '../utils/htmlxparser' ;
5
6
import { getSlotName } from '../utils/svelteAst' ;
6
7
import { handleActionDirective } from './nodes/action-directive' ;
@@ -26,7 +27,7 @@ import { handleText } from './nodes/text';
26
27
import { handleTransitionDirective } from './nodes/transition-directive' ;
27
28
import { usesLet } from './utils/node-utils' ;
28
29
29
- type Walker = ( node : Node , parent : Node , prop : string , index : number ) => void ;
30
+ type Walker = ( node : TemplateNode , parent : BaseNode , prop : string , index : number ) => void ;
30
31
31
32
function stripDoctype ( str : MagicString ) : void {
32
33
const regex = / < ! d o c t y p e ( .+ ?) > ( \n ) ? / i;
@@ -42,7 +43,7 @@ function stripDoctype(str: MagicString): void {
42
43
*/
43
44
export function convertHtmlxToJsx (
44
45
str : MagicString ,
45
- ast : Node ,
46
+ ast : TemplateNode ,
46
47
onWalk : Walker = null ,
47
48
onLeave : Walker = null
48
49
) : void {
@@ -56,7 +57,7 @@ export function convertHtmlxToJsx(
56
57
let ifScope = new IfScope ( templateScopeManager ) ;
57
58
58
59
walk ( ast , {
59
- enter : ( node : Node , parent : Node , prop : string , index : number ) => {
60
+ enter : ( node : TemplateNode , parent : BaseNode , prop : string , index : number ) => {
60
61
try {
61
62
switch ( node . type ) {
62
63
case 'IfBlock' :
@@ -123,25 +124,25 @@ export function convertHtmlxToJsx(
123
124
handleComment ( str , node ) ;
124
125
break ;
125
126
case 'Binding' :
126
- handleBinding ( htmlx , str , node , parent ) ;
127
+ handleBinding ( htmlx , str , node as BaseDirective , parent ) ;
127
128
break ;
128
129
case 'Class' :
129
- handleClassDirective ( str , node ) ;
130
+ handleClassDirective ( str , node as BaseDirective ) ;
130
131
break ;
131
132
case 'Action' :
132
- handleActionDirective ( htmlx , str , node , parent ) ;
133
+ handleActionDirective ( htmlx , str , node as BaseDirective , parent ) ;
133
134
break ;
134
135
case 'Transition' :
135
- handleTransitionDirective ( htmlx , str , node , parent ) ;
136
+ handleTransitionDirective ( htmlx , str , node as BaseDirective , parent ) ;
136
137
break ;
137
138
case 'Animation' :
138
- handleAnimateDirective ( htmlx , str , node , parent ) ;
139
+ handleAnimateDirective ( htmlx , str , node as BaseDirective , parent ) ;
139
140
break ;
140
141
case 'Attribute' :
141
- handleAttribute ( htmlx , str , node , parent ) ;
142
+ handleAttribute ( htmlx , str , node as Attribute , parent ) ;
142
143
break ;
143
144
case 'EventHandler' :
144
- handleEventHandler ( htmlx , str , node , parent ) ;
145
+ handleEventHandler ( htmlx , str , node as BaseDirective , parent ) ;
145
146
break ;
146
147
case 'Options' :
147
148
handleSvelteTag ( htmlx , str , node ) ;
@@ -171,7 +172,7 @@ export function convertHtmlxToJsx(
171
172
}
172
173
break ;
173
174
case 'Text' :
174
- handleText ( str , node ) ;
175
+ handleText ( str , node as Text ) ;
175
176
break ;
176
177
}
177
178
if ( onWalk ) {
@@ -183,7 +184,7 @@ export function convertHtmlxToJsx(
183
184
}
184
185
} ,
185
186
186
- leave : ( node : Node , parent : Node , prop : string , index : number ) => {
187
+ leave : ( node : TemplateNode , parent : BaseNode , prop : string , index : number ) => {
187
188
try {
188
189
switch ( node . type ) {
189
190
case 'IfBlock' :
0 commit comments