Skip to content

Commit dc286ae

Browse files
authored
Fix bug on typescript (#28)
1 parent 2290d99 commit dc286ae

File tree

9 files changed

+5195
-4
lines changed

9 files changed

+5195
-4
lines changed

src/context/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,15 @@ function* extractBlocks(code: string): IterableIterator<{
153153
const codeRange: [number, number] = [startTagEnd, endTagStart]
154154

155155
const attrRe =
156-
// eslint-disable-next-line regexp/no-unused-capturing-group -- maybe bug
157-
/(<key>[^\s=]+)(?:=(?:"(<val>[^"]*)"|'(<val>[^"]*)'|(<val>[^\s=]+)))?/giu
156+
/(?<key>[^\s=]+)(?:=(?:"(?<val1>[^"]*)"|'(?<val2>[^"]*)'|(?<val3>[^\s=]+)))?/giu
158157
const attrs: Record<string, string | undefined> = {}
159158
let attrRes
160159
while ((attrRes = attrRe.exec(attributes))) {
161-
attrs[attrRes.groups!.key] = attrRes.groups!.val
160+
attrs[attrRes.groups!.key] =
161+
(attrRes.groups!.val1 ||
162+
attrRes.groups!.val2 ||
163+
attrRes.groups!.val3) ??
164+
null
162165
}
163166
yield {
164167
code: code.slice(...codeRange),

src/parser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function parseForESLint(
111111
statement = statements[0]
112112
}
113113
if (
114-
body.startTag.attributes.every(
114+
!body.startTag.attributes.some(
115115
(attr) =>
116116
attr.type === "SvelteAttribute" &&
117117
attr.key.name === "context" &&
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<script lang="ts">
2+
export let visible:boolean = false;
3+
4+
function typewriter(node:HTMLElement, { speed = 50 }) {
5+
const valid = (
6+
node.childNodes.length === 1 &&
7+
node.childNodes[0].nodeType === Node.TEXT_NODE
8+
);
9+
10+
if (!valid) return {};
11+
12+
const text = node.textContent!;
13+
const duration = text.length * speed;
14+
15+
return {
16+
duration,
17+
tick: (t:number, _u:number) => {
18+
const i = ~~(text.length * t);
19+
node.textContent = text.slice(0, i);
20+
}
21+
};
22+
}
23+
</script>
24+
25+
{#if visible}
26+
<p in:typewriter="{{ speed: 20 }}">
27+
The quick brown fox jumps over the lazy dog
28+
</p>
29+
{/if}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"ruleId": "no-unused-vars",
4+
"code": "_u:number",
5+
"line": 17,
6+
"column": 21
7+
}
8+
]

0 commit comments

Comments
 (0)