hermes-estree 0.32.1 → 0.33.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.
Files changed (87) hide show
  1. package/dist/generated/HermesESTreeSelectorTypes.js.flow +262 -27
  2. package/dist/generated/predicates.js +120 -0
  3. package/dist/generated/predicates.js.flow +72 -0
  4. package/dist/predicates.js +2 -4
  5. package/dist/predicates.js.flow +5 -4
  6. package/dist/src/generated/predicates.js +120 -0
  7. package/dist/src/predicates.js +2 -4
  8. package/dist/types.js.flow +103 -11
  9. package/package.json +1 -1
  10. package/dist/HermesAST.js.flow +0 -57
  11. package/dist/HermesASTAdapter.js +0 -192
  12. package/dist/HermesASTAdapter.js.flow +0 -189
  13. package/dist/HermesParser.js +0 -108
  14. package/dist/HermesParser.js.flow +0 -161
  15. package/dist/HermesParserDecodeUTF8String.js +0 -68
  16. package/dist/HermesParserDecodeUTF8String.js.flow +0 -65
  17. package/dist/HermesParserDeserializer.js +0 -242
  18. package/dist/HermesParserDeserializer.js.flow +0 -260
  19. package/dist/HermesParserNodeDeserializers.js +0 -2477
  20. package/dist/HermesParserNodeDeserializers.js.flow +0 -16
  21. package/dist/HermesParserWASM.js +0 -6
  22. package/dist/HermesParserWASM.js.flow +0 -87
  23. package/dist/HermesToESTreeAdapter.js +0 -439
  24. package/dist/HermesToESTreeAdapter.js.flow +0 -421
  25. package/dist/ParserOptions.js +0 -18
  26. package/dist/ParserOptions.js.flow +0 -41
  27. package/dist/babel/TransformESTreeToBabel.js +0 -1123
  28. package/dist/babel/TransformESTreeToBabel.js.flow +0 -1277
  29. package/dist/estree/StripFlowTypes.js +0 -175
  30. package/dist/estree/StripFlowTypes.js.flow +0 -158
  31. package/dist/estree/StripFlowTypesForBabel.js +0 -215
  32. package/dist/estree/StripFlowTypesForBabel.js.flow +0 -216
  33. package/dist/estree/TransformComponentSyntax.js +0 -788
  34. package/dist/estree/TransformComponentSyntax.js.flow +0 -864
  35. package/dist/estree/TransformEnumSyntax.js +0 -106
  36. package/dist/estree/TransformEnumSyntax.js.flow +0 -125
  37. package/dist/estree/TransformMatchSyntax.js +0 -1006
  38. package/dist/estree/TransformMatchSyntax.js.flow +0 -912
  39. package/dist/generated/ESTreeVisitorKeys.js +0 -220
  40. package/dist/generated/ESTreeVisitorKeys.js.flow +0 -15
  41. package/dist/generated/ParserVisitorKeys.js +0 -794
  42. package/dist/generated/ParserVisitorKeys.js.flow +0 -17
  43. package/dist/getModuleDocblock.js +0 -112
  44. package/dist/getModuleDocblock.js.flow +0 -118
  45. package/dist/src/HermesASTAdapter.js +0 -192
  46. package/dist/src/HermesParser.js +0 -108
  47. package/dist/src/HermesParserDecodeUTF8String.js +0 -68
  48. package/dist/src/HermesParserDeserializer.js +0 -242
  49. package/dist/src/HermesParserNodeDeserializers.js +0 -2477
  50. package/dist/src/HermesToESTreeAdapter.js +0 -439
  51. package/dist/src/ParserOptions.js +0 -18
  52. package/dist/src/babel/TransformESTreeToBabel.js +0 -1123
  53. package/dist/src/estree/StripFlowTypes.js +0 -175
  54. package/dist/src/estree/StripFlowTypesForBabel.js +0 -215
  55. package/dist/src/estree/TransformComponentSyntax.js +0 -788
  56. package/dist/src/estree/TransformEnumSyntax.js +0 -106
  57. package/dist/src/estree/TransformMatchSyntax.js +0 -1006
  58. package/dist/src/generated/ESTreeVisitorKeys.js +0 -220
  59. package/dist/src/generated/ParserVisitorKeys.js +0 -794
  60. package/dist/src/getModuleDocblock.js +0 -112
  61. package/dist/src/transform/SimpleTransform.js +0 -136
  62. package/dist/src/transform/astArrayMutationHelpers.js +0 -62
  63. package/dist/src/transform/astNodeMutationHelpers.js +0 -200
  64. package/dist/src/traverse/SimpleTraverser.js +0 -137
  65. package/dist/src/traverse/getVisitorKeys.js +0 -37
  66. package/dist/src/utils/Builders.js +0 -191
  67. package/dist/src/utils/GenID.js +0 -41
  68. package/dist/src/utils/createSyntaxError.js +0 -25
  69. package/dist/src/utils/mutateESTreeASTForPrettier.js +0 -127
  70. package/dist/transform/SimpleTransform.js +0 -136
  71. package/dist/transform/SimpleTransform.js.flow +0 -169
  72. package/dist/transform/astArrayMutationHelpers.js +0 -62
  73. package/dist/transform/astArrayMutationHelpers.js.flow +0 -71
  74. package/dist/transform/astNodeMutationHelpers.js +0 -200
  75. package/dist/transform/astNodeMutationHelpers.js.flow +0 -246
  76. package/dist/traverse/SimpleTraverser.js +0 -137
  77. package/dist/traverse/SimpleTraverser.js.flow +0 -133
  78. package/dist/traverse/getVisitorKeys.js +0 -37
  79. package/dist/traverse/getVisitorKeys.js.flow +0 -36
  80. package/dist/utils/Builders.js +0 -191
  81. package/dist/utils/Builders.js.flow +0 -218
  82. package/dist/utils/GenID.js +0 -41
  83. package/dist/utils/GenID.js.flow +0 -38
  84. package/dist/utils/createSyntaxError.js +0 -25
  85. package/dist/utils/createSyntaxError.js.flow +0 -24
  86. package/dist/utils/mutateESTreeASTForPrettier.js +0 -127
  87. package/dist/utils/mutateESTreeASTForPrettier.js.flow +0 -130
