Skip to content

Commit 973543c

Browse files
authored
(fix) make bind:this understand specific element type again (#402)
* (fix) make bind:this understand specific element type again The changes done in #363 can be reverted because the bug which the PR was fixing (#338) is also fixed through #314 #400 Revert "fix bind:this used before assign (#363)" This reverts commit 5348104. * fix rename
1 parent fc82a27 commit 973543c

File tree

8 files changed

+18
-17
lines changed

8 files changed

+18
-17
lines changed

packages/language-server/src/plugins/typescript/features/RenameProvider.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,18 @@ export class RenameProviderImpl implements RenameProvider {
311311
}
312312

313313
const content = snapshot.getText(0, snapshot.getLength());
314-
const svelteInstanceOfFn = '__sveltets_instanceOf(';
315314
// When the user renames a Svelte component, ts will also want to rename
316-
// `__sveltets_instanceOf(TheComponentToRename)`. Prevent that.
315+
// `__sveltets_instanceOf(TheComponentToRename)` or
316+
// `__sveltets_ensureType(TheComponentToRename,..`. Prevent that.
317317
return (
318-
content.lastIndexOf(svelteInstanceOfFn, loc.textSpan.start) !==
319-
loc.textSpan.start - svelteInstanceOfFn.length
318+
notPrecededBy('__sveltets_instanceOf(') && notPrecededBy('__sveltets_ensureType(')
320319
);
320+
321+
function notPrecededBy(str: string) {
322+
return (
323+
content.lastIndexOf(str, loc.textSpan.start) !== loc.textSpan.start - str.length
324+
);
325+
}
321326
});
322327
}
323328

packages/svelte2tsx/src/htmlxtojsx.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,8 @@ export function convertHtmlxToJsx(
214214

215215
if (thisType) {
216216
str.remove(attr.start, attr.expression.start);
217-
str.appendLeft(attr.expression.start, '{...__sveltets_empty(');
218-
str.overwrite(
219-
attr.expression.end,
220-
attr.end,
221-
`=__sveltets_instanceOf(${thisType}))}`
222-
);
217+
str.appendLeft(attr.expression.start, `{...__sveltets_ensureType(${thisType}, `);
218+
str.overwrite(attr.expression.end, attr.end, ')}');
223219
return;
224220
}
225221
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<><Component type="radio" {...__sveltets_empty(element=__sveltets_instanceOf(Component))} value="Plain"/></>
1+
<><Component type="radio" {...__sveltets_ensureType(Component, element)} value="Plain"/></>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<><sveltebody {...__sveltets_empty(element=__sveltets_instanceOf(HTMLBodyElement))} /></>
1+
<><sveltebody {...__sveltets_ensureType(HTMLBodyElement, element)} /></>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<><sveltecomponent this={A} {...__sveltets_empty(element=__sveltets_instanceOf(__sveltets_componentType()))} /></>
1+
<><sveltecomponent this={A} {...__sveltets_ensureType(__sveltets_componentType(), element)} /></>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<>{() => {if (false){<>
2-
<svelteself {...__sveltets_empty(element=__sveltets_instanceOf(__sveltets_componentType()))} />
2+
<svelteself {...__sveltets_ensureType(__sveltets_componentType(), element)} />
33
</>}}}</>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<><input type="radio" {...__sveltets_empty(element=__sveltets_instanceOf(HTMLElement))} value="Plain"/></>
1+
<><input type="radio" {...__sveltets_ensureType(HTMLElement, element)} value="Plain"/></>

packages/svelte2tsx/test/sourcemaps/repl.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
<TableOfContents sections={sections} slug={slug} selected={selected}/>
136136
</div>
137137

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

141141
<div class="controls">
@@ -159,7 +159,7 @@
159159

160160
<div class="tutorial-repl">
161161
<Repl
162-
{...__sveltets_empty(repl=__sveltets_instanceOf(Repl))}
162+
{...__sveltets_ensureType(Repl, repl)}
163163
workersUrl="workers"
164164
svelteUrl={svelteUrl}
165165
rollupUrl={rollupUrl}

0 commit comments

Comments
 (0)