@futpib/parser 1.0.2 → 1.0.3

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 (284) hide show
  1. package/.github/copilot-instructions.md +149 -0
  2. package/.github/workflows/copilot-setup-steps.yml +18 -0
  3. package/.github/workflows/main.yml +29 -8
  4. package/.yarn/releases/yarn-4.9.4.cjs +942 -0
  5. package/.yarnrc.yml +1 -1
  6. package/build/allSettledStream.js +1 -1
  7. package/build/allSettledStream.test.js +2 -2
  8. package/build/androidPackageParser.d.ts +1 -1
  9. package/build/androidPackageParser.js +5 -3
  10. package/build/androidPackageParser.test.js +7 -7
  11. package/build/androidPackageUnparser.d.ts +2 -2
  12. package/build/androidPackageUnparser.js +18 -14
  13. package/build/androidPackageUnparser.test.js +7 -7
  14. package/build/arbitrarilySlicedAsyncInterator.js +2 -1
  15. package/build/arbitraryDalvikBytecode.d.ts +4 -0
  16. package/build/arbitraryDalvikBytecode.js +640 -0
  17. package/build/arbitraryDalvikExecutable.d.ts +3 -0
  18. package/build/arbitraryDalvikExecutable.js +282 -0
  19. package/build/arbitraryDosDateTime.js +1 -0
  20. package/build/arbitraryZipStream.js +1 -1
  21. package/build/arrayParser.js +2 -2
  22. package/build/arrayUnparser.d.ts +1 -1
  23. package/build/backsmali.d.ts +3 -1
  24. package/build/backsmali.js +31 -3
  25. package/build/customInvariant.d.ts +2 -1
  26. package/build/customInvariant.js +4 -6
  27. package/build/dalvikBytecodeParser/formatParsers.d.ts +76 -2
  28. package/build/dalvikBytecodeParser/formatParsers.js +146 -11
  29. package/build/dalvikBytecodeParser/formatSizes.d.ts +34 -0
  30. package/build/dalvikBytecodeParser/formatSizes.js +34 -0
  31. package/build/dalvikBytecodeParser/operationFormats.d.ts +225 -0
  32. package/build/dalvikBytecodeParser/operationFormats.js +225 -0
  33. package/build/dalvikBytecodeParser.d.ts +1105 -5
  34. package/build/dalvikBytecodeParser.js +658 -205
  35. package/build/dalvikBytecodeUnparser/formatUnparsers.d.ts +152 -0
  36. package/build/dalvikBytecodeUnparser/formatUnparsers.js +225 -0
  37. package/build/dalvikBytecodeUnparser.d.ts +3 -0
  38. package/build/dalvikBytecodeUnparser.js +642 -0
  39. package/build/dalvikBytecodeUnparser.test.d.ts +1 -0
  40. package/build/dalvikBytecodeUnparser.test.js +25 -0
  41. package/build/dalvikExecutable.d.ts +65 -8
  42. package/build/dalvikExecutable.js +36 -0
  43. package/build/dalvikExecutableParser/stringSyntaxParser.d.ts +1 -1
  44. package/build/dalvikExecutableParser/stringSyntaxParser.js +17 -17
  45. package/build/dalvikExecutableParser/typeParsers.d.ts +2 -1
  46. package/build/dalvikExecutableParser/typeParsers.js +16 -11
  47. package/build/dalvikExecutableParser/typedNumbers.d.ts +85 -69
  48. package/build/dalvikExecutableParser/typedNumbers.js +0 -1
  49. package/build/dalvikExecutableParser.d.ts +2 -2
  50. package/build/dalvikExecutableParser.js +655 -337
  51. package/build/dalvikExecutableParser.test.js +24 -22
  52. package/build/dalvikExecutableParserAgainstSmaliParser.test.js +223 -246
  53. package/build/dalvikExecutableUnparser/annotationUnparsers.d.ts +14 -0
  54. package/build/dalvikExecutableUnparser/annotationUnparsers.js +97 -0
  55. package/build/dalvikExecutableUnparser/poolBuilders.d.ts +49 -0
  56. package/build/dalvikExecutableUnparser/poolBuilders.js +140 -0
  57. package/build/dalvikExecutableUnparser/poolScanners.d.ts +4 -0
  58. package/build/dalvikExecutableUnparser/poolScanners.js +220 -0
  59. package/build/dalvikExecutableUnparser/sectionUnparsers.d.ts +25 -0
  60. package/build/dalvikExecutableUnparser/sectionUnparsers.js +581 -0
  61. package/build/dalvikExecutableUnparser/utils.d.ts +10 -0
  62. package/build/dalvikExecutableUnparser/utils.js +108 -0
  63. package/build/dalvikExecutableUnparser.d.ts +4 -0
  64. package/build/dalvikExecutableUnparser.js +406 -0
  65. package/build/dalvikExecutableUnparser.test.d.ts +1 -0
  66. package/build/dalvikExecutableUnparser.test.js +31 -0
  67. package/build/debugLogInputParser.js +1 -1
  68. package/build/disjunctionParser.d.ts +2 -2
  69. package/build/disjunctionParser.js +2 -2
  70. package/build/elementTerminatedArrayParser.d.ts +2 -2
  71. package/build/elementTerminatedArrayParser.js +1 -1
  72. package/build/elementTerminatedArrayParser.test.js +5 -5
  73. package/build/elementTerminatedSequenceArrayParser.d.ts +2 -2
  74. package/build/elementTerminatedSequenceArrayParser.js +1 -1
  75. package/build/elementTerminatedSequenceArrayParser.test.js +2 -2
  76. package/build/elementTerminatedSequenceParser.d.ts +2 -2
  77. package/build/elementTerminatedSequenceParser.js +1 -1
  78. package/build/elementTerminatedSequenceParser.test.js +2 -2
  79. package/build/endOfInputParser.d.ts +1 -1
  80. package/build/exactElementSwitchParser.d.ts +3 -0
  81. package/build/exactElementSwitchParser.js +22 -0
  82. package/build/fetchCid.js +2 -6
  83. package/build/fetchCid.test.d.ts +1 -0
  84. package/build/fetchCid.test.js +16 -0
  85. package/build/fixedLengthSequenceParser.test.js +2 -2
  86. package/build/hasExecutable.js +2 -2
  87. package/build/highResolutionTimer.js +1 -1
  88. package/build/inputReader.d.ts +1 -1
  89. package/build/inputReader.test.js +33 -45
  90. package/build/javaKeyStoreParser.test.js +6 -6
  91. package/build/jsonParser.js +8 -8
  92. package/build/lazyMessageError.d.ts +48 -0
  93. package/build/lazyMessageError.js +53 -0
  94. package/build/lazyMessageError.test.d.ts +1 -0
  95. package/build/lazyMessageError.test.js +15 -0
  96. package/build/leb128Parser.d.ts +1 -1
  97. package/build/leb128Parser.js +10 -10
  98. package/build/leb128Parser.test.js +7 -7
  99. package/build/negativeLookaheadParser.js +2 -2
  100. package/build/negativeLookaheadParser.test.js +4 -4
  101. package/build/noStackCaptureOverheadError.d.ts +4 -0
  102. package/build/noStackCaptureOverheadError.js +9 -0
  103. package/build/noStackCaptureOverheadError.test.d.ts +1 -0
  104. package/build/noStackCaptureOverheadError.test.js +15 -0
  105. package/build/nonEmptyArrayParser.js +2 -2
  106. package/build/nonEmptyArrayParser.test.js +2 -1
  107. package/build/optionalParser.js +2 -2
  108. package/build/parser.d.ts +2 -1
  109. package/build/parser.js +23 -8
  110. package/build/parser.test.js +78 -29
  111. package/build/parserConsumedSequenceParser.d.ts +1 -1
  112. package/build/parserConsumedSequenceParser.js +2 -2
  113. package/build/parserContext.d.ts +8 -6
  114. package/build/parserContext.js +60 -33
  115. package/build/parserContext.test.js +7 -3
  116. package/build/parserError.d.ts +603 -44
  117. package/build/parserError.js +98 -53
  118. package/build/parserImplementationInvariant.d.ts +1 -1
  119. package/build/parserImplementationInvariant.js +2 -2
  120. package/build/parserInputCompanion.js +2 -2
  121. package/build/promiseCompose.js +1 -2
  122. package/build/separatedArrayParser.js +2 -2
  123. package/build/separatedNonEmptyArrayParser.d.ts +2 -0
  124. package/build/separatedNonEmptyArrayParser.js +40 -0
  125. package/build/separatedNonEmptyArrayParser.test.d.ts +1 -0
  126. package/build/separatedNonEmptyArrayParser.test.js +66 -0
  127. package/build/sequenceBuffer.js +1 -1
  128. package/build/sequenceTerminatedSequenceParser.d.ts +2 -2
  129. package/build/sequenceTerminatedSequenceParser.js +3 -3
  130. package/build/sequenceTerminatedSequenceParser.test.js +1 -1
  131. package/build/sequenceUnparser.d.ts +1 -1
  132. package/build/skipToParser.d.ts +1 -1
  133. package/build/skipToParser.js +2 -2
  134. package/build/sliceBoundedParser.test.js +4 -9
  135. package/build/smali.d.ts +1 -1
  136. package/build/smali.js +6 -2
  137. package/build/smaliParser.d.ts +62 -6
  138. package/build/smaliParser.js +1721 -296
  139. package/build/smaliParser.test.js +338 -43
  140. package/build/stringFromAsyncIterable.d.ts +1 -0
  141. package/build/stringFromAsyncIterable.js +7 -0
  142. package/build/terminatedArrayParser.js +4 -4
  143. package/build/terminatedArrayParser.test.js +7 -7
  144. package/build/toAsyncIterator.js +4 -4
  145. package/build/unionParser.d.ts +1 -1
  146. package/build/unionParser.js +2 -2
  147. package/build/unionParser.test.js +3 -3
  148. package/build/unparser.d.ts +3 -3
  149. package/build/unparser.js +6 -4
  150. package/build/unparser.test.js +7 -19
  151. package/build/unparserContext.d.ts +2 -2
  152. package/build/unparserContext.js +2 -3
  153. package/build/unparserError.d.ts +2 -1
  154. package/build/unparserError.js +2 -1
  155. package/build/unparserImplementationInvariant.d.ts +1 -1
  156. package/build/unparserOutputCompanion.d.ts +1 -1
  157. package/build/unparserOutputCompanion.js +1 -1
  158. package/build/zipParser.js +1 -1
  159. package/build/zipUnparser.d.ts +3 -3
  160. package/build/zipUnparser.js +9 -19
  161. package/build/zipUnparser.test.js +1 -1
  162. package/package.json +19 -26
  163. package/src/allSettledStream.test.ts +2 -2
  164. package/src/allSettledStream.ts +3 -3
  165. package/src/androidPackageParser.test.ts +17 -19
  166. package/src/androidPackageParser.ts +129 -171
  167. package/src/androidPackageUnparser.test.ts +19 -21
  168. package/src/androidPackageUnparser.ts +23 -17
  169. package/src/arbitrarilySlicedAsyncInterable.ts +1 -1
  170. package/src/arbitrarilySlicedAsyncInterator.ts +4 -4
  171. package/src/arbitraryDalvikBytecode.ts +992 -0
  172. package/src/arbitraryDalvikExecutable.ts +434 -0
  173. package/src/arbitraryDosDateTime.ts +1 -0
  174. package/src/arbitraryZipStream.ts +1 -1
  175. package/src/arrayParser.ts +2 -2
  176. package/src/arrayUnparser.ts +2 -2
  177. package/src/backsmali.ts +48 -4
  178. package/src/bsonParser.test.ts +12 -14
  179. package/src/customInvariant.ts +8 -12
  180. package/src/dalvikBytecodeParser/formatParsers.ts +376 -17
  181. package/src/dalvikBytecodeParser/formatSizes.ts +35 -0
  182. package/src/dalvikBytecodeParser/operationFormats.ts +226 -0
  183. package/src/dalvikBytecodeParser.ts +1042 -243
  184. package/src/dalvikBytecodeUnparser/formatUnparsers.ts +442 -0
  185. package/src/dalvikBytecodeUnparser.test.ts +44 -0
  186. package/src/dalvikBytecodeUnparser.ts +758 -0
  187. package/src/dalvikExecutable.ts +110 -48
  188. package/src/dalvikExecutableParser/stringSyntaxParser.ts +33 -33
  189. package/src/dalvikExecutableParser/typeParsers.ts +23 -14
  190. package/src/dalvikExecutableParser/typedNumbers.ts +19 -19
  191. package/src/dalvikExecutableParser.test.ts +60 -60
  192. package/src/dalvikExecutableParser.test.ts.md +6 -6
  193. package/src/dalvikExecutableParser.test.ts.snap +0 -0
  194. package/src/dalvikExecutableParser.ts +911 -434
  195. package/src/dalvikExecutableParserAgainstSmaliParser.test.ts +256 -239
  196. package/src/dalvikExecutableUnparser/annotationUnparsers.ts +135 -0
  197. package/src/dalvikExecutableUnparser/poolBuilders.ts +189 -0
  198. package/src/dalvikExecutableUnparser/poolScanners.ts +297 -0
  199. package/src/dalvikExecutableUnparser/sectionUnparsers.ts +683 -0
  200. package/src/dalvikExecutableUnparser/utils.ts +149 -0
  201. package/src/dalvikExecutableUnparser.test.ts +57 -0
  202. package/src/dalvikExecutableUnparser.ts +581 -0
  203. package/src/debugLogInputParser.ts +1 -1
  204. package/src/disjunctionParser.ts +5 -5
  205. package/src/elementTerminatedArrayParser.test.ts +8 -8
  206. package/src/elementTerminatedArrayParser.ts +2 -2
  207. package/src/elementTerminatedSequenceArrayParser.test.ts +4 -6
  208. package/src/elementTerminatedSequenceArrayParser.ts +2 -2
  209. package/src/elementTerminatedSequenceParser.test.ts +4 -6
  210. package/src/elementTerminatedSequenceParser.ts +2 -2
  211. package/src/endOfInputParser.ts +1 -1
  212. package/src/exactElementSwitchParser.ts +41 -0
  213. package/src/fetchCid.test.ts +20 -0
  214. package/src/fetchCid.ts +3 -7
  215. package/src/fixedLengthSequenceParser.test.ts +10 -12
  216. package/src/hasExecutable.ts +2 -2
  217. package/src/highResolutionTimer.ts +1 -1
  218. package/src/inputReader.test.ts +39 -52
  219. package/src/inputReader.ts +2 -4
  220. package/src/inputReaderState.ts +1 -1
  221. package/src/inspect.ts +1 -1
  222. package/src/javaKeyStoreParser.test.ts +12 -14
  223. package/src/javaKeyStoreParser.ts +2 -6
  224. package/src/jsonParser.test.ts +2 -4
  225. package/src/jsonParser.ts +34 -38
  226. package/src/lazyMessageError.test.ts +21 -0
  227. package/src/lazyMessageError.ts +88 -0
  228. package/src/leb128Parser.test.ts +25 -23
  229. package/src/leb128Parser.ts +19 -19
  230. package/src/negativeLookaheadParser.test.ts +7 -11
  231. package/src/negativeLookaheadParser.ts +2 -2
  232. package/src/noStackCaptureOverheadError.test.ts +17 -0
  233. package/src/noStackCaptureOverheadError.ts +12 -0
  234. package/src/nonEmptyArrayParser.test.ts +3 -2
  235. package/src/nonEmptyArrayParser.ts +2 -2
  236. package/src/optionalParser.ts +2 -2
  237. package/src/parser.test.ts +96 -43
  238. package/src/parser.test.ts.md +13 -6
  239. package/src/parser.test.ts.snap +0 -0
  240. package/src/parser.ts +35 -12
  241. package/src/parserAccessorParser.ts +1 -1
  242. package/src/parserConsumedSequenceParser.ts +3 -3
  243. package/src/parserContext.test.ts +7 -3
  244. package/src/parserContext.ts +82 -48
  245. package/src/parserError.ts +143 -63
  246. package/src/parserImplementationInvariant.ts +3 -3
  247. package/src/parserInputCompanion.ts +2 -2
  248. package/src/promiseCompose.ts +2 -2
  249. package/src/separatedArrayParser.ts +3 -3
  250. package/src/separatedNonEmptyArrayParser.test.ts +117 -0
  251. package/src/separatedNonEmptyArrayParser.ts +61 -0
  252. package/src/sequenceBuffer.test.ts +9 -9
  253. package/src/sequenceBuffer.ts +4 -4
  254. package/src/sequenceTerminatedSequenceParser.test.ts +3 -5
  255. package/src/sequenceTerminatedSequenceParser.ts +4 -4
  256. package/src/sequenceUnparser.ts +2 -2
  257. package/src/skipToParser.ts +2 -2
  258. package/src/sliceBoundedParser.test.ts +4 -12
  259. package/src/sliceBoundedParser.ts +2 -2
  260. package/src/smali.ts +8 -3
  261. package/src/smaliParser.test.ts +377 -66
  262. package/src/smaliParser.test.ts.md +1635 -48
  263. package/src/smaliParser.test.ts.snap +0 -0
  264. package/src/smaliParser.ts +2751 -569
  265. package/src/stringFromAsyncIterable.ts +9 -0
  266. package/src/terminatedArrayParser.test.ts +11 -11
  267. package/src/terminatedArrayParser.ts +5 -7
  268. package/src/toAsyncIterator.ts +8 -8
  269. package/src/uint8Array.ts +2 -3
  270. package/src/unionParser.test.ts +22 -23
  271. package/src/unionParser.ts +6 -8
  272. package/src/unparser.test.ts +18 -34
  273. package/src/unparser.ts +13 -9
  274. package/src/unparserContext.ts +9 -13
  275. package/src/unparserError.ts +2 -1
  276. package/src/unparserImplementationInvariant.ts +1 -1
  277. package/src/unparserOutputCompanion.ts +1 -1
  278. package/src/zip.ts +2 -6
  279. package/src/zipParser.ts +10 -18
  280. package/src/zipUnparser.test.ts +1 -1
  281. package/src/zipUnparser.ts +52 -64
  282. package/tsconfig.json +7 -1
  283. package/xo.config.ts +15 -0
  284. package/.yarn/releases/yarn-4.5.3.cjs +0 -934
