hermes-parser 0.5.0 → 0.6.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/LICENSE +1 -1
- package/dist/HermesAST.js.flow +2 -1
- package/dist/HermesASTAdapter.js +133 -144
- package/dist/HermesASTAdapter.js.flow +1 -1
- package/dist/HermesParser.js +19 -19
- package/dist/HermesParser.js.flow +1 -1
- package/dist/HermesParserDecodeUTF8String.js +10 -10
- package/dist/HermesParserDecodeUTF8String.js.flow +3 -3
- package/dist/HermesParserDeserializer.js +187 -221
- package/dist/HermesParserDeserializer.js.flow +2 -1
- package/dist/HermesParserNodeDeserializers.js +58 -27
- package/dist/HermesParserNodeDeserializers.js.flow +1 -1
- package/dist/HermesParserWASM.js +2 -2
- package/dist/HermesParserWASM.js.flow +1 -1
- package/dist/HermesToBabelAdapter.js +336 -370
- package/dist/HermesToBabelAdapter.js.flow +17 -2
- package/dist/HermesToESTreeAdapter.js +188 -167
- package/dist/HermesToESTreeAdapter.js.flow +64 -14
- package/dist/ParserOptions.js.flow +1 -1
- package/dist/generated/visitor-keys.js +20 -13
- package/dist/generated/visitor-keys.js.flow +1 -1
- package/dist/index.js +12 -21
- package/dist/index.js.flow +2 -2
- package/package.json +5 -2
|
@@ -1,446 +1,412 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
|
-
exports
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _HermesASTAdapter = _interopRequireDefault(require("./HermesASTAdapter"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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
|
+
|
|
22
|
+
/*
|
|
23
|
+
This class does some very "javascripty" things in the name of
|
|
24
|
+
performance which are ultimately impossible to soundly type.
|
|
25
|
+
|
|
26
|
+
So instead of adding strict types and a large number of suppression
|
|
27
|
+
comments, instead it is left untyped and subclasses are strictly
|
|
28
|
+
typed via a separate flow declaration file.
|
|
29
|
+
*/
|
|
30
|
+
class HermesToBabelAdapter extends _HermesASTAdapter.default {
|
|
31
|
+
fixSourceLocation(node) {
|
|
32
|
+
var _this$sourceFilename;
|
|
33
|
+
|
|
34
|
+
const loc = node.loc;
|
|
35
|
+
|
|
36
|
+
if (loc == null) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
13
39
|
|
|
14
|
-
|
|
40
|
+
node.loc = {
|
|
41
|
+
source: (_this$sourceFilename = this.sourceFilename) != null ? _this$sourceFilename : null,
|
|
42
|
+
start: loc.start,
|
|
43
|
+
end: loc.end
|
|
44
|
+
};
|
|
45
|
+
node.start = loc.rangeStart;
|
|
46
|
+
node.end = loc.rangeEnd;
|
|
47
|
+
}
|
|
15
48
|
|
|
16
|
-
|
|
49
|
+
mapNode(node) {
|
|
50
|
+
this.fixSourceLocation(node);
|
|
17
51
|
|
|
18
|
-
|
|
52
|
+
switch (node.type) {
|
|
53
|
+
case 'Program':
|
|
54
|
+
return this.mapProgram(node);
|
|
19
55
|
|
|
20
|
-
|
|
56
|
+
case 'BlockStatement':
|
|
57
|
+
return this.mapNodeWithDirectives(node);
|
|
21
58
|
|
|
22
|
-
|
|
59
|
+
case 'Empty':
|
|
60
|
+
return this.mapEmpty(node);
|
|
23
61
|
|
|
24
|
-
|
|
62
|
+
case 'Identifier':
|
|
63
|
+
return this.mapIdentifier(node);
|
|
25
64
|
|
|
26
|
-
|
|
65
|
+
case 'TemplateElement':
|
|
66
|
+
return this.mapTemplateElement(node);
|
|
27
67
|
|
|
28
|
-
|
|
68
|
+
case 'GenericTypeAnnotation':
|
|
69
|
+
return this.mapGenericTypeAnnotation(node);
|
|
29
70
|
|
|
30
|
-
|
|
71
|
+
case 'SymbolTypeAnnotation':
|
|
72
|
+
return this.mapSymbolTypeAnnotation(node);
|
|
31
73
|
|
|
32
|
-
|
|
74
|
+
case 'Property':
|
|
75
|
+
return this.mapProperty(node);
|
|
33
76
|
|
|
34
|
-
|
|
77
|
+
case 'MethodDefinition':
|
|
78
|
+
return this.mapMethodDefinition(node);
|
|
35
79
|
|
|
36
|
-
|
|
80
|
+
case 'ImportDeclaration':
|
|
81
|
+
return this.mapImportDeclaration(node);
|
|
37
82
|
|
|
38
|
-
|
|
83
|
+
case 'ImportSpecifier':
|
|
84
|
+
return this.mapImportSpecifier(node);
|
|
39
85
|
|
|
40
|
-
|
|
86
|
+
case 'ExportDefaultDeclaration':
|
|
87
|
+
return this.mapExportDefaultDeclaration(node);
|
|
41
88
|
|
|
42
|
-
|
|
89
|
+
case 'ExportNamedDeclaration':
|
|
90
|
+
return this.mapExportNamedDeclaration(node);
|
|
43
91
|
|
|
44
|
-
|
|
92
|
+
case 'ExportAllDeclaration':
|
|
93
|
+
return this.mapExportAllDeclaration(node);
|
|
45
94
|
|
|
46
|
-
|
|
47
|
-
|
|
95
|
+
case 'RestElement':
|
|
96
|
+
return this.mapRestElement(node);
|
|
48
97
|
|
|
49
|
-
|
|
98
|
+
case 'ImportExpression':
|
|
99
|
+
return this.mapImportExpression(node);
|
|
50
100
|
|
|
51
|
-
|
|
52
|
-
|
|
101
|
+
case 'JSXStringLiteral':
|
|
102
|
+
return this.mapJSXStringLiteral(node);
|
|
53
103
|
|
|
54
|
-
|
|
55
|
-
|
|
104
|
+
case 'PrivateName':
|
|
105
|
+
case 'ClassPrivateProperty':
|
|
106
|
+
return this.mapPrivateProperty(node);
|
|
56
107
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var _this$sourceFilename;
|
|
108
|
+
case 'FunctionDeclaration':
|
|
109
|
+
case 'FunctionExpression':
|
|
110
|
+
return this.mapFunction(node);
|
|
61
111
|
|
|
62
|
-
|
|
112
|
+
case 'IndexedAccessType':
|
|
113
|
+
case 'OptionalIndexedAccessType':
|
|
114
|
+
return this.mapUnsupportedTypeAnnotation(node);
|
|
63
115
|
|
|
64
|
-
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
node.loc = {
|
|
69
|
-
source: (_this$sourceFilename = this.sourceFilename) !== null && _this$sourceFilename !== void 0 ? _this$sourceFilename : null,
|
|
70
|
-
start: loc.start,
|
|
71
|
-
end: loc.end
|
|
72
|
-
};
|
|
73
|
-
node.start = loc.rangeStart;
|
|
74
|
-
node.end = loc.rangeEnd;
|
|
116
|
+
default:
|
|
117
|
+
return this.mapNodeDefault(node);
|
|
75
118
|
}
|
|
76
|
-
}
|
|
77
|
-
key: "mapNode",
|
|
78
|
-
value: function mapNode(node) {
|
|
79
|
-
this.fixSourceLocation(node);
|
|
80
|
-
|
|
81
|
-
switch (node.type) {
|
|
82
|
-
case 'Program':
|
|
83
|
-
return this.mapProgram(node);
|
|
84
|
-
|
|
85
|
-
case 'BlockStatement':
|
|
86
|
-
return this.mapNodeWithDirectives(node);
|
|
87
|
-
|
|
88
|
-
case 'Empty':
|
|
89
|
-
return this.mapEmpty(node);
|
|
90
|
-
|
|
91
|
-
case 'Identifier':
|
|
92
|
-
return this.mapIdentifier(node);
|
|
93
|
-
|
|
94
|
-
case 'TemplateElement':
|
|
95
|
-
return this.mapTemplateElement(node);
|
|
96
|
-
|
|
97
|
-
case 'GenericTypeAnnotation':
|
|
98
|
-
return this.mapGenericTypeAnnotation(node);
|
|
119
|
+
}
|
|
99
120
|
|
|
100
|
-
|
|
101
|
-
|
|
121
|
+
mapProgram(node) {
|
|
122
|
+
// Visit child nodes and convert to directives
|
|
123
|
+
const {
|
|
124
|
+
comments,
|
|
125
|
+
...program
|
|
126
|
+
} = this.mapNodeWithDirectives(node);
|
|
127
|
+
program.sourceType = this.getSourceType(); // Adjust start loc to beginning of file
|
|
128
|
+
|
|
129
|
+
program.loc.start = {
|
|
130
|
+
line: 1,
|
|
131
|
+
column: 0
|
|
132
|
+
};
|
|
133
|
+
program.start = 0; // Adjust end loc to include last comment if program ends with a comment
|
|
134
|
+
|
|
135
|
+
if (comments.length > 0) {
|
|
136
|
+
const lastComment = comments[comments.length - 1];
|
|
137
|
+
|
|
138
|
+
if (lastComment.end > program.end) {
|
|
139
|
+
program.loc.end = lastComment.loc.end;
|
|
140
|
+
program.end = lastComment.end;
|
|
141
|
+
}
|
|
142
|
+
} // Rename root node to File node and move Program node under program property
|
|
102
143
|
|
|
103
|
-
case 'Property':
|
|
104
|
-
return this.mapProperty(node);
|
|
105
144
|
|
|
106
|
-
|
|
107
|
-
|
|
145
|
+
return {
|
|
146
|
+
type: 'File',
|
|
147
|
+
loc: program.loc,
|
|
148
|
+
start: program.start,
|
|
149
|
+
end: program.end,
|
|
150
|
+
program,
|
|
151
|
+
comments
|
|
152
|
+
};
|
|
153
|
+
}
|
|
108
154
|
|
|
109
|
-
|
|
110
|
-
|
|
155
|
+
mapNodeWithDirectives(node) {
|
|
156
|
+
const directives = [];
|
|
111
157
|
|
|
112
|
-
|
|
113
|
-
|
|
158
|
+
for (const child of node.body) {
|
|
159
|
+
if (child.type === 'ExpressionStatement' && child.directive != null) {
|
|
160
|
+
// Visit directive children
|
|
161
|
+
const directiveChild = this.mapNode(child); // Modify string literal node to be DirectiveLiteral node
|
|
114
162
|
|
|
115
|
-
|
|
116
|
-
return this.mapExportDefaultDeclaration(node);
|
|
163
|
+
directiveChild.expression.type = 'DirectiveLiteral'; // Construct Directive node with DirectiveLiteral value
|
|
117
164
|
|
|
118
|
-
|
|
119
|
-
|
|
165
|
+
directives.push({
|
|
166
|
+
type: 'Directive',
|
|
167
|
+
loc: directiveChild.loc,
|
|
168
|
+
start: directiveChild.start,
|
|
169
|
+
end: directiveChild.end,
|
|
170
|
+
value: directiveChild.expression
|
|
171
|
+
});
|
|
172
|
+
} else {
|
|
173
|
+
// Once we have found the first non-directive node we know there cannot be any more directives
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
} // Move directives from body to new directives array
|
|
120
177
|
|
|
121
|
-
case 'ExportAllDeclaration':
|
|
122
|
-
return this.mapExportAllDeclaration(node);
|
|
123
178
|
|
|
124
|
-
|
|
125
|
-
return this.mapRestElement(node);
|
|
179
|
+
node.directives = directives;
|
|
126
180
|
|
|
127
|
-
|
|
128
|
-
|
|
181
|
+
if (directives.length !== 0) {
|
|
182
|
+
node.body = node.body.slice(directives.length);
|
|
183
|
+
} // Visit expression statement children
|
|
129
184
|
|
|
130
|
-
case 'PrivateName':
|
|
131
|
-
case 'ClassPrivateProperty':
|
|
132
|
-
return this.mapPrivateProperty(node);
|
|
133
185
|
|
|
134
|
-
|
|
135
|
-
case 'FunctionExpression':
|
|
136
|
-
return this.mapFunction(node);
|
|
186
|
+
const body = node.body;
|
|
137
187
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return this.mapUnsupportedTypeAnnotation(node);
|
|
188
|
+
for (let i = 0; i < body.length; i++) {
|
|
189
|
+
const child = body[i];
|
|
141
190
|
|
|
142
|
-
|
|
143
|
-
|
|
191
|
+
if (child != null) {
|
|
192
|
+
body[i] = this.mapNode(child);
|
|
144
193
|
}
|
|
145
194
|
}
|
|
146
|
-
}, {
|
|
147
|
-
key: "mapProgram",
|
|
148
|
-
value: function mapProgram(node) {
|
|
149
|
-
// Visit child nodes and convert to directives
|
|
150
|
-
var _this$mapNodeWithDire = this.mapNodeWithDirectives(node),
|
|
151
|
-
comments = _this$mapNodeWithDire.comments,
|
|
152
|
-
program = _objectWithoutProperties(_this$mapNodeWithDire, _excluded);
|
|
153
|
-
|
|
154
|
-
program.sourceType = this.getSourceType(); // Adjust start loc to beginning of file
|
|
155
|
-
|
|
156
|
-
program.loc.start = {
|
|
157
|
-
line: 1,
|
|
158
|
-
column: 0
|
|
159
|
-
};
|
|
160
|
-
program.start = 0; // Adjust end loc to include last comment if program ends with a comment
|
|
161
|
-
|
|
162
|
-
if (comments.length > 0) {
|
|
163
|
-
var lastComment = comments[comments.length - 1];
|
|
164
|
-
|
|
165
|
-
if (lastComment.end > program.end) {
|
|
166
|
-
program.loc.end = lastComment.loc.end;
|
|
167
|
-
program.end = lastComment.end;
|
|
168
|
-
}
|
|
169
|
-
} // Rename root node to File node and move Program node under program property
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return {
|
|
173
|
-
type: 'File',
|
|
174
|
-
loc: program.loc,
|
|
175
|
-
start: program.start,
|
|
176
|
-
end: program.end,
|
|
177
|
-
program: program,
|
|
178
|
-
comments: comments
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
}, {
|
|
182
|
-
key: "mapNodeWithDirectives",
|
|
183
|
-
value: function mapNodeWithDirectives(node) {
|
|
184
|
-
var directives = [];
|
|
185
|
-
|
|
186
|
-
var _iterator = _createForOfIteratorHelper(node.body),
|
|
187
|
-
_step;
|
|
188
|
-
|
|
189
|
-
try {
|
|
190
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
191
|
-
var _child = _step.value;
|
|
192
|
-
|
|
193
|
-
if (_child.type === 'ExpressionStatement' && _child.directive != null) {
|
|
194
|
-
// Visit directive children
|
|
195
|
-
var directiveChild = this.mapNode(_child); // Modify string literal node to be DirectiveLiteral node
|
|
196
|
-
|
|
197
|
-
directiveChild.expression.type = 'DirectiveLiteral'; // Construct Directive node with DirectiveLiteral value
|
|
198
|
-
|
|
199
|
-
directives.push({
|
|
200
|
-
type: 'Directive',
|
|
201
|
-
loc: directiveChild.loc,
|
|
202
|
-
start: directiveChild.start,
|
|
203
|
-
end: directiveChild.end,
|
|
204
|
-
value: directiveChild.expression
|
|
205
|
-
});
|
|
206
|
-
} else {
|
|
207
|
-
// Once we have found the first non-directive node we know there cannot be any more directives
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
} // Move directives from body to new directives array
|
|
211
|
-
|
|
212
|
-
} catch (err) {
|
|
213
|
-
_iterator.e(err);
|
|
214
|
-
} finally {
|
|
215
|
-
_iterator.f();
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
node.directives = directives;
|
|
219
|
-
|
|
220
|
-
if (directives.length !== 0) {
|
|
221
|
-
node.body = node.body.slice(directives.length);
|
|
222
|
-
} // Visit expression statement children
|
|
223
195
|
|
|
196
|
+
return node;
|
|
197
|
+
}
|
|
224
198
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
199
|
+
mapIdentifier(node) {
|
|
200
|
+
node.loc.identifierName = node.name;
|
|
201
|
+
return this.mapNodeDefault(node);
|
|
202
|
+
}
|
|
229
203
|
|
|
230
|
-
|
|
231
|
-
|
|
204
|
+
mapTemplateElement(node) {
|
|
205
|
+
// Adjust start loc to exclude "`" at beginning of template literal if this is the first quasi,
|
|
206
|
+
// otherwise exclude "}" from previous expression.
|
|
207
|
+
const startCharsToExclude = 1; // Adjust end loc to exclude "`" at end of template literal if this is the last quasi,
|
|
208
|
+
// otherwise exclude "${" from next expression.
|
|
209
|
+
|
|
210
|
+
const endCharsToExclude = node.tail ? 1 : 2;
|
|
211
|
+
return {
|
|
212
|
+
type: 'TemplateElement',
|
|
213
|
+
loc: {
|
|
214
|
+
start: {
|
|
215
|
+
line: node.loc.start.line,
|
|
216
|
+
column: node.loc.start.column + startCharsToExclude
|
|
217
|
+
},
|
|
218
|
+
end: {
|
|
219
|
+
line: node.loc.end.line,
|
|
220
|
+
column: node.loc.end.column - endCharsToExclude
|
|
232
221
|
}
|
|
222
|
+
},
|
|
223
|
+
start: node.start + startCharsToExclude,
|
|
224
|
+
end: node.end - endCharsToExclude,
|
|
225
|
+
tail: node.tail,
|
|
226
|
+
value: {
|
|
227
|
+
cooked: node.cooked,
|
|
228
|
+
raw: node.raw
|
|
233
229
|
}
|
|
230
|
+
};
|
|
231
|
+
}
|
|
234
232
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
key: "mapIdentifier",
|
|
239
|
-
value: function mapIdentifier(node) {
|
|
240
|
-
node.loc.identifierName = node.name;
|
|
241
|
-
return this.mapNodeDefault(node);
|
|
242
|
-
}
|
|
243
|
-
}, {
|
|
244
|
-
key: "mapTemplateElement",
|
|
245
|
-
value: function mapTemplateElement(node) {
|
|
246
|
-
// Adjust start loc to exclude "`" at beginning of template literal if this is the first quasi,
|
|
247
|
-
// otherwise exclude "}" from previous expression.
|
|
248
|
-
var startCharsToExclude = 1; // Adjust end loc to exclude "`" at end of template literal if this is the last quasi,
|
|
249
|
-
// otherwise exclude "${" from next expression.
|
|
250
|
-
|
|
251
|
-
var endCharsToExclude = node.tail ? 1 : 2;
|
|
233
|
+
mapGenericTypeAnnotation(node) {
|
|
234
|
+
// Convert simple `this` generic type to ThisTypeAnnotation
|
|
235
|
+
if (node.typeParameters == null && node.id.type === 'Identifier' && node.id.name === 'this') {
|
|
252
236
|
return {
|
|
253
|
-
type: '
|
|
254
|
-
loc:
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
column: node.loc.start.column + startCharsToExclude
|
|
258
|
-
},
|
|
259
|
-
end: {
|
|
260
|
-
line: node.loc.end.line,
|
|
261
|
-
column: node.loc.end.column - endCharsToExclude
|
|
262
|
-
}
|
|
263
|
-
},
|
|
264
|
-
start: node.start + startCharsToExclude,
|
|
265
|
-
end: node.end - endCharsToExclude,
|
|
266
|
-
tail: node.tail,
|
|
267
|
-
value: {
|
|
268
|
-
cooked: node.cooked,
|
|
269
|
-
raw: node.raw
|
|
270
|
-
}
|
|
237
|
+
type: 'ThisTypeAnnotation',
|
|
238
|
+
loc: node.loc,
|
|
239
|
+
start: node.start,
|
|
240
|
+
end: node.end
|
|
271
241
|
};
|
|
272
242
|
}
|
|
273
|
-
}, {
|
|
274
|
-
key: "mapGenericTypeAnnotation",
|
|
275
|
-
value: function mapGenericTypeAnnotation(node) {
|
|
276
|
-
// Convert simple `this` generic type to ThisTypeAnnotation
|
|
277
|
-
if (node.typeParameters === null && node.id.type === 'Identifier' && node.id.name === 'this') {
|
|
278
|
-
return {
|
|
279
|
-
type: 'ThisTypeAnnotation',
|
|
280
|
-
loc: node.loc,
|
|
281
|
-
start: node.start,
|
|
282
|
-
end: node.end
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
243
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
244
|
+
return this.mapNodeDefault(node);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
mapSymbolTypeAnnotation(node) {
|
|
248
|
+
return {
|
|
249
|
+
type: 'GenericTypeAnnotation',
|
|
250
|
+
loc: node.loc,
|
|
251
|
+
start: node.start,
|
|
252
|
+
end: node.end,
|
|
253
|
+
id: {
|
|
254
|
+
type: 'Identifier',
|
|
293
255
|
loc: node.loc,
|
|
294
256
|
start: node.start,
|
|
295
257
|
end: node.end,
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
generator = value.generator,
|
|
320
|
-
returnType = value.returnType,
|
|
321
|
-
typeParameters = value.typeParameters,
|
|
322
|
-
predicate = value.predicate;
|
|
323
|
-
return {
|
|
324
|
-
type: 'ObjectMethod',
|
|
325
|
-
loc: node.loc,
|
|
326
|
-
start: node.start,
|
|
327
|
-
end: node.end,
|
|
328
|
-
// Non getter or setter methods have `kind = method`
|
|
329
|
-
kind: node.kind === 'init' ? 'method' : node.kind,
|
|
330
|
-
computed: node.computed,
|
|
331
|
-
key: key,
|
|
332
|
-
id: id,
|
|
333
|
-
params: params,
|
|
334
|
-
body: body,
|
|
335
|
-
async: async,
|
|
336
|
-
generator: generator,
|
|
337
|
-
returnType: returnType,
|
|
338
|
-
typeParameters: typeParameters,
|
|
339
|
-
predicate: predicate
|
|
340
|
-
};
|
|
341
|
-
} else {
|
|
342
|
-
// Non-method property nodes should be renamed to ObjectProperty
|
|
343
|
-
node.type = 'ObjectProperty';
|
|
344
|
-
return node;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}, {
|
|
348
|
-
key: "mapMethodDefinition",
|
|
349
|
-
value: function mapMethodDefinition(node) {
|
|
350
|
-
var key = this.mapNode(node.key);
|
|
351
|
-
var value = this.mapNode(node.value); // Properties under the FunctionExpression value that should be moved
|
|
352
|
-
// to the ClassMethod node itself.
|
|
353
|
-
|
|
354
|
-
var id = value.id,
|
|
355
|
-
params = value.params,
|
|
356
|
-
body = value.body,
|
|
357
|
-
async = value.async,
|
|
358
|
-
generator = value.generator,
|
|
359
|
-
returnType = value.returnType,
|
|
360
|
-
typeParameters = value.typeParameters,
|
|
361
|
-
predicate = value.predicate;
|
|
258
|
+
name: 'symbol'
|
|
259
|
+
},
|
|
260
|
+
typeParameters: null
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
mapProperty(node) {
|
|
265
|
+
const key = this.mapNode(node.key);
|
|
266
|
+
const value = this.mapNode(node.value); // Convert methods, getters, and setters to ObjectMethod nodes
|
|
267
|
+
|
|
268
|
+
if (node.method || node.kind !== 'init') {
|
|
269
|
+
// Properties under the FunctionExpression value that should be moved
|
|
270
|
+
// to the ObjectMethod node itself.
|
|
271
|
+
const {
|
|
272
|
+
id,
|
|
273
|
+
params,
|
|
274
|
+
body,
|
|
275
|
+
async,
|
|
276
|
+
generator,
|
|
277
|
+
returnType,
|
|
278
|
+
typeParameters,
|
|
279
|
+
predicate
|
|
280
|
+
} = value;
|
|
362
281
|
return {
|
|
363
|
-
type: '
|
|
282
|
+
type: 'ObjectMethod',
|
|
364
283
|
loc: node.loc,
|
|
365
284
|
start: node.start,
|
|
366
285
|
end: node.end,
|
|
367
|
-
kind
|
|
286
|
+
// Non getter or setter methods have `kind = method`
|
|
287
|
+
kind: node.kind === 'init' ? 'method' : node.kind,
|
|
368
288
|
computed: node.computed,
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
predicate: predicate
|
|
289
|
+
key,
|
|
290
|
+
id,
|
|
291
|
+
params,
|
|
292
|
+
body,
|
|
293
|
+
async,
|
|
294
|
+
generator,
|
|
295
|
+
returnType,
|
|
296
|
+
typeParameters,
|
|
297
|
+
predicate
|
|
379
298
|
};
|
|
299
|
+
} else {
|
|
300
|
+
// Non-method property nodes should be renamed to ObjectProperty
|
|
301
|
+
node.type = 'ObjectProperty';
|
|
302
|
+
return node;
|
|
380
303
|
}
|
|
381
|
-
}
|
|
382
|
-
key: "mapRestElement",
|
|
383
|
-
value: function mapRestElement(node) {
|
|
384
|
-
var restElement = this.mapNodeDefault(node); // Hermes puts type annotations on rest elements on the argument node,
|
|
385
|
-
// but Babel expects type annotations on the rest element node itself.
|
|
304
|
+
}
|
|
386
305
|
|
|
387
|
-
|
|
306
|
+
mapMethodDefinition(node) {
|
|
307
|
+
const key = this.mapNode(node.key);
|
|
308
|
+
const value = this.mapNode(node.value); // Properties under the FunctionExpression value that should be moved
|
|
309
|
+
// to the ClassMethod node itself.
|
|
310
|
+
|
|
311
|
+
const {
|
|
312
|
+
id,
|
|
313
|
+
params,
|
|
314
|
+
body,
|
|
315
|
+
async,
|
|
316
|
+
generator,
|
|
317
|
+
returnType,
|
|
318
|
+
typeParameters,
|
|
319
|
+
predicate
|
|
320
|
+
} = value;
|
|
321
|
+
return {
|
|
322
|
+
type: 'ClassMethod',
|
|
323
|
+
loc: node.loc,
|
|
324
|
+
start: node.start,
|
|
325
|
+
end: node.end,
|
|
326
|
+
kind: node.kind,
|
|
327
|
+
computed: node.computed,
|
|
328
|
+
static: node.static,
|
|
329
|
+
key,
|
|
330
|
+
id,
|
|
331
|
+
params,
|
|
332
|
+
body,
|
|
333
|
+
async,
|
|
334
|
+
generator,
|
|
335
|
+
returnType,
|
|
336
|
+
typeParameters,
|
|
337
|
+
predicate
|
|
338
|
+
};
|
|
339
|
+
}
|
|
388
340
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
}
|
|
341
|
+
mapRestElement(node) {
|
|
342
|
+
const restElement = this.mapNodeDefault(node); // Hermes puts type annotations on rest elements on the argument node,
|
|
343
|
+
// but Babel expects type annotations on the rest element node itself.
|
|
393
344
|
|
|
394
|
-
|
|
395
|
-
}
|
|
396
|
-
}, {
|
|
397
|
-
key: "mapImportExpression",
|
|
398
|
-
value: function mapImportExpression(node) {
|
|
399
|
-
// Babel expects ImportExpression to be structued as a regular
|
|
400
|
-
// CallExpression where the callee is an Import node.
|
|
401
|
-
return {
|
|
402
|
-
type: 'CallExpression',
|
|
403
|
-
loc: node.loc,
|
|
404
|
-
start: node.start,
|
|
405
|
-
end: node.end,
|
|
406
|
-
callee: {
|
|
407
|
-
type: 'Import',
|
|
408
|
-
loc: node.loc,
|
|
409
|
-
start: node.start,
|
|
410
|
-
end: node.end
|
|
411
|
-
},
|
|
412
|
-
arguments: [this.mapNode(node.source)]
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
}, {
|
|
416
|
-
key: "mapFunction",
|
|
417
|
-
value: function mapFunction(node) {
|
|
418
|
-
// Remove the first parameter if it is a this-type annotation,
|
|
419
|
-
// which is not recognized by Babel.
|
|
420
|
-
if (node.params.length !== 0 && node.params[0].name === 'this') {
|
|
421
|
-
node.params.shift();
|
|
422
|
-
}
|
|
345
|
+
const annotation = restElement.argument.typeAnnotation;
|
|
423
346
|
|
|
424
|
-
|
|
347
|
+
if (annotation != null) {
|
|
348
|
+
restElement.typeAnnotation = annotation;
|
|
349
|
+
restElement.argument.typeAnnotation = null;
|
|
425
350
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
351
|
+
|
|
352
|
+
return restElement;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
mapImportExpression(node) {
|
|
356
|
+
// Babel expects ImportExpression to be structued as a regular
|
|
357
|
+
// CallExpression where the callee is an Import node.
|
|
358
|
+
return {
|
|
359
|
+
type: 'CallExpression',
|
|
360
|
+
loc: node.loc,
|
|
361
|
+
start: node.start,
|
|
362
|
+
end: node.end,
|
|
363
|
+
callee: {
|
|
364
|
+
type: 'Import',
|
|
436
365
|
loc: node.loc,
|
|
437
366
|
start: node.start,
|
|
438
367
|
end: node.end
|
|
439
|
-
}
|
|
368
|
+
},
|
|
369
|
+
arguments: [this.mapNode(node.source)]
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
mapJSXStringLiteral(node) {
|
|
374
|
+
// Babel expects StringLiterals in JSX,
|
|
375
|
+
// but Hermes uses JSXStringLiteral to attach the raw value without
|
|
376
|
+
// having to internally attach it to every single string literal.
|
|
377
|
+
return {
|
|
378
|
+
type: 'StringLiteral',
|
|
379
|
+
loc: node.loc,
|
|
380
|
+
start: node.start,
|
|
381
|
+
end: node.end,
|
|
382
|
+
value: node.value
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
mapFunction(node) {
|
|
387
|
+
// Remove the first parameter if it is a this-type annotation,
|
|
388
|
+
// which is not recognized by Babel.
|
|
389
|
+
if (node.params.length !== 0 && node.params[0].name === 'this') {
|
|
390
|
+
node.params.shift();
|
|
440
391
|
}
|
|
441
|
-
}]);
|
|
442
392
|
|
|
443
|
-
|
|
444
|
-
}
|
|
393
|
+
return this.mapNodeDefault(node);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* If Babel (the version we target) does not support a type annotation we
|
|
397
|
+
* parse, we need to return some other valid type annotation in its place.
|
|
398
|
+
*/
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
mapUnsupportedTypeAnnotation(node) {
|
|
402
|
+
return {
|
|
403
|
+
type: 'AnyTypeAnnotation',
|
|
404
|
+
loc: node.loc,
|
|
405
|
+
start: node.start,
|
|
406
|
+
end: node.end
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
}
|
|
445
411
|
|
|
446
|
-
exports
|
|
412
|
+
exports.default = HermesToBabelAdapter;
|