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,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -73,6 +73,8 @@ export default class HermesToBabelAdapter extends HermesASTAdapter {
|
|
|
73
73
|
return this.mapRestElement(node);
|
|
74
74
|
case 'ImportExpression':
|
|
75
75
|
return this.mapImportExpression(node);
|
|
76
|
+
case 'JSXStringLiteral':
|
|
77
|
+
return this.mapJSXStringLiteral(node);
|
|
76
78
|
case 'PrivateName':
|
|
77
79
|
case 'ClassPrivateProperty':
|
|
78
80
|
return this.mapPrivateProperty(node);
|
|
@@ -198,7 +200,7 @@ export default class HermesToBabelAdapter extends HermesASTAdapter {
|
|
|
198
200
|
mapGenericTypeAnnotation(node: HermesNode): HermesNode {
|
|
199
201
|
// Convert simple `this` generic type to ThisTypeAnnotation
|
|
200
202
|
if (
|
|
201
|
-
node.typeParameters
|
|
203
|
+
node.typeParameters == null &&
|
|
202
204
|
node.id.type === 'Identifier' &&
|
|
203
205
|
node.id.name === 'this'
|
|
204
206
|
) {
|
|
@@ -343,6 +345,19 @@ export default class HermesToBabelAdapter extends HermesASTAdapter {
|
|
|
343
345
|
};
|
|
344
346
|
}
|
|
345
347
|
|
|
348
|
+
mapJSXStringLiteral(node: HermesNode): HermesNode {
|
|
349
|
+
// Babel expects StringLiterals in JSX,
|
|
350
|
+
// but Hermes uses JSXStringLiteral to attach the raw value without
|
|
351
|
+
// having to internally attach it to every single string literal.
|
|
352
|
+
return {
|
|
353
|
+
type: 'StringLiteral',
|
|
354
|
+
loc: node.loc,
|
|
355
|
+
start: node.start,
|
|
356
|
+
end: node.end,
|
|
357
|
+
value: node.value,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
|
|
346
361
|
mapFunction(node: HermesNode): HermesNode {
|
|
347
362
|
// Remove the first parameter if it is a this-type annotation,
|
|
348
363
|
// which is not recognized by Babel.
|
|
@@ -1,216 +1,237 @@
|
|
|
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
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : {
|
|
13
|
-
|
|
14
|
-
|
|
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 HermesToESTreeAdapter extends _HermesASTAdapter.default {
|
|
31
|
+
constructor(options, code) {
|
|
32
|
+
super(options);
|
|
33
|
+
this.code = void 0;
|
|
34
|
+
this.code = code;
|
|
35
|
+
}
|
|
15
36
|
|
|
16
|
-
|
|
37
|
+
fixSourceLocation(node) {
|
|
38
|
+
var _this$sourceFilename;
|
|
17
39
|
|
|
18
|
-
|
|
40
|
+
const loc = node.loc;
|
|
19
41
|
|
|
20
|
-
|
|
42
|
+
if (loc == null) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
21
45
|
|
|
22
|
-
|
|
46
|
+
node.loc = {
|
|
47
|
+
source: (_this$sourceFilename = this.sourceFilename) != null ? _this$sourceFilename : null,
|
|
48
|
+
start: loc.start,
|
|
49
|
+
end: loc.end
|
|
50
|
+
};
|
|
51
|
+
node.range = [loc.rangeStart, loc.rangeEnd];
|
|
52
|
+
}
|
|
23
53
|
|
|
24
|
-
|
|
54
|
+
mapNode(node) {
|
|
55
|
+
this.fixSourceLocation(node);
|
|
25
56
|
|
|
26
|
-
|
|
57
|
+
switch (node.type) {
|
|
58
|
+
case 'Program':
|
|
59
|
+
return this.mapProgram(node);
|
|
27
60
|
|
|
28
|
-
|
|
61
|
+
case 'NullLiteral':
|
|
62
|
+
return this.mapNullLiteral(node);
|
|
29
63
|
|
|
30
|
-
|
|
64
|
+
case 'BooleanLiteral':
|
|
65
|
+
case 'StringLiteral':
|
|
66
|
+
case 'NumericLiteral':
|
|
67
|
+
case 'JSXStringLiteral':
|
|
68
|
+
return this.mapSimpleLiteral(node);
|
|
31
69
|
|
|
32
|
-
|
|
70
|
+
case 'BigIntLiteral':
|
|
71
|
+
return this.mapBigIntLiteral(node);
|
|
33
72
|
|
|
34
|
-
|
|
73
|
+
case 'RegExpLiteral':
|
|
74
|
+
return this.mapRegExpLiteral(node);
|
|
35
75
|
|
|
36
|
-
|
|
37
|
-
|
|
76
|
+
case 'Empty':
|
|
77
|
+
return this.mapEmpty(node);
|
|
38
78
|
|
|
39
|
-
|
|
79
|
+
case 'TemplateElement':
|
|
80
|
+
return this.mapTemplateElement(node);
|
|
40
81
|
|
|
41
|
-
|
|
42
|
-
|
|
82
|
+
case 'BigIntLiteralTypeAnnotation':
|
|
83
|
+
return this.mapBigIntLiteralTypeAnnotation(node);
|
|
43
84
|
|
|
44
|
-
|
|
85
|
+
case 'GenericTypeAnnotation':
|
|
86
|
+
return this.mapGenericTypeAnnotation(node);
|
|
45
87
|
|
|
46
|
-
|
|
88
|
+
case 'ImportDeclaration':
|
|
89
|
+
return this.mapImportDeclaration(node);
|
|
47
90
|
|
|
48
|
-
|
|
91
|
+
case 'ImportSpecifier':
|
|
92
|
+
return this.mapImportSpecifier(node);
|
|
49
93
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
94
|
+
case 'ExportDefaultDeclaration':
|
|
95
|
+
return this.mapExportDefaultDeclaration(node);
|
|
53
96
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
value: function fixSourceLocation(node) {
|
|
57
|
-
var _this$sourceFilename;
|
|
97
|
+
case 'ExportNamedDeclaration':
|
|
98
|
+
return this.mapExportNamedDeclaration(node);
|
|
58
99
|
|
|
59
|
-
|
|
100
|
+
case 'ExportAllDeclaration':
|
|
101
|
+
return this.mapExportAllDeclaration(node);
|
|
60
102
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
103
|
+
case 'PrivateName':
|
|
104
|
+
case 'ClassPrivateProperty':
|
|
105
|
+
return this.mapPrivateProperty(node);
|
|
64
106
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
start: loc.start,
|
|
68
|
-
end: loc.end
|
|
69
|
-
};
|
|
70
|
-
node.range = [loc.rangeStart, loc.rangeEnd];
|
|
107
|
+
default:
|
|
108
|
+
return this.mapNodeDefault(node);
|
|
71
109
|
}
|
|
72
|
-
}
|
|
73
|
-
key: "mapNode",
|
|
74
|
-
value: function mapNode(node) {
|
|
75
|
-
this.fixSourceLocation(node);
|
|
76
|
-
|
|
77
|
-
switch (node.type) {
|
|
78
|
-
case 'Program':
|
|
79
|
-
return this.mapProgram(node);
|
|
80
|
-
|
|
81
|
-
case 'NullLiteral':
|
|
82
|
-
return this.mapNullLiteral(node);
|
|
83
|
-
|
|
84
|
-
case 'BooleanLiteral':
|
|
85
|
-
case 'StringLiteral':
|
|
86
|
-
case 'NumericLiteral':
|
|
87
|
-
return this.mapSimpleLiteral(node);
|
|
110
|
+
}
|
|
88
111
|
|
|
89
|
-
|
|
90
|
-
|
|
112
|
+
mapProgram(node) {
|
|
113
|
+
node = this.mapNodeDefault(node);
|
|
114
|
+
node.sourceType = this.getSourceType();
|
|
115
|
+
return node;
|
|
116
|
+
}
|
|
91
117
|
|
|
92
|
-
|
|
93
|
-
|
|
118
|
+
mapSimpleLiteral(node) {
|
|
119
|
+
return {
|
|
120
|
+
type: 'Literal',
|
|
121
|
+
loc: node.loc,
|
|
122
|
+
range: node.range,
|
|
123
|
+
value: node.value,
|
|
124
|
+
raw: this.code.slice(node.range[0], node.range[1]),
|
|
125
|
+
literalType: (() => {
|
|
126
|
+
switch (node.type) {
|
|
127
|
+
case 'NullLiteral':
|
|
128
|
+
return 'null';
|
|
129
|
+
|
|
130
|
+
case 'BooleanLiteral':
|
|
131
|
+
return 'boolean';
|
|
132
|
+
|
|
133
|
+
case 'StringLiteral':
|
|
134
|
+
case 'JSXStringLiteral':
|
|
135
|
+
return 'string';
|
|
136
|
+
|
|
137
|
+
case 'NumericLiteral':
|
|
138
|
+
return 'numeric';
|
|
139
|
+
|
|
140
|
+
case 'BigIntLiteral':
|
|
141
|
+
return 'bigint';
|
|
142
|
+
|
|
143
|
+
case 'RegExpLiteral':
|
|
144
|
+
return 'regexp';
|
|
145
|
+
}
|
|
94
146
|
|
|
95
|
-
|
|
96
|
-
|
|
147
|
+
return null;
|
|
148
|
+
})()
|
|
149
|
+
};
|
|
150
|
+
}
|
|
97
151
|
|
|
98
|
-
|
|
99
|
-
|
|
152
|
+
mapBigIntLiteral(node) {
|
|
153
|
+
const newNode = this.mapSimpleLiteral(node);
|
|
154
|
+
const bigint = node.bigint // estree spec is to not have a trailing `n` on this property
|
|
155
|
+
// https://github.com/estree/estree/blob/db962bb417a97effcfe9892f87fbb93c81a68584/es2020.md#bigintliteral
|
|
156
|
+
.replace(/n$/, '') // `BigInt` doesn't accept numeric separator and `bigint` property should not include numeric separator
|
|
157
|
+
.replace(/_/, '');
|
|
158
|
+
return { ...newNode,
|
|
159
|
+
// coerce the string to a bigint value if supported by the environment
|
|
160
|
+
value: typeof BigInt === 'function' ? BigInt(bigint) : null,
|
|
161
|
+
bigint
|
|
162
|
+
};
|
|
163
|
+
}
|
|
100
164
|
|
|
101
|
-
|
|
102
|
-
|
|
165
|
+
mapNullLiteral(node) {
|
|
166
|
+
return { ...this.mapSimpleLiteral(node),
|
|
167
|
+
value: null
|
|
168
|
+
};
|
|
169
|
+
}
|
|
103
170
|
|
|
104
|
-
|
|
105
|
-
|
|
171
|
+
mapRegExpLiteral(node) {
|
|
172
|
+
const {
|
|
173
|
+
pattern,
|
|
174
|
+
flags
|
|
175
|
+
} = node; // Create RegExp value if possible. This can fail when the flags are invalid.
|
|
106
176
|
|
|
107
|
-
|
|
108
|
-
return this.mapExportDefaultDeclaration(node);
|
|
177
|
+
let value;
|
|
109
178
|
|
|
110
|
-
|
|
111
|
-
|
|
179
|
+
try {
|
|
180
|
+
value = new RegExp(pattern, flags);
|
|
181
|
+
} catch (e) {
|
|
182
|
+
value = null;
|
|
183
|
+
}
|
|
112
184
|
|
|
113
|
-
|
|
114
|
-
|
|
185
|
+
return { ...this.mapSimpleLiteral(node),
|
|
186
|
+
value,
|
|
187
|
+
regex: {
|
|
188
|
+
pattern,
|
|
189
|
+
flags
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
115
193
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
194
|
+
mapBigIntLiteralTypeAnnotation(node) {
|
|
195
|
+
node.value = null;
|
|
196
|
+
return node;
|
|
197
|
+
}
|
|
119
198
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return node;
|
|
130
|
-
}
|
|
131
|
-
}, {
|
|
132
|
-
key: "mapSimpleLiteral",
|
|
133
|
-
value: function mapSimpleLiteral(node) {
|
|
134
|
-
node.type = 'Literal';
|
|
135
|
-
node.raw = this.code.slice(node.range[0], node.range[1]);
|
|
136
|
-
return node;
|
|
137
|
-
}
|
|
138
|
-
}, {
|
|
139
|
-
key: "mapNullLiteral",
|
|
140
|
-
value: function mapNullLiteral(node) {
|
|
141
|
-
node.type = 'Literal';
|
|
142
|
-
node.value = null;
|
|
143
|
-
node.raw = this.code.slice(node.range[0], node.range[1]);
|
|
144
|
-
return node;
|
|
145
|
-
}
|
|
146
|
-
}, {
|
|
147
|
-
key: "mapRegExpLiteral",
|
|
148
|
-
value: function mapRegExpLiteral(node) {
|
|
149
|
-
var pattern = node.pattern,
|
|
150
|
-
flags = node.flags; // Create RegExp value if possible. This can fail when the flags are invalid.
|
|
151
|
-
|
|
152
|
-
var value;
|
|
153
|
-
|
|
154
|
-
try {
|
|
155
|
-
value = new RegExp(pattern, flags);
|
|
156
|
-
} catch (e) {
|
|
157
|
-
value = null;
|
|
199
|
+
mapTemplateElement(node) {
|
|
200
|
+
return {
|
|
201
|
+
type: 'TemplateElement',
|
|
202
|
+
loc: node.loc,
|
|
203
|
+
range: node.range,
|
|
204
|
+
tail: node.tail,
|
|
205
|
+
value: {
|
|
206
|
+
cooked: node.cooked,
|
|
207
|
+
raw: node.raw
|
|
158
208
|
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
159
211
|
|
|
212
|
+
mapGenericTypeAnnotation(node) {
|
|
213
|
+
// Convert simple `this` generic type to ThisTypeAnnotation
|
|
214
|
+
if (node.typeParameters == null && node.id.type === 'Identifier' && node.id.name === 'this') {
|
|
160
215
|
return {
|
|
161
|
-
type: '
|
|
162
|
-
loc: node.loc,
|
|
163
|
-
range: node.range,
|
|
164
|
-
value: value,
|
|
165
|
-
raw: this.code.slice(node.range[0], node.range[1]),
|
|
166
|
-
regex: {
|
|
167
|
-
pattern: pattern,
|
|
168
|
-
flags: flags
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
}, {
|
|
173
|
-
key: "mapTemplateElement",
|
|
174
|
-
value: function mapTemplateElement(node) {
|
|
175
|
-
return {
|
|
176
|
-
type: 'TemplateElement',
|
|
216
|
+
type: 'ThisTypeAnnotation',
|
|
177
217
|
loc: node.loc,
|
|
178
|
-
range: node.range
|
|
179
|
-
tail: node.tail,
|
|
180
|
-
value: {
|
|
181
|
-
cooked: node.cooked,
|
|
182
|
-
raw: node.raw
|
|
183
|
-
}
|
|
218
|
+
range: node.range
|
|
184
219
|
};
|
|
185
220
|
}
|
|
186
|
-
}, {
|
|
187
|
-
key: "mapGenericTypeAnnotation",
|
|
188
|
-
value: function mapGenericTypeAnnotation(node) {
|
|
189
|
-
// Convert simple `this` generic type to ThisTypeAnnotation
|
|
190
|
-
if (node.typeParameters === null && node.id.type === 'Identifier' && node.id.name === 'this') {
|
|
191
|
-
return {
|
|
192
|
-
type: 'ThisTypeAnnotation',
|
|
193
|
-
loc: node.loc,
|
|
194
|
-
range: node.range
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
221
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}, {
|
|
201
|
-
key: "mapComment",
|
|
202
|
-
value: function mapComment(node) {
|
|
203
|
-
if (node.type === 'CommentBlock') {
|
|
204
|
-
node.type = 'Block';
|
|
205
|
-
} else if (node.type === 'CommentLine') {
|
|
206
|
-
node.type = 'Line';
|
|
207
|
-
}
|
|
222
|
+
return this.mapNodeDefault(node);
|
|
223
|
+
}
|
|
208
224
|
|
|
209
|
-
|
|
225
|
+
mapComment(node) {
|
|
226
|
+
if (node.type === 'CommentBlock') {
|
|
227
|
+
node.type = 'Block';
|
|
228
|
+
} else if (node.type === 'CommentLine') {
|
|
229
|
+
node.type = 'Line';
|
|
210
230
|
}
|
|
211
|
-
}]);
|
|
212
231
|
|
|
213
|
-
|
|
214
|
-
}
|
|
232
|
+
return node;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
}
|
|
215
236
|
|
|
216
|
-
exports
|
|
237
|
+
exports.default = HermesToESTreeAdapter;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -22,6 +22,8 @@ import type {ParserOptions} from './ParserOptions';
|
|
|
22
22
|
|
|
23
23
|
import HermesASTAdapter from './HermesASTAdapter';
|
|
24
24
|
|
|
25
|
+
declare var BigInt: ?(value: $FlowFixMe) => mixed;
|
|
26
|
+
|
|
25
27
|
export default class HermesToESTreeAdapter extends HermesASTAdapter {
|
|
26
28
|
+code: string;
|
|
27
29
|
|
|
@@ -55,13 +57,18 @@ export default class HermesToESTreeAdapter extends HermesASTAdapter {
|
|
|
55
57
|
case 'BooleanLiteral':
|
|
56
58
|
case 'StringLiteral':
|
|
57
59
|
case 'NumericLiteral':
|
|
60
|
+
case 'JSXStringLiteral':
|
|
58
61
|
return this.mapSimpleLiteral(node);
|
|
62
|
+
case 'BigIntLiteral':
|
|
63
|
+
return this.mapBigIntLiteral(node);
|
|
59
64
|
case 'RegExpLiteral':
|
|
60
65
|
return this.mapRegExpLiteral(node);
|
|
61
66
|
case 'Empty':
|
|
62
67
|
return this.mapEmpty(node);
|
|
63
68
|
case 'TemplateElement':
|
|
64
69
|
return this.mapTemplateElement(node);
|
|
70
|
+
case 'BigIntLiteralTypeAnnotation':
|
|
71
|
+
return this.mapBigIntLiteralTypeAnnotation(node);
|
|
65
72
|
case 'GenericTypeAnnotation':
|
|
66
73
|
return this.mapGenericTypeAnnotation(node);
|
|
67
74
|
case 'ImportDeclaration':
|
|
@@ -90,18 +97,59 @@ export default class HermesToESTreeAdapter extends HermesASTAdapter {
|
|
|
90
97
|
}
|
|
91
98
|
|
|
92
99
|
mapSimpleLiteral(node: HermesNode): HermesNode {
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
return {
|
|
101
|
+
type: 'Literal',
|
|
102
|
+
loc: node.loc,
|
|
103
|
+
range: node.range,
|
|
104
|
+
value: node.value,
|
|
105
|
+
raw: this.code.slice(node.range[0], node.range[1]),
|
|
106
|
+
literalType: (() => {
|
|
107
|
+
switch (node.type) {
|
|
108
|
+
case 'NullLiteral':
|
|
109
|
+
return 'null';
|
|
95
110
|
|
|
96
|
-
|
|
111
|
+
case 'BooleanLiteral':
|
|
112
|
+
return 'boolean';
|
|
113
|
+
|
|
114
|
+
case 'StringLiteral':
|
|
115
|
+
case 'JSXStringLiteral':
|
|
116
|
+
return 'string';
|
|
117
|
+
|
|
118
|
+
case 'NumericLiteral':
|
|
119
|
+
return 'numeric';
|
|
120
|
+
|
|
121
|
+
case 'BigIntLiteral':
|
|
122
|
+
return 'bigint';
|
|
123
|
+
|
|
124
|
+
case 'RegExpLiteral':
|
|
125
|
+
return 'regexp';
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
})(),
|
|
129
|
+
};
|
|
97
130
|
}
|
|
98
131
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
132
|
+
mapBigIntLiteral(node: HermesNode): HermesNode {
|
|
133
|
+
const newNode = this.mapSimpleLiteral(node);
|
|
134
|
+
const bigint = node.bigint
|
|
135
|
+
// estree spec is to not have a trailing `n` on this property
|
|
136
|
+
// https://github.com/estree/estree/blob/db962bb417a97effcfe9892f87fbb93c81a68584/es2020.md#bigintliteral
|
|
137
|
+
.replace(/n$/, '')
|
|
138
|
+
// `BigInt` doesn't accept numeric separator and `bigint` property should not include numeric separator
|
|
139
|
+
.replace(/_/, '');
|
|
140
|
+
return {
|
|
141
|
+
...newNode,
|
|
142
|
+
// coerce the string to a bigint value if supported by the environment
|
|
143
|
+
value: typeof BigInt === 'function' ? BigInt(bigint) : null,
|
|
144
|
+
bigint,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
103
147
|
|
|
104
|
-
|
|
148
|
+
mapNullLiteral(node: HermesNode): HermesNode {
|
|
149
|
+
return {
|
|
150
|
+
...this.mapSimpleLiteral(node),
|
|
151
|
+
value: null,
|
|
152
|
+
};
|
|
105
153
|
}
|
|
106
154
|
|
|
107
155
|
mapRegExpLiteral(node: HermesNode): HermesNode {
|
|
@@ -116,11 +164,8 @@ export default class HermesToESTreeAdapter extends HermesASTAdapter {
|
|
|
116
164
|
}
|
|
117
165
|
|
|
118
166
|
return {
|
|
119
|
-
|
|
120
|
-
loc: node.loc,
|
|
121
|
-
range: node.range,
|
|
167
|
+
...this.mapSimpleLiteral(node),
|
|
122
168
|
value,
|
|
123
|
-
raw: this.code.slice(node.range[0], node.range[1]),
|
|
124
169
|
regex: {
|
|
125
170
|
pattern,
|
|
126
171
|
flags,
|
|
@@ -128,6 +173,11 @@ export default class HermesToESTreeAdapter extends HermesASTAdapter {
|
|
|
128
173
|
};
|
|
129
174
|
}
|
|
130
175
|
|
|
176
|
+
mapBigIntLiteralTypeAnnotation(node: HermesNode): HermesNode {
|
|
177
|
+
node.value = null;
|
|
178
|
+
return node;
|
|
179
|
+
}
|
|
180
|
+
|
|
131
181
|
mapTemplateElement(node: HermesNode): HermesNode {
|
|
132
182
|
return {
|
|
133
183
|
type: 'TemplateElement',
|
|
@@ -144,7 +194,7 @@ export default class HermesToESTreeAdapter extends HermesASTAdapter {
|
|
|
144
194
|
mapGenericTypeAnnotation(node: HermesNode): HermesNode {
|
|
145
195
|
// Convert simple `this` generic type to ThisTypeAnnotation
|
|
146
196
|
if (
|
|
147
|
-
node.typeParameters
|
|
197
|
+
node.typeParameters == null &&
|
|
148
198
|
node.id.type === 'Identifier' &&
|
|
149
199
|
node.id.name === 'this'
|
|
150
200
|
) {
|