hermes-transform 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ESLINT_LICENCE +19 -0
- package/PRETTIER_LICENCE +7 -0
- package/dist/detachedNode.js +100 -42
- package/dist/detachedNode.js.flow +116 -41
- package/dist/generated/TransformCloneSignatures.js.flow +18 -0
- package/dist/generated/TransformModifySignatures.js.flow +1127 -0
- package/dist/generated/TransformReplaceSignatures.js.flow +15 -1
- package/dist/generated/node-types.js +852 -883
- package/dist/generated/node-types.js.flow +1187 -1217
- package/dist/generated/special-case-node-types/Comment.js +36 -0
- package/dist/generated/special-case-node-types/Comment.js.flow +36 -0
- package/dist/generated/special-case-node-types/DeclareExportDeclaration.js +55 -0
- package/dist/generated/special-case-node-types/DeclareExportDeclaration.js.flow +97 -0
- package/dist/generated/special-case-node-types/ExportNamedDeclaration.js +42 -0
- package/dist/generated/special-case-node-types/ExportNamedDeclaration.js.flow +75 -0
- package/dist/generated/special-case-node-types/Literal.js +97 -0
- package/dist/generated/special-case-node-types/Literal.js.flow +139 -0
- package/dist/generated/special-case-node-types/ObjectTypeProperty.js +73 -0
- package/dist/generated/special-case-node-types/ObjectTypeProperty.js.flow +107 -0
- package/dist/generated/special-case-node-types/Property.js +136 -0
- package/dist/generated/special-case-node-types/Property.js.flow +237 -0
- package/dist/generated/special-case-node-types/misc.js +119 -0
- package/dist/generated/special-case-node-types/misc.js.flow +205 -0
- package/dist/generated/special-case-node-types.js +42 -180
- package/dist/generated/special-case-node-types.js.flow +7 -258
- package/dist/index.js +19 -3
- package/dist/index.js.flow +6 -2
- package/dist/transform/TransformContext.js +34 -11
- package/dist/transform/TransformContext.js.flow +90 -33
- package/dist/transform/comments/comments.js +34 -5
- package/dist/transform/comments/comments.js.flow +39 -4
- package/dist/transform/comments/prettier/main/comments.js +1 -1
- package/dist/transform/comments/prettier/main/comments.js.flow +2 -1
- package/dist/transform/mutations/InsertStatement.js +4 -3
- package/dist/transform/mutations/InsertStatement.js.flow +4 -3
- package/dist/transform/mutations/RemoveComment.js +3 -3
- package/dist/transform/mutations/RemoveComment.js.flow +3 -5
- package/dist/transform/mutations/RemoveNode.js +2 -2
- package/dist/transform/mutations/RemoveNode.js.flow +2 -2
- package/dist/transform/mutations/RemoveStatement.js +2 -2
- package/dist/transform/mutations/RemoveStatement.js.flow +2 -2
- package/dist/transform/mutations/ReplaceNode.js +10 -7
- package/dist/transform/mutations/ReplaceNode.js.flow +7 -5
- package/dist/transform/mutations/ReplaceStatementWithMany.js +2 -2
- package/dist/transform/mutations/ReplaceStatementWithMany.js.flow +7 -4
- package/dist/transform/mutations/utils/getStatementParent.js +3 -2
- package/dist/transform/mutations/utils/getStatementParent.js.flow +5 -2
- package/dist/transform/parse.js +55 -0
- package/dist/transform/parse.js.flow +55 -0
- package/dist/transform/print.js +160 -0
- package/dist/transform/print.js.flow +176 -0
- package/dist/transform/transform.js +6 -67
- package/dist/transform/transform.js.flow +6 -69
- package/dist/transform/{getTransformedAST.js → transformAST.js} +7 -16
- package/dist/transform/{getTransformedAST.js.flow → transformAST.js.flow} +7 -14
- package/dist/traverse/NodeEventGenerator.js.flow +1 -1
- package/dist/traverse/traverse.js +36 -35
- package/dist/traverse/traverse.js.flow +46 -27
- package/package.json +10 -5
- package/dist/getVisitorKeys.js +0 -33
- package/dist/getVisitorKeys.js.flow +0 -31
- package/dist/transform/mutations/utils/arrayUtils.js +0 -43
- package/dist/transform/mutations/utils/arrayUtils.js.flow +0 -50
- package/dist/traverse/SimpleTraverser.js +0 -118
- package/dist/traverse/SimpleTraverser.js.flow +0 -112
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
ESNode,
|
|
13
|
+
ObjectTypeAccessorSignature as ObjectTypeAccessorSignatureType,
|
|
14
|
+
ObjectTypeMethodSignature as ObjectTypeMethodSignatureType,
|
|
15
|
+
ObjectTypePropertySignature as ObjectTypePropertySignatureType,
|
|
16
|
+
} from 'hermes-estree';
|
|
17
|
+
import type {DetachedNode, MaybeDetachedNode} from '../../detachedNode';
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
asDetachedNode,
|
|
21
|
+
detachedProps,
|
|
22
|
+
setParentPointersInDirectChildren,
|
|
23
|
+
} from '../../detachedNode';
|
|
24
|
+
|
|
25
|
+
export type ObjectTypeMethodSignatureProps = {
|
|
26
|
+
+key: MaybeDetachedNode<ObjectTypeMethodSignatureType['key']>,
|
|
27
|
+
+value: MaybeDetachedNode<ObjectTypeMethodSignatureType['value']>,
|
|
28
|
+
|
|
29
|
+
// optional because they only apply to the class decl case
|
|
30
|
+
+static?: ObjectTypeMethodSignatureType['static'],
|
|
31
|
+
+proto?: ObjectTypeMethodSignatureType['proto'],
|
|
32
|
+
};
|
|
33
|
+
export function ObjectTypeMethodSignature(props: {
|
|
34
|
+
...$ReadOnly<ObjectTypeMethodSignatureProps>,
|
|
35
|
+
+parent?: ESNode,
|
|
36
|
+
}): DetachedNode<ObjectTypeMethodSignatureType> {
|
|
37
|
+
const node = detachedProps<ObjectTypeMethodSignatureType>(props.parent, {
|
|
38
|
+
type: 'ObjectTypeProperty',
|
|
39
|
+
key: asDetachedNode(props.key),
|
|
40
|
+
kind: 'init',
|
|
41
|
+
method: true,
|
|
42
|
+
optional: false,
|
|
43
|
+
proto: props.proto ?? false,
|
|
44
|
+
static: props.static ?? false,
|
|
45
|
+
value: asDetachedNode(props.value),
|
|
46
|
+
variance: null,
|
|
47
|
+
});
|
|
48
|
+
setParentPointersInDirectChildren(node);
|
|
49
|
+
return node;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type ObjectTypePropertySignatureProps = {
|
|
53
|
+
+key: MaybeDetachedNode<ObjectTypePropertySignatureType['key']>,
|
|
54
|
+
+value: MaybeDetachedNode<ObjectTypePropertySignatureType['value']>,
|
|
55
|
+
+optional: ObjectTypePropertySignatureType['optional'],
|
|
56
|
+
+variance?: ?MaybeDetachedNode<ObjectTypePropertySignatureType['variance']>,
|
|
57
|
+
|
|
58
|
+
// optional because they only apply to the class decl case
|
|
59
|
+
+static?: ObjectTypeMethodSignatureType['static'],
|
|
60
|
+
+proto?: ObjectTypeMethodSignatureType['proto'],
|
|
61
|
+
};
|
|
62
|
+
export function ObjectTypePropertySignature(props: {
|
|
63
|
+
...$ReadOnly<ObjectTypePropertySignatureProps>,
|
|
64
|
+
+parent?: ESNode,
|
|
65
|
+
}): DetachedNode<ObjectTypePropertySignatureType> {
|
|
66
|
+
const node = detachedProps<ObjectTypePropertySignatureType>(props.parent, {
|
|
67
|
+
type: 'ObjectTypeProperty',
|
|
68
|
+
key: asDetachedNode(props.key),
|
|
69
|
+
kind: 'init',
|
|
70
|
+
method: false,
|
|
71
|
+
optional: props.optional,
|
|
72
|
+
proto: props.proto ?? false,
|
|
73
|
+
static: props.static ?? false,
|
|
74
|
+
value: asDetachedNode(props.value),
|
|
75
|
+
variance: asDetachedNode(props.variance),
|
|
76
|
+
});
|
|
77
|
+
setParentPointersInDirectChildren(node);
|
|
78
|
+
return node;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type ObjectTypeAccessorSignatureProps = {
|
|
82
|
+
+key: MaybeDetachedNode<ObjectTypeAccessorSignatureType['key']>,
|
|
83
|
+
+value: MaybeDetachedNode<ObjectTypeAccessorSignatureType['value']>,
|
|
84
|
+
+kind: ObjectTypeAccessorSignatureType['kind'],
|
|
85
|
+
|
|
86
|
+
// optional because they only apply to the class decl case
|
|
87
|
+
+static?: ObjectTypeMethodSignatureType['static'],
|
|
88
|
+
+proto?: ObjectTypeMethodSignatureType['proto'],
|
|
89
|
+
};
|
|
90
|
+
export function ObjectTypeAccessorSignature(props: {
|
|
91
|
+
...$ReadOnly<ObjectTypeAccessorSignatureProps>,
|
|
92
|
+
+parent?: ESNode,
|
|
93
|
+
}): DetachedNode<ObjectTypeAccessorSignatureType> {
|
|
94
|
+
const node = detachedProps<ObjectTypeAccessorSignatureType>(props.parent, {
|
|
95
|
+
type: 'ObjectTypeProperty',
|
|
96
|
+
key: asDetachedNode(props.key),
|
|
97
|
+
kind: props.kind,
|
|
98
|
+
method: false,
|
|
99
|
+
optional: false,
|
|
100
|
+
proto: props.proto ?? false,
|
|
101
|
+
static: props.static ?? false,
|
|
102
|
+
value: asDetachedNode(props.value),
|
|
103
|
+
variance: null,
|
|
104
|
+
});
|
|
105
|
+
setParentPointersInDirectChildren(node);
|
|
106
|
+
return node;
|
|
107
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DestructuringObjectProperty = DestructuringObjectProperty;
|
|
7
|
+
exports.DestructuringObjectPropertyWithComputedName = DestructuringObjectPropertyWithComputedName;
|
|
8
|
+
exports.DestructuringObjectPropertyWithNonShorthandStaticName = DestructuringObjectPropertyWithNonShorthandStaticName;
|
|
9
|
+
exports.DestructuringObjectPropertyWithShorthandStaticName = DestructuringObjectPropertyWithShorthandStaticName;
|
|
10
|
+
exports.ObjectProperty = ObjectProperty;
|
|
11
|
+
exports.ObjectPropertyWithComputedName = ObjectPropertyWithComputedName;
|
|
12
|
+
exports.ObjectPropertyWithNonShorthandStaticName = ObjectPropertyWithNonShorthandStaticName;
|
|
13
|
+
exports.ObjectPropertyWithShorthandStaticName = ObjectPropertyWithShorthandStaticName;
|
|
14
|
+
|
|
15
|
+
var _detachedNode = require("../../detachedNode");
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
19
|
+
*
|
|
20
|
+
* This source code is licensed under the MIT license found in the
|
|
21
|
+
* LICENSE file in the root directory of this source tree.
|
|
22
|
+
*
|
|
23
|
+
*
|
|
24
|
+
* @format
|
|
25
|
+
*/
|
|
26
|
+
function DestructuringObjectProperty(props) {
|
|
27
|
+
const node = (0, _detachedNode.detachedProps)(props.parent, {
|
|
28
|
+
type: 'Property',
|
|
29
|
+
kind: 'init',
|
|
30
|
+
method: false,
|
|
31
|
+
key: (0, _detachedNode.asDetachedNode)(props.key),
|
|
32
|
+
value: (0, _detachedNode.asDetachedNode)(props.value),
|
|
33
|
+
computed: props.computed,
|
|
34
|
+
shorthand: props.shorthand
|
|
35
|
+
});
|
|
36
|
+
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
37
|
+
return node;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function DestructuringObjectPropertyWithNonShorthandStaticName(props) {
|
|
41
|
+
const node = (0, _detachedNode.detachedProps)(props.parent, {
|
|
42
|
+
type: 'Property',
|
|
43
|
+
kind: 'init',
|
|
44
|
+
method: false,
|
|
45
|
+
key: (0, _detachedNode.asDetachedNode)(props.key),
|
|
46
|
+
value: (0, _detachedNode.asDetachedNode)(props.value),
|
|
47
|
+
computed: false,
|
|
48
|
+
shorthand: false
|
|
49
|
+
});
|
|
50
|
+
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
51
|
+
return node;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function DestructuringObjectPropertyWithShorthandStaticName(props) {
|
|
55
|
+
const node = (0, _detachedNode.detachedProps)(props.parent, {
|
|
56
|
+
type: 'Property',
|
|
57
|
+
kind: 'init',
|
|
58
|
+
method: false,
|
|
59
|
+
key: (0, _detachedNode.asDetachedNode)(props.key),
|
|
60
|
+
value: (0, _detachedNode.asDetachedNode)(props.value),
|
|
61
|
+
computed: false,
|
|
62
|
+
shorthand: true
|
|
63
|
+
});
|
|
64
|
+
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
65
|
+
return node;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function DestructuringObjectPropertyWithComputedName(props) {
|
|
69
|
+
const node = (0, _detachedNode.detachedProps)(props.parent, {
|
|
70
|
+
type: 'Property',
|
|
71
|
+
kind: 'init',
|
|
72
|
+
method: false,
|
|
73
|
+
key: (0, _detachedNode.asDetachedNode)(props.key),
|
|
74
|
+
value: (0, _detachedNode.asDetachedNode)(props.value),
|
|
75
|
+
computed: true,
|
|
76
|
+
shorthand: false
|
|
77
|
+
});
|
|
78
|
+
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
79
|
+
return node;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function ObjectProperty(props) {
|
|
83
|
+
const node = (0, _detachedNode.detachedProps)(props.parent, {
|
|
84
|
+
type: 'Property',
|
|
85
|
+
key: (0, _detachedNode.asDetachedNode)(props.key),
|
|
86
|
+
kind: props.kind,
|
|
87
|
+
value: (0, _detachedNode.asDetachedNode)(props.value),
|
|
88
|
+
computed: props.computed,
|
|
89
|
+
method: props.method,
|
|
90
|
+
shorthand: props.shorthand
|
|
91
|
+
});
|
|
92
|
+
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
93
|
+
return node;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function ObjectPropertyWithNonShorthandStaticName(props) {
|
|
97
|
+
const node = (0, _detachedNode.detachedProps)(props.parent, {
|
|
98
|
+
type: 'Property',
|
|
99
|
+
key: (0, _detachedNode.asDetachedNode)(props.key),
|
|
100
|
+
kind: props.kind,
|
|
101
|
+
value: (0, _detachedNode.asDetachedNode)(props.value),
|
|
102
|
+
computed: false,
|
|
103
|
+
method: props.method,
|
|
104
|
+
shorthand: false
|
|
105
|
+
});
|
|
106
|
+
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
107
|
+
return node;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function ObjectPropertyWithShorthandStaticName(props) {
|
|
111
|
+
const node = (0, _detachedNode.detachedProps)(props.parent, {
|
|
112
|
+
type: 'Property',
|
|
113
|
+
key: (0, _detachedNode.asDetachedNode)(props.key),
|
|
114
|
+
kind: 'init',
|
|
115
|
+
value: (0, _detachedNode.asDetachedNode)(props.value),
|
|
116
|
+
computed: false,
|
|
117
|
+
method: false,
|
|
118
|
+
shorthand: true
|
|
119
|
+
});
|
|
120
|
+
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
121
|
+
return node;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function ObjectPropertyWithComputedName(props) {
|
|
125
|
+
const node = (0, _detachedNode.detachedProps)(props.parent, {
|
|
126
|
+
type: 'Property',
|
|
127
|
+
key: (0, _detachedNode.asDetachedNode)(props.key),
|
|
128
|
+
kind: props.kind,
|
|
129
|
+
value: (0, _detachedNode.asDetachedNode)(props.value),
|
|
130
|
+
computed: true,
|
|
131
|
+
method: props.method,
|
|
132
|
+
shorthand: false
|
|
133
|
+
});
|
|
134
|
+
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
135
|
+
return node;
|
|
136
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
DestructuringObjectProperty as DestructuringObjectPropertyType,
|
|
13
|
+
DestructuringObjectPropertyWithComputedName as DestructuringObjectPropertyWithComputedNameType,
|
|
14
|
+
DestructuringObjectPropertyWithNonShorthandStaticName as DestructuringObjectPropertyWithNonShorthandStaticNameType,
|
|
15
|
+
DestructuringObjectPropertyWithShorthandStaticName as DestructuringObjectPropertyWithShorthandStaticNameType,
|
|
16
|
+
ESNode,
|
|
17
|
+
ObjectProperty as ObjectPropertyType,
|
|
18
|
+
ObjectPropertyWithComputedName as ObjectPropertyWithComputedNameType,
|
|
19
|
+
ObjectPropertyWithNonShorthandStaticName as ObjectPropertyWithNonShorthandStaticNameType,
|
|
20
|
+
ObjectPropertyWithShorthandStaticName as ObjectPropertyWithShorthandStaticNameType,
|
|
21
|
+
} from 'hermes-estree';
|
|
22
|
+
import type {DetachedNode, MaybeDetachedNode} from '../../detachedNode';
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
asDetachedNode,
|
|
26
|
+
detachedProps,
|
|
27
|
+
setParentPointersInDirectChildren,
|
|
28
|
+
} from '../../detachedNode';
|
|
29
|
+
|
|
30
|
+
export type DestructuringObjectPropertyProps = {
|
|
31
|
+
+key: MaybeDetachedNode<DestructuringObjectPropertyType['key']>,
|
|
32
|
+
+value: MaybeDetachedNode<DestructuringObjectPropertyType['value']>,
|
|
33
|
+
+computed: DestructuringObjectPropertyType['computed'],
|
|
34
|
+
+shorthand: DestructuringObjectPropertyType['shorthand'],
|
|
35
|
+
};
|
|
36
|
+
export function DestructuringObjectProperty(props: {
|
|
37
|
+
...$ReadOnly<DestructuringObjectPropertyProps>,
|
|
38
|
+
+parent?: ESNode,
|
|
39
|
+
}): DetachedNode<DestructuringObjectPropertyType> {
|
|
40
|
+
const node = detachedProps<DestructuringObjectPropertyType>(props.parent, {
|
|
41
|
+
type: 'Property',
|
|
42
|
+
kind: 'init',
|
|
43
|
+
method: false,
|
|
44
|
+
key: asDetachedNode(props.key),
|
|
45
|
+
value: asDetachedNode(props.value),
|
|
46
|
+
computed: props.computed,
|
|
47
|
+
shorthand: props.shorthand,
|
|
48
|
+
});
|
|
49
|
+
setParentPointersInDirectChildren(node);
|
|
50
|
+
return node;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type DestructuringObjectPropertyWithNonShorthandStaticNameProps = {
|
|
54
|
+
+key: MaybeDetachedNode<
|
|
55
|
+
DestructuringObjectPropertyWithNonShorthandStaticNameType['key'],
|
|
56
|
+
>,
|
|
57
|
+
+value: MaybeDetachedNode<
|
|
58
|
+
DestructuringObjectPropertyWithNonShorthandStaticNameType['value'],
|
|
59
|
+
>,
|
|
60
|
+
};
|
|
61
|
+
export function DestructuringObjectPropertyWithNonShorthandStaticName(props: {
|
|
62
|
+
...$ReadOnly<DestructuringObjectPropertyWithNonShorthandStaticNameProps>,
|
|
63
|
+
+parent?: ESNode,
|
|
64
|
+
}): DetachedNode<DestructuringObjectPropertyWithNonShorthandStaticNameType> {
|
|
65
|
+
const node =
|
|
66
|
+
detachedProps<DestructuringObjectPropertyWithNonShorthandStaticNameType>(
|
|
67
|
+
props.parent,
|
|
68
|
+
{
|
|
69
|
+
type: 'Property',
|
|
70
|
+
kind: 'init',
|
|
71
|
+
method: false,
|
|
72
|
+
key: asDetachedNode(props.key),
|
|
73
|
+
value: asDetachedNode(props.value),
|
|
74
|
+
computed: false,
|
|
75
|
+
shorthand: false,
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
setParentPointersInDirectChildren(node);
|
|
79
|
+
return node;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type DestructuringObjectPropertyWithShorthandStaticNameProps = {
|
|
83
|
+
+key: MaybeDetachedNode<
|
|
84
|
+
DestructuringObjectPropertyWithShorthandStaticNameType['key'],
|
|
85
|
+
>,
|
|
86
|
+
+value: MaybeDetachedNode<
|
|
87
|
+
DestructuringObjectPropertyWithShorthandStaticNameType['value'],
|
|
88
|
+
>,
|
|
89
|
+
};
|
|
90
|
+
export function DestructuringObjectPropertyWithShorthandStaticName(props: {
|
|
91
|
+
...$ReadOnly<DestructuringObjectPropertyWithShorthandStaticNameProps>,
|
|
92
|
+
+parent?: ESNode,
|
|
93
|
+
}): DetachedNode<DestructuringObjectPropertyWithShorthandStaticNameType> {
|
|
94
|
+
const node =
|
|
95
|
+
detachedProps<DestructuringObjectPropertyWithShorthandStaticNameType>(
|
|
96
|
+
props.parent,
|
|
97
|
+
{
|
|
98
|
+
type: 'Property',
|
|
99
|
+
kind: 'init',
|
|
100
|
+
method: false,
|
|
101
|
+
key: asDetachedNode(props.key),
|
|
102
|
+
value: asDetachedNode(props.value),
|
|
103
|
+
computed: false,
|
|
104
|
+
shorthand: true,
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
setParentPointersInDirectChildren(node);
|
|
108
|
+
return node;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type DestructuringObjectPropertyWithComputedNameProps = {
|
|
112
|
+
+key: MaybeDetachedNode<
|
|
113
|
+
DestructuringObjectPropertyWithComputedNameType['key'],
|
|
114
|
+
>,
|
|
115
|
+
+value: MaybeDetachedNode<
|
|
116
|
+
DestructuringObjectPropertyWithComputedNameType['value'],
|
|
117
|
+
>,
|
|
118
|
+
};
|
|
119
|
+
export function DestructuringObjectPropertyWithComputedName(props: {
|
|
120
|
+
...$ReadOnly<DestructuringObjectPropertyWithComputedNameProps>,
|
|
121
|
+
+parent?: ESNode,
|
|
122
|
+
}): DetachedNode<DestructuringObjectPropertyWithComputedNameType> {
|
|
123
|
+
const node = detachedProps<DestructuringObjectPropertyWithComputedNameType>(
|
|
124
|
+
props.parent,
|
|
125
|
+
{
|
|
126
|
+
type: 'Property',
|
|
127
|
+
kind: 'init',
|
|
128
|
+
method: false,
|
|
129
|
+
key: asDetachedNode(props.key),
|
|
130
|
+
value: asDetachedNode(props.value),
|
|
131
|
+
computed: true,
|
|
132
|
+
shorthand: false,
|
|
133
|
+
},
|
|
134
|
+
);
|
|
135
|
+
setParentPointersInDirectChildren(node);
|
|
136
|
+
return node;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export type ObjectPropertyProps = {
|
|
140
|
+
+key: MaybeDetachedNode<ObjectPropertyType['key']>,
|
|
141
|
+
+value: MaybeDetachedNode<ObjectPropertyType['value']>,
|
|
142
|
+
+kind: ObjectPropertyType['kind'],
|
|
143
|
+
+computed: ObjectPropertyType['computed'],
|
|
144
|
+
+method: ObjectPropertyType['method'],
|
|
145
|
+
+shorthand: ObjectPropertyType['shorthand'],
|
|
146
|
+
};
|
|
147
|
+
export function ObjectProperty(props: {
|
|
148
|
+
...$ReadOnly<ObjectPropertyProps>,
|
|
149
|
+
+parent?: ESNode,
|
|
150
|
+
}): DetachedNode<ObjectPropertyType> {
|
|
151
|
+
const node = detachedProps<ObjectPropertyType>(props.parent, {
|
|
152
|
+
type: 'Property',
|
|
153
|
+
key: asDetachedNode(props.key),
|
|
154
|
+
kind: props.kind,
|
|
155
|
+
value: asDetachedNode(props.value),
|
|
156
|
+
computed: props.computed,
|
|
157
|
+
method: props.method,
|
|
158
|
+
shorthand: props.shorthand,
|
|
159
|
+
});
|
|
160
|
+
setParentPointersInDirectChildren(node);
|
|
161
|
+
return node;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export type ObjectPropertyWithNonShorthandStaticNameProps = {
|
|
165
|
+
+key: MaybeDetachedNode<ObjectPropertyWithNonShorthandStaticNameType['key']>,
|
|
166
|
+
+value: MaybeDetachedNode<
|
|
167
|
+
ObjectPropertyWithNonShorthandStaticNameType['value'],
|
|
168
|
+
>,
|
|
169
|
+
+kind: ObjectPropertyWithNonShorthandStaticNameType['kind'],
|
|
170
|
+
+method: ObjectPropertyWithNonShorthandStaticNameType['method'],
|
|
171
|
+
};
|
|
172
|
+
export function ObjectPropertyWithNonShorthandStaticName(props: {
|
|
173
|
+
...$ReadOnly<ObjectPropertyWithNonShorthandStaticNameProps>,
|
|
174
|
+
+parent?: ESNode,
|
|
175
|
+
}): DetachedNode<ObjectPropertyWithNonShorthandStaticNameType> {
|
|
176
|
+
const node = detachedProps<ObjectPropertyWithNonShorthandStaticNameType>(
|
|
177
|
+
props.parent,
|
|
178
|
+
{
|
|
179
|
+
type: 'Property',
|
|
180
|
+
key: asDetachedNode(props.key),
|
|
181
|
+
kind: props.kind,
|
|
182
|
+
value: asDetachedNode(props.value),
|
|
183
|
+
computed: false,
|
|
184
|
+
method: props.method,
|
|
185
|
+
shorthand: false,
|
|
186
|
+
},
|
|
187
|
+
);
|
|
188
|
+
setParentPointersInDirectChildren(node);
|
|
189
|
+
return node;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export type ObjectPropertyWithShorthandStaticNameProps = {
|
|
193
|
+
+key: MaybeDetachedNode<ObjectPropertyWithShorthandStaticNameType['key']>,
|
|
194
|
+
+value: MaybeDetachedNode<ObjectPropertyWithShorthandStaticNameType['value']>,
|
|
195
|
+
};
|
|
196
|
+
export function ObjectPropertyWithShorthandStaticName(props: {
|
|
197
|
+
...$ReadOnly<ObjectPropertyWithShorthandStaticNameProps>,
|
|
198
|
+
+parent?: ESNode,
|
|
199
|
+
}): DetachedNode<ObjectPropertyWithShorthandStaticNameType> {
|
|
200
|
+
const node = detachedProps<ObjectPropertyWithShorthandStaticNameType>(
|
|
201
|
+
props.parent,
|
|
202
|
+
{
|
|
203
|
+
type: 'Property',
|
|
204
|
+
key: asDetachedNode(props.key),
|
|
205
|
+
kind: 'init',
|
|
206
|
+
value: asDetachedNode(props.value),
|
|
207
|
+
computed: false,
|
|
208
|
+
method: false,
|
|
209
|
+
shorthand: true,
|
|
210
|
+
},
|
|
211
|
+
);
|
|
212
|
+
setParentPointersInDirectChildren(node);
|
|
213
|
+
return node;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export type ObjectPropertyWithComputedNameProps = {
|
|
217
|
+
+key: MaybeDetachedNode<ObjectPropertyWithComputedNameType['key']>,
|
|
218
|
+
+value: MaybeDetachedNode<ObjectPropertyWithComputedNameType['value']>,
|
|
219
|
+
+kind: ObjectPropertyWithComputedNameType['kind'],
|
|
220
|
+
+method: ObjectPropertyWithComputedNameType['method'],
|
|
221
|
+
};
|
|
222
|
+
export function ObjectPropertyWithComputedName(props: {
|
|
223
|
+
...$ReadOnly<ObjectPropertyWithComputedNameProps>,
|
|
224
|
+
+parent?: ESNode,
|
|
225
|
+
}): DetachedNode<ObjectPropertyWithComputedNameType> {
|
|
226
|
+
const node = detachedProps<ObjectPropertyWithComputedNameType>(props.parent, {
|
|
227
|
+
type: 'Property',
|
|
228
|
+
key: asDetachedNode(props.key),
|
|
229
|
+
kind: props.kind,
|
|
230
|
+
value: asDetachedNode(props.value),
|
|
231
|
+
computed: true,
|
|
232
|
+
method: props.method,
|
|
233
|
+
shorthand: false,
|
|
234
|
+
});
|
|
235
|
+
setParentPointersInDirectChildren(node);
|
|
236
|
+
return node;
|
|
237
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ArrowFunctionExpression = ArrowFunctionExpression;
|
|
7
|
+
exports.ClassDeclaration = ClassDeclaration;
|
|
8
|
+
exports.DeclareFunction = DeclareFunction;
|
|
9
|
+
exports.Identifier = Identifier;
|
|
10
|
+
exports.Program = Program;
|
|
11
|
+
exports.TemplateElement = TemplateElement;
|
|
12
|
+
|
|
13
|
+
var _detachedNode = require("../../detachedNode");
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
17
|
+
*
|
|
18
|
+
* This source code is licensed under the MIT license found in the
|
|
19
|
+
* LICENSE file in the root directory of this source tree.
|
|
20
|
+
*
|
|
21
|
+
*
|
|
22
|
+
* @format
|
|
23
|
+
*/
|
|
24
|
+
function ArrowFunctionExpression(props) {
|
|
25
|
+
const node = (0, _detachedNode.detachedProps)(props.parent, {
|
|
26
|
+
type: 'ArrowFunctionExpression',
|
|
27
|
+
id: null,
|
|
28
|
+
// $FlowExpectedError[incompatible-use]
|
|
29
|
+
expression: props.body.type !== 'BlockStatement',
|
|
30
|
+
params: props.params.map(n => (0, _detachedNode.asDetachedNode)(n)),
|
|
31
|
+
body: (0, _detachedNode.asDetachedNode)(props.body),
|
|
32
|
+
typeParameters: (0, _detachedNode.asDetachedNode)(props.typeParameters),
|
|
33
|
+
returnType: (0, _detachedNode.asDetachedNode)(props.returnType),
|
|
34
|
+
predicate: (0, _detachedNode.asDetachedNode)(props.predicate),
|
|
35
|
+
async: props.async
|
|
36
|
+
});
|
|
37
|
+
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
38
|
+
return node;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function ClassDeclaration(props) {
|
|
42
|
+
var _props$decorators, _props$implements;
|
|
43
|
+
|
|
44
|
+
const node = (0, _detachedNode.detachedProps)(props.parent, {
|
|
45
|
+
type: 'ClassDeclaration',
|
|
46
|
+
id: (0, _detachedNode.asDetachedNode)(props.id),
|
|
47
|
+
typeParameters: (0, _detachedNode.asDetachedNode)(props.typeParameters),
|
|
48
|
+
superClass: (0, _detachedNode.asDetachedNode)(props.superClass),
|
|
49
|
+
superTypeParameters: (0, _detachedNode.asDetachedNode)(props.superTypeParameters),
|
|
50
|
+
decorators: ((_props$decorators = props.decorators) != null ? _props$decorators : []).map(n => (0, _detachedNode.asDetachedNode)(n)),
|
|
51
|
+
implements: ((_props$implements = props.implements) != null ? _props$implements : []).map(n => (0, _detachedNode.asDetachedNode)(n)),
|
|
52
|
+
body: (0, _detachedNode.asDetachedNode)(props.body)
|
|
53
|
+
});
|
|
54
|
+
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
55
|
+
return node;
|
|
56
|
+
} // raw/cooked are on a subobject in the estree spec, but are flat on the hermes types
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
function TemplateElement(props) {
|
|
60
|
+
return (0, _detachedNode.detachedProps)(props.parent, {
|
|
61
|
+
type: 'TemplateElement',
|
|
62
|
+
tail: props.tail,
|
|
63
|
+
value: {
|
|
64
|
+
cooked: props.cooked,
|
|
65
|
+
raw: props.raw
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
} // Identifier has a bunch of stuff that usually you don't want to provide - so we have
|
|
69
|
+
// this manual def to allow us to default some values
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
function Identifier(props) {
|
|
73
|
+
var _props$optional;
|
|
74
|
+
|
|
75
|
+
const node = (0, _detachedNode.detachedProps)(props.parent, {
|
|
76
|
+
type: 'Identifier',
|
|
77
|
+
name: props.name,
|
|
78
|
+
optional: (_props$optional = props.optional) != null ? _props$optional : false,
|
|
79
|
+
typeAnnotation: (0, _detachedNode.asDetachedNode)(props.typeAnnotation)
|
|
80
|
+
});
|
|
81
|
+
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
82
|
+
return node;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function Program(props) {
|
|
86
|
+
return (0, _detachedNode.detachedProps)(null, {
|
|
87
|
+
type: 'Program',
|
|
88
|
+
sourceType: props.sourceType,
|
|
89
|
+
body: props.body.map(n => (0, _detachedNode.asDetachedNode)(n)),
|
|
90
|
+
tokens: props.tokens,
|
|
91
|
+
comments: props.comments,
|
|
92
|
+
interpreter: props.interpreter != null ? // $FlowFixMe[incompatible-call]
|
|
93
|
+
(0, _detachedNode.asDetachedNode)({
|
|
94
|
+
type: 'InterpreterDirective',
|
|
95
|
+
value: props.interpreter
|
|
96
|
+
}) : null,
|
|
97
|
+
docblock: props.docblock
|
|
98
|
+
});
|
|
99
|
+
} // the type annotation is stored on the Identifier's typeAnnotation
|
|
100
|
+
// which is super awkward to work with and type - so we flatten the input
|
|
101
|
+
// and put it in the right spot after
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
function DeclareFunction(props) {
|
|
105
|
+
const node = (0, _detachedNode.detachedProps)(props.parent, {
|
|
106
|
+
type: 'DeclareFunction',
|
|
107
|
+
id: (0, _detachedNode.detachedProps)(null, {
|
|
108
|
+
type: 'Identifier',
|
|
109
|
+
name: props.name,
|
|
110
|
+
typeAnnotation: (0, _detachedNode.detachedProps)(null, {
|
|
111
|
+
type: 'TypeAnnotation',
|
|
112
|
+
typeAnnotation: (0, _detachedNode.asDetachedNode)(props.functionType)
|
|
113
|
+
})
|
|
114
|
+
}),
|
|
115
|
+
predicate: (0, _detachedNode.asDetachedNode)(props.predicate)
|
|
116
|
+
});
|
|
117
|
+
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
118
|
+
return node;
|
|
119
|
+
}
|