Skip to content

Commit

Permalink
fix bind:this used before assign (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlyu123 committed Jul 26, 2020
1 parent 9fe3db5 commit 5348104
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
8 changes: 6 additions & 2 deletions packages/svelte2tsx/src/htmlxtojsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,12 @@ export function convertHtmlxToJsx(

if (thisType) {
str.remove(attr.start, attr.expression.start);
str.appendLeft(attr.expression.start, `{...__sveltets_ensureType(${thisType}, `);
str.overwrite(attr.expression.end, attr.end, ')}');
str.appendLeft(attr.expression.start, '{...__sveltets_empty(');
str.overwrite(
attr.expression.end,
attr.end,
`=__sveltets_instanceOf(${thisType}))}`
);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<><Component type="radio" {...__sveltets_ensureType(Component, element)} value="Plain"/></>
<><Component type="radio" {...__sveltets_empty(element=__sveltets_instanceOf(Component))} value="Plain"/></>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<><sveltebody {...__sveltets_ensureType(HTMLBodyElement, element)} /></>
<><sveltebody {...__sveltets_empty(element=__sveltets_instanceOf(HTMLBodyElement))} /></>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<><sveltecomponent this={A} {...__sveltets_ensureType(__sveltets_componentType(), element)} /></>
<><sveltecomponent this={A} {...__sveltets_empty(element=__sveltets_instanceOf(__sveltets_componentType()))} /></>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<>{() => {if (false){<>
<svelteself {...__sveltets_ensureType(__sveltets_componentType(), element)} />
<svelteself {...__sveltets_empty(element=__sveltets_instanceOf(__sveltets_componentType()))} />
</>}}}</>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<><input type="radio" {...__sveltets_ensureType(HTMLElement, element)} value="Plain"/></>
<><input type="radio" {...__sveltets_empty(element=__sveltets_instanceOf(HTMLElement))} value="Plain"/></>
4 changes: 2 additions & 2 deletions packages/svelte2tsx/test/sourcemaps/repl.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
<TableOfContents sections={sections} slug={slug} selected={selected}/>
</div>

<div class="chapter-markup" {...__sveltets_ensureType(HTMLElement, scrollable)}>
<div class="chapter-markup" {...__sveltets_empty(scrollable=__sveltets_instanceOf(HTMLElement))}>
{ chapter.html}

<div class="controls">
Expand All @@ -159,7 +159,7 @@

<div class="tutorial-repl">
<Repl
{...__sveltets_ensureType(Repl, repl)}
{...__sveltets_empty(repl=__sveltets_instanceOf(Repl))}
workersUrl="workers"
svelteUrl={svelteUrl}
rollupUrl={rollupUrl}
Expand Down

0 comments on commit 5348104

Please sign in to comment.