@futpib/parser 1.0.4 → 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 (250) 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 +6 -1
  20. package/build/bashParser.js +131 -90
  21. package/build/bashParser.test.js +162 -0
  22. package/build/bashParserEdgeCases.test.d.ts +1 -0
  23. package/build/bashParserEdgeCases.test.js +117 -0
  24. package/build/dalvikBytecodeParser/addressConversion.d.ts +110 -0
  25. package/build/dalvikBytecodeParser/addressConversion.js +334 -0
  26. package/build/dalvikBytecodeParser/formatParsers.d.ts +7 -6
  27. package/build/dalvikBytecodeParser/formatParsers.js +13 -14
  28. package/build/dalvikBytecodeParser.d.ts +60 -31
  29. package/build/dalvikBytecodeParser.js +92 -35
  30. package/build/dalvikBytecodeParser.test-d.d.ts +1 -0
  31. package/build/dalvikBytecodeParser.test-d.js +268 -0
  32. package/build/dalvikBytecodeUnparser/formatUnparsers.d.ts +9 -8
  33. package/build/dalvikBytecodeUnparser/formatUnparsers.js +13 -12
  34. package/build/dalvikBytecodeUnparser.d.ts +2 -2
  35. package/build/dalvikBytecodeUnparser.js +23 -23
  36. package/build/dalvikBytecodeUnparser.test.js +7 -7
  37. package/build/dalvikExecutable.d.ts +3 -3
  38. package/build/dalvikExecutable.test-d.d.ts +1 -0
  39. package/build/dalvikExecutable.test-d.js +59 -0
  40. package/build/dalvikExecutableParser/typedNumbers.d.ts +18 -0
  41. package/build/dalvikExecutableParser/typedNumbers.js +3 -0
  42. package/build/dalvikExecutableParser.d.ts +2 -1
  43. package/build/dalvikExecutableParser.js +96 -77
  44. package/build/dalvikExecutableParser.test.js +24 -3
  45. package/build/dalvikExecutableParserAgainstSmaliParser.test.js +3 -0
  46. package/build/dalvikExecutableUnparser/poolScanners.d.ts +2 -2
  47. package/build/dalvikExecutableUnparser/sectionUnparsers.d.ts +3 -3
  48. package/build/dalvikExecutableUnparser/sectionUnparsers.js +26 -11
  49. package/build/dalvikExecutableUnparser.d.ts +2 -2
  50. package/build/dalvikExecutableUnparser.test.js +2 -1
  51. package/build/disjunctionParser.d.ts +5 -3
  52. package/build/disjunctionParser.js +79 -17
  53. package/build/disjunctionParser.test-d.d.ts +1 -0
  54. package/build/disjunctionParser.test-d.js +72 -0
  55. package/build/elementSwitchParser.d.ts +4 -0
  56. package/build/{exactElementSwitchParser.js → elementSwitchParser.js} +3 -4
  57. package/build/elementSwitchParser.test-d.d.ts +1 -0
  58. package/build/elementSwitchParser.test-d.js +44 -0
  59. package/build/exactSequenceParser.d.ts +4 -2
  60. package/build/exactSequenceParser.test-d.d.ts +1 -0
  61. package/build/exactSequenceParser.test-d.js +36 -0
  62. package/build/fetchCid.js +2 -66
  63. package/build/index.d.ts +3 -2
  64. package/build/index.js +2 -1
  65. package/build/index.test.js +16 -1
  66. package/build/inputReader.d.ts +10 -0
  67. package/build/inputReader.js +36 -0
  68. package/build/java.d.ts +502 -0
  69. package/build/java.js +2 -0
  70. package/build/javaKeyStoreParser.js +14 -17
  71. package/build/javaParser.d.ts +51 -0
  72. package/build/javaParser.js +1538 -0
  73. package/build/javaParser.test.d.ts +1 -0
  74. package/build/javaParser.test.js +1287 -0
  75. package/build/javaScript.d.ts +35 -0
  76. package/build/javaScript.js +1 -0
  77. package/build/javaScriptParser.d.ts +9 -0
  78. package/build/javaScriptParser.js +34 -0
  79. package/build/javaScriptUnparser.d.ts +3 -0
  80. package/build/javaScriptUnparser.js +4 -0
  81. package/build/javaScriptUnparser.test.d.ts +1 -0
  82. package/build/javaScriptUnparser.test.js +24 -0
  83. package/build/javaUnparser.d.ts +2 -0
  84. package/build/javaUnparser.js +519 -0
  85. package/build/javaUnparser.test.d.ts +1 -0
  86. package/build/javaUnparser.test.js +24 -0
  87. package/build/javascript.d.ts +35 -0
  88. package/build/javascript.js +1 -0
  89. package/build/javascriptParser.d.ts +9 -0
  90. package/build/javascriptParser.js +34 -0
  91. package/build/javascriptUnparser.d.ts +3 -0
  92. package/build/javascriptUnparser.js +4 -0
  93. package/build/javascriptUnparser.test.d.ts +1 -0
  94. package/build/javascriptUnparser.test.js +24 -0
  95. package/build/jsonParser.js +2 -12
  96. package/build/lazyMessageError.d.ts +3 -0
  97. package/build/lookaheadParser.js +60 -3
  98. package/build/negativeLookaheadParser.js +70 -11
  99. package/build/nonEmptyArrayParser.js +72 -13
  100. package/build/objectParser.d.ts +12 -0
  101. package/build/objectParser.js +31 -0
  102. package/build/objectParser.test-d.d.ts +1 -0
  103. package/build/objectParser.test-d.js +112 -0
  104. package/build/objectParser.test.d.ts +1 -0
  105. package/build/objectParser.test.js +55 -0
  106. package/build/optionalParser.js +69 -10
  107. package/build/parser.d.ts +4 -0
  108. package/build/parser.js +3 -1
  109. package/build/parser.test.js +114 -1
  110. package/build/parserConsumedSequenceParser.js +66 -7
  111. package/build/parserContext.d.ts +6 -0
  112. package/build/parserContext.js +20 -11
  113. package/build/parserError.d.ts +119 -27
  114. package/build/parserError.js +16 -8
  115. package/build/regexpParser.js +33 -3
  116. package/build/regexpParser.test.js +31 -0
  117. package/build/regularExpressionParser.js +35 -15
  118. package/build/separatedArrayParser.js +73 -14
  119. package/build/separatedNonEmptyArrayParser.js +73 -14
  120. package/build/sliceBoundedParser.js +62 -5
  121. package/build/smaliParser.d.ts +7 -7
  122. package/build/smaliParser.js +185 -268
  123. package/build/smaliParser.test.js +58 -0
  124. package/build/stringEscapes.d.ts +5 -0
  125. package/build/stringEscapes.js +244 -0
  126. package/build/symbolicExpression.d.ts +29 -0
  127. package/build/symbolicExpression.js +1 -0
  128. package/build/symbolicExpressionParser.d.ts +4 -0
  129. package/build/symbolicExpressionParser.js +123 -0
  130. package/build/symbolicExpressionParser.test.d.ts +1 -0
  131. package/build/symbolicExpressionParser.test.js +289 -0
  132. package/build/terminatedArrayParser.js +113 -38
  133. package/build/terminatedArrayParser.test.js +4 -2
  134. package/build/tupleParser.d.ts +7 -15
  135. package/build/tupleParser.js +1 -0
  136. package/build/unionParser.d.ts +5 -3
  137. package/build/unionParser.js +7 -2
  138. package/build/unionParser.test-d.d.ts +1 -0
  139. package/build/unionParser.test-d.js +72 -0
  140. package/build/unionParser.test.js +10 -11
  141. package/build/zig.d.ts +280 -0
  142. package/build/zig.js +2 -0
  143. package/build/zigParser.d.ts +3 -0
  144. package/build/zigParser.js +1119 -0
  145. package/build/zigParser.test.d.ts +1 -0
  146. package/build/zigParser.test.js +1590 -0
  147. package/build/zigUnparser.d.ts +2 -0
  148. package/build/zigUnparser.js +460 -0
  149. package/build/zigUnparser.test.d.ts +1 -0
  150. package/build/zigUnparser.test.js +24 -0
  151. package/build/zipParser.js +19 -32
  152. package/build/zipUnparser.js +19 -7
  153. package/build/zipUnparser.test.js +1 -1
  154. package/node_modules-@types/s-expression/index.d.ts +5 -0
  155. package/package.json +24 -6
  156. package/src/androidPackageParser.ts +33 -60
  157. package/src/arbitraryDalvikBytecode.ts +39 -31
  158. package/src/arbitraryDalvikExecutable.ts +65 -20
  159. package/src/arbitraryJava.ts +804 -0
  160. package/src/arbitraryJavaScript.ts +410 -0
  161. package/src/arbitraryZig.ts +380 -0
  162. package/src/arrayParser.ts +1 -3
  163. package/src/backsmali.ts +35 -4
  164. package/src/bash.ts +8 -1
  165. package/src/bashParser.test.ts +258 -0
  166. package/src/bashParser.ts +180 -143
  167. package/src/dalvikBytecodeParser/addressConversion.ts +496 -0
  168. package/src/dalvikBytecodeParser/formatParsers.ts +19 -29
  169. package/src/dalvikBytecodeParser.test-d.ts +310 -0
  170. package/src/dalvikBytecodeParser.ts +194 -69
  171. package/src/dalvikBytecodeUnparser/formatUnparsers.ts +27 -26
  172. package/src/dalvikBytecodeUnparser.test.ts +7 -7
  173. package/src/dalvikBytecodeUnparser.ts +31 -30
  174. package/src/dalvikExecutable.test-d.ts +132 -0
  175. package/src/dalvikExecutable.ts +3 -3
  176. package/src/dalvikExecutableParser/typedNumbers.ts +11 -0
  177. package/src/dalvikExecutableParser.test.ts +37 -3
  178. package/src/dalvikExecutableParser.test.ts.md +163 -2
  179. package/src/dalvikExecutableParser.test.ts.snap +0 -0
  180. package/src/dalvikExecutableParser.ts +121 -139
  181. package/src/dalvikExecutableParserAgainstSmaliParser.test.ts +4 -0
  182. package/src/dalvikExecutableUnparser/poolScanners.ts +6 -6
  183. package/src/dalvikExecutableUnparser/sectionUnparsers.ts +38 -14
  184. package/src/dalvikExecutableUnparser.test.ts +3 -2
  185. package/src/dalvikExecutableUnparser.ts +4 -4
  186. package/src/disjunctionParser.test-d.ts +105 -0
  187. package/src/disjunctionParser.ts +18 -15
  188. package/src/elementSwitchParser.test-d.ts +74 -0
  189. package/src/elementSwitchParser.ts +51 -0
  190. package/src/exactSequenceParser.test-d.ts +43 -0
  191. package/src/exactSequenceParser.ts +13 -8
  192. package/src/fetchCid.ts +2 -76
  193. package/src/index.test.ts +22 -1
  194. package/src/index.ts +7 -1
  195. package/src/inputReader.ts +53 -0
  196. package/src/java.ts +708 -0
  197. package/src/javaKeyStoreParser.ts +18 -32
  198. package/src/javaParser.test.ts +1592 -0
  199. package/src/javaParser.ts +2640 -0
  200. package/src/javaScript.ts +36 -0
  201. package/src/javaScriptParser.ts +57 -0
  202. package/src/javaScriptUnparser.test.ts +37 -0
  203. package/src/javaScriptUnparser.ts +7 -0
  204. package/src/javaUnparser.test.ts +37 -0
  205. package/src/javaUnparser.ts +640 -0
  206. package/src/jsonParser.ts +6 -27
  207. package/src/lookaheadParser.ts +2 -6
  208. package/src/negativeLookaheadParser.ts +1 -3
  209. package/src/nonEmptyArrayParser.ts +1 -3
  210. package/src/objectParser.test-d.ts +152 -0
  211. package/src/objectParser.test.ts +71 -0
  212. package/src/objectParser.ts +69 -0
  213. package/src/optionalParser.ts +1 -3
  214. package/src/parser.test.ts +151 -4
  215. package/src/parser.ts +11 -1
  216. package/src/parserConsumedSequenceParser.ts +2 -4
  217. package/src/parserContext.ts +26 -11
  218. package/src/parserError.ts +17 -3
  219. package/src/regexpParser.test.ts +78 -0
  220. package/src/regexpParser.ts +35 -3
  221. package/src/regularExpressionParser.ts +36 -37
  222. package/src/separatedArrayParser.ts +1 -3
  223. package/src/separatedNonEmptyArrayParser.ts +1 -3
  224. package/src/sliceBoundedParser.test.ts +2 -2
  225. package/src/sliceBoundedParser.ts +15 -19
  226. package/src/smaliParser.test.ts +64 -0
  227. package/src/smaliParser.test.ts.md +12 -12
  228. package/src/smaliParser.test.ts.snap +0 -0
  229. package/src/smaliParser.ts +246 -534
  230. package/src/stringEscapes.ts +253 -0
  231. package/src/symbolicExpression.ts +17 -0
  232. package/src/symbolicExpressionParser.test.ts +466 -0
  233. package/src/symbolicExpressionParser.ts +190 -0
  234. package/src/terminatedArrayParser.test.ts +9 -6
  235. package/src/terminatedArrayParser.ts +25 -29
  236. package/src/tupleParser.ts +21 -18
  237. package/src/unionParser.test-d.ts +105 -0
  238. package/src/unionParser.test.ts +18 -17
  239. package/src/unionParser.ts +28 -16
  240. package/src/zig.ts +411 -0
  241. package/src/zigParser.test.ts +1693 -0
  242. package/src/zigParser.ts +1745 -0
  243. package/src/zigUnparser.test.ts +37 -0
  244. package/src/zigUnparser.ts +615 -0
  245. package/src/zipParser.ts +20 -56
  246. package/src/zipUnparser.test.ts +1 -1
  247. package/src/zipUnparser.ts +22 -7
  248. package/tsconfig.json +2 -2
  249. package/build/exactElementSwitchParser.d.ts +0 -3
  250. package/src/exactElementSwitchParser.ts +0 -41
