hermes-parser 0.5.0 → 0.8.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 +129 -144
- package/dist/HermesASTAdapter.js.flow +1 -7
- 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 +415 -370
- package/dist/HermesToBabelAdapter.js.flow +109 -5
- package/dist/HermesToESTreeAdapter.js +393 -156
- package/dist/HermesToESTreeAdapter.js.flow +282 -15
- package/dist/ParserOptions.js.flow +1 -1
- package/dist/generated/visitor-keys.js +56 -41
- package/dist/generated/visitor-keys.js.flow +1 -1
- package/dist/getModuleDocblock.js +111 -0
- package/dist/getModuleDocblock.js.flow +116 -0
- package/dist/index.js +12 -21
- package/dist/index.js.flow +2 -2
- package/package.json +7 -2
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/HermesAST.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.
|
|
@@ -33,6 +33,7 @@ export type HermesToken = {
|
|
|
33
33
|
| 'Keyword'
|
|
34
34
|
| 'Null'
|
|
35
35
|
| 'Numeric'
|
|
36
|
+
| 'BigInt'
|
|
36
37
|
| 'Punctuator'
|
|
37
38
|
| 'String'
|
|
38
39
|
| 'RegularExpression'
|
package/dist/HermesASTAdapter.js
CHANGED
|
@@ -3,30 +3,37 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
var _visitorKeys = require("./generated/visitor-keys");
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
12
|
+
*
|
|
13
|
+
* This source code is licensed under the MIT license found in the
|
|
14
|
+
* LICENSE file in the root directory of this source tree.
|
|
15
|
+
*
|
|
16
|
+
*
|
|
17
|
+
* @format
|
|
18
|
+
*/
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
/*
|
|
21
|
+
This class does some very "javascripty" things in the name of
|
|
22
|
+
performance which are ultimately impossible to soundly type.
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
So instead of adding strict types and a large number of suppression
|
|
25
|
+
comments, instead it is left untyped and subclasses are strictly
|
|
26
|
+
typed via a separate flow declaration file.
|
|
27
|
+
*/
|
|
17
28
|
|
|
18
29
|
/**
|
|
19
30
|
* The base class for transforming the Hermes AST to the desired output format.
|
|
20
31
|
* Extended by concrete adapters which output an ESTree or Babel AST.
|
|
21
32
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
_defineProperty(this, "sourceFilename", void 0);
|
|
27
|
-
|
|
28
|
-
_defineProperty(this, "sourceType", void 0);
|
|
29
|
-
|
|
33
|
+
class HermesASTAdapter {
|
|
34
|
+
constructor(options) {
|
|
35
|
+
this.sourceFilename = void 0;
|
|
36
|
+
this.sourceType = void 0;
|
|
30
37
|
this.sourceFilename = options.sourceFilename;
|
|
31
38
|
this.sourceType = options.sourceType;
|
|
32
39
|
}
|
|
@@ -36,162 +43,140 @@ var HermesASTAdapter = /*#__PURE__*/function () {
|
|
|
36
43
|
*/
|
|
37
44
|
|
|
38
45
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// Comments are not traversed via visitor keys
|
|
43
|
-
var comments = program.comments;
|
|
46
|
+
transform(program) {
|
|
47
|
+
// Comments are not traversed via visitor keys
|
|
48
|
+
const comments = program.comments;
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
for (let i = 0; i < comments.length; i++) {
|
|
51
|
+
const comment = comments[i];
|
|
52
|
+
this.fixSourceLocation(comment);
|
|
53
|
+
comments[i] = this.mapComment(comment);
|
|
54
|
+
} // The first comment may be an interpreter directive and is stored directly on the program node
|
|
50
55
|
|
|
51
56
|
|
|
52
|
-
|
|
57
|
+
program.interpreter = comments.length > 0 && comments[0].type === 'InterpreterDirective' ? comments.shift() : null; // Tokens are not traversed via visitor keys
|
|
53
58
|
|
|
54
|
-
|
|
59
|
+
const tokens = program.tokens;
|
|
55
60
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
61
|
+
if (tokens) {
|
|
62
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
63
|
+
this.fixSourceLocation(tokens[i]);
|
|
60
64
|
}
|
|
61
|
-
|
|
62
|
-
return this.mapNode(program);
|
|
63
65
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Transform a Hermes AST node to the output AST format.
|
|
66
|
-
*
|
|
67
|
-
* This may modify the input node in-place and return that same node, or a completely
|
|
68
|
-
* new node may be constructed and returned. Overriden in child classes.
|
|
69
|
-
*/
|
|
70
|
-
|
|
71
|
-
}, {
|
|
72
|
-
key: "mapNode",
|
|
73
|
-
value: function mapNode(_node) {
|
|
74
|
-
throw new Error('Implemented in subclasses');
|
|
75
|
-
}
|
|
76
|
-
}, {
|
|
77
|
-
key: "mapNodeDefault",
|
|
78
|
-
value: function mapNodeDefault(node) {
|
|
79
|
-
var visitorKeys = _visitorKeys.HERMES_AST_VISITOR_KEYS[node.type];
|
|
80
66
|
|
|
81
|
-
|
|
82
|
-
|
|
67
|
+
return this.mapNode(program);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Transform a Hermes AST node to the output AST format.
|
|
71
|
+
*
|
|
72
|
+
* This may modify the input node in-place and return that same node, or a completely
|
|
73
|
+
* new node may be constructed and returned. Overriden in child classes.
|
|
74
|
+
*/
|
|
83
75
|
|
|
84
|
-
if (childType === _visitorKeys.NODE_CHILD) {
|
|
85
|
-
var child = node[key];
|
|
86
76
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
} else if (childType === _visitorKeys.NODE_LIST_CHILD) {
|
|
91
|
-
var children = node[key];
|
|
77
|
+
mapNode(_node) {
|
|
78
|
+
throw new Error('Implemented in subclasses');
|
|
79
|
+
}
|
|
92
80
|
|
|
93
|
-
|
|
94
|
-
|
|
81
|
+
mapNodeDefault(node) {
|
|
82
|
+
const visitorKeys = _visitorKeys.HERMES_AST_VISITOR_KEYS[node.type];
|
|
95
83
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
84
|
+
for (const key in visitorKeys) {
|
|
85
|
+
const childType = visitorKeys[key];
|
|
86
|
+
|
|
87
|
+
if (childType === _visitorKeys.NODE_CHILD) {
|
|
88
|
+
const child = node[key];
|
|
89
|
+
|
|
90
|
+
if (child != null) {
|
|
91
|
+
node[key] = this.mapNode(child);
|
|
100
92
|
}
|
|
101
|
-
}
|
|
93
|
+
} else if (childType === _visitorKeys.NODE_LIST_CHILD) {
|
|
94
|
+
const children = node[key];
|
|
102
95
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Update the source location for this node depending on the output AST format.
|
|
107
|
-
* This can modify the input node in-place. Overriden in child classes.
|
|
108
|
-
*/
|
|
109
|
-
|
|
110
|
-
}, {
|
|
111
|
-
key: "fixSourceLocation",
|
|
112
|
-
value: function fixSourceLocation(_node) {
|
|
113
|
-
throw new Error('Implemented in subclasses');
|
|
114
|
-
}
|
|
115
|
-
}, {
|
|
116
|
-
key: "getSourceType",
|
|
117
|
-
value: function getSourceType() {
|
|
118
|
-
var _this$sourceType;
|
|
96
|
+
for (let i = 0; i < children.length; i++) {
|
|
97
|
+
const child = children[i];
|
|
119
98
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
value: function setModuleSourceType() {
|
|
125
|
-
if (this.sourceType == null) {
|
|
126
|
-
this.sourceType = 'module';
|
|
99
|
+
if (child != null) {
|
|
100
|
+
children[i] = this.mapNode(child);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
127
103
|
}
|
|
128
104
|
}
|
|
129
|
-
}, {
|
|
130
|
-
key: "mapComment",
|
|
131
|
-
value: function mapComment(node) {
|
|
132
|
-
return node;
|
|
133
|
-
}
|
|
134
|
-
}, {
|
|
135
|
-
key: "mapEmpty",
|
|
136
|
-
value: function mapEmpty(_node) {
|
|
137
|
-
// $FlowExpectedError
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
}, {
|
|
141
|
-
key: "mapImportDeclaration",
|
|
142
|
-
value: function mapImportDeclaration(node) {
|
|
143
|
-
if (node.importKind === 'value') {
|
|
144
|
-
this.setModuleSourceType();
|
|
145
|
-
}
|
|
146
105
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
106
|
+
return node;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Update the source location for this node depending on the output AST format.
|
|
110
|
+
* This can modify the input node in-place. Overriden in child classes.
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
fixSourceLocation(_node) {
|
|
115
|
+
throw new Error('Implemented in subclasses');
|
|
116
|
+
}
|
|
155
117
|
|
|
156
|
-
|
|
118
|
+
getSourceType() {
|
|
119
|
+
var _this$sourceType;
|
|
120
|
+
|
|
121
|
+
return (_this$sourceType = this.sourceType) != null ? _this$sourceType : 'script';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
setModuleSourceType() {
|
|
125
|
+
if (this.sourceType == null) {
|
|
126
|
+
this.sourceType = 'module';
|
|
157
127
|
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
mapComment(node) {
|
|
131
|
+
return node;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
mapEmpty(_node) {
|
|
135
|
+
// $FlowExpectedError
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
mapImportDeclaration(node) {
|
|
140
|
+
if (node.importKind === 'value') {
|
|
161
141
|
this.setModuleSourceType();
|
|
162
|
-
return this.mapNodeDefault(node);
|
|
163
142
|
}
|
|
164
|
-
}, {
|
|
165
|
-
key: "mapExportNamedDeclaration",
|
|
166
|
-
value: function mapExportNamedDeclaration(node) {
|
|
167
|
-
if (node.exportKind === 'value') {
|
|
168
|
-
this.setModuleSourceType();
|
|
169
|
-
}
|
|
170
143
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}, {
|
|
174
|
-
key: "mapExportAllDeclaration",
|
|
175
|
-
value: function mapExportAllDeclaration(node) {
|
|
176
|
-
if (node.exportKind === 'value') {
|
|
177
|
-
this.setModuleSourceType();
|
|
178
|
-
}
|
|
144
|
+
return this.mapNodeDefault(node);
|
|
145
|
+
}
|
|
179
146
|
|
|
180
|
-
|
|
147
|
+
mapImportSpecifier(node) {
|
|
148
|
+
if (node.importKind === 'value') {
|
|
149
|
+
node.importKind = null;
|
|
181
150
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
151
|
+
|
|
152
|
+
return this.mapNodeDefault(node);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
mapExportDefaultDeclaration(node) {
|
|
156
|
+
this.setModuleSourceType();
|
|
157
|
+
return this.mapNodeDefault(node);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
mapExportNamedDeclaration(node) {
|
|
161
|
+
if (node.exportKind === 'value') {
|
|
162
|
+
this.setModuleSourceType();
|
|
186
163
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
164
|
+
|
|
165
|
+
return this.mapNodeDefault(node);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
mapExportAllDeclaration(node) {
|
|
169
|
+
if (node.exportKind === 'value') {
|
|
170
|
+
this.setModuleSourceType();
|
|
191
171
|
}
|
|
192
|
-
}]);
|
|
193
172
|
|
|
194
|
-
|
|
195
|
-
}
|
|
173
|
+
return this.mapNodeDefault(node);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
formatError(node, message) {
|
|
177
|
+
return `${message} (${node.loc.start.line}:${node.loc.start.column})`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
}
|
|
196
181
|
|
|
197
|
-
exports
|
|
182
|
+
exports.default = HermesASTAdapter;
|
|
@@ -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.
|
|
@@ -166,12 +166,6 @@ export default class HermesASTAdapter {
|
|
|
166
166
|
return this.mapNodeDefault(node);
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
mapPrivateProperty(node: HermesNode): HermesNode {
|
|
170
|
-
throw new SyntaxError(
|
|
171
|
-
this.formatError(node, 'Private properties are not supported'),
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
169
|
formatError(node: HermesNode, message: string): string {
|
|
176
170
|
return `${message} (${node.loc.start.line}:${node.loc.start.column})`;
|
|
177
171
|
}
|
package/dist/HermesParser.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.
|
|
@@ -18,36 +18,36 @@ var _HermesParserDeserializer = _interopRequireDefault(require("./HermesParserDe
|
|
|
18
18
|
|
|
19
19
|
var _HermesParserWASM = _interopRequireDefault(require("./HermesParserWASM"));
|
|
20
20
|
|
|
21
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : {
|
|
21
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
const hermesParse = _HermesParserWASM.default.cwrap('hermesParse', 'number', ['number', 'number', 'number', 'number', 'number']);
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const hermesParseResult_free = _HermesParserWASM.default.cwrap('hermesParseResult_free', 'void', ['number']);
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const hermesParseResult_getError = _HermesParserWASM.default.cwrap('hermesParseResult_getError', 'string', ['number']);
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
const hermesParseResult_getErrorLine = _HermesParserWASM.default.cwrap('hermesParseResult_getErrorLine', 'number', ['number']);
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
const hermesParseResult_getErrorColumn = _HermesParserWASM.default.cwrap('hermesParseResult_getErrorColumn', 'number', ['number']);
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
const hermesParseResult_getProgramBuffer = _HermesParserWASM.default.cwrap('hermesParseResult_getProgramBuffer', 'number', ['number']);
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
const hermesParseResult_getPositionBuffer = _HermesParserWASM.default.cwrap('hermesParseResult_getPositionBuffer', 'number', ['number']);
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
const hermesParseResult_getPositionBufferSize = _HermesParserWASM.default.cwrap('hermesParseResult_getPositionBufferSize', 'number', ['number']); // Copy a string into the WASM heap and null-terminate
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
function copyToHeap(buffer, addr) {
|
|
41
|
-
_HermesParserWASM
|
|
41
|
+
_HermesParserWASM.default.HEAP8.set(buffer, addr);
|
|
42
42
|
|
|
43
|
-
_HermesParserWASM
|
|
43
|
+
_HermesParserWASM.default.HEAP8[addr + buffer.length] = 0;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
function parse(source, options) {
|
|
47
47
|
// Allocate space on heap for source text
|
|
48
|
-
|
|
48
|
+
const sourceBuffer = Buffer.from(source, 'utf8');
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
const sourceAddr = _HermesParserWASM.default._malloc(sourceBuffer.length + 1);
|
|
51
51
|
|
|
52
52
|
if (!sourceAddr) {
|
|
53
53
|
throw new Error('Parser out of memory');
|
|
@@ -56,14 +56,14 @@ function parse(source, options) {
|
|
|
56
56
|
try {
|
|
57
57
|
// Copy source text onto WASM heap
|
|
58
58
|
copyToHeap(sourceBuffer, sourceAddr);
|
|
59
|
-
|
|
59
|
+
const parseResult = hermesParse(sourceAddr, sourceBuffer.length + 1, options.flow === 'detect', options.tokens, options.allowReturnOutsideFunction);
|
|
60
60
|
|
|
61
61
|
try {
|
|
62
62
|
// Extract and throw error from parse result if parsing failed
|
|
63
|
-
|
|
63
|
+
const err = hermesParseResult_getError(parseResult);
|
|
64
64
|
|
|
65
65
|
if (err) {
|
|
66
|
-
|
|
66
|
+
const syntaxError = new SyntaxError(err); // $FlowExpectedError[prop-missing]
|
|
67
67
|
|
|
68
68
|
syntaxError.loc = {
|
|
69
69
|
line: hermesParseResult_getErrorLine(parseResult),
|
|
@@ -72,12 +72,12 @@ function parse(source, options) {
|
|
|
72
72
|
throw syntaxError;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
const deserializer = new _HermesParserDeserializer.default(hermesParseResult_getProgramBuffer(parseResult), hermesParseResult_getPositionBuffer(parseResult), hermesParseResult_getPositionBufferSize(parseResult), _HermesParserWASM.default, options);
|
|
76
76
|
return deserializer.deserialize();
|
|
77
77
|
} finally {
|
|
78
78
|
hermesParseResult_free(parseResult);
|
|
79
79
|
}
|
|
80
80
|
} finally {
|
|
81
|
-
_HermesParserWASM
|
|
81
|
+
_HermesParserWASM.default._free(sourceAddr);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -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.
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
Object.defineProperty(exports, "__esModule", {
|
|
21
21
|
value: true
|
|
22
22
|
});
|
|
23
|
-
exports
|
|
23
|
+
exports.default = HermesParserDecodeUTF8String;
|
|
24
24
|
|
|
25
25
|
function HermesParserDecodeUTF8String(ptrIn, length, heap) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
let ptr = ptrIn;
|
|
27
|
+
const endPtr = ptr + length;
|
|
28
|
+
let str = '';
|
|
29
29
|
|
|
30
30
|
while (ptr < endPtr) {
|
|
31
31
|
// ASCII characters fit in single byte code point
|
|
32
|
-
|
|
32
|
+
let u0 = heap[ptr++];
|
|
33
33
|
|
|
34
34
|
if (!(u0 & 0x80)) {
|
|
35
35
|
str += String.fromCharCode(u0);
|
|
@@ -37,16 +37,16 @@ function HermesParserDecodeUTF8String(ptrIn, length, heap) {
|
|
|
37
37
|
} // Two byte code point
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
const u1 = heap[ptr++] & 0x3f;
|
|
41
41
|
|
|
42
|
-
if ((u0 & 0xe0)
|
|
42
|
+
if ((u0 & 0xe0) === 0xc0) {
|
|
43
43
|
str += String.fromCharCode((u0 & 0x1f) << 6 | u1);
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
const u2 = heap[ptr++] & 0x3f;
|
|
48
48
|
|
|
49
|
-
if ((u0 & 0xf0)
|
|
49
|
+
if ((u0 & 0xf0) === 0xe0) {
|
|
50
50
|
// Three byte code point
|
|
51
51
|
u0 = (u0 & 0x0f) << 12 | u1 << 6 | u2;
|
|
52
52
|
} else {
|
|
@@ -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.
|
|
@@ -37,13 +37,13 @@ export default function HermesParserDecodeUTF8String(
|
|
|
37
37
|
|
|
38
38
|
// Two byte code point
|
|
39
39
|
const u1 = heap[ptr++] & 0x3f;
|
|
40
|
-
if ((u0 & 0xe0)
|
|
40
|
+
if ((u0 & 0xe0) === 0xc0) {
|
|
41
41
|
str += String.fromCharCode(((u0 & 0x1f) << 6) | u1);
|
|
42
42
|
continue;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
const u2 = heap[ptr++] & 0x3f;
|
|
46
|
-
if ((u0 & 0xf0)
|
|
46
|
+
if ((u0 & 0xf0) === 0xe0) {
|
|
47
47
|
// Three byte code point
|
|
48
48
|
u0 = ((u0 & 0x0f) << 12) | (u1 << 6) | u2;
|
|
49
49
|
} else {
|