forked from prettier/angular-estree-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform-unary-expression.ts
More file actions
56 lines (52 loc) · 1.38 KB
/
transform-unary-expression.ts
File metadata and controls
56 lines (52 loc) · 1.38 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
46
47
48
49
50
51
52
53
54
55
56
import {
type PrefixNot,
type TypeofExpression,
type Unary,
type VoidExpression,
} from '@angular/compiler';
import type * as babel from '@babel/types';
import { type NodeTransformer } from '../node-transformer.ts';
type VisitorPrefixNot = {
node: PrefixNot;
operator: '!';
};
type VisitorTypeofExpression = {
node: TypeofExpression;
operator: 'typeof';
};
type VisitorVoidExpression = {
node: VoidExpression;
operator: 'void';
};
const transformUnaryExpression =
<
Visitor extends
| VisitorPrefixNot
| VisitorTypeofExpression
| VisitorVoidExpression,
>(
operator: Visitor['operator'],
) =>
(
node: Visitor['node'],
transformer: NodeTransformer,
): babel.UnaryExpression => ({
type: 'UnaryExpression',
prefix: true,
operator,
argument: transformer.transformChild<babel.Expression>(node.expression),
});
export const visitPrefixNot = transformUnaryExpression<VisitorPrefixNot>('!');
export const visitTypeofExpression =
transformUnaryExpression<VisitorTypeofExpression>('typeof');
export const visitVoidExpression =
transformUnaryExpression<VisitorVoidExpression>('void');
export const visitUnary = (
node: Unary,
transformer: NodeTransformer,
): babel.UnaryExpression => ({
type: 'UnaryExpression',
prefix: true,
argument: transformer.transformChild<babel.Expression>(node.expr),
operator: node.operator,
});