@@ -0,0 +1,263 @@
1
+ import * as fc from 'fast-check';
2
+ const jsKeywords = new Set([
3
+ 'abstract', 'arguments', 'await', 'boolean', 'break', 'byte', 'case', 'catch',
4
+ 'char', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do',
5
+ 'double', 'else', 'enum', 'eval', 'export', 'extends', 'false', 'final',
6
+ 'finally', 'float', 'for', 'function', 'goto', 'if', 'implements', 'import',
7
+ 'in', 'instanceof', 'int', 'interface', 'let', 'long', 'native', 'new',
8
+ 'null', 'package', 'private', 'protected', 'public', 'return', 'short',
9
+ 'static', 'super', 'switch', 'synchronized', 'this', 'throw', 'throws',
10
+ 'transient', 'true', 'try', 'typeof', 'var', 'void', 'volatile', 'while',
11
+ 'with', 'yield', 'undefined', 'NaN', 'Infinity',
12
+ ]);
13
+ const arbitraryIdentifierName = fc.stringMatching(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/).filter(id => !jsKeywords.has(id));
14
+ const arbitraryIdentifier = fc.record({
15
+ type: fc.constant('Identifier'),
16
+ name: arbitraryIdentifierName,
17
+ });
18
+ const arbitraryStringLiteral = fc.record({
19
+ type: fc.constant('Literal'),
20
+ value: fc.stringMatching(/^[a-zA-Z0-9 ]*$/),
21
+ });
22
+ const arbitraryNumberLiteral = fc.record({
23
+ type: fc.constant('Literal'),
24
+ value: fc.integer({ min: 0, max: 999 }),
25
+ });
26
+ const arbitraryBooleanLiteral = fc.record({
27
+ type: fc.constant('Literal'),
28
+ value: fc.boolean(),
29
+ });
30
+ const arbitraryNullLiteral = fc.record({
31
+ type: fc.constant('Literal'),
32
+ value: fc.constant(null),
33
+ });
34
+ const arbitraryThisExpression = fc.record({
35
+ type: fc.constant('ThisExpression'),
36
+ });
37
+ const arbitraryLeafExpression = fc.oneof(arbitraryIdentifier, arbitraryStringLiteral, arbitraryNumberLiteral, arbitraryBooleanLiteral, arbitraryNullLiteral, arbitraryThisExpression);
38
+ const safeBinaryOperators = [
39
+ '==', '!=', '===', '!==', '<', '<=', '>', '>=',
40
+ '<<', '>>', '>>>',
41
+ '+', '-', '*', '/', '%', '**',
42
+ '|', '^', '&',
43
+ 'instanceof',
44
+ ];
45
+ const arbitraryBinaryExpression = fc.record({
46
+ type: fc.constant('BinaryExpression'),
47
+ operator: fc.oneof(...safeBinaryOperators.map(op => fc.constant(op))),
48
+ left: arbitraryLeafExpression,
49
+ right: arbitraryLeafExpression,
50
+ });
51
+ const arbitraryLogicalExpression = fc.record({
52
+ type: fc.constant('LogicalExpression'),
53
+ operator: fc.oneof(fc.constant('||'), fc.constant('&&'), fc.constant('??')),
54
+ left: arbitraryLeafExpression,
55
+ right: arbitraryLeafExpression,
56
+ });
57
+ const safeUnaryOperators = [
58
+ '-', '+', '!', '~', 'typeof', 'void',
59
+ ];
60
+ const arbitraryUnaryExpression = fc.record({
61
+ type: fc.constant('UnaryExpression'),
62
+ operator: fc.oneof(...safeUnaryOperators.map(op => fc.constant(op))),
63
+ prefix: fc.constant(true),
64
+ argument: arbitraryLeafExpression,
65
+ });
66
+ const arbitraryUpdateExpression = fc.record({
67
+ type: fc.constant('UpdateExpression'),
68
+ operator: fc.oneof(fc.constant('++'), fc.constant('--')),
69
+ argument: arbitraryIdentifier,
70
+ prefix: fc.boolean(),
71
+ });
72
+ const arbitraryAssignmentExpression = fc.record({
73
+ type: fc.constant('AssignmentExpression'),
74
+ operator: fc.constant('='),
75
+ left: arbitraryIdentifier,
76
+ right: arbitraryLeafExpression,
77
+ });
78
+ const arbitraryConditionalExpression = fc.record({
79
+ type: fc.constant('ConditionalExpression'),
80
+ test: arbitraryLeafExpression,
81
+ consequent: arbitraryLeafExpression,
82
+ alternate: arbitraryLeafExpression,
83
+ });
84
+ const arbitraryCallExpression = fc.record({
85
+ type: fc.constant('CallExpression'),
86
+ callee: arbitraryIdentifier,
87
+ arguments: fc.array(arbitraryLeafExpression, { minLength: 0, maxLength: 3 }),
88
+ optional: fc.constant(false),
89
+ });
90
+ const arbitraryMemberExpression = fc.record({
91
+ type: fc.constant('MemberExpression'),
92
+ object: arbitraryIdentifier,
93
+ property: arbitraryIdentifier,
94
+ computed: fc.constant(false),
95
+ optional: fc.constant(false),
96
+ });
97
+ const arbitraryArrayExpression = fc.record({
98
+ type: fc.constant('ArrayExpression'),
99
+ elements: fc.array(arbitraryLeafExpression, { minLength: 0, maxLength: 3 }),
100
+ });
101
+ const arbitraryProperty = fc.record({
102
+ type: fc.constant('Property'),
103
+ key: arbitraryIdentifier,
104
+ value: arbitraryLeafExpression,
105
+ kind: fc.constant('init'),
106
+ method: fc.constant(false),
107
+ shorthand: fc.constant(false),
108
+ computed: fc.constant(false),
109
+ });
110
+ const arbitraryObjectExpression = fc.record({
111
+ type: fc.constant('ObjectExpression'),
112
+ properties: fc.array(arbitraryProperty, { minLength: 0, maxLength: 3 }),
113
+ });
114
+ const arbitraryNewExpression = fc.record({
115
+ type: fc.constant('NewExpression'),
116
+ callee: arbitraryIdentifier,
117
+ arguments: fc.array(arbitraryLeafExpression, { minLength: 0, maxLength: 3 }),
118
+ });
119
+ const arbitraryExpression = fc.oneof({ weight: 5, arbitrary: arbitraryLeafExpression }, { weight: 2, arbitrary: arbitraryBinaryExpression }, { weight: 2, arbitrary: arbitraryLogicalExpression }, { weight: 2, arbitrary: arbitraryUnaryExpression }, { weight: 1, arbitrary: arbitraryUpdateExpression }, { weight: 1, arbitrary: arbitraryAssignmentExpression }, { weight: 1, arbitrary: arbitraryConditionalExpression }, { weight: 2, arbitrary: arbitraryCallExpression }, { weight: 1, arbitrary: arbitraryMemberExpression }, { weight: 1, arbitrary: arbitraryArrayExpression }, { weight: 1, arbitrary: arbitraryObjectExpression }, { weight: 1, arbitrary: arbitraryNewExpression });
120
+ const arbitraryExpressionStatement = arbitraryExpression
121
+ .filter(expr => {
122
+ if (expr.type === 'Literal' && typeof expr.value === 'string') {
123
+ return false;
124
+ }
125
+ if (expr.type === 'ObjectExpression') {
126
+ return false;
127
+ }
128
+ return true;
129
+ })
130
+ .map(expression => ({
131
+ type: 'ExpressionStatement',
132
+ expression,
133
+ }));
134
+ const arbitraryVariableDeclaration = fc.record({
135
+ type: fc.constant('VariableDeclaration'),
136
+ kind: fc.constant('var'),
137
+ declarations: fc.array(fc.record({
138
+ type: fc.constant('VariableDeclarator'),
139
+ id: arbitraryIdentifier,
140
+ init: fc.oneof(fc.constant(null), arbitraryLeafExpression),
141
+ }), { minLength: 1, maxLength: 3 }),
142
+ });
143
+ const arbitraryReturnStatement = fc.record({
144
+ type: fc.constant('ReturnStatement'),
145
+ argument: fc.oneof(fc.constant(null), arbitraryLeafExpression),
146
+ });
147
+ const arbitraryEmptyStatement = fc.record({
148
+ type: fc.constant('EmptyStatement'),
149
+ });
150
+ const arbitraryThrowStatement = fc.record({
151
+ type: fc.constant('ThrowStatement'),
152
+ argument: arbitraryLeafExpression,
153
+ });
154
+ const arbitrarySimpleNonFunctionStatement = fc.oneof({ weight: 3, arbitrary: arbitraryExpressionStatement }, { weight: 2, arbitrary: arbitraryVariableDeclaration }, { weight: 1, arbitrary: arbitraryEmptyStatement }, { weight: 1, arbitrary: arbitraryThrowStatement });
155
+ const arbitrarySimpleBlockStatement = fc.record({
156
+ type: fc.constant('BlockStatement'),
157
+ body: fc.array(arbitrarySimpleNonFunctionStatement, { minLength: 0, maxLength: 3 }),
158
+ });
159
+ const arbitraryFunctionBodyStatement = fc.oneof({ weight: 3, arbitrary: arbitraryExpressionStatement }, { weight: 2, arbitrary: arbitraryVariableDeclaration }, { weight: 2, arbitrary: arbitraryReturnStatement }, { weight: 1, arbitrary: arbitraryEmptyStatement }, { weight: 1, arbitrary: arbitraryThrowStatement });
160
+ const arbitraryFunctionBodyBlockStatement = fc.record({
161
+ type: fc.constant('BlockStatement'),
162
+ body: fc.array(arbitraryFunctionBodyStatement, { minLength: 0, maxLength: 3 }),
163
+ });
164
+ const arbitraryArrowFunctionExpression = fc.oneof(fc.record({
165
+ type: fc.constant('ArrowFunctionExpression'),
166
+ id: fc.constant(null),
167
+ params: fc.array(arbitraryIdentifier, { minLength: 0, maxLength: 3 }),
168
+ body: arbitraryFunctionBodyBlockStatement,
169
+ expression: fc.constant(false),
170
+ generator: fc.constant(false),
171
+ async: fc.constant(false),
172
+ }), fc.record({
173
+ type: fc.constant('ArrowFunctionExpression'),
174
+ id: fc.constant(null),
175
+ params: fc.array(arbitraryIdentifier, { minLength: 0, maxLength: 3 }),
176
+ body: arbitraryLeafExpression,
177
+ expression: fc.constant(true),
178
+ generator: fc.constant(false),
179
+ async: fc.constant(false),
180
+ }));
181
+ const arbitraryFunctionExpression = fc.record({
182
+ type: fc.constant('FunctionExpression'),
183
+ id: fc.constant(null),
184
+ params: fc.array(arbitraryIdentifier, { minLength: 0, maxLength: 3 }),
185
+ body: arbitraryFunctionBodyBlockStatement,
186
+ expression: fc.constant(false),
187
+ generator: fc.constant(false),
188
+ async: fc.constant(false),
189
+ });
190
+ const arbitraryIfStatement = fc.record({
191
+ type: fc.constant('IfStatement'),
192
+ test: arbitraryLeafExpression,
193
+ consequent: arbitrarySimpleBlockStatement,
194
+ alternate: fc.oneof(fc.constant(null), arbitrarySimpleBlockStatement),
195
+ });
196
+ const arbitraryWhileStatement = fc.record({
197
+ type: fc.constant('WhileStatement'),
198
+ test: arbitraryLeafExpression,
199
+ body: arbitrarySimpleBlockStatement,
200
+ });
201
+ const arbitraryForStatement = fc.record({
202
+ type: fc.constant('ForStatement'),
203
+ init: fc.oneof(fc.constant(null), fc.record({
204
+ type: fc.constant('VariableDeclaration'),
205
+ kind: fc.constant('let'),
206
+ declarations: fc.tuple(fc.record({
207
+ type: fc.constant('VariableDeclarator'),
208
+ id: arbitraryIdentifier,
209
+ init: fc.oneof(fc.constant(null), arbitraryNumberLiteral),
210
+ })).map(([decl]) => [decl]),
211
+ })),
212
+ test: fc.oneof(fc.constant(null), arbitraryLeafExpression),
213
+ update: fc.oneof(fc.constant(null), arbitraryLeafExpression),
214
+ body: arbitrarySimpleBlockStatement,
215
+ });
216
+ const arbitraryCatchClause = fc.record({
217
+ type: fc.constant('CatchClause'),
218
+ param: fc.oneof(fc.constant(null), arbitraryIdentifier),
219
+ body: arbitrarySimpleBlockStatement,
220
+ });
221
+ const arbitraryTryStatement = fc.oneof(fc.record({
222
+ type: fc.constant('TryStatement'),
223
+ block: arbitrarySimpleBlockStatement,
224
+ handler: arbitraryCatchClause,
225
+ finalizer: fc.oneof(fc.constant(null), arbitrarySimpleBlockStatement),
226
+ }), fc.record({
227
+ type: fc.constant('TryStatement'),
228
+ block: arbitrarySimpleBlockStatement,
229
+ handler: fc.constant(null),
230
+ finalizer: arbitrarySimpleBlockStatement,
231
+ }));
232
+ const arbitraryFunctionDeclaration = fc.record({
233
+ type: fc.constant('FunctionDeclaration'),
234
+ id: arbitraryIdentifier,
235
+ params: fc.array(arbitraryIdentifier, { minLength: 0, maxLength: 3 }),
236
+ body: arbitraryFunctionBodyBlockStatement,
237
+ expression: fc.constant(false),
238
+ generator: fc.constant(false),
239
+ async: fc.constant(false),
240
+ });
241
+ const arbitraryTopLevelExpressionStatement = fc.oneof(arbitraryExpression, arbitraryArrowFunctionExpression, arbitraryFunctionExpression)
242
+ .filter(expr => {
243
+ if (expr.type === 'Literal' && typeof expr.value === 'string') {
244
+ return false;
245
+ }
246
+ if (expr.type === 'ObjectExpression') {
247
+ return false;
248
+ }
249
+ if (expr.type === 'FunctionExpression') {
250
+ return false;
251
+ }
252
+ return true;
253
+ })
254
+ .map(expression => ({
255
+ type: 'ExpressionStatement',
256
+ expression,
257
+ }));
258
+ const arbitraryStatement = fc.oneof({ weight: 3, arbitrary: arbitraryTopLevelExpressionStatement }, { weight: 2, arbitrary: arbitraryVariableDeclaration }, { weight: 2, arbitrary: arbitraryIfStatement }, { weight: 1, arbitrary: arbitraryWhileStatement }, { weight: 1, arbitrary: arbitraryForStatement }, { weight: 1, arbitrary: arbitraryEmptyStatement }, { weight: 1, arbitrary: arbitraryFunctionDeclaration }, { weight: 1, arbitrary: arbitraryThrowStatement }, { weight: 1, arbitrary: arbitraryTryStatement });
259
+ export const arbitraryJavaScriptProgram = fc.record({
260
+ type: fc.constant('Program'),
261
+ sourceType: fc.constant('script'),
262
+ body: fc.array(arbitraryStatement, { minLength: 0, maxLength: 5 }),
263
+ });
@@ -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>;
@@ -0,0 +1,263 @@
1
+ import * as fc from 'fast-check';
2
+ const jsKeywords = new Set([
3
+ 'abstract', 'arguments', 'await', 'boolean', 'break', 'byte', 'case', 'catch',
4
+ 'char', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do',
5
+ 'double', 'else', 'enum', 'eval', 'export', 'extends', 'false', 'final',
6
+ 'finally', 'float', 'for', 'function', 'goto', 'if', 'implements', 'import',
7
+ 'in', 'instanceof', 'int', 'interface', 'let', 'long', 'native', 'new',
8
+ 'null', 'package', 'private', 'protected', 'public', 'return', 'short',
9
+ 'static', 'super', 'switch', 'synchronized', 'this', 'throw', 'throws',
10
+ 'transient', 'true', 'try', 'typeof', 'var', 'void', 'volatile', 'while',
11
+ 'with', 'yield', 'undefined', 'NaN', 'Infinity',
12
+ ]);
13
+ const arbitraryIdentifierName = fc.stringMatching(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/).filter(id => !jsKeywords.has(id));
14
+ const arbitraryIdentifier = fc.record({
15
+ type: fc.constant('Identifier'),
16
+ name: arbitraryIdentifierName,
17
+ });
18
+ const arbitraryStringLiteral = fc.record({
19
+ type: fc.constant('Literal'),
20
+ value: fc.stringMatching(/^[a-zA-Z0-9 ]*$/),
21
+ });
22
+ const arbitraryNumberLiteral = fc.record({
23
+ type: fc.constant('Literal'),
24
+ value: fc.integer({ min: 0, max: 999 }),
25
+ });
26
+ const arbitraryBooleanLiteral = fc.record({
27
+ type: fc.constant('Literal'),
28
+ value: fc.boolean(),
29
+ });
30
+ const arbitraryNullLiteral = fc.record({
31
+ type: fc.constant('Literal'),
32
+ value: fc.constant(null),
33
+ });
34
+ const arbitraryThisExpression = fc.record({
35
+ type: fc.constant('ThisExpression'),
36
+ });
37
+ const arbitraryLeafExpression = fc.oneof(arbitraryIdentifier, arbitraryStringLiteral, arbitraryNumberLiteral, arbitraryBooleanLiteral, arbitraryNullLiteral, arbitraryThisExpression);
38
+ const safeBinaryOperators = [
39
+ '==', '!=', '===', '!==', '<', '<=', '>', '>=',
40
+ '<<', '>>', '>>>',
41
+ '+', '-', '*', '/', '%', '**',
42
+ '|', '^', '&',
43
+ 'instanceof',
44
+ ];
45
+ const arbitraryBinaryExpression = fc.record({
46
+ type: fc.constant('BinaryExpression'),
47
+ operator: fc.oneof(...safeBinaryOperators.map(op => fc.constant(op))),
48
+ left: arbitraryLeafExpression,
49
+ right: arbitraryLeafExpression,
50
+ });
51
+ const arbitraryLogicalExpression = fc.record({
52
+ type: fc.constant('LogicalExpression'),
53
+ operator: fc.oneof(fc.constant('||'), fc.constant('&&'), fc.constant('??')),
54
+ left: arbitraryLeafExpression,
55
+ right: arbitraryLeafExpression,
56
+ });
57
+ const safeUnaryOperators = [
58
+ '-', '+', '!', '~', 'typeof', 'void',
59
+ ];
60
+ const arbitraryUnaryExpression = fc.record({
61
+ type: fc.constant('UnaryExpression'),
62
+ operator: fc.oneof(...safeUnaryOperators.map(op => fc.constant(op))),
63
+ prefix: fc.constant(true),
64
+ argument: arbitraryLeafExpression,
65
+ });
66
+ const arbitraryUpdateExpression = fc.record({
67
+ type: fc.constant('UpdateExpression'),
68
+ operator: fc.oneof(fc.constant('++'), fc.constant('--')),
69
+ argument: arbitraryIdentifier,
70
+ prefix: fc.boolean(),
71
+ });
72
+ const arbitraryAssignmentExpression = fc.record({
73
+ type: fc.constant('AssignmentExpression'),
74
+ operator: fc.constant('='),
75
+ left: arbitraryIdentifier,
76
+ right: arbitraryLeafExpression,
77
+ });
78
+ const arbitraryConditionalExpression = fc.record({
79
+ type: fc.constant('ConditionalExpression'),
80
+ test: arbitraryLeafExpression,
81
+ consequent: arbitraryLeafExpression,
82
+ alternate: arbitraryLeafExpression,
83
+ });
84
+ const arbitraryCallExpression = fc.record({
85
+ type: fc.constant('CallExpression'),
86
+ callee: arbitraryIdentifier,
87
+ arguments: fc.array(arbitraryLeafExpression, { minLength: 0, maxLength: 3 }),
88
+ optional: fc.constant(false),
89
+ });
90
+ const arbitraryMemberExpression = fc.record({
91
+ type: fc.constant('MemberExpression'),
92
+ object: arbitraryIdentifier,
93
+ property: arbitraryIdentifier,
94
+ computed: fc.constant(false),
95
+ optional: fc.constant(false),
96
+ });
97
+ const arbitraryArrayExpression = fc.record({
98
+ type: fc.constant('ArrayExpression'),
99
+ elements: fc.array(arbitraryLeafExpression, { minLength: 0, maxLength: 3 }),
100
+ });
101
+ const arbitraryProperty = fc.record({
102
+ type: fc.constant('Property'),
103
+ key: arbitraryIdentifier,
104
+ value: arbitraryLeafExpression,
105
+ kind: fc.constant('init'),
106
+ method: fc.constant(false),
107
+ shorthand: fc.constant(false),
108
+ computed: fc.constant(false),
109
+ });
110
+ const arbitraryObjectExpression = fc.record({
111
+ type: fc.constant('ObjectExpression'),
112
+ properties: fc.array(arbitraryProperty, { minLength: 0, maxLength: 3 }),
113
+ });
114
+ const arbitraryNewExpression = fc.record({
115
+ type: fc.constant('NewExpression'),
116
+ callee: arbitraryIdentifier,
117
+ arguments: fc.array(arbitraryLeafExpression, { minLength: 0, maxLength: 3 }),
118
+ });
119
+ const arbitraryExpression = fc.oneof({ weight: 5, arbitrary: arbitraryLeafExpression }, { weight: 2, arbitrary: arbitraryBinaryExpression }, { weight: 2, arbitrary: arbitraryLogicalExpression }, { weight: 2, arbitrary: arbitraryUnaryExpression }, { weight: 1, arbitrary: arbitraryUpdateExpression }, { weight: 1, arbitrary: arbitraryAssignmentExpression }, { weight: 1, arbitrary: arbitraryConditionalExpression }, { weight: 2, arbitrary: arbitraryCallExpression }, { weight: 1, arbitrary: arbitraryMemberExpression }, { weight: 1, arbitrary: arbitraryArrayExpression }, { weight: 1, arbitrary: arbitraryObjectExpression }, { weight: 1, arbitrary: arbitraryNewExpression });
120
+ const arbitraryExpressionStatement = arbitraryExpression
121
+ .filter(expr => {
122
+ if (expr.type === 'Literal' && typeof expr.value === 'string') {
123
+ return false;
124
+ }
125
+ if (expr.type === 'ObjectExpression') {
126
+ return false;
127
+ }
128
+ return true;
129
+ })
130
+ .map(expression => ({
131
+ type: 'ExpressionStatement',
132
+ expression,
133
+ }));
134
+ const arbitraryVariableDeclaration = fc.record({
135
+ type: fc.constant('VariableDeclaration'),
136
+ kind: fc.constant('var'),
137
+ declarations: fc.array(fc.record({
138
+ type: fc.constant('VariableDeclarator'),
139
+ id: arbitraryIdentifier,
140
+ init: fc.oneof(fc.constant(null), arbitraryLeafExpression),
141
+ }), { minLength: 1, maxLength: 3 }),
142
+ });
143
+ const arbitraryReturnStatement = fc.record({
144
+ type: fc.constant('ReturnStatement'),
145
+ argument: fc.oneof(fc.constant(null), arbitraryLeafExpression),
146
+ });
147
+ const arbitraryEmptyStatement = fc.record({
148
+ type: fc.constant('EmptyStatement'),
149
+ });
150
+ const arbitraryThrowStatement = fc.record({
151
+ type: fc.constant('ThrowStatement'),
152
+ argument: arbitraryLeafExpression,
153
+ });
154
+ const arbitrarySimpleNonFunctionStatement = fc.oneof({ weight: 3, arbitrary: arbitraryExpressionStatement }, { weight: 2, arbitrary: arbitraryVariableDeclaration }, { weight: 1, arbitrary: arbitraryEmptyStatement }, { weight: 1, arbitrary: arbitraryThrowStatement });
155
+ const arbitrarySimpleBlockStatement = fc.record({
156
+ type: fc.constant('BlockStatement'),
157
+ body: fc.array(arbitrarySimpleNonFunctionStatement, { minLength: 0, maxLength: 3 }),
158
+ });
159
+ const arbitraryFunctionBodyStatement = fc.oneof({ weight: 3, arbitrary: arbitraryExpressionStatement }, { weight: 2, arbitrary: arbitraryVariableDeclaration }, { weight: 2, arbitrary: arbitraryReturnStatement }, { weight: 1, arbitrary: arbitraryEmptyStatement }, { weight: 1, arbitrary: arbitraryThrowStatement });
160
+ const arbitraryFunctionBodyBlockStatement = fc.record({
161
+ type: fc.constant('BlockStatement'),
162
+ body: fc.array(arbitraryFunctionBodyStatement, { minLength: 0, maxLength: 3 }),
163
+ });
164
+ const arbitraryArrowFunctionExpression = fc.oneof(fc.record({
165
+ type: fc.constant('ArrowFunctionExpression'),
166
+ id: fc.constant(null),
167
+ params: fc.array(arbitraryIdentifier, { minLength: 0, maxLength: 3 }),
168
+ body: arbitraryFunctionBodyBlockStatement,
169
+ expression: fc.constant(false),
170
+ generator: fc.constant(false),
171
+ async: fc.constant(false),
172
+ }), fc.record({
173
+ type: fc.constant('ArrowFunctionExpression'),
174
+ id: fc.constant(null),
175
+ params: fc.array(arbitraryIdentifier, { minLength: 0, maxLength: 3 }),
176
+ body: arbitraryLeafExpression,
177
+ expression: fc.constant(true),
178
+ generator: fc.constant(false),
179
+ async: fc.constant(false),
180
+ }));
181
+ const arbitraryFunctionExpression = fc.record({
182
+ type: fc.constant('FunctionExpression'),
183
+ id: fc.constant(null),
184
+ params: fc.array(arbitraryIdentifier, { minLength: 0, maxLength: 3 }),
185
+ body: arbitraryFunctionBodyBlockStatement,
186
+ expression: fc.constant(false),
187
+ generator: fc.constant(false),
188
+ async: fc.constant(false),
189
+ });
190
+ const arbitraryIfStatement = fc.record({
191
+ type: fc.constant('IfStatement'),
192
+ test: arbitraryLeafExpression,
193
+ consequent: arbitrarySimpleBlockStatement,
194
+ alternate: fc.oneof(fc.constant(null), arbitrarySimpleBlockStatement),
195
+ });
196
+ const arbitraryWhileStatement = fc.record({
197
+ type: fc.constant('WhileStatement'),
198
+ test: arbitraryLeafExpression,
199
+ body: arbitrarySimpleBlockStatement,
200
+ });
201
+ const arbitraryForStatement = fc.record({
202
+ type: fc.constant('ForStatement'),
203
+ init: fc.oneof(fc.constant(null), fc.record({
204
+ type: fc.constant('VariableDeclaration'),
205
+ kind: fc.constant('let'),
206
+ declarations: fc.tuple(fc.record({
207
+ type: fc.constant('VariableDeclarator'),
208
+ id: arbitraryIdentifier,
209
+ init: fc.oneof(fc.constant(null), arbitraryNumberLiteral),
210
+ })).map(([decl]) => [decl]),
211
+ })),
212
+ test: fc.oneof(fc.constant(null), arbitraryLeafExpression),
213
+ update: fc.oneof(fc.constant(null), arbitraryLeafExpression),
214
+ body: arbitrarySimpleBlockStatement,
215
+ });
216
+ const arbitraryCatchClause = fc.record({
217
+ type: fc.constant('CatchClause'),
218
+ param: fc.oneof(fc.constant(null), arbitraryIdentifier),
219
+ body: arbitrarySimpleBlockStatement,
220
+ });
221
+ const arbitraryTryStatement = fc.oneof(fc.record({
222
+ type: fc.constant('TryStatement'),
223
+ block: arbitrarySimpleBlockStatement,
224
+ handler: arbitraryCatchClause,
225
+ finalizer: fc.oneof(fc.constant(null), arbitrarySimpleBlockStatement),
226
+ }), fc.record({
227
+ type: fc.constant('TryStatement'),
228
+ block: arbitrarySimpleBlockStatement,
229
+ handler: fc.constant(null),
230
+ finalizer: arbitrarySimpleBlockStatement,
231
+ }));
232
+ const arbitraryFunctionDeclaration = fc.record({
233
+ type: fc.constant('FunctionDeclaration'),
234
+ id: arbitraryIdentifier,
235
+ params: fc.array(arbitraryIdentifier, { minLength: 0, maxLength: 3 }),
236
+ body: arbitraryFunctionBodyBlockStatement,
237
+ expression: fc.constant(false),
238
+ generator: fc.constant(false),
239
+ async: fc.constant(false),
240
+ });
241
+ const arbitraryTopLevelExpressionStatement = fc.oneof(arbitraryExpression, arbitraryArrowFunctionExpression, arbitraryFunctionExpression)
242
+ .filter(expr => {
243
+ if (expr.type === 'Literal' && typeof expr.value === 'string') {
244
+ return false;
245
+ }
246
+ if (expr.type === 'ObjectExpression') {
247
+ return false;
248
+ }
249
+ if (expr.type === 'FunctionExpression') {
250
+ return false;
251
+ }
252
+ return true;
253
+ })
254
+ .map(expression => ({
255
+ type: 'ExpressionStatement',
256
+ expression,
257
+ }));
258
+ const arbitraryStatement = fc.oneof({ weight: 3, arbitrary: arbitraryTopLevelExpressionStatement }, { weight: 2, arbitrary: arbitraryVariableDeclaration }, { weight: 2, arbitrary: arbitraryIfStatement }, { weight: 1, arbitrary: arbitraryWhileStatement }, { weight: 1, arbitrary: arbitraryForStatement }, { weight: 1, arbitrary: arbitraryEmptyStatement }, { weight: 1, arbitrary: arbitraryFunctionDeclaration }, { weight: 1, arbitrary: arbitraryThrowStatement }, { weight: 1, arbitrary: arbitraryTryStatement });
259
+ export const arbitraryJavascriptProgram = fc.record({
260
+ type: fc.constant('Program'),
261
+ sourceType: fc.constant('script'),
262
+ body: fc.array(arbitraryStatement, { minLength: 0, maxLength: 5 }),
263
+ });
@@ -0,0 +1,3 @@
1
+ import * as fc from 'fast-check';
2
+ import { type ZigRoot } from './zig.js';
3
+ export declare const arbitraryZigRoot: fc.Arbitrary<ZigRoot>;