Skip to content

Commit 0595770

Browse files
committed
better
1 parent 5e4c194 commit 0595770

File tree

3 files changed

+73
-82
lines changed

3 files changed

+73
-82
lines changed

packages/svelte/src/compiler/phases/1-parse/state/element.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export default function tag(parser) {
6565
const data = parser.read_until(regex_closing_comment);
6666
parser.eat('-->', true);
6767

68+
/** @type {ReturnType<typeof parser.append<import('#compiler').Comment>>} */
6869
parser.append({
6970
type: 'Comment',
7071
start,

packages/svelte/src/compiler/phases/1-parse/state/tag.js

Lines changed: 64 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,17 @@ export default function mustache(parser) {
2323
parser.allow_whitespace();
2424
parser.eat('}', true);
2525

26-
parser.append(
27-
/** @type {import('#compiler').ExpressionTag} */ ({
28-
type: 'ExpressionTag',
29-
start,
30-
end: parser.index,
31-
expression,
32-
metadata: {
33-
contains_call_expression: false,
34-
dynamic: false
35-
}
36-
})
37-
);
26+
/** @type {ReturnType<typeof parser.append<import('#compiler').ExpressionTag>>} */
27+
parser.append({
28+
type: 'ExpressionTag',
29+
start,
30+
end: parser.index,
31+
expression,
32+
metadata: {
33+
contains_call_expression: false,
34+
dynamic: false
35+
}
36+
});
3837
}
3938

4039
/** @param {import('../index.js').Parser} parser */
@@ -44,7 +43,8 @@ function open(parser) {
4443
if (parser.eat('if')) {
4544
parser.require_whitespace();
4645

47-
const block = /** @type {typeof parser.append<import('#compiler').IfBlock>} */ (parser.append)({
46+
/** @type {ReturnType<typeof parser.append<import('#compiler').IfBlock>>} */
47+
const block = parser.append({
4848
type: 'IfBlock',
4949
elseif: false,
5050
start,
@@ -164,9 +164,8 @@ function open(parser) {
164164

165165
parser.eat('}', true);
166166

167-
const block = /** @type {typeof parser.append<import('#compiler').EachBlock>} */ (
168-
parser.append
169-
)({
167+
/** @type {ReturnType<typeof parser.append<import('#compiler').EachBlock>>} */
168+
const block = parser.append({
170169
type: 'EachBlock',
171170
start,
172171
end: -1,
@@ -189,9 +188,8 @@ function open(parser) {
189188
const expression = read_expression(parser);
190189
parser.allow_whitespace();
191190

192-
const block = /** @type {typeof parser.append<import('#compiler').AwaitBlock>} */ (
193-
parser.append
194-
)({
191+
/** @type {ReturnType<typeof parser.append<import('#compiler').AwaitBlock>>} */
192+
const block = parser.append({
195193
type: 'AwaitBlock',
196194
start,
197195
end: -1,
@@ -244,15 +242,14 @@ function open(parser) {
244242

245243
parser.eat('}', true);
246244

247-
const block = /** @type {typeof parser.append<import('#compiler').KeyBlock>} */ (parser.append)(
248-
{
249-
type: 'KeyBlock',
250-
start,
251-
end: -1,
252-
expression,
253-
fragment: create_fragment()
254-
}
255-
);
245+
/** @type {ReturnType<typeof parser.append<import('#compiler').KeyBlock>>} */
246+
const block = parser.append({
247+
type: 'KeyBlock',
248+
start,
249+
end: -1,
250+
expression,
251+
fragment: create_fragment()
252+
});
256253

257254
parser.stack.push(block);
258255
parser.fragments.push(block.fragment);
@@ -302,9 +299,8 @@ function open(parser) {
302299
parser.allow_whitespace();
303300
parser.eat('}', true);
304301

305-
const block = /** @type {typeof parser.append<import('#compiler').SnippetBlock>} */ (
306-
parser.append
307-
)({
302+
/** @type {ReturnType<typeof parser.append<import('#compiler').SnippetBlock>>} */
303+
const block = parser.append({
308304
type: 'SnippetBlock',
309305
start,
310306
end: -1,
@@ -353,9 +349,8 @@ function next(parser) {
353349
parser.allow_whitespace();
354350
parser.eat('}', true);
355351

356-
const child = /** @type {typeof parser.append<import('#compiler').IfBlock>} */ (
357-
parser.append
358-
)({
352+
/** @type {ReturnType<typeof parser.append<import('#compiler').IfBlock>>} */
353+
const child = parser.append({
359354
start: parser.index,
360355
end: -1,
361356
type: 'IfBlock',
@@ -498,14 +493,13 @@ function special(parser) {
498493
parser.allow_whitespace();
499494
parser.eat('}', true);
500495

501-
parser.append(
502-
/** @type {import('#compiler').HtmlTag} */ ({
503-
type: 'HtmlTag',
504-
start,
505-
end: parser.index,
506-
expression
507-
})
508-
);
496+
/** @type {ReturnType<typeof parser.append<import('#compiler').HtmlTag>>} */
497+
parser.append({
498+
type: 'HtmlTag',
499+
start,
500+
end: parser.index,
501+
expression
502+
});
509503

510504
return;
511505
}
@@ -537,14 +531,13 @@ function special(parser) {
537531
parser.eat('}', true);
538532
}
539533

540-
parser.append(
541-
/** @type {import('#compiler').DebugTag} */ ({
542-
type: 'DebugTag',
543-
start,
544-
end: parser.index,
545-
identifiers
546-
})
547-
);
534+
/** @type {ReturnType<typeof parser.append<import('#compiler').DebugTag>>} */
535+
parser.append({
536+
type: 'DebugTag',
537+
start,
538+
end: parser.index,
539+
identifiers
540+
});
548541

549542
return;
550543
}
@@ -563,20 +556,19 @@ function special(parser) {
563556

564557
parser.eat('}', true);
565558

566-
parser.append(
567-
/** @type {import('#compiler').ConstTag} */ ({
568-
type: 'ConstTag',
569-
start,
570-
end: parser.index,
571-
declaration: {
572-
type: 'VariableDeclaration',
573-
kind: 'const',
574-
declarations: [{ type: 'VariableDeclarator', id, init }],
575-
start: start + 1,
576-
end: parser.index - 1
577-
}
578-
})
579-
);
559+
/** @type {ReturnType<typeof parser.append<import('#compiler').ConstTag>>} */
560+
parser.append({
561+
type: 'ConstTag',
562+
start,
563+
end: parser.index,
564+
declaration: {
565+
type: 'VariableDeclaration',
566+
kind: 'const',
567+
declarations: [{ type: 'VariableDeclarator', id, init }],
568+
start: start + 1,
569+
end: parser.index - 1
570+
}
571+
});
580572
}
581573

582574
if (parser.eat('render')) {
@@ -592,14 +584,13 @@ function special(parser) {
592584
parser.allow_whitespace();
593585
parser.eat('}', true);
594586

595-
parser.append(
596-
/** @type {import('#compiler').RenderTag} */ ({
597-
type: 'RenderTag',
598-
start,
599-
end: parser.index,
600-
expression: expression.callee,
601-
arguments: expression.arguments
602-
})
603-
);
587+
/** @type {ReturnType<typeof parser.append<import('#compiler').RenderTag>>} */
588+
parser.append({
589+
type: 'RenderTag',
590+
start,
591+
end: parser.index,
592+
expression: expression.callee,
593+
arguments: expression.arguments
594+
});
604595
}
605596
}

packages/svelte/src/compiler/phases/1-parse/state/text.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ export default function text(parser) {
1010
data += parser.template[parser.index++];
1111
}
1212

13-
parser.append(
14-
/** @type {import('#compiler').Text} */ ({
15-
type: 'Text',
16-
start,
17-
end: parser.index,
18-
raw: data,
19-
data: decode_character_references(data, false)
20-
})
21-
);
13+
/** @type {ReturnType<typeof parser.append<import('#compiler').Text>>} */
14+
parser.append({
15+
type: 'Text',
16+
start,
17+
end: parser.index,
18+
raw: data,
19+
data: decode_character_references(data, false)
20+
});
2221
}

0 commit comments

Comments
 (0)