Skip to content

Commit 136e6e0

Browse files
committed
more skip
1 parent c8adb0b commit 136e6e0

File tree

7 files changed

+2610
-23
lines changed

7 files changed

+2610
-23
lines changed

Diff for: src/parser/converts/attr.ts

+2-20
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { ParseError } from "../../errors";
3434
import type { ScriptLetCallback } from "../../context/script-let";
3535
import type { AttributeToken } from "../html";
3636
import { svelteVersion } from "../svelte-version";
37+
import { hasTypeInfo } from "../../utils";
3738

3839
/** Convert for Attributes */
3940
export function* convertAttributes(
@@ -923,7 +924,7 @@ function buildProcessExpressionForExpression(
923924
): (expression: ESTree.Expression) => ScriptLetCallback<ESTree.Expression>[] {
924925
return (expression) => {
925926
if (hasTypeInfo(expression)) {
926-
return ctx.scriptLet.addExpression(expression, directive);
927+
return ctx.scriptLet.addExpression(expression, directive, null);
927928
}
928929
return ctx.scriptLet.addExpression(expression, directive, typing);
929930
};
@@ -944,22 +945,3 @@ function buildExpressionTypeChecker<T extends ESTree.Expression>(
944945
}
945946
};
946947
}
947-
948-
function hasTypeInfo(element: any): boolean {
949-
if (element.type?.startsWith("TS")) {
950-
return true;
951-
}
952-
for (const key of Object.keys(element)) {
953-
if (key === "parent") continue;
954-
const value = element[key];
955-
if (value == null) continue;
956-
if (typeof value === "object") {
957-
if (hasTypeInfo(value)) return true;
958-
} else if (Array.isArray(value)) {
959-
for (const v of value) {
960-
if (typeof v === "object" && hasTypeInfo(v)) return true;
961-
}
962-
}
963-
}
964-
return false;
965-
}

Diff for: src/parser/converts/mustache.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import type {
66
} from "../../ast";
77
import type { Context } from "../../context";
88
import type * as SvAST from "../svelte-ast-types";
9+
import { hasTypeInfo } from "../../utils";
10+
911
/** Convert for MustacheTag */
1012
export function convertMustacheTag(
1113
node: SvAST.MustacheTag,
@@ -76,8 +78,14 @@ function convertMustacheTag0<T extends SvelteMustacheTag>(
7678
parent,
7779
...ctx.getConvertLocation(node),
7880
} as T;
79-
ctx.scriptLet.addExpression(node.expression, mustache, typing, (es) => {
80-
mustache.expression = es;
81-
});
81+
82+
ctx.scriptLet.addExpression(
83+
node.expression,
84+
mustache,
85+
hasTypeInfo(node.expression) ? null : typing,
86+
(es) => {
87+
mustache.expression = es;
88+
},
89+
);
8290
return mustache;
8391
}

Diff for: src/utils/index.ts

+19
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,22 @@ export function sortedLastIndex<T>(
5959

6060
return upper;
6161
}
62+
63+
export function hasTypeInfo(element: any): boolean {
64+
if (element.type?.startsWith("TS")) {
65+
return true;
66+
}
67+
for (const key of Object.keys(element)) {
68+
if (key === "parent") continue;
69+
const value = element[key];
70+
if (value == null) continue;
71+
if (typeof value === "object") {
72+
if (hasTypeInfo(value)) return true;
73+
} else if (Array.isArray(value)) {
74+
for (const v of value) {
75+
if (typeof v === "object" && hasTypeInfo(v)) return true;
76+
}
77+
}
78+
}
79+
return false;
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script lang="ts">
2+
let count = $state(0);
3+
</script>
4+
5+
<button onclick={(event: number) => {
6+
count += event;
7+
}}>
8+
clicks: {count}
9+
</button>

0 commit comments

Comments
 (0)