Skip to content

Commit 505eef3

Browse files
committed
chore: refactor
1 parent 1d104cc commit 505eef3

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,13 @@ function convertGenericsAttribute(script: SvelteScriptElement, ctx: Context) {
262262
const { ast } = result;
263263
const statement = ast.body[0] as ESTree.ExpressionStatement;
264264
const rawExpression = statement.expression as ESTree.UnaryExpression;
265-
const classDecl = rawExpression.argument as ESTree.FunctionExpression;
266-
const typeParameters = (classDecl as TSESTree.FunctionExpression)
265+
const fnDecl = rawExpression.argument as ESTree.FunctionExpression;
266+
const typeParameters = (fnDecl as TSESTree.FunctionExpression)
267267
.typeParameters!;
268268
const params = typeParameters.params;
269269

270270
// Replace tokens
271271
for (const tokensKey of ["tokens", "comments"] as const) {
272-
const newTokens: any[] = [];
273272
for (const token of result.ast[tokensKey]!) {
274273
if (
275274
params.every(
@@ -278,13 +277,14 @@ function convertGenericsAttribute(script: SvelteScriptElement, ctx: Context) {
278277
param.range[1] <= token.range[0],
279278
)
280279
) {
281-
newTokens.push(token);
280+
ctx[tokensKey].push(token as any);
282281
}
283282
}
284-
ctx[tokensKey].push(...newTokens);
285283
}
286284

287285
for (const param of params) {
286+
(param as any).parent = generics;
287+
generics.params.push(param);
288288
ctx.scriptLet.addGenericTypeAliasDeclaration(
289289
param,
290290
(id, typeNode) => {
@@ -297,7 +297,5 @@ function convertGenericsAttribute(script: SvelteScriptElement, ctx: Context) {
297297
param.default = typeNode;
298298
},
299299
);
300-
(param as any).parent = generics;
301-
generics.params.push(param);
302300
}
303301
}

0 commit comments

Comments
 (0)