hermes-transform 0.9.0 → 0.10.1

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.
Files changed (64) hide show
  1. package/dist/detachedNode.js +9 -27
  2. package/dist/detachedNode.js.flow +21 -34
  3. package/dist/generated/TransformCloneSignatures.js.flow +331 -316
  4. package/dist/generated/TransformModifySignatures.js.flow +171 -157
  5. package/dist/generated/TransformReplaceSignatures.js.flow +16 -2
  6. package/dist/generated/node-types.js +254 -60
  7. package/dist/generated/node-types.js.flow +258 -103
  8. package/dist/generated/special-case-node-types/Comment.js +36 -0
  9. package/dist/generated/special-case-node-types/Comment.js.flow +36 -0
  10. package/dist/generated/special-case-node-types/DeclareExportDeclaration.js +55 -0
  11. package/dist/generated/special-case-node-types/DeclareExportDeclaration.js.flow +97 -0
  12. package/dist/generated/special-case-node-types/ExportNamedDeclaration.js +42 -0
  13. package/dist/generated/special-case-node-types/ExportNamedDeclaration.js.flow +75 -0
  14. package/dist/generated/special-case-node-types/Literal.js +97 -0
  15. package/dist/generated/special-case-node-types/Literal.js.flow +139 -0
  16. package/dist/generated/special-case-node-types/ObjectTypeProperty.js +73 -0
  17. package/dist/generated/special-case-node-types/ObjectTypeProperty.js.flow +107 -0
  18. package/dist/generated/special-case-node-types/Property.js +136 -0
  19. package/dist/generated/special-case-node-types/Property.js.flow +237 -0
  20. package/dist/generated/special-case-node-types/misc.js +119 -0
  21. package/dist/generated/special-case-node-types/misc.js.flow +205 -0
  22. package/dist/generated/special-case-node-types.js +42 -174
  23. package/dist/generated/special-case-node-types.js.flow +7 -274
  24. package/dist/index.js +19 -3
  25. package/dist/index.js.flow +6 -2
  26. package/dist/transform/TransformContext.js +1 -1
  27. package/dist/transform/TransformContext.js.flow +2 -2
  28. package/dist/transform/comments/comments.js +11 -0
  29. package/dist/transform/comments/comments.js.flow +16 -1
  30. package/dist/transform/comments/prettier/main/comments.js +1 -1
  31. package/dist/transform/comments/prettier/main/comments.js.flow +2 -1
  32. package/dist/transform/mutations/InsertStatement.js +3 -3
  33. package/dist/transform/mutations/InsertStatement.js.flow +3 -3
  34. package/dist/transform/mutations/RemoveComment.js +3 -3
  35. package/dist/transform/mutations/RemoveComment.js.flow +3 -5
  36. package/dist/transform/mutations/RemoveNode.js +2 -2
  37. package/dist/transform/mutations/RemoveNode.js.flow +2 -2
  38. package/dist/transform/mutations/RemoveStatement.js +2 -2
  39. package/dist/transform/mutations/RemoveStatement.js.flow +2 -2
  40. package/dist/transform/mutations/ReplaceNode.js +4 -6
  41. package/dist/transform/mutations/ReplaceNode.js.flow +2 -3
  42. package/dist/transform/mutations/ReplaceStatementWithMany.js +2 -2
  43. package/dist/transform/mutations/ReplaceStatementWithMany.js.flow +2 -2
  44. package/dist/transform/mutations/utils/getStatementParent.js +3 -2
  45. package/dist/transform/mutations/utils/getStatementParent.js.flow +5 -2
  46. package/dist/transform/parse.js +55 -0
  47. package/dist/transform/parse.js.flow +55 -0
  48. package/dist/transform/print.js +160 -0
  49. package/dist/transform/print.js.flow +176 -0
  50. package/dist/transform/transform.js +6 -67
  51. package/dist/transform/transform.js.flow +6 -69
  52. package/dist/transform/{getTransformedAST.js → transformAST.js} +7 -31
  53. package/dist/transform/{getTransformedAST.js.flow → transformAST.js.flow} +8 -33
  54. package/dist/traverse/NodeEventGenerator.js +3 -3
  55. package/dist/traverse/NodeEventGenerator.js.flow +3 -3
  56. package/dist/traverse/traverse.js +36 -35
  57. package/dist/traverse/traverse.js.flow +45 -26
  58. package/package.json +5 -4
  59. package/dist/getVisitorKeys.js +0 -33
  60. package/dist/getVisitorKeys.js.flow +0 -31
  61. package/dist/transform/mutations/utils/arrayUtils.js +0 -43
  62. package/dist/transform/mutations/utils/arrayUtils.js.flow +0 -50
  63. package/dist/traverse/SimpleTraverser.js +0 -118
  64. package/dist/traverse/SimpleTraverser.js.flow +0 -112
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BlockComment = BlockComment;
7
+ exports.LineComment = LineComment;
8
+
9
+ var _detachedNode = require("../../detachedNode");
10
+
11
+ /**
12
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
13
+ *
14
+ * This source code is licensed under the MIT license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ *
17
+ *
18
+ * @format
19
+ */
20
+ function LineComment(props) {
21
+ // $FlowExpectedError[prop-missing]
22
+ // $FlowExpectedError[incompatible-return]
23
+ return (0, _detachedNode.detachedProps)(undefined, {
24
+ type: 'Line',
25
+ value: props.value
26
+ });
27
+ }
28
+
29
+ function BlockComment(props) {
30
+ // $FlowExpectedError[prop-missing]
31
+ // $FlowExpectedError[incompatible-return]
32
+ return (0, _detachedNode.detachedProps)(undefined, {
33
+ type: 'Block',
34
+ value: props.value
35
+ });
36
+ }
@@ -0,0 +1,36 @@
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
+ BlockComment as BlockCommentType,
13
+ LineComment as LineCommentType,
14
+ } from 'hermes-estree';
15
+
16
+ import {detachedProps} from '../../detachedNode';
17
+
18
+ export type LineCommentProps = {+value: string};
19
+ export function LineComment(props: LineCommentProps): LineCommentType {
20
+ // $FlowExpectedError[prop-missing]
21
+ // $FlowExpectedError[incompatible-return]
22
+ return detachedProps<LineCommentType>(undefined, {
23
+ type: 'Line',
24
+ value: props.value,
25
+ });
26
+ }
27
+
28
+ export type BlockCommentProps = {+value: string};
29
+ export function BlockComment(props: BlockCommentProps): BlockCommentType {
30
+ // $FlowExpectedError[prop-missing]
31
+ // $FlowExpectedError[incompatible-return]
32
+ return detachedProps<BlockCommentType>(undefined, {
33
+ type: 'Block',
34
+ value: props.value,
35
+ });
36
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DeclareExportDeclarationNamedWithDeclaration = DeclareExportDeclarationNamedWithDeclaration;
7
+ exports.DeclareExportDeclarationNamedWithSpecifiers = DeclareExportDeclarationNamedWithSpecifiers;
8
+ exports.DeclareExportDefaultDeclaration = DeclareExportDefaultDeclaration;
9
+
10
+ var _detachedNode = require("../../detachedNode");
11
+
12
+ /**
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ *
18
+ *
19
+ * @format
20
+ */
21
+ function DeclareExportDefaultDeclaration(props) {
22
+ const node = (0, _detachedNode.detachedProps)(props.parent, {
23
+ type: 'DeclareExportDeclaration',
24
+ declaration: (0, _detachedNode.asDetachedNode)(props.declaration),
25
+ specifiers: [],
26
+ source: null,
27
+ default: true
28
+ });
29
+ (0, _detachedNode.setParentPointersInDirectChildren)(node);
30
+ return node;
31
+ }
32
+
33
+ function DeclareExportDeclarationNamedWithDeclaration(props) {
34
+ const node = (0, _detachedNode.detachedProps)(props.parent, {
35
+ type: 'DeclareExportDeclaration',
36
+ declaration: (0, _detachedNode.asDetachedNode)(props.declaration),
37
+ specifiers: [],
38
+ source: null,
39
+ default: false
40
+ });
41
+ (0, _detachedNode.setParentPointersInDirectChildren)(node);
42
+ return node;
43
+ }
44
+
45
+ function DeclareExportDeclarationNamedWithSpecifiers(props) {
46
+ const node = (0, _detachedNode.detachedProps)(props.parent, {
47
+ type: 'DeclareExportDeclaration',
48
+ declaration: null,
49
+ specifiers: props.specifiers.map(n => (0, _detachedNode.asDetachedNode)(n)),
50
+ source: (0, _detachedNode.asDetachedNode)(props.source),
51
+ default: false
52
+ });
53
+ (0, _detachedNode.setParentPointersInDirectChildren)(node);
54
+ return node;
55
+ }
@@ -0,0 +1,97 @@
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
+ DeclareExportDefaultDeclaration as DeclareExportDefaultDeclarationType,
13
+ ESNode,
14
+ DeclareExportDeclarationNamedWithDeclaration as DeclareExportDeclarationNamedWithDeclarationType,
15
+ DeclareExportDeclarationNamedWithSpecifiers as DeclareExportDeclarationNamedWithSpecifiersType,
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 DeclareExportDefaultDeclarationProps = {
26
+ +declaration?: ?MaybeDetachedNode<
27
+ DeclareExportDefaultDeclarationType['declaration'],
28
+ >,
29
+ };
30
+ export function DeclareExportDefaultDeclaration(props: {
31
+ ...$ReadOnly<DeclareExportDefaultDeclarationProps>,
32
+ +parent?: ESNode,
33
+ }): DetachedNode<DeclareExportDefaultDeclarationType> {
34
+ const node = detachedProps<DeclareExportDefaultDeclarationType>(
35
+ props.parent,
36
+ {
37
+ type: 'DeclareExportDeclaration',
38
+ declaration: asDetachedNode(props.declaration),
39
+ specifiers: [],
40
+ source: null,
41
+ default: true,
42
+ },
43
+ );
44
+ setParentPointersInDirectChildren(node);
45
+ return node;
46
+ }
47
+
48
+ export type DeclareExportDeclarationNamedWithDeclarationProps = {
49
+ +declaration?: ?MaybeDetachedNode<
50
+ DeclareExportDeclarationNamedWithDeclarationType['declaration'],
51
+ >,
52
+ };
53
+ export function DeclareExportDeclarationNamedWithDeclaration(props: {
54
+ ...$ReadOnly<DeclareExportDeclarationNamedWithDeclarationProps>,
55
+ +parent?: ESNode,
56
+ }): DetachedNode<DeclareExportDeclarationNamedWithDeclarationType> {
57
+ const node = detachedProps<DeclareExportDeclarationNamedWithDeclarationType>(
58
+ props.parent,
59
+ {
60
+ type: 'DeclareExportDeclaration',
61
+ declaration: asDetachedNode(props.declaration),
62
+ specifiers: [],
63
+ source: null,
64
+ default: false,
65
+ },
66
+ );
67
+ setParentPointersInDirectChildren(node);
68
+ return node;
69
+ }
70
+
71
+ export type DeclareExportDeclarationNamedWithSpecifiersProps = {
72
+ +specifiers: $ReadOnlyArray<
73
+ MaybeDetachedNode<
74
+ DeclareExportDeclarationNamedWithSpecifiersType['specifiers'][number],
75
+ >,
76
+ >,
77
+ +source?: ?MaybeDetachedNode<
78
+ DeclareExportDeclarationNamedWithSpecifiersType['source'],
79
+ >,
80
+ };
81
+ export function DeclareExportDeclarationNamedWithSpecifiers(props: {
82
+ ...$ReadOnly<DeclareExportDeclarationNamedWithSpecifiersProps>,
83
+ +parent?: ESNode,
84
+ }): DetachedNode<DeclareExportDeclarationNamedWithSpecifiersType> {
85
+ const node = detachedProps<DeclareExportDeclarationNamedWithSpecifiersType>(
86
+ props.parent,
87
+ {
88
+ type: 'DeclareExportDeclaration',
89
+ declaration: null,
90
+ specifiers: props.specifiers.map(n => asDetachedNode(n)),
91
+ source: asDetachedNode(props.source),
92
+ default: false,
93
+ },
94
+ );
95
+ setParentPointersInDirectChildren(node);
96
+ return node;
97
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ExportNamedDeclarationWithDeclaration = ExportNamedDeclarationWithDeclaration;
7
+ exports.ExportNamedDeclarationWithSpecifiers = ExportNamedDeclarationWithSpecifiers;
8
+
9
+ var _detachedNode = require("../../detachedNode");
10
+
11
+ /**
12
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
13
+ *
14
+ * This source code is licensed under the MIT license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ *
17
+ *
18
+ * @format
19
+ */
20
+ function ExportNamedDeclarationWithDeclaration(props) {
21
+ const node = (0, _detachedNode.detachedProps)(props.parent, {
22
+ type: 'ExportNamedDeclaration',
23
+ declaration: (0, _detachedNode.asDetachedNode)(props.declaration),
24
+ specifiers: [],
25
+ source: null,
26
+ exportKind: props.exportKind
27
+ });
28
+ (0, _detachedNode.setParentPointersInDirectChildren)(node);
29
+ return node;
30
+ }
31
+
32
+ function ExportNamedDeclarationWithSpecifiers(props) {
33
+ const node = (0, _detachedNode.detachedProps)(props.parent, {
34
+ type: 'ExportNamedDeclaration',
35
+ declaration: null,
36
+ specifiers: props.specifiers.map(n => (0, _detachedNode.asDetachedNode)(n)),
37
+ source: (0, _detachedNode.asDetachedNode)(props.source),
38
+ exportKind: props.exportKind
39
+ });
40
+ (0, _detachedNode.setParentPointersInDirectChildren)(node);
41
+ return node;
42
+ }
@@ -0,0 +1,75 @@
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
+ ExportNamedDeclarationWithDeclaration as ExportNamedDeclarationWithDeclarationType,
14
+ ExportNamedDeclarationWithSpecifiers as ExportNamedDeclarationWithSpecifiersType,
15
+ } from 'hermes-estree';
16
+ import type {DetachedNode, MaybeDetachedNode} from '../../detachedNode';
17
+
18
+ import {
19
+ asDetachedNode,
20
+ detachedProps,
21
+ setParentPointersInDirectChildren,
22
+ } from '../../detachedNode';
23
+
24
+ export type ExportNamedDeclarationWithDeclarationProps = {
25
+ +declaration?: ?MaybeDetachedNode<
26
+ ExportNamedDeclarationWithDeclarationType['declaration'],
27
+ >,
28
+ +exportKind: ExportNamedDeclarationWithDeclarationType['exportKind'],
29
+ };
30
+ export function ExportNamedDeclarationWithDeclaration(props: {
31
+ ...$ReadOnly<ExportNamedDeclarationWithDeclarationProps>,
32
+ +parent?: ESNode,
33
+ }): DetachedNode<ExportNamedDeclarationWithDeclarationType> {
34
+ const node = detachedProps<ExportNamedDeclarationWithDeclarationType>(
35
+ props.parent,
36
+ {
37
+ type: 'ExportNamedDeclaration',
38
+ declaration: asDetachedNode(props.declaration),
39
+ specifiers: [],
40
+ source: null,
41
+ exportKind: props.exportKind,
42
+ },
43
+ );
44
+ setParentPointersInDirectChildren(node);
45
+ return node;
46
+ }
47
+
48
+ export type ExportNamedDeclarationWithSpecifiersProps = {
49
+ +specifiers: $ReadOnlyArray<
50
+ MaybeDetachedNode<
51
+ ExportNamedDeclarationWithSpecifiersType['specifiers'][number],
52
+ >,
53
+ >,
54
+ +source?: ?MaybeDetachedNode<
55
+ ExportNamedDeclarationWithSpecifiersType['source'],
56
+ >,
57
+ +exportKind: ExportNamedDeclarationWithSpecifiersType['exportKind'],
58
+ };
59
+ export function ExportNamedDeclarationWithSpecifiers(props: {
60
+ ...$ReadOnly<ExportNamedDeclarationWithSpecifiersProps>,
61
+ +parent?: ESNode,
62
+ }): DetachedNode<ExportNamedDeclarationWithSpecifiersType> {
63
+ const node = detachedProps<ExportNamedDeclarationWithSpecifiersType>(
64
+ props.parent,
65
+ {
66
+ type: 'ExportNamedDeclaration',
67
+ declaration: null,
68
+ specifiers: props.specifiers.map(n => asDetachedNode(n)),
69
+ source: asDetachedNode(props.source),
70
+ exportKind: props.exportKind,
71
+ },
72
+ );
73
+ setParentPointersInDirectChildren(node);
74
+ return node;
75
+ }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BigIntLiteral = BigIntLiteral;
7
+ exports.BooleanLiteral = BooleanLiteral;
8
+ exports.NullLiteral = NullLiteral;
9
+ exports.NumericLiteral = NumericLiteral;
10
+ exports.RegExpLiteral = RegExpLiteral;
11
+ exports.StringLiteral = StringLiteral;
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 BigIntLiteral(props) {
25
+ var _props$raw;
26
+
27
+ return (0, _detachedNode.detachedProps)(props.parent, {
28
+ type: 'Literal',
29
+ value: props.value,
30
+ raw: (_props$raw = props.raw) != null ? _props$raw : `${props.value}n`,
31
+ bigint: `${props.value}`
32
+ });
33
+ }
34
+
35
+ function BooleanLiteral(props) {
36
+ return (0, _detachedNode.detachedProps)(props.parent, {
37
+ type: 'Literal',
38
+ raw: props.value ? 'true' : 'false',
39
+ value: props.value
40
+ });
41
+ }
42
+
43
+ function NumericLiteral(props) {
44
+ var _props$raw2;
45
+
46
+ return (0, _detachedNode.detachedProps)(props.parent, {
47
+ type: 'Literal',
48
+ value: props.value,
49
+ raw: (_props$raw2 = props.raw) != null ? _props$raw2 : `${props.value}`
50
+ });
51
+ }
52
+
53
+ function NullLiteral(props = { ...null
54
+ }) {
55
+ return (0, _detachedNode.detachedProps)(props.parent, {
56
+ type: 'Literal',
57
+ value: null,
58
+ raw: 'null'
59
+ });
60
+ } // pattern/flags are on a subobject in the estree spec, but are flat on the hermes types
61
+ // also the value is supposed to be a RegExp instance
62
+
63
+
64
+ function RegExpLiteral(props) {
65
+ const value = new RegExp(props.pattern, props.flags);
66
+ return (0, _detachedNode.detachedProps)(props.parent, {
67
+ type: 'Literal',
68
+ value,
69
+ raw: value.toString(),
70
+ regex: {
71
+ pattern: props.pattern,
72
+ flags: props.flags
73
+ }
74
+ });
75
+ }
76
+
77
+ function StringLiteral(props) {
78
+ const hasSingleQuote = props.value.includes('"');
79
+ const hasDoubleQuote = props.value.includes("'");
80
+ let raw = props.raw;
81
+
82
+ if (raw == null) {
83
+ if (hasSingleQuote && hasDoubleQuote) {
84
+ raw = `'${props.value.replace(/'/g, "\\'")}'`;
85
+ } else if (hasSingleQuote) {
86
+ raw = `"${props.value}"`;
87
+ } else {
88
+ raw = `'${props.value}'`;
89
+ }
90
+ }
91
+
92
+ return (0, _detachedNode.detachedProps)(props.parent, {
93
+ type: 'Literal',
94
+ raw,
95
+ value: props.value
96
+ });
97
+ }
@@ -0,0 +1,139 @@
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
+ BigIntLiteral as BigIntLiteralType,
13
+ BooleanLiteral as BooleanLiteralType,
14
+ ESNode,
15
+ NullLiteral as NullLiteralType,
16
+ NumericLiteral as NumericLiteralType,
17
+ RegExpLiteral as RegExpLiteralType,
18
+ StringLiteral as StringLiteralType,
19
+ } from 'hermes-estree';
20
+ import type {DetachedNode} from '../../detachedNode';
21
+
22
+ import {detachedProps} from '../../detachedNode';
23
+
24
+ // Literals require a "raw" which is added by the estree transform, not hermes.
25
+
26
+ export type BigIntLiteralProps = {
27
+ +value: $FlowFixMe /* bigint | null */,
28
+ /**
29
+ * Only set this if you want to use a source-code representation like 1_1n, etc.
30
+ * By default "raw" will just be the exact number you've given.
31
+ */
32
+ +raw?: NumericLiteralType['raw'],
33
+ };
34
+ export function BigIntLiteral(props: {
35
+ ...$ReadOnly<BigIntLiteralProps>,
36
+ +parent?: ESNode,
37
+ }): DetachedNode<BigIntLiteralType> {
38
+ return detachedProps<BigIntLiteralType>(props.parent, {
39
+ type: 'Literal',
40
+ value: props.value,
41
+ raw: props.raw ?? `${props.value}n`,
42
+ bigint: `${props.value}`,
43
+ });
44
+ }
45
+
46
+ export type BooleanLiteralProps = {
47
+ +value: BooleanLiteralType['value'],
48
+ };
49
+ export function BooleanLiteral(props: {
50
+ ...$ReadOnly<BooleanLiteralProps>,
51
+ +parent?: ESNode,
52
+ }): DetachedNode<BooleanLiteralType> {
53
+ return detachedProps<BooleanLiteralType>(props.parent, {
54
+ type: 'Literal',
55
+ raw: props.value ? 'true' : 'false',
56
+ value: props.value,
57
+ });
58
+ }
59
+
60
+ export type NumericLiteralProps = {
61
+ +value: NumericLiteralType['value'],
62
+ /**
63
+ * Only set this if you want to use a source-code representation like 1e100, 0x11, 1_1, etc.
64
+ * By default "raw" will just be the exact number you've given.
65
+ */
66
+ +raw?: NumericLiteralType['raw'],
67
+ };
68
+ export function NumericLiteral(props: {
69
+ ...$ReadOnly<NumericLiteralProps>,
70
+ +parent?: ESNode,
71
+ }): DetachedNode<NumericLiteralType> {
72
+ return detachedProps<NumericLiteralType>(props.parent, {
73
+ type: 'Literal',
74
+ value: props.value,
75
+ raw: props.raw ?? `${props.value}`,
76
+ });
77
+ }
78
+
79
+ export type NullLiteralProps = {};
80
+ export function NullLiteral(
81
+ props: {
82
+ +parent?: ESNode,
83
+ } = {...null},
84
+ ): DetachedNode<NullLiteralType> {
85
+ return detachedProps<NullLiteralType>(props.parent, {
86
+ type: 'Literal',
87
+ value: null,
88
+ raw: 'null',
89
+ });
90
+ }
91
+
92
+ // pattern/flags are on a subobject in the estree spec, but are flat on the hermes types
93
+ // also the value is supposed to be a RegExp instance
94
+ export type RegExpLiteralProps = {
95
+ +pattern: RegExpLiteralType['regex']['pattern'],
96
+ +flags: RegExpLiteralType['regex']['flags'],
97
+ };
98
+ export function RegExpLiteral(props: {
99
+ ...$ReadOnly<RegExpLiteralProps>,
100
+ +parent?: ESNode,
101
+ }): DetachedNode<RegExpLiteralType> {
102
+ const value = new RegExp(props.pattern, props.flags);
103
+ return detachedProps<RegExpLiteralType>(props.parent, {
104
+ type: 'Literal',
105
+ value,
106
+ raw: value.toString(),
107
+ regex: {
108
+ pattern: props.pattern,
109
+ flags: props.flags,
110
+ },
111
+ });
112
+ }
113
+
114
+ export type StringLiteralProps = {
115
+ +value: StringLiteralType['value'],
116
+ +raw?: StringLiteralType['raw'],
117
+ };
118
+ export function StringLiteral(props: {
119
+ ...$ReadOnly<StringLiteralProps>,
120
+ +parent?: ESNode,
121
+ }): DetachedNode<StringLiteralType> {
122
+ const hasSingleQuote = props.value.includes('"');
123
+ const hasDoubleQuote = props.value.includes("'");
124
+ let raw = props.raw;
125
+ if (raw == null) {
126
+ if (hasSingleQuote && hasDoubleQuote) {
127
+ raw = `'${props.value.replace(/'/g, "\\'")}'`;
128
+ } else if (hasSingleQuote) {
129
+ raw = `"${props.value}"`;
130
+ } else {
131
+ raw = `'${props.value}'`;
132
+ }
133
+ }
134
+ return detachedProps<StringLiteralType>(props.parent, {
135
+ type: 'Literal',
136
+ raw,
137
+ value: props.value,
138
+ });
139
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ObjectTypeAccessorSignature = ObjectTypeAccessorSignature;
7
+ exports.ObjectTypeMethodSignature = ObjectTypeMethodSignature;
8
+ exports.ObjectTypePropertySignature = ObjectTypePropertySignature;
9
+
10
+ var _detachedNode = require("../../detachedNode");
11
+
12
+ /**
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ *
18
+ *
19
+ * @format
20
+ */
21
+ function ObjectTypeMethodSignature(props) {
22
+ var _props$proto, _props$static;
23
+
24
+ const node = (0, _detachedNode.detachedProps)(props.parent, {
25
+ type: 'ObjectTypeProperty',
26
+ key: (0, _detachedNode.asDetachedNode)(props.key),
27
+ kind: 'init',
28
+ method: true,
29
+ optional: false,
30
+ proto: (_props$proto = props.proto) != null ? _props$proto : false,
31
+ static: (_props$static = props.static) != null ? _props$static : false,
32
+ value: (0, _detachedNode.asDetachedNode)(props.value),
33
+ variance: null
34
+ });
35
+ (0, _detachedNode.setParentPointersInDirectChildren)(node);
36
+ return node;
37
+ }
38
+
39
+ function ObjectTypePropertySignature(props) {
40
+ var _props$proto2, _props$static2;
41
+
42
+ const node = (0, _detachedNode.detachedProps)(props.parent, {
43
+ type: 'ObjectTypeProperty',
44
+ key: (0, _detachedNode.asDetachedNode)(props.key),
45
+ kind: 'init',
46
+ method: false,
47
+ optional: props.optional,
48
+ proto: (_props$proto2 = props.proto) != null ? _props$proto2 : false,
49
+ static: (_props$static2 = props.static) != null ? _props$static2 : false,
50
+ value: (0, _detachedNode.asDetachedNode)(props.value),
51
+ variance: (0, _detachedNode.asDetachedNode)(props.variance)
52
+ });
53
+ (0, _detachedNode.setParentPointersInDirectChildren)(node);
54
+ return node;
55
+ }
56
+
57
+ function ObjectTypeAccessorSignature(props) {
58
+ var _props$proto3, _props$static3;
59
+
60
+ const node = (0, _detachedNode.detachedProps)(props.parent, {
61
+ type: 'ObjectTypeProperty',
62
+ key: (0, _detachedNode.asDetachedNode)(props.key),
63
+ kind: props.kind,
64
+ method: false,
65
+ optional: false,
66
+ proto: (_props$proto3 = props.proto) != null ? _props$proto3 : false,
67
+ static: (_props$static3 = props.static) != null ? _props$static3 : false,
68
+ value: (0, _detachedNode.asDetachedNode)(props.value),
69
+ variance: null
70
+ });
71
+ (0, _detachedNode.setParentPointersInDirectChildren)(node);
72
+ return node;
73
+ }