Skip to content

Commit 0a96b72

Browse files
authored
(fix) ignore typeof $store (#908)
Don't translate this into a store access #903
1 parent 966d411 commit 0a96b72

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,17 @@ export function processInstanceScriptContent(
142142
};
143143

144144
const handleStore = (ident: ts.Identifier, parent: ts.Node) => {
145+
// ignore "typeof $store"
146+
if (parent && parent.kind === ts.SyntaxKind.TypeQuery) {
147+
return;
148+
}
149+
// ignore break
150+
if (parent && parent.kind === ts.SyntaxKind.BreakStatement) {
151+
return;
152+
}
153+
145154
const storename = ident.getText().slice(1); // drop the $
146155
// handle assign to
147-
// eslint-disable-next-line max-len
148156
if (
149157
parent &&
150158
ts.isBinaryExpression(parent) &&
@@ -160,10 +168,7 @@ export function processInstanceScriptContent(
160168
str.appendLeft(parent.end + astOffset, ')');
161169
return;
162170
}
163-
// ignore break
164-
if (parent && parent.kind === ts.SyntaxKind.BreakStatement) {
165-
return;
166-
}
171+
167172
// handle Assignment operators ($store +=, -=, *=, /=, %=, **=, etc.)
168173
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Assignment
169174
const operators = {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
///<reference types="svelte" />
2+
<></>;
3+
import {writable} from "svelte/store";
4+
function render() {
5+
6+
7+
const foo = writable(1)/*Ωignore_startΩ*/;let $foo = __sveltets_store_get(foo);/*Ωignore_endΩ*/;
8+
type Foo = typeof $foo;
9+
;
10+
() => (<></>);
11+
return { props: {}, slots: {}, getters: {}, events: {} }}
12+
13+
export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) {
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script lang="ts">
2+
import {writable} from "svelte/store";
3+
const foo = writable(1);
4+
type Foo = typeof $foo;
5+
</script>

0 commit comments

Comments
 (0)