@ohos-ports/hermes-parser 0.37.0-beta.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.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/dist/HermesAST.js.flow +57 -0
  4. package/dist/HermesASTAdapter.js +192 -0
  5. package/dist/HermesASTAdapter.js.flow +189 -0
  6. package/dist/HermesParser.js +108 -0
  7. package/dist/HermesParser.js.flow +163 -0
  8. package/dist/HermesParserDecodeUTF8String.js +68 -0
  9. package/dist/HermesParserDecodeUTF8String.js.flow +65 -0
  10. package/dist/HermesParserDeserializer.js +242 -0
  11. package/dist/HermesParserDeserializer.js.flow +260 -0
  12. package/dist/HermesParserNodeDeserializers.js +2594 -0
  13. package/dist/HermesParserNodeDeserializers.js.flow +16 -0
  14. package/dist/HermesParserWASM.js +6 -0
  15. package/dist/HermesParserWASM.js.flow +97 -0
  16. package/dist/HermesToESTreeAdapter.js +441 -0
  17. package/dist/HermesToESTreeAdapter.js.flow +423 -0
  18. package/dist/ParserOptions.js +20 -0
  19. package/dist/ParserOptions.js.flow +44 -0
  20. package/dist/babel/TransformESTreeToBabel.js +1197 -0
  21. package/dist/babel/TransformESTreeToBabel.js.flow +1349 -0
  22. package/dist/estree/StripFlowTypes.js +175 -0
  23. package/dist/estree/StripFlowTypes.js.flow +158 -0
  24. package/dist/estree/StripFlowTypesForBabel.js +215 -0
  25. package/dist/estree/StripFlowTypesForBabel.js.flow +216 -0
  26. package/dist/estree/TransformComponentSyntax.js +792 -0
  27. package/dist/estree/TransformComponentSyntax.js.flow +864 -0
  28. package/dist/estree/TransformEnumSyntax.js +106 -0
  29. package/dist/estree/TransformEnumSyntax.js.flow +125 -0
  30. package/dist/estree/TransformMatchSyntax.js +1083 -0
  31. package/dist/estree/TransformMatchSyntax.js.flow +991 -0
  32. package/dist/estree/TransformRecordSyntax.js +296 -0
  33. package/dist/estree/TransformRecordSyntax.js.flow +310 -0
  34. package/dist/generated/ESTreeVisitorKeys.js +233 -0
  35. package/dist/generated/ESTreeVisitorKeys.js.flow +15 -0
  36. package/dist/generated/ParserVisitorKeys.js +842 -0
  37. package/dist/generated/ParserVisitorKeys.js.flow +17 -0
  38. package/dist/getModuleDocblock.js +112 -0
  39. package/dist/getModuleDocblock.js.flow +118 -0
  40. package/dist/index.js +170 -0
  41. package/dist/index.js.flow +131 -0
  42. package/dist/src/HermesASTAdapter.js +192 -0
  43. package/dist/src/HermesParser.js +108 -0
  44. package/dist/src/HermesParserDecodeUTF8String.js +68 -0
  45. package/dist/src/HermesParserDeserializer.js +242 -0
  46. package/dist/src/HermesParserNodeDeserializers.js +2594 -0
  47. package/dist/src/HermesToESTreeAdapter.js +441 -0
  48. package/dist/src/ParserOptions.js +20 -0
  49. package/dist/src/babel/TransformESTreeToBabel.js +1197 -0
  50. package/dist/src/estree/StripFlowTypes.js +175 -0
  51. package/dist/src/estree/StripFlowTypesForBabel.js +215 -0
  52. package/dist/src/estree/TransformComponentSyntax.js +792 -0
  53. package/dist/src/estree/TransformEnumSyntax.js +106 -0
  54. package/dist/src/estree/TransformMatchSyntax.js +1083 -0
  55. package/dist/src/estree/TransformRecordSyntax.js +296 -0
  56. package/dist/src/generated/ESTreeVisitorKeys.js +233 -0
  57. package/dist/src/generated/ParserVisitorKeys.js +842 -0
  58. package/dist/src/getModuleDocblock.js +112 -0
  59. package/dist/src/index.js +170 -0
  60. package/dist/src/transform/SimpleTransform.js +145 -0
  61. package/dist/src/transform/astArrayMutationHelpers.js +62 -0
  62. package/dist/src/transform/astNodeMutationHelpers.js +201 -0
  63. package/dist/src/traverse/SimpleTraverser.js +139 -0
  64. package/dist/src/traverse/getVisitorKeys.js +39 -0
  65. package/dist/src/utils/Builders.js +190 -0
  66. package/dist/src/utils/GenID.js +46 -0
  67. package/dist/src/utils/createSyntaxError.js +25 -0
  68. package/dist/src/utils/isReservedWord.js +62 -0
  69. package/dist/src/utils/mutateESTreeASTForPrettier.js +127 -0
  70. package/dist/transform/SimpleTransform.js +145 -0
  71. package/dist/transform/SimpleTransform.js.flow +168 -0
  72. package/dist/transform/astArrayMutationHelpers.js +62 -0
  73. package/dist/transform/astArrayMutationHelpers.js.flow +71 -0
  74. package/dist/transform/astNodeMutationHelpers.js +201 -0
  75. package/dist/transform/astNodeMutationHelpers.js.flow +252 -0
  76. package/dist/traverse/SimpleTraverser.js +139 -0
  77. package/dist/traverse/SimpleTraverser.js.flow +133 -0
  78. package/dist/traverse/getVisitorKeys.js +39 -0
  79. package/dist/traverse/getVisitorKeys.js.flow +38 -0
  80. package/dist/utils/Builders.js +190 -0
  81. package/dist/utils/Builders.js.flow +218 -0
  82. package/dist/utils/GenID.js +46 -0
  83. package/dist/utils/GenID.js.flow +39 -0
  84. package/dist/utils/createSyntaxError.js +25 -0
  85. package/dist/utils/createSyntaxError.js.flow +24 -0
  86. package/dist/utils/isReservedWord.js +62 -0
  87. package/dist/utils/isReservedWord.js.flow +57 -0
  88. package/dist/utils/mutateESTreeASTForPrettier.js +127 -0
  89. package/dist/utils/mutateESTreeASTForPrettier.js.flow +130 -0
  90. package/package.json +30 -0
