Skip to content

Commit c8718b3

Browse files
authored
fix comma operator in debug (#746)
#739
1 parent 69d49f6 commit c8718b3

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
import MagicString from 'magic-string';
21
import { Node } from 'estree-walker';
2+
import MagicString from 'magic-string';
33

44
/**
5-
* {@debug ...} ---> {...}
5+
* {@debug a} ---> {a}
6+
* {@debug a, b} ---> {a}{b}
7+
* tsx won't accept commas, must split
68
*/
7-
export function handleDebug(htmlx: string, str: MagicString, debugBlock: Node): void {
8-
const tokenStart = htmlx.indexOf('@debug', debugBlock.start);
9-
str.remove(tokenStart, tokenStart + '@debug'.length);
9+
export function handleDebug(_htmlx: string, str: MagicString, debugBlock: Node): void {
10+
let cursor = debugBlock.start;
11+
for (const identifier of debugBlock.identifiers as Node[]) {
12+
str.remove(cursor, identifier.start);
13+
str.prependLeft(identifier.start, '{');
14+
str.prependLeft(identifier.end, '}');
15+
cursor = identifier.end;
16+
}
17+
str.remove(cursor, debugBlock.end);
1018
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
<>{ myfile, someOtherFile }</>
1+
<>{myfile}
2+
{myfile}{someOtherFile}
3+
{myfile}{someOtherFile}{someThirdFile}</>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{@debug myfile, someOtherFile }
1+
{@debug myfile}
2+
{@debug myfile , someOtherFile }
3+
{@debug myfile, someOtherFile, someThirdFile }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
///<reference types="svelte" />
2+
<></>;function render() {
3+
<>{myfile}
4+
{__sveltets_store_get(myfile)}{someOtherFile}
5+
{myfile}{__sveltets_store_get(someOtherFile)}{someThirdFile}</>
6+
return { props: {}, slots: {}, getters: {}, events: {} }}
7+
8+
export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) {
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{@debug myfile}
2+
{@debug $myfile , someOtherFile }
3+
{@debug myfile, $someOtherFile, someThirdFile }

0 commit comments

Comments
 (0)