-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import MagicString from 'magic-string'; | ||
import { Node } from 'estree-walker'; | ||
|
||
/** | ||
* {#key expr}content{/key} ---> {expr || <>...</>} | ||
*/ | ||
export function handleKey(htmlx: string, str: MagicString, keyBlock: Node): void { | ||
// {#key expr} -> {expr || <> | ||
str.overwrite(keyBlock.start, keyBlock.expression.start, '{'); | ||
const end = htmlx.indexOf('}', keyBlock.expression.end); | ||
str.overwrite(keyBlock.expression.end, end + 1, ' || <>'); | ||
|
||
// {/key} -> </>} | ||
const endKey = htmlx.lastIndexOf('{', keyBlock.end - 1); | ||
str.overwrite(endKey, keyBlock.end, '</>}'); | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/svelte2tsx/test/htmlx2jsx/samples/key-block/expected.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<>{value || <> | ||
<p>hello</p> | ||
</>} | ||
{$store || <> | ||
<p>hello</p> | ||
</>} | ||
{expr.obj || <> | ||
<p>hello</p> | ||
</>}</> |
9 changes: 9 additions & 0 deletions
9
packages/svelte2tsx/test/htmlx2jsx/samples/key-block/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{#key value} | ||
<p>hello</p> | ||
{/key} | ||
{#key $store} | ||
<p>hello</p> | ||
{/key} | ||
{#key expr.obj} | ||
<p>hello</p> | ||
{/key} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters