8000 refactor(typescript-estree): simplify applyModifiersToResult (#3084) · mikeauclair/typescript-eslint@0469102 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0469102

Browse files
authored
refactor(typescript-estree): simplify applyModifiersToResult (typescript-eslint#3084)
1 parent 763a252 commit 0469102

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

packages/typescript-estree/src/convert.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -580,13 +580,13 @@ export class Converter {
580580
if (!modifiers || !modifiers.length) {
581581
return;
582582
}
583+
const remainingModifiers: TSESTree.Modifier[] = [];
583584
/**
584585
* Some modifiers are explicitly handled by applying them as
585586
* boolean values on the result node. As well as adding them
586587
* to the result, we remove them from the array, so that they
587588
* are not handled twice.
588589
*/
589-
const handledModifierIndices: { [key: number]: boolean } = {};
590590
for (let i = 0; i < modifiers.length; i++) {
591591
const modifier = modifiers[i];
592592
switch (modifier.kind) {
@@ -596,31 +596,26 @@ export class Converter {
596596
*/
597597
case SyntaxKind.ExportKeyword:
598598
case SyntaxKind.DefaultKeyword:
599-
handledModifierIndices[i] = true;
600599
break;
601600
case SyntaxKind.ConstKeyword:
602601
(result as any).const = true;
603-
handledModifierIndices[i] = true;
604602
break;
605603
case SyntaxKind.DeclareKeyword:
606604
result.declare = true;
607-
handledModifierIndices[i] = true;
608605
break;
609606
default:
607+
remainingModifiers.push(this.convertChild(modifier));
608+
break;
610609
}
611610
}
612611
/**
613612
* If there are still valid modifiers available which have
614613
* not been explicitly handled above, we just convert and
615614
* add the modifiers array to the result node.
616615
*/
617-
const remainingModifiers = modifiers.filter(
618-
(_, i) => !handledModifierIndices[i],
619-
);
620-
if (!remainingModifiers || !remainingModifiers.length) {
621-
return;
616+
if (remainingModifiers.length) {
617+
result.modifiers = remainingModifiers;
622618
}
623-
result.modifiers = remainingModifiers.map(el => this.convertChild(el));
624619
}
625620

626621
/**

0 commit comments

Comments
 (0)
0