@@ -1,61 +1,106 @@
1
- export class ParserError extends Error {
2
- name = 'ParserError';
3
- position = undefined;
4
- inputReaderSate = undefined;
1
+ import { NormalLazyMessageError, NoStackCaptureOverheadLazyMessageError } from './lazyMessageError.js';
2
+ export function isParserError(value) {
3
+ return (typeof value === 'object'
4
+ && value !== null
5
+ && value instanceof Error
6
+ && 'position' in value
7
+ && (typeof value.position === 'number' || value.position === undefined)
8
+ && 'inputReaderSate' in value
9
+ && (value.inputReaderSate === undefined || typeof value.inputReaderSate === 'object'));
5
10
  }
6
- export class ParserImplementationError extends ParserError {
7
- name = 'ParserImplementationError';
11
+ export function isParserParsingFailedError(value) {
12
+ return (typeof value === 'object'
13
+ && value !== null
14
+ && value instanceof Error
15
+ && 'depth' in value
16
+ && typeof value.depth === 'number'
17
+ && 'position' in value
18
+ && typeof value.position === 'number');
8
19
  }
9
- export class ParserImplementationInvariantError extends ParserImplementationError {
10
- name = 'ParserImplementationInvariantError';
20
+ export function isParserParsingJoinError(value) {
21
+ return (typeof value === 'object'
22
+ && value !== null
23
+ && value instanceof Error
24
+ && 'childErrors' in value
25
+ && Array.isArray(value.childErrors)
26
+ && value.childErrors.every((childError) => isParserParsingFailedError(childError)));
11
27
  }
12
- export class ParserParsingFailedError extends ParserError {
13
- depth;
14
- position;
15
- name = 'ParserParsingFailedError';
16
- constructor(message, depth, position) {
17
- super(message);
18
- this.depth = depth;
19
- this.position = position;
28
+ function createParserErrorModule(BaseLazyMessageError) {
29
+ class ParserError extends BaseLazyMessageError {
30
+ name = 'ParserError';
31
+ position = undefined;
32
+ inputReaderSate = undefined;
20
33
  }
21
- }
22
- export class ParserParsingJoinError extends ParserParsingFailedError {
23
- name = 'ParserParsingJoinError';
24
- childErrors = [];
25
- }
26
- export class ParserParsingJoinNoneError extends ParserParsingJoinError {
27
- name = 'ParserParsingJoinNoneError';
28
- }
29
- export class ParserParsingJoinAllError extends ParserParsingJoinError {
30
- childErrors;
31
- name = 'ParserParsingJoinAllError';
32
- constructor(message, depth, position, childErrors) {
33
- super(message, depth, position);
34
- this.childErrors = childErrors;
34
+ class ParserImplementationError extends ParserError {
35
+ name = 'ParserImplementationError';
35
36
  }
36
- }
37
- export class ParserParsingJoinDeepestError extends ParserParsingJoinError {
38
- childErrors;
39
- name = 'ParserParsingJoinDeepestError';
40
- constructor(message, depth, position, childErrors) {
41
- super(message, depth, position);
42
- this.childErrors = childErrors;
37
+ class ParserImplementationInvariantError extends ParserImplementationError {
38
+ name = 'ParserImplementationInvariantError';
43
39
  }
44
- }
45
- export class ParserParsingJoinFurthestError extends ParserParsingJoinError {
46
- childErrors;
47
- name = 'ParserParsingJoinFurthestError';
48
- constructor(message, depth, position, childErrors) {
49
- super(message, depth, position);
50
- this.childErrors = childErrors;
40
+ class ParserParsingFailedError extends ParserError {
41
+ depth;
42
+ position;
43
+ name = 'ParserParsingFailedError';
44
+ constructor(message, depth, position) {
45
+ super(message);
46
+ this.depth = depth;
47
+ this.position = position;
48
+ }
51
49
  }
50
+ class ParserParsingJoinError extends ParserParsingFailedError {
51
+ name = 'ParserParsingJoinError';
52
+ childErrors = [];
53
+ }
54
+ class ParserParsingJoinNoneError extends ParserParsingJoinError {
55
+ name = 'ParserParsingJoinNoneError';
56
+ }
57
+ class ParserParsingJoinAllError extends ParserParsingJoinError {
58
+ childErrors;
59
+ name = 'ParserParsingJoinAllError';
60
+ constructor(message, depth, position, childErrors) {
61
+ super(message, depth, position);
62
+ this.childErrors = childErrors;
63
+ }
64
+ }
65
+ class ParserParsingJoinDeepestError extends ParserParsingJoinError {
66
+ childErrors;
67
+ name = 'ParserParsingJoinDeepestError';
68
+ constructor(message, depth, position, childErrors) {
69
+ super(message, depth, position);
70
+ this.childErrors = childErrors;
71
+ }
72
+ }
73
+ class ParserParsingJoinFurthestError extends ParserParsingJoinError {
74
+ childErrors;
75
+ name = 'ParserParsingJoinFurthestError';
76
+ constructor(message, depth, position, childErrors) {
77
+ super(message, depth, position);
78
+ this.childErrors = childErrors;
79
+ }
80
+ }
81
+ class ParserParsingInvariantError extends ParserParsingFailedError {
82
+ name = 'ParserParsingInvariantError';
83
+ }
84
+ class ParserUnexpectedEndOfInputError extends ParserParsingFailedError {
85
+ name = 'ParserUnexpectedEndOfInputError';
86
+ }
87
+ class ParserUnexpectedRemainingInputError extends ParserParsingFailedError {
88
+ name = 'ParserUnexpectedRemainingInputError';
89
+ }
90
+ return {
91
+ ParserError,
92
+ ParserImplementationError,
93
+ ParserImplementationInvariantError,
94
+ ParserParsingFailedError,
95
+ ParserParsingJoinError,
96
+ ParserParsingJoinNoneError,
97
+ ParserParsingJoinAllError,
98
+ ParserParsingJoinDeepestError,
99
+ ParserParsingJoinFurthestError,
100
+ ParserParsingInvariantError,
101
+ ParserUnexpectedEndOfInputError,
102
+ ParserUnexpectedRemainingInputError,
103
+ };
52
104
  }
53
- export class ParserParsingInvariantError extends ParserParsingFailedError {
54
- name = 'ParserParsingInvariantError';
55
- }
56
- export class ParserUnexpectedEndOfInputError extends ParserParsingFailedError {
57
- name = 'ParserUnexpectedEndOfInputError';
58
- }
59
- export class ParserUnexpectedRemainingInputError extends ParserParsingFailedError {
60
- name = 'ParserUnexpectedRemainingInputError';
61
- }
105
+ export const normalParserErrorModule = createParserErrorModule(NormalLazyMessageError);
106
+ export const noStackCaptureOverheadParserErrorModule = createParserErrorModule(NoStackCaptureOverheadLazyMessageError);
@@ -1,2 +1,2 @@
1
1
  import { type Falsy, type ValueOrAccessor } from './customInvariant.js';
2
- export declare function parserImplementationInvariant<T>(value: T, format: ValueOrAccessor<string | string[]>, ...formatArguments: any[]): Exclude<T, Falsy>;
2
+ export declare function parserImplementationInvariant<T>(value: T, format: ValueOrAccessor<string | string[]>, ...formatArguments: unknown[]): Exclude<T, Falsy>;
@@ -1,5 +1,5 @@
1
- import { ParserImplementationInvariantError } from './parserError.js';
2
1
  import { customInvariant } from './customInvariant.js';
2
+ import { normalParserErrorModule } from './parserError.js';
3
3
  export function parserImplementationInvariant(value, format, ...formatArguments) {
4
- return customInvariant(ParserImplementationInvariantError, value, format, ...formatArguments);
4
+ return customInvariant(normalParserErrorModule.ParserImplementationInvariantError, value, format, ...formatArguments);
5
5
  }
@@ -57,8 +57,8 @@ export class Uint8ArrayParserInputCompanion {
57
57
  if (sequenceA.length !== sequenceB.length) {
58
58
  return false;
59
59
  }
60
- for (let index = 0; index < sequenceA.length; index++) {
61
- if (sequenceA[index] !== sequenceB[index]) {
60
+ for (const [index, element] of sequenceA.entries()) {
61
+ if (element !== sequenceB[index]) {
62
62
  return false;
63
63
  }
64
64
  }
@@ -1,12 +1,11 @@
1
1
  export function promiseCompose(f1, f2) {
2
- function promiseComposed(a) {
2
+ async function promiseComposed(a) {
3
3
  const bOrBPromise = f1(a);
4
4
  if (bOrBPromise instanceof Promise) {
5
5
  return bOrBPromise.then(f2);
6
6
  }
7
7
  return f2(bOrBPromise);
8
8
  }
9
- ;
10
9
  Object.defineProperty(promiseComposed, 'name', {
11
10
  value: `promiseCompose(${f1.name}, ${f2.name})`,
12
11
  });
@@ -1,5 +1,5 @@
1
1
  import { getParserName, setParserName } from './parser.js';
2
- import { ParserParsingFailedError } from './parserError.js';
2
+ import { isParserParsingFailedError } from './parserError.js';
3
3
  import { promiseCompose } from './promiseCompose.js';
4
4
  import { createTupleParser } from './tupleParser.js';
5
5
  export const createSeparatedArrayParser = (elementParser, separatorParser) => {
@@ -22,7 +22,7 @@ export const createSeparatedArrayParser = (elementParser, separatorParser) => {
22
22
  elementParserContext.unlookahead();
23
23
  }
24
24
  catch (error) {
25
- if (error instanceof ParserParsingFailedError) {
25
+ if (isParserParsingFailedError(error)) {
26
26
  break;
27
27
  }
28
28
  throw error;
@@ -0,0 +1,2 @@
1
+ import { type Parser } from './parser.js';
2
+ export declare const createSeparatedNonEmptyArrayParser: <ElementOutput, Sequence>(elementParser: Parser<ElementOutput, Sequence>, separatorParser: Parser<unknown, Sequence>) => Parser<ElementOutput[], Sequence>;
@@ -0,0 +1,40 @@
1
+ import { getParserName, setParserName } from './parser.js';
2
+ import { isParserParsingFailedError } from './parserError.js';
3
+ import { promiseCompose } from './promiseCompose.js';
4
+ import { createTupleParser } from './tupleParser.js';
5
+ export const createSeparatedNonEmptyArrayParser = (elementParser, separatorParser) => {
6
+ const separatorThenElementParser = promiseCompose(createTupleParser([
7
+ separatorParser,
8
+ elementParser,
9
+ ]), ([, element]) => element);
10
+ const separatedNonEmptyArrayParser = async (parserContext) => {
11
+ let parser = elementParser;
12
+ const elements = [];
13
+ while (true) {
14
+ const elementParserContext = parserContext.lookahead();
15
+ const initialPosition = elementParserContext.position;
16
+ try {
17
+ const element = await parser(elementParserContext);
18
+ if (elementParserContext.position === initialPosition) {
19
+ break;
20
+ }
21
+ elements.push(element);
22
+ elementParserContext.unlookahead();
23
+ }
24
+ catch (error) {
25
+ if (isParserParsingFailedError(error)) {
26
+ break;
27
+ }
28
+ throw error;
29
+ }
30
+ finally {
31
+ elementParserContext.dispose();
32
+ }
33
+ parser = separatorThenElementParser;
34
+ }
35
+ parserContext.invariant(elements.length > 0, 'Expected elementParser (%s) to match at least once', getParserName(elementParser, 'anonymousSeparatedNonEmptyArrayChild'));
36
+ return elements;
37
+ };
38
+ setParserName(separatedNonEmptyArrayParser, getParserName(elementParser, 'anonymousSeparatedNonEmptyArrayChild') + '+');
39
+ return separatedNonEmptyArrayParser;
40
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,66 @@
1
+ import test from 'ava';
2
+ import { testProp, fc } from '@fast-check/ava';
3
+ import { createSeparatedNonEmptyArrayParser } from './separatedNonEmptyArrayParser.js';
4
+ import { runParser, runParserWithRemainingInput } from './parser.js';
5
+ import { stringParserInputCompanion } from './parserInputCompanion.js';
6
+ import { createExactSequenceParser } from './exactSequenceParser.js';
7
+ import { stringFromAsyncIterable } from './stringFromAsyncIterable.js';
8
+ test('empty input throws error', async (t) => {
9
+ const parser = createSeparatedNonEmptyArrayParser(createExactSequenceParser('element'), createExactSequenceParser(','));
10
+ await t.throwsAsync(async () => runParser(parser, '', stringParserInputCompanion), {
11
+ any: true,
12
+ message: /Expected .* to match at least once/,
13
+ });
14
+ });
15
+ test('single element without separator matches', async (t) => {
16
+ const parser = createSeparatedNonEmptyArrayParser(createExactSequenceParser('element'), createExactSequenceParser(','));
17
+ const result = await runParser(parser, 'element', stringParserInputCompanion);
18
+ t.deepEqual(result, ['element']);
19
+ });
20
+ test('two elements with separator matches', async (t) => {
21
+ const parser = createSeparatedNonEmptyArrayParser(createExactSequenceParser('element'), createExactSequenceParser(','));
22
+ const result = await runParser(parser, 'element,element', stringParserInputCompanion);
23
+ t.deepEqual(result, ['element', 'element']);
24
+ });
25
+ test('multiple elements with separator matches', async (t) => {
26
+ const parser = createSeparatedNonEmptyArrayParser(createExactSequenceParser('a'), createExactSequenceParser(','));
27
+ const result = await runParser(parser, 'a,a,a,a', stringParserInputCompanion);
28
+ t.deepEqual(result, ['a', 'a', 'a', 'a']);
29
+ });
30
+ test('does not consume trailing separator', async (t) => {
31
+ const parser = createSeparatedNonEmptyArrayParser(createExactSequenceParser('element'), createExactSequenceParser(','));
32
+ const { output, remainingInput } = await runParserWithRemainingInput(parser, 'element,element,', stringParserInputCompanion);
33
+ t.deepEqual(output, ['element', 'element']);
34
+ t.is(await stringFromAsyncIterable(remainingInput), ',');
35
+ });
36
+ test('does not loop forever with a child parser that does not consume anything', async (t) => {
37
+ const parser = createSeparatedNonEmptyArrayParser(async () => undefined, () => undefined);
38
+ await t.throwsAsync(async () => runParser(parser, 'foo', stringParserInputCompanion), {
39
+ any: true,
40
+ message: /Expected .* to match at least once/,
41
+ });
42
+ });
43
+ test('partial match throws error', async (t) => {
44
+ const parser = createSeparatedNonEmptyArrayParser(createExactSequenceParser('element'), createExactSequenceParser(','));
45
+ await t.throwsAsync(async () => runParser(parser, 'elem', stringParserInputCompanion), {
46
+ any: true,
47
+ message: /Expected .* to match at least once/,
48
+ });
49
+ });
50
+ testProp('separatedNonEmptyArray with at least one element', [
51
+ fc.array(fc.constant('element'), { minLength: 1 }),
52
+ ], async (t, elements) => {
53
+ const separatedNonEmptyArrayParser = createSeparatedNonEmptyArrayParser(createExactSequenceParser('element'), createExactSequenceParser('separator'));
54
+ const actual = await runParser(separatedNonEmptyArrayParser, elements.join('separator'), stringParserInputCompanion);
55
+ const expected = elements;
56
+ t.deepEqual(actual, expected);
57
+ }, {
58
+ verbose: true,
59
+ });
60
+ test('separatedNonEmptyArray throws on empty array', async (t) => {
61
+ const separatedNonEmptyArrayParser = createSeparatedNonEmptyArrayParser(createExactSequenceParser('element'), createExactSequenceParser('separator'));
62
+ await t.throwsAsync(async () => runParser(separatedNonEmptyArrayParser, '', stringParserInputCompanion), {
63
+ any: true,
64
+ message: /Expected .* to match at least once/,
65
+ });
66
+ });
@@ -74,7 +74,7 @@ export class SequenceBufferImplementation {
74
74
  if (this._indexInFirstSequence === 0) {
75
75
  return {
76
76
  consumedBufferedSequences: [],
77
- unconsumedBufferedSequences: this._sequences.slice(),
77
+ unconsumedBufferedSequences: [...this._sequences],
78
78
  };
79
79
  }
80
80
  const firstSequence = this._sequences[0];
@@ -1,5 +1,5 @@
1
- import { Parser } from "./parser.js";
2
- import { DeriveSequenceElement } from "./sequence.js";
1
+ import { type Parser } from './parser.js';
2
+ import { type DeriveSequenceElement } from './sequence.js';
3
3
  export declare const createSequenceTerminatedSequenceParser: <Sequence, Element = DeriveSequenceElement<Sequence>>(terminatorSequence: Sequence, { consumeTerminator, }?: {
4
4
  consumeTerminator?: boolean;
5
5
  }) => Parser<Sequence, Sequence, Element>;
@@ -1,5 +1,5 @@
1
- import { inspect } from "./inspect.js";
2
- import { setParserName } from "./parser.js";
1
+ import { inspect } from './inspect.js';
2
+ import { setParserName } from './parser.js';
3
3
  function clamp(x, min, max) {
4
4
  return Math.max(min, Math.min(x, max));
5
5
  }
@@ -17,7 +17,7 @@ export const createSequenceTerminatedSequenceParser = (terminatorSequence, { con
17
17
  nonEndOfInputWindow = Math.max(window, nonEndOfInputWindow);
18
18
  const terminatorIndex = parserContext.indexOfSubsequence(sequence, terminatorSequence);
19
19
  if (terminatorIndex === -1) {
20
- window = window * 2;
20
+ window *= 2;
21
21
  continue;
22
22
  }
23
23
  const sequence_ = await parserContext.readSequence(0, terminatorIndex);
@@ -15,7 +15,7 @@ testProp.serial('sequenceTerminatedSequenceParser', [
15
15
  string,
16
16
  terminator: string.slice(-terminatorLength),
17
17
  }))
18
- .filter(({ string, terminator }) => string.split(terminator).length === 2)
18
+ .filter(({ string, terminator }) => string.split(terminator).length === 2),
19
19
  ], async (t, { string, terminator }) => {
20
20
  const sequenceTerminatedSequenceParser = createSequenceTerminatedSequenceParser(terminator);
21
21
  const createTestWrapperParser = (innerParser) => async (parserContext) => {
@@ -1,2 +1,2 @@
1
- import { Unparser } from "./unparser.js";
1
+ import { type Unparser } from './unparser.js';
2
2
  export declare const createSequenceUnparser: <Sequence>() => Unparser<Sequence, Sequence>;
@@ -1,2 +1,2 @@
1
- import { Parser } from "./parser.js";
1
+ import { type Parser } from './parser.js';
2
2
  export declare const createSkipToParser: (offset: number) => Parser<void, Uint8Array>;
@@ -1,7 +1,7 @@
1
- import { setParserName } from "./parser.js";
1
+ import { setParserName } from './parser.js';
2
2
  import { parserImplementationInvariant } from './parserImplementationInvariant.js';
3
3
  export const createSkipToParser = (offset) => {
4
- const skipToParser = (parserContext) => {
4
+ const skipToParser = parserContext => {
5
5
  const length = offset - parserContext.position;
6
6
  parserImplementationInvariant(length >= 0, 'Skip length must be positive, got %s (position: %s)', length, parserContext.position);
7
7
  parserContext.skip(length);
@@ -6,13 +6,7 @@ import { createSliceBoundedParser } from './sliceBoundedParser.js';
6
6
  import { runParser, runParserWithRemainingInput } from './parser.js';
7
7
  import { stringParserInputCompanion } from './parserInputCompanion.js';
8
8
  import { createExactElementParser } from './exactElementParser.js';
9
- async function stringFromAsyncIterable(asyncIterable) {
10
- let string = '';
11
- for await (const chunk of asyncIterable) {
12
- string += chunk;
13
- }
14
- return string;
15
- }
9
+ import { stringFromAsyncIterable } from './stringFromAsyncIterable.js';
16
10
  const anythingParser = createArrayParser(createElementParser());
17
11
  test('sliceBoundedParser', async (t) => {
18
12
  const parser = createTupleParser([
@@ -36,7 +30,8 @@ test('sliceBoundedParser mustConsumeAll: true fail to cosume all', async (t) =>
36
30
  createSliceBoundedParser(createArrayParser(createExactElementParser('b')), 2),
37
31
  createElementParser(),
38
32
  ]);
39
- await t.throwsAsync(() => runParser(parser, 'abcd', stringParserInputCompanion), {
33
+ await t.throwsAsync(async () => runParser(parser, 'abcd', stringParserInputCompanion), {
34
+ any: true,
40
35
  message: /child parser must consume all input in the slice/,
41
36
  });
42
37
  });
@@ -54,5 +49,5 @@ test('sliceBoundedParser mustConsumeAll: false', async (t) => {
54
49
  ],
55
50
  'c',
56
51
  ]);
57
- t.deepEqual(await stringFromAsyncIterable(remainingInput), 'd');
52
+ t.is(await stringFromAsyncIterable(remainingInput), 'd');
58
53
  });
package/build/smali.d.ts CHANGED
@@ -1 +1 @@
1
- export declare function smaliClass(smaliStream: AsyncIterable<string>): Promise<Buffer<ArrayBufferLike>>;
1
+ export declare function smaliClass(smaliStream: string | AsyncIterable<string>): Promise<Uint8Array>;
package/build/smali.js CHANGED
@@ -5,11 +5,15 @@ export async function smaliClass(smaliStream) {
5
5
  const inputFilePath = temporaryFile();
6
6
  const outputFilePath = temporaryFile();
7
7
  await fs.writeFile(inputFilePath, smaliStream);
8
- await execa('smali', [
8
+ const smaliResult = await execa('smali', [
9
9
  'assemble',
10
- '--output', outputFilePath,
10
+ '--output',
11
+ outputFilePath,
11
12
  inputFilePath,
12
13
  ]);
14
+ if (smaliResult.stderr) {
15
+ throw new Error(`smali error: ${smaliResult.stderr}`);
16
+ }
13
17
  await fs.unlink(inputFilePath);
14
18
  const dex = await fs.readFile(outputFilePath);
15
19
  await fs.unlink(outputFilePath);
@@ -1,12 +1,68 @@
1
- import { DalvikBytecode } from "./dalvikBytecodeParser.js";
2
- import { DalvikExecutableClassDefinition, DalvikExecutableFieldWithAccess } from "./dalvikExecutable.js";
3
- import { Parser } from "./parser.js";
4
- export declare const smaliFieldParser: Parser<DalvikExecutableFieldWithAccess, string>;
5
- export declare const smaliAnnotationParser: Parser<unknown, string>;
1
+ import { type Simplify } from 'type-fest';
2
+ import { type DalvikBytecode, type DalvikBytecodeOperation } from './dalvikBytecodeParser.js';
3
+ import { type DalvikExecutableClassDefinition, type DalvikExecutableField, type DalvikExecutableFieldWithAccess, type DalvikExecutableMethod, type DalvikExecutableMethodWithAccess } from './dalvikExecutable.js';
4
+ import { type Parser } from './parser.js';
5
+ import { type IndexIntoMethodIds } from './dalvikExecutableParser/typedNumbers.js';
6
+ export declare const smaliCommentParser: Parser<string, string>;
7
+ type SmaliAnnotationElementValue = {
8
+ kind: 'type';
9
+ value: string | string[];
10
+ } | {
11
+ kind: 'string';
12
+ value: string | string[];
13
+ } | {
14
+ kind: 'enum';
15
+ value: DalvikExecutableField | DalvikExecutableField[];
16
+ } | {
17
+ kind: 'raw';
18
+ value: unknown;
19
+ };
20
+ type SmaliAnnotationElement = {
21
+ name: string;
22
+ value: SmaliAnnotationElementValue;
23
+ };
24
+ type SmaliAnnotation = {
25
+ type: string;
26
+ elements: SmaliAnnotationElement[];
27
+ visibility: 'build' | 'runtime' | 'system';
28
+ };
29
+ export declare const smaliAnnotationParser: Parser<SmaliAnnotation, string>;
30
+ type SmaliField = {
31
+ field: DalvikExecutableFieldWithAccess;
32
+ annotations: SmaliAnnotation[];
33
+ initialValue?: number | bigint | string | boolean | null;
34
+ };
35
+ export declare const smaliFieldParser: Parser<SmaliField, string>;
6
36
  type SmaliRegister = {
7
37
  prefix: 'v' | 'p';
8
38
  index: number;
9
39
  };
10
- export declare const smaliCodeParameterParser: Parser<SmaliRegister, string>;
40
+ type SmaliCodeParameter = {
41
+ register: SmaliRegister;
42
+ name: string | undefined;
43
+ annotation: SmaliAnnotation | undefined;
44
+ };
45
+ export declare const smaliCodeParameterParser: Parser<SmaliCodeParameter, string>;
46
+ type SmaliCodeOperationFromDalvikBytecodeOperation<T extends DalvikBytecodeOperation> = T extends {
47
+ branchOffsets: number[];
48
+ } ? Simplify<Omit<T, 'branchOffsets'> & {
49
+ branchOffsetIndices: number[];
50
+ }> : T extends {
51
+ branchOffset: number;
52
+ } ? Simplify<Omit<T, 'branchOffset'> & {
53
+ branchOffsetIndex: number;
54
+ }> : T extends {
55
+ methodIndex: IndexIntoMethodIds;
56
+ } ? Simplify<Omit<T, 'methodIndex'> & {
57
+ method: DalvikExecutableMethod;
58
+ }> : T;
59
+ type SmaliCodeOperation = SmaliCodeOperationFromDalvikBytecodeOperation<DalvikBytecodeOperation>;
60
+ export declare const smaliCodeOperationParser: Parser<SmaliCodeOperation, string>;
61
+ type SmaliMethod<DalvikBytecode> = {
62
+ dalvikExecutableMethodWithAccess: DalvikExecutableMethodWithAccess<DalvikBytecode>;
63
+ parameterAnnotations: SmaliCodeParameter[];
64
+ methodAnnotations: SmaliAnnotation[];
65
+ };
66
+ export declare const smaliMethodParser: Parser<SmaliMethod<DalvikBytecode>, string>;
11
67
  export declare const smaliParser: Parser<DalvikExecutableClassDefinition<DalvikBytecode>, string>;
12
68
  export {};