@futpib/parser 1.0.3 → 1.0.6

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 (262) hide show
  1. package/.claude/settings.local.json +24 -0
  2. package/.github/workflows/main.yml +1 -0
  3. package/build/androidPackageParser.js +30 -32
  4. package/build/arbitraryDalvikBytecode.d.ts +3 -3
  5. package/build/arbitraryDalvikBytecode.js +33 -27
  6. package/build/arbitraryDalvikExecutable.js +55 -17
  7. package/build/arbitraryJava.d.ts +31 -0
  8. package/build/arbitraryJava.js +532 -0
  9. package/build/arbitraryJavaScript.d.ts +3 -0
  10. package/build/arbitraryJavaScript.js +263 -0
  11. package/build/arbitraryJavascript.d.ts +3 -0
  12. package/build/arbitraryJavascript.js +263 -0
  13. package/build/arbitraryZig.d.ts +3 -0
  14. package/build/arbitraryZig.js +240 -0
  15. package/build/arbitraryZipStream.d.ts +1 -1
  16. package/build/arrayParser.js +72 -13
  17. package/build/backsmali.d.ts +4 -3
  18. package/build/backsmali.js +26 -6
  19. package/build/bash.d.ts +89 -0
  20. package/build/bash.js +1 -0
  21. package/build/bashParser.d.ts +6 -0
  22. package/build/bashParser.js +335 -0
  23. package/build/bashParser.test.d.ts +1 -0
  24. package/build/bashParser.test.js +343 -0
  25. package/build/bashParserEdgeCases.test.d.ts +1 -0
  26. package/build/bashParserEdgeCases.test.js +117 -0
  27. package/build/dalvikBytecodeParser/addressConversion.d.ts +110 -0
  28. package/build/dalvikBytecodeParser/addressConversion.js +334 -0
  29. package/build/dalvikBytecodeParser/formatParsers.d.ts +7 -6
  30. package/build/dalvikBytecodeParser/formatParsers.js +13 -14
  31. package/build/dalvikBytecodeParser.d.ts +60 -31
  32. package/build/dalvikBytecodeParser.js +92 -35
  33. package/build/dalvikBytecodeParser.test-d.d.ts +1 -0
  34. package/build/dalvikBytecodeParser.test-d.js +268 -0
  35. package/build/dalvikBytecodeUnparser/formatUnparsers.d.ts +9 -8
  36. package/build/dalvikBytecodeUnparser/formatUnparsers.js +13 -12
  37. package/build/dalvikBytecodeUnparser.d.ts +2 -2
  38. package/build/dalvikBytecodeUnparser.js +23 -23
  39. package/build/dalvikBytecodeUnparser.test.js +7 -7
  40. package/build/dalvikExecutable.d.ts +3 -3
  41. package/build/dalvikExecutable.test-d.d.ts +1 -0
  42. package/build/dalvikExecutable.test-d.js +59 -0
  43. package/build/dalvikExecutableParser/typedNumbers.d.ts +18 -0
  44. package/build/dalvikExecutableParser/typedNumbers.js +3 -0
  45. package/build/dalvikExecutableParser.d.ts +2 -1
  46. package/build/dalvikExecutableParser.js +96 -77
  47. package/build/dalvikExecutableParser.test.js +24 -3
  48. package/build/dalvikExecutableParserAgainstSmaliParser.test.js +3 -0
  49. package/build/dalvikExecutableUnparser/poolScanners.d.ts +2 -2
  50. package/build/dalvikExecutableUnparser/sectionUnparsers.d.ts +3 -3
  51. package/build/dalvikExecutableUnparser/sectionUnparsers.js +26 -11
  52. package/build/dalvikExecutableUnparser.d.ts +2 -2
  53. package/build/dalvikExecutableUnparser.test.js +2 -1
  54. package/build/disjunctionParser.d.ts +5 -3
  55. package/build/disjunctionParser.js +79 -17
  56. package/build/disjunctionParser.test-d.d.ts +1 -0
  57. package/build/disjunctionParser.test-d.js +72 -0
  58. package/build/elementSwitchParser.d.ts +4 -0
  59. package/build/{exactElementSwitchParser.js → elementSwitchParser.js} +3 -4
  60. package/build/elementSwitchParser.test-d.d.ts +1 -0
  61. package/build/elementSwitchParser.test-d.js +44 -0
  62. package/build/exactSequenceParser.d.ts +4 -2
  63. package/build/exactSequenceParser.test-d.d.ts +1 -0
  64. package/build/exactSequenceParser.test-d.js +36 -0
  65. package/build/fetchCid.js +2 -66
  66. package/build/index.d.ts +25 -2
  67. package/build/index.js +23 -1
  68. package/build/index.test.js +16 -1
  69. package/build/inputReader.d.ts +10 -0
  70. package/build/inputReader.js +36 -0
  71. package/build/java.d.ts +502 -0
  72. package/build/java.js +2 -0
  73. package/build/javaKeyStoreParser.js +14 -17
  74. package/build/javaParser.d.ts +51 -0
  75. package/build/javaParser.js +1538 -0
  76. package/build/javaParser.test.d.ts +1 -0
  77. package/build/javaParser.test.js +1287 -0
  78. package/build/javaScript.d.ts +35 -0
  79. package/build/javaScript.js +1 -0
  80. package/build/javaScriptParser.d.ts +9 -0
  81. package/build/javaScriptParser.js +34 -0
  82. package/build/javaScriptUnparser.d.ts +3 -0
  83. package/build/javaScriptUnparser.js +4 -0
  84. package/build/javaScriptUnparser.test.d.ts +1 -0
  85. package/build/javaScriptUnparser.test.js +24 -0
  86. package/build/javaUnparser.d.ts +2 -0
  87. package/build/javaUnparser.js +519 -0
  88. package/build/javaUnparser.test.d.ts +1 -0
  89. package/build/javaUnparser.test.js +24 -0
  90. package/build/javascript.d.ts +35 -0
  91. package/build/javascript.js +1 -0
  92. package/build/javascriptParser.d.ts +9 -0
  93. package/build/javascriptParser.js +34 -0
  94. package/build/javascriptUnparser.d.ts +3 -0
  95. package/build/javascriptUnparser.js +4 -0
  96. package/build/javascriptUnparser.test.d.ts +1 -0
  97. package/build/javascriptUnparser.test.js +24 -0
  98. package/build/jsonParser.js +2 -12
  99. package/build/lazyMessageError.d.ts +3 -0
  100. package/build/lookaheadParser.js +60 -3
  101. package/build/negativeLookaheadParser.js +70 -11
  102. package/build/nonEmptyArrayParser.js +72 -13
  103. package/build/objectParser.d.ts +12 -0
  104. package/build/objectParser.js +31 -0
  105. package/build/objectParser.test-d.d.ts +1 -0
  106. package/build/objectParser.test-d.js +112 -0
  107. package/build/objectParser.test.d.ts +1 -0
  108. package/build/objectParser.test.js +55 -0
  109. package/build/optionalParser.js +69 -10
  110. package/build/parser.d.ts +4 -0
  111. package/build/parser.js +3 -1
  112. package/build/parser.test.js +114 -1
  113. package/build/parserConsumedSequenceParser.js +66 -7
  114. package/build/parserContext.d.ts +6 -0
  115. package/build/parserContext.js +20 -11
  116. package/build/parserError.d.ts +119 -27
  117. package/build/parserError.js +16 -8
  118. package/build/regexpParser.d.ts +2 -0
  119. package/build/regexpParser.js +101 -0
  120. package/build/regexpParser.test.d.ts +1 -0
  121. package/build/regexpParser.test.js +114 -0
  122. package/build/regularExpression.d.ts +63 -0
  123. package/build/regularExpression.js +1 -0
  124. package/build/regularExpressionParser.d.ts +3 -0
  125. package/build/regularExpressionParser.js +600 -0
  126. package/build/regularExpressionParser.test.d.ts +1 -0
  127. package/build/regularExpressionParser.test.js +89 -0
  128. package/build/separatedArrayParser.js +73 -14
  129. package/build/separatedNonEmptyArrayParser.js +73 -14
  130. package/build/sliceBoundedParser.js +62 -5
  131. package/build/smaliParser.d.ts +7 -7
  132. package/build/smaliParser.js +185 -268
  133. package/build/smaliParser.test.js +58 -0
  134. package/build/stringEscapes.d.ts +5 -0
  135. package/build/stringEscapes.js +244 -0
  136. package/build/symbolicExpression.d.ts +29 -0
  137. package/build/symbolicExpression.js +1 -0
  138. package/build/symbolicExpressionParser.d.ts +4 -0
  139. package/build/symbolicExpressionParser.js +123 -0
  140. package/build/symbolicExpressionParser.test.d.ts +1 -0
  141. package/build/symbolicExpressionParser.test.js +289 -0
  142. package/build/terminatedArrayParser.js +113 -38
  143. package/build/terminatedArrayParser.test.js +4 -2
  144. package/build/tupleParser.d.ts +7 -15
  145. package/build/tupleParser.js +1 -0
  146. package/build/unionParser.d.ts +5 -3
  147. package/build/unionParser.js +7 -2
  148. package/build/unionParser.test-d.d.ts +1 -0
  149. package/build/unionParser.test-d.js +72 -0
  150. package/build/unionParser.test.js +10 -11
  151. package/build/zig.d.ts +280 -0
  152. package/build/zig.js +2 -0
  153. package/build/zigParser.d.ts +3 -0
  154. package/build/zigParser.js +1119 -0
  155. package/build/zigParser.test.d.ts +1 -0
  156. package/build/zigParser.test.js +1590 -0
  157. package/build/zigUnparser.d.ts +2 -0
  158. package/build/zigUnparser.js +460 -0
  159. package/build/zigUnparser.test.d.ts +1 -0
  160. package/build/zigUnparser.test.js +24 -0
  161. package/build/zipParser.js +19 -32
  162. package/build/zipUnparser.js +19 -7
  163. package/build/zipUnparser.test.js +1 -1
  164. package/node_modules-@types/s-expression/index.d.ts +5 -0
  165. package/package.json +25 -6
  166. package/src/androidPackageParser.ts +33 -60
  167. package/src/arbitraryDalvikBytecode.ts +39 -31
  168. package/src/arbitraryDalvikExecutable.ts +65 -20
  169. package/src/arbitraryJava.ts +804 -0
  170. package/src/arbitraryJavaScript.ts +410 -0
  171. package/src/arbitraryZig.ts +380 -0
  172. package/src/arrayParser.ts +1 -3
  173. package/src/backsmali.ts +35 -4
  174. package/src/bash.ts +127 -0
  175. package/src/bashParser.test.ts +590 -0
  176. package/src/bashParser.ts +498 -0
  177. package/src/dalvikBytecodeParser/addressConversion.ts +496 -0
  178. package/src/dalvikBytecodeParser/formatParsers.ts +19 -29
  179. package/src/dalvikBytecodeParser.test-d.ts +310 -0
  180. package/src/dalvikBytecodeParser.ts +194 -69
  181. package/src/dalvikBytecodeUnparser/formatUnparsers.ts +27 -26
  182. package/src/dalvikBytecodeUnparser.test.ts +7 -7
  183. package/src/dalvikBytecodeUnparser.ts +31 -30
  184. package/src/dalvikExecutable.test-d.ts +132 -0
  185. package/src/dalvikExecutable.ts +3 -3
  186. package/src/dalvikExecutableParser/typedNumbers.ts +11 -0
  187. package/src/dalvikExecutableParser.test.ts +37 -3
  188. package/src/dalvikExecutableParser.test.ts.md +163 -2
  189. package/src/dalvikExecutableParser.test.ts.snap +0 -0
  190. package/src/dalvikExecutableParser.ts +121 -139
  191. package/src/dalvikExecutableParserAgainstSmaliParser.test.ts +4 -0
  192. package/src/dalvikExecutableUnparser/poolScanners.ts +6 -6
  193. package/src/dalvikExecutableUnparser/sectionUnparsers.ts +38 -14
  194. package/src/dalvikExecutableUnparser.test.ts +3 -2
  195. package/src/dalvikExecutableUnparser.ts +4 -4
  196. package/src/disjunctionParser.test-d.ts +105 -0
  197. package/src/disjunctionParser.ts +18 -15
  198. package/src/elementSwitchParser.test-d.ts +74 -0
  199. package/src/elementSwitchParser.ts +51 -0
  200. package/src/exactSequenceParser.test-d.ts +43 -0
  201. package/src/exactSequenceParser.ts +13 -8
  202. package/src/fetchCid.ts +2 -76
  203. package/src/index.test.ts +22 -1
  204. package/src/index.ts +119 -2
  205. package/src/inputReader.ts +53 -0
  206. package/src/java.ts +708 -0
  207. package/src/javaKeyStoreParser.ts +18 -32
  208. package/src/javaParser.test.ts +1592 -0
  209. package/src/javaParser.ts +2640 -0
  210. package/src/javaScript.ts +36 -0
  211. package/src/javaScriptParser.ts +57 -0
  212. package/src/javaScriptUnparser.test.ts +37 -0
  213. package/src/javaScriptUnparser.ts +7 -0
  214. package/src/javaUnparser.test.ts +37 -0
  215. package/src/javaUnparser.ts +640 -0
  216. package/src/jsonParser.ts +6 -27
  217. package/src/lookaheadParser.ts +2 -6
  218. package/src/negativeLookaheadParser.ts +1 -3
  219. package/src/nonEmptyArrayParser.ts +1 -3
  220. package/src/objectParser.test-d.ts +152 -0
  221. package/src/objectParser.test.ts +71 -0
  222. package/src/objectParser.ts +69 -0
  223. package/src/optionalParser.ts +1 -3
  224. package/src/parser.test.ts +151 -4
  225. package/src/parser.ts +11 -1
  226. package/src/parserConsumedSequenceParser.ts +2 -4
  227. package/src/parserContext.ts +26 -11
  228. package/src/parserError.ts +17 -3
  229. package/src/regexpParser.test.ts +264 -0
  230. package/src/regexpParser.ts +126 -0
  231. package/src/regularExpression.ts +24 -0
  232. package/src/regularExpressionParser.test.ts +102 -0
  233. package/src/regularExpressionParser.ts +920 -0
  234. package/src/separatedArrayParser.ts +1 -3
  235. package/src/separatedNonEmptyArrayParser.ts +1 -3
  236. package/src/sliceBoundedParser.test.ts +2 -2
  237. package/src/sliceBoundedParser.ts +15 -19
  238. package/src/smaliParser.test.ts +64 -0
  239. package/src/smaliParser.test.ts.md +12 -12
  240. package/src/smaliParser.test.ts.snap +0 -0
  241. package/src/smaliParser.ts +246 -534
  242. package/src/stringEscapes.ts +253 -0
  243. package/src/symbolicExpression.ts +17 -0
  244. package/src/symbolicExpressionParser.test.ts +466 -0
  245. package/src/symbolicExpressionParser.ts +190 -0
  246. package/src/terminatedArrayParser.test.ts +9 -6
  247. package/src/terminatedArrayParser.ts +25 -29
  248. package/src/tupleParser.ts +21 -18
  249. package/src/unionParser.test-d.ts +105 -0
  250. package/src/unionParser.test.ts +18 -17
  251. package/src/unionParser.ts +28 -16
  252. package/src/zig.ts +411 -0
  253. package/src/zigParser.test.ts +1693 -0
  254. package/src/zigParser.ts +1745 -0
  255. package/src/zigUnparser.test.ts +37 -0
  256. package/src/zigUnparser.ts +615 -0
  257. package/src/zipParser.ts +20 -56
  258. package/src/zipUnparser.test.ts +1 -1
  259. package/src/zipUnparser.ts +22 -7
  260. package/tsconfig.json +2 -2
  261. package/build/exactElementSwitchParser.d.ts +0 -3
  262. package/src/exactElementSwitchParser.ts +0 -41
