@teamscale/javascript-instrumenter 0.0.1-alpha.20 → 0.0.1-beta.1
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 +25 -2
- package/dist/package.json +15 -14
- package/dist/src/App.d.ts +1 -0
- package/dist/src/App.d.ts.map +1 -0
- package/dist/src/App.js +67 -40
- package/dist/src/instrumenter/FileSystem.d.ts +1 -0
- package/dist/src/instrumenter/FileSystem.d.ts.map +1 -0
- package/dist/src/instrumenter/FileSystem.js +44 -18
- package/dist/src/instrumenter/Instrumenter.d.ts +9 -2
- package/dist/src/instrumenter/Instrumenter.d.ts.map +1 -0
- package/dist/src/instrumenter/Instrumenter.js +99 -47
- package/dist/src/instrumenter/Task.d.ts +3 -2
- package/dist/src/instrumenter/Task.d.ts.map +1 -0
- package/dist/src/instrumenter/Task.js +52 -23
- package/dist/src/instrumenter/TaskBuilder.d.ts +18 -0
- package/dist/src/instrumenter/TaskBuilder.d.ts.map +1 -0
- package/dist/src/instrumenter/TaskBuilder.js +111 -50
- package/dist/src/main.d.ts +1 -0
- package/dist/src/main.d.ts.map +1 -0
- package/dist/src/main.js +4 -2
- package/dist/vaccine.js +216 -571
- package/package.json +11 -14
- package/dist/src/ConfigurationParameters.d.ts +0 -11
- package/dist/src/ConfigurationParameters.js +0 -1
- package/dist/vaccine.js.map +0 -1
package/dist/vaccine.js
CHANGED
|
@@ -1,576 +1,221 @@
|
|
|
1
|
-
(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Constructor.
|
|
83
|
-
*
|
|
84
|
-
* @param url - The URL to send messages to.
|
|
85
|
-
*/
|
|
86
|
-
constructor(url) {
|
|
87
|
-
/** The messages that have been cached */
|
|
88
|
-
this.cache = [];
|
|
89
|
-
this.url = url;
|
|
90
|
-
this.socket = this.createSocket();
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Re-Create the WebSocket.
|
|
94
|
-
*/
|
|
95
|
-
createSocket() {
|
|
96
|
-
const socket = new WebSocket(this.url);
|
|
97
|
-
socket.onopen = () => this.onopen();
|
|
98
|
-
socket.onclose = () => this.onclose();
|
|
99
|
-
return socket;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Handle a lost connection.
|
|
103
|
-
*/
|
|
104
|
-
onclose() {
|
|
105
|
-
this.socket = this.createSocket();
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Handle a (re-)established connection.
|
|
109
|
-
*/
|
|
110
|
-
onopen() {
|
|
111
|
-
this.cache.forEach(message => this.socket.send(message));
|
|
112
|
-
this.cache = [];
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Send the message, or cache it if the connection
|
|
116
|
-
* has not yet been established.
|
|
117
|
-
*/
|
|
118
|
-
send(message) {
|
|
119
|
-
if (this.socket.readyState === WebSocket.OPEN) {
|
|
120
|
-
this.socket.send(message);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
// socket has not been opened yet for the first time
|
|
124
|
-
this.cache.push(message);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
CachingSocket$1.CachingSocket = CachingSocket;
|
|
129
|
-
|
|
130
|
-
var CoverageAggregator$1 = {};
|
|
131
|
-
|
|
132
|
-
Object.defineProperty(CoverageAggregator$1, "__esModule", { value: true });
|
|
133
|
-
CoverageAggregator$1.Countdown = CoverageAggregator$1.CoverageAggregator = void 0;
|
|
134
|
-
/**
|
|
135
|
-
* The number of cache elements after that the cache should be flushed.
|
|
136
|
-
*/
|
|
137
|
-
const FLUSH_AFTER_ELEMENTS = 20;
|
|
138
|
-
/**
|
|
139
|
-
* Number of milliseconds after that the cash should be flushed.
|
|
140
|
-
*/
|
|
141
|
-
const FLUSH_AFTER_MILLIS = 1000;
|
|
142
|
-
/**
|
|
143
|
-
* Is supposed to exist once per app and might deal with
|
|
144
|
-
* different JavaScript files that were instrumented upfront.
|
|
145
|
-
*/
|
|
146
|
-
class CoverageAggregator {
|
|
147
|
-
/**
|
|
148
|
-
* The constructor.
|
|
149
|
-
*
|
|
150
|
-
* @param socket - The socket to send collected coverage information to.
|
|
151
|
-
*/
|
|
152
|
-
constructor(socket) {
|
|
153
|
-
this.socket = socket;
|
|
154
|
-
this.cachedCoveredPositions = new Map();
|
|
155
|
-
this.numberOfCachedPositions = 0;
|
|
156
|
-
this.flushCountdown = new Countdown(FLUSH_AFTER_MILLIS, () => this.flush());
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Add coverage information.
|
|
160
|
-
*
|
|
161
|
-
* @param positionCoverageInfo - A string that encodes the coverage information.
|
|
162
|
-
* The string is supposed to be formatted as follows: `<fileId>:<lineNumber>:<columNumber>`
|
|
163
|
-
*/
|
|
164
|
-
add(positionCoverageInfo) {
|
|
165
|
-
const parts = positionCoverageInfo.split(':');
|
|
166
|
-
if (parts.length != 3) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
const [fileId, line, column] = parts;
|
|
170
|
-
let coveredPositions = this.cachedCoveredPositions.get(fileId);
|
|
171
|
-
if (!coveredPositions) {
|
|
172
|
-
coveredPositions = new Set();
|
|
173
|
-
this.cachedCoveredPositions.set(fileId, coveredPositions);
|
|
174
|
-
}
|
|
175
|
-
coveredPositions.add(`${line}:${column}`);
|
|
176
|
-
this.numberOfCachedPositions += 1;
|
|
177
|
-
this.flushCountdown.restartCountdown();
|
|
178
|
-
if (this.numberOfCachedPositions >= FLUSH_AFTER_ELEMENTS) {
|
|
179
|
-
this.flush();
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Flush the caches (send them to the collector).
|
|
184
|
-
*/
|
|
185
|
-
flush() {
|
|
186
|
-
if (this.numberOfCachedPositions === 0) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
this.flushCountdown.stopCountdown();
|
|
190
|
-
this.cachedCoveredPositions.forEach((positionSet, fileId) => {
|
|
191
|
-
this.socket.send(`c ${fileId} ${Array.from(positionSet).join(' ')}`);
|
|
192
|
-
});
|
|
193
|
-
this.cachedCoveredPositions = new Map();
|
|
194
|
-
this.numberOfCachedPositions = 0;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
CoverageAggregator$1.CoverageAggregator = CoverageAggregator;
|
|
198
|
-
/**
|
|
199
|
-
* Countdown that can be reset to start counting from 0.
|
|
200
|
-
*/
|
|
201
|
-
class Countdown {
|
|
202
|
-
/**
|
|
203
|
-
* Constructor.
|
|
204
|
-
*
|
|
205
|
-
* @param milliseconds - The duration of the countdown in milliseconds.
|
|
206
|
-
* @param onCountedToZero - The action to execute when the countdown reaches 0.
|
|
207
|
-
*/
|
|
208
|
-
constructor(milliseconds, onCountedToZero) {
|
|
209
|
-
this.milliseconds = milliseconds;
|
|
210
|
-
this.onCountedToZero = onCountedToZero;
|
|
211
|
-
/**
|
|
212
|
-
* The timer handle.
|
|
213
|
-
*/
|
|
214
|
-
this.timerHandle = null;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Restart the countdown.
|
|
218
|
-
*/
|
|
219
|
-
restartCountdown() {
|
|
220
|
-
this.stopCountdown();
|
|
221
|
-
this.timerHandle = self.setTimeout(() => {
|
|
222
|
-
this.stopCountdown();
|
|
223
|
-
this.onCountedToZero();
|
|
224
|
-
}, this.milliseconds);
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Stop the countdown.
|
|
228
|
-
*/
|
|
229
|
-
stopCountdown() {
|
|
230
|
-
if (this.timerHandle === null) {
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
self.clearTimeout(this.timerHandle);
|
|
234
|
-
this.timerHandle = null;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
CoverageAggregator$1.Countdown = Countdown;
|
|
238
|
-
|
|
239
|
-
var protocol = {};
|
|
240
|
-
|
|
241
|
-
(function (exports) {
|
|
242
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
243
|
-
exports.ProtocolMessageTypes = void 0;
|
|
244
|
-
(function (ProtocolMessageTypes) {
|
|
245
|
-
/** A message that provides a source map */
|
|
246
|
-
ProtocolMessageTypes["MESSAGE_TYPE_SOURCEMAP"] = "s";
|
|
247
|
-
/** A message that provides coverage information */
|
|
248
|
-
ProtocolMessageTypes["MESSAGE_TYPE_COVERAGE"] = "c";
|
|
249
|
-
})(exports.ProtocolMessageTypes || (exports.ProtocolMessageTypes = {}));
|
|
250
|
-
}(protocol));
|
|
251
|
-
|
|
252
|
-
Object.defineProperty(main, "__esModule", { value: true });
|
|
253
|
-
/**
|
|
254
|
-
* This is the code of the WebWorker that forwards the coverage
|
|
255
|
-
* information to the collector.
|
|
256
|
-
*/
|
|
257
|
-
const CachingSocket_1 = CachingSocket$1;
|
|
258
|
-
const CoverageAggregator_1 = CoverageAggregator$1;
|
|
259
|
-
const protocol_1 = protocol;
|
|
260
|
-
console.log('Starting coverage forwarding worker.');
|
|
261
|
-
// Create the client socket.
|
|
262
|
-
// ATTENTION: Parts of the URLs, for example, $REPORT_TO_HOST,
|
|
263
|
-
// get replaced when injecting the code into the code to record coverage for.
|
|
264
|
-
const socket = new CachingSocket_1.CachingSocket('ws://$REPORT_TO_HOST:$REPORT_TO_PORT/socket');
|
|
265
|
-
const aggregator = new CoverageAggregator_1.CoverageAggregator(socket);
|
|
266
|
-
// Handling of the messages the WebWorker receives
|
|
267
|
-
onmessage = (event) => {
|
|
268
|
-
const message = event.data;
|
|
269
|
-
if (message.startsWith(protocol_1.ProtocolMessageTypes.MESSAGE_TYPE_SOURCEMAP)) {
|
|
270
|
-
socket.send(message);
|
|
271
|
-
}
|
|
272
|
-
else if (message === 'unload') {
|
|
273
|
-
// Send all information immediately
|
|
274
|
-
aggregator.flush();
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
// Coverage information
|
|
278
|
-
aggregator.add(message);
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
return main;
|
|
283
|
-
|
|
284
|
-
})());
|
|
285
|
-
}, null);
|
|
286
|
-
/* eslint-enable */
|
|
287
|
-
|
|
288
|
-
var Interceptor$1 = {};
|
|
289
|
-
|
|
290
|
-
var utils = {};
|
|
291
|
-
|
|
292
|
-
Object.defineProperty(utils, "__esModule", { value: true });
|
|
293
|
-
var universeAttribute_1 = utils.universeAttribute = getWindow_1 = utils.getWindow = hasWindow_1 = utils.hasWindow = universe_1 = utils.universe = utils.isWebWorker = void 0;
|
|
294
|
-
/**
|
|
295
|
-
* Determines if the code is executed in a Web Worker.
|
|
296
|
-
*/
|
|
297
|
-
function isWebWorker() {
|
|
298
|
-
return typeof importScripts === 'function';
|
|
299
|
-
}
|
|
300
|
-
utils.isWebWorker = isWebWorker;
|
|
301
|
-
/**
|
|
302
|
-
* Return the global universe object (in a Web browser: The window object).
|
|
303
|
-
*/
|
|
304
|
-
function universe() {
|
|
305
|
-
return getWindow();
|
|
306
|
-
}
|
|
307
|
-
var universe_1 = utils.universe = universe;
|
|
308
|
-
/**
|
|
309
|
-
* Determines if the window object is present.
|
|
310
|
-
*/
|
|
311
|
-
function hasWindow() {
|
|
312
|
-
return typeof window !== 'undefined';
|
|
313
|
-
}
|
|
314
|
-
var hasWindow_1 = utils.hasWindow = hasWindow;
|
|
315
|
-
/**
|
|
316
|
-
* Returns the window object.
|
|
317
|
-
*/
|
|
318
|
-
function getWindow() {
|
|
319
|
-
return window;
|
|
320
|
-
}
|
|
321
|
-
var getWindow_1 = utils.getWindow = getWindow;
|
|
322
|
-
/**
|
|
323
|
-
* Query or set a global attribute.
|
|
324
|
-
*/
|
|
325
|
-
function universeAttribute(attributeName, defaultValue) {
|
|
326
|
-
let result = universe()[attributeName];
|
|
327
|
-
if (!result) {
|
|
328
|
-
result = defaultValue;
|
|
329
|
-
universe()[attributeName] = result;
|
|
330
|
-
}
|
|
331
|
-
return result;
|
|
332
|
-
}
|
|
333
|
-
universeAttribute_1 = utils.universeAttribute = universeAttribute;
|
|
334
|
-
|
|
335
|
-
Object.defineProperty(Interceptor$1, "__esModule", { value: true });
|
|
336
|
-
var makeProxy_1 = Interceptor$1.makeProxy = void 0;
|
|
337
|
-
const utils_1 = utils;
|
|
338
|
-
const STATEMENT_COVERAGE_ID = 's';
|
|
339
|
-
/**
|
|
340
|
-
* Used to intercepts updates to Istanbuls' coverage object.
|
|
341
|
-
*/
|
|
342
|
-
class Interceptor {
|
|
343
|
-
/**
|
|
344
|
-
* Constructor.
|
|
345
|
-
*/
|
|
346
|
-
constructor(coverageObj, path) {
|
|
347
|
-
this.coverageObj = coverageObj;
|
|
348
|
-
this.path = path;
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Intercept reading an objects' property.
|
|
352
|
-
*/
|
|
353
|
-
get(target, prop, receiver) {
|
|
354
|
-
const value = target[prop];
|
|
355
|
-
if (value !== Object(value)) {
|
|
356
|
-
// Extract the primitive value
|
|
357
|
-
return value;
|
|
358
|
-
}
|
|
359
|
-
return makeProxy(this.coverageObj, value, [...this.path, prop]);
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Intercept writing an objects' property.
|
|
363
|
-
*/
|
|
364
|
-
set(obj, prop, value) {
|
|
365
|
-
const fullPath = [...this.path, prop];
|
|
366
|
-
// Handle "Statement" coverage
|
|
367
|
-
if (fullPath[0] === STATEMENT_COVERAGE_ID) {
|
|
368
|
-
const fileId = this.coverageObj.hash;
|
|
369
|
-
const start = this.coverageObj.statementMap[fullPath[1]].start;
|
|
370
|
-
utils_1.universe()['_$Bc'](fileId, start.line, start.column);
|
|
371
|
-
}
|
|
372
|
-
return true;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* Constructs the actual interceptor/proxy that forwards changed coverage information.
|
|
377
|
-
*
|
|
378
|
-
* See {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy}.
|
|
379
|
-
*/
|
|
380
|
-
function makeProxy(coverage, target, path) {
|
|
381
|
-
return new Proxy(target, new Interceptor(coverage, path));
|
|
382
|
-
}
|
|
383
|
-
makeProxy_1 = Interceptor$1.makeProxy = makeProxy;
|
|
384
|
-
|
|
385
|
-
// Only Node.JS has a process variable that is of [[Class]] process
|
|
386
|
-
var isNode = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
|
|
387
|
-
|
|
388
|
-
/* global WorkerGlobalScope */
|
|
389
|
-
function add$2(fn) {
|
|
390
|
-
if (typeof WorkerGlobalScope === 'function' && self instanceof WorkerGlobalScope) ; else {
|
|
391
|
-
/**
|
|
392
|
-
* if we are on react-native, there is no window.addEventListener
|
|
393
|
-
* @link https://github.com/pubkey/unload/issues/6
|
|
394
|
-
*/
|
|
395
|
-
if (typeof window.addEventListener !== 'function') return;
|
|
396
|
-
/**
|
|
397
|
-
* for normal browser-windows, we use the beforeunload-event
|
|
398
|
-
*/
|
|
399
|
-
|
|
400
|
-
window.addEventListener('beforeunload', function () {
|
|
401
|
-
fn();
|
|
402
|
-
}, true);
|
|
403
|
-
/**
|
|
404
|
-
* for iframes, we have to use the unload-event
|
|
405
|
-
* @link https://stackoverflow.com/q/47533670/3443137
|
|
406
|
-
*/
|
|
407
|
-
|
|
408
|
-
window.addEventListener('unload', function () {
|
|
409
|
-
fn();
|
|
410
|
-
}, true);
|
|
1
|
+
(() => {
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
9
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
+
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module, desc) => {
|
|
13
|
+
if (module && typeof module === "object" || typeof module === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toModule = (module) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// ../../node_modules/detect-node/browser.js
|
|
25
|
+
var require_browser = __commonJS({
|
|
26
|
+
"../../node_modules/detect-node/browser.js"(exports, module) {
|
|
27
|
+
module.exports = false;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// (disabled):../../node_modules/unload/dist/es/node.js
|
|
32
|
+
var require_node = __commonJS({
|
|
33
|
+
"(disabled):../../node_modules/unload/dist/es/node.js"() {
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// inline-worker:__inline-worker
|
|
38
|
+
function inlineWorker(scriptText) {
|
|
39
|
+
let blob = new Blob([scriptText], { type: "text/javascript" });
|
|
40
|
+
let url = URL.createObjectURL(blob);
|
|
41
|
+
let worker = new Worker(url);
|
|
42
|
+
URL.revokeObjectURL(url);
|
|
43
|
+
return worker;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/vaccine/worker/vaccine.worker.ts
|
|
47
|
+
function Worker2() {
|
|
48
|
+
return inlineWorker('var n=class{constructor(t){this.cachedMessages=[];this.url=t,this.socket=this.createSocket()}createSocket(){let t=new WebSocket(this.url);return t.onopen=()=>this.onopen(),t.onclose=()=>this.onclose(),t}onclose(){this.socket=this.createSocket()}onopen(){this.cachedMessages.forEach(t=>this.socket.send(t)),this.cachedMessages=[]}send(t){this.socket.readyState===WebSocket.OPEN?this.socket.send(t):this.cachedMessages.push(t)}};var o;(function(e){e.MESSAGE_TYPE_SOURCEMAP="s",e.MESSAGE_TYPE_COVERAGE="c"})(o||(o={}));var C=20,p=1e3,a=class{constructor(t,e){this.milliseconds=t;this.onCountedToZero=e;this.timerHandle=null}restartCountdown(){this.stopCountdown(),this.timerHandle=self.setTimeout(()=>{this.stopCountdown(),this.onCountedToZero()},this.milliseconds)}stopCountdown(){this.timerHandle!==null&&(self.clearTimeout(this.timerHandle),this.timerHandle=null)}},r=class{constructor(t){this.socket=t,this.cachedCoveredPositions=new Map,this.numberOfCachedPositions=0,this.flushCountdown=new a(p,()=>this.flush())}add(t){let e=t.split(":");if(e.length!==3)return;let[c,u,l]=e,i=this.cachedCoveredPositions.get(c);i||(i=new Set,this.cachedCoveredPositions.set(c,i)),i.add(`${u}:${l}`),this.numberOfCachedPositions+=1,this.flushCountdown.restartCountdown(),this.numberOfCachedPositions>=C&&this.flush()}flush(){this.numberOfCachedPositions!==0&&(this.flushCountdown.stopCountdown(),this.cachedCoveredPositions.forEach((t,e)=>{this.socket.send(`${o.MESSAGE_TYPE_COVERAGE} ${e} ${Array.from(t).join(" ")}`)}),this.cachedCoveredPositions=new Map,this.numberOfCachedPositions=0)}};console.log("Starting coverage forwarding worker.");var h=new n("ws://$REPORT_TO_HOST:$REPORT_TO_PORT/socket"),d=new r(h);onmessage=s=>{let t=s.data;t.startsWith(o.MESSAGE_TYPE_SOURCEMAP)?h.send(t):t==="unload"?d.flush():d.add(t)};\n');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/vaccine/utils.ts
|
|
52
|
+
function universe() {
|
|
53
|
+
return getWindow();
|
|
54
|
+
}
|
|
55
|
+
function hasWindow() {
|
|
56
|
+
return typeof window !== "undefined";
|
|
57
|
+
}
|
|
58
|
+
function getWindow() {
|
|
59
|
+
return window;
|
|
60
|
+
}
|
|
61
|
+
function universeAttribute(attributeName, defaultValue) {
|
|
62
|
+
let result = universe()[attributeName];
|
|
63
|
+
if (!result) {
|
|
64
|
+
result = defaultValue;
|
|
65
|
+
universe()[attributeName] = result;
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/vaccine/Interceptor.ts
|
|
71
|
+
var STATEMENT_COVERAGE_ID = "s";
|
|
72
|
+
var Interceptor = class {
|
|
73
|
+
constructor(coverageObj, path) {
|
|
74
|
+
this.coverageObj = coverageObj;
|
|
75
|
+
this.path = path;
|
|
76
|
+
}
|
|
77
|
+
get(target, prop, receiver) {
|
|
78
|
+
const value = target[prop];
|
|
79
|
+
if (value !== Object(value)) {
|
|
80
|
+
return value;
|
|
411
81
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
82
|
+
return makeProxy(this.coverageObj, value, [...this.path, prop]);
|
|
83
|
+
}
|
|
84
|
+
set(obj, prop, value) {
|
|
85
|
+
const fullPath = [...this.path, prop];
|
|
86
|
+
if (fullPath[0] === STATEMENT_COVERAGE_ID) {
|
|
87
|
+
const fileId = this.coverageObj.hash;
|
|
88
|
+
const start = this.coverageObj.statementMap[fullPath[1]].start;
|
|
89
|
+
universe()._$Bc(fileId, start.line, start.column);
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
function makeProxy(coverage, target, path) {
|
|
95
|
+
return new Proxy(target, new Interceptor(coverage, path));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ../../node_modules/unload/dist/es/index.js
|
|
99
|
+
var import_detect_node = __toModule(require_browser());
|
|
100
|
+
|
|
101
|
+
// ../../node_modules/unload/dist/es/browser.js
|
|
102
|
+
function add(fn) {
|
|
103
|
+
if (typeof WorkerGlobalScope === "function" && self instanceof WorkerGlobalScope) {
|
|
104
|
+
} else {
|
|
105
|
+
if (typeof window.addEventListener !== "function")
|
|
106
|
+
return;
|
|
107
|
+
window.addEventListener("beforeunload", function() {
|
|
108
|
+
fn();
|
|
109
|
+
}, true);
|
|
110
|
+
window.addEventListener("unload", function() {
|
|
111
|
+
fn();
|
|
112
|
+
}, true);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
var browser_default = {
|
|
116
|
+
add
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// ../../node_modules/unload/dist/es/index.js
|
|
120
|
+
var import_node = __toModule(require_node());
|
|
121
|
+
var USE_METHOD = import_detect_node.default ? import_node.default : browser_default;
|
|
122
|
+
var LISTENERS = new Set();
|
|
123
|
+
var startedListening = false;
|
|
124
|
+
function startListening() {
|
|
125
|
+
if (startedListening)
|
|
126
|
+
return;
|
|
127
|
+
startedListening = true;
|
|
128
|
+
USE_METHOD.add(runAll);
|
|
129
|
+
}
|
|
130
|
+
function add2(fn) {
|
|
131
|
+
startListening();
|
|
132
|
+
if (typeof fn !== "function")
|
|
133
|
+
throw new Error("Listener is no function");
|
|
134
|
+
LISTENERS.add(fn);
|
|
135
|
+
var addReturn = {
|
|
136
|
+
remove: function remove() {
|
|
137
|
+
return LISTENERS["delete"](fn);
|
|
138
|
+
},
|
|
139
|
+
run: function run() {
|
|
140
|
+
LISTENERS["delete"](fn);
|
|
427
141
|
return fn();
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* on the following events,
|
|
431
|
-
* the process will not end if there are
|
|
432
|
-
* event-handlers attached,
|
|
433
|
-
* therefore we have to call process.exit()
|
|
434
|
-
*/
|
|
435
|
-
|
|
436
|
-
process.on('beforeExit', function () {
|
|
437
|
-
return fn().then(function () {
|
|
438
|
-
return process.exit();
|
|
439
|
-
});
|
|
440
|
-
}); // catches ctrl+c event
|
|
441
|
-
|
|
442
|
-
process.on('SIGINT', function () {
|
|
443
|
-
return fn().then(function () {
|
|
444
|
-
return process.exit();
|
|
445
|
-
});
|
|
446
|
-
}); // catches uncaught exceptions
|
|
447
|
-
|
|
448
|
-
process.on('uncaughtException', function (err) {
|
|
449
|
-
return fn().then(function () {
|
|
450
|
-
console.trace(err);
|
|
451
|
-
process.exit(1);
|
|
452
|
-
});
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
var NodeMethod = {
|
|
457
|
-
add: add$1
|
|
142
|
+
}
|
|
458
143
|
};
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
var
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
144
|
+
return addReturn;
|
|
145
|
+
}
|
|
146
|
+
function runAll() {
|
|
147
|
+
var promises = [];
|
|
148
|
+
LISTENERS.forEach(function(fn) {
|
|
149
|
+
promises.push(fn());
|
|
150
|
+
LISTENERS["delete"](fn);
|
|
151
|
+
});
|
|
152
|
+
return Promise.all(promises);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/vaccine/protocol.ts
|
|
156
|
+
var ProtocolMessageTypes;
|
|
157
|
+
(function(ProtocolMessageTypes2) {
|
|
158
|
+
ProtocolMessageTypes2["MESSAGE_TYPE_SOURCEMAP"] = "s";
|
|
159
|
+
ProtocolMessageTypes2["MESSAGE_TYPE_COVERAGE"] = "c";
|
|
160
|
+
})(ProtocolMessageTypes || (ProtocolMessageTypes = {}));
|
|
161
|
+
|
|
162
|
+
// src/vaccine/main.ts
|
|
163
|
+
var globalAgentObject = universeAttribute("__TS_AGENT", {});
|
|
164
|
+
function getWorker() {
|
|
165
|
+
return globalAgentObject._$BcWorker;
|
|
166
|
+
}
|
|
167
|
+
function setWorker(worker) {
|
|
168
|
+
globalAgentObject._$BcWorker = worker;
|
|
169
|
+
return worker;
|
|
170
|
+
}
|
|
171
|
+
universe().makeCoverageInterceptor = function(coverage) {
|
|
172
|
+
const fileId = coverage.hash;
|
|
173
|
+
if (!getWorker()) {
|
|
174
|
+
const worker = setWorker(new Worker2());
|
|
175
|
+
(function handleUnloading() {
|
|
176
|
+
const protectWindowEvent = function(name) {
|
|
177
|
+
let wrappedHandler = getWindow()[name];
|
|
178
|
+
getWindow()[name] = function(...args) {
|
|
179
|
+
worker.postMessage("unload");
|
|
180
|
+
if (wrappedHandler) {
|
|
181
|
+
return wrappedHandler.apply(this, args);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
if (hasWindow()) {
|
|
185
|
+
Object.defineProperty(getWindow(), name, {
|
|
186
|
+
get: function() {
|
|
187
|
+
return wrappedHandler;
|
|
188
|
+
},
|
|
189
|
+
set: function(newHandler) {
|
|
190
|
+
wrappedHandler = newHandler;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
protectWindowEvent("onunload");
|
|
196
|
+
protectWindowEvent("onbeforeunload");
|
|
197
|
+
add2(() => worker.postMessage("unload"));
|
|
198
|
+
})();
|
|
199
|
+
}
|
|
200
|
+
(function sendSourceMaps() {
|
|
201
|
+
const sentMaps = universeAttribute("sentMaps", new Set());
|
|
202
|
+
if (coverage.inputSourceMap) {
|
|
203
|
+
if (!sentMaps.has(coverage.path)) {
|
|
204
|
+
getWorker().postMessage(`${ProtocolMessageTypes.MESSAGE_TYPE_SOURCEMAP} ${fileId}:${JSON.stringify(coverage.inputSourceMap)}`);
|
|
205
|
+
sentMaps.add(coverage.path);
|
|
481
206
|
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
return Promise.all(promises);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
var protocol = {};
|
|
495
|
-
|
|
496
|
-
(function (exports) {
|
|
497
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
498
|
-
exports.ProtocolMessageTypes = void 0;
|
|
499
|
-
(function (ProtocolMessageTypes) {
|
|
500
|
-
/** A message that provides a source map */
|
|
501
|
-
ProtocolMessageTypes["MESSAGE_TYPE_SOURCEMAP"] = "s";
|
|
502
|
-
/** A message that provides coverage information */
|
|
503
|
-
ProtocolMessageTypes["MESSAGE_TYPE_COVERAGE"] = "c";
|
|
504
|
-
})(exports.ProtocolMessageTypes || (exports.ProtocolMessageTypes = {}));
|
|
505
|
-
}(protocol));
|
|
506
|
-
|
|
507
|
-
var globalAgentObject = universeAttribute_1('__TS_AGENT', {});
|
|
508
|
-
function getWorker() {
|
|
509
|
-
return globalAgentObject._$BcWorker;
|
|
510
|
-
}
|
|
511
|
-
function setWorker(worker) {
|
|
512
|
-
globalAgentObject._$BcWorker = worker;
|
|
513
|
-
return worker;
|
|
514
|
-
}
|
|
515
|
-
universe_1().makeCoverageInterceptor = function (coverage) {
|
|
516
|
-
var fileId = coverage.hash;
|
|
517
|
-
if (!getWorker()) {
|
|
518
|
-
var worker_1 = setWorker(new WorkerFactory());
|
|
519
|
-
(function handleUnloading() {
|
|
520
|
-
var protectWindowEvent = function (name) {
|
|
521
|
-
var wrappedHandler = getWindow_1()[name];
|
|
522
|
-
getWindow_1()[name] = function () {
|
|
523
|
-
var args = [];
|
|
524
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
525
|
-
args[_i] = arguments[_i];
|
|
526
|
-
}
|
|
527
|
-
worker_1.postMessage('unload');
|
|
528
|
-
if (wrappedHandler) {
|
|
529
|
-
return wrappedHandler.apply(this, args);
|
|
530
|
-
}
|
|
531
|
-
};
|
|
532
|
-
if (hasWindow_1()) {
|
|
533
|
-
Object.defineProperty(getWindow_1(), name, {
|
|
534
|
-
get: function () {
|
|
535
|
-
return wrappedHandler;
|
|
536
|
-
},
|
|
537
|
-
set: function (newHandler) {
|
|
538
|
-
wrappedHandler = newHandler;
|
|
539
|
-
}
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
};
|
|
543
|
-
protectWindowEvent('onunload');
|
|
544
|
-
protectWindowEvent('onbeforeunload');
|
|
545
|
-
add(function () { return worker_1.postMessage('unload'); });
|
|
546
|
-
})();
|
|
207
|
+
}
|
|
208
|
+
})();
|
|
209
|
+
(function registerCoverageReporter() {
|
|
210
|
+
const reported = new Set();
|
|
211
|
+
universe()._$Bc = (fileId2, coveredLine, coveredColumn) => {
|
|
212
|
+
const coverageMessage = `${fileId2}:${coveredLine}:${coveredColumn}`;
|
|
213
|
+
if (!reported.has(coverageMessage)) {
|
|
214
|
+
getWorker().postMessage(coverageMessage);
|
|
215
|
+
reported.add(coverageMessage);
|
|
547
216
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
var sourceMap = value.inputSourceMap;
|
|
554
|
-
if (!sentMaps.has(key)) {
|
|
555
|
-
if (sourceMap) {
|
|
556
|
-
getWorker().postMessage(protocol.ProtocolMessageTypes.MESSAGE_TYPE_SOURCEMAP + " " + fileId + ":" + JSON.stringify(sourceMap));
|
|
557
|
-
sentMaps.add(key);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
})();
|
|
562
|
-
(function registerCoverageReporter() {
|
|
563
|
-
var reported = new Set();
|
|
564
|
-
universe_1()._$Bc = function (fileId, coveredLine, coveredColumn) {
|
|
565
|
-
var coverageMessage = fileId + ":" + coveredLine + ":" + coveredColumn;
|
|
566
|
-
if (!reported.has(coverageMessage)) {
|
|
567
|
-
getWorker().postMessage(coverageMessage);
|
|
568
|
-
reported.add(coverageMessage);
|
|
569
|
-
}
|
|
570
|
-
};
|
|
571
|
-
})();
|
|
572
|
-
return makeProxy_1(coverage, coverage, []);
|
|
573
|
-
};
|
|
574
|
-
|
|
575
|
-
}());
|
|
576
|
-
//# sourceMappingURL=vaccine.js.map
|
|
217
|
+
};
|
|
218
|
+
})();
|
|
219
|
+
return makeProxy(coverage, coverage, []);
|
|
220
|
+
};
|
|
221
|
+
})();
|