@@ -1,17 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and 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
- declare export var NODE_CHILD: 'Node';
12
- declare export var NODE_LIST_CHILD: 'NodeList';
13
- declare export var HERMES_AST_VISITOR_KEYS: $ReadOnly<{
14
- [string]: $ReadOnly<{
15
- [string]: 'Node' | 'NodeList',
16
- }>,
17
- }>;
@@ -1,112 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and 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
- *
8
- * @format
9
- */
10
- 'use strict';
11
-
12
- Object.defineProperty(exports, "__esModule", {
13
- value: true
14
- });
15
- exports.getModuleDocblock = getModuleDocblock;
16
- exports.parseDocblockString = parseDocblockString;
17
- const DIRECTIVE_REGEX = /^\s*@([a-zA-Z0-9_-]+)( +.+)?$/;
18
-
19
- function parseDocblockString(docblock) {
20
- const directiveLines = docblock.split('\n') // remove the leading " *" from each line
21
- .map(line => line.trimStart().replace(/^\* ?/, '').trim()).filter(line => line.startsWith('@'));
22
- const directives = // $FlowExpectedError[incompatible-type] - flow types this return as {...}
23
- Object.create(null);
24
-
25
- for (const line of directiveLines) {
26
- var _match$;
27
-
28
- const match = DIRECTIVE_REGEX.exec(line);
29
-
30
- if (match == null) {
31
- continue;
32
- }
33
-
34
- const name = match[1]; // explicitly use an empty string if there's no value
35
- // this way the array length tracks how many instances of the directive there was
36
-
37
- const value = ((_match$ = match[2]) != null ? _match$ : '').trim();
38
-
39
- if (directives[name]) {
40
- directives[name].push(value);
41
- } else {
42
- directives[name] = [value];
43
- }
44
- }
45
-
46
- return directives;
47
- }
48
-
49
- function getModuleDocblock(hermesProgram) {
50
- const docblockNode = (() => {
51
- if (hermesProgram.type !== 'Program') {
52
- return null;
53
- } // $FlowExpectedError[incompatible-type] - escape out of the unsafe hermes types
54
-
55
-
56
- const program = hermesProgram;
57
-
58
- if (program.comments.length === 0) {
59
- return null;
60
- }
61
-
62
- const firstComment = (() => {
63
- const first = program.comments[0];
64
-
65
- if (first.type === 'Block') {
66
- return first;
67
- }
68
-
69
- if (program.comments.length === 1) {
70
- return null;
71
- } // ESLint will always strip out the shebang comment from the code before passing it to the parser
72
- // https://github.com/eslint/eslint/blob/21d647904dc30f9484b22acdd9243a6d0ecfba38/lib/linter/linter.js#L779
73
- // this means that we're forced to parse it as a line comment :(
74
- // this hacks around it by selecting the second comment in this case
75
-
76
-
77
- const second = program.comments[1];
78
-
79
- if (first.type === 'Line' && first.range[0] === 0 && second.type === 'Block') {
80
- return second;
81
- }
82
-
83
- return null;
84
- })();
85
-
86
- if (firstComment == null) {
87
- return null;
88
- }
89
- /*
90
- Handle cases like this where the comment isn't actually the first thing in the code:
91
- ```
92
- const x = 1; /* docblock *./
93
- ```
94
- */
95
-
96
-
97
- if (program.body.length > 0 && program.body[0].range[0] < firstComment.range[0]) {
98
- return null;
99
- }
100
-
101
- return firstComment;
102
- })();
103
-
104
- if (docblockNode == null) {
105
- return null;
106
- }
107
-
108
- return {
109
- directives: parseDocblockString(docblockNode.value),
110
- comment: docblockNode
111
- };
112
- }
@@ -1,118 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and 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
- 'use strict';
12
-
13
- import type {HermesNode} from './HermesAST';
14
- import type {DocblockDirectives, Program} from 'hermes-estree';
15
-
16
- const DIRECTIVE_REGEX = /^\s*@([a-zA-Z0-9_-]+)( +.+)?$/;
17
-
18
- export function parseDocblockString(docblock: string): DocblockDirectives {
19
- const directiveLines = docblock
20
- .split('\n')
21
- // remove the leading " *" from each line
22
- .map(line => line.trimStart().replace(/^\* ?/, '').trim())
23
- .filter(line => line.startsWith('@'));
24
-
25
- const directives: {
26
- [string]: Array<string>,
27
- } =
28
- // $FlowExpectedError[incompatible-type] - flow types this return as {...}
29
- Object.create(null);
30
-
31
- for (const line of directiveLines) {
32
- const match = DIRECTIVE_REGEX.exec(line);
33
- if (match == null) {
34
- continue;
35
- }
36
- const name = match[1];
37
- // explicitly use an empty string if there's no value
38
- // this way the array length tracks how many instances of the directive there was
39
- const value = (match[2] ?? '').trim();
40
- if (directives[name]) {
41
- directives[name].push(value);
42
- } else {
43
- directives[name] = [value];
44
- }
45
- }
46
-
47
- return directives;
48
- }
49
-
50
- export function getModuleDocblock(
51
- hermesProgram: HermesNode,
52
- ): Program['docblock'] {
53
- const docblockNode = (() => {
54
- if (hermesProgram.type !== 'Program') {
55
- return null;
56
- }
57
-
58
- // $FlowExpectedError[incompatible-type] - escape out of the unsafe hermes types
59
- const program: Program = hermesProgram;
60
-
61
- if (program.comments.length === 0) {
62
- return null;
63
- }
64
-
65
- const firstComment = (() => {
66
- const first = program.comments[0];
67
- if (first.type === 'Block') {
68
- return first;
69
- }
70
-
71
- if (program.comments.length === 1) {
72
- return null;
73
- }
74
-
75
- // ESLint will always strip out the shebang comment from the code before passing it to the parser
76
- // https://github.com/eslint/eslint/blob/21d647904dc30f9484b22acdd9243a6d0ecfba38/lib/linter/linter.js#L779
77
- // this means that we're forced to parse it as a line comment :(
78
- // this hacks around it by selecting the second comment in this case
79
- const second = program.comments[1];
80
- if (
81
- first.type === 'Line' &&
82
- first.range[0] === 0 &&
83
- second.type === 'Block'
84
- ) {
85
- return second;
86
- }
87
-
88
- return null;
89
- })();
90
- if (firstComment == null) {
91
- return null;
92
- }
93
-
94
- /*
95
- Handle cases like this where the comment isn't actually the first thing in the code:
96
- ```
97
- const x = 1; /* docblock *./
98
- ```
99
- */
100
- if (
101
- program.body.length > 0 &&
102
- program.body[0].range[0] < firstComment.range[0]
103
- ) {
104
- return null;
105
- }
106
-
107
- return firstComment;
108
- })();
109
-
110
- if (docblockNode == null) {
111
- return null;
112
- }
113
-
114
- return {
115
- directives: parseDocblockString(docblockNode.value),
116
- comment: docblockNode,
117
- };
118
- }
@@ -1,192 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _ParserVisitorKeys = require("./generated/ParserVisitorKeys");
9
-
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
- */
19
-
20
- /**
21
- * The base class for transforming the Hermes AST to the desired output format.
22
- * Extended by concrete adapters which output an ESTree or Babel AST.
23
- */
24
- class HermesASTAdapter {
25
- constructor(options) {
26
- this.sourceFilename = void 0;
27
- this.sourceType = void 0;
28
- this.sourceFilename = options.sourceFilename;
29
- this.sourceType = options.sourceType;
30
- }
31
- /**
32
- * Transform the input Hermes AST to the desired output format.
33
- * This modifies the input AST in place instead of constructing a new AST.
34
- */
35
-
36
-
37
- transform(program) {
38
- // Comments are not traversed via visitor keys
39
- const comments = program.comments;
40
-
41
- for (let i = 0; i < comments.length; i++) {
42
- const comment = comments[i];
43
- this.fixSourceLocation(comment);
44
- comments[i] = this.mapComment(comment);
45
- } // The first comment may be an interpreter directive and is stored directly on the program node
46
-
47
-
48
- program.interpreter = comments.length > 0 && comments[0].type === 'InterpreterDirective' ? comments.shift() : null; // Tokens are not traversed via visitor keys
49
-
50
- const tokens = program.tokens;
51
-
52
- if (tokens) {
53
- for (let i = 0; i < tokens.length; i++) {
54
- this.fixSourceLocation(tokens[i]);
55
- }
56
- }
57
-
58
- const resultNode = this.mapNode(program);
59
-
60
- if (resultNode.type !== 'Program') {
61
- throw new Error(`HermesToESTreeAdapter: Must return a Program node, instead of "${resultNode.type}". `);
62
- } // $FlowExpectedError[incompatible-type] We know this is a program at this point.
63
-
64
-
65
- return resultNode;
66
- }
67
- /**
68
- * Transform a Hermes AST node to the output AST format.
69
- *
70
- * This may modify the input node in-place and return that same node, or a completely
71
- * new node may be constructed and returned. Overriden in child classes.
72
- */
73
-
74
-
75
- mapNode(_node) {
76
- throw new Error('Implemented in subclasses');
77
- }
78
-
79
- mapNodeDefault(node) {
80
- const visitorKeys = _ParserVisitorKeys.HERMES_AST_VISITOR_KEYS[node.type];
81
-
82
- for (const key in visitorKeys) {
83
- const childType = visitorKeys[key];
84
-
85
- if (childType === _ParserVisitorKeys.NODE_CHILD) {
86
- const child = node[key];
87
-
88
- if (child != null) {
89
- node[key] = this.mapNode(child);
90
- }
91
- } else if (childType === _ParserVisitorKeys.NODE_LIST_CHILD) {
92
- const children = node[key];
93
-
94
- for (let i = 0; i < children.length; i++) {
95
- const child = children[i];
96
-
97
- if (child != null) {
98
- children[i] = this.mapNode(child);
99
- }
100
- }
101
- }
102
- }
103
-
104
- return node;
105
- }
106
- /**
107
- * Update the source location for this node depending on the output AST format.
108
- * This can modify the input node in-place. Overriden in child classes.
109
- */
110
-
111
-
112
- fixSourceLocation(_node) {
113
- throw new Error('Implemented in subclasses');
114
- }
115
-
116
- getSourceType() {
117
- var _this$sourceType;
118
-
119
- return (_this$sourceType = this.sourceType) != null ? _this$sourceType : 'script';
120
- }
121
-
122
- setModuleSourceType() {
123
- if (this.sourceType == null) {
124
- this.sourceType = 'module';
125
- }
126
- }
127
-
128
- mapComment(node) {
129
- return node;
130
- }
131
-
132
- mapEmpty(_node) {
133
- // $FlowExpectedError[incompatible-type]
134
- return null;
135
- }
136
-
137
- mapImportDeclaration(node) {
138
- if (node.importKind === 'value') {
139
- this.setModuleSourceType();
140
- }
141
-
142
- return this.mapNodeDefault(node);
143
- }
144
-
145
- mapImportSpecifier(node) {
146
- if (node.importKind === 'value') {
147
- node.importKind = null;
148
- }
149
-
150
- return this.mapNodeDefault(node);
151
- }
152
-
153
- mapExportDefaultDeclaration(node) {
154
- this.setModuleSourceType();
155
- return this.mapNodeDefault(node);
156
- }
157
-
158
- mapExportNamedDeclaration(node) {
159
- if (node.exportKind === 'value') {
160
- this.setModuleSourceType();
161
- }
162
-
163
- return this.mapNodeDefault(node);
164
- }
165
-
166
- mapExportAllDeclaration(node) {
167
- if (node.exportKind === 'value') {
168
- this.setModuleSourceType();
169
- }
170
-
171
- return this.mapNodeDefault(node);
172
- }
173
-
174
- formatError(node, message) {
175
- return `${message} (${node.loc.start.line}:${node.loc.start.column})`;
176
- }
177
-
178
- getBigIntLiteralValue(bigintString) {
179
- const bigint = bigintString // estree spec is to not have a trailing `n` on this property
180
- // https://github.com/estree/estree/blob/db962bb417a97effcfe9892f87fbb93c81a68584/es2020.md#bigintliteral
181
- .replace(/n$/, '') // `BigInt` doesn't accept numeric separator and `bigint` property should not include numeric separator
182
- .replaceAll('_', '');
183
- return {
184
- bigint,
185
- // coerce the string to a bigint value if supported by the environment
186
- value: typeof BigInt === 'function' ? BigInt(bigint) : null
187
- };
188
- }
189
-
190
- }
191
-
192
- exports.default = HermesASTAdapter;
@@ -1,108 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and 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
- *
8
- * @format
9
- */
10
- 'use strict';
11
-
12
- Object.defineProperty(exports, "__esModule", {
13
- value: true
14
- });
15
- exports.parse = parse;
16
-
17
- var _HermesParserDeserializer = _interopRequireDefault(require("./HermesParserDeserializer"));
18
-
19
- var _HermesParserWASM = _interopRequireDefault(require("./HermesParserWASM"));
20
-
21
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
-
23
- let HermesParserWASM;
24
- let hermesParse;
25
- let hermesParseResult_free;
26
- let hermesParseResult_getError;
27
- let hermesParseResult_getErrorLine;
28
- let hermesParseResult_getErrorColumn;
29
- let hermesParseResult_getProgramBuffer;
30
- let hermesParseResult_getPositionBuffer;
31
- let hermesParseResult_getPositionBufferSize;
32
- /**
33
- * Init the WASM wrapper code generated by `emscripten` to preparse the
34
- * HermesParser WASM code.
35
- */
36
-
37
- function initHermesParserWASM() {
38
- if (HermesParserWASM != null) {
39
- return;
40
- }
41
-
42
- HermesParserWASM = (0, _HermesParserWASM.default)({
43
- /**
44
- * The emscripten version of `quit` unconditionally assigns the `status` to
45
- * `process.exitCode` which overrides any pre-existing code that has been
46
- * set, even if it is non zero. For our use case we never want an
47
- * `exitCode` to be set so this override removes that functionality.
48
- */
49
- quit(_status, toThrow) {
50
- throw toThrow;
51
- }
52
-
53
- });
54
- hermesParse = HermesParserWASM.cwrap('hermesParse', 'number', ['number', 'number', 'number', 'number', 'number', 'number', 'number']);
55
- hermesParseResult_free = HermesParserWASM.cwrap('hermesParseResult_free', 'void', ['number']);
56
- hermesParseResult_getError = HermesParserWASM.cwrap('hermesParseResult_getError', 'string', ['number']);
57
- hermesParseResult_getErrorLine = HermesParserWASM.cwrap('hermesParseResult_getErrorLine', 'number', ['number']);
58
- hermesParseResult_getErrorColumn = HermesParserWASM.cwrap('hermesParseResult_getErrorColumn', 'number', ['number']);
59
- hermesParseResult_getProgramBuffer = HermesParserWASM.cwrap('hermesParseResult_getProgramBuffer', 'number', ['number']);
60
- hermesParseResult_getPositionBuffer = HermesParserWASM.cwrap('hermesParseResult_getPositionBuffer', 'number', ['number']);
61
- hermesParseResult_getPositionBufferSize = HermesParserWASM.cwrap('hermesParseResult_getPositionBufferSize', 'number', ['number']);
62
- } // Copy a string into the WASM heap and null-terminate
63
-
64
-
65
- function copyToHeap(buffer, addr) {
66
- HermesParserWASM.HEAP8.set(buffer, addr);
67
- HermesParserWASM.HEAP8[addr + buffer.length] = 0;
68
- }
69
-
70
- function parse(source, options) {
71
- initHermesParserWASM(); // Allocate space on heap for source text
72
-
73
- const sourceBuffer = Buffer.from(source, 'utf8');
74
-
75
- const sourceAddr = HermesParserWASM._malloc(sourceBuffer.length + 1);
76
-
77
- if (!sourceAddr) {
78
- throw new Error('Parser out of memory');
79
- }
80
-
81
- try {
82
- // Copy source text onto WASM heap
83
- copyToHeap(sourceBuffer, sourceAddr);
84
- const parseResult = hermesParse(sourceAddr, sourceBuffer.length + 1, options.flow === 'detect', options.enableExperimentalComponentSyntax, options.enableExperimentalFlowMatchSyntax, options.tokens, options.allowReturnOutsideFunction);
85
-
86
- try {
87
- // Extract and throw error from parse result if parsing failed
88
- const err = hermesParseResult_getError(parseResult);
89
-
90
- if (err) {
91
- const syntaxError = new SyntaxError(err); // $FlowExpectedError[prop-missing]
92
-
93
- syntaxError.loc = {
94
- line: hermesParseResult_getErrorLine(parseResult),
95
- column: hermesParseResult_getErrorColumn(parseResult)
96
- };
97
- throw syntaxError;
98
- }
99
-
100
- const deserializer = new _HermesParserDeserializer.default(hermesParseResult_getProgramBuffer(parseResult), hermesParseResult_getPositionBuffer(parseResult), hermesParseResult_getPositionBufferSize(parseResult), HermesParserWASM, options);
101
- return deserializer.deserialize();
102
- } finally {
103
- hermesParseResult_free(parseResult);
104
- }
105
- } finally {
106
- HermesParserWASM._free(sourceAddr);
107
- }
108
- }
@@ -1,68 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and 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
- *
8
- * @format
9
- */
10
- 'use strict';
11
- /**
12
- * Decode a UTF-8 encoded string from Hermes with a known length.
13
- * Based on Emscripten's UTF8ToString with the following differences:
14
- * - Always reads all bytes up to the given length, including null bytes. This
15
- * means that we can decode strings that contain null bytes in the middle.
16
- * - Allow UTF-8 encoded code points that are part of a surrogate pair, even though
17
- * this is technically invalid UTF-8 that UTF8ToString would convert to 0xfffd.
18
- */
19
-
20
- Object.defineProperty(exports, "__esModule", {
21
- value: true
22
- });
23
- exports.default = HermesParserDecodeUTF8String;
24
-
25
- function HermesParserDecodeUTF8String(ptrIn, length, heap) {
26
- let ptr = ptrIn;
27
- const endPtr = ptr + length;
28
- let str = '';
29
-
30
- while (ptr < endPtr) {
31
- // ASCII characters fit in single byte code point
32
- let u0 = heap[ptr++];
33
-
34
- if (!(u0 & 0x80)) {
35
- str += String.fromCharCode(u0);
36
- continue;
37
- } // Two byte code point
38
-
39
-
40
- const u1 = heap[ptr++] & 0x3f;
41
-
42
- if ((u0 & 0xe0) === 0xc0) {
43
- str += String.fromCharCode((u0 & 0x1f) << 6 | u1);
44
- continue;
45
- }
46
-
47
- const u2 = heap[ptr++] & 0x3f;
48
-
49
- if ((u0 & 0xf0) === 0xe0) {
50
- // Three byte code point
51
- u0 = (u0 & 0x0f) << 12 | u1 << 6 | u2;
52
- } else {
53
- // Four byte code point
54
- u0 = (u0 & 0x07) << 18 | u1 << 12 | u2 << 6 | heap[ptr++] & 0x3f;
55
- }
56
-
57
- if (u0 < 0x10000) {
58
- // Code point fits into a single UTF-16 code unit
59
- str += String.fromCharCode(u0);
60
- } else {
61
- // Code point does not fit into single UTF-16 code unit so convert to surrogate pair
62
- u0 -= 0x10000;
63
- str += String.fromCharCode(0xd800 | u0 >> 10, 0xdc00 | u0 & 0x3ff);
64
- }
65
- }
66
-
67
- return str;
68
- }