@@ -0,0 +1,532 @@
1
+ import * as fc from 'fast-check';
2
+ const javaKeywords = new Set([
3
+ 'abstract', 'assert', 'boolean', 'break', 'byte', 'case', 'catch', 'char',
4
+ 'class', 'const', 'continue', 'default', 'do', 'double', 'else', 'enum',
5
+ 'extends', 'final', 'finally', 'float', 'for', 'goto', 'if', 'implements',
6
+ 'import', 'instanceof', 'int', 'interface', 'long', 'native', 'new',
7
+ 'package', 'private', 'protected', 'public', 'return', 'short', 'static',
8
+ 'strictfp', 'super', 'switch', 'synchronized', 'this', 'throw', 'throws',
9
+ 'transient', 'try', 'void', 'volatile', 'while', 'true', 'false', 'null',
10
+ 'sealed', 'non-sealed', 'record', 'yield', 'var',
11
+ ]);
12
+ const arbitraryJavaIdentifier = fc.stringMatching(/^[a-zA-Z_][a-zA-Z0-9_]*$/).filter(id => !javaKeywords.has(id));
13
+ const arbitrarySimpleName = fc.record({
14
+ type: fc.constant('SimpleName'),
15
+ identifier: arbitraryJavaIdentifier,
16
+ });
17
+ const arbitraryName = fc.nat({ max: 2 }).chain(depth => {
18
+ if (depth === 0) {
19
+ return fc.record({
20
+ type: fc.constant('Name'),
21
+ identifier: arbitraryJavaIdentifier,
22
+ });
23
+ }
24
+ return arbitraryJavaIdentifier.chain(identifier => {
25
+ const buildQualifier = (d) => {
26
+ if (d === 0) {
27
+ return fc.record({
28
+ type: fc.constant('Name'),
29
+ identifier: arbitraryJavaIdentifier,
30
+ });
31
+ }
32
+ return fc.record({
33
+ type: fc.constant('Name'),
34
+ identifier: arbitraryJavaIdentifier,
35
+ qualifier: buildQualifier(d - 1),
36
+ });
37
+ };
38
+ return fc.record({
39
+ type: fc.constant('Name'),
40
+ identifier: fc.constant(identifier),
41
+ qualifier: buildQualifier(depth - 1),
42
+ });
43
+ });
44
+ });
45
+ // Types
46
+ const arbitraryPrimitiveType = fc.record({
47
+ type: fc.constant('PrimitiveType'),
48
+ type_: fc.oneof(fc.constant('BOOLEAN'), fc.constant('BYTE'), fc.constant('CHAR'), fc.constant('DOUBLE'), fc.constant('FLOAT'), fc.constant('INT'), fc.constant('LONG'), fc.constant('SHORT')),
49
+ annotations: fc.constant([]),
50
+ });
51
+ const arbitraryVoidType = fc.record({
52
+ type: fc.constant('VoidType'),
53
+ annotations: fc.constant([]),
54
+ });
55
+ const arbitraryAnnotation = fc.record({
56
+ type: fc.constant('MarkerAnnotationExpr'),
57
+ name: arbitraryName,
58
+ });
59
+ const arbitraryClassOrInterfaceType = fc.nat({ max: 1 }).chain(depth => {
60
+ const buildType = (d) => {
61
+ if (d === 0) {
62
+ return fc.record({
63
+ type: fc.constant('ClassOrInterfaceType'),
64
+ name: arbitrarySimpleName,
65
+ annotations: fc.constant([]),
66
+ });
67
+ }
68
+ return fc.record({
69
+ type: fc.constant('ClassOrInterfaceType'),
70
+ scope: buildType(d - 1),
71
+ name: arbitrarySimpleName,
72
+ annotations: fc.constant([]),
73
+ });
74
+ };
75
+ return buildType(depth);
76
+ });
77
+ // ClassOrInterfaceType with optional type arguments (for extends/implements)
78
+ const arbitraryClassOrInterfaceTypeWithTypeArgs = fc.nat({ max: 1 }).chain(depth => {
79
+ const buildType = (d) => {
80
+ const baseFields = {
81
+ type: fc.constant('ClassOrInterfaceType'),
82
+ name: arbitrarySimpleName,
83
+ annotations: fc.constant([]),
84
+ };
85
+ if (d === 0) {
86
+ return fc.oneof(fc.record(baseFields), fc.record({
87
+ ...baseFields,
88
+ typeArguments: fc.array(fc.oneof(arbitraryPrimitiveType, fc.record({
89
+ type: fc.constant('ClassOrInterfaceType'),
90
+ name: arbitrarySimpleName,
91
+ annotations: fc.constant([]),
92
+ }), fc.record({
93
+ type: fc.constant('WildcardType'),
94
+ annotations: fc.constant([]),
95
+ })), { minLength: 1, maxLength: 2 }),
96
+ }));
97
+ }
98
+ return fc.record({
99
+ ...baseFields,
100
+ scope: buildType(d - 1),
101
+ });
102
+ };
103
+ return buildType(depth);
104
+ });
105
+ const arbitraryNonArrayType = fc.oneof(arbitraryPrimitiveType, arbitraryClassOrInterfaceType);
106
+ const arbitraryType = fc.oneof({ weight: 3, arbitrary: arbitraryNonArrayType }, {
107
+ weight: 1,
108
+ arbitrary: arbitraryNonArrayType.map(componentType => ({
109
+ type: 'ArrayType',
110
+ componentType,
111
+ origin: 'TYPE',
112
+ annotations: [],
113
+ })),
114
+ });
115
+ const arbitraryReturnType = fc.oneof({ weight: 3, arbitrary: arbitraryType }, { weight: 1, arbitrary: arbitraryVoidType });
116
+ // Leaf expressions (used as operands in compound expressions to avoid precedence issues)
117
+ const arbitraryNameExpr = fc.record({
118
+ type: fc.constant('NameExpr'),
119
+ name: arbitrarySimpleName,
120
+ });
121
+ const arbitraryStringLiteralExpr = fc.record({
122
+ type: fc.constant('StringLiteralExpr'),
123
+ value: fc.oneof(fc.stringMatching(/^[a-zA-Z0-9 ]*$/), fc.constantFrom('hello\nworld', 'tab\there', 'back\\slash', 'quote\ttab\nnewline')),
124
+ });
125
+ const arbitraryIntegerLiteralExpr = fc.record({
126
+ type: fc.constant('IntegerLiteralExpr'),
127
+ value: fc.nat({ max: 999 }).map(n => String(n)),
128
+ });
129
+ const arbitraryNullLiteralExpr = fc.record({
130
+ type: fc.constant('NullLiteralExpr'),
131
+ });
132
+ const arbitraryBooleanLiteralExpr = fc.record({
133
+ type: fc.constant('BooleanLiteralExpr'),
134
+ value: fc.boolean(),
135
+ });
136
+ const arbitraryThisExpr = fc.record({
137
+ type: fc.constant('ThisExpr'),
138
+ });
139
+ const arbitraryLeafExpression = fc.oneof(arbitraryNameExpr, arbitraryStringLiteralExpr, arbitraryIntegerLiteralExpr, arbitraryNullLiteralExpr, arbitraryBooleanLiteralExpr, arbitraryThisExpr);
140
+ // Compound expressions (only use leaf operands)
141
+ const arbitraryMethodCallExpr = fc.oneof(
142
+ // Without scope
143
+ fc.record({
144
+ type: fc.constant('MethodCallExpr'),
145
+ name: arbitrarySimpleName,
146
+ arguments: fc.array(arbitraryLeafExpression, { maxLength: 2 }),
147
+ }),
148
+ // With scope
149
+ fc.record({
150
+ type: fc.constant('MethodCallExpr'),
151
+ scope: arbitraryLeafExpression,
152
+ name: arbitrarySimpleName,
153
+ arguments: fc.array(arbitraryLeafExpression, { maxLength: 2 }),
154
+ }));
155
+ const arbitraryFieldAccessExpr = fc.record({
156
+ type: fc.constant('FieldAccessExpr'),
157
+ scope: arbitraryLeafExpression,
158
+ name: arbitrarySimpleName,
159
+ });
160
+ const arbitraryEnclosedExpr = fc.record({
161
+ type: fc.constant('EnclosedExpr'),
162
+ inner: arbitraryLeafExpression,
163
+ });
164
+ const arbitraryArrayAccessExpr = fc.record({
165
+ type: fc.constant('ArrayAccessExpr'),
166
+ name: arbitraryLeafExpression,
167
+ index: arbitraryLeafExpression,
168
+ });
169
+ const arbitraryObjectCreationExpr = fc.oneof(fc.record({
170
+ type: fc.constant('ObjectCreationExpr'),
171
+ type_: arbitraryClassOrInterfaceType,
172
+ arguments: fc.array(arbitraryLeafExpression, { maxLength: 2 }),
173
+ }),
174
+ // With diamond operator (empty typeArguments)
175
+ fc.record({
176
+ type: fc.constant('ObjectCreationExpr'),
177
+ type_: arbitraryClassOrInterfaceType.map(t => ({
178
+ ...t,
179
+ typeArguments: [],
180
+ })),
181
+ arguments: fc.array(arbitraryLeafExpression, { maxLength: 2 }),
182
+ }));
183
+ const arbitraryPrimaryExpression = fc.oneof(arbitraryLeafExpression, arbitraryMethodCallExpr, arbitraryFieldAccessExpr, arbitraryEnclosedExpr, arbitraryArrayAccessExpr, arbitraryObjectCreationExpr);
184
+ const arbitraryBinaryOperator = fc.oneof(fc.constant('PLUS'), fc.constant('MINUS'), fc.constant('MULTIPLY'), fc.constant('DIVIDE'), fc.constant('REMAINDER'), fc.constant('LESS'), fc.constant('GREATER'), fc.constant('LESS_EQUALS'), fc.constant('GREATER_EQUALS'), fc.constant('EQUALS'), fc.constant('NOT_EQUALS'), fc.constant('AND'), fc.constant('OR'));
185
+ const arbitraryBinaryExpr = fc.record({
186
+ type: fc.constant('BinaryExpr'),
187
+ left: arbitraryLeafExpression,
188
+ right: arbitraryLeafExpression,
189
+ operator: arbitraryBinaryOperator,
190
+ });
191
+ // UnaryExpr in parser output has NO prefix field - operator encodes prefix/postfix
192
+ const arbitraryUnaryExpr = fc.record({
193
+ type: fc.constant('UnaryExpr'),
194
+ operator: fc.oneof(fc.constant('PREFIX_INCREMENT'), fc.constant('PREFIX_DECREMENT'), fc.constant('POSTFIX_INCREMENT'), fc.constant('POSTFIX_DECREMENT'), fc.constant('MINUS'), fc.constant('PLUS'), fc.constant('LOGICAL_COMPLEMENT')),
195
+ expression: arbitraryLeafExpression,
196
+ });
197
+ const arbitraryAssignOperator = fc.oneof(fc.constant('ASSIGN'), fc.constant('PLUS'), fc.constant('MINUS'), fc.constant('MULTIPLY'), fc.constant('DIVIDE'));
198
+ const arbitraryAssignExpr = fc.record({
199
+ type: fc.constant('AssignExpr'),
200
+ target: arbitraryNameExpr,
201
+ value: arbitraryLeafExpression,
202
+ operator: arbitraryAssignOperator,
203
+ });
204
+ const arbitraryConditionalExpr = fc.record({
205
+ type: fc.constant('ConditionalExpr'),
206
+ condition: arbitraryLeafExpression,
207
+ thenExpr: arbitraryLeafExpression,
208
+ elseExpr: arbitraryLeafExpression,
209
+ });
210
+ const arbitraryCastExpr = fc.record({
211
+ type: fc.constant('CastExpr'),
212
+ type_: arbitraryType,
213
+ expression: arbitraryPrimaryExpression,
214
+ });
215
+ const arbitraryInstanceOfExpr = fc.record({
216
+ type: fc.constant('InstanceOfExpr'),
217
+ expression: arbitraryLeafExpression,
218
+ type_: fc.oneof(arbitraryClassOrInterfaceType, arbitraryNonArrayType.map(componentType => ({
219
+ type: 'ArrayType',
220
+ componentType,
221
+ origin: 'TYPE',
222
+ annotations: [],
223
+ }))),
224
+ });
225
+ // Lambda expressions
226
+ const arbitraryLambdaExpr = fc.oneof(
227
+ // With parenthesized params
228
+ fc.record({
229
+ type: fc.constant('LambdaExpr'),
230
+ parameters: fc.array(fc.record({
231
+ type: fc.constant('Parameter'),
232
+ annotations: fc.constant([]),
233
+ modifiers: fc.constant([]),
234
+ isVarArgs: fc.constant(false),
235
+ varArgsAnnotations: fc.constant([]),
236
+ name: arbitrarySimpleName,
237
+ type_: fc.constant({ type: 'UnknownType', annotations: [] }),
238
+ }), { maxLength: 2 }),
239
+ body: fc.oneof(
240
+ // Expression body (wrapped in ExpressionStmt)
241
+ arbitraryLeafExpression.map(expr => ({
242
+ type: 'ExpressionStmt',
243
+ expression: expr,
244
+ })),
245
+ // Block body
246
+ fc.constant({ type: 'BlockStmt', statements: [] })),
247
+ isEnclosingParameters: fc.constant(true),
248
+ }),
249
+ // Single unparenthesized param
250
+ fc.record({
251
+ type: fc.constant('LambdaExpr'),
252
+ parameters: arbitrarySimpleName.map(name => ([{
253
+ type: 'Parameter',
254
+ annotations: [],
255
+ modifiers: [],
256
+ isVarArgs: false,
257
+ varArgsAnnotations: [],
258
+ name,
259
+ type_: { type: 'UnknownType', annotations: [] },
260
+ }])),
261
+ body: fc.oneof(arbitraryLeafExpression.map(expr => ({
262
+ type: 'ExpressionStmt',
263
+ expression: expr,
264
+ })), fc.constant({ type: 'BlockStmt', statements: [] })),
265
+ isEnclosingParameters: fc.constant(false),
266
+ }));
267
+ const arbitraryExpression = fc.oneof({ weight: 4, arbitrary: arbitraryLeafExpression }, { weight: 1, arbitrary: arbitraryBinaryExpr }, { weight: 1, arbitrary: arbitraryUnaryExpr }, { weight: 1, arbitrary: arbitraryAssignExpr }, { weight: 1, arbitrary: arbitraryConditionalExpr }, { weight: 1, arbitrary: arbitraryCastExpr }, { weight: 1, arbitrary: arbitraryEnclosedExpr }, { weight: 1, arbitrary: arbitraryMethodCallExpr }, { weight: 1, arbitrary: arbitraryFieldAccessExpr }, { weight: 1, arbitrary: arbitraryObjectCreationExpr }, { weight: 1, arbitrary: arbitraryArrayAccessExpr }, { weight: 1, arbitrary: arbitraryInstanceOfExpr }, { weight: 1, arbitrary: arbitraryLambdaExpr });
268
+ // Variable declarations
269
+ const arbitraryVariableDeclarator = fc.record({
270
+ type: fc.constant('VariableDeclarator'),
271
+ name: arbitrarySimpleName,
272
+ type_: arbitraryType,
273
+ }).chain(base => fc.oneof(fc.constant(base), arbitraryLeafExpression.map(init => ({
274
+ ...base,
275
+ initializer: init,
276
+ }))));
277
+ const arbitraryVariableDeclarationExpr = arbitraryType.chain(type_ => fc.record({
278
+ type: fc.constant('VariableDeclarationExpr'),
279
+ modifiers: fc.constant([]),
280
+ annotations: fc.constant([]),
281
+ variables: fc.array(fc.record({
282
+ type: fc.constant('VariableDeclarator'),
283
+ name: arbitrarySimpleName,
284
+ type_: fc.constant(type_),
285
+ }).chain(base => fc.oneof(fc.constant(base), arbitraryLeafExpression.map(init => ({
286
+ ...base,
287
+ initializer: init,
288
+ })))), { minLength: 1, maxLength: 2 }),
289
+ }));
290
+ // Statements
291
+ const arbitraryBlockStmt = fc.record({
292
+ type: fc.constant('BlockStmt'),
293
+ statements: fc.constant([]),
294
+ });
295
+ const arbitraryExpressionStmt = fc.record({
296
+ type: fc.constant('ExpressionStmt'),
297
+ expression: arbitraryExpression,
298
+ });
299
+ const arbitraryReturnStmt = fc.oneof(fc.constant({ type: 'ReturnStmt' }), fc.record({
300
+ type: fc.constant('ReturnStmt'),
301
+ expression: arbitraryExpression,
302
+ }));
303
+ const arbitraryThrowStmt = fc.record({
304
+ type: fc.constant('ThrowStmt'),
305
+ expression: arbitraryExpression,
306
+ });
307
+ const arbitraryIfStmt = fc.oneof(fc.record({
308
+ type: fc.constant('IfStmt'),
309
+ condition: arbitraryExpression,
310
+ thenStmt: arbitraryBlockStmt,
311
+ }), fc.record({
312
+ type: fc.constant('IfStmt'),
313
+ condition: arbitraryExpression,
314
+ thenStmt: arbitraryBlockStmt,
315
+ elseStmt: arbitraryBlockStmt,
316
+ }));
317
+ const arbitraryForStmt = fc.oneof(
318
+ // Empty for
319
+ fc.record({
320
+ type: fc.constant('ForStmt'),
321
+ initialization: fc.constant([]),
322
+ update: fc.constant([]),
323
+ body: arbitraryBlockStmt,
324
+ }),
325
+ // For with init and compare
326
+ fc.record({
327
+ type: fc.constant('ForStmt'),
328
+ initialization: fc.array(arbitraryVariableDeclarationExpr, { minLength: 1, maxLength: 1 }),
329
+ compare: arbitraryExpression,
330
+ update: fc.array(arbitraryExpression, { maxLength: 2 }),
331
+ body: arbitraryBlockStmt,
332
+ }));
333
+ const arbitraryForEachStmt = fc.record({
334
+ type: fc.constant('ForEachStmt'),
335
+ variable: arbitraryVariableDeclarationExpr,
336
+ iterable: arbitraryExpression,
337
+ body: arbitraryBlockStmt,
338
+ });
339
+ const arbitraryParameter = fc.record({
340
+ type: fc.constant('Parameter'),
341
+ modifiers: fc.constant([]),
342
+ annotations: fc.constant([]),
343
+ type_: arbitraryType,
344
+ isVarArgs: fc.constant(false),
345
+ varArgsAnnotations: fc.constant([]),
346
+ name: arbitrarySimpleName,
347
+ });
348
+ const arbitraryCatchClause = fc.record({
349
+ type: fc.constant('CatchClause'),
350
+ parameter: arbitraryParameter,
351
+ body: fc.record({
352
+ type: fc.constant('BlockStmt'),
353
+ statements: fc.constant([]),
354
+ }),
355
+ });
356
+ const arbitraryTryStmt = fc.oneof(
357
+ // try-catch
358
+ fc.record({
359
+ type: fc.constant('TryStmt'),
360
+ resources: fc.constant([]),
361
+ tryBlock: fc.record({
362
+ type: fc.constant('BlockStmt'),
363
+ statements: fc.constant([]),
364
+ }),
365
+ catchClauses: fc.array(arbitraryCatchClause, { minLength: 1, maxLength: 2 }),
366
+ }),
367
+ // try-catch-finally
368
+ fc.record({
369
+ type: fc.constant('TryStmt'),
370
+ resources: fc.constant([]),
371
+ tryBlock: fc.record({
372
+ type: fc.constant('BlockStmt'),
373
+ statements: fc.constant([]),
374
+ }),
375
+ catchClauses: fc.array(arbitraryCatchClause, { maxLength: 1 }),
376
+ finallyBlock: fc.record({
377
+ type: fc.constant('BlockStmt'),
378
+ statements: fc.constant([]),
379
+ }),
380
+ }),
381
+ // try-with-resources
382
+ fc.record({
383
+ type: fc.constant('TryStmt'),
384
+ resources: fc.array(arbitraryVariableDeclarationExpr, { minLength: 1, maxLength: 1 }),
385
+ tryBlock: fc.record({
386
+ type: fc.constant('BlockStmt'),
387
+ statements: fc.constant([]),
388
+ }),
389
+ catchClauses: fc.constant([]),
390
+ }));
391
+ const arbitrarySwitchEntry = fc.oneof(
392
+ // case
393
+ fc.record({
394
+ type: fc.constant('SwitchEntry'),
395
+ isDefault: fc.constant(false),
396
+ labels: fc.array(arbitraryExpression, { minLength: 1, maxLength: 1 }),
397
+ statements: fc.constant([]),
398
+ type_: fc.constant('STATEMENT_GROUP'),
399
+ }),
400
+ // default
401
+ fc.record({
402
+ type: fc.constant('SwitchEntry'),
403
+ isDefault: fc.constant(true),
404
+ labels: fc.constant([]),
405
+ statements: fc.constant([]),
406
+ type_: fc.constant('STATEMENT_GROUP'),
407
+ }));
408
+ const arbitrarySwitchStmt = fc.record({
409
+ type: fc.constant('SwitchStmt'),
410
+ selector: arbitraryExpression,
411
+ entries: fc.array(arbitrarySwitchEntry, { maxLength: 3 }),
412
+ });
413
+ const arbitraryExplicitConstructorInvocationStmt = fc.record({
414
+ type: fc.constant('ExplicitConstructorInvocationStmt'),
415
+ isThis: fc.boolean(),
416
+ arguments: fc.array(arbitraryLeafExpression, { maxLength: 2 }),
417
+ });
418
+ const arbitraryLocalVarDeclStmt = fc.record({
419
+ type: fc.constant('ExpressionStmt'),
420
+ expression: arbitraryVariableDeclarationExpr,
421
+ });
422
+ const arbitraryStatement = fc.oneof({ weight: 2, arbitrary: arbitraryBlockStmt }, { weight: 2, arbitrary: arbitraryExpressionStmt }, { weight: 2, arbitrary: arbitraryReturnStmt }, { weight: 1, arbitrary: arbitraryThrowStmt }, { weight: 1, arbitrary: arbitraryIfStmt }, { weight: 1, arbitrary: arbitraryForStmt }, { weight: 1, arbitrary: arbitraryForEachStmt }, { weight: 1, arbitrary: arbitraryTryStmt }, { weight: 1, arbitrary: arbitrarySwitchStmt }, { weight: 1, arbitrary: arbitraryExplicitConstructorInvocationStmt }, { weight: 1, arbitrary: arbitraryLocalVarDeclStmt });
423
+ // Body declarations
424
+ const arbitraryModifier = fc.record({
425
+ type: fc.constant('Modifier'),
426
+ keyword: fc.oneof(fc.constant('PUBLIC'), fc.constant('PROTECTED'), fc.constant('PRIVATE'), fc.constant('STATIC'), fc.constant('FINAL'), fc.constant('ABSTRACT')),
427
+ });
428
+ const arbitraryFieldDeclaration = arbitraryType.chain(type_ => fc.record({
429
+ type: fc.constant('FieldDeclaration'),
430
+ modifiers: fc.array(arbitraryModifier, { maxLength: 2 }),
431
+ annotations: fc.array(arbitraryAnnotation, { maxLength: 1 }),
432
+ variables: fc.array(fc.record({
433
+ type: fc.constant('VariableDeclarator'),
434
+ name: arbitrarySimpleName,
435
+ type_: fc.constant(type_),
436
+ }).chain(base => fc.oneof(fc.constant(base), arbitraryLeafExpression.map(init => ({
437
+ ...base,
438
+ initializer: init,
439
+ })))), { minLength: 1, maxLength: 2 }),
440
+ }));
441
+ const arbitraryMethodDeclaration = fc.oneof(
442
+ // Method with body
443
+ fc.record({
444
+ type: fc.constant('MethodDeclaration'),
445
+ modifiers: fc.array(arbitraryModifier, { maxLength: 2 }),
446
+ annotations: fc.array(arbitraryAnnotation, { maxLength: 1 }),
447
+ typeParameters: fc.constant([]),
448
+ type_: arbitraryReturnType,
449
+ name: arbitrarySimpleName,
450
+ parameters: fc.array(arbitraryParameter, { maxLength: 2 }),
451
+ thrownExceptions: fc.constant([]),
452
+ body: fc.record({
453
+ type: fc.constant('BlockStmt'),
454
+ statements: fc.array(arbitraryStatement, { maxLength: 2 }),
455
+ }),
456
+ }),
457
+ // Abstract method (no body)
458
+ fc.record({
459
+ type: fc.constant('MethodDeclaration'),
460
+ modifiers: fc.array(arbitraryModifier, { maxLength: 2 }),
461
+ annotations: fc.array(arbitraryAnnotation, { maxLength: 1 }),
462
+ typeParameters: fc.constant([]),
463
+ type_: arbitraryReturnType,
464
+ name: arbitrarySimpleName,
465
+ parameters: fc.array(arbitraryParameter, { maxLength: 2 }),
466
+ thrownExceptions: fc.constant([]),
467
+ }));
468
+ const arbitraryConstructorDeclaration = fc.record({
469
+ type: fc.constant('ConstructorDeclaration'),
470
+ modifiers: fc.array(arbitraryModifier, { maxLength: 1 }),
471
+ annotations: fc.constant([]),
472
+ typeParameters: fc.constant([]),
473
+ name: arbitrarySimpleName,
474
+ parameters: fc.array(arbitraryParameter, { maxLength: 2 }),
475
+ thrownExceptions: fc.constant([]),
476
+ body: fc.record({
477
+ type: fc.constant('BlockStmt'),
478
+ statements: fc.array(arbitraryStatement, { maxLength: 2 }),
479
+ }),
480
+ });
481
+ const arbitraryBodyDeclaration = fc.oneof({ weight: 2, arbitrary: arbitraryFieldDeclaration }, { weight: 2, arbitrary: arbitraryMethodDeclaration }, { weight: 1, arbitrary: arbitraryConstructorDeclaration });
482
+ // Type declarations
483
+ const arbitraryEnumDeclaration = fc.record({
484
+ type: fc.constant('EnumDeclaration'),
485
+ modifiers: fc.array(arbitraryModifier, { maxLength: 2 }),
486
+ annotations: fc.array(arbitraryAnnotation, { maxLength: 1 }),
487
+ name: arbitrarySimpleName,
488
+ implementedTypes: fc.constant([]),
489
+ entries: fc.constant([]),
490
+ members: fc.constant([]),
491
+ });
492
+ const arbitraryClassOrInterfaceDeclaration = fc.boolean().chain(isInterface => fc.record({
493
+ type: fc.constant('ClassOrInterfaceDeclaration'),
494
+ modifiers: fc.array(arbitraryModifier, { maxLength: 2 }),
495
+ annotations: fc.array(arbitraryAnnotation, { maxLength: 1 }),
496
+ name: arbitrarySimpleName,
497
+ isInterface: fc.constant(isInterface),
498
+ typeParameters: fc.oneof(fc.constant([]), fc.array(fc.record({
499
+ type: fc.constant('TypeParameter'),
500
+ annotations: fc.constant([]),
501
+ name: arbitrarySimpleName,
502
+ typeBound: fc.constant([]),
503
+ }), { minLength: 1, maxLength: 2 })),
504
+ extendedTypes: fc.oneof(fc.constant([]), fc.array(arbitraryClassOrInterfaceTypeWithTypeArgs, { minLength: 1, maxLength: 1 })),
505
+ // Interfaces always have implementedTypes: [] (parser outputs empty array for interfaces)
506
+ implementedTypes: isInterface
507
+ ? fc.constant([])
508
+ : fc.oneof(fc.constant([]), fc.array(arbitraryClassOrInterfaceTypeWithTypeArgs, { minLength: 1, maxLength: 2 })),
509
+ permittedTypes: fc.constant([]),
510
+ members: fc.array(arbitraryBodyDeclaration, { maxLength: 3 }),
511
+ }));
512
+ const arbitraryTypeDeclaration = fc.oneof({ weight: 3, arbitrary: arbitraryClassOrInterfaceDeclaration }, { weight: 1, arbitrary: arbitraryEnumDeclaration });
513
+ // Import declaration
514
+ const arbitraryImportDeclaration = fc.record({
515
+ type: fc.constant('ImportDeclaration'),
516
+ isStatic: fc.boolean(),
517
+ isAsterisk: fc.boolean(),
518
+ name: arbitraryName,
519
+ });
520
+ // Package declaration
521
+ const arbitraryPackageDeclaration = fc.record({
522
+ type: fc.constant('PackageDeclaration'),
523
+ annotations: fc.array(arbitraryAnnotation, { maxLength: 1 }),
524
+ name: arbitraryName,
525
+ });
526
+ // Compilation unit
527
+ export const arbitraryJavaCompilationUnit = fc.record({
528
+ type: fc.constant('CompilationUnit'),
529
+ packageDeclaration: fc.option(arbitraryPackageDeclaration, { nil: undefined }),
530
+ imports: fc.array(arbitraryImportDeclaration, { maxLength: 2 }),
531
+ types: fc.array(arbitraryTypeDeclaration, { minLength: 1, maxLength: 2 }),
532
+ });
@@ -0,0 +1,3 @@
1
+ import * as fc from 'fast-check';
2
+ import { type JavaScriptProgram } from './javaScriptParser.js';
3
+ export declare const arbitraryJavaScriptProgram: fc.Arbitrary<JavaScriptProgram>;