Skip to content
This repository was archived by the owner on Jan 14, 2019. It is now read-only.

Commit edf2727

Browse files
armano2JamesHenry
authored andcommitted
refactor: remove convertDecorators helper (#75)
1 parent 6690f0b commit edf2727

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

src/convert.ts

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -282,28 +282,6 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
282282
return classImplementsNode;
283283
}
284284

285-
/**
286-
* Converts a ts.NodeArray of ts.Decorators into an array of ESTreeNode decorators
287-
* @param {ts.NodeArray<ts.Decorator>} decorators A ts.NodeArray of ts.Decorators to be converted
288-
* @returns {ESTreeNode[]} an array of converted ESTreeNode decorators
289-
*/
290-
function convertDecorators(
291-
decorators: ts.NodeArray<ts.Decorator>
292-
): ESTreeNode[] {
293-
if (!decorators || !decorators.length) {
294-
return [];
295-
}
296-
return decorators.map(decorator => {
297-
const expression = convertChild(decorator.expression);
298-
return {
299-
type: AST_NODE_TYPES.Decorator,
300-
range: [decorator.getStart(ast), decorator.end],
301-
loc: nodeUtils.getLoc(decorator, ast),
302-
expression
303-
};
304-
});
305-
}
306-
307285
/**
308286
* Converts an array of ts.Node parameters into an array of ESTreeNode params
309287
* @param {ts.Node[]} parameters An array of ts.Node params to be converted
@@ -319,7 +297,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
319297
return convertedParam;
320298
}
321299
return Object.assign(convertedParam, {
322-
decorators: convertDecorators(param.decorators)
300+
decorators: param.decorators.map(convertChild)
323301
});
324302
});
325303
}
@@ -366,9 +344,8 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
366344
)
367345
: null;
368346
} else if (key === 'decorators') {
369-
const decorators = convertDecorators((node as any).decorators);
370-
if (decorators && decorators.length) {
371-
result.decorators = decorators;
347+
if (node.decorators && node.decorators.length) {
348+
result.decorators = node.decorators.map(convertChild);
372349
}
373350
} else {
374351
if (Array.isArray((node as any)[key])) {
@@ -966,7 +943,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
966943
}
967944

968945
if (node.decorators) {
969-
result.decorators = convertDecorators(node.decorators);
946+
result.decorators = node.decorators.map(convertChild);
970947
}
971948

972949
const accessibility = nodeUtils.getTSNodeAccessibility(node);
@@ -1071,7 +1048,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
10711048
});
10721049

10731050
if (node.decorators) {
1074-
result.decorators = convertDecorators(node.decorators);
1051+
result.decorators = node.decorators.map(convertChild);
10751052
}
10761053

10771054
const accessibility = nodeUtils.getTSNodeAccessibility(node);
@@ -1631,7 +1608,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
16311608
}
16321609

16331610
if (node.decorators) {
1634-
result.decorators = convertDecorators(node.decorators);
1611+
result.decorators = node.decorators.map(convertChild);
16351612
}
16361613

16371614
const filteredMembers = node.members.filter(
@@ -1979,6 +1956,14 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
19791956
break;
19801957
}
19811958

1959+
case SyntaxKind.Decorator: {
1960+
Object.assign(result, {
1961+
type: AST_NODE_TYPES.Decorator,
1962+
expression: convertChild(node.expression)
1963+
});
1964+
break;
1965+
}
1966+
19821967
// Literals
19831968

19841969
case SyntaxKind.StringLiteral:
@@ -2550,7 +2535,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
25502535
* so we handle them here too.
25512536
*/
25522537
if (node.decorators) {
2553-
result.decorators = convertDecorators(node.decorators);
2538+
result.decorators = node.decorators.map(convertChild);
25542539
}
25552540
if (nodeUtils.hasModifier(SyntaxKind.AbstractKeyword, node)) {
25562541
result.abstract = true;
@@ -2605,7 +2590,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
26052590
* so we handle them here too.
26062591
*/
26072592
if (node.decorators) {
2608-
result.decorators = convertDecorators(node.decorators);
2593+
result.decorators = node.decorators.map(convertChild);
26092594
}
26102595
break;
26112596
}

0 commit comments

Comments
 (0)