@@ -0,0 +1,296 @@
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
+ * strict
8
+ * @format
9
+ */
10
+ 'use strict';
11
+ /**
12
+ * Transform record declarations.
13
+ */
14
+
15
+ Object.defineProperty(exports, "__esModule", {
16
+ value: true
17
+ });
18
+ exports.transformProgram = transformProgram;
19
+
20
+ var _hermesEstree = require("hermes-estree");
21
+
22
+ var _SimpleTransform = require("../transform/SimpleTransform");
23
+
24
+ var _astNodeMutationHelpers = require("../transform/astNodeMutationHelpers");
25
+
26
+ var _Builders = require("../utils/Builders");
27
+
28
+ var _isReservedWord = _interopRequireDefault(require("../utils/isReservedWord"));
29
+
30
+ var _GenID = _interopRequireDefault(require("../utils/GenID"));
31
+
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
+
34
+ function nameOfKey(key) {
35
+ switch (key.type) {
36
+ case 'Identifier':
37
+ return key.name;
38
+
39
+ case 'Literal':
40
+ if ((0, _hermesEstree.isBigIntLiteral)(key)) {
41
+ return key.bigint;
42
+ }
43
+
44
+ return String(key.value);
45
+ }
46
+ }
47
+
48
+ function mapRecordDeclaration(genID, node) {
49
+ const ownProperties = [];
50
+ const staticProperties = [];
51
+ const methods = [];
52
+ const staticMethods = [];
53
+
54
+ for (const element of node.body.elements) {
55
+ switch (element.type) {
56
+ case 'RecordDeclarationProperty':
57
+ ownProperties.push(element);
58
+ break;
59
+
60
+ case 'RecordDeclarationStaticProperty':
61
+ staticProperties.push(element);
62
+ break;
63
+
64
+ case 'MethodDefinition':
65
+ if (element.static) {
66
+ staticMethods.push(element);
67
+ } else {
68
+ methods.push(element);
69
+ }
70
+
71
+ break;
72
+ }
73
+ }
74
+
75
+ const reservedPropNames = new Map(); // Create constructor parameter as an object pattern with all properties
76
+
77
+ const constructorParam = {
78
+ type: 'ObjectPattern',
79
+ properties: ownProperties.map(prop => {
80
+ const {
81
+ key,
82
+ defaultValue
83
+ } = prop;
84
+ const keyName = nameOfKey(key);
85
+
86
+ const getValue = bindingIdent => defaultValue != null ? {
87
+ type: 'AssignmentPattern',
88
+ left: bindingIdent,
89
+ right: (0, _astNodeMutationHelpers.deepCloneNode)(defaultValue),
90
+ ...(0, _Builders.etc)()
91
+ } : bindingIdent;
92
+
93
+ switch (key.type) {
94
+ case 'Identifier':
95
+ {
96
+ const needsNewBinding = (0, _isReservedWord.default)(keyName);
97
+ const bindingName = needsNewBinding ? genID.id() : keyName;
98
+ const bindingIdent = (0, _Builders.ident)(bindingName);
99
+
100
+ if (needsNewBinding) {
101
+ reservedPropNames.set(keyName, bindingName);
102
+ }
103
+
104
+ if (needsNewBinding) {
105
+ return {
106
+ type: 'Property',
107
+ kind: 'init',
108
+ key: (0, _astNodeMutationHelpers.shallowCloneNode)(key),
109
+ value: getValue(bindingIdent),
110
+ shorthand: false,
111
+ method: false,
112
+ computed: false,
113
+ ...(0, _Builders.etc)(),
114
+ parent: _Builders.EMPTY_PARENT
115
+ };
116
+ } else {
117
+ return {
118
+ type: 'Property',
119
+ kind: 'init',
120
+ key: (0, _astNodeMutationHelpers.shallowCloneNode)(key),
121
+ value: getValue(bindingIdent),
122
+ shorthand: true,
123
+ method: false,
124
+ computed: false,
125
+ ...(0, _Builders.etc)(),
126
+ parent: _Builders.EMPTY_PARENT
127
+ };
128
+ }
129
+ }
130
+
131
+ case 'Literal':
132
+ {
133
+ const bindingName = genID.id();
134
+ const bindingIdent = (0, _Builders.ident)(bindingName);
135
+ reservedPropNames.set(keyName, bindingName);
136
+ return {
137
+ type: 'Property',
138
+ kind: 'init',
139
+ key: (0, _astNodeMutationHelpers.shallowCloneNode)(key),
140
+ value: getValue(bindingIdent),
141
+ shorthand: false,
142
+ method: false,
143
+ computed: false,
144
+ ...(0, _Builders.etc)(),
145
+ parent: _Builders.EMPTY_PARENT
146
+ };
147
+ }
148
+ }
149
+ }),
150
+ typeAnnotation: null,
151
+ ...(0, _Builders.etc)()
152
+ }; // Create the constructor method
153
+
154
+ const constructor = {
155
+ type: 'MethodDefinition',
156
+ key: (0, _Builders.ident)('constructor'),
157
+ kind: 'constructor',
158
+ computed: false,
159
+ static: false,
160
+ decorators: [],
161
+ value: {
162
+ type: 'FunctionExpression',
163
+ id: null,
164
+ params: [constructorParam],
165
+ body: {
166
+ type: 'BlockStatement',
167
+ body: ownProperties.map(({
168
+ key
169
+ }) => {
170
+ var _reservedPropNames$ge;
171
+
172
+ const keyName = nameOfKey(key);
173
+ const bindingIdent = (0, _Builders.ident)((_reservedPropNames$ge = reservedPropNames.get(keyName)) != null ? _reservedPropNames$ge : keyName);
174
+ const object = {
175
+ type: 'ThisExpression',
176
+ ...(0, _Builders.etc)()
177
+ };
178
+ const memberExpression = key.type === 'Identifier' ? {
179
+ type: 'MemberExpression',
180
+ object,
181
+ property: (0, _astNodeMutationHelpers.shallowCloneNode)(key),
182
+ computed: false,
183
+ optional: false,
184
+ ...(0, _Builders.etc)()
185
+ } : {
186
+ type: 'MemberExpression',
187
+ object,
188
+ property: (0, _astNodeMutationHelpers.shallowCloneNode)(key),
189
+ computed: true,
190
+ optional: false,
191
+ ...(0, _Builders.etc)()
192
+ };
193
+ return {
194
+ type: 'ExpressionStatement',
195
+ expression: {
196
+ type: 'AssignmentExpression',
197
+ operator: '=',
198
+ left: memberExpression,
199
+ right: bindingIdent,
200
+ ...(0, _Builders.etc)()
201
+ },
202
+ directive: null,
203
+ ...(0, _Builders.etc)()
204
+ };
205
+ }),
206
+ ...(0, _Builders.etc)()
207
+ },
208
+ generator: false,
209
+ async: false,
210
+ predicate: null,
211
+ returnType: null,
212
+ typeParameters: null,
213
+ ...(0, _Builders.etc)()
214
+ },
215
+ ...(0, _Builders.etc)(),
216
+ parent: _Builders.EMPTY_PARENT
217
+ };
218
+ const classStaticProperties = staticProperties.map(prop => ({
219
+ type: 'PropertyDefinition',
220
+ key: (0, _astNodeMutationHelpers.shallowCloneNode)(prop.key),
221
+ value: (0, _astNodeMutationHelpers.deepCloneNode)(prop.value),
222
+ static: true,
223
+ decorators: [],
224
+ typeAnnotation: null,
225
+ variance: null,
226
+ computed: false,
227
+ declare: false,
228
+ optional: false,
229
+ ...(0, _Builders.etc)(),
230
+ parent: _Builders.EMPTY_PARENT
231
+ }));
232
+ const classBodyElements = [constructor, ...methods, ...classStaticProperties, ...staticMethods];
233
+ return {
234
+ type: 'ClassDeclaration',
235
+ id: (0, _astNodeMutationHelpers.shallowCloneNode)(node.id),
236
+ body: {
237
+ type: 'ClassBody',
238
+ body: classBodyElements,
239
+ ...(0, _Builders.etc)(),
240
+ parent: _Builders.EMPTY_PARENT
241
+ },
242
+ superClass: null,
243
+ typeParameters: null,
244
+ superTypeArguments: null,
245
+ implements: [],
246
+ decorators: [],
247
+ ...(0, _Builders.etc)()
248
+ };
249
+ }
250
+
251
+ function mapRecordExpression(node) {
252
+ const obj = {
253
+ type: 'ObjectExpression',
254
+ properties: node.properties.properties,
255
+ ...(0, _Builders.etc)()
256
+ };
257
+ return {
258
+ type: 'NewExpression',
259
+ callee: node.recordConstructor,
260
+ arguments: [obj],
261
+ typeArguments: null,
262
+ ...(0, _Builders.etc)()
263
+ };
264
+ }
265
+
266
+ function transformProgram(program, _options) {
267
+ const genID = new _GenID.default('r');
268
+ return _SimpleTransform.SimpleTransform.transformProgram(program, {
269
+ transform(node) {
270
+ switch (node.type) {
271
+ case 'RecordDeclaration':
272
+ {
273
+ return mapRecordDeclaration(genID, node);
274
+ }
275
+
276
+ case 'RecordExpression':
277
+ {
278
+ return mapRecordExpression(node);
279
+ }
280
+
281
+ case 'Identifier':
282
+ {
283
+ // A rudimentary check to avoid some collisions with our generated
284
+ // variable names. Ideally, we would have access a scope analyzer
285
+ // inside the transform instead.
286
+ genID.addUsage(node.name);
287
+ return node;
288
+ }
289
+
290
+ default:
291
+ return node;
292
+ }
293
+ }
294
+
295
+ });
296
+ }
@@ -0,0 +1,310 @@
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
8
+ * @format
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ /**
14
+ * Transform record declarations.
15
+ */
16
+
17
+ import type {ParserOptions} from '../ParserOptions';
18
+ import type {
19
+ AssignmentPattern,
20
+ ClassDeclaration,
21
+ ClassMember,
22
+ ESNode,
23
+ Identifier,
24
+ MemberExpression,
25
+ MethodDefinition,
26
+ NewExpression,
27
+ ObjectExpression,
28
+ ObjectPattern,
29
+ ObjectPropertyKey,
30
+ Program,
31
+ RecordDeclaration,
32
+ RecordDeclarationProperty,
33
+ RecordDeclarationStaticProperty,
34
+ RecordExpression,
35
+ ThisExpression,
36
+ } from 'hermes-estree';
37
+
38
+ import {isBigIntLiteral} from 'hermes-estree';
39
+ import {SimpleTransform} from '../transform/SimpleTransform';
40
+ import {
41
+ deepCloneNode,
42
+ shallowCloneNode,
43
+ } from '../transform/astNodeMutationHelpers';
44
+ import {EMPTY_PARENT, etc, ident} from '../utils/Builders';
45
+ import isReservedWord from '../utils/isReservedWord';
46
+ import GenID from '../utils/GenID';
47
+
48
+ function nameOfKey(key: ObjectPropertyKey): string {
49
+ switch (key.type) {
50
+ case 'Identifier':
51
+ return key.name;
52
+ case 'Literal':
53
+ if (isBigIntLiteral(key)) {
54
+ return key.bigint;
55
+ }
56
+ return String(key.value);
57
+ }
58
+ }
59
+
60
+ function mapRecordDeclaration(
61
+ genID: GenID,
62
+ node: RecordDeclaration,
63
+ ): ClassDeclaration {
64
+ const ownProperties: Array<RecordDeclarationProperty> = [];
65
+ const staticProperties: Array<RecordDeclarationStaticProperty> = [];
66
+ const methods: Array<MethodDefinition> = [];
67
+ const staticMethods: Array<MethodDefinition> = [];
68
+
69
+ for (const element of node.body.elements) {
70
+ switch (element.type) {
71
+ case 'RecordDeclarationProperty':
72
+ ownProperties.push(element);
73
+ break;
74
+ case 'RecordDeclarationStaticProperty':
75
+ staticProperties.push(element);
76
+ break;
77
+ case 'MethodDefinition':
78
+ if (element.static) {
79
+ staticMethods.push(element);
80
+ } else {
81
+ methods.push(element);
82
+ }
83
+ break;
84
+ }
85
+ }
86
+
87
+ const reservedPropNames = new Map<string, string>();
88
+
89
+ // Create constructor parameter as an object pattern with all properties
90
+ const constructorParam: ObjectPattern = {
91
+ type: 'ObjectPattern',
92
+ properties: ownProperties.map(prop => {
93
+ const {key, defaultValue} = prop;
94
+ const keyName = nameOfKey(key);
95
+
96
+ const getValue = (
97
+ bindingIdent: Identifier,
98
+ ): AssignmentPattern | Identifier =>
99
+ defaultValue != null
100
+ ? {
101
+ type: 'AssignmentPattern',
102
+ left: bindingIdent,
103
+ right: deepCloneNode(defaultValue),
104
+ ...etc(),
105
+ }
106
+ : bindingIdent;
107
+
108
+ switch (key.type) {
109
+ case 'Identifier': {
110
+ const needsNewBinding = isReservedWord(keyName);
111
+ const bindingName = needsNewBinding ? genID.id() : keyName;
112
+ const bindingIdent = ident(bindingName);
113
+ if (needsNewBinding) {
114
+ reservedPropNames.set(keyName, bindingName);
115
+ }
116
+
117
+ if (needsNewBinding) {
118
+ return {
119
+ type: 'Property',
120
+ kind: 'init',
121
+ key: shallowCloneNode(key),
122
+ value: getValue(bindingIdent),
123
+ shorthand: false,
124
+ method: false,
125
+ computed: false,
126
+ ...etc(),
127
+ parent: EMPTY_PARENT,
128
+ };
129
+ } else {
130
+ return {
131
+ type: 'Property',
132
+ kind: 'init',
133
+ key: shallowCloneNode(key),
134
+ value: getValue(bindingIdent),
135
+ shorthand: true,
136
+ method: false,
137
+ computed: false,
138
+ ...etc(),
139
+ parent: EMPTY_PARENT,
140
+ };
141
+ }
142
+ }
143
+ case 'Literal': {
144
+ const bindingName = genID.id();
145
+ const bindingIdent = ident(bindingName);
146
+ reservedPropNames.set(keyName, bindingName);
147
+
148
+ return {
149
+ type: 'Property',
150
+ kind: 'init',
151
+ key: shallowCloneNode(key),
152
+ value: getValue(bindingIdent),
153
+ shorthand: false,
154
+ method: false,
155
+ computed: false,
156
+ ...etc(),
157
+ parent: EMPTY_PARENT,
158
+ };
159
+ }
160
+ }
161
+ }),
162
+ typeAnnotation: null,
163
+ ...etc(),
164
+ };
165
+
166
+ // Create the constructor method
167
+ const constructor: MethodDefinition = {
168
+ type: 'MethodDefinition',
169
+ key: ident('constructor'),
170
+ kind: 'constructor',
171
+ computed: false,
172
+ static: false,
173
+ decorators: [],
174
+ value: {
175
+ type: 'FunctionExpression',
176
+ id: null,
177
+ params: [constructorParam],
178
+ body: {
179
+ type: 'BlockStatement',
180
+ body: ownProperties.map(({key}) => {
181
+ const keyName = nameOfKey(key);
182
+ const bindingIdent = ident(reservedPropNames.get(keyName) ?? keyName);
183
+ const object: ThisExpression = {type: 'ThisExpression', ...etc()};
184
+ const memberExpression: MemberExpression =
185
+ key.type === 'Identifier'
186
+ ? {
187
+ type: 'MemberExpression',
188
+ object,
189
+ property: shallowCloneNode(key),
190
+ computed: false,
191
+ optional: false,
192
+ ...etc(),
193
+ }
194
+ : {
195
+ type: 'MemberExpression',
196
+ object,
197
+ property: shallowCloneNode(key),
198
+ computed: true,
199
+ optional: false,
200
+ ...etc(),
201
+ };
202
+ return {
203
+ type: 'ExpressionStatement',
204
+ expression: {
205
+ type: 'AssignmentExpression',
206
+ operator: '=',
207
+ left: memberExpression,
208
+ right: bindingIdent,
209
+ ...etc(),
210
+ },
211
+ directive: null,
212
+ ...etc(),
213
+ };
214
+ }),
215
+ ...etc(),
216
+ },
217
+ generator: false,
218
+ async: false,
219
+ predicate: null,
220
+ returnType: null,
221
+ typeParameters: null,
222
+ ...etc(),
223
+ },
224
+ ...etc(),
225
+ parent: EMPTY_PARENT,
226
+ };
227
+
228
+ const classStaticProperties: ReadonlyArray<ClassMember> =
229
+ staticProperties.map(prop => ({
230
+ type: 'PropertyDefinition',
231
+ key: shallowCloneNode(prop.key),
232
+ value: deepCloneNode(prop.value),
233
+ static: true,
234
+ decorators: [],
235
+ typeAnnotation: null,
236
+ variance: null,
237
+ computed: false,
238
+ declare: false,
239
+ optional: false,
240
+ ...etc(),
241
+ parent: EMPTY_PARENT,
242
+ }));
243
+
244
+ const classBodyElements: ReadonlyArray<ClassMember> = [
245
+ constructor,
246
+ ...methods,
247
+ ...classStaticProperties,
248
+ ...staticMethods,
249
+ ];
250
+
251
+ return {
252
+ type: 'ClassDeclaration',
253
+ id: shallowCloneNode(node.id),
254
+ body: {
255
+ type: 'ClassBody',
256
+ body: classBodyElements,
257
+ ...etc(),
258
+ parent: EMPTY_PARENT,
259
+ },
260
+ superClass: null,
261
+ typeParameters: null,
262
+ superTypeArguments: null,
263
+ implements: [],
264
+ decorators: [],
265
+ ...etc(),
266
+ };
267
+ }
268
+
269
+ function mapRecordExpression(node: RecordExpression): NewExpression {
270
+ const obj: ObjectExpression = {
271
+ type: 'ObjectExpression',
272
+ properties: node.properties.properties,
273
+ ...etc(),
274
+ };
275
+ return {
276
+ type: 'NewExpression',
277
+ callee: node.recordConstructor,
278
+ arguments: [obj],
279
+ typeArguments: null,
280
+ ...etc(),
281
+ };
282
+ }
283
+
284
+ export function transformProgram(
285
+ program: Program,
286
+ _options: ParserOptions,
287
+ ): Program {
288
+ const genID = new GenID('r');
289
+ return SimpleTransform.transformProgram(program, {
290
+ transform(node: ESNode) {
291
+ switch (node.type) {
292
+ case 'RecordDeclaration': {
293
+ return mapRecordDeclaration(genID, node);
294
+ }
295
+ case 'RecordExpression': {
296
+ return mapRecordExpression(node);
297
+ }
298
+ case 'Identifier': {
299
+ // A rudimentary check to avoid some collisions with our generated
300
+ // variable names. Ideally, we would have access a scope analyzer
301
+ // inside the transform instead.
302
+ genID.addUsage(node.name);
303
+ return node;
304
+ }
305
+ default:
306
+ return node;
307
+ }
308
+ },
309
+ });
310
+ }