react-nitro-hermes 0.0.1-alpha.8 → 0.0.1-alpha.9

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 (181) hide show
  1. package/hermes/CMakeLists.txt +874 -0
  2. package/hermes/android/HostObjectJniTest.cpp +178 -0
  3. package/hermes/android/build-logic/build.gradle.kts +31 -0
  4. package/hermes/android/build-logic/settings.gradle.kts +17 -0
  5. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/helpers/internal/SerializeHermesCompilerPackageJson.kt +33 -0
  6. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/plugins/internal/TestUtilsPlugin.kt +80 -0
  7. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/tasks/internal/CustomExecTask.kt +46 -0
  8. package/hermes/android/build-logic/src/main/kotlin/publish.gradle.kts +82 -0
  9. package/hermes/android/build.gradle.kts +332 -0
  10. package/hermes/android/cppruntime/build.gradle +72 -0
  11. package/hermes/android/cppruntime/src/main/AndroidManifest.xml +2 -0
  12. package/hermes/android/cppruntime/src/main/cpp/CMakeLists.txt +8 -0
  13. package/hermes/android/cppruntime/src/main/cpp/stub.cpp +12 -0
  14. package/hermes/android/cross-compile/swift-libicu.patch +13 -0
  15. package/hermes/android/cross-compile/toolchain-android-arm-api13-gnustl.cmake +13 -0
  16. package/hermes/android/cross-compile/toolchain-android-arm-api15-gnustl.cmake +14 -0
  17. package/hermes/android/gradle/libs.versions.toml +30 -0
  18. package/hermes/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  19. package/hermes/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  20. package/hermes/android/gradle.properties +3 -0
  21. package/hermes/android/gradlew +248 -0
  22. package/hermes/android/gradlew.bat +93 -0
  23. package/hermes/android/intltest/build.gradle +147 -0
  24. package/hermes/android/intltest/java/com/facebook/hermes/test/CMakeLists.txt +45 -0
  25. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.cpp +68 -0
  26. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.h +44 -0
  27. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.java +45 -0
  28. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogueTestData.java +32 -0
  29. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesInstrumentationTest.java +150 -0
  30. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlAndroidTest.java +147 -0
  31. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlTest262.java +470 -0
  32. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesRuntimeFactory.cpp +73 -0
  33. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.cpp +90 -0
  34. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.h +62 -0
  35. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.java +155 -0
  36. package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.cpp +48 -0
  37. package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.h +36 -0
  38. package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoad.cpp +13 -0
  39. package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoadEpilogue.cpp +13 -0
  40. package/hermes/android/intltest/src/main/AndroidManifest.xml +2 -0
  41. package/hermes/android/ios-artifacts/build.gradle.kts +65 -0
  42. package/hermes/android/settings.gradle.kts +27 -0
  43. package/hermes/cmake/modules/Hermes.cmake +481 -0
  44. package/hermes/cmake/modules/Lit.cmake +96 -0
  45. package/hermes/doc/Branches.md +38 -0
  46. package/hermes/doc/BuildingAndRunning.md +121 -0
  47. package/hermes/doc/CodingStandards.md +112 -0
  48. package/hermes/doc/CrossCompilation.md +79 -0
  49. package/hermes/doc/Design.md +217 -0
  50. package/hermes/doc/Emscripten.md +156 -0
  51. package/hermes/doc/Features.md +143 -0
  52. package/hermes/doc/GCSafeCoding.md +563 -0
  53. package/hermes/doc/GenGC.md +300 -0
  54. package/hermes/doc/Hades.md +344 -0
  55. package/hermes/doc/HighLevelOptimizations.md +37 -0
  56. package/hermes/doc/IR.md +1306 -0
  57. package/hermes/doc/IntlAPIs.md +196 -0
  58. package/hermes/doc/JIT.md +999 -0
  59. package/hermes/doc/LazyEvalCompilation.md +84 -0
  60. package/hermes/doc/MemoryProfilers.md +316 -0
  61. package/hermes/doc/Modules.md +144 -0
  62. package/hermes/doc/Optimizer.md +83 -0
  63. package/hermes/doc/PerfProfiling.md +29 -0
  64. package/hermes/doc/ProhibitInvoke.md +329 -0
  65. package/hermes/doc/ReactNative.md +40 -0
  66. package/hermes/doc/ReactNativeIntegration.md +94 -0
  67. package/hermes/doc/RegExp.md +24 -0
  68. package/hermes/doc/SpecIncompat.md +85 -0
  69. package/hermes/doc/Strings.md +140 -0
  70. package/hermes/doc/TypedLanguage.md +432 -0
  71. package/hermes/doc/VM.md +174 -0
  72. package/hermes/doc/blog/2024-11-09-octane-benchmark-jit-progress.md +17 -0
  73. package/hermes/doc/blog/2024-12-19-static-hermes-update-dec-2024.md +47 -0
  74. package/hermes/doc/blog/2024-12-23-compiling-javascript-to-wasm.md +267 -0
  75. package/hermes/doc/blog/2025-06-09-jsi-runtime-data-apis.md +23 -0
  76. package/hermes/doc/blog/2025-07-15-static-h-performance-june-2025.md +18 -0
  77. package/hermes/doc/blog/2025-11-02-hermes-compilation-runtime-modes.md +23 -0
  78. package/hermes/doc/blog/2025-11-06-hermes-memory-modes.md +35 -0
  79. package/hermes/doc/blog/2025-11-24-json-parsing-performance.md +17 -0
  80. package/hermes/doc/blog/2025-12-02-iserialization.md +11 -0
  81. package/hermes/doc/blog/2025-12-12-new-way-to-contribute.md +68 -0
  82. package/hermes/doc/blog/2026-06-05-new-hermes-stable-release.md +51 -0
  83. package/hermes/doc/blog/README.md +25 -0
  84. package/hermes/doc/blog/images/2024-11-09-octane-pi3.jpeg +0 -0
  85. package/hermes/doc/blog/images/2024-11-09-octane-pi5.jpeg +0 -0
  86. package/hermes/doc/blog/images/2025-07-15-perf-hv32-interpreter.jpeg +0 -0
  87. package/hermes/doc/blog/images/2025-07-15-perf-hv32-jit.jpeg +0 -0
  88. package/hermes/doc/icu_license.txt +420 -0
  89. package/hermes/doc/img/heap_snapshot_retainers.png +0 -0
  90. package/hermes/doc/img/logo.svg +1 -0
  91. package/hermes/doc/img/object_captured_by_environment.png +0 -0
  92. package/hermes/doc/img/root_categories.png +0 -0
  93. package/hermes/doc/plans/ir-type/flow-type-system.md +324 -0
  94. package/hermes/doc/plans/ir-type/ir-type-system-v2-design.md +652 -0
  95. package/hermes/doc/plans/ir-type/ir-type-system.md +220 -0
  96. package/hermes/doc/plans/ir-type/ir-type-v2-implementation.md +1187 -0
  97. package/hermes/doc/plans/ir-type/memory.md +48 -0
  98. package/hermes/doc/plans/ir-type/phase1-steps.md +512 -0
  99. package/hermes/doc/plans/ir-type/progress.md +239 -0
  100. package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-design.md +203 -0
  101. package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-results.md +71 -0
  102. package/hermes/doc/superpowers/plans/2026-07-28-worker-arraybuffer-input.md +597 -0
  103. package/hermes/doc/superpowers/plans/2026-08-18-jitemitter-split.md +1149 -0
  104. package/hermes/doc/superpowers/plans/2026-08-20-jit-type-asserts.md +969 -0
  105. package/hermes/doc/superpowers/plans/2026-08-23-jit-shared-compiler-driver.md +478 -0
  106. package/hermes/doc/superpowers/plans/2026-08-23-x86-64-jit-skeleton.md +797 -0
  107. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-arith.md +444 -0
  108. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-calls.md +261 -0
  109. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-props.md +240 -0
  110. package/hermes/doc/superpowers/plans/2026-10-26-regexp-bytecode-sharing.md +2197 -0
  111. package/hermes/doc/superpowers/plans/2026-10-28-regexp-start-filter-and-exec-fast-paths.md +3981 -0
  112. package/hermes/doc/superpowers/specs/2026-07-28-worker-arraybuffer-input-design.md +206 -0
  113. package/hermes/doc/superpowers/specs/2026-08-18-jitemitter-split-design.md +530 -0
  114. package/hermes/doc/superpowers/specs/2026-08-20-jit-type-asserts-design.md +360 -0
  115. package/hermes/doc/superpowers/specs/2026-08-23-x86-64-jit-design.md +246 -0
  116. package/hermes/doc/superpowers/specs/2026-08-26-icu-free-normalize-design.md +355 -0
  117. package/hermes/doc/superpowers/specs/2026-08-27-icu-free-convert-to-case-design.md +305 -0
  118. package/hermes/doc/superpowers/specs/2026-08-27-icu-free-locale-compare-design.md +429 -0
  119. package/hermes/doc/superpowers/specs/2026-08-29-icu-free-date-format-design.md +297 -0
  120. package/hermes/doc/superpowers/specs/2026-10-26-regexp-bytecode-sharing-design.md +605 -0
  121. package/hermes/doc/superpowers/specs/2026-10-28-regexp-start-filter-and-exec-fast-paths-design.md +551 -0
  122. package/hermes/doc/typescript-stripping.md +90 -0
  123. package/hermes/external/CMakeLists.txt +20 -0
  124. package/hermes/utils/IntlGen/IntlGen.java +531 -0
  125. package/hermes/utils/bench_with_stats.py +827 -0
  126. package/hermes/utils/build-apple-framework.sh +323 -0
  127. package/hermes/utils/chrome_snapshot_parser.py +210 -0
  128. package/hermes/utils/cmake-dev-build.sh +18 -0
  129. package/hermes/utils/commons.sh +55 -0
  130. package/hermes/utils/dump-cpp-funcs.sh +3 -0
  131. package/hermes/utils/es5objects.js +198 -0
  132. package/hermes/utils/format.sh +145 -0
  133. package/hermes/utils/gen-promise-internal-bc.sh +66 -0
  134. package/hermes/utils/genUnicodeTable.py +2503 -0
  135. package/hermes/utils/hermes-lit/CMakeLists.txt +22 -0
  136. package/hermes/utils/hermes-lit/hermes-lit.in +15 -0
  137. package/hermes/utils/jit/README.md +134 -0
  138. package/hermes/utils/jit/jit-diff.sh +160 -0
  139. package/hermes/utils/jit/jit-dump.sh +193 -0
  140. package/hermes/utils/lit-expect-gen/generate.py +217 -0
  141. package/hermes/utils/promise/index.js +15 -0
  142. package/hermes/utils/promise/package.json +13 -0
  143. package/hermes/utils/promise/rollup.config.js +19 -0
  144. package/hermes/utils/promise/yarn.lock +247 -0
  145. package/hermes/utils/scripts/hermes/consts.js +26 -0
  146. package/hermes/utils/scripts/hermes/create-tarball.js +75 -0
  147. package/hermes/utils/scripts/hermes/get-hermes-version.js +57 -0
  148. package/hermes/utils/scripts/hermes/hermes-utils.js +122 -0
  149. package/hermes/utils/scripts/hermes/package.json +6 -0
  150. package/hermes/utils/scripts/hermes/prepare-artifacts.js +113 -0
  151. package/hermes/utils/scripts/hermes/publish-artifacts.js +109 -0
  152. package/hermes/utils/scripts/hermes/publish-npm.js +96 -0
  153. package/hermes/utils/scripts/hermes/scm-utils.js +41 -0
  154. package/hermes/utils/scripts/hermes/set-artifacts-version.js +64 -0
  155. package/hermes/utils/scripts/hermes/version-utils.js +98 -0
  156. package/hermes/utils/scripts/hermes/yarn.lock +240 -0
  157. package/hermes/utils/summarize_sizes.py +184 -0
  158. package/hermes/utils/symbolicate-nativecall-stats.py +112 -0
  159. package/hermes/utils/test_runner.py +13 -0
  160. package/hermes/utils/testsuite/README.facebook +3 -0
  161. package/hermes/utils/testsuite/README.md +69 -0
  162. package/hermes/utils/testsuite/cli.py +547 -0
  163. package/hermes/utils/testsuite/es_ast.py +337 -0
  164. package/hermes/utils/testsuite/external/LICENSE +28 -0
  165. package/hermes/utils/testsuite/external/README.facebook +8 -0
  166. package/hermes/utils/testsuite/external/__init__.py +0 -0
  167. package/hermes/utils/testsuite/external/_monkeyYaml.py +164 -0
  168. package/hermes/utils/testsuite/external/parse_test262.py +141 -0
  169. package/hermes/utils/testsuite/hermes.py +522 -0
  170. package/hermes/utils/testsuite/preprocess.py +365 -0
  171. package/hermes/utils/testsuite/progress.py +377 -0
  172. package/hermes/utils/testsuite/skiplist.json +4356 -0
  173. package/hermes/utils/testsuite/skiplist.py +270 -0
  174. package/hermes/utils/testsuite/test_run_defs.py +435 -0
  175. package/hermes/utils/testsuite/typing_defs.py +52 -0
  176. package/hermes/utils/testsuite/utils.py +214 -0
  177. package/hermes/utils/tidy.sh +22 -0
  178. package/hermes/utils/update-fbcode-hermes.sh +53 -0
  179. package/hermes/utils/updateErrorTest.py +193 -0
  180. package/hermes/utils/wasm-compile.sh +65 -0
  181. package/package.json +1 -1
