File tree Expand file tree Collapse file tree 7 files changed +44
-6
lines changed
test/htmlx2jsx/samples/key-block Expand file tree Collapse file tree 7 files changed +44
-6
lines changed Original file line number Diff line number Diff line change 5353 "prettier" : " 2.1.1" ,
5454 "prettier-plugin-svelte" : " ~1.2.1" ,
5555 "source-map" : " ^0.7.3" ,
56- "svelte" : " 3.25.1 " ,
56+ "svelte" : " 3.28.0 " ,
5757 "svelte-preprocess" : " ~4.3.0" ,
5858 "svelte2tsx" : " *" ,
5959 "typescript" : " *" ,
Original file line number Diff line number Diff line change 3232 "rollup-plugin-typescript" : " ^1.0.1" ,
3333 "source-map" : " ^0.6.1" ,
3434 "source-map-support" : " ^0.5.16" ,
35- "svelte" : " 3.25.1 " ,
35+ "svelte" : " 3.28.0 " ,
3636 "tiny-glob" : " ^0.2.6" ,
3737 "tslib" : " ^1.10.0" ,
3838 "typescript" : " ^4.0.2"
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { handleActionDirective } from './nodes/action-directive';
66import { handleAnimateDirective } from './nodes/animation-directive' ;
77import { handleAttribute } from './nodes/attribute' ;
88import { handleAwait } from './nodes/await' ;
9+ import { handleKey } from './nodes/key' ;
910import { handleBinding } from './nodes/binding' ;
1011import { handleClassDirective } from './nodes/class-directive' ;
1112import { handleComment } from './nodes/comment' ;
@@ -60,6 +61,9 @@ export function convertHtmlxToJsx(
6061 case 'AwaitBlock' :
6162 handleAwait ( htmlx , str , node ) ;
6263 break ;
64+ case 'KeyBlock' :
65+ handleKey ( htmlx , str , node ) ;
66+ break ;
6367 case 'RawMustacheTag' :
6468 handleRawHtml ( htmlx , str , node ) ;
6569 break ;
Original file line number Diff line number Diff line change 1+ import MagicString from 'magic-string' ;
2+ import { Node } from 'estree-walker' ;
3+
4+ /**
5+ * {#key expr}content{/key} ---> {expr || <>...</>}
6+ */
7+ export function handleKey ( htmlx : string , str : MagicString , keyBlock : Node ) : void {
8+ // {#key expr} -> {expr || <>
9+ str . overwrite ( keyBlock . start , keyBlock . expression . start , '{' ) ;
10+ const end = htmlx . indexOf ( '}' , keyBlock . expression . end ) ;
11+ str . overwrite ( keyBlock . expression . end , end + 1 , ' || <>' ) ;
12+
13+ // {/key} -> </> }
14+ const endKey = htmlx . lastIndexOf ( '{' , keyBlock . end - 1 ) ;
15+ str . overwrite ( endKey , keyBlock . end , '</>}' ) ;
16+ }
Original file line number Diff line number Diff line change 1+ < > { value || < >
2+ < p > hello</ p >
3+ </ > }
4+ { $store || < >
5+ < p > hello</ p >
6+ </ > }
7+ { expr . obj || < >
8+ < p > hello</ p >
9+ </ > } </ >
Original file line number Diff line number Diff line change 1+ {#key value }
2+ <p >hello</p >
3+ {/ key }
4+ {#key $store }
5+ <p >hello</p >
6+ {/ key }
7+ {#key expr .obj }
8+ <p >hello</p >
9+ {/ key }
Original file line number Diff line number Diff line change @@ -1975,10 +1975,10 @@ svelte-preprocess@~4.3.0:
19751975 detect-indent "^6.0.0"
19761976 strip-indent "^3.0.0"
19771977
1978- svelte@3.25.1 :
1979- version "3.25.1 "
1980- resolved "https://registry.yarnpkg.com/svelte/-/svelte-3.25.1 .tgz#218def1243fea5a97af6eb60f5e232315bb57ac4 "
1981- integrity sha512-IbrVKTmuR0BvDw4ii8/gBNy8REu7nWTRy9uhUz+Yuae5lIjWgSGwKlWtJGC2Vg95s+UnXPqDu0Kk/sUwe0t2GQ ==
1978+ svelte@3.28.0 :
1979+ version "3.28.0 "
1980+ resolved "https://registry.yarnpkg.com/svelte/-/svelte-3.28.0 .tgz#e257fab5666701cf230bea583ceb470bdda1344c "
1981+ integrity sha512-WJW8wD+aTmU5GUnTUjdhVF35mve2MjylubLgB6fGWoXHpYENdwcwWsWvjMQLayzMynqNH733h1Ck8wJzNR7gdQ ==
19821982
19831983table@^5.2.3 :
19841984 version "5.4.6"
You can’t perform that action at this time.
0 commit comments