-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
31 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
import MagicString from 'magic-string'; | ||
import { Node } from 'estree-walker'; | ||
import MagicString from 'magic-string'; | ||
|
||
/** | ||
* {@debug ...} ---> {...} | ||
* {@debug a} ---> {a} | ||
* {@debug a, b} ---> {a}{b} | ||
* tsx won't accept commas, must split | ||
*/ | ||
export function handleDebug(htmlx: string, str: MagicString, debugBlock: Node): void { | ||
const tokenStart = htmlx.indexOf('@debug', debugBlock.start); | ||
str.remove(tokenStart, tokenStart + '@debug'.length); | ||
export function handleDebug(_htmlx: string, str: MagicString, debugBlock: Node): void { | ||
let cursor = debugBlock.start; | ||
for (const identifier of debugBlock.identifiers as Node[]) { | ||
str.remove(cursor, identifier.start); | ||
str.prependLeft(identifier.start, '{'); | ||
str.prependLeft(identifier.end, '}'); | ||
cursor = identifier.end; | ||
} | ||
str.remove(cursor, debugBlock.end); | ||
} |
4 changes: 3 additions & 1 deletion
4
packages/svelte2tsx/test/htmlx2jsx/samples/debug-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 |
---|---|---|
@@ -1 +1,3 @@ | ||
<>{ myfile, someOtherFile }</> | ||
<>{myfile} | ||
{myfile}{someOtherFile} | ||
{myfile}{someOtherFile}{someThirdFile}</> |
4 changes: 3 additions & 1 deletion
4
packages/svelte2tsx/test/htmlx2jsx/samples/debug-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 |
---|---|---|
@@ -1 +1,3 @@ | ||
{@debug myfile, someOtherFile } | ||
{@debug myfile} | ||
{@debug myfile , someOtherFile } | ||
{@debug myfile, someOtherFile, someThirdFile } |
9 changes: 9 additions & 0 deletions
9
packages/svelte2tsx/test/svelte2tsx/samples/debug-block/expected.tsx
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 @@ | ||
///<reference types="svelte" /> | ||
<></>;function render() { | ||
<>{myfile} | ||
{__sveltets_store_get(myfile)}{someOtherFile} | ||
{myfile}{__sveltets_store_get(someOtherFile)}{someThirdFile}</> | ||
return { props: {}, slots: {}, getters: {}, events: {} }} | ||
|
||
export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) { | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/svelte2tsx/test/svelte2tsx/samples/debug-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,3 @@ | ||
{@debug myfile} | ||
{@debug $myfile , someOtherFile } | ||
{@debug myfile, $someOtherFile, someThirdFile } |