forked from prettier/angular-estree-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform-call-expression.ts
More file actions
45 lines (38 loc) · 1.27 KB
/
transform-call-expression.ts
File metadata and controls
45 lines (38 loc) · 1.27 KB
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
42
43
44
45
import { type Call, type SafeCall } from '@angular/compiler';
import type * as babel from '@babel/types';
import { type Transformer } from './transform.ts';
import { isOptionalObjectOrCallee } from './utilities.ts';
const callOptions = { optional: false } as const;
const safeCallOptions = { optional: true } as const;
type VisitorCall = {
node: Call;
options: typeof callOptions;
};
type VisitorSafeCall = {
node: SafeCall;
options: typeof safeCallOptions;
};
const transformCall =
<Visitor extends VisitorCall | VisitorSafeCall>({
optional,
}: Visitor['options']) =>
(
node: Visitor['node'],
transformer: Transformer,
): babel.CallExpression | babel.OptionalCallExpression => {
const arguments_ = transformer.transformChildren<babel.Expression>(
node.args,
);
const callee = transformer.transformChild<babel.Expression>(node.receiver);
if (optional || isOptionalObjectOrCallee(callee)) {
return {
type: 'OptionalCallExpression',
callee,
arguments: arguments_,
optional,
};
}
return { type: 'CallExpression', callee, arguments: arguments_ };
};
export const visitCall = transformCall<VisitorCall>(callOptions);
export const visitSafeCall = transformCall<VisitorSafeCall>(safeCallOptions);