Skip to content

Commit

Permalink
more skip
Browse files Browse the repository at this point in the history
  • Loading branch information
baseballyama committed Nov 23, 2023
1 parent c8adb0b commit 136e6e0
Show file tree
Hide file tree
Showing 7 changed files with 2,610 additions and 23 deletions.
22 changes: 2 additions & 20 deletions src/parser/converts/attr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { ParseError } from "../../errors";
import type { ScriptLetCallback } from "../../context/script-let";
import type { AttributeToken } from "../html";
import { svelteVersion } from "../svelte-version";
import { hasTypeInfo } from "../../utils";

/** Convert for Attributes */
export function* convertAttributes(
Expand Down Expand Up @@ -923,7 +924,7 @@ function buildProcessExpressionForExpression(
): (expression: ESTree.Expression) => ScriptLetCallback<ESTree.Expression>[] {
return (expression) => {
if (hasTypeInfo(expression)) {
return ctx.scriptLet.addExpression(expression, directive);
return ctx.scriptLet.addExpression(expression, directive, null);
}
return ctx.scriptLet.addExpression(expression, directive, typing);
};
Expand All @@ -944,22 +945,3 @@ function buildExpressionTypeChecker<T extends ESTree.Expression>(
}
};
}

function hasTypeInfo(element: any): boolean {
if (element.type?.startsWith("TS")) {
return true;
}
for (const key of Object.keys(element)) {
if (key === "parent") continue;
const value = element[key];
if (value == null) continue;
if (typeof value === "object") {
if (hasTypeInfo(value)) return true;
} else if (Array.isArray(value)) {
for (const v of value) {
if (typeof v === "object" && hasTypeInfo(v)) return true;
}
}
}
return false;
}
14 changes: 11 additions & 3 deletions src/parser/converts/mustache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import type {
} from "../../ast";
import type { Context } from "../../context";
import type * as SvAST from "../svelte-ast-types";
import { hasTypeInfo } from "../../utils";

/** Convert for MustacheTag */
export function convertMustacheTag(
node: SvAST.MustacheTag,
Expand Down Expand Up @@ -76,8 +78,14 @@ function convertMustacheTag0<T extends SvelteMustacheTag>(
parent,
...ctx.getConvertLocation(node),
} as T;
ctx.scriptLet.addExpression(node.expression, mustache, typing, (es) => {
mustache.expression = es;
});

ctx.scriptLet.addExpression(
node.expression,
mustache,
hasTypeInfo(node.expression) ? null : typing,
(es) => {
mustache.expression = es;
},
);
return mustache;
}
19 changes: 19 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,22 @@ export function sortedLastIndex<T>(

return upper;
}

export function hasTypeInfo(element: any): boolean {
if (element.type?.startsWith("TS")) {
return true;
}
for (const key of Object.keys(element)) {
if (key === "parent") continue;
const value = element[key];
if (value == null) continue;
if (typeof value === "object") {
if (hasTypeInfo(value)) return true;
} else if (Array.isArray(value)) {
for (const v of value) {
if (typeof v === "object" && hasTypeInfo(v)) return true;
}
}
}
return false;
}
9 changes: 9 additions & 0 deletions tests/fixtures/parser/ast/svelte5/ts-event08-input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script lang="ts">
let count = $state(0);
</script>

<button onclick={(event: number) => {
count += event;
}}>
clicks: {count}
</button>

0 comments on commit 136e6e0

Please sign in to comment.