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.
|
|
@@ -7,17 +7,22 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
+
// lint directives to let us do some basic validation of generated files
|
|
11
|
+
|
|
12
|
+
/* eslint no-undef: 'error', no-unused-vars: ['error', {vars: "local"}], no-redeclare: 'error' */
|
|
13
|
+
|
|
14
|
+
/* global $NonMaybeType, $Partial, $ReadOnly, $ReadOnlyArray */
|
|
10
15
|
'use strict';
|
|
11
16
|
|
|
12
17
|
Object.defineProperty(exports, "__esModule", {
|
|
13
18
|
value: true
|
|
14
19
|
});
|
|
15
20
|
exports.NODE_LIST_CHILD = exports.NODE_CHILD = exports.HERMES_AST_VISITOR_KEYS = void 0;
|
|
16
|
-
|
|
21
|
+
const NODE_CHILD = 'Node';
|
|
17
22
|
exports.NODE_CHILD = NODE_CHILD;
|
|
18
|
-
|
|
23
|
+
const NODE_LIST_CHILD = 'NodeList';
|
|
19
24
|
exports.NODE_LIST_CHILD = NODE_LIST_CHILD;
|
|
20
|
-
|
|
25
|
+
const HERMES_AST_VISITOR_KEYS = {
|
|
21
26
|
AnyTypeAnnotation: {},
|
|
22
27
|
ArrayExpression: {
|
|
23
28
|
elements: 'NodeList'
|
|
@@ -48,6 +53,8 @@ var HERMES_AST_VISITOR_KEYS = {
|
|
|
48
53
|
AwaitExpression: {
|
|
49
54
|
argument: 'Node'
|
|
50
55
|
},
|
|
56
|
+
BigIntLiteral: {},
|
|
57
|
+
BigIntLiteralTypeAnnotation: {},
|
|
51
58
|
BinaryExpression: {
|
|
52
59
|
left: 'Node',
|
|
53
60
|
right: 'Node'
|
|
@@ -78,7 +85,7 @@ var HERMES_AST_VISITOR_KEYS = {
|
|
|
78
85
|
typeParameters: 'Node',
|
|
79
86
|
superClass: 'Node',
|
|
80
87
|
superTypeParameters: 'Node',
|
|
81
|
-
|
|
88
|
+
implements: 'NodeList',
|
|
82
89
|
decorators: 'NodeList',
|
|
83
90
|
body: 'Node'
|
|
84
91
|
},
|
|
@@ -87,7 +94,7 @@ var HERMES_AST_VISITOR_KEYS = {
|
|
|
87
94
|
typeParameters: 'Node',
|
|
88
95
|
superClass: 'Node',
|
|
89
96
|
superTypeParameters: 'Node',
|
|
90
|
-
|
|
97
|
+
implements: 'NodeList',
|
|
91
98
|
decorators: 'NodeList',
|
|
92
99
|
body: 'Node'
|
|
93
100
|
},
|
|
@@ -119,8 +126,8 @@ var HERMES_AST_VISITOR_KEYS = {
|
|
|
119
126
|
DeclareClass: {
|
|
120
127
|
id: 'Node',
|
|
121
128
|
typeParameters: 'Node',
|
|
122
|
-
|
|
123
|
-
|
|
129
|
+
extends: 'NodeList',
|
|
130
|
+
implements: 'NodeList',
|
|
124
131
|
mixins: 'NodeList',
|
|
125
132
|
body: 'Node'
|
|
126
133
|
},
|
|
@@ -142,7 +149,7 @@ var HERMES_AST_VISITOR_KEYS = {
|
|
|
142
149
|
DeclareInterface: {
|
|
143
150
|
id: 'Node',
|
|
144
151
|
typeParameters: 'Node',
|
|
145
|
-
|
|
152
|
+
extends: 'NodeList',
|
|
146
153
|
body: 'Node'
|
|
147
154
|
},
|
|
148
155
|
DeclareModule: {
|
|
@@ -259,7 +266,7 @@ var HERMES_AST_VISITOR_KEYS = {
|
|
|
259
266
|
},
|
|
260
267
|
FunctionTypeAnnotation: {
|
|
261
268
|
params: 'NodeList',
|
|
262
|
-
|
|
269
|
+
this: 'Node',
|
|
263
270
|
returnType: 'Node',
|
|
264
271
|
rest: 'Node',
|
|
265
272
|
typeParameters: 'Node'
|
|
@@ -311,7 +318,7 @@ var HERMES_AST_VISITOR_KEYS = {
|
|
|
311
318
|
InterfaceDeclaration: {
|
|
312
319
|
id: 'Node',
|
|
313
320
|
typeParameters: 'Node',
|
|
314
|
-
|
|
321
|
+
extends: 'NodeList',
|
|
315
322
|
body: 'Node'
|
|
316
323
|
},
|
|
317
324
|
InterfaceExtends: {
|
|
@@ -319,7 +326,7 @@ var HERMES_AST_VISITOR_KEYS = {
|
|
|
319
326
|
typeParameters: 'Node'
|
|
320
327
|
},
|
|
321
328
|
InterfaceTypeAnnotation: {
|
|
322
|
-
|
|
329
|
+
extends: 'NodeList',
|
|
323
330
|
body: 'Node'
|
|
324
331
|
},
|
|
325
332
|
IntersectionTypeAnnotation: {
|
|
@@ -535,7 +542,7 @@ var HERMES_AST_VISITOR_KEYS = {
|
|
|
535
542
|
TypeParameter: {
|
|
536
543
|
bound: 'Node',
|
|
537
544
|
variance: 'Node',
|
|
538
|
-
|
|
545
|
+
default: 'Node'
|
|
539
546
|
},
|
|
540
547
|
TypeParameterDeclaration: {
|
|
541
548
|
params: 'NodeList'
|
package/dist/index.js
CHANGED
|
@@ -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.
|
|
@@ -9,8 +9,6 @@
|
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
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); }
|
|
13
|
-
|
|
14
12
|
Object.defineProperty(exports, "__esModule", {
|
|
15
13
|
value: true
|
|
16
14
|
});
|
|
@@ -22,30 +20,23 @@ var _HermesToBabelAdapter = _interopRequireDefault(require("./HermesToBabelAdapt
|
|
|
22
20
|
|
|
23
21
|
var _HermesToESTreeAdapter = _interopRequireDefault(require("./HermesToESTreeAdapter"));
|
|
24
22
|
|
|
25
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : {
|
|
26
|
-
|
|
27
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
28
|
-
|
|
29
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
24
|
|
|
31
|
-
function
|
|
25
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
32
26
|
|
|
33
|
-
function
|
|
27
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
34
28
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var DEFAULTS = {
|
|
29
|
+
const DEFAULTS = {
|
|
38
30
|
flow: 'detect'
|
|
39
31
|
};
|
|
40
32
|
|
|
41
|
-
function getOptions(
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
function getOptions(options = { ...DEFAULTS
|
|
34
|
+
}) {
|
|
44
35
|
// Default to detecting whether to parse Flow syntax by the presence
|
|
45
36
|
// of an pragma.
|
|
46
37
|
if (options.flow == null) {
|
|
47
38
|
options.flow = DEFAULTS.flow;
|
|
48
|
-
} else if (options.flow
|
|
39
|
+
} else if (options.flow !== 'all' && options.flow !== 'detect') {
|
|
49
40
|
throw new Error('flow option must be "all" or "detect"');
|
|
50
41
|
}
|
|
51
42
|
|
|
@@ -62,14 +53,14 @@ function getOptions() {
|
|
|
62
53
|
}
|
|
63
54
|
|
|
64
55
|
function getAdapter(options, code) {
|
|
65
|
-
return options.babel === true ? new _HermesToBabelAdapter
|
|
56
|
+
return options.babel === true ? new _HermesToBabelAdapter.default(options) : new _HermesToESTreeAdapter.default(options, code);
|
|
66
57
|
} // $FlowExpectedError[unclear-type]
|
|
67
58
|
|
|
68
59
|
|
|
69
60
|
// eslint-disable-next-line no-redeclare
|
|
70
61
|
function parse(code, opts) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
const options = getOptions(opts);
|
|
63
|
+
const ast = HermesParser.parse(code, options);
|
|
64
|
+
const adapter = getAdapter(options, code);
|
|
74
65
|
return adapter.transform(ast);
|
|
75
66
|
}
|
package/dist/index.js.flow
CHANGED
|
@@ -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.
|
|
@@ -26,7 +26,7 @@ function getOptions(options?: ParserOptions = {...DEFAULTS}) {
|
|
|
26
26
|
// of an @flow pragma.
|
|
27
27
|
if (options.flow == null) {
|
|
28
28
|
options.flow = DEFAULTS.flow;
|
|
29
|
-
} else if (options.flow
|
|
29
|
+
} else if (options.flow !== 'all' && options.flow !== 'detect') {
|
|
30
30
|
throw new Error('flow option must be "all" or "detect"');
|
|
31
31
|
}
|
|
32
32
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hermes-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "A JavaScript parser built from the Hermes engine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
"url": "git@github.com:facebook/hermes.git"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"hermes-estree": "0.
|
|
12
|
+
"hermes-estree": "0.6.0"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"hermes-transform": "0.6.0"
|
|
13
16
|
},
|
|
14
17
|
"files": [
|
|
15
18
|
"dist"
|