Skip to content

Commit

Permalink
fix comma operator in debug (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
pushkine committed Jan 8, 2021
1 parent 69d49f6 commit c8718b3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
18 changes: 13 additions & 5 deletions packages/svelte2tsx/src/htmlxtojsx/nodes/debug.ts
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);
}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<>{ myfile, someOtherFile }</>
<>{myfile}
{myfile}{someOtherFile}
{myfile}{someOtherFile}{someThirdFile}</>
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 }
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))) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{@debug myfile}
{@debug $myfile , someOtherFile }
{@debug myfile, $someOtherFile, someThirdFile }

0 comments on commit c8718b3

Please sign in to comment.