vitest-pool-assemblyscript 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -4
- package/assembly/compare.ts +127 -0
- package/assembly/expect.ts +116 -11
- package/dist/{ast-visitor-lTahoS9R.mjs → ast-visitor-DJLJd5dt.mjs} +2 -2
- package/dist/{ast-visitor-lTahoS9R.mjs.map → ast-visitor-DJLJd5dt.mjs.map} +1 -1
- package/dist/{compile-runner-C2eh_xLp.mjs → compile-runner-BJ_ZF3Ma.mjs} +11 -8
- package/dist/compile-runner-BJ_ZF3Ma.mjs.map +1 -0
- package/dist/compiler/transforms/strip-inline.mjs +2 -2
- package/dist/{compiler-BaNECXMW.mjs → compiler-CscxCJw3.mjs} +78 -38
- package/dist/compiler-CscxCJw3.mjs.map +1 -0
- package/dist/config/index-v3.d.mts +2 -2
- package/dist/config/index.d.mts +3 -3
- package/dist/config/index.mjs +5 -5
- package/dist/{constants-DX9yo-el.mjs → constants-DuBLuMjt.mjs} +9 -9
- package/dist/constants-DuBLuMjt.mjs.map +1 -0
- package/dist/{coverage-merge-0WqdC-dq.mjs → coverage-merge-DCEwyjMy.mjs} +1 -1
- package/dist/{coverage-merge-0WqdC-dq.mjs.map → coverage-merge-DCEwyjMy.mjs.map} +1 -1
- package/dist/coverage-provider/index.mjs +35 -28
- package/dist/coverage-provider/index.mjs.map +1 -1
- package/dist/{custom-provider-options-CF5C1kXb.d.mts → custom-provider-options-i_O0OSTV.d.mts} +2 -2
- package/dist/{custom-provider-options-CF5C1kXb.d.mts.map → custom-provider-options-i_O0OSTV.d.mts.map} +1 -1
- package/dist/{debug-Cf2jt1kg.mjs → debug-Cm1VFmaz.mjs} +16 -13
- package/dist/{debug-Cf2jt1kg.mjs.map → debug-Cm1VFmaz.mjs.map} +1 -1
- package/dist/index-internal.d.mts +1 -14
- package/dist/index-internal.d.mts.map +1 -1
- package/dist/index-internal.mjs +3 -3
- package/dist/index-v3.mjs +4 -4
- package/dist/index-v3.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +5 -5
- package/dist/{load-user-imports-eGZuxeNp.mjs → load-user-imports-CYTTU22Q.mjs} +30 -149
- package/dist/load-user-imports-CYTTU22Q.mjs.map +1 -0
- package/dist/node-check-CooGQMLH.mjs +16 -0
- package/dist/node-check-CooGQMLH.mjs.map +1 -0
- package/dist/{pool-runner-init-Cdpz_B-F.mjs → pool-runner-init-D1QamWkS.mjs} +5 -5
- package/dist/{pool-runner-init-Cdpz_B-F.mjs.map → pool-runner-init-D1QamWkS.mjs.map} +1 -1
- package/dist/{pool-runner-init-CEwLyNI3.d.mts → pool-runner-init-D56aVMMD.d.mts} +2 -2
- package/dist/pool-runner-init-D56aVMMD.d.mts.map +1 -0
- package/dist/pool-thread/compile-worker-thread.d.mts +1 -1
- package/dist/pool-thread/compile-worker-thread.d.mts.map +1 -1
- package/dist/pool-thread/compile-worker-thread.mjs +11 -9
- package/dist/pool-thread/compile-worker-thread.mjs.map +1 -1
- package/dist/pool-thread/test-worker-thread.d.mts +1 -1
- package/dist/pool-thread/test-worker-thread.d.mts.map +1 -1
- package/dist/pool-thread/test-worker-thread.mjs +10 -8
- package/dist/pool-thread/test-worker-thread.mjs.map +1 -1
- package/dist/pool-thread/v3-tinypool-thread.d.mts +1 -1
- package/dist/pool-thread/v3-tinypool-thread.d.mts.map +1 -1
- package/dist/pool-thread/v3-tinypool-thread.mjs +14 -12
- package/dist/pool-thread/v3-tinypool-thread.mjs.map +1 -1
- package/dist/{resolve-config-BKjJQyy5.mjs → resolve-config-BFNr7LW7.mjs} +9 -3
- package/dist/resolve-config-BFNr7LW7.mjs.map +1 -0
- package/dist/{test-runner-vGpTcXsw.mjs → test-runner-CfhzcYNS.mjs} +5 -5
- package/dist/{test-runner-vGpTcXsw.mjs.map → test-runner-CfhzcYNS.mjs.map} +1 -1
- package/dist/{types-8KKo9Hbf.d.mts → types-DmyeERkL.d.mts} +15 -6
- package/dist/types-DmyeERkL.d.mts.map +1 -0
- package/dist/{vitest-tasks-Cbri6MWZ.mjs → vitest-tasks-ByPK8DvF.mjs} +3 -3
- package/dist/{vitest-tasks-Cbri6MWZ.mjs.map → vitest-tasks-ByPK8DvF.mjs.map} +1 -1
- package/dist/wasm-names-CydfYzQK.mjs +124 -0
- package/dist/wasm-names-CydfYzQK.mjs.map +1 -0
- package/package.json +11 -5
- package/prebuilds/darwin-arm64/vitest-pool-assemblyscript.glibc.node +0 -0
- package/prebuilds/darwin-x64/vitest-pool-assemblyscript.glibc.node +0 -0
- package/prebuilds/linux-arm64/vitest-pool-assemblyscript.glibc.node +0 -0
- package/prebuilds/linux-x64/vitest-pool-assemblyscript.glibc.node +0 -0
- package/prebuilds/linux-x64/vitest-pool-assemblyscript.musl.node +0 -0
- package/prebuilds/win32-arm64/vitest-pool-assemblyscript.glibc.node +0 -0
- package/prebuilds/win32-x64/vitest-pool-assemblyscript.glibc.node +0 -0
- package/src/native-instrumentation/addon.cpp +28 -2
- package/dist/compile-runner-C2eh_xLp.mjs.map +0 -1
- package/dist/compiler-BaNECXMW.mjs.map +0 -1
- package/dist/constants-DX9yo-el.mjs.map +0 -1
- package/dist/load-user-imports-eGZuxeNp.mjs.map +0 -1
- package/dist/pool-runner-init-CEwLyNI3.d.mts.map +0 -1
- package/dist/resolve-config-BKjJQyy5.mjs.map +0 -1
- package/dist/types-8KKo9Hbf.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -141,7 +141,7 @@ npx vitest run
|
|
|
141
141
|
- Suite and test definition using `describe()` and `test()` in AssemblyScript
|
|
142
142
|
- Inline test option configuration for common vitest options: `timeout`, `retry`, `skip`, `only`, `fails`
|
|
143
143
|
- Assertion matching API based on vitest/jest `expect()` API
|
|
144
|
-
- `.not`, `toBe`, `toBeCloseTo`, `toEqual` (with caveats*), `toStrictEqual`, `toHaveLength`, `toThrowError`, `toBeTruthy`, `toBeFalsy`, `toBeNull`, `toBeNullable`, `toBeNaN`
|
|
144
|
+
- `.not`, `toBe`, `toBeCloseTo`, `toEqual` (with caveats*), `toStrictEqual`, `toBeGreaterThan`, `toBeGreaterThanOrEqual`, `toBeLessThan`, `toBeLessThanOrEqual`, `toHaveLength`, `toThrowError`, `toBeTruthy`, `toBeFalsy`, `toBeNull`, `toBeNullable`, `toBeNaN`
|
|
145
145
|
- See [Matchers API](docs/matchers-api.md) for details and differences from JavaScript
|
|
146
146
|
- Highlighted diffs for assertion and runtime failures, which point to source code
|
|
147
147
|
- Source-mapped WASM error stack traces (accurate AssemblyScript source `function file:line:column`)
|
|
@@ -166,11 +166,15 @@ npx vitest run
|
|
|
166
166
|
|
|
167
167
|
| Dependency | Supported Versions |
|
|
168
168
|
|---|---|
|
|
169
|
-
| Node.js | 20, 22, 24+ |
|
|
169
|
+
| Node.js | (20*), 22, 24+ |
|
|
170
170
|
| Vitest | 3.2.x, 4.x |
|
|
171
171
|
| AssemblyScript | 0.28+ |
|
|
172
172
|
|
|
173
|
-
|
|
173
|
+
>ℹ️ ***Node 20 Support:** If you don't need code coverage, Node 20 should continue to work for test execution.
|
|
174
|
+
>
|
|
175
|
+
>WASM coverage instrumentation is implemented using WebAssembly [multi-memory](https://github.com/WebAssembly/multi-memory) to isolate coverage counters from user test memory. This feature shipped in V8 12.0 / Node 22.
|
|
176
|
+
|
|
177
|
+
**Platforms with prebuilt native binaries for coverage instrumentation & debug info:**
|
|
174
178
|
|
|
175
179
|
| | x64 | arm64 |
|
|
176
180
|
|---|---|---|
|
|
@@ -293,7 +297,7 @@ These are known limitations which are currently being worked on.
|
|
|
293
297
|
- Maybe: Per-file compilation setting override
|
|
294
298
|
|
|
295
299
|
**Epic: Expand expect matcher API**
|
|
296
|
-
- Planned: `toBeDefined`, `toBeUndefined`, `
|
|
300
|
+
- Planned: `toBeDefined`, `toBeUndefined`, `toContain`, `toContainEqual`
|
|
297
301
|
- Likely: `toBeOneOf`, `toBeTypeOf`, `toBeInstanceOf`, `toHaveProperty`, `toMatch`
|
|
298
302
|
|
|
299
303
|
**Epic: Spy and Mock**
|
package/assembly/compare.ts
CHANGED
|
@@ -219,6 +219,133 @@ export function equals<T, U>(actual: T, expected: U): bool {
|
|
|
219
219
|
);
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
export enum InequalityOperation {
|
|
223
|
+
LessThan,
|
|
224
|
+
LessThanOrEqual,
|
|
225
|
+
GreaterThan,
|
|
226
|
+
GreaterThanOrEqual,
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Applies an inequality operation to two values of the same promoted type.
|
|
231
|
+
* Handles <, <=, >, >= for any type that supports these operators (numbers, strings).
|
|
232
|
+
*/
|
|
233
|
+
function applyInequalityOp<T>(a: T, b: T, op: InequalityOperation): bool {
|
|
234
|
+
if (op == InequalityOperation.LessThan) return a < b;
|
|
235
|
+
if (op == InequalityOperation.LessThanOrEqual) return a <= b;
|
|
236
|
+
if (op == InequalityOperation.GreaterThan) return a > b;
|
|
237
|
+
return a >= b; // GreaterThanOrEqual
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Generic inequality comparison. Promotes both values to a common type and applies
|
|
242
|
+
* the requested inequality operation.
|
|
243
|
+
*
|
|
244
|
+
* Strings are compared lexicographically. Booleans are treated as integers (true=1, false=0).
|
|
245
|
+
* Non-string references are not comparable and throw an error.
|
|
246
|
+
*
|
|
247
|
+
* Cross-sign integer comparisons are supported (more permissive than AS's own operators)
|
|
248
|
+
* via signed-negative early return + u64 promotion. Float/integer combinations where the
|
|
249
|
+
* float's mantissa cannot losslessly represent the integer type's range are rejected,
|
|
250
|
+
* matching AS compiler behavior. See docs/matcher-research.md for details.
|
|
251
|
+
*/
|
|
252
|
+
export function compareInequality<T, U>(actual: T, compareTo: U, expectedOperation: InequalityOperation): bool {
|
|
253
|
+
// --- Strings: lexicographic comparison ---
|
|
254
|
+
if (isString<T>() && isString<U>()) {
|
|
255
|
+
// Guard against null before casting, mirroring identical()'s pattern
|
|
256
|
+
const actualIsNull = isNullable<T>() && actual == null;
|
|
257
|
+
const compareToIsNull = isNullable<U>() && compareTo == null;
|
|
258
|
+
if (actualIsNull || compareToIsNull) {
|
|
259
|
+
throw new Error(
|
|
260
|
+
"Cannot compare null string with inequality operators: the result is undefined."
|
|
261
|
+
+ " Use toBeNull() to check for null values."
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
return applyInequalityOp(<string>actual, <string>compareTo, expectedOperation);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// --- Reject non-string references (objects, arrays, etc.) ---
|
|
268
|
+
if (isReference<T>() || isReference<U>()) {
|
|
269
|
+
throw new Error(
|
|
270
|
+
"Inequality comparison is not supported for " + nameof<T>() + " and " + nameof<U>()
|
|
271
|
+
+ ". Only numeric types and strings can be compared with inequality matchers."
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// --- Float/integer precision-loss rejection ---
|
|
276
|
+
// Reject combinations where the float's mantissa cannot losslessly represent
|
|
277
|
+
// the integer type's full range (sizeof(integer) >= sizeof(float)).
|
|
278
|
+
// This mirrors AS's own operator rejection (e.g. f32 > i32, f64 > i64).
|
|
279
|
+
if (isFloat<T>() && isInteger<U>()) {
|
|
280
|
+
if (sizeof<U>() >= sizeof<T>()) {
|
|
281
|
+
throw new Error(
|
|
282
|
+
"Cannot compare " + nameof<T>() + " with " + nameof<U>()
|
|
283
|
+
+ ": float precision is insufficient for the integer type's range."
|
|
284
|
+
+ " Cast both values to f64 before comparing, e.g. expect(f64(a)).toBeGreaterThan(f64(b))."
|
|
285
|
+
+ " Note: large integer values may lose precision when cast to f64, which could cause false positives."
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
} else if (isInteger<T>() && isFloat<U>()) {
|
|
289
|
+
if (sizeof<T>() >= sizeof<U>()) {
|
|
290
|
+
throw new Error(
|
|
291
|
+
"Cannot compare " + nameof<T>() + " with " + nameof<U>()
|
|
292
|
+
+ ": float precision is insufficient for the integer type's range."
|
|
293
|
+
+ " Cast both values to f64 before comparing, e.g. expect(f64(a)).toBeGreaterThan(f64(b))."
|
|
294
|
+
+ " Note: large integer values may lose precision when cast to f64, which could cause false positives."
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// --- Numeric comparisons ---
|
|
300
|
+
// Booleans flow through here naturally (isInteger<bool>() is true in AS).
|
|
301
|
+
|
|
302
|
+
if (isInteger<T>() && isInteger<U>()) {
|
|
303
|
+
// Both signed → promote to i64
|
|
304
|
+
if (isSigned<T>() && isSigned<U>()) {
|
|
305
|
+
return applyInequalityOp(i64(actual), i64(compareTo), expectedOperation);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Both unsigned → promote to u64
|
|
309
|
+
if (!isSigned<T>() && !isSigned<U>()) {
|
|
310
|
+
return applyInequalityOp(u64(actual), u64(compareTo), expectedOperation);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Mixed sign — more permissive than AS, which rejects these at compile time.
|
|
314
|
+
// If the signed value is negative, the result is deterministic: signed < unsigned.
|
|
315
|
+
if (isSigned<T>() && !isSigned<U>()) {
|
|
316
|
+
if (i64(actual) < 0) {
|
|
317
|
+
// actual (signed negative) is always less than compareTo (unsigned)
|
|
318
|
+
return expectedOperation == InequalityOperation.LessThan
|
|
319
|
+
|| expectedOperation == InequalityOperation.LessThanOrEqual;
|
|
320
|
+
}
|
|
321
|
+
return applyInequalityOp(u64(actual), u64(compareTo), expectedOperation);
|
|
322
|
+
} else {
|
|
323
|
+
// !isSigned<T>() && isSigned<U>()
|
|
324
|
+
if (i64(compareTo) < 0) {
|
|
325
|
+
// compareTo (signed negative) is always less than actual (unsigned)
|
|
326
|
+
return expectedOperation == InequalityOperation.GreaterThan
|
|
327
|
+
|| expectedOperation == InequalityOperation.GreaterThanOrEqual;
|
|
328
|
+
}
|
|
329
|
+
return applyInequalityOp(u64(actual), u64(compareTo), expectedOperation);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Both floats → promote to f64
|
|
334
|
+
if (isFloat<T>() && isFloat<U>()) {
|
|
335
|
+
return applyInequalityOp(f64(actual), f64(compareTo), expectedOperation);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Supported float/integer combo (passed precision-loss check above) → promote to f64
|
|
339
|
+
if ( (isFloat<T>() && isInteger<U>()) || (isInteger<T>() && isFloat<U>()) ) {
|
|
340
|
+
return applyInequalityOp(f64(actual), f64(compareTo), expectedOperation);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Unsupported type combination (e.g. vectors)
|
|
344
|
+
throw new Error(
|
|
345
|
+
"Inequality comparison is not supported for " + nameof<T>() + " and " + nameof<U>() + "."
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
222
349
|
export function truthyOrFalsey<T>(actual: T, expected: bool): bool {
|
|
223
350
|
return actual ? expected == true : expected == false;
|
|
224
351
|
}
|
package/assembly/expect.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
closeTo,
|
|
3
|
+
compareInequality,
|
|
3
4
|
equals,
|
|
4
5
|
identical,
|
|
6
|
+
InequalityOperation,
|
|
5
7
|
isNull,
|
|
6
8
|
nan,
|
|
7
9
|
truthyOrFalsey
|
|
@@ -97,12 +99,12 @@ abstract class BaseExpectMatcher<T> {
|
|
|
97
99
|
* objects, arrays, etc).
|
|
98
100
|
*
|
|
99
101
|
* Cross-type numeric comparisons are allowed where AssemblyScript's own `==` operator
|
|
100
|
-
* permits them (e.g. `f64` vs `i32`).
|
|
101
|
-
*
|
|
102
|
-
*
|
|
102
|
+
* permits them (e.g. `f64` vs `i32`). `toBeCloseTo()` is safer for any comparison
|
|
103
|
+
* involving a float and allows all numeric types because it can still produce accurate
|
|
104
|
+
* results in precision-loss casting edge cases.
|
|
103
105
|
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
+
* @throws When comparing float/integer types where the float's mantissa cannot losslessly
|
|
107
|
+
* represent the integer type's range (e.g. `f32` vs `i32`, `f64` vs `i64`).
|
|
106
108
|
*
|
|
107
109
|
* @example
|
|
108
110
|
* expect(1 + 1).toBe(2);
|
|
@@ -132,7 +134,7 @@ abstract class BaseExpectMatcher<T> {
|
|
|
132
134
|
* Strings are compared by value equality as with `toBe`. Non-numeric, non-string types return false.
|
|
133
135
|
*
|
|
134
136
|
* @param precision - Specify the number of decimal places that must match for values to be
|
|
135
|
-
* considered close. Defaults to 2 digits, meaning effectively that values must be within 0.005 of
|
|
137
|
+
* considered close. Defaults to 2 digits, meaning effectively that values must be within 0.005 of
|
|
136
138
|
* each other.
|
|
137
139
|
*
|
|
138
140
|
* @example
|
|
@@ -142,7 +144,109 @@ abstract class BaseExpectMatcher<T> {
|
|
|
142
144
|
toBeCloseTo<U>(val: U, precision: i32 = 2): void {
|
|
143
145
|
this.assertComparison(closeTo(this.actual, val, precision), this.actual, val, "to be close to", true);
|
|
144
146
|
}
|
|
145
|
-
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Checks that a value is greater than the expected value. Supports numeric types
|
|
150
|
+
* (integers, floats, booleans) and strings (lexicographic comparison).
|
|
151
|
+
*
|
|
152
|
+
* Cross-type numeric comparisons are allowed where safe, including cross-sign integers
|
|
153
|
+
* (more permissive than AS's own `>` operator). Booleans are treated as numeric
|
|
154
|
+
* (true=1, false=0).
|
|
155
|
+
*
|
|
156
|
+
* @throws When comparing float/integer types where the float's mantissa cannot losslessly
|
|
157
|
+
* represent the integer type's range (e.g. `f32` vs `i32`, `f64` vs `i64`).
|
|
158
|
+
* @throws When comparing nullable strings where either value is null. Use `toBeNull()`
|
|
159
|
+
* to check for null values.
|
|
160
|
+
* @throws When comparing non-string reference types (objects, arrays, etc).
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* expect(10).toBeGreaterThan(5);
|
|
164
|
+
* expect(3.14).toBeGreaterThan(3);
|
|
165
|
+
* expect("banana").toBeGreaterThan("apple");
|
|
166
|
+
*/
|
|
167
|
+
toBeGreaterThan<U>(val: U): void {
|
|
168
|
+
this.assertComparison(
|
|
169
|
+
compareInequality(this.actual, val, InequalityOperation.GreaterThan),
|
|
170
|
+
this.actual, val, "to be greater than", true
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Checks that a value is greater than or equal to the expected value. Supports numeric
|
|
176
|
+
* types (integers, floats, booleans) and strings (lexicographic comparison).
|
|
177
|
+
*
|
|
178
|
+
* Cross-type numeric comparisons are allowed where safe, including cross-sign integers
|
|
179
|
+
* (more permissive than AS's own `>=` operator). Booleans are treated as numeric
|
|
180
|
+
* (true=1, false=0).
|
|
181
|
+
*
|
|
182
|
+
* @throws When comparing float/integer types where the float's mantissa cannot losslessly
|
|
183
|
+
* represent the integer type's range (e.g. `f32` vs `i32`, `f64` vs `i64`).
|
|
184
|
+
* @throws When comparing nullable strings where either value is null. Use `toBeNull()`
|
|
185
|
+
* to check for null values.
|
|
186
|
+
* @throws When comparing non-string reference types (objects, arrays, etc).
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* expect(10).toBeGreaterThanOrEqual(10);
|
|
190
|
+
* expect(3.14).toBeGreaterThanOrEqual(3);
|
|
191
|
+
*/
|
|
192
|
+
toBeGreaterThanOrEqual<U>(val: U): void {
|
|
193
|
+
this.assertComparison(
|
|
194
|
+
compareInequality(this.actual, val, InequalityOperation.GreaterThanOrEqual),
|
|
195
|
+
this.actual, val, "to be greater than or equal to", true
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Checks that a value is less than the expected value. Supports numeric types
|
|
201
|
+
* (integers, floats, booleans) and strings (lexicographic comparison).
|
|
202
|
+
*
|
|
203
|
+
* Cross-type numeric comparisons are allowed where safe, including cross-sign integers
|
|
204
|
+
* (more permissive than AS's own `<` operator). Booleans are treated as numeric
|
|
205
|
+
* (true=1, false=0).
|
|
206
|
+
*
|
|
207
|
+
* @throws When comparing float/integer types where the float's mantissa cannot losslessly
|
|
208
|
+
* represent the integer type's range (e.g. `f32` vs `i32`, `f64` vs `i64`).
|
|
209
|
+
* @throws When comparing nullable strings where either value is null. Use `toBeNull()`
|
|
210
|
+
* to check for null values.
|
|
211
|
+
* @throws When comparing non-string reference types (objects, arrays, etc).
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* expect(5).toBeLessThan(10);
|
|
215
|
+
* expect(3).toBeLessThan(3.14);
|
|
216
|
+
* expect("apple").toBeLessThan("banana");
|
|
217
|
+
*/
|
|
218
|
+
toBeLessThan<U>(val: U): void {
|
|
219
|
+
this.assertComparison(
|
|
220
|
+
compareInequality(this.actual, val, InequalityOperation.LessThan),
|
|
221
|
+
this.actual, val, "to be less than", true
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Checks that a value is less than or equal to the expected value. Supports numeric
|
|
227
|
+
* types (integers, floats, booleans) and strings (lexicographic comparison).
|
|
228
|
+
*
|
|
229
|
+
* Cross-type numeric comparisons are allowed where safe, including cross-sign integers
|
|
230
|
+
* (more permissive than AS's own `<=` operator). Booleans are treated as numeric
|
|
231
|
+
* (true=1, false=0).
|
|
232
|
+
*
|
|
233
|
+
* @throws When comparing float/integer types where the float's mantissa cannot losslessly
|
|
234
|
+
* represent the integer type's range (e.g. `f32` vs `i32`, `f64` vs `i64`).
|
|
235
|
+
* @throws When comparing nullable strings where either value is null. Use `toBeNull()`
|
|
236
|
+
* to check for null values.
|
|
237
|
+
* @throws When comparing non-string reference types (objects, arrays, etc).
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* expect(5).toBeLessThanOrEqual(5);
|
|
241
|
+
* expect(3).toBeLessThanOrEqual(3.14);
|
|
242
|
+
*/
|
|
243
|
+
toBeLessThanOrEqual<U>(val: U): void {
|
|
244
|
+
this.assertComparison(
|
|
245
|
+
compareInequality(this.actual, val, InequalityOperation.LessThanOrEqual),
|
|
246
|
+
this.actual, val, "to be less than or equal to", true
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
146
250
|
/**
|
|
147
251
|
* Checks that two values have the same value (deep equality). Currently supports
|
|
148
252
|
* checking equality of Arrays, Sets, Maps, and nulls. Values inside arrays are
|
|
@@ -151,13 +255,14 @@ abstract class BaseExpectMatcher<T> {
|
|
|
151
255
|
* `toBe()` rules.
|
|
152
256
|
*
|
|
153
257
|
* Like `toBe`, cross-type numeric comparisons follow AssemblyScript's own `==` operator
|
|
154
|
-
* restrictions.
|
|
155
|
-
*
|
|
156
|
-
* `f64` vs `i64`). `toBeCloseTo()` is safer for any comparison involving a float and
|
|
157
|
-
* accurately handles these edge cases.
|
|
258
|
+
* restrictions. `toBeCloseTo()` is safer for any comparison involving a float and
|
|
259
|
+
* accurately handles precision-loss edge cases.
|
|
158
260
|
*
|
|
159
261
|
* ⚠️ IMPORTANT: Does not yet support user-defined object deep equality checking.
|
|
160
262
|
*
|
|
263
|
+
* @throws When comparing float/integer types where the float's mantissa cannot losslessly
|
|
264
|
+
* represent the integer type's range (e.g. `f32` vs `i32`, `f64` vs `i64`).
|
|
265
|
+
*
|
|
161
266
|
* @example
|
|
162
267
|
* expect([1, 2, 3]).toEqual([1, 2, 3]);
|
|
163
268
|
* expect(["one", "two", "three"]).toEqual(["one", "two", "three"]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ASNodeKind } from "./constants-
|
|
1
|
+
import { ASNodeKind } from "./constants-DuBLuMjt.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/util/ast-visitor.ts
|
|
4
4
|
/**
|
|
@@ -307,4 +307,4 @@ var ASTVisitor = class {
|
|
|
307
307
|
|
|
308
308
|
//#endregion
|
|
309
309
|
export { ASTVisitor };
|
|
310
|
-
//# sourceMappingURL=ast-visitor-
|
|
310
|
+
//# sourceMappingURL=ast-visitor-DJLJd5dt.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast-visitor-lTahoS9R.mjs","names":[],"sources":["../src/util/ast-visitor.ts"],"sourcesContent":["/**\n * Base AST Visitor for AssemblyScript\n *\n * Provides reusable walking logic for traversing AS AST nodes.\n * Subclasses override hook methods to perform specific tasks.\n *\n * Used by:\n * - ast-parser.ts: Extract function metadata for coverage\n * - strip-inline.mts: Strip @inline decorators\n */\n\nimport {\n Node,\n Source,\n BlockStatement,\n FunctionDeclaration,\n MethodDeclaration,\n ClassDeclaration,\n NamespaceDeclaration,\n VariableStatement,\n VariableDeclaration,\n FunctionExpression,\n ExpressionStatement,\n BinaryExpression,\n PropertyAccessExpression,\n IfStatement,\n WhileStatement,\n DoStatement,\n ForStatement,\n ForOfStatement,\n SwitchStatement,\n SwitchCase,\n TryStatement,\n ThrowStatement,\n ReturnStatement,\n CallExpression,\n NewExpression,\n ParenthesizedExpression,\n TernaryExpression,\n CommaExpression,\n AssertionExpression,\n InstanceOfExpression,\n ElementAccessExpression,\n UnaryPostfixExpression,\n UnaryPrefixExpression,\n ClassExpression,\n ParameterNode,\n EnumDeclaration,\n EnumValueDeclaration,\n FieldDeclaration,\n InterfaceDeclaration,\n VoidStatement,\n} from 'assemblyscript';\n\nimport { ASNodeKind } from '../types/constants.js';\n\n/**\n * Abstract base class for AST visitors.\n *\n * Subclasses override hook methods to perform tasks during traversal:\n * - beforeVisit: Called before visiting each node (e.g., strip decorators)\n * - onFunctionDeclaration: Called when visiting a function declaration\n * - onMethodDeclaration: Called when visiting a method declaration\n * - onVariableDeclaration: Called when visiting a variable declaration\n * - onClassEnter/onClassExit: Called when entering/exiting a class\n */\nexport abstract class ASTVisitor {\n /**\n * Visit all statements in a source file\n */\n visitSource(source: Source): void {\n for (const stmt of source.statements) {\n this.visitNode(stmt);\n }\n }\n\n /**\n * Hook called before visiting each node.\n * Override to perform pre-visit tasks (e.g., stripping decorators).\n */\n protected beforeVisit(_node: Node): void {}\n\n /**\n * Hook called when entering a class declaration.\n * Override to track class context.\n */\n protected onClassEnter(_node: ClassDeclaration): void {}\n\n /**\n * Hook called when exiting a class declaration.\n * Override to restore class context.\n */\n protected onClassExit(_node: ClassDeclaration): void {}\n\n /**\n * Hook called when visiting a function declaration.\n * Override to extract function info or perform other tasks.\n * Return false to skip recursing into the function body.\n */\n protected onFunctionDeclaration(_node: FunctionDeclaration): boolean {\n return true; // Continue recursion by default\n }\n\n /**\n * Hook called when visiting a method declaration.\n * Override to extract method info or perform other tasks.\n * Return false to skip recursing into the method body.\n */\n protected onMethodDeclaration(_node: MethodDeclaration): boolean {\n return true; // Continue recursion by default\n }\n\n /**\n * Hook called when visiting a variable declaration.\n * Override to handle variable declarations (e.g., arrow functions).\n * Return false to skip recursing into the initializer.\n */\n protected onVariableDeclaration(_node: VariableDeclaration): boolean {\n return true; // Continue recursion by default\n }\n\n /**\n * Main visitor dispatch - routes to specific handler based on node kind\n */\n visitNode(node: Node): void {\n // Call pre-visit hook\n this.beforeVisit(node);\n\n // Recurse into children based on node kind\n switch (node.kind) {\n // Type nodes - no children to visit\n case ASNodeKind.NamedType:\n case ASNodeKind.FunctionType:\n case ASNodeKind.TypeName:\n case ASNodeKind.TypeParameter:\n break;\n\n // Parameter - may have default value\n case ASNodeKind.Parameter: {\n const param = node as ParameterNode;\n if (param.initializer) this.visitNode(param.initializer);\n break;\n }\n\n // Simple expressions - no children\n case ASNodeKind.Identifier:\n case ASNodeKind.False:\n case ASNodeKind.Literal:\n case ASNodeKind.Null:\n case ASNodeKind.Omitted:\n case ASNodeKind.Super:\n case ASNodeKind.This:\n case ASNodeKind.True:\n case ASNodeKind.Constructor:\n case ASNodeKind.Compiled:\n break;\n\n // Expressions with children\n case ASNodeKind.Assertion: {\n const expr = node as AssertionExpression;\n this.visitNode(expr.expression);\n break;\n }\n case ASNodeKind.Binary: {\n const expr = node as BinaryExpression;\n this.visitNode(expr.left);\n this.visitNode(expr.right);\n break;\n }\n case ASNodeKind.Call: {\n const expr = node as CallExpression;\n this.visitNode(expr.expression);\n for (const arg of expr.args) this.visitNode(arg);\n break;\n }\n case ASNodeKind.Class: {\n const expr = node as ClassExpression;\n this.visitNode(expr.declaration);\n break;\n }\n case ASNodeKind.Comma: {\n const expr = node as CommaExpression;\n for (const e of expr.expressions) this.visitNode(e);\n break;\n }\n case ASNodeKind.ElementAccess: {\n const expr = node as ElementAccessExpression;\n this.visitNode(expr.expression);\n this.visitNode(expr.elementExpression);\n break;\n }\n case ASNodeKind.Function: {\n const expr = node as FunctionExpression;\n this.visitNode(expr.declaration);\n break;\n }\n case ASNodeKind.InstanceOf: {\n const expr = node as InstanceOfExpression;\n this.visitNode(expr.expression);\n break;\n }\n case ASNodeKind.New: {\n const expr = node as NewExpression;\n for (const arg of expr.args) this.visitNode(arg);\n break;\n }\n case ASNodeKind.Parenthesized: {\n const expr = node as ParenthesizedExpression;\n this.visitNode(expr.expression);\n break;\n }\n case ASNodeKind.PropertyAccess: {\n const expr = node as PropertyAccessExpression;\n this.visitNode(expr.expression);\n break;\n }\n case ASNodeKind.Ternary: {\n const expr = node as TernaryExpression;\n this.visitNode(expr.condition);\n this.visitNode(expr.ifThen);\n this.visitNode(expr.ifElse);\n break;\n }\n case ASNodeKind.UnaryPostfix: {\n const expr = node as UnaryPostfixExpression;\n this.visitNode(expr.operand);\n break;\n }\n case ASNodeKind.UnaryPrefix: {\n const expr = node as UnaryPrefixExpression;\n this.visitNode(expr.operand);\n break;\n }\n\n // Statements with no interesting children\n case ASNodeKind.Break:\n case ASNodeKind.Continue:\n case ASNodeKind.Empty:\n case ASNodeKind.Export:\n case ASNodeKind.ExportDefault:\n case ASNodeKind.ExportImport:\n case ASNodeKind.Import:\n case ASNodeKind.Module:\n break;\n\n // Statements with children\n case ASNodeKind.Block: {\n const stmt = node as BlockStatement;\n for (const s of stmt.statements) this.visitNode(s);\n break;\n }\n case ASNodeKind.Do: {\n const stmt = node as DoStatement;\n this.visitNode(stmt.body);\n this.visitNode(stmt.condition);\n break;\n }\n case ASNodeKind.Expression: {\n const stmt = node as ExpressionStatement;\n this.visitNode(stmt.expression);\n break;\n }\n case ASNodeKind.For: {\n const stmt = node as ForStatement;\n if (stmt.initializer) this.visitNode(stmt.initializer);\n if (stmt.condition) this.visitNode(stmt.condition);\n if (stmt.incrementor) this.visitNode(stmt.incrementor);\n this.visitNode(stmt.body);\n break;\n }\n case ASNodeKind.ForOf: {\n const stmt = node as ForOfStatement;\n this.visitNode(stmt.variable);\n this.visitNode(stmt.iterable);\n this.visitNode(stmt.body);\n break;\n }\n case ASNodeKind.If: {\n const stmt = node as IfStatement;\n this.visitNode(stmt.condition);\n this.visitNode(stmt.ifTrue);\n if (stmt.ifFalse) this.visitNode(stmt.ifFalse);\n break;\n }\n case ASNodeKind.Return: {\n const stmt = node as ReturnStatement;\n if (stmt.value) this.visitNode(stmt.value);\n break;\n }\n case ASNodeKind.Switch: {\n const stmt = node as SwitchStatement;\n this.visitNode(stmt.condition);\n for (const switchCase of stmt.cases) this.visitNode(switchCase);\n break;\n }\n case ASNodeKind.Throw: {\n const stmt = node as ThrowStatement;\n this.visitNode(stmt.value);\n break;\n }\n case ASNodeKind.Try: {\n const stmt = node as TryStatement;\n for (const s of stmt.bodyStatements) this.visitNode(s);\n if (stmt.catchStatements) {\n for (const s of stmt.catchStatements) this.visitNode(s);\n }\n if (stmt.finallyStatements) {\n for (const s of stmt.finallyStatements) this.visitNode(s);\n }\n break;\n }\n case ASNodeKind.Variable: {\n const stmt = node as VariableStatement;\n for (const decl of stmt.declarations) this.visitNode(decl);\n break;\n }\n case ASNodeKind.Void: {\n const stmt = node as VoidStatement;\n this.visitNode(stmt.expression);\n break;\n }\n case ASNodeKind.While: {\n const stmt = node as WhileStatement;\n this.visitNode(stmt.condition);\n this.visitNode(stmt.body);\n break;\n }\n case ASNodeKind.SwitchCase: {\n const stmt = node as SwitchCase;\n if (stmt.label) this.visitNode(stmt.label);\n for (const s of stmt.statements) this.visitNode(s);\n break;\n }\n\n // Declaration statements\n case ASNodeKind.ImportDeclaration:\n case ASNodeKind.TypeDeclaration:\n break;\n\n case ASNodeKind.ClassDeclaration: {\n const decl = node as ClassDeclaration;\n this.onClassEnter(decl);\n for (const member of decl.members) this.visitNode(member);\n this.onClassExit(decl);\n break;\n }\n case ASNodeKind.EnumDeclaration: {\n const decl = node as EnumDeclaration;\n for (const value of decl.values) this.visitNode(value);\n break;\n }\n case ASNodeKind.EnumValueDeclaration: {\n const decl = node as EnumValueDeclaration;\n if (decl.initializer) this.visitNode(decl.initializer);\n break;\n }\n case ASNodeKind.FieldDeclaration: {\n const decl = node as FieldDeclaration;\n if (decl.initializer) this.visitNode(decl.initializer);\n break;\n }\n case ASNodeKind.FunctionDeclaration: {\n const decl = node as FunctionDeclaration;\n const shouldRecurse = this.onFunctionDeclaration(decl);\n if (shouldRecurse && decl.body) this.visitNode(decl.body);\n break;\n }\n case ASNodeKind.InterfaceDeclaration: {\n const decl = node as InterfaceDeclaration;\n for (const member of decl.members) this.visitNode(member);\n break;\n }\n case ASNodeKind.MethodDeclaration: {\n const decl = node as MethodDeclaration;\n const shouldRecurse = this.onMethodDeclaration(decl);\n if (shouldRecurse && decl.body) this.visitNode(decl.body);\n break;\n }\n case ASNodeKind.NamespaceDeclaration: {\n const decl = node as NamespaceDeclaration;\n for (const member of decl.members) this.visitNode(member);\n break;\n }\n case ASNodeKind.VariableDeclaration: {\n const decl = node as VariableDeclaration;\n const shouldRecurse = this.onVariableDeclaration(decl);\n if (shouldRecurse && decl.initializer) this.visitNode(decl.initializer);\n break;\n }\n\n // Special nodes - no action needed\n case ASNodeKind.ExportMember:\n case ASNodeKind.IndexSignature:\n case ASNodeKind.Comment:\n case ASNodeKind.Decorator:\n break;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAkEA,IAAsB,aAAtB,MAAiC;;;;CAI/B,YAAY,QAAsB;AAChC,OAAK,MAAM,QAAQ,OAAO,WACxB,MAAK,UA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M,UAAU,KAAK,QAAS,MAAK,UAAU,OAAO;AACzD;;GAEF,KAAK,WAAW,qBAAqB;IACnC,MAAM,OAAO;AAEb,QADsB,KAAK,sBAAsB,KAAK,IACjC,KAAK,YAAa,MAAK,UAAU,KAAK,YAAY;AACvE;;GAIF,KAAK,WAAW;GAChB,KAAK,WAAW;GAChB,KAAK,WAAW;GAChB,KAAK,WAAW,UACd"}
|
|
1
|
+
{"version":3,"file":"ast-visitor-DJLJd5dt.mjs","names":[],"sources":["../src/util/ast-visitor.ts"],"sourcesContent":["/**\n * Base AST Visitor for AssemblyScript\n *\n * Provides reusable walking logic for traversing AS AST nodes.\n * Subclasses override hook methods to perform specific tasks.\n *\n * Used by:\n * - ast-parser.ts: Extract function metadata for coverage\n * - strip-inline.mts: Strip @inline decorators\n */\n\nimport {\n Node,\n Source,\n BlockStatement,\n FunctionDeclaration,\n MethodDeclaration,\n ClassDeclaration,\n NamespaceDeclaration,\n VariableStatement,\n VariableDeclaration,\n FunctionExpression,\n ExpressionStatement,\n BinaryExpression,\n PropertyAccessExpression,\n IfStatement,\n WhileStatement,\n DoStatement,\n ForStatement,\n ForOfStatement,\n SwitchStatement,\n SwitchCase,\n TryStatement,\n ThrowStatement,\n ReturnStatement,\n CallExpression,\n NewExpression,\n ParenthesizedExpression,\n TernaryExpression,\n CommaExpression,\n AssertionExpression,\n InstanceOfExpression,\n ElementAccessExpression,\n UnaryPostfixExpression,\n UnaryPrefixExpression,\n ClassExpression,\n ParameterNode,\n EnumDeclaration,\n EnumValueDeclaration,\n FieldDeclaration,\n InterfaceDeclaration,\n VoidStatement,\n} from 'assemblyscript';\n\nimport { ASNodeKind } from '../types/constants.js';\n\n/**\n * Abstract base class for AST visitors.\n *\n * Subclasses override hook methods to perform tasks during traversal:\n * - beforeVisit: Called before visiting each node (e.g., strip decorators)\n * - onFunctionDeclaration: Called when visiting a function declaration\n * - onMethodDeclaration: Called when visiting a method declaration\n * - onVariableDeclaration: Called when visiting a variable declaration\n * - onClassEnter/onClassExit: Called when entering/exiting a class\n */\nexport abstract class ASTVisitor {\n /**\n * Visit all statements in a source file\n */\n visitSource(source: Source): void {\n for (const stmt of source.statements) {\n this.visitNode(stmt);\n }\n }\n\n /**\n * Hook called before visiting each node.\n * Override to perform pre-visit tasks (e.g., stripping decorators).\n */\n protected beforeVisit(_node: Node): void {}\n\n /**\n * Hook called when entering a class declaration.\n * Override to track class context.\n */\n protected onClassEnter(_node: ClassDeclaration): void {}\n\n /**\n * Hook called when exiting a class declaration.\n * Override to restore class context.\n */\n protected onClassExit(_node: ClassDeclaration): void {}\n\n /**\n * Hook called when visiting a function declaration.\n * Override to extract function info or perform other tasks.\n * Return false to skip recursing into the function body.\n */\n protected onFunctionDeclaration(_node: FunctionDeclaration): boolean {\n return true; // Continue recursion by default\n }\n\n /**\n * Hook called when visiting a method declaration.\n * Override to extract method info or perform other tasks.\n * Return false to skip recursing into the method body.\n */\n protected onMethodDeclaration(_node: MethodDeclaration): boolean {\n return true; // Continue recursion by default\n }\n\n /**\n * Hook called when visiting a variable declaration.\n * Override to handle variable declarations (e.g., arrow functions).\n * Return false to skip recursing into the initializer.\n */\n protected onVariableDeclaration(_node: VariableDeclaration): boolean {\n return true; // Continue recursion by default\n }\n\n /**\n * Main visitor dispatch - routes to specific handler based on node kind\n */\n visitNode(node: Node): void {\n // Call pre-visit hook\n this.beforeVisit(node);\n\n // Recurse into children based on node kind\n switch (node.kind) {\n // Type nodes - no children to visit\n case ASNodeKind.NamedType:\n case ASNodeKind.FunctionType:\n case ASNodeKind.TypeName:\n case ASNodeKind.TypeParameter:\n break;\n\n // Parameter - may have default value\n case ASNodeKind.Parameter: {\n const param = node as ParameterNode;\n if (param.initializer) this.visitNode(param.initializer);\n break;\n }\n\n // Simple expressions - no children\n case ASNodeKind.Identifier:\n case ASNodeKind.False:\n case ASNodeKind.Literal:\n case ASNodeKind.Null:\n case ASNodeKind.Omitted:\n case ASNodeKind.Super:\n case ASNodeKind.This:\n case ASNodeKind.True:\n case ASNodeKind.Constructor:\n case ASNodeKind.Compiled:\n break;\n\n // Expressions with children\n case ASNodeKind.Assertion: {\n const expr = node as AssertionExpression;\n this.visitNode(expr.expression);\n break;\n }\n case ASNodeKind.Binary: {\n const expr = node as BinaryExpression;\n this.visitNode(expr.left);\n this.visitNode(expr.right);\n break;\n }\n case ASNodeKind.Call: {\n const expr = node as CallExpression;\n this.visitNode(expr.expression);\n for (const arg of expr.args) this.visitNode(arg);\n break;\n }\n case ASNodeKind.Class: {\n const expr = node as ClassExpression;\n this.visitNode(expr.declaration);\n break;\n }\n case ASNodeKind.Comma: {\n const expr = node as CommaExpression;\n for (const e of expr.expressions) this.visitNode(e);\n break;\n }\n case ASNodeKind.ElementAccess: {\n const expr = node as ElementAccessExpression;\n this.visitNode(expr.expression);\n this.visitNode(expr.elementExpression);\n break;\n }\n case ASNodeKind.Function: {\n const expr = node as FunctionExpression;\n this.visitNode(expr.declaration);\n break;\n }\n case ASNodeKind.InstanceOf: {\n const expr = node as InstanceOfExpression;\n this.visitNode(expr.expression);\n break;\n }\n case ASNodeKind.New: {\n const expr = node as NewExpression;\n for (const arg of expr.args) this.visitNode(arg);\n break;\n }\n case ASNodeKind.Parenthesized: {\n const expr = node as ParenthesizedExpression;\n this.visitNode(expr.expression);\n break;\n }\n case ASNodeKind.PropertyAccess: {\n const expr = node as PropertyAccessExpression;\n this.visitNode(expr.expression);\n break;\n }\n case ASNodeKind.Ternary: {\n const expr = node as TernaryExpression;\n this.visitNode(expr.condition);\n this.visitNode(expr.ifThen);\n this.visitNode(expr.ifElse);\n break;\n }\n case ASNodeKind.UnaryPostfix: {\n const expr = node as UnaryPostfixExpression;\n this.visitNode(expr.operand);\n break;\n }\n case ASNodeKind.UnaryPrefix: {\n const expr = node as UnaryPrefixExpression;\n this.visitNode(expr.operand);\n break;\n }\n\n // Statements with no interesting children\n case ASNodeKind.Break:\n case ASNodeKind.Continue:\n case ASNodeKind.Empty:\n case ASNodeKind.Export:\n case ASNodeKind.ExportDefault:\n case ASNodeKind.ExportImport:\n case ASNodeKind.Import:\n case ASNodeKind.Module:\n break;\n\n // Statements with children\n case ASNodeKind.Block: {\n const stmt = node as BlockStatement;\n for (const s of stmt.statements) this.visitNode(s);\n break;\n }\n case ASNodeKind.Do: {\n const stmt = node as DoStatement;\n this.visitNode(stmt.body);\n this.visitNode(stmt.condition);\n break;\n }\n case ASNodeKind.Expression: {\n const stmt = node as ExpressionStatement;\n this.visitNode(stmt.expression);\n break;\n }\n case ASNodeKind.For: {\n const stmt = node as ForStatement;\n if (stmt.initializer) this.visitNode(stmt.initializer);\n if (stmt.condition) this.visitNode(stmt.condition);\n if (stmt.incrementor) this.visitNode(stmt.incrementor);\n this.visitNode(stmt.body);\n break;\n }\n case ASNodeKind.ForOf: {\n const stmt = node as ForOfStatement;\n this.visitNode(stmt.variable);\n this.visitNode(stmt.iterable);\n this.visitNode(stmt.body);\n break;\n }\n case ASNodeKind.If: {\n const stmt = node as IfStatement;\n this.visitNode(stmt.condition);\n this.visitNode(stmt.ifTrue);\n if (stmt.ifFalse) this.visitNode(stmt.ifFalse);\n break;\n }\n case ASNodeKind.Return: {\n const stmt = node as ReturnStatement;\n if (stmt.value) this.visitNode(stmt.value);\n break;\n }\n case ASNodeKind.Switch: {\n const stmt = node as SwitchStatement;\n this.visitNode(stmt.condition);\n for (const switchCase of stmt.cases) this.visitNode(switchCase);\n break;\n }\n case ASNodeKind.Throw: {\n const stmt = node as ThrowStatement;\n this.visitNode(stmt.value);\n break;\n }\n case ASNodeKind.Try: {\n const stmt = node as TryStatement;\n for (const s of stmt.bodyStatements) this.visitNode(s);\n if (stmt.catchStatements) {\n for (const s of stmt.catchStatements) this.visitNode(s);\n }\n if (stmt.finallyStatements) {\n for (const s of stmt.finallyStatements) this.visitNode(s);\n }\n break;\n }\n case ASNodeKind.Variable: {\n const stmt = node as VariableStatement;\n for (const decl of stmt.declarations) this.visitNode(decl);\n break;\n }\n case ASNodeKind.Void: {\n const stmt = node as VoidStatement;\n this.visitNode(stmt.expression);\n break;\n }\n case ASNodeKind.While: {\n const stmt = node as WhileStatement;\n this.visitNode(stmt.condition);\n this.visitNode(stmt.body);\n break;\n }\n case ASNodeKind.SwitchCase: {\n const stmt = node as SwitchCase;\n if (stmt.label) this.visitNode(stmt.label);\n for (const s of stmt.statements) this.visitNode(s);\n break;\n }\n\n // Declaration statements\n case ASNodeKind.ImportDeclaration:\n case ASNodeKind.TypeDeclaration:\n break;\n\n case ASNodeKind.ClassDeclaration: {\n const decl = node as ClassDeclaration;\n this.onClassEnter(decl);\n for (const member of decl.members) this.visitNode(member);\n this.onClassExit(decl);\n break;\n }\n case ASNodeKind.EnumDeclaration: {\n const decl = node as EnumDeclaration;\n for (const value of decl.values) this.visitNode(value);\n break;\n }\n case ASNodeKind.EnumValueDeclaration: {\n const decl = node as EnumValueDeclaration;\n if (decl.initializer) this.visitNode(decl.initializer);\n break;\n }\n case ASNodeKind.FieldDeclaration: {\n const decl = node as FieldDeclaration;\n if (decl.initializer) this.visitNode(decl.initializer);\n break;\n }\n case ASNodeKind.FunctionDeclaration: {\n const decl = node as FunctionDeclaration;\n const shouldRecurse = this.onFunctionDeclaration(decl);\n if (shouldRecurse && decl.body) this.visitNode(decl.body);\n break;\n }\n case ASNodeKind.InterfaceDeclaration: {\n const decl = node as InterfaceDeclaration;\n for (const member of decl.members) this.visitNode(member);\n break;\n }\n case ASNodeKind.MethodDeclaration: {\n const decl = node as MethodDeclaration;\n const shouldRecurse = this.onMethodDeclaration(decl);\n if (shouldRecurse && decl.body) this.visitNode(decl.body);\n break;\n }\n case ASNodeKind.NamespaceDeclaration: {\n const decl = node as NamespaceDeclaration;\n for (const member of decl.members) this.visitNode(member);\n break;\n }\n case ASNodeKind.VariableDeclaration: {\n const decl = node as VariableDeclaration;\n const shouldRecurse = this.onVariableDeclaration(decl);\n if (shouldRecurse && decl.initializer) this.visitNode(decl.initializer);\n break;\n }\n\n // Special nodes - no action needed\n case ASNodeKind.ExportMember:\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AAO;AACzD;;GAEF,KAAK,WAAW,mBAAmB;IACjC,MAAM,OAAO;AAEb,QADsB,KAAK,oBAAoB,KAAK,IAC/B,KAAK,KAAM,MAAK,UAAU,KAAK,KAAK;AACzD;;GAEF,KAAK,WAAW,sBAAsB;IACpC,MAAM,OAAO;AACb,SAAK,MAAM,UAAU,KAAK,QAAS,MAAK,UAAU,OAAO;AACzD;;GAEF,KAAK,WAAW,qBAAqB;IACnC,MAAM,OAAO;AAEb,QADsB,KAAK,sBAAsB,KAAK,IACjC,KAAK,YAAa,MAAK,UAAU,KAAK,YAAY;AACvE;;GAIF,KAAK,WAAW;GAChB,KAAK,WAAW;GAChB,KAAK,WAAW;GAChB,KAAK,WAAW,UACd"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { POOL_ERROR_NAMES, POOL_INTERNAL_PATHS } from "./constants-
|
|
2
|
-
import { createPoolErrorFromAnyError, debug, getTestErrorFromPoolError } from "./debug-
|
|
1
|
+
import { INTERNAL_PATH_LIB_PREFIX, POOL_ERROR_NAMES, POOL_INTERNAL_PATHS } from "./constants-DuBLuMjt.mjs";
|
|
2
|
+
import { createPoolErrorFromAnyError, debug, getTestErrorFromPoolError } from "./debug-Cm1VFmaz.mjs";
|
|
3
3
|
import { failFile, getFullTaskHierarchy, prepareFileTaskForCollection } from "./vitest-file-tasks-BUwzh375.mjs";
|
|
4
|
-
import { getTaskLogLabel, getTaskLogPrefix } from "./vitest-tasks-
|
|
5
|
-
import { executeWASMDiscovery, flushRpcUpdates, reportFileCollected, reportFileError, reportFileQueued, reportUserConsoleLogs } from "./load-user-imports-
|
|
6
|
-
import { compileAssemblyScript } from "./compiler-
|
|
4
|
+
import { getTaskLogLabel, getTaskLogPrefix } from "./vitest-tasks-ByPK8DvF.mjs";
|
|
5
|
+
import { executeWASMDiscovery, flushRpcUpdates, reportFileCollected, reportFileError, reportFileQueued, reportUserConsoleLogs } from "./load-user-imports-CYTTU22Q.mjs";
|
|
6
|
+
import { compileAssemblyScript } from "./compiler-CscxCJw3.mjs";
|
|
7
7
|
import { basename, relative } from "node:path";
|
|
8
8
|
|
|
9
9
|
//#region src/pool-thread/runner/compile-runner.ts
|
|
@@ -21,14 +21,17 @@ async function runCompileAndDiscover(file, logModule, rpc, poolOptions, projectR
|
|
|
21
21
|
try {
|
|
22
22
|
await reportFileQueued(rpc, file, logModule, fileLogLabel);
|
|
23
23
|
const instrumentationOptions = {
|
|
24
|
+
projectRoot,
|
|
24
25
|
relativeExcludedFiles: [
|
|
25
26
|
relative(projectRoot, file.filepath),
|
|
26
|
-
...POOL_INTERNAL_PATHS,
|
|
27
|
+
...poolOptions._instrumentPoolInternals ? [] : POOL_INTERNAL_PATHS,
|
|
27
28
|
...relativeUserCoverageExclusions
|
|
28
29
|
],
|
|
29
30
|
excludedLibraryFilePrefix: "~lib/",
|
|
31
|
+
excludedLibraryFileOverridePrefix: poolOptions._instrumentPoolInternals ? INTERNAL_PATH_LIB_PREFIX : void 0,
|
|
30
32
|
coverageMemoryPagesMin: poolOptions.coverageMemoryPagesInitial,
|
|
31
|
-
coverageMemoryPagesMax: poolOptions.coverageMemoryPagesMax
|
|
33
|
+
coverageMemoryPagesMax: poolOptions.coverageMemoryPagesMax,
|
|
34
|
+
debug: poolOptions.debugNative
|
|
32
35
|
};
|
|
33
36
|
const compilerOptions = {
|
|
34
37
|
stripInline: poolOptions.stripInline,
|
|
@@ -77,4 +80,4 @@ async function runCompileAndDiscover(file, logModule, rpc, poolOptions, projectR
|
|
|
77
80
|
|
|
78
81
|
//#endregion
|
|
79
82
|
export { runCompileAndDiscover };
|
|
80
|
-
//# sourceMappingURL=compile-runner-
|
|
83
|
+
//# sourceMappingURL=compile-runner-BJ_ZF3Ma.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-runner-BJ_ZF3Ma.mjs","names":[],"sources":["../src/pool-thread/runner/compile-runner.ts"],"sourcesContent":["/**\n * Worker thread test runner logic for AssemblyScript Pool\n */\n\nimport { basename, relative } from 'node:path';\nimport type { File } from '@vitest/runner/types';\nimport type { SerializedDiffOptions } from '@vitest/utils/diff';\n\nimport type {\n AssemblyScriptCompilerOptions,\n AssemblyScriptConsoleLog,\n AssemblyScriptConsoleLogHandler,\n InstrumentationOptions,\n ResolvedAssemblyScriptPoolOptions,\n ThreadImports,\n WASMCompilation,\n WorkerRPC,\n} from '../../types/types.js';\nimport {\n ASSEMBLYSCRIPT_LIB_PREFIX,\n INTERNAL_PATH_LIB_PREFIX,\n POOL_ERROR_NAMES,\n POOL_INTERNAL_PATHS,\n} from '../../types/constants.js';\nimport { executeWASMDiscovery } from '../../wasm-executor/index.js';\nimport { debug } from '../../util/debug.js';\nimport {\n reportFileQueued,\n reportFileCollected,\n reportUserConsoleLogs,\n flushRpcUpdates,\n reportFileError,\n} from '../rpc-reporter.js';\nimport { createPoolErrorFromAnyError, getTestErrorFromPoolError } from '../../util/pool-errors.js';\nimport { compileAssemblyScript } from '../../compiler/index.js';\nimport {\n getTaskLogLabel,\n getTaskLogPrefix,\n} from '../../util/vitest-tasks.js';\nimport {\n failFile,\n getFullTaskHierarchy,\n prepareFileTaskForCollection,\n} from '../../util/vitest-file-tasks.js';\n\nlet threadCompilationCount: number = 0;\n\nexport async function runCompileAndDiscover(\n file: File,\n logModule: string,\n rpc: WorkerRPC,\n poolOptions: ResolvedAssemblyScriptPoolOptions,\n projectRoot: string,\n collectCoverage: boolean,\n relativeUserCoverageExclusions: string[],\n threadImports: ThreadImports,\n diffOptions?: SerializedDiffOptions,\n testNamePattern?: RegExp,\n allowOnly?: boolean,\n): Promise<WASMCompilation | undefined> {\n const base = basename(file.filepath);\n const fileLogPrefix = getTaskLogPrefix(logModule, base, file);\n const fileLogLabel = getTaskLogLabel(base, file);\n\n debug(`${fileLogPrefix} - Beginning runCompileAndDiscover for \"${file.filepath}\" at ${Date.now()}`);\n\n const runStart = performance.now();\n let compilation: WASMCompilation | undefined;\n\n try {\n await reportFileQueued(rpc, file, logModule, fileLogLabel);\n\n // TODO - move to options helpers\n const relativeTestFilePath = relative(projectRoot, file.filepath);\n const instrumentationOptions: InstrumentationOptions = {\n projectRoot,\n relativeExcludedFiles: [\n relativeTestFilePath,\n ...(poolOptions._instrumentPoolInternals ? [] : POOL_INTERNAL_PATHS),\n ...relativeUserCoverageExclusions,\n ],\n excludedLibraryFilePrefix: ASSEMBLYSCRIPT_LIB_PREFIX,\n excludedLibraryFileOverridePrefix: poolOptions._instrumentPoolInternals ? INTERNAL_PATH_LIB_PREFIX : undefined,\n coverageMemoryPagesMin: poolOptions.coverageMemoryPagesInitial,\n coverageMemoryPagesMax: poolOptions.coverageMemoryPagesMax,\n debug: poolOptions.debugNative,\n };\n const compilerOptions: AssemblyScriptCompilerOptions = {\n stripInline: poolOptions.stripInline,\n projectRoot: projectRoot,\n shouldInstrument: collectCoverage,\n instrumentationOptions,\n extraFlags: poolOptions.extraCompilerFlags\n };\n\n const { binary, sourceMap, debugInfo, compileTiming } = await compileAssemblyScript(\n file.filepath,\n compilerOptions,\n logModule,\n fileLogLabel\n );\n file.setupDuration = compileTiming;\n threadCompilationCount++;\n\n debug(`${fileLogPrefix} - TIMING compileAssemblyScript total `\n + `(thread comp # ${threadCompilationCount}): ${compileTiming.toFixed(2)} ms`\n );\n \n const logMessages: AssemblyScriptConsoleLog[] = [];\n const handleLog: AssemblyScriptConsoleLogHandler = (msg: string, isError: boolean = false): void => {\n logMessages.push({ msg, time: Date.now(), isError });\n };\n \n const discoverStart = performance.now();\n\n await executeWASMDiscovery(\n binary,\n sourceMap,\n base,\n poolOptions,\n collectCoverage,\n handleLog,\n file,\n logModule,\n threadImports,\n diffOptions\n );\n\n // set skips when using only and/or user test name pattern, skip file task if all tests skipped\n prepareFileTaskForCollection(file, testNamePattern, allowOnly);\n\n file.collectDuration = performance.now() - discoverStart;\n debug(`${fileLogPrefix} - TIMING Discovery Phase: ${file.collectDuration.toFixed(2)} ms`);\n\n // vitest collect - report discovery results\n await Promise.all([\n // Report user console logs\n reportUserConsoleLogs(rpc, logMessages, logModule, base, file),\n\n // Report onCollected with collected and filtered tasks\n reportFileCollected(rpc, file, logModule, fileLogLabel),\n ]);\n\n debug(() => `${fileLogPrefix} - Collected Test Suite Hierarchy:\\n${getFullTaskHierarchy(file)}`);\n\n const totalTime = performance.now() - runStart;\n debug(`${fileLogPrefix} - TIMING Compilation and Discovery: ${totalTime.toFixed(2)} ms`);\n\n compilation = {\n filePath: file.filepath,\n binary,\n sourceMap,\n debugInfo,\n };\n } catch (error) {\n const poolError = createPoolErrorFromAnyError(\n `${fileLogLabel} - runCompileAndDiscover failure in worker`,\n POOL_ERROR_NAMES.WASMExecutionHarnessError,\n error\n );\n const testError = getTestErrorFromPoolError(poolError);\n\n failFile(file, testError, runStart);\n\n await reportFileQueued(rpc, file, logModule, fileLogLabel);\n await reportFileError(rpc, file, logModule, fileLogLabel);\n\n debug(`${fileLogPrefix} - Reported file error`);\n } finally {\n await flushRpcUpdates(rpc);\n debug(`${fileLogPrefix} - runCompileAndDiscover Completed`);\n }\n\n return compilation;\n}\n"],"mappings":";;;;;;;;;;;;AA6CA,IAAI,yBAAiC;AAErC,eAAsB,sBACpB,MACA,WACA,KACA,aACA,aACA,iBACA,gCACA,eACA,aACA,iBACA,WACsC;CACtC,MAAM,OAAO,SAAS,KAAK,SAAS;CACpC,MAAM,gBAAgB,iBAAiB,WAAW,MAAM,KAAK;CAC7D,MAAM,eAAe,gBAAgB,MAAM,KAAK;AAEhD,OAAM,GAAG,cAAc,0CAA0C,KAAK,SAAS,OAAO,KAAK,KAAK,GAAG;CAEnG,MAAM,WAAW,YAAY,KAAK;CAClC,IAAI;AAEJ,KAAI;AACF,QAAM,iBAAiB,KAAK,MAAM,WAAW,aAAa;EAI1D,MAAM,yBAAiD;GACrD;GACA,uBAAuB;IAHI,SAAS,aAAa,KAAK,SAAS;IAK7D,GAAI,YAAY,2BAA2B,EAAE,GAAG;IAChD,GAAG;IACJ;GACD;GACA,mCAAmC,YAAY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,aAAa;AAEzD,QAAM,GAAG,cAAc,wBAAwB;WACvC;AACR,QAAM,gBAAgB,IAAI;AAC1B,QAAM,GAAG,cAAc,oCAAoC;;AAG7D,QAAO"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ASDecoratorKind, ASSourceKind } from "../../constants-
|
|
2
|
-
import { ASTVisitor } from "../../ast-visitor-
|
|
1
|
+
import { ASDecoratorKind, ASSourceKind } from "../../constants-DuBLuMjt.mjs";
|
|
2
|
+
import { ASTVisitor } from "../../ast-visitor-DJLJd5dt.mjs";
|
|
3
3
|
import { Transform } from "assemblyscript/transform";
|
|
4
4
|
|
|
5
5
|
//#region src/compiler/transforms/strip-inline.mts
|