@teamscale/javascript-instrumenter 0.0.1-beta.33 → 0.0.1-beta.34

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamscale/javascript-instrumenter",
3
- "version": "0.0.1-beta.33",
3
+ "version": "0.0.1-beta.34",
4
4
  "description": "Istanbul-based coverage instrumenter with coverage forwarding via WebSockets",
5
5
  "main": "dist/src/main.js",
6
6
  "bin": "dist/src/main.js",
@@ -1 +1 @@
1
- {"version":3,"file":"Cleaner.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/Cleaner.ts"],"names":[],"mappings":"AAGA,OAAO,EAON,cAAc,EACd,MAAM,cAAc,CAAC;AAEtB;;;;;GAKG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,OAAO,EAClB,aAAa,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,OAAO,GAClD,MAAM,CAcR"}
1
+ {"version":3,"file":"Cleaner.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/Cleaner.ts"],"names":[],"mappings":"AAGA,OAAO,EAKN,cAAc,EACd,MAAM,cAAc,CAAC;AAEtB;;;;;GAKG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,OAAO,EAClB,aAAa,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,OAAO,GAClD,MAAM,CAYR"}
@@ -17,11 +17,8 @@ const types_1 = require("@babel/types");
17
17
  function cleanSourceCode(code, esModules, makeCoverable) {
18
18
  const ast = (0, parser_1.parse)(code, { sourceType: esModules ? 'module' : 'script' });
19
19
  (0, traverse_1.default)(ast, {
20
- ExpressionStatement(path) {
21
- if (isUnsupportedCounterTypeIncrement(path)) {
22
- path.remove();
23
- }
24
- else if (isCoverageIncrementNode(path)) {
20
+ UpdateExpression(path) {
21
+ if (isCoverageIncrementNode(path)) {
25
22
  if (path.node.loc && !makeCoverable(path.node.loc)) {
26
23
  path.remove();
27
24
  }
@@ -35,23 +32,7 @@ exports.cleanSourceCode = cleanSourceCode;
35
32
  * Checks if the given `path.node` to a statement like `cov_104fq7oo4i().f[0]++;`
36
33
  */
37
34
  function isCoverageIncrementNode(path) {
38
- const expr = path.node.expression;
39
- if (!(0, types_1.isUpdateExpression)(expr)) {
40
- return false;
41
- }
42
- return extractCoverageCallExpression(expr) !== undefined;
43
- }
44
- /**
45
- * Is the given expression statement a coverage increment that
46
- * is not supported by our approach?
47
- *
48
- * For example, branch coverage is not supported.
49
- */
50
- function isUnsupportedCounterTypeIncrement(path) {
51
- if (!(0, types_1.isUpdateExpression)(path.node.expression)) {
52
- return false;
53
- }
54
- return extractBranchCounterExpression(path.node.expression) !== undefined;
35
+ return extractCoverageCallExpression(path.node) !== undefined;
55
36
  }
56
37
  /**
57
38
  * Returns the call expression from `cov_2pvvu1hl8v().b[2][0]++;` if
package/dist/vaccine.js CHANGED
@@ -1 +1 @@
1
- (()=>{var R=Object.create;var h=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var j=e=>h(e,"__esModule",{value:!0});var v=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports);var L=(e,n,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of $(n))!A.call(e,o)&&o!=="default"&&h(e,o,{get:()=>n[o],enumerable:!(t=y(n,o))||t.enumerable});return e},b=e=>L(j(h(e!=null?R(I(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);var E=v((K,C)=>{C.exports=!1});var W=v(()=>{});function f(e){let n=new Blob([e],{type:"text/javascript"}),t=URL.createObjectURL(n),o=new Worker(t);return URL.revokeObjectURL(t),o}function p(){return f('var i=class{constructor(e){this.cachedMessages=[];this.url=e,this.socket=this.createSocket()}createSocket(){let e=new WebSocket(this.url);return e.onopen=()=>this.onopen(),e.onclose=()=>this.onclose(),e}onclose(){this.socket=this.createSocket()}onopen(){this.cachedMessages.forEach(e=>this.socket.send(e)),this.cachedMessages=[]}send(e){this.socket.readyState===WebSocket.OPEN?this.socket.send(e):this.cachedMessages.push(e)}};var p=20,f=1e3,c=class{constructor(e,t){this.milliseconds=e;this.onCountedToZero=t;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)}},n=class{constructor(e){this.socket=e,this.cachedCoveredPositions=new Map,this.numberOfCachedPositions=0,this.flushCountdown=new c(f,()=>this.flush())}add(e){let t=e.split(":");if(t.length!==3)return;let[r,d,u]=t,o=this.cachedCoveredPositions.get(r);o||(o=new Set,this.cachedCoveredPositions.set(r,o)),o.add(`${d}:${u}`),this.numberOfCachedPositions+=1,this.flushCountdown.restartCountdown(),this.numberOfCachedPositions>=p&&this.flush()}flush(){this.numberOfCachedPositions!==0&&(this.flushCountdown.stopCountdown(),this.cachedCoveredPositions.forEach((e,t)=>{this.socket.send(`${"c"} ${t} ${Array.from(e).join(" ")}`)}),this.cachedCoveredPositions=new Map,this.numberOfCachedPositions=0)}};console.log("Starting coverage forwarding worker.");var h=new i("ws://$REPORT_TO_HOST:$REPORT_TO_PORT/socket"),a=new n(h);onmessage=s=>{let e=s.data;e.startsWith("s")?h.send(e):e==="unload"?a.flush():a.add(e)};\n')}function u(){return c()}function k(){return typeof window!="undefined"}function c(){return window}function m(e,n){let t=u()[e];return t||(t=n,u()[e]=t),t}var D="s",S=class{constructor(n,t){this.coverageObj=n;this.path=t}get(n,t,o){let r=n[t];return r!==Object(r)?r:w(this.coverageObj,r,[...this.path,t])}set(n,t,o){let r=[...this.path,t];if(r[0]===D){let i=this.coverageObj.hash,s=this.coverageObj.statementMap[r[1]].start;u()._$Bc(i,s.line,s.column)}return!0}};function w(e,n,t){return new Proxy(n,new S(e,t))}var M=b(E());function H(e){if(!(typeof WorkerGlobalScope=="function"&&self instanceof WorkerGlobalScope)){if(typeof window.addEventListener!="function")return;window.addEventListener("beforeunload",function(){e()},!0),window.addEventListener("unload",function(){e()},!0)}}var O={add:H};var T=b(W()),B=M.default?T.default:O,d=new Set,x=!1;function G(){x||(x=!0,B.add(U))}function P(e){if(G(),typeof e!="function")throw new Error("Listener is no function");d.add(e);var n={remove:function(){return d.delete(e)},run:function(){return d.delete(e),e()}};return n}function U(){var e=[];return d.forEach(function(n){e.push(n()),d.delete(n)}),Promise.all(e)}var l;(function(t){t.MESSAGE_TYPE_SOURCEMAP="s",t.MESSAGE_TYPE_COVERAGE="c"})(l||(l={}));var _=m("__TS_AGENT",{});function g(){return _._$BcWorker}function N(e){return _._$BcWorker=e,e}u().makeCoverageInterceptor=function(e){let n=e.hash;if(!g()){let t=N(new p);(function(){let r=function(i){let s=c()[i];c()[i]=function(...a){if(t.postMessage("unload"),s)return s.apply(this,a)},k()&&Object.defineProperty(c(),i,{get:function(){return s},set:function(a){s=a}})};r("onunload"),r("onbeforeunload"),P(()=>t.postMessage("unload"))})()}return function(){let o=m("sentMaps",new Set);e.inputSourceMap&&(o.has(e.path)||(g().postMessage(`${l.MESSAGE_TYPE_SOURCEMAP} ${n}:${JSON.stringify(e.inputSourceMap)}`),o.add(e.path)))}(),function(){let o=new Set;u()._$Bc=(r,i,s)=>{let a=`${r}:${i}:${s}`;o.has(a)||(g().postMessage(a),o.add(a))}}(),w(e,e,[])};})();
1
+ (()=>{var y=Object.create;var f=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var H=e=>f(e,"__esModule",{value:!0});var v=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var B=(e,t,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of I(t))!L.call(e,o)&&o!=="default"&&f(e,o,{get:()=>t[o],enumerable:!(n=A(t,o))||n.enumerable});return e},C=e=>B(H(f(e!=null?y(j(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);var R=v((ee,E)=>{E.exports=!1});var M=v(()=>{});function p(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o=new Worker(n);return URL.revokeObjectURL(n),o}function m(){return p('var i=class{constructor(e){this.cachedMessages=[];this.url=e,this.socket=this.createSocket()}createSocket(){let e=new WebSocket(this.url);return e.onopen=()=>this.onopen(),e.onclose=()=>this.onclose(),e}onclose(){this.socket=this.createSocket()}onopen(){this.cachedMessages.forEach(e=>this.socket.send(e)),this.cachedMessages=[]}send(e){this.socket.readyState===WebSocket.OPEN?this.socket.send(e):this.cachedMessages.push(e)}};var u=20,l=1e3,c=class{constructor(e,t){this.milliseconds=e;this.onCountedToZero=t;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)}},n=class{constructor(e){this.socket=e,this.cachedCoveredPositions=new Map,this.numberOfCachedPositions=0,this.flushCountdown=new c(l,()=>this.flush())}add(e){let t=e.split(":");if(t.length!==5)return;let r=t[0],o=this.cachedCoveredPositions.get(r);o||(o=new Set,this.cachedCoveredPositions.set(r,o)),o.add(`${t[1]}:${t[2]}:${t[3]}:${t[4]}`),this.numberOfCachedPositions+=1,this.flushCountdown.restartCountdown(),this.numberOfCachedPositions>=u&&this.flush()}flush(){this.numberOfCachedPositions!==0&&(this.flushCountdown.stopCountdown(),this.cachedCoveredPositions.forEach((e,t)=>{this.socket.send(`${"c"} ${t} ${Array.from(e).join(" ")}`)}),this.cachedCoveredPositions=new Map,this.numberOfCachedPositions=0)}};console.log("Starting coverage forwarding worker.");var h=new i("ws://$REPORT_TO_HOST:$REPORT_TO_PORT/socket"),a=new n(h);onmessage=s=>{let e=s.data;e.startsWith("s")?h.send(e):e==="unload"?a.flush():a.add(e)};\n')}function u(){return c()}function k(){return typeof window!="undefined"}function c(){return window}function b(e,t){let n=u()[e];return n||(n=t,u()[e]=n),n}var G="s",N="b",S=class{constructor(t,n){this.coverageObj=t;this.path=n}get(t,n,o){let r=t[n];return r!==Object(r)?r:g(this.coverageObj,r,[...this.path,n])}set(t,n,o){let r=[...this.path,n];if(r[0]===G){let i=r[1],s=this.coverageObj.statementMap[i];this.broadcastCodeRangeCoverage(s)}else if(r[0]===N){let i=r[1],s=Number.parseInt(r[2]),a=this.coverageObj.branchMap[i].locations[s];this.broadcastCodeRangeCoverage(a)}return!0}broadcastCodeRangeCoverage(t){let n=this.coverageObj.hash;u()._$Bc(n,t.start.line,t.start.column,t.end.line,t.end.column)}};function g(e,t,n){return new Proxy(t,new S(e,n))}var W=C(R());function U(e){if(!(typeof WorkerGlobalScope=="function"&&self instanceof WorkerGlobalScope)){if(typeof window.addEventListener!="function")return;window.addEventListener("beforeunload",function(){e()},!0),window.addEventListener("unload",function(){e()},!0)}}var O={add:U};var T=C(M()),D=W.default?T.default:O,d=new Set,_=!1;function V(){_||(_=!0,D.add(Y))}function x(e){if(V(),typeof e!="function")throw new Error("Listener is no function");d.add(e);var t={remove:function(){return d.delete(e)},run:function(){return d.delete(e),e()}};return t}function Y(){var e=[];return d.forEach(function(t){e.push(t()),d.delete(t)}),Promise.all(e)}var l;(function(n){n.MESSAGE_TYPE_SOURCEMAP="s",n.MESSAGE_TYPE_COVERAGE="c"})(l||(l={}));var P=b("__TS_AGENT",{});function w(){return P._$BcWorker}function z(e){return P._$BcWorker=e,e}u().makeCoverageInterceptor=function(e){let t=e.hash;if(!w()){let n=z(new m);(function(){let r=function(i){let s=c()[i];c()[i]=function(...a){if(n.postMessage("unload"),s)return s.apply(this,a)},k()&&Object.defineProperty(c(),i,{get:function(){return s},set:function(a){s=a}})};r("onunload"),r("onbeforeunload"),x(()=>n.postMessage("unload"))})()}return function(){let o=b("sentMaps",new Set);e.inputSourceMap&&(o.has(e.path)||(w().postMessage(`${l.MESSAGE_TYPE_SOURCEMAP} ${t}:${JSON.stringify(e.inputSourceMap)}`),o.add(e.path)))}(),function(){let o=new Set;u()._$Bc=(r,i,s,a,$)=>{let h=`${r}:${i}:${s}:${a}:${$}`;o.has(h)||(w().postMessage(h),o.add(h))}}(),g(e,e,[])};})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamscale/javascript-instrumenter",
3
- "version": "0.0.1-beta.33",
3
+ "version": "0.0.1-beta.34",
4
4
  "description": "Istanbul-based coverage instrumenter with coverage forwarding via WebSockets",
5
5
  "main": "dist/src/main.js",
6
6
  "bin": "dist/src/main.js",