hermes-parser 0.4.8 → 0.5.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/dist/HermesAST.js.flow +56 -0
- package/dist/HermesASTAdapter.js +24 -25
- package/dist/HermesASTAdapter.js.flow +178 -0
- package/dist/HermesParser.js +35 -21
- package/dist/HermesParser.js.flow +123 -0
- package/dist/HermesParserDecodeUTF8String.js +9 -4
- package/dist/HermesParserDecodeUTF8String.js.flow +65 -0
- package/dist/HermesParserDeserializer.js +40 -13
- package/dist/HermesParserDeserializer.js.flow +260 -0
- package/dist/HermesParserNodeDeserializers.js +2 -1
- package/dist/HermesParserNodeDeserializers.js.flow +16 -0
- package/dist/HermesParserWASM.js +1 -1
- package/dist/HermesParserWASM.js.flow +75 -0
- package/dist/HermesToBabelAdapter.js +18 -17
- package/dist/HermesToBabelAdapter.js.flow +368 -0
- package/dist/HermesToESTreeAdapter.js +18 -14
- package/dist/HermesToESTreeAdapter.js.flow +170 -0
- package/dist/ParserOptions.js.flow +18 -0
- package/dist/generated/visitor-keys.js +598 -0
- package/dist/generated/visitor-keys.js.flow +17 -0
- package/dist/index.js +36 -14
- package/dist/index.js.flow +71 -12
- package/package.json +4 -1
- package/dist/HermesParserVisitorKeys.js +0 -729
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its 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
|
+
type INTENTIONAL_ANY = $FlowFixMe;
|
|
12
|
+
type JSType = 'number' | 'string' | 'array' | 'boolean';
|
|
13
|
+
type CBoolean = ?(number | boolean);
|
|
14
|
+
|
|
15
|
+
type HermesParserWASM = $ReadOnly<{
|
|
16
|
+
HEAP8: Int8Array,
|
|
17
|
+
HEAP16: Int16Array,
|
|
18
|
+
HEAP32: Int32Array,
|
|
19
|
+
HEAPU8: Uint8Array,
|
|
20
|
+
HEAPU16: Uint16Array,
|
|
21
|
+
HEAPU32: Uint32Array,
|
|
22
|
+
HEAPF32: Float32Array,
|
|
23
|
+
HEAPF64: Float64Array,
|
|
24
|
+
|
|
25
|
+
_malloc(size: number): number,
|
|
26
|
+
_free(ptr: number): void,
|
|
27
|
+
|
|
28
|
+
ccall(
|
|
29
|
+
ident: string,
|
|
30
|
+
returnType: JSType | null,
|
|
31
|
+
argTypes: $ReadOnlyArray<JSType>,
|
|
32
|
+
args: $ReadOnlyArray<
|
|
33
|
+
number | string | $ReadOnlyArray<INTENTIONAL_ANY> | boolean,
|
|
34
|
+
>,
|
|
35
|
+
opts?: $ReadOnly<{
|
|
36
|
+
async?: boolean | void,
|
|
37
|
+
}>,
|
|
38
|
+
): INTENTIONAL_ANY,
|
|
39
|
+
cwrap: {
|
|
40
|
+
(
|
|
41
|
+
'hermesParse',
|
|
42
|
+
'number',
|
|
43
|
+
['number', 'number', 'number', 'number', 'number'],
|
|
44
|
+
): (number, number, CBoolean, CBoolean, CBoolean) => number,
|
|
45
|
+
('hermesParseResult_free', 'void', ['number']): number => void,
|
|
46
|
+
('hermesParseResult_getError', 'string', ['number']): number => string,
|
|
47
|
+
('hermesParseResult_getErrorLine', 'number', ['number']): number => number,
|
|
48
|
+
(
|
|
49
|
+
'hermesParseResult_getErrorColumn',
|
|
50
|
+
'number',
|
|
51
|
+
['number'],
|
|
52
|
+
): number => number,
|
|
53
|
+
(
|
|
54
|
+
'hermesParseResult_getProgramBuffer',
|
|
55
|
+
'number',
|
|
56
|
+
['number'],
|
|
57
|
+
): number => number,
|
|
58
|
+
(
|
|
59
|
+
'hermesParseResult_getPositionBuffer',
|
|
60
|
+
'number',
|
|
61
|
+
['number'],
|
|
62
|
+
): number => number,
|
|
63
|
+
(
|
|
64
|
+
'hermesParseResult_getPositionBufferSize',
|
|
65
|
+
'number',
|
|
66
|
+
['number'],
|
|
67
|
+
): number => number,
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
stackAlloc(size: number): number,
|
|
71
|
+
stackSave(): number,
|
|
72
|
+
stackRestore(ptr: number): void,
|
|
73
|
+
}>;
|
|
74
|
+
|
|
75
|
+
declare module.exports: HermesParserWASM;
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its 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
|
-
* @format
|
|
8
|
-
*/
|
|
9
|
-
'use strict';
|
|
1
|
+
"use strict";
|
|
10
2
|
|
|
11
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); }
|
|
12
4
|
|
|
13
|
-
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _HermesASTAdapter2 = _interopRequireDefault(require("./HermesASTAdapter"));
|
|
11
|
+
|
|
12
|
+
var _excluded = ["comments"];
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
|
+
|
|
16
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
14
17
|
|
|
15
18
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
19
|
|
|
@@ -32,16 +35,14 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
|
|
|
32
35
|
|
|
33
36
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
34
37
|
|
|
35
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
38
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
36
39
|
|
|
37
40
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
38
41
|
|
|
39
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try {
|
|
42
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
40
43
|
|
|
41
44
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
42
45
|
|
|
43
|
-
var HermesASTAdapter = require('./HermesASTAdapter');
|
|
44
|
-
|
|
45
46
|
var HermesToBabelAdapter = /*#__PURE__*/function (_HermesASTAdapter) {
|
|
46
47
|
_inherits(HermesToBabelAdapter, _HermesASTAdapter);
|
|
47
48
|
|
|
@@ -148,7 +149,7 @@ var HermesToBabelAdapter = /*#__PURE__*/function (_HermesASTAdapter) {
|
|
|
148
149
|
// Visit child nodes and convert to directives
|
|
149
150
|
var _this$mapNodeWithDire = this.mapNodeWithDirectives(node),
|
|
150
151
|
comments = _this$mapNodeWithDire.comments,
|
|
151
|
-
program = _objectWithoutProperties(_this$mapNodeWithDire,
|
|
152
|
+
program = _objectWithoutProperties(_this$mapNodeWithDire, _excluded);
|
|
152
153
|
|
|
153
154
|
program.sourceType = this.getSourceType(); // Adjust start loc to beginning of file
|
|
154
155
|
|
|
@@ -440,6 +441,6 @@ var HermesToBabelAdapter = /*#__PURE__*/function (_HermesASTAdapter) {
|
|
|
440
441
|
}]);
|
|
441
442
|
|
|
442
443
|
return HermesToBabelAdapter;
|
|
443
|
-
}(
|
|
444
|
+
}(_HermesASTAdapter2["default"]);
|
|
444
445
|
|
|
445
|
-
|
|
446
|
+
exports["default"] = HermesToBabelAdapter;
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its 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
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
This class does some very "javascripty" things in the name of
|
|
13
|
+
performance which are ultimately impossible to soundly type.
|
|
14
|
+
|
|
15
|
+
So instead of adding strict types and a large number of suppression
|
|
16
|
+
comments, instead it is left untyped and subclasses are strictly
|
|
17
|
+
typed via a separate flow declaration file.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type {HermesNode} from './HermesAST';
|
|
21
|
+
|
|
22
|
+
import HermesASTAdapter from './HermesASTAdapter';
|
|
23
|
+
|
|
24
|
+
export default class HermesToBabelAdapter extends HermesASTAdapter {
|
|
25
|
+
fixSourceLocation(node: HermesNode): void {
|
|
26
|
+
const loc = node.loc;
|
|
27
|
+
if (loc == null) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
node.loc = {
|
|
32
|
+
source: this.sourceFilename ?? null,
|
|
33
|
+
start: loc.start,
|
|
34
|
+
end: loc.end,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
node.start = loc.rangeStart;
|
|
38
|
+
node.end = loc.rangeEnd;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
mapNode(node: HermesNode): HermesNode {
|
|
42
|
+
this.fixSourceLocation(node);
|
|
43
|
+
switch (node.type) {
|
|
44
|
+
case 'Program':
|
|
45
|
+
return this.mapProgram(node);
|
|
46
|
+
case 'BlockStatement':
|
|
47
|
+
return this.mapNodeWithDirectives(node);
|
|
48
|
+
case 'Empty':
|
|
49
|
+
return this.mapEmpty(node);
|
|
50
|
+
case 'Identifier':
|
|
51
|
+
return this.mapIdentifier(node);
|
|
52
|
+
case 'TemplateElement':
|
|
53
|
+
return this.mapTemplateElement(node);
|
|
54
|
+
case 'GenericTypeAnnotation':
|
|
55
|
+
return this.mapGenericTypeAnnotation(node);
|
|
56
|
+
case 'SymbolTypeAnnotation':
|
|
57
|
+
return this.mapSymbolTypeAnnotation(node);
|
|
58
|
+
case 'Property':
|
|
59
|
+
return this.mapProperty(node);
|
|
60
|
+
case 'MethodDefinition':
|
|
61
|
+
return this.mapMethodDefinition(node);
|
|
62
|
+
case 'ImportDeclaration':
|
|
63
|
+
return this.mapImportDeclaration(node);
|
|
64
|
+
case 'ImportSpecifier':
|
|
65
|
+
return this.mapImportSpecifier(node);
|
|
66
|
+
case 'ExportDefaultDeclaration':
|
|
67
|
+
return this.mapExportDefaultDeclaration(node);
|
|
68
|
+
case 'ExportNamedDeclaration':
|
|
69
|
+
return this.mapExportNamedDeclaration(node);
|
|
70
|
+
case 'ExportAllDeclaration':
|
|
71
|
+
return this.mapExportAllDeclaration(node);
|
|
72
|
+
case 'RestElement':
|
|
73
|
+
return this.mapRestElement(node);
|
|
74
|
+
case 'ImportExpression':
|
|
75
|
+
return this.mapImportExpression(node);
|
|
76
|
+
case 'PrivateName':
|
|
77
|
+
case 'ClassPrivateProperty':
|
|
78
|
+
return this.mapPrivateProperty(node);
|
|
79
|
+
case 'FunctionDeclaration':
|
|
80
|
+
case 'FunctionExpression':
|
|
81
|
+
return this.mapFunction(node);
|
|
82
|
+
case 'IndexedAccessType':
|
|
83
|
+
case 'OptionalIndexedAccessType':
|
|
84
|
+
return this.mapUnsupportedTypeAnnotation(node);
|
|
85
|
+
default:
|
|
86
|
+
return this.mapNodeDefault(node);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
mapProgram(node: HermesNode): HermesNode {
|
|
91
|
+
// Visit child nodes and convert to directives
|
|
92
|
+
const {comments, ...program} = this.mapNodeWithDirectives(node);
|
|
93
|
+
|
|
94
|
+
program.sourceType = this.getSourceType();
|
|
95
|
+
|
|
96
|
+
// Adjust start loc to beginning of file
|
|
97
|
+
program.loc.start = {line: 1, column: 0};
|
|
98
|
+
program.start = 0;
|
|
99
|
+
|
|
100
|
+
// Adjust end loc to include last comment if program ends with a comment
|
|
101
|
+
if (comments.length > 0) {
|
|
102
|
+
const lastComment = comments[comments.length - 1];
|
|
103
|
+
if (lastComment.end > program.end) {
|
|
104
|
+
program.loc.end = lastComment.loc.end;
|
|
105
|
+
program.end = lastComment.end;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Rename root node to File node and move Program node under program property
|
|
110
|
+
return {
|
|
111
|
+
type: 'File',
|
|
112
|
+
loc: program.loc,
|
|
113
|
+
start: program.start,
|
|
114
|
+
end: program.end,
|
|
115
|
+
program,
|
|
116
|
+
comments,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
mapNodeWithDirectives(node: HermesNode): HermesNode {
|
|
121
|
+
const directives = [];
|
|
122
|
+
for (const child of node.body) {
|
|
123
|
+
if (child.type === 'ExpressionStatement' && child.directive != null) {
|
|
124
|
+
// Visit directive children
|
|
125
|
+
const directiveChild = this.mapNode(child);
|
|
126
|
+
|
|
127
|
+
// Modify string literal node to be DirectiveLiteral node
|
|
128
|
+
directiveChild.expression.type = 'DirectiveLiteral';
|
|
129
|
+
|
|
130
|
+
// Construct Directive node with DirectiveLiteral value
|
|
131
|
+
directives.push({
|
|
132
|
+
type: 'Directive',
|
|
133
|
+
loc: directiveChild.loc,
|
|
134
|
+
start: directiveChild.start,
|
|
135
|
+
end: directiveChild.end,
|
|
136
|
+
value: directiveChild.expression,
|
|
137
|
+
});
|
|
138
|
+
} else {
|
|
139
|
+
// Once we have found the first non-directive node we know there cannot be any more directives
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Move directives from body to new directives array
|
|
145
|
+
node.directives = directives;
|
|
146
|
+
if (directives.length !== 0) {
|
|
147
|
+
node.body = node.body.slice(directives.length);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Visit expression statement children
|
|
151
|
+
const body = node.body;
|
|
152
|
+
for (let i = 0; i < body.length; i++) {
|
|
153
|
+
const child = body[i];
|
|
154
|
+
if (child != null) {
|
|
155
|
+
body[i] = this.mapNode(child);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return node;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
mapIdentifier(node: HermesNode): HermesNode {
|
|
163
|
+
node.loc.identifierName = node.name;
|
|
164
|
+
return this.mapNodeDefault(node);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
mapTemplateElement(node: HermesNode): HermesNode {
|
|
168
|
+
// Adjust start loc to exclude "`" at beginning of template literal if this is the first quasi,
|
|
169
|
+
// otherwise exclude "}" from previous expression.
|
|
170
|
+
const startCharsToExclude = 1;
|
|
171
|
+
|
|
172
|
+
// Adjust end loc to exclude "`" at end of template literal if this is the last quasi,
|
|
173
|
+
// otherwise exclude "${" from next expression.
|
|
174
|
+
const endCharsToExclude = node.tail ? 1 : 2;
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
type: 'TemplateElement',
|
|
178
|
+
loc: {
|
|
179
|
+
start: {
|
|
180
|
+
line: node.loc.start.line,
|
|
181
|
+
column: node.loc.start.column + startCharsToExclude,
|
|
182
|
+
},
|
|
183
|
+
end: {
|
|
184
|
+
line: node.loc.end.line,
|
|
185
|
+
column: node.loc.end.column - endCharsToExclude,
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
start: node.start + startCharsToExclude,
|
|
189
|
+
end: node.end - endCharsToExclude,
|
|
190
|
+
tail: node.tail,
|
|
191
|
+
value: {
|
|
192
|
+
cooked: node.cooked,
|
|
193
|
+
raw: node.raw,
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
mapGenericTypeAnnotation(node: HermesNode): HermesNode {
|
|
199
|
+
// Convert simple `this` generic type to ThisTypeAnnotation
|
|
200
|
+
if (
|
|
201
|
+
node.typeParameters === null &&
|
|
202
|
+
node.id.type === 'Identifier' &&
|
|
203
|
+
node.id.name === 'this'
|
|
204
|
+
) {
|
|
205
|
+
return {
|
|
206
|
+
type: 'ThisTypeAnnotation',
|
|
207
|
+
loc: node.loc,
|
|
208
|
+
start: node.start,
|
|
209
|
+
end: node.end,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return this.mapNodeDefault(node);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
mapSymbolTypeAnnotation(node: HermesNode): HermesNode {
|
|
217
|
+
return {
|
|
218
|
+
type: 'GenericTypeAnnotation',
|
|
219
|
+
loc: node.loc,
|
|
220
|
+
start: node.start,
|
|
221
|
+
end: node.end,
|
|
222
|
+
id: {
|
|
223
|
+
type: 'Identifier',
|
|
224
|
+
loc: node.loc,
|
|
225
|
+
start: node.start,
|
|
226
|
+
end: node.end,
|
|
227
|
+
name: 'symbol',
|
|
228
|
+
},
|
|
229
|
+
typeParameters: null,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
mapProperty(node: HermesNode): HermesNode {
|
|
234
|
+
const key = this.mapNode(node.key);
|
|
235
|
+
const value = this.mapNode(node.value);
|
|
236
|
+
|
|
237
|
+
// Convert methods, getters, and setters to ObjectMethod nodes
|
|
238
|
+
if (node.method || node.kind !== 'init') {
|
|
239
|
+
// Properties under the FunctionExpression value that should be moved
|
|
240
|
+
// to the ObjectMethod node itself.
|
|
241
|
+
const {
|
|
242
|
+
id,
|
|
243
|
+
params,
|
|
244
|
+
body,
|
|
245
|
+
async,
|
|
246
|
+
generator,
|
|
247
|
+
returnType,
|
|
248
|
+
typeParameters,
|
|
249
|
+
predicate,
|
|
250
|
+
} = value;
|
|
251
|
+
|
|
252
|
+
return {
|
|
253
|
+
type: 'ObjectMethod',
|
|
254
|
+
loc: node.loc,
|
|
255
|
+
start: node.start,
|
|
256
|
+
end: node.end,
|
|
257
|
+
// Non getter or setter methods have `kind = method`
|
|
258
|
+
kind: node.kind === 'init' ? 'method' : node.kind,
|
|
259
|
+
computed: node.computed,
|
|
260
|
+
key,
|
|
261
|
+
id,
|
|
262
|
+
params,
|
|
263
|
+
body,
|
|
264
|
+
async,
|
|
265
|
+
generator,
|
|
266
|
+
returnType,
|
|
267
|
+
typeParameters,
|
|
268
|
+
predicate,
|
|
269
|
+
};
|
|
270
|
+
} else {
|
|
271
|
+
// Non-method property nodes should be renamed to ObjectProperty
|
|
272
|
+
node.type = 'ObjectProperty';
|
|
273
|
+
return node;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
mapMethodDefinition(node: HermesNode): HermesNode {
|
|
278
|
+
const key = this.mapNode(node.key);
|
|
279
|
+
const value = this.mapNode(node.value);
|
|
280
|
+
|
|
281
|
+
// Properties under the FunctionExpression value that should be moved
|
|
282
|
+
// to the ClassMethod node itself.
|
|
283
|
+
const {
|
|
284
|
+
id,
|
|
285
|
+
params,
|
|
286
|
+
body,
|
|
287
|
+
async,
|
|
288
|
+
generator,
|
|
289
|
+
returnType,
|
|
290
|
+
typeParameters,
|
|
291
|
+
predicate,
|
|
292
|
+
} = value;
|
|
293
|
+
|
|
294
|
+
return {
|
|
295
|
+
type: 'ClassMethod',
|
|
296
|
+
loc: node.loc,
|
|
297
|
+
start: node.start,
|
|
298
|
+
end: node.end,
|
|
299
|
+
kind: node.kind,
|
|
300
|
+
computed: node.computed,
|
|
301
|
+
static: node.static,
|
|
302
|
+
key,
|
|
303
|
+
id,
|
|
304
|
+
params,
|
|
305
|
+
body,
|
|
306
|
+
async,
|
|
307
|
+
generator,
|
|
308
|
+
returnType,
|
|
309
|
+
typeParameters,
|
|
310
|
+
predicate,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
mapRestElement(node: HermesNode): HermesNode {
|
|
315
|
+
const restElement = this.mapNodeDefault(node);
|
|
316
|
+
|
|
317
|
+
// Hermes puts type annotations on rest elements on the argument node,
|
|
318
|
+
// but Babel expects type annotations on the rest element node itself.
|
|
319
|
+
const annotation = restElement.argument.typeAnnotation;
|
|
320
|
+
if (annotation != null) {
|
|
321
|
+
restElement.typeAnnotation = annotation;
|
|
322
|
+
restElement.argument.typeAnnotation = null;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return restElement;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
mapImportExpression(node: HermesNode): HermesNode {
|
|
329
|
+
// Babel expects ImportExpression to be structued as a regular
|
|
330
|
+
// CallExpression where the callee is an Import node.
|
|
331
|
+
return {
|
|
332
|
+
type: 'CallExpression',
|
|
333
|
+
loc: node.loc,
|
|
334
|
+
start: node.start,
|
|
335
|
+
end: node.end,
|
|
336
|
+
callee: {
|
|
337
|
+
type: 'Import',
|
|
338
|
+
loc: node.loc,
|
|
339
|
+
start: node.start,
|
|
340
|
+
end: node.end,
|
|
341
|
+
},
|
|
342
|
+
arguments: [this.mapNode(node.source)],
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
mapFunction(node: HermesNode): HermesNode {
|
|
347
|
+
// Remove the first parameter if it is a this-type annotation,
|
|
348
|
+
// which is not recognized by Babel.
|
|
349
|
+
if (node.params.length !== 0 && node.params[0].name === 'this') {
|
|
350
|
+
node.params.shift();
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
return this.mapNodeDefault(node);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* If Babel (the version we target) does not support a type annotation we
|
|
358
|
+
* parse, we need to return some other valid type annotation in its place.
|
|
359
|
+
*/
|
|
360
|
+
mapUnsupportedTypeAnnotation(node: HermesNode): HermesNode {
|
|
361
|
+
return {
|
|
362
|
+
type: 'AnyTypeAnnotation',
|
|
363
|
+
loc: node.loc,
|
|
364
|
+
start: node.start,
|
|
365
|
+
end: node.end,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its 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
|
-
* @format
|
|
8
|
-
*/
|
|
9
|
-
'use strict';
|
|
1
|
+
"use strict";
|
|
10
2
|
|
|
11
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); }
|
|
12
4
|
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _HermesASTAdapter2 = _interopRequireDefault(require("./HermesASTAdapter"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
|
|
13
14
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
15
|
|
|
15
16
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
@@ -22,15 +23,15 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
|
|
|
22
23
|
|
|
23
24
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
24
25
|
|
|
25
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
26
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
26
27
|
|
|
27
28
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
28
29
|
|
|
29
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try {
|
|
30
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
30
31
|
|
|
31
32
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
34
35
|
|
|
35
36
|
var HermesToESTreeAdapter = /*#__PURE__*/function (_HermesASTAdapter) {
|
|
36
37
|
_inherits(HermesToESTreeAdapter, _HermesASTAdapter);
|
|
@@ -43,6 +44,9 @@ var HermesToESTreeAdapter = /*#__PURE__*/function (_HermesASTAdapter) {
|
|
|
43
44
|
_classCallCheck(this, HermesToESTreeAdapter);
|
|
44
45
|
|
|
45
46
|
_this = _super.call(this, options);
|
|
47
|
+
|
|
48
|
+
_defineProperty(_assertThisInitialized(_this), "code", void 0);
|
|
49
|
+
|
|
46
50
|
_this.code = code;
|
|
47
51
|
return _this;
|
|
48
52
|
}
|
|
@@ -207,6 +211,6 @@ var HermesToESTreeAdapter = /*#__PURE__*/function (_HermesASTAdapter) {
|
|
|
207
211
|
}]);
|
|
208
212
|
|
|
209
213
|
return HermesToESTreeAdapter;
|
|
210
|
-
}(
|
|
214
|
+
}(_HermesASTAdapter2["default"]);
|
|
211
215
|
|
|
212
|
-
|
|
216
|
+
exports["default"] = HermesToESTreeAdapter;
|