vitest-pool-assemblyscript 0.2.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/BINARYEN_VERSION +1 -0
- package/LICENSE +53 -0
- package/README.md +607 -0
- package/assembly/compare.ts +219 -0
- package/assembly/describe.ts +104 -0
- package/assembly/expect.ts +335 -0
- package/assembly/index.ts +14 -0
- package/assembly/options.ts +198 -0
- package/assembly/test.ts +147 -0
- package/assembly/tsconfig.json +6 -0
- package/binding.gyp +62 -0
- package/dist/ast-visitor-DC3SuTzs.mjs +310 -0
- package/dist/ast-visitor-DC3SuTzs.mjs.map +1 -0
- package/dist/compile-runner-8h0dBwG2.mjs +80 -0
- package/dist/compile-runner-8h0dBwG2.mjs.map +1 -0
- package/dist/compiler/transforms/strip-inline.d.mts +18 -0
- package/dist/compiler/transforms/strip-inline.d.mts.map +1 -0
- package/dist/compiler/transforms/strip-inline.mjs +38 -0
- package/dist/compiler/transforms/strip-inline.mjs.map +1 -0
- package/dist/compiler-CN6BRK_N.mjs +295 -0
- package/dist/compiler-CN6BRK_N.mjs.map +1 -0
- package/dist/config/index-v3.d.mts +111 -0
- package/dist/config/index-v3.d.mts.map +1 -0
- package/dist/config/index-v3.mjs +11 -0
- package/dist/config/index-v3.mjs.map +1 -0
- package/dist/config/index.d.mts +4 -0
- package/dist/config/index.mjs +8 -0
- package/dist/constants-CA50WBdr.mjs +130 -0
- package/dist/constants-CA50WBdr.mjs.map +1 -0
- package/dist/coverage-merge-0WqdC-dq.mjs +22 -0
- package/dist/coverage-merge-0WqdC-dq.mjs.map +1 -0
- package/dist/coverage-provider/index.d.mts +15 -0
- package/dist/coverage-provider/index.d.mts.map +1 -0
- package/dist/coverage-provider/index.mjs +535 -0
- package/dist/coverage-provider/index.mjs.map +1 -0
- package/dist/custom-provider-options-CF5C1kXb.d.mts +26 -0
- package/dist/custom-provider-options-CF5C1kXb.d.mts.map +1 -0
- package/dist/debug-IeEHsxy0.mjs +195 -0
- package/dist/debug-IeEHsxy0.mjs.map +1 -0
- package/dist/index-internal.d.mts +23 -0
- package/dist/index-internal.d.mts.map +1 -0
- package/dist/index-internal.mjs +4 -0
- package/dist/index-v3.d.mts +7 -0
- package/dist/index-v3.d.mts.map +1 -0
- package/dist/index-v3.mjs +206 -0
- package/dist/index-v3.mjs.map +1 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +8 -0
- package/dist/load-user-imports-J9eaAW0_.mjs +801 -0
- package/dist/load-user-imports-J9eaAW0_.mjs.map +1 -0
- package/dist/pool-runner-init-CEwLyNI3.d.mts +8 -0
- package/dist/pool-runner-init-CEwLyNI3.d.mts.map +1 -0
- package/dist/pool-runner-init-d5qScS41.mjs +400 -0
- package/dist/pool-runner-init-d5qScS41.mjs.map +1 -0
- package/dist/pool-thread/compile-worker-thread.d.mts +7 -0
- package/dist/pool-thread/compile-worker-thread.d.mts.map +1 -0
- package/dist/pool-thread/compile-worker-thread.mjs +42 -0
- package/dist/pool-thread/compile-worker-thread.mjs.map +1 -0
- package/dist/pool-thread/test-worker-thread.d.mts +7 -0
- package/dist/pool-thread/test-worker-thread.d.mts.map +1 -0
- package/dist/pool-thread/test-worker-thread.mjs +39 -0
- package/dist/pool-thread/test-worker-thread.mjs.map +1 -0
- package/dist/pool-thread/v3-tinypool-thread.d.mts +7 -0
- package/dist/pool-thread/v3-tinypool-thread.d.mts.map +1 -0
- package/dist/pool-thread/v3-tinypool-thread.mjs +57 -0
- package/dist/pool-thread/v3-tinypool-thread.mjs.map +1 -0
- package/dist/resolve-config-as1w-Qyz.mjs +65 -0
- package/dist/resolve-config-as1w-Qyz.mjs.map +1 -0
- package/dist/test-runner-B2BpyPNK.mjs +142 -0
- package/dist/test-runner-B2BpyPNK.mjs.map +1 -0
- package/dist/types-8KKo9Hbf.d.mts +228 -0
- package/dist/types-8KKo9Hbf.d.mts.map +1 -0
- package/dist/vitest-file-tasks-BUwzh375.mjs +61 -0
- package/dist/vitest-file-tasks-BUwzh375.mjs.map +1 -0
- package/dist/vitest-tasks-BKS7689f.mjs +319 -0
- package/dist/vitest-tasks-BKS7689f.mjs.map +1 -0
- package/dist/worker-rpc-channel-lbhK7Qz8.mjs +25 -0
- package/dist/worker-rpc-channel-lbhK7Qz8.mjs.map +1 -0
- package/package.json +112 -0
- package/prebuilds/linux-x64/vitest-pool-assemblyscript.glibc.node +0 -0
- package/scripts/install.js +91 -0
- package/scripts/setup-binaryen.js +179 -0
- package/src/native-instrumentation/addon.cpp +788 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { POOL_ERROR_NAMES } from "./constants-CA50WBdr.mjs";
|
|
2
|
+
import { createPoolError, debug, throwPoolErrorIfAborted } from "./debug-IeEHsxy0.mjs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { basename, dirname, resolve } from "node:path";
|
|
5
|
+
import { access } from "node:fs/promises";
|
|
6
|
+
import { main } from "assemblyscript/asc";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
//#region src/native-instrumentation/addon-interface.ts
|
|
10
|
+
/**
|
|
11
|
+
* Native addon interface for extracting debug information from WebAssembly binaries
|
|
12
|
+
*
|
|
13
|
+
* This module wraps Binaryen's C++ API to provide expression-level debug locations
|
|
14
|
+
* and basic block information that the JavaScript API doesn't expose.
|
|
15
|
+
*
|
|
16
|
+
* The native addon outputs raw data (0-based columns, relative paths) which this
|
|
17
|
+
* wrapper transforms into the final BinaryDebugInfo format (1-based columns,
|
|
18
|
+
* absolute paths, grouped by file and position).
|
|
19
|
+
*/
|
|
20
|
+
const DEBUG_NATIVE_ADDON = false;
|
|
21
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
22
|
+
const rootFromDist = resolve(__dirname, "..");
|
|
23
|
+
const rootFromSrc = resolve(__dirname, "../..");
|
|
24
|
+
const nodeGypBuild = createRequire(import.meta.url)("node-gyp-build");
|
|
25
|
+
let addon;
|
|
26
|
+
try {
|
|
27
|
+
addon = nodeGypBuild(rootFromDist);
|
|
28
|
+
} catch {
|
|
29
|
+
try {
|
|
30
|
+
addon = nodeGypBuild(rootFromSrc);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
throw createPoolError(`Native addon not found. Searched from ${rootFromDist} and ${rootFromSrc}. Ensure prebuilds are available or run 'npm run build:native' to compile from source. Original error: ${err instanceof Error ? err.message : String(err)}`, POOL_ERROR_NAMES.WASMInstrumentationError);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Convert a raw location (0-indexed columns, path indexes) to
|
|
37
|
+
* processed location (1-indexed columns, path strings)
|
|
38
|
+
*/
|
|
39
|
+
function convertLocation(rawLocation, debugSourceFiles) {
|
|
40
|
+
const filePath = debugSourceFiles[rawLocation.fileIndex];
|
|
41
|
+
if (!filePath) throw createPoolError(`No debug source file with index: ${rawLocation.fileIndex}}`, POOL_ERROR_NAMES.WASMInstrumentationError);
|
|
42
|
+
return {
|
|
43
|
+
filePath,
|
|
44
|
+
line: rawLocation.line,
|
|
45
|
+
column: rawLocation.column + 1
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Convert a raw expression to processed format
|
|
50
|
+
*/
|
|
51
|
+
function convertExpression(rawExpr, debugSourceFiles) {
|
|
52
|
+
const converted = {
|
|
53
|
+
type: rawExpr.type,
|
|
54
|
+
isBranch: rawExpr.isBranch
|
|
55
|
+
};
|
|
56
|
+
if (rawExpr.branchPaths !== void 0) converted.branchPaths = rawExpr.branchPaths;
|
|
57
|
+
if (rawExpr.location) {
|
|
58
|
+
const convertedLocation = convertLocation(rawExpr.location, debugSourceFiles);
|
|
59
|
+
if (convertedLocation) converted.location = convertedLocation;
|
|
60
|
+
}
|
|
61
|
+
return converted;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Generate a position key to identify the SourceLocation uniquely
|
|
65
|
+
* within a file. Does NOT include the file identifier.
|
|
66
|
+
*/
|
|
67
|
+
function getPositionKey(location) {
|
|
68
|
+
return `${location.line}:${location.column}`;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Convert a raw function to processed format and compute position key
|
|
72
|
+
* Returns undefined if function has no valid representative location
|
|
73
|
+
*/
|
|
74
|
+
function convertFunction(rawFunc, debugSourceFiles) {
|
|
75
|
+
const representativeLocation = convertLocation(rawFunc.representativeLocation, debugSourceFiles);
|
|
76
|
+
const expressions = [];
|
|
77
|
+
if (rawFunc.expressions) for (const expr of rawFunc.expressions) expressions.push(convertExpression(expr, debugSourceFiles));
|
|
78
|
+
return {
|
|
79
|
+
func: {
|
|
80
|
+
wasmIndex: rawFunc.wasmIndex,
|
|
81
|
+
name: rawFunc.name,
|
|
82
|
+
representativeLocation,
|
|
83
|
+
coverageMemoryIndex: rawFunc.coverageMemoryIndex,
|
|
84
|
+
expressions,
|
|
85
|
+
basicBlocks: rawFunc.basicBlocks
|
|
86
|
+
},
|
|
87
|
+
filePath: representativeLocation.filePath,
|
|
88
|
+
positionKey: getPositionKey(representativeLocation)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Transform raw native addon output to processed BinaryDebugInfo
|
|
93
|
+
*/
|
|
94
|
+
function transformDebugInfo(raw, logPrefix) {
|
|
95
|
+
const functionsByFileAndPosition = {};
|
|
96
|
+
debug(`${logPrefix} - Converting ${raw.functions.length} functions`);
|
|
97
|
+
let positionCollisionCount = 0;
|
|
98
|
+
let skippedCount = 0;
|
|
99
|
+
let instrumentedFunctionCount = 0;
|
|
100
|
+
for (const rawFunc of raw.functions) {
|
|
101
|
+
const result = convertFunction(rawFunc, raw.debugSourceFiles);
|
|
102
|
+
if (!result) {
|
|
103
|
+
debug(`${logPrefix} - WARNING: Skipped function (bad conversion): "${rawFunc.name}"`);
|
|
104
|
+
skippedCount++;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const { func, filePath, positionKey } = result;
|
|
108
|
+
if (functionsByFileAndPosition[filePath]?.[positionKey]) {
|
|
109
|
+
const existing = functionsByFileAndPosition[filePath][positionKey];
|
|
110
|
+
positionCollisionCount++;
|
|
111
|
+
throw createPoolError(`ERROR - Function Debug Position Collision at ${filePath}:${positionKey}: "${existing.name}" will be replaced by "${func.name}"`, POOL_ERROR_NAMES.WASMInstrumentationError);
|
|
112
|
+
}
|
|
113
|
+
instrumentedFunctionCount++;
|
|
114
|
+
if (!functionsByFileAndPosition[filePath]) functionsByFileAndPosition[filePath] = {};
|
|
115
|
+
functionsByFileAndPosition[filePath][positionKey] = func;
|
|
116
|
+
}
|
|
117
|
+
debug(`${logPrefix} - BinaryDebugInfo transform complete: ${instrumentedFunctionCount} instrumented functions (${positionCollisionCount} position collisions, ${skippedCount} skipped)`);
|
|
118
|
+
return {
|
|
119
|
+
debugSourceFiles: raw.debugSourceFiles,
|
|
120
|
+
functionsByFileAndPosition,
|
|
121
|
+
instrumentedFunctionCount
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Instrument a WASM binary for coverage collection and regenerate source map
|
|
126
|
+
*
|
|
127
|
+
* This function:
|
|
128
|
+
* 1. Adds __coverage_memory import (multi-memory for coverage counters)
|
|
129
|
+
* 2. Injects coverage counter increments at each function entry
|
|
130
|
+
* 3. Regenerates source map with correct offsets after instrumentation
|
|
131
|
+
* 4. Extracts debug info with coverageMemoryIndex assigned
|
|
132
|
+
*
|
|
133
|
+
* @param wasmBuffer - Buffer containing the clean WASM binary
|
|
134
|
+
* @param sourceMapBuffer - Buffer containing the source map JSON
|
|
135
|
+
* @returns Instrumented binary, regenerated source map, and debug info
|
|
136
|
+
*
|
|
137
|
+
* @throws {TypeError} If wasmBuffer or sourceMapBuffer are not Buffers
|
|
138
|
+
* @throws {Error} If WASM binary or source map is invalid
|
|
139
|
+
*/
|
|
140
|
+
function instrumentForCoverage(wasmBuffer, sourceMapBuffer, instrumentationOptions, logModule, logLabel) {
|
|
141
|
+
if (!Buffer.isBuffer(wasmBuffer)) throw createPoolError("instrumentForCoverage - wasmBuffer must be a Buffer", POOL_ERROR_NAMES.WASMInstrumentationError);
|
|
142
|
+
if (!Buffer.isBuffer(sourceMapBuffer)) throw createPoolError("instrumentForCoverage - sourceMapBuffer must be a Buffer", POOL_ERROR_NAMES.WASMInstrumentationError);
|
|
143
|
+
const interfaceLogPrefix = `[${logModule} Inst] ${logLabel}`;
|
|
144
|
+
const nativeLogPrefix = `[${logModule} InstNative] ${logLabel}`;
|
|
145
|
+
debug(`${interfaceLogPrefix} - Calling native instrumentForCoverage`);
|
|
146
|
+
const startTime = performance.now();
|
|
147
|
+
const options = {
|
|
148
|
+
coverageMemoryPagesMin: instrumentationOptions.coverageMemoryPagesMin,
|
|
149
|
+
coverageMemoryPagesMax: instrumentationOptions.coverageMemoryPagesMax,
|
|
150
|
+
excludedFiles: instrumentationOptions.relativeExcludedFiles,
|
|
151
|
+
excludedLibraryFilePrefix: instrumentationOptions.excludedLibraryFilePrefix,
|
|
152
|
+
debug: DEBUG_NATIVE_ADDON,
|
|
153
|
+
logPrefix: nativeLogPrefix
|
|
154
|
+
};
|
|
155
|
+
const nativeResult = addon.instrumentForCoverage(wasmBuffer, sourceMapBuffer, options);
|
|
156
|
+
const addonTime = performance.now();
|
|
157
|
+
debug(`${interfaceLogPrefix} - TIMING Native addon: ${(addonTime - startTime).toFixed(2)} ms`);
|
|
158
|
+
if (nativeResult.errors?.length) throw createPoolError(`Errors encountered duriing native instrumentation: ${nativeResult.errors.join("\n")}`, POOL_ERROR_NAMES.WASMInstrumentationError);
|
|
159
|
+
const debugInfo = transformDebugInfo(nativeResult.debugInfo, interfaceLogPrefix);
|
|
160
|
+
debug(`${interfaceLogPrefix} - TIMING DebugInfo Transform: ${(performance.now() - addonTime).toFixed(2)} ms`);
|
|
161
|
+
debug(`${interfaceLogPrefix} - Binary size: ${nativeResult.instrumentedWasm.length} bytes | Source map size: ${nativeResult.sourceMap.length * 2} bytes`);
|
|
162
|
+
return {
|
|
163
|
+
instrumentedWasm: nativeResult.instrumentedWasm,
|
|
164
|
+
sourceMap: nativeResult.sourceMap,
|
|
165
|
+
debugInfo
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/compiler/index.ts
|
|
171
|
+
/**
|
|
172
|
+
* AssemblyScript Compiler
|
|
173
|
+
*
|
|
174
|
+
* Handles compilation of AssemblyScript source code to WASM binaries.
|
|
175
|
+
* Manages compiler options, transforms, and in-memory compilation.
|
|
176
|
+
*/
|
|
177
|
+
const STRIP_INLINE_TRANSFORM = resolve(import.meta.dirname, "./compiler/transforms/strip-inline.mjs");
|
|
178
|
+
setImmediate(async () => {
|
|
179
|
+
try {
|
|
180
|
+
await access(STRIP_INLINE_TRANSFORM);
|
|
181
|
+
} catch {
|
|
182
|
+
throw createPoolError(`AS Compiler strip inline transform file not found at "${STRIP_INLINE_TRANSFORM}"`, POOL_ERROR_NAMES.CompilationError);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
/**
|
|
186
|
+
* Compile AssemblyScript source code to WASM binary
|
|
187
|
+
*
|
|
188
|
+
* Features:
|
|
189
|
+
* - In-memory compilation (binary captured via writeFile callback)
|
|
190
|
+
* - Filesystem reading enabled (for import resolution)
|
|
191
|
+
* - Uses stub runtime and imported memory pattern
|
|
192
|
+
* - Exports _start function for explicit initialization control
|
|
193
|
+
* - Always returns clean binary
|
|
194
|
+
* - Conditionally returns instrumented binary when coverage enabled
|
|
195
|
+
*
|
|
196
|
+
* @param filename - Full path to the source file (used as entry point)
|
|
197
|
+
* @param options - Compilation options (coverage mode, etc.)
|
|
198
|
+
* @returns Compilation result with clean binary and optional instrumented binary
|
|
199
|
+
* @throws Error if compilation fails
|
|
200
|
+
*/
|
|
201
|
+
async function compileAssemblyScript(filename, options, logModule, logLabel, signal) {
|
|
202
|
+
throwPoolErrorIfAborted(signal);
|
|
203
|
+
const compileStart = performance.now();
|
|
204
|
+
const logPrefix = `[${logModule} ASC] ${logLabel}`;
|
|
205
|
+
const { shouldInstrument, instrumentationOptions, extraFlags } = options;
|
|
206
|
+
if (shouldInstrument && !instrumentationOptions) throw createPoolError("Instrumentation options are required for coverage instrumentation", POOL_ERROR_NAMES.CompilationError);
|
|
207
|
+
const stdoutLines = [];
|
|
208
|
+
const stderrLines = [];
|
|
209
|
+
let binary;
|
|
210
|
+
let sourceMap;
|
|
211
|
+
const entryFile = filename;
|
|
212
|
+
const outputFile = "output.wasm";
|
|
213
|
+
debug(`${logPrefix} - Compiling: "${filename}"`);
|
|
214
|
+
const stdout = { write: (text) => {
|
|
215
|
+
stdoutLines.push(text);
|
|
216
|
+
return true;
|
|
217
|
+
} };
|
|
218
|
+
const stderr = { write: (text) => {
|
|
219
|
+
stderrLines.push(text);
|
|
220
|
+
return true;
|
|
221
|
+
} };
|
|
222
|
+
const compilerFlags = [
|
|
223
|
+
entryFile,
|
|
224
|
+
"--optimizeLevel",
|
|
225
|
+
"0",
|
|
226
|
+
"--shrinkLevel",
|
|
227
|
+
"0",
|
|
228
|
+
"--runtime",
|
|
229
|
+
"stub",
|
|
230
|
+
...extraFlags || [],
|
|
231
|
+
"--outFile",
|
|
232
|
+
outputFile,
|
|
233
|
+
"--importMemory",
|
|
234
|
+
"--debug",
|
|
235
|
+
"--sourceMap",
|
|
236
|
+
"--exportStart",
|
|
237
|
+
"_start",
|
|
238
|
+
"--exportTable"
|
|
239
|
+
];
|
|
240
|
+
if (options.stripInline === true) {
|
|
241
|
+
compilerFlags.push("--transform", STRIP_INLINE_TRANSFORM);
|
|
242
|
+
debug(`${logPrefix} - Added Transform - Stripping @inline decorators`);
|
|
243
|
+
}
|
|
244
|
+
const ascStart = performance.now();
|
|
245
|
+
const result = await main(compilerFlags, {
|
|
246
|
+
stdout,
|
|
247
|
+
stderr,
|
|
248
|
+
writeFile: (name, contents, _baseDir) => {
|
|
249
|
+
throwPoolErrorIfAborted(signal);
|
|
250
|
+
if (name.endsWith(".wasm") && contents instanceof Uint8Array) {
|
|
251
|
+
binary = contents;
|
|
252
|
+
debug(`${logPrefix} - Captured binary in memory: "${name}"`);
|
|
253
|
+
} else if (name.endsWith(".wasm.map") && typeof contents === "string") {
|
|
254
|
+
debug(`${logPrefix} - Captured source map in memory: "${name}"`);
|
|
255
|
+
sourceMap = contents;
|
|
256
|
+
} else debug(`${logPrefix} - WARNING - Captured Unexpected File: "${name}" at baseDir: "${_baseDir}"`);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
debug(`${logPrefix} - TIMING asc.main: ${(performance.now() - ascStart).toFixed(2)} ms`);
|
|
260
|
+
if (result.error) {
|
|
261
|
+
const errorMessage = stderrLines.length > 0 ? `${result.error.message}\n\n${stderrLines.join("")}` : result.error.message;
|
|
262
|
+
throw createPoolError(errorMessage, POOL_ERROR_NAMES.CompilationError, errorMessage);
|
|
263
|
+
}
|
|
264
|
+
if (!binary) throw createPoolError(stderrLines.length > 0 ? `No WASM binary was generated\n\nAS Compiler output:\n${stderrLines.join("")}` : "No WASM binary was generated", POOL_ERROR_NAMES.CompilationError);
|
|
265
|
+
if (!sourceMap) throw createPoolError("Source map not captured from AssemblyScript Compiler", POOL_ERROR_NAMES.CompilationError);
|
|
266
|
+
const cleanBinary = binary;
|
|
267
|
+
const wasmSourceMap = sourceMap;
|
|
268
|
+
debug(`${logPrefix} - Compilation successful, clean binary size: ${cleanBinary.length} bytes`);
|
|
269
|
+
debug(`${logPrefix} - Source map generated, size: ${wasmSourceMap.length * 2} bytes`);
|
|
270
|
+
if (options.shouldInstrument) {
|
|
271
|
+
throwPoolErrorIfAborted(signal);
|
|
272
|
+
const instrumentStart = performance.now();
|
|
273
|
+
const instrumentResult = instrumentForCoverage(Buffer.from(cleanBinary), Buffer.from(wasmSourceMap), options.instrumentationOptions, logModule, logLabel);
|
|
274
|
+
const instCount = instrumentResult.debugInfo.instrumentedFunctionCount;
|
|
275
|
+
const instrumentEnd = performance.now();
|
|
276
|
+
debug(`${logPrefix} - TIMING Instrumented ${instCount} functions: ${(performance.now() - instrumentStart).toFixed(2)} ms`);
|
|
277
|
+
return {
|
|
278
|
+
binary: instrumentResult.instrumentedWasm,
|
|
279
|
+
sourceMap: instrumentResult.sourceMap,
|
|
280
|
+
debugInfo: instrumentResult.debugInfo,
|
|
281
|
+
isInstrumented: true,
|
|
282
|
+
compileTiming: instrumentEnd - compileStart
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
binary: cleanBinary,
|
|
287
|
+
sourceMap: wasmSourceMap,
|
|
288
|
+
isInstrumented: false,
|
|
289
|
+
compileTiming: performance.now() - compileStart
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
//#endregion
|
|
294
|
+
export { compileAssemblyScript };
|
|
295
|
+
//# sourceMappingURL=compiler-CN6BRK_N.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler-CN6BRK_N.mjs","names":["ascMain"],"sources":["../src/native-instrumentation/addon-interface.ts","../src/compiler/index.ts"],"sourcesContent":["/**\n * Native addon interface for extracting debug information from WebAssembly binaries\n *\n * This module wraps Binaryen's C++ API to provide expression-level debug locations\n * and basic block information that the JavaScript API doesn't expose.\n *\n * The native addon outputs raw data (0-based columns, relative paths) which this\n * wrapper transforms into the final BinaryDebugInfo format (1-based columns,\n * absolute paths, grouped by file and position).\n */\n\nimport { createRequire } from 'node:module';\nimport { resolve, dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { debug } from '../util/debug.js';\nimport {\n NativeAddon,\n NativeInstrumentationResult,\n NativeDebugInfoOutput,\n NativeFunctionDebugInfo,\n NativeExpressionDebugInfo,\n NativeSourceLocation,\n BinaryDebugInfo,\n FunctionDebugInfo,\n SourceLocation,\n ExpressionDebugInfo,\n InstrumentationResult,\n NativeInstrumentationOptions,\n InstrumentationOptions,\n} from '../types/types.js';\nimport { POOL_ERROR_NAMES } from '../types/constants.js';\nimport { createPoolError } from '../util/pool-errors.js';\n\nconst DEBUG_NATIVE_ADDON = false;\n\n// Load the native addon via node-gyp-build\n// node-gyp-build checks: prebuilds/ first, then build/Release/\n// It searches from the given directory for a package.json to find the package root.\n// We run from dist/ (published) or src/ (dev/tests), so we try both root paths.\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst rootFromDist = resolve(__dirname, '..');\nconst rootFromSrc = resolve(__dirname, '../..');\n\nconst require = createRequire(import.meta.url);\nconst nodeGypBuild: (dir: string) => NativeAddon = require('node-gyp-build');\n\nlet addon: NativeAddon;\ntry {\n addon = nodeGypBuild(rootFromDist);\n} catch {\n try {\n addon = nodeGypBuild(rootFromSrc);\n } catch (err) {\n throw createPoolError(\n `Native addon not found. Searched from ${rootFromDist} and ${rootFromSrc}. ` +\n `Ensure prebuilds are available or run 'npm run build:native' to compile from source. ` +\n `Original error: ${err instanceof Error ? err.message : String(err)}`,\n POOL_ERROR_NAMES.WASMInstrumentationError\n );\n }\n}\n\n/**\n * Convert a raw location (0-indexed columns, path indexes) to \n * processed location (1-indexed columns, path strings)\n */\nfunction convertLocation(\n rawLocation: NativeSourceLocation,\n debugSourceFiles: string[]\n): SourceLocation {\n const filePath = debugSourceFiles[rawLocation.fileIndex];\n\n if (!filePath) {\n throw createPoolError(\n `No debug source file with index: ${rawLocation.fileIndex}}`,\n POOL_ERROR_NAMES.WASMInstrumentationError\n );\n }\n \n return {\n filePath: filePath!,\n line: rawLocation.line,\n column: rawLocation.column + 1, // convert from 0-indexed to 1-indexed\n };\n}\n\n/**\n * Convert a raw expression to processed format\n */\nfunction convertExpression(\n rawExpr: NativeExpressionDebugInfo,\n debugSourceFiles: string[]\n): ExpressionDebugInfo {\n const converted: ExpressionDebugInfo = {\n type: rawExpr.type,\n isBranch: rawExpr.isBranch,\n };\n\n if (rawExpr.branchPaths !== undefined) {\n converted.branchPaths = rawExpr.branchPaths;\n }\n\n if (rawExpr.location) {\n const convertedLocation = convertLocation(rawExpr.location, debugSourceFiles);\n if (convertedLocation) {\n converted.location = convertedLocation;\n }\n }\n\n return converted;\n}\n\n/**\n * Generate a position key to identify the SourceLocation uniquely\n * within a file. Does NOT include the file identifier.\n */\nfunction getPositionKey(location: SourceLocation) {\n return `${location.line}:${location.column}`;\n}\n\n/**\n * Convert a raw function to processed format and compute position key\n * Returns undefined if function has no valid representative location\n */\nfunction convertFunction(\n rawFunc: NativeFunctionDebugInfo,\n debugSourceFiles: string[]\n): { func: FunctionDebugInfo; filePath: string; positionKey: string } | undefined {\n const representativeLocation = convertLocation(rawFunc.representativeLocation, debugSourceFiles);\n\n // Convert expressions\n const expressions: ExpressionDebugInfo[] = [];\n if (rawFunc.expressions) {\n for (const expr of rawFunc.expressions) {\n expressions.push(convertExpression(expr, debugSourceFiles));\n }\n }\n\n const converted: FunctionDebugInfo = {\n wasmIndex: rawFunc.wasmIndex,\n name: rawFunc.name,\n representativeLocation,\n coverageMemoryIndex: rawFunc.coverageMemoryIndex,\n expressions,\n basicBlocks: rawFunc.basicBlocks,\n };\n\n const filePath = representativeLocation.filePath;\n const positionKey = getPositionKey(representativeLocation);\n\n return { func: converted, filePath, positionKey };\n}\n\n/**\n * Transform raw native addon output to processed BinaryDebugInfo\n */\nfunction transformDebugInfo(\n raw: NativeDebugInfoOutput,\n logPrefix: string,\n): BinaryDebugInfo {\n const functionsByFileAndPosition: Record<string, Record<string, FunctionDebugInfo>> = {};\n\n debug(`${logPrefix} - Converting ${raw.functions.length} functions`);\n\n let positionCollisionCount = 0;\n let skippedCount = 0;\n let instrumentedFunctionCount = 0;\n \n for (const rawFunc of raw.functions) {\n const result = convertFunction(rawFunc, raw.debugSourceFiles);\n if (!result) {\n debug(`${logPrefix} - WARNING: Skipped function (bad conversion): \"${rawFunc.name}\"`);\n skippedCount++;\n continue;\n }\n\n const { func, filePath, positionKey } = result;\n\n // Check for position collisions\n if (functionsByFileAndPosition[filePath]?.[positionKey]) {\n const existing = functionsByFileAndPosition[filePath][positionKey];\n positionCollisionCount++;\n throw createPoolError(\n `ERROR - Function Debug Position Collision at ${filePath}:${positionKey}: \"${existing.name}\" will be replaced by \"${func.name}\"`,\n POOL_ERROR_NAMES.WASMInstrumentationError\n );\n }\n\n instrumentedFunctionCount++;\n\n // Group by file and position\n if (!functionsByFileAndPosition[filePath]) {\n functionsByFileAndPosition[filePath] = {};\n }\n\n functionsByFileAndPosition[filePath][positionKey] = func;\n }\n\n debug(\n `${logPrefix} - BinaryDebugInfo transform complete: ${instrumentedFunctionCount} instrumented functions`\n +` (${positionCollisionCount} position collisions, ${skippedCount} skipped)`\n );\n\n return {\n debugSourceFiles: raw.debugSourceFiles,\n functionsByFileAndPosition,\n instrumentedFunctionCount,\n };\n}\n\n/**\n * Instrument a WASM binary for coverage collection and regenerate source map\n *\n * This function:\n * 1. Adds __coverage_memory import (multi-memory for coverage counters)\n * 2. Injects coverage counter increments at each function entry\n * 3. Regenerates source map with correct offsets after instrumentation\n * 4. Extracts debug info with coverageMemoryIndex assigned\n *\n * @param wasmBuffer - Buffer containing the clean WASM binary\n * @param sourceMapBuffer - Buffer containing the source map JSON\n * @returns Instrumented binary, regenerated source map, and debug info\n *\n * @throws {TypeError} If wasmBuffer or sourceMapBuffer are not Buffers\n * @throws {Error} If WASM binary or source map is invalid\n */\nexport function instrumentForCoverage(\n wasmBuffer: Buffer,\n sourceMapBuffer: Buffer,\n instrumentationOptions: InstrumentationOptions,\n logModule: string,\n logLabel: string,\n): InstrumentationResult {\n if (!Buffer.isBuffer(wasmBuffer)) {\n throw createPoolError(\n 'instrumentForCoverage - wasmBuffer must be a Buffer',\n POOL_ERROR_NAMES.WASMInstrumentationError\n );\n }\n if (!Buffer.isBuffer(sourceMapBuffer)) {\n throw createPoolError(\n 'instrumentForCoverage - sourceMapBuffer must be a Buffer',\n POOL_ERROR_NAMES.WASMInstrumentationError\n );\n }\n\n const interfaceLogPrefix = `[${logModule} Inst] ${logLabel}`;\n const nativeLogPrefix = `[${logModule} InstNative] ${logLabel}`;\n\n debug(`${interfaceLogPrefix} - Calling native instrumentForCoverage`);\n const startTime = performance.now();\n\n const options: NativeInstrumentationOptions = {\n coverageMemoryPagesMin: instrumentationOptions.coverageMemoryPagesMin,\n coverageMemoryPagesMax: instrumentationOptions.coverageMemoryPagesMax,\n excludedFiles: instrumentationOptions.relativeExcludedFiles,\n excludedLibraryFilePrefix: instrumentationOptions.excludedLibraryFilePrefix,\n debug: DEBUG_NATIVE_ADDON,\n logPrefix: nativeLogPrefix\n };\n const nativeResult: NativeInstrumentationResult = addon.instrumentForCoverage(wasmBuffer, sourceMapBuffer, options);\n const addonTime = performance.now();\n debug(`${interfaceLogPrefix} - TIMING Native addon: ${(addonTime - startTime).toFixed(2)} ms`);\n\n if (nativeResult.errors?.length) {\n throw createPoolError(\n `Errors encountered duriing native instrumentation: ${nativeResult.errors.join('\\n')}`,\n POOL_ERROR_NAMES.WASMInstrumentationError,\n );\n } \n\n const debugInfo = transformDebugInfo(nativeResult.debugInfo, interfaceLogPrefix);\n \n const transformTime = performance.now();\n debug(`${interfaceLogPrefix} - TIMING DebugInfo Transform: ${(transformTime - addonTime).toFixed(2)} ms`);\n debug(`${interfaceLogPrefix} - Binary size: ${nativeResult.instrumentedWasm.length} bytes | Source map size: ${nativeResult.sourceMap.length * 2} bytes`);\n\n return {\n instrumentedWasm: nativeResult.instrumentedWasm,\n sourceMap: nativeResult.sourceMap,\n debugInfo,\n };\n}\n","/**\n * AssemblyScript Compiler\n *\n * Handles compilation of AssemblyScript source code to WASM binaries.\n * Manages compiler options, transforms, and in-memory compilation.\n */\n\nimport { main as ascMain } from 'assemblyscript/asc';\nimport { basename, resolve } from 'node:path';\nimport { access } from 'node:fs/promises';\nimport { writeFile, mkdir } from 'node:fs/promises';\n\nimport { AssemblyScriptCompilerResult, AssemblyScriptCompilerOptions } from '../types/types.js';\nimport { POOL_ERROR_NAMES } from '../types/constants.js';\nimport { debug } from '../util/debug.js';\nimport { instrumentForCoverage } from '../native-instrumentation/addon-interface.js';\nimport { createPoolError, throwPoolErrorIfAborted } from '../util/pool-errors.js';\n\nconst DEBUG_WRITE_FILES = false;\n\n// path assumes that we're running from dist/\nconst STRIP_INLINE_TRANSFORM = resolve(import.meta.dirname, './compiler/transforms/strip-inline.mjs');\n\nsetImmediate(async () => {\n try {\n await access(STRIP_INLINE_TRANSFORM);\n } catch {\n throw createPoolError(\n `AS Compiler strip inline transform file not found at \"${STRIP_INLINE_TRANSFORM}\"`,\n POOL_ERROR_NAMES.CompilationError\n );\n }\n});\n\n/**\n * Compile AssemblyScript source code to WASM binary\n *\n * Features:\n * - In-memory compilation (binary captured via writeFile callback)\n * - Filesystem reading enabled (for import resolution)\n * - Uses stub runtime and imported memory pattern\n * - Exports _start function for explicit initialization control\n * - Always returns clean binary\n * - Conditionally returns instrumented binary when coverage enabled\n *\n * @param filename - Full path to the source file (used as entry point)\n * @param options - Compilation options (coverage mode, etc.)\n * @returns Compilation result with clean binary and optional instrumented binary\n * @throws Error if compilation fails\n */\nexport async function compileAssemblyScript(\n filename: string,\n options: AssemblyScriptCompilerOptions,\n logModule: string,\n logLabel: string,\n signal?: AbortSignal\n): Promise<AssemblyScriptCompilerResult> {\n throwPoolErrorIfAborted(signal);\n\n const compileStart = performance.now();\n const logPrefix = `[${logModule} ASC] ${logLabel}`;\n\n const { shouldInstrument, instrumentationOptions, extraFlags } = options;\n\n if (shouldInstrument && !instrumentationOptions) {\n throw createPoolError(\n 'Instrumentation options are required for coverage instrumentation',\n POOL_ERROR_NAMES.CompilationError\n );\n }\n\n const stdoutLines: string[] = [];\n const stderrLines: string[] = [];\n let binary: Uint8Array | undefined;\n let sourceMap: string | undefined;\n\n // Use full path as entry file so AS compiler can resolve relative imports\n const entryFile = filename;\n // Use simple output name to avoid AS compiler prepending it to source map paths\n const outputFile = 'output.wasm';\n\n debug(`${logPrefix} - Compiling: \"${filename}\"`);\n\n // Capture stdout/stderr (for potential error reporting)\n const stdout = {\n write: (text: string) => {\n stdoutLines.push(text);\n return true;\n }\n };\n\n const stderr = {\n write: (text: string) => {\n stderrLines.push(text);\n return true;\n }\n };\n\n // Build compiler flags\n const compilerFlags = [\n entryFile,\n\n // overrideable, though not recommended\n '--optimizeLevel', '0', // No optimization for easier debugging\n '--shrinkLevel', '0', // No shrink\n '--runtime', 'stub', // stub runtime (no GC)\n\n ...(extraFlags || []),\n\n // non-overrideable\n '--outFile', outputFile,\n '--importMemory', // Import memory from JS (enables imports during WASM start)\n '--debug', // Include debug info\n '--sourceMap', // Generate source maps for error reporting\n '--exportStart', '_start', // Export start function for explicit initialization control\n '--exportTable' // Export function table for direct test execution\n ];\n\n // Add transform to strip @inline decorators if requested\n // This improves coverage accuracy by preventing functions from being inlined,\n // and enables correct source-mapped error reporting for errors originating\n // inside inlined functions.\n if (options.stripInline === true) {\n compilerFlags.push(\n '--transform', STRIP_INLINE_TRANSFORM\n );\n debug(`${logPrefix} - Added Transform - Stripping @inline decorators`);\n }\n\n // Compile with AssemblyScript compiler\n const ascStart = performance.now();\n const result = await ascMain(compilerFlags, {\n stdout,\n stderr,\n // Let AS read from filesystem for import resolution\n // WASM binary and source map are captured in memory via writeFile callback\n writeFile: (name: string, contents: string | Uint8Array, _baseDir: string) => {\n throwPoolErrorIfAborted(signal);\n\n if (name.endsWith('.wasm') && contents instanceof Uint8Array) {\n binary = contents;\n debug(`${logPrefix} - Captured binary in memory: \"${name}\"`);\n } else if (name.endsWith('.wasm.map') && typeof contents === 'string') {\n debug(`${logPrefix} - Captured source map in memory: \"${name}\"`);\n sourceMap = contents;\n } else {\n debug(`${logPrefix} - WARNING - Captured Unexpected File: \"${name}\" at baseDir: \"${_baseDir}\"`);\n }\n },\n });\n\n debug(`${logPrefix} - TIMING asc.main: ${(performance.now() - ascStart).toFixed(2)} ms`);\n\n if (result.error) {\n const errorMessage = stderrLines.length > 0\n ? `${result.error.message}\\n\\n${stderrLines.join('')}`\n : result.error.message;\n\n throw createPoolError(errorMessage, POOL_ERROR_NAMES.CompilationError, errorMessage);\n }\n\n if (!binary) {\n const errorMessage = stderrLines.length > 0\n ? `No WASM binary was generated\\n\\nAS Compiler output:\\n${stderrLines.join('')}`\n : 'No WASM binary was generated';\n\n throw createPoolError(errorMessage, POOL_ERROR_NAMES.CompilationError);\n }\n\n if (!sourceMap) {\n throw createPoolError('Source map not captured from AssemblyScript Compiler', POOL_ERROR_NAMES.CompilationError);\n }\n\n const cleanBinary: Uint8Array = binary;\n const wasmSourceMap: string = sourceMap;\n\n debug(`${logPrefix} - Compilation successful, clean binary size: ${cleanBinary.length} bytes`);\n debug(`${logPrefix} - Source map generated, size: ${wasmSourceMap.length * 2} bytes`);\n \n if (DEBUG_WRITE_FILES) {\n // Write source map to project maps directory for debugging\n const dir = './debug';\n const sourceMapFileName = `${basename(filename, '.ts')}.as.ts.map`;\n const sourceMapPath = `${dir}/${sourceMapFileName}`;\n\n // Create directory if it doesn't exist\n try {\n await mkdir(dir, { recursive: true });\n } catch {\n // Directory already exists or creation failed, continue\n }\n\n // Format as well-formed JSON\n const formattedSourceMap = JSON.stringify(JSON.parse(wasmSourceMap), null, 2);\n\n writeFile(sourceMapPath, formattedSourceMap, { encoding: 'utf8' });\n debug(`${logPrefix} - Wrote source map to: \"${sourceMapPath}\"`);\n\n // Also write WASM binary for inspection\n const wasmPath = sourceMapPath.replace('.map', '.wasm');\n writeFile(wasmPath, cleanBinary);\n debug(`${logPrefix} - Wrote WASM binary to: \"${wasmPath}\"`);\n }\n\n // Instrument binary for coverage if requested\n if (options.shouldInstrument) {\n throwPoolErrorIfAborted(signal);\n\n const instrumentStart = performance.now();\n const wasmBuffer = Buffer.from(cleanBinary);\n const sourceMapBuffer = Buffer.from(wasmSourceMap);\n\n const instrumentResult = instrumentForCoverage(wasmBuffer, sourceMapBuffer, options.instrumentationOptions!, logModule, logLabel);\n const instCount = instrumentResult.debugInfo.instrumentedFunctionCount;\n\n const instrumentEnd = performance.now();\n debug(`${logPrefix} - TIMING Instrumented ${instCount} functions: ${(performance.now() - instrumentStart).toFixed(2)} ms`);\n\n return {\n binary: instrumentResult.instrumentedWasm,\n sourceMap: instrumentResult.sourceMap,\n debugInfo: instrumentResult.debugInfo,\n isInstrumented: true,\n compileTiming: instrumentEnd - compileStart,\n };\n }\n\n // No instrumentation requested\n return {\n binary: cleanBinary,\n sourceMap: wasmSourceMap,\n isInstrumented: false,\n compileTiming: performance.now() - compileStart,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiCA,MAAM,qBAAqB;AAO3B,MAAM,YAAY,QADC,cAAc,OAAO,KAAK,IAAI,CACZ;AACrC,MAAM,eAAe,QAAQ,WAAW,KAAK;AAC7C,MAAM,cAAc,QAAQ,WAAW,QAAQ;AAG/C,MAAM,eADU,cAAc,OAAO,KAAK,IAAI,CACa,iBAAiB;AAE5E,IAAI;AACJ,IAAI;AACF,SAAQ,aAAa,aAAa;QAC5B;AACN,KAAI;AACF,UAAQ,aAAa,YAAY;UAC1B,KAAK;AACZ,QAAM,gBACJ,yCAAyC,aAAa,OAAO,YAAY,yGAEtD,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,IACnE,iBAAiB,yBAClB;;;;;;;AAQL,SAAS,gBACP,aACA,kBACgB;CAChB,MAAM,WAAW,iBAAiB,YAAY;AAE9C,KAAI,CAAC,SACH,OAAM,gBACJ,oCAAoC,YAAY,UAAU,IAC1D,iBAAiB,yBAClB;AAGH,QAAO;EACK;EACV,MAAM,YAAY;EAClB,QAAQ,YAAY,SAAS;EAC9B;;;;;AAMH,SAAS,kBACP,SACA,kBACqB;CACrB,MAAM,YAAiC;EACrC,MAAM,QAAQ;EACd,UAAU,QAAQ;EACnB;AAED,KAAI,QAAQ,gBAAgB,OAC1B,WAAU,cAAc,QAAQ;AAGlC,KAAI,QAAQ,UAAU;EACpB,MAAM,oBAAoB,gBAAgB,QAAQ,UAAU,iBAAiB;AAC7E,MAAI,kBACF,WAAU,WAAW;;AAIzB,QAAO;;;;;;AAOT,SAAS,eAAe,UAA0B;AAChD,QA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ory, WasmImportsFactoryInfo } from "../types-8KKo9Hbf.mjs";
|
|
2
|
+
import "../custom-provider-options-CF5C1kXb.mjs";
|
|
3
|
+
import { ConfigEnv, UserWorkspaceConfig, ViteUserConfig } from "vitest/config";
|
|
4
|
+
|
|
5
|
+
//#region src/config/config-helpers-v3.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* AssemblyScript pool configuration with proper typing for poolOptions
|
|
8
|
+
*
|
|
9
|
+
* Use this type with `defineAssemblyScriptConfig` for root-level configs,
|
|
10
|
+
* or `defineAssemblyScriptProject` for project-level configs.
|
|
11
|
+
*
|
|
12
|
+
* Vitest v3's ProjectConfig narrows poolOptions as an inline object type,
|
|
13
|
+
* which cannot be augmented via TypeScript module augmentation. Config helpers
|
|
14
|
+
* use type intersection to add poolOptions.assemblyScript typing.
|
|
15
|
+
*
|
|
16
|
+
* Note: Coverage is NOT included here because it's global-only config in Vitest.
|
|
17
|
+
* Coverage typing comes from the CustomProviderOptions augmentation above.
|
|
18
|
+
*/
|
|
19
|
+
type AssemblyScriptUserConfig<T extends ViteUserConfig> = T & {
|
|
20
|
+
test?: {
|
|
21
|
+
poolOptions?: {
|
|
22
|
+
assemblyScript?: AssemblyScriptPoolOptions;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Root-level config type with AssemblyScript pool support
|
|
28
|
+
*/
|
|
29
|
+
type AssemblyScriptConfigExport = AssemblyScriptUserConfig<ViteUserConfig>;
|
|
30
|
+
/**
|
|
31
|
+
* Project-level config type with AssemblyScript pool support
|
|
32
|
+
*/
|
|
33
|
+
type AssemblyScriptProjectConfigExport = AssemblyScriptUserConfig<UserWorkspaceConfig>;
|
|
34
|
+
/**
|
|
35
|
+
* Define a root-level Vitest config with AssemblyScript pool options.
|
|
36
|
+
*
|
|
37
|
+
* This is a type-safe wrapper that properly types `poolOptions.assemblyScript`
|
|
38
|
+
* for both root and project-level configurations.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { defineAssemblyScriptConfig } from 'vitest-pool-assemblyscript/config';
|
|
43
|
+
*
|
|
44
|
+
* export default defineAssemblyScriptConfig({
|
|
45
|
+
* test: {
|
|
46
|
+
* name: 'assemblyscript-unit-tests',
|
|
47
|
+
* pool: 'vitest-pool-assemblyscript',
|
|
48
|
+
* include: ['test/assembly/**/*.as.test.ts'], // example
|
|
49
|
+
* poolOptions: {
|
|
50
|
+
* assemblyScript: { // optional },
|
|
51
|
+
* },
|
|
52
|
+
* coverage: {
|
|
53
|
+
* provider: 'custom',
|
|
54
|
+
* customProviderModule: 'vitest-pool-assemblyscript/coverage',
|
|
55
|
+
* include: ['src/**/*.ts'], // example JS/TS sources (v8 provider)
|
|
56
|
+
* assemblyScriptInclude: ['assembly/**/*.ts'], // example AS sources
|
|
57
|
+
* assemblyScriptExclude: ['**/*.as.test.ts'], // exclude AS test files
|
|
58
|
+
* },
|
|
59
|
+
* },
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare function defineAssemblyScriptConfig(config: AssemblyScriptConfigExport): AssemblyScriptConfigExport;
|
|
64
|
+
declare function defineAssemblyScriptConfig(config: Promise<AssemblyScriptConfigExport>): Promise<AssemblyScriptConfigExport>;
|
|
65
|
+
declare function defineAssemblyScriptConfig(config: (env: ConfigEnv) => AssemblyScriptConfigExport | Promise<AssemblyScriptConfigExport>): (env: ConfigEnv) => AssemblyScriptConfigExport | Promise<AssemblyScriptConfigExport>;
|
|
66
|
+
/**
|
|
67
|
+
* Define a project-level Vitest config with AssemblyScript pool options.
|
|
68
|
+
*
|
|
69
|
+
* Use this when defining AssemblyScript test projects within a workspace.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { defineConfig, defineProject } from 'vitest/config';
|
|
74
|
+
* import { defineAssemblyScriptProject } from 'vitest-pool-assemblyscript/config';
|
|
75
|
+
*
|
|
76
|
+
* export default defineConfig({
|
|
77
|
+
* test: {
|
|
78
|
+
* projects: [
|
|
79
|
+
* defineProject({
|
|
80
|
+
* test: {
|
|
81
|
+
* name: { label: 'typescript-unit-tests', color: 'blue' },
|
|
82
|
+
* }
|
|
83
|
+
* }),
|
|
84
|
+
* defineAssemblyScriptProject({
|
|
85
|
+
* test: {
|
|
86
|
+
* name: { label: 'assemblyscript-unit-tests', color: 'yellow' },
|
|
87
|
+
* pool: 'vitest-pool-assemblyscript',
|
|
88
|
+
* include: ['test/assembly/**/*.as.test.ts'], // example
|
|
89
|
+
* poolOptions: {
|
|
90
|
+
* assemblyScript: { // optional },
|
|
91
|
+
* },
|
|
92
|
+
* },
|
|
93
|
+
* }),
|
|
94
|
+
* ],
|
|
95
|
+
* coverage: { // coverage section is global only in vitest
|
|
96
|
+
* provider: 'custom',
|
|
97
|
+
* customProviderModule: 'vitest-pool-assemblyscript/coverage',
|
|
98
|
+
* include: ['src/**/*.ts'], // example JS/TS sources (v8 provider)
|
|
99
|
+
* assemblyScriptInclude: ['assembly/**/*.ts'], // example AS sources
|
|
100
|
+
* assemblyScriptExclude: ['**/*.as.test.ts'], // exclude AS test files
|
|
101
|
+
* },
|
|
102
|
+
* },
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function defineAssemblyScriptProject(config: AssemblyScriptProjectConfigExport): AssemblyScriptProjectConfigExport;
|
|
107
|
+
declare function defineAssemblyScriptProject(config: Promise<AssemblyScriptProjectConfigExport>): Promise<AssemblyScriptProjectConfigExport>;
|
|
108
|
+
declare function defineAssemblyScriptProject(config: (env: ConfigEnv) => AssemblyScriptProjectConfigExport | Promise<AssemblyScriptProjectConfigExport>): (env: ConfigEnv) => AssemblyScriptProjectConfigExport | Promise<AssemblyScriptProjectConfigExport>;
|
|
109
|
+
//#endregion
|
|
110
|
+
export { AssemblyScriptConfigExport, type AssemblyScriptPoolOptions, AssemblyScriptProjectConfigExport, AssemblyScriptUserConfig, type WasmImportsFactory, type WasmImportsFactoryInfo, defineAssemblyScriptConfig, defineAssemblyScriptProject };
|
|
111
|
+
//# sourceMappingURL=index-v3.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-v3.d.mts","names":[],"sources":["../../src/config/config-helpers-v3.ts"],"mappings":";;;;;;;;;;;;;;;;;;KAgCY,wBAAA,WAAmC,cAAA,IAAkB,CAAA;EAC/D,IAAA;IAEE,WAAA;MACE,cAAA,GAAiB,yBAAA;IAAA;EAAA;AAAA;;;;KAQX,0BAAA,GAA6B,wBAAA,CAAyB,cAAA;AAoClE;;;AAAA,KA/BY,iCAAA,GAAoC,wBAAA,CAAyB,mBAAA;;;;;;AAkCzE;;;;;;;;;;;;;;;;AAGA;;;;;;;;iBANgB,0BAAA,CACd,MAAA,EAAQ,0BAAA,GACP,0BAAA;AAAA,iBACa,0BAAA,CACd,MAAA,EAAQ,OAAA,CAAQ,0BAAA,IACf,OAAA,CAAQ,0BAAA;AAAA,iBACK,0BAAA,CACd,MAAA,GAAS,GAAA,EAAK,SAAA,KAAc,0BAAA,GAA6B,OAAA,CAAQ,0BAAA,KAC/D,GAAA,EAAK,SAAA,KAAc,0BAAA,GAA6B,OAAA,CAAQ,0BAAA;;;;;;;;;;;;;;;;AAgD5D;;;;;;;;;AAGA;;;;;;;;;;;;;;;;iBAHgB,2BAAA,CACd,MAAA,EAAQ,iCAAA,GACP,iCAAA;AAAA,iBACa,2BAAA,CACd,MAAA,EAAQ,OAAA,CAAQ,iCAAA,IACf,OAAA,CAAQ,iCAAA;AAAA,iBACK,2BAAA,CACd,MAAA,GAAS,GAAA,EAAK,SAAA,KAAc,iCAAA,GAAoC,OAAA,CAAQ,iCAAA,KACtE,GAAA,EAAK,SAAA,KAAc,iCAAA,GAAoC,OAAA,CAAQ,iCAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/config/config-helpers-v3.ts
|
|
2
|
+
function defineAssemblyScriptConfig(config) {
|
|
3
|
+
return config;
|
|
4
|
+
}
|
|
5
|
+
function defineAssemblyScriptProject(config) {
|
|
6
|
+
return config;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { defineAssemblyScriptConfig, defineAssemblyScriptProject };
|
|
11
|
+
//# sourceMappingURL=index-v3.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-v3.mjs","names":[],"sources":["../../src/config/config-helpers-v3.ts"],"sourcesContent":["/**\n * Configuration helpers for vitest-pool-assemblyscript\n *\n * Provides custom type-safe config helpers similar to Cloudflare's vitest-pool-workers\n * to work around TypeScript's ProjectConfig poolOptions type narrowing in Vitest v3.\n */\n\nimport type { ViteUserConfig, UserWorkspaceConfig, ConfigEnv } from 'vitest/config';\n\nimport type { AssemblyScriptPoolOptions } from '../types/types.js';\n\n/**\n * Type for config that may be a value, Promise, or function\n */\ntype AnyConfigExport<T extends ViteUserConfig> =\n | T\n | Promise<T>\n | ((env: ConfigEnv) => T | Promise<T>);\n\n/**\n * AssemblyScript pool configuration with proper typing for poolOptions\n *\n * Use this type with `defineAssemblyScriptConfig` for root-level configs,\n * or `defineAssemblyScriptProject` for project-level configs.\n * \n * Vitest v3's ProjectConfig narrows poolOptions as an inline object type,\n * which cannot be augmented via TypeScript module augmentation. Config helpers\n * use type intersection to add poolOptions.assemblyScript typing.\n *\n * Note: Coverage is NOT included here because it's global-only config in Vitest.\n * Coverage typing comes from the CustomProviderOptions augmentation above.\n */\nexport type AssemblyScriptUserConfig<T extends ViteUserConfig> = T & {\n test?: {\n // pool?: string;\n poolOptions?: {\n assemblyScript?: AssemblyScriptPoolOptions;\n };\n };\n};\n\n/**\n * Root-level config type with AssemblyScript pool support\n */\nexport type AssemblyScriptConfigExport = AssemblyScriptUserConfig<ViteUserConfig>;\n\n/**\n * Project-level config type with AssemblyScript pool support\n */\nexport type AssemblyScriptProjectConfigExport = AssemblyScriptUserConfig<UserWorkspaceConfig>;\n\n/**\n * Define a root-level Vitest config with AssemblyScript pool options.\n *\n * This is a type-safe wrapper that properly types `poolOptions.assemblyScript`\n * for both root and project-level configurations.\n *\n * @example\n * ```ts\n * import { defineAssemblyScriptConfig } from 'vitest-pool-assemblyscript/config';\n *\n * export default defineAssemblyScriptConfig({\n * test: {\n * name: 'assemblyscript-unit-tests',\n * pool: 'vitest-pool-assemblyscript',\n * include: ['test/assembly/**/*.as.test.ts'], // example\n * poolOptions: {\n * assemblyScript: { // optional },\n * },\n * coverage: {\n * provider: 'custom',\n * customProviderModule: 'vitest-pool-assemblyscript/coverage',\n * include: ['src/**/*.ts'], // example JS/TS sources (v8 provider)\n * assemblyScriptInclude: ['assembly/**/*.ts'], // example AS sources\n * assemblyScriptExclude: ['**/*.as.test.ts'], // exclude AS test files\n * },\n * },\n * });\n * ```\n */\nexport function defineAssemblyScriptConfig(\n config: AssemblyScriptConfigExport\n): AssemblyScriptConfigExport;\nexport function defineAssemblyScriptConfig(\n config: Promise<AssemblyScriptConfigExport>\n): Promise<AssemblyScriptConfigExport>;\nexport function defineAssemblyScriptConfig(\n config: (env: ConfigEnv) => AssemblyScriptConfigExport | Promise<AssemblyScriptConfigExport>\n): (env: ConfigEnv) => AssemblyScriptConfigExport | Promise<AssemblyScriptConfigExport>;\nexport function defineAssemblyScriptConfig(\n config: AnyConfigExport<AssemblyScriptConfigExport>\n): AnyConfigExport<AssemblyScriptConfigExport> {\n // Pass through - this is just for type safety\n return config;\n}\n\n/**\n * Define a project-level Vitest config with AssemblyScript pool options.\n *\n * Use this when defining AssemblyScript test projects within a workspace.\n *\n * @example\n * ```ts\n * import { defineConfig, defineProject } from 'vitest/config';\n * import { defineAssemblyScriptProject } from 'vitest-pool-assemblyscript/config';\n *\n * export default defineConfig({\n * test: {\n * projects: [\n * defineProject({\n * test: {\n * name: { label: 'typescript-unit-tests', color: 'blue' },\n * }\n * }),\n * defineAssemblyScriptProject({\n * test: {\n * name: { label: 'assemblyscript-unit-tests', color: 'yellow' },\n * pool: 'vitest-pool-assemblyscript',\n * include: ['test/assembly/**/*.as.test.ts'], // example\n * poolOptions: {\n * assemblyScript: { // optional },\n * },\n * },\n * }),\n * ],\n * coverage: { // coverage section is global only in vitest\n * provider: 'custom',\n * customProviderModule: 'vitest-pool-assemblyscript/coverage',\n * include: ['src/**/*.ts'], // example JS/TS sources (v8 provider)\n * assemblyScriptInclude: ['assembly/**/*.ts'], // example AS sources\n * assemblyScriptExclude: ['**/*.as.test.ts'], // exclude AS test files\n * },\n * },\n * });\n * ```\n */\nexport function defineAssemblyScriptProject(\n config: AssemblyScriptProjectConfigExport\n): AssemblyScriptProjectConfigExport;\nexport function defineAssemblyScriptProject(\n config: Promise<AssemblyScriptProjectConfigExport>\n): Promise<AssemblyScriptProjectConfigExport>;\nexport function defineAssemblyScriptProject(\n config: (env: ConfigEnv) => AssemblyScriptProjectConfigExport | Promise<AssemblyScriptProjectConfigExport>\n): (env: ConfigEnv) => AssemblyScriptProjectConfigExport | Promise<AssemblyScriptProjectConfigExport>;\nexport function defineAssemblyScriptProject(\n config: AnyConfigExport<AssemblyScriptProjectConfigExport>\n): AnyConfigExport<AssemblyScriptProjectConfigExport> {\n // Pass through - this is just for type safety\n return config;\n}\n"],"mappings":";AAyFA,SAAgB,2BACd,QAC6C;AAE7C,QAAO;;AAoDT,SAAgB,4BACd,QACoD;AAEpD,QAAO"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AssemblyScriptPoolOptions, WasmImportsFactory, WasmImportsFactoryInfo } from "../types-8KKo9Hbf.mjs";
|
|
2
|
+
import "../custom-provider-options-CF5C1kXb.mjs";
|
|
3
|
+
import { createAssemblyScriptPool } from "../pool-runner-init-CEwLyNI3.mjs";
|
|
4
|
+
export { type AssemblyScriptPoolOptions, type WasmImportsFactory, type WasmImportsFactoryInfo, createAssemblyScriptPool };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "../resolve-config-as1w-Qyz.mjs";
|
|
2
|
+
import "../debug-IeEHsxy0.mjs";
|
|
3
|
+
import "../vitest-file-tasks-BUwzh375.mjs";
|
|
4
|
+
import "../vitest-tasks-BKS7689f.mjs";
|
|
5
|
+
import "../worker-rpc-channel-lbhK7Qz8.mjs";
|
|
6
|
+
import { createAssemblyScriptPool } from "../pool-runner-init-d5qScS41.mjs";
|
|
7
|
+
|
|
8
|
+
export { createAssemblyScriptPool };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
//#region src/types/constants.ts
|
|
2
|
+
const COVERAGE_PAYLOAD_FORMATS = { AssemblyScript: "assemblyscript" };
|
|
3
|
+
/** Paths instrumentation exclusions and assetion error stack frame filtering */
|
|
4
|
+
const POOL_INTERNAL_PATHS = [
|
|
5
|
+
"assembly/compare.ts",
|
|
6
|
+
"assembly/describe.ts",
|
|
7
|
+
"assembly/expect.ts",
|
|
8
|
+
"assembly/index.ts",
|
|
9
|
+
"assembly/options.ts",
|
|
10
|
+
"assembly/test.ts"
|
|
11
|
+
];
|
|
12
|
+
/** Error names for AssemblyScript test failures reported to vitest */
|
|
13
|
+
const TEST_ERROR_NAMES = {
|
|
14
|
+
AssertionError: "AssertionError",
|
|
15
|
+
WASMRuntimeError: "WASMRuntimeError"
|
|
16
|
+
};
|
|
17
|
+
/** Error names for internal AssemblyScript pool failures */
|
|
18
|
+
const POOL_ERROR_NAMES = {
|
|
19
|
+
CompilationError: "CompilationError",
|
|
20
|
+
WASMInstrumentationError: "WASMInstrumentationError",
|
|
21
|
+
WASMExecutionHarnessError: "WASMExecutionHarnessError",
|
|
22
|
+
HybridCoverageProviderError: "HybridCoverageProviderError",
|
|
23
|
+
PoolReportingError: "PoolReportingError",
|
|
24
|
+
PoolConfigError: "PoolConfigError",
|
|
25
|
+
PoolError: "PoolError",
|
|
26
|
+
PoolSyntaxError: "PoolSyntaxError",
|
|
27
|
+
PoolRunAbortedError: "PoolRunAbortedError",
|
|
28
|
+
WASMExecutionAbortError: "WASMExecutionAbortError",
|
|
29
|
+
WASMExecutionTimeoutError: "WASMExecutionTimeoutError"
|
|
30
|
+
};
|
|
31
|
+
const ASCommonFlags = {
|
|
32
|
+
Static: 32,
|
|
33
|
+
Get: 2048,
|
|
34
|
+
Set: 4096
|
|
35
|
+
};
|
|
36
|
+
const ASNodeKind = {
|
|
37
|
+
Source: 0,
|
|
38
|
+
NamedType: 1,
|
|
39
|
+
FunctionType: 2,
|
|
40
|
+
TypeName: 3,
|
|
41
|
+
TypeParameter: 4,
|
|
42
|
+
Parameter: 5,
|
|
43
|
+
Identifier: 6,
|
|
44
|
+
Assertion: 7,
|
|
45
|
+
Binary: 8,
|
|
46
|
+
Call: 9,
|
|
47
|
+
Class: 10,
|
|
48
|
+
Comma: 11,
|
|
49
|
+
ElementAccess: 12,
|
|
50
|
+
False: 13,
|
|
51
|
+
Function: 14,
|
|
52
|
+
InstanceOf: 15,
|
|
53
|
+
Literal: 16,
|
|
54
|
+
New: 17,
|
|
55
|
+
Null: 18,
|
|
56
|
+
Omitted: 19,
|
|
57
|
+
Parenthesized: 20,
|
|
58
|
+
PropertyAccess: 21,
|
|
59
|
+
Ternary: 22,
|
|
60
|
+
Super: 23,
|
|
61
|
+
This: 24,
|
|
62
|
+
True: 25,
|
|
63
|
+
Constructor: 26,
|
|
64
|
+
UnaryPostfix: 27,
|
|
65
|
+
UnaryPrefix: 28,
|
|
66
|
+
Compiled: 29,
|
|
67
|
+
Block: 30,
|
|
68
|
+
Break: 31,
|
|
69
|
+
Continue: 32,
|
|
70
|
+
Do: 33,
|
|
71
|
+
Empty: 34,
|
|
72
|
+
Export: 35,
|
|
73
|
+
ExportDefault: 36,
|
|
74
|
+
ExportImport: 37,
|
|
75
|
+
Expression: 38,
|
|
76
|
+
For: 39,
|
|
77
|
+
ForOf: 40,
|
|
78
|
+
If: 41,
|
|
79
|
+
Import: 42,
|
|
80
|
+
Return: 43,
|
|
81
|
+
Switch: 44,
|
|
82
|
+
Throw: 45,
|
|
83
|
+
Try: 46,
|
|
84
|
+
Variable: 47,
|
|
85
|
+
Void: 48,
|
|
86
|
+
While: 49,
|
|
87
|
+
Module: 50,
|
|
88
|
+
ClassDeclaration: 51,
|
|
89
|
+
EnumDeclaration: 52,
|
|
90
|
+
EnumValueDeclaration: 53,
|
|
91
|
+
FieldDeclaration: 54,
|
|
92
|
+
FunctionDeclaration: 55,
|
|
93
|
+
ImportDeclaration: 56,
|
|
94
|
+
InterfaceDeclaration: 57,
|
|
95
|
+
MethodDeclaration: 58,
|
|
96
|
+
NamespaceDeclaration: 59,
|
|
97
|
+
TypeDeclaration: 60,
|
|
98
|
+
VariableDeclaration: 61,
|
|
99
|
+
Decorator: 62,
|
|
100
|
+
ExportMember: 63,
|
|
101
|
+
SwitchCase: 64,
|
|
102
|
+
IndexSignature: 65,
|
|
103
|
+
Comment: 66
|
|
104
|
+
};
|
|
105
|
+
const ASDecoratorKind = {
|
|
106
|
+
Custom: 0,
|
|
107
|
+
Global: 1,
|
|
108
|
+
Operator: 2,
|
|
109
|
+
OperatorBinary: 3,
|
|
110
|
+
OperatorPrefix: 4,
|
|
111
|
+
OperatorPostfix: 5,
|
|
112
|
+
Unmanaged: 6,
|
|
113
|
+
Final: 7,
|
|
114
|
+
Inline: 8,
|
|
115
|
+
External: 9,
|
|
116
|
+
ExternalJs: 10,
|
|
117
|
+
Builtin: 11,
|
|
118
|
+
Lazy: 12,
|
|
119
|
+
Unsafe: 13
|
|
120
|
+
};
|
|
121
|
+
const ASSourceKind = {
|
|
122
|
+
User: 0,
|
|
123
|
+
UserEntry: 1,
|
|
124
|
+
Library: 2,
|
|
125
|
+
LibraryEntry: 3
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
//#endregion
|
|
129
|
+
export { ASCommonFlags, ASDecoratorKind, ASNodeKind, ASSourceKind, COVERAGE_PAYLOAD_FORMATS, POOL_ERROR_NAMES, POOL_INTERNAL_PATHS, TEST_ERROR_NAMES };
|
|
130
|
+
//# sourceMappingURL=constants-CA50WBdr.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants-CA50WBdr.mjs","names":[],"sources":["../src/types/constants.ts"],"sourcesContent":["/**\n * Plain Constants\n * \n * Only things that don't require importing ./types to avoid circular dependencies.\n */\n\n\n// ============================================================================\n// General / Shared Constants\n// ============================================================================\n\nexport const ASSEMBLYSCRIPT_POOL_NAME = 'assemblyscript' as const;\n\nexport const AS_POOL_ERROR_TYPE_FLAG = '__as_pool__' as const;\n\nexport const AS_POOL_WORKER_MSG_FLAG = '__as_pool__' as const;\n\nexport const AS_POOL_WASM_IMPORTS_ENV = '__as_pool_env__' as const;\n\nexport const VITEST_WORKER_REQUEST_MSG_FLAG = '__vitest_worker_request__' as const;\n\nexport const VITEST_WORKER_RESPONSE_MSG_FLAG = '__vitest_worker_response__' as const;\n\nexport const COVERAGE_PAYLOAD_FORMATS = {\n AssemblyScript: 'assemblyscript',\n} as const;\n\n/** Prefix for AssemblyScript compiler strip-inline exclusions and instrumentation exclusions */\nexport const ASSEMBLYSCRIPT_LIB_PREFIX = '~lib/' as const;\n\n/** Paths instrumentation exclusions and assetion error stack frame filtering */\nexport const POOL_INTERNAL_PATHS: string[] = [\n 'assembly/compare.ts',\n 'assembly/describe.ts',\n 'assembly/expect.ts',\n 'assembly/index.ts',\n 'assembly/options.ts',\n 'assembly/test.ts',\n] as const;\n\n/** Error names for AssemblyScript test failures reported to vitest */\nexport const TEST_ERROR_NAMES = {\n /** Assertion evaluated to false within a test function */\n AssertionError: 'AssertionError',\n /** WASM runtime called abort after a non-planned user code error */\n WASMRuntimeError: 'WASMRuntimeError',\n} as const;\n\n/** Error names for internal AssemblyScript pool failures */\nexport const POOL_ERROR_NAMES = {\n /** AssemblyScript compiler (asc) error */\n CompilationError: 'CompilationError',\n /** Native instrumentation and debug info extraction error */\n WASMInstrumentationError: 'WASMInstrumentationError',\n /** Unexpected WASM execution error (not a known test error path) */\n WASMExecutionHarnessError: 'WASMExecutionHarnessError',\n /** Hybrid coverage provider error */\n HybridCoverageProviderError: 'HybridCoverageProviderError',\n /** vitest RPC reporting error */\n PoolReportingError: 'PoolReportingError',\n /** User configuration error */\n PoolConfigError: 'PoolConfigError',\n /** Generic AssemblyScript pool error */\n PoolError: 'PoolError',\n /** User syntax error in test/suite/expect */\n PoolSyntaxError: 'PoolSyntaxError',\n\n /** Flow Control: Indicates intentional abort */\n PoolRunAbortedError: 'PoolRunAbortedError',\n /**\n * Flow Control: Indicates WASM execution halt through abort() handler,\n * and should be handled by reporting an AssemblyScriptTestError to vitest\n */\n WASMExecutionAbortError: 'WASMExecutionAbortError',\n /** Flow Control: Indicates WASM execution halt because test timeout elapsed */\n WASMExecutionTimeoutError: 'WASMExecutionTimeoutError',\n} as const;\n\n// ============================================================================\n// AssemblyScript Compiler\n// ============================================================================\n\n// Redefined locally to avoid isolatedModules const enum access issues\n// with assemmblyscript enum exports. Reference assemblyscript.generated.d.ts\n\nexport const ASCommonFlags = {\n Static: 32,\n Get: 2048,\n Set: 4096,\n} as const;\n\nexport const ASNodeKind = {\n Source: 0,\n NamedType: 1,\n FunctionType: 2,\n TypeName: 3,\n TypeParameter: 4,\n Parameter: 5,\n Identifier: 6,\n Assertion: 7,\n Binary: 8,\n Call: 9,\n Class: 10,\n Comma: 11,\n ElementAccess: 12,\n False: 13,\n Function: 14,\n InstanceOf: 15,\n Literal: 16,\n New: 17,\n Null: 18,\n Omitted: 19,\n Parenthesized: 20,\n PropertyAccess: 21,\n Ternary: 22,\n Super: 23,\n This: 24,\n True: 25,\n Constructor: 26,\n UnaryPostfix: 27,\n UnaryPrefix: 28,\n Compiled: 29,\n Block: 30,\n Break: 31,\n Continue: 32,\n Do: 33,\n Empty: 34,\n Export: 35,\n ExportDefault: 36,\n ExportImport: 37,\n Expression: 38,\n For: 39,\n ForOf: 40,\n If: 41,\n Import: 42,\n Return: 43,\n Switch: 44,\n Throw: 45,\n Try: 46,\n Variable: 47,\n Void: 48,\n While: 49,\n Module: 50,\n ClassDeclaration: 51,\n EnumDeclaration: 52,\n EnumValueDeclaration: 53,\n FieldDeclaration: 54,\n FunctionDeclaration: 55,\n ImportDeclaration: 56,\n InterfaceDeclaration: 57,\n MethodDeclaration: 58,\n NamespaceDeclaration: 59,\n TypeDeclaration: 60,\n VariableDeclaration: 61,\n Decorator: 62,\n ExportMember: 63,\n SwitchCase: 64,\n IndexSignature: 65,\n Comment: 66,\n} as const;\n\nexport const ASDecoratorKind = {\n Custom: 0,\n Global: 1,\n Operator: 2,\n OperatorBinary: 3,\n OperatorPrefix: 4,\n OperatorPostfix: 5,\n Unmanaged: 6,\n Final: 7,\n Inline: 8,\n External: 9,\n ExternalJs: 10,\n Builtin: 11,\n Lazy: 12,\n Unsafe: 13\n} as const;\n\nexport const ASSourceKind = {\n User: 0,\n UserEntry: 1,\n Library: 2,\n LibraryEntry: 3\n} as const;\n"],"mappings":";AAuBA,MAAa,2BAA2B,EACtC,gBAAgB,kBACjB;;AAMD,MAAa,sBAAgC;CAC3C;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAa,mBAAmB;CAE9B,gBAAgB;CAEhB,kBAAkB;CACnB;;AAGD,MAAa,mBAAmB;CAE9B,kBAAkB;CAElB,0BAA0B;CAE1B,2BAA2B;CAE3B,6BAA6B;CAE7B,oBAAoB;CAEpB,iBAAiB;CAEjB,WAAW;CAEX,iBAAiB;CAGjB,qBAAqB;CAKrB,yBAAyB;CAEzB,2BAA2B;CAC5B;AASD,MAAa,gBAAgB;CAC3B,QAAQ;CACR,KAAK;CACL,KAAK;CACN;AAED,MAAa,aAAa;CACxB,QAAQ;CACR,WAAW;CACX,cAAc;CACd,UAAU;CACV,eAAe;CACf,WAAW;CACX,YAAY;CACZ,WAAW;CACX,QAAQ;CACR,MAAM;CACN,OAAO;CACP,OAAO;CACP,eAAe;CACf,OAAO;CACP,UAAU;CACV,YAAY;CACZ,SAAS;CACT,KAAK;CACL,MAAM;CACN,SAAS;CACT,eAAe;CACf,gBAAgB;CAChB,SAAS;CACT,O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