@@ -0,0 +1,337 @@
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ #
3
+ # This source code is licensed under the MIT license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ import json
7
+ import traceback
8
+ from typing import no_type_check, Tuple
9
+
10
+ from .typing_defs import JSON
11
+ from .utils import TestCaseResult, TestResultCode
12
+
13
+ # Collect the keys that should be omitted from either Hermes or esprima ASTs.
14
+ # Key is the type of a node, and value is the set of keys of child nodes that
15
+ # need to be omitted.
16
+ # fmt: off
17
+ OMITTED_KEYS = {
18
+ # Keys in Hermes
19
+ "ArrayExpression": {"trailingComma"},
20
+ "BlockStatement": {"implicit"},
21
+ # Some literals support "raw" and others don't.
22
+ # esprima doesn't distinguish.
23
+ "EnumStringBody": {"hasUnknownMembers"},
24
+ "EnumNumberBody": {"hasUnknownMembers"},
25
+ "EnumBooleanBody": {"hasUnknownMembers"},
26
+ "EnumSymbolBody": {"hasUnknownMembers"},
27
+
28
+ # Common keys in both Hermes and esprima
29
+ "Literal": {"raw"},
30
+ "ImportDeclaration": {
31
+ # Hermes
32
+ "assertions",
33
+ # esprima
34
+ "importKind",
35
+ "attributes",
36
+ },
37
+ "ImportSpecifier": {"importKind"},
38
+ "ExportNamedDeclaration": {"exportKind"},
39
+ "ExportAllDeclaration": {"exportKind"},
40
+ # TODO: Flow conditionally outputs "inexact" depending on whether the parent
41
+ # node is an Interface or not.
42
+ "ObjectTypeAnnotation": {"inexact"},
43
+ "ForOfStatement": {"await"},
44
+
45
+ # Keys in esprima
46
+ "Program": {"tokens", "sourceType", "comments"},
47
+ "BigIntLiteral": {"value"},
48
+ "BigIntLiteralTypeAnnotation": {"value"},
49
+ # ES6+ specific enhancement to the ESTree original definitions that Hermes
50
+ # does not support yet.
51
+ # TODO: remember to update or remove them once we update the parser.
52
+ "FunctionDeclaration": {"expression", "predicate"},
53
+ "FunctionExpression": {"expression", "predicate"},
54
+ "ArrowFunctionExpression": {"id", "generator"},
55
+ "ForInStatement": {"each"},
56
+ "Identifier": {"optional"},
57
+ "MethodDefinition": {"decorators"},
58
+ "ExportDefaultDeclaration": {"exportKind"},
59
+ }
60
+ # fmt: on
61
+
62
+ # These are the keys in the JSON ASTs that should be omitted when trimming.
63
+ OMITTED_KEYS_COMMON = {"loc", "range", "errors"} # These are all from esprima
64
+
65
+
66
+ def trim_ast(node: JSON) -> JSON:
67
+ """Further trim the AST after normalization."""
68
+ if isinstance(node, dict):
69
+ tree = node
70
+ res = {}
71
+ for key, val in tree.items():
72
+ if key in OMITTED_KEYS_COMMON:
73
+ continue
74
+ if (
75
+ "type" in tree
76
+ and tree["type"] in OMITTED_KEYS
77
+ and key in OMITTED_KEYS[tree["type"]]
78
+ ):
79
+ continue
80
+ else:
81
+ res[key] = trim_ast(val)
82
+ return res
83
+ elif isinstance(node, list):
84
+ return [trim_ast(elt) for elt in node]
85
+ else:
86
+ return node
87
+
88
+
89
+ # We could make typing this function work, but it needs a few wrapper functions
90
+ # and assertions. For now, let's simply disable typing it.
91
+ @no_type_check
92
+ def normalize_hermes_ast(ast: JSON) -> JSON:
93
+ """
94
+ Recursively normalize the Hermes AST for diff checking. Normalizations
95
+ include deleting nodes that do not exist in esprima, updating node values
96
+ to match esprima and skipping some nodes. Normalized AST is in a form
97
+ between Hermes AST and esprima AST (we will do normalizations on esprima
98
+ AST as well).
99
+ """
100
+
101
+ HERMES_LITERAL_NODE_TYPES = {
102
+ "NullLiteral",
103
+ "BooleanLiteral",
104
+ "StringLiteral",
105
+ "NumericLiteral",
106
+ "BigIntLiteral",
107
+ "RegExpLiteral",
108
+ "JSXStringLiteral",
109
+ }
110
+
111
+ if isinstance(ast, list):
112
+ return [normalize_hermes_ast(elt) for elt in ast]
113
+ if not isinstance(ast, dict):
114
+ return ast
115
+
116
+ if "type" not in ast:
117
+ return ast
118
+ if ast["type"] == "Empty":
119
+ return None
120
+ # skip top level 'File' node
121
+ if ast["type"] == "File":
122
+ ast = ast["program"]
123
+ # We don't really need this recursive call, this is just to make
124
+ # type checker happy.
125
+ return normalize_hermes_ast(ast)
126
+ if ast["type"] == "ExpressionStatement":
127
+ # esprima asts don't have the 'directive' field if it's null
128
+ if (
129
+ isinstance(ast["expression"], dict)
130
+ and ast["expression"]["type"] == "StringLiteral"
131
+ and ast["expression"]["value"] == "use strict"
132
+ ):
133
+ ast["directive"] = "use strict"
134
+ else:
135
+ del ast["directive"]
136
+ if ast["type"] == "Identifier" and ast["name"] == "this":
137
+ del ast["optional"]
138
+ if ast["type"] == "DeclareNamespace":
139
+ del ast["id"]["optional"]
140
+ if ast["type"] == "PrivateName":
141
+ ast = ast["id"]
142
+ ast["type"] = "PrivateIdentifier"
143
+ if ast["type"] == "ClassPrivateProperty":
144
+ ast["key"]["type"] = "PrivateIdentifier"
145
+ ast["computed"] = False
146
+ ast["static"] = False
147
+ if ast["type"] == "ClassProperty" or ast["type"] == "ClassPrivateProperty":
148
+ if not ast["optional"]:
149
+ del ast["optional"]
150
+ if len(ast["decorators"]) == 0:
151
+ del ast["decorators"]
152
+ ast["type"] = "PropertyDefinition"
153
+ if ast["type"] == "TypeParameter":
154
+ if not ast["usesExtendsBound"]:
155
+ del ast["usesExtendsBound"]
156
+ if ast["type"] == "TupleTypeLabeledElement":
157
+ if not ast["optional"]:
158
+ del ast["optional"]
159
+ if ast["type"] == "ClassDeclaration" or ast["type"] == "ClassExpression":
160
+ if "decorators" in ast:
161
+ if len(ast["decorators"]) == 0:
162
+ del ast["decorators"]
163
+ # convert the literal node types to ESTree standard form
164
+ if ast["type"] in HERMES_LITERAL_NODE_TYPES:
165
+ if ast["type"] == "NullLiteral":
166
+ ast["value"] = None
167
+ if ast["type"] == "RegExpLiteral":
168
+ ast["regex"] = {"pattern": ast["pattern"], "flags": ast["flags"]}
169
+ del ast["pattern"]
170
+ del ast["flags"]
171
+ if ast["type"] == "BigIntLiteral":
172
+ ast["bigint"] = ast["bigint"]
173
+ ast["value"] = None
174
+ ast["type"] = "Literal"
175
+
176
+ # Normalize children node
177
+ for key, val in ast.items():
178
+ ast[key] = normalize_hermes_ast(val)
179
+ return ast
180
+
181
+
182
+ @no_type_check
183
+ def normalize_esprima_ast(ast: JSON) -> JSON:
184
+ """
185
+ Recursively normalize the full esprima AST for diff checking.
186
+ Normalizations include deleting some nodes that do not exist in Hermes AST
187
+ and updating node values to match Hermes AST. Normalized AST is in a form
188
+ between Hermes AST and esprima AST.
189
+ """
190
+
191
+ if isinstance(ast, list):
192
+ return [normalize_esprima_ast(elt) for elt in ast]
193
+ if not isinstance(ast, dict):
194
+ return ast
195
+
196
+ if "type" in ast and ast["type"] == "ExpressionStatement":
197
+ # If the expression is a string, esprima will set the string to
198
+ # the 'directive' field. Even if it's not 'use strict'
199
+ if "directive" in ast and ast["directive"] != "use strict":
200
+ del ast["directive"]
201
+ if "type" in ast:
202
+ # If it is a regexp literal, the 'value' field is unnecessary and
203
+ # Hermes does not have it.
204
+ if ast["type"] == "Literal" and "regex" in ast:
205
+ del ast["value"]
206
+
207
+ # Flow outputs RestProperty/SpreadProperty sometimes.
208
+ if ast["type"] == "RestProperty":
209
+ ast["type"] = "RestElement"
210
+ if ast["type"] == "SpreadProperty":
211
+ ast["type"] = "SpreadElement"
212
+ if (
213
+ ast["type"] == "ClassProperty"
214
+ or ast["type"] == "ClassPrivateProperty"
215
+ or ast["type"] == "PropertyDefinition"
216
+ ):
217
+ if "declare" not in ast:
218
+ ast["declare"] = False
219
+ if ast["type"] == "ClassDeclaration" or ast["type"] == "ClassExpression":
220
+ if "superTypeParameters" in ast:
221
+ ast["superTypeArguments"] = ast["superTypeParameters"]
222
+ del ast["superTypeParameters"]
223
+ if "decorators" in ast:
224
+ if len(ast["decorators"]) == 0:
225
+ del ast["decorators"]
226
+ if ast["type"] == "ComponentDeclaration":
227
+ if "async" not in ast:
228
+ ast["async"] = False
229
+ if ast["type"] == "HookDeclaration":
230
+ if "async" not in ast:
231
+ ast["async"] = False
232
+ # If it is a template literal, the 'value' field contains
233
+ # the 'cooked' and 'raw' strings, which should be moved.
234
+ if "type" in ast and ast["type"] == "TemplateLiteral" and "quasis" in ast:
235
+ for quasi in ast["quasis"]:
236
+ quasi["cooked"] = quasi["value"]["cooked"]
237
+ quasi["raw"] = quasi["value"]["raw"]
238
+ del quasi["value"]
239
+
240
+ for key, val in ast.items():
241
+ ast[key] = normalize_esprima_ast(val)
242
+ return ast
243
+
244
+
245
+ def compare_ast(hermes_n: JSON, esprima_n: JSON) -> Tuple[bool, str]:
246
+ """
247
+ Compare the two (normalized) AST.
248
+
249
+ Returns:
250
+ (True, "") if they are matched.
251
+ (False, message) if there is a mismatch. Here message is the details.
252
+ """
253
+ if type(hermes_n) != type(esprima_n): # noqa: E721
254
+ msg = f"Expected {type(esprima_n)}, found {type(hermes_n)}"
255
+ if isinstance(esprima_n, dict):
256
+ msg += f"\n in {esprima_n['type']}"
257
+ elif isinstance(hermes_n, dict):
258
+ msg += f"\n in Hermes {hermes_n['type']}"
259
+ return (False, msg)
260
+ if isinstance(hermes_n, dict):
261
+ # Just to make type checking happy
262
+ assert isinstance(esprima_n, dict)
263
+ # Check if Hermes is missing keys.
264
+ for key, val in esprima_n.items():
265
+ if key not in hermes_n:
266
+ msg = f"{hermes_n['type']} missing property: {key}"
267
+ return (False, msg)
268
+ (eq, msg) = compare_ast(hermes_n[key], val)
269
+ if not eq:
270
+ return (False, msg)
271
+ # Check if Hermes has extra keys.
272
+ for key, val in hermes_n.items():
273
+ if key not in esprima_n and val is not None:
274
+ # Flow omits some keys which are null in Hermes output.
275
+ # Ignore these keys in Hermes if they don't show up in
276
+ # the expected AST if they have no value anyway.
277
+ msg = f"{hermes_n['type']} extra property: {key}"
278
+ return (False, msg)
279
+ return (True, "")
280
+ elif isinstance(hermes_n, list):
281
+ # Just to make type checking happy
282
+ assert isinstance(esprima_n, list)
283
+ if len(hermes_n) != len(esprima_n):
284
+ msg = f"List expected {len(esprima_n)} elements, found {len(hermes_n)}"
285
+ return (False, msg)
286
+ for i in range(len(hermes_n)):
287
+ (eq, msg) = compare_ast(hermes_n[i], esprima_n[i])
288
+ if not eq:
289
+ return (False, msg)
290
+ return (True, "")
291
+ else:
292
+ if hermes_n != esprima_n:
293
+ msg = f"Expected {esprima_n}, found {hermes_n}"
294
+ return (False, msg)
295
+ return (True, "")
296
+
297
+
298
+ def diff(output: str, test_name: str, expected_ast: JSON) -> TestCaseResult:
299
+ """
300
+ Diff check the AST provided in output string against expected AST.
301
+
302
+ Returns:
303
+ True, if the two ASTs match (with normalization).
304
+ False, if there is a mismatch, or other errors such as JSON decoder error.
305
+ """
306
+ try:
307
+ hermes_ast = json.loads(output)
308
+ except json.JSONDecodeError as err:
309
+ msg = "FAIL: fail to get AST"
310
+ details = f"JSON decode error: {err}\n"
311
+ details += f"Raw:\n{output}"
312
+ return TestCaseResult(test_name, TestResultCode.TEST_FAILED, msg, details)
313
+
314
+ # We always normalize and trim the full AST for simplicity.
315
+ # Most ASTs in esprima/flow tests are very small, performance is not a
316
+ # concern. Even it is, most expensive operations happen in normalization
317
+ # (e.g., del), and those have to be done when comparing ASTs.
318
+ try:
319
+ hermes_ast = trim_ast(normalize_hermes_ast(hermes_ast))
320
+ expected_ast = trim_ast(normalize_esprima_ast(expected_ast))
321
+ except Exception:
322
+ # In case that hermes parser gets updated and adds/removes some keys,
323
+ # we might see Exception such as KeyError. Treat it as a failure and
324
+ # report the error message and stack.
325
+ msg = "FAIL: fail to trim AST"
326
+ details = f"Error: {traceback.format_exc()}\n"
327
+ details += f"Hermes AST: \n{json.dumps(hermes_ast, indent=2)}\n"
328
+ details += f"ESPRIMA AST: \n{json.dumps(expected_ast, indent=2)}"
329
+ return TestCaseResult(test_name, TestResultCode.TEST_FAILED, msg, details)
330
+ (test_passed, details) = compare_ast(hermes_ast, expected_ast)
331
+ if not test_passed:
332
+ msg = "FAIL: AST not expected"
333
+ details = f"Reason: {details}\n"
334
+ details += f"Hermes AST: \n{json.dumps(hermes_ast, indent=2)}\n"
335
+ details += f"ESPRIMA AST: \n{json.dumps(expected_ast, indent=2)}"
336
+ return TestCaseResult(test_name, TestResultCode.TEST_FAILED, msg, details)
337
+ return TestCaseResult(test_name, TestResultCode.TEST_PASSED)
@@ -0,0 +1,28 @@
1
+ The << Software identified by reference to the Ecma Standard* ("Software)">> is protected by copyright and is being
2
+ made available under the "BSD License", included below. This Software may be subject to third party rights (rights
3
+ from parties other than Ecma International), including patent rights, and no licenses under such third party rights
4
+ are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA
5
+ CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT http://www.ecma-international.org/memento/codeofconduct.htm FOR
6
+ INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS*.
7
+
8
+ Copyright © <<2012>> <<Ecma International>>
9
+ All rights reserved.
10
+
11
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
12
+ following conditions are met:
13
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
14
+ disclaimer.
15
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
16
+ following disclaimer in the documentation and/or other materials provided with the distribution.
17
+ 3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22
+ SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26
+ DAMAGE.
27
+
28
+ * Ecma International Standards hereafter means Ecma International Standards as well as Ecma Technical Reports
@@ -0,0 +1,8 @@
1
+ This directory includes utility code for parsing metadata in test262 test files.
2
+
3
+ Only copied _monkeyYaml.py and parseTestRecord.py (renamed to parse_test262, and
4
+ added typing annotations) from
5
+ https://github.com/test262-utils/test262-harness-py/tree/master/src, and LICENSE
6
+ from the Github repo.
7
+
8
+ Downloaded from commit hash 278bcfaed0dcaa13936831fb1769d15e7c1e3b2b.
File without changes
@@ -0,0 +1,164 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright 2014 by Sam Mikes. All rights reserved.
4
+ # This code is governed by the BSD license found in the LICENSE file.
5
+
6
+ # This code provides a fallback parser that can handle the subset of
7
+ # YAML used in test262 frontmatter
8
+
9
+ # @lint-ignore-every LICENSELINT
10
+
11
+ import re
12
+
13
+ mYamlKV = re.compile(r"(.*?):(.*)")
14
+ mYamlIntDigits = re.compile(r"^[-0-9]*$")
15
+ mYamlFloatDigits = re.compile(r"^[-.0-9eE]*$")
16
+ mYamlListPattern = re.compile(r"^\[(.*)\]$")
17
+ mYamlMultilineList = re.compile(r"^ *- (.*)$")
18
+ mYamlStringValue = re.compile(r"^('|\").*\1$")
19
+
20
+
21
+ def load(str):
22
+ return myReadDict(str.splitlines())[1]
23
+
24
+
25
+ def myReadDict(lines, indent=""):
26
+ dict = None
27
+ key = None
28
+ emptyLines = 0
29
+
30
+ while lines:
31
+ if not lines[0].startswith(indent):
32
+ break
33
+
34
+ line = lines.pop(0)
35
+ if myIsAllSpaces(line):
36
+ emptyLines += 1
37
+ continue
38
+ result = mYamlKV.match(line)
39
+
40
+ if result:
41
+ if not dict:
42
+ dict = {}
43
+ key = result.group(1).strip()
44
+ value = result.group(2).strip()
45
+ (lines, value) = myReadValue(lines, value, indent)
46
+ dict[key] = value
47
+ else:
48
+ if dict and key and key in dict:
49
+ c = " " if emptyLines == 0 else "\n" * emptyLines
50
+ dict[key] += c + line.strip()
51
+ else:
52
+ raise Exception("monkeyYaml is confused at " + line)
53
+ emptyLines = 0
54
+ return lines, dict
55
+
56
+
57
+ def myReadValue(lines, value, indent):
58
+ if value == ">" or value == "|":
59
+ (lines, value) = myMultiline(lines, value == "|")
60
+ value = value + "\n"
61
+ return (lines, value)
62
+ if lines and not value:
63
+ if myMaybeList(lines[0]):
64
+ return myMultilineList(lines, value)
65
+ indentMatch = re.match("(" + indent + r"\s+)", lines[0])
66
+ if indentMatch:
67
+ if ":" in lines[0]:
68
+ return myReadDict(lines, indentMatch.group(1))
69
+ return myMultiline(lines, False)
70
+ return lines, myReadOneLine(value)
71
+
72
+
73
+ def myMaybeList(value):
74
+ return mYamlMultilineList.match(value)
75
+
76
+
77
+ def myMultilineList(lines, value):
78
+ # assume no explcit indentor (otherwise have to parse value)
79
+ value = []
80
+ indent = None
81
+ while lines:
82
+ line = lines.pop(0)
83
+ leading = myLeadingSpaces(line)
84
+ if myIsAllSpaces(line):
85
+ pass
86
+ elif indent and leading < indent:
87
+ lines.insert(0, line)
88
+ break
89
+ else:
90
+ indent = indent or leading
91
+ value += [myReadOneLine(myRemoveListHeader(indent, line))]
92
+ return (lines, value)
93
+
94
+
95
+ def myRemoveListHeader(indent, line):
96
+ line = line[indent:]
97
+ matched = mYamlMultilineList.match(line)
98
+ if matched:
99
+ return matched.group(1)
100
+ return ""
101
+
102
+
103
+ def myReadOneLine(value):
104
+ if mYamlListPattern.match(value):
105
+ return myFlowList(value)
106
+ elif mYamlIntDigits.match(value):
107
+ try:
108
+ value = int(value)
109
+ except ValueError:
110
+ pass
111
+ elif mYamlFloatDigits.match(value):
112
+ try:
113
+ value = float(value)
114
+ except ValueError:
115
+ pass
116
+ elif mYamlStringValue.match(value):
117
+ value = value[1:-1]
118
+ return value
119
+
120
+
121
+ def myFlowList(value):
122
+ result = mYamlListPattern.match(value)
123
+ values = result.group(1).split(",") if result else []
124
+ return [myReadOneLine(v.strip()) for v in values]
125
+
126
+
127
+ def myMultiline(lines, preserveNewlines=False):
128
+ # assume no explcit indentor (otherwise have to parse value)
129
+ value = ""
130
+ indent = myLeadingSpaces(lines[0])
131
+ wasEmpty = None
132
+
133
+ while lines:
134
+ line = lines.pop(0)
135
+ isEmpty = myIsAllSpaces(line)
136
+
137
+ if isEmpty:
138
+ if preserveNewlines:
139
+ value += "\n"
140
+ elif myLeadingSpaces(line) < indent:
141
+ lines.insert(0, line)
142
+ break
143
+ else:
144
+ if preserveNewlines:
145
+ if wasEmpty != None:
146
+ value += "\n"
147
+ else:
148
+ if wasEmpty == False:
149
+ value += " "
150
+ elif wasEmpty == True:
151
+ value += "\n"
152
+ value += line[(indent):]
153
+
154
+ wasEmpty = isEmpty
155
+
156
+ return (lines, value)
157
+
158
+
159
+ def myIsAllSpaces(line):
160
+ return len(line.strip()) == 0
161
+
162
+
163
+ def myLeadingSpaces(line):
164
+ return len(line) - len(line.lstrip(" "))
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright 2011 by Google, Inc. All rights reserved.
4
+ # This code is governed by the BSD license found in the LICENSE file.
5
+
6
+ # @lint-ignore-every LICENSELINT
7
+
8
+ # Format of test262:
9
+ # https://chromium.googlesource.com/external/github.com/tc39/test262/+/HEAD/CONTRIBUTING.md
10
+
11
+ import re
12
+ from typing import Optional, Tuple
13
+
14
+ from ._monkeyYaml import load as yamlLoad
15
+
16
+
17
+ # Matches trailing whitespace and any following blank lines.
18
+ _BLANK_LINES = r"([ \t]*[\r\n]{1,2})*"
19
+
20
+ # Matches the YAML frontmatter block.
21
+ _YAML_PATTERN = re.compile(r"/\*---(.*)---\*/" + _BLANK_LINES, re.DOTALL)
22
+
23
+ # Matches all known variants for the license block.
24
+ # https://github.com/tc39/test262/blob/cf4c281a3857d88f7165bc022b059132d71ef0ce/tools/lint/lib/checks/license.py
25
+ _LICENSE_PATTERN = re.compile(
26
+ r"// Copyright( \(C\))? ([1-9][0-9-]*) .+\. {1,2}All rights reserved\.[\r\n]{1,2}"
27
+ + r"("
28
+ + r"// This code is governed by the( BSD)? license found in the LICENSE file\."
29
+ + r"|"
30
+ + r"// See LICENSE for details."
31
+ + r"|"
32
+ + r"// Use of this source code is governed by a BSD-style license that can be[\r\n]{1,2}"
33
+ + r"// found in the LICENSE file\."
34
+ + r"|"
35
+ + r"// See LICENSE or https://github\.com/tc39/test262/blob/HEAD/LICENSE"
36
+ + r")",
37
+ re.IGNORECASE,
38
+ )
39
+
40
+ _PD_PATTERN = re.compile(
41
+ r"/\*[\r\n]{1,2}"
42
+ + r" \* Any copyright is dedicated to the Public Domain.[\r\n]{1,2}"
43
+ + r" \* http://creativecommons.org/licenses/publicdomain/[\r\n]{1,2}"
44
+ + r" \*/[\r\n]{1,2}",
45
+ re.IGNORECASE,
46
+ )
47
+
48
+
49
+ def yamlAttrParser(testRecord: dict, attrs: str, test_name: str) -> None:
50
+ parsed = yamlLoad(attrs)
51
+ if parsed is None:
52
+ print(f"Failed to parse yaml in name {test_name}")
53
+ return
54
+
55
+ for key in parsed:
56
+ value = parsed[key]
57
+ if key == "info":
58
+ key = "commentary"
59
+ testRecord[key] = value
60
+
61
+
62
+ def findLicense(src: str) -> Optional[str]:
63
+ match = _LICENSE_PATTERN.search(src)
64
+ if match:
65
+ return match.group(0)
66
+
67
+ # Some tests have both a license block and a public domain block, and the
68
+ # latter is placed after the former. So we detect it after the license
69
+ # pattern matching.
70
+ match = _PD_PATTERN.search(src)
71
+ if match:
72
+ return match.group(0)
73
+
74
+ return None
75
+
76
+
77
+ def findAttrs(src: str) -> Tuple[Optional[str], Optional[str]]:
78
+ match = _YAML_PATTERN.search(src)
79
+ if not match:
80
+ return (None, None)
81
+
82
+ return (match.group(0), match.group(1).strip())
83
+
84
+
85
+ def print_verbose(s: str, verbose: bool) -> None:
86
+ if verbose:
87
+ print(s)
88
+
89
+
90
+ def parseTestRecord(src: str, test_name: str, verbose: bool = True) -> dict:
91
+ # Find the license block.
92
+ header = findLicense(src)
93
+
94
+ # Find the YAML frontmatter.
95
+ (frontmatter, attrs) = findAttrs(src)
96
+
97
+ # YAML frontmatter is required for all tests.
98
+ if frontmatter is None:
99
+ print_verbose(f"Missing frontmatter: {test_name}", verbose)
100
+
101
+ # The license shuold be placed before the frontmatter and there shouldn't be
102
+ # any extra content between the license and the frontmatter.
103
+ if header is not None and frontmatter is not None:
104
+ headerIdx = src.index(header)
105
+ frontmatterIdx = src.index(frontmatter)
106
+ if headerIdx > frontmatterIdx:
107
+ print_verbose(f"Unexpected license after frontmatter: {test_name}", verbose)
108
+
109
+ # Search for any extra test content, but ignore whitespace only or comment lines.
110
+ extra = src[headerIdx + len(header) : frontmatterIdx]
111
+ if extra and any(
112
+ line.strip() and not line.lstrip().startswith("//")
113
+ for line in extra.split("\n")
114
+ ):
115
+ print_verbose(
116
+ f"Unexpected test content between license and frontmatter: {test_name}",
117
+ verbose,
118
+ )
119
+
120
+ # Remove the license and YAML parts from the actual test content.
121
+ test = src
122
+ if frontmatter is not None:
123
+ test = test.replace(frontmatter, "")
124
+ if header is not None:
125
+ test = test.replace(header, "")
126
+
127
+ testRecord = {}
128
+ testRecord["src"] = test
129
+
130
+ if attrs:
131
+ yamlAttrParser(testRecord, attrs, test_name)
132
+
133
+ # Report if the license block is missing in non-generated tests.
134
+ if (
135
+ header is None
136
+ and "generated" not in testRecord.get("flags", "")
137
+ and "hashbang" not in test_name
138
+ ):
139
+ print_verbose(f"No license found in: {test_name}", verbose)
140
+
141
+ return testRecord