/
renderCallArguments.ts
41 lines (40 loc) · 1.16 KB
/
renderCallArguments.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import MagicString from 'magic-string';
import CallExpression from '../ast/nodes/CallExpression';
import NewExpression from '../ast/nodes/NewExpression';
import { findFirstOccurrenceOutsideComment, RenderOptions } from './renderHelpers';
export function renderCallArguments(
code: MagicString,
options: RenderOptions,
node: CallExpression | NewExpression
): void {
if (node.arguments.length > 0) {
if (node.arguments[node.arguments.length - 1].included) {
for (const arg of node.arguments) {
arg.render(code, options);
}
} else {
let lastIncludedIndex = node.arguments.length - 2;
while (lastIncludedIndex >= 0 && !node.arguments[lastIncludedIndex].included) {
lastIncludedIndex--;
}
if (lastIncludedIndex >= 0) {
for (let index = 0; index <= lastIncludedIndex; index++) {
node.arguments[index].render(code, options);
}
code.remove(
findFirstOccurrenceOutsideComment(
code.original,
',',
node.arguments[lastIncludedIndex].end
),
node.end - 1
);
} else {
code.remove(
findFirstOccurrenceOutsideComment(code.original, '(', node.callee.end) + 1,
node.end - 1
);
}
}
}
}