@teamscale/javascript-instrumenter 0.0.1-beta.24 → 0.0.1-beta.29

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.24",
3
+ "version": "0.0.1-beta.29",
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,CAYR"}
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"}
@@ -18,7 +18,10 @@ 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
20
  ExpressionStatement(path) {
21
- if (isCoverageIncrementNode(path)) {
21
+ if (isUnsupportedCounterTypeIncrement(path)) {
22
+ path.remove();
23
+ }
24
+ else if (isCoverageIncrementNode(path)) {
22
25
  if (path.node.loc && !makeCoverable(path.node.loc)) {
23
26
  path.remove();
24
27
  }
@@ -36,11 +39,64 @@ function isCoverageIncrementNode(path) {
36
39
  if (!(0, types_1.isUpdateExpression)(expr)) {
37
40
  return false;
38
41
  }
39
- return (expr.operator === '++' &&
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;
55
+ }
56
+ /**
57
+ * Returns the call expression from `cov_2pvvu1hl8v().b[2][0]++;` if
58
+ * the given UpdateExpression is a branch coverage update expression.
59
+ */
60
+ function extractBranchCounterExpression(expr) {
61
+ if (expr.operator === '++' &&
62
+ (0, types_1.isMemberExpression)(expr.argument) &&
63
+ (0, types_1.isMemberExpression)(expr.argument.object) &&
64
+ (0, types_1.isMemberExpression)(expr.argument.object.object) &&
65
+ (0, types_1.isCallExpression)(expr.argument.object.object.object)) {
66
+ // Branch counter
67
+ return extractCoverageObjectCall(expr.argument.object.object.object);
68
+ }
69
+ return undefined;
70
+ }
71
+ /**
72
+ * Returns the call expression from `cov_104fq7oo4i().f[0]++;` if
73
+ * the given UpdateExpression is a function or statement coverage update expression.
74
+ */
75
+ function extractFunctionOrStatementCounterExpression(expr) {
76
+ if (expr.operator === '++' &&
40
77
  (0, types_1.isMemberExpression)(expr.argument) &&
41
78
  (0, types_1.isMemberExpression)(expr.argument.object) &&
42
- (0, types_1.isCallExpression)(expr.argument.object.object) &&
43
- (0, types_1.isIdentifier)(expr.argument.object.object.callee) &&
44
- expr.argument.object.object.callee.name.startsWith('cov_') &&
45
- (0, types_1.isNumericLiteral)(expr.argument.property));
79
+ (0, types_1.isCallExpression)(expr.argument.object.object)) {
80
+ // Function and statement counter
81
+ return extractCoverageObjectCall(expr.argument.object.object);
82
+ }
83
+ return undefined;
84
+ }
85
+ /**
86
+ * Given an `UpdateExpression` extract the call expression returning the coverage object.
87
+ */
88
+ function extractCoverageCallExpression(expr) {
89
+ var _a;
90
+ return (_a = extractBranchCounterExpression(expr)) !== null && _a !== void 0 ? _a : extractFunctionOrStatementCounterExpression(expr);
91
+ }
92
+ /**
93
+ * Check if the given call expression is a coverage call expression.
94
+ * If this is not the case return `undefined`, and the call expression itself otherwise.
95
+ */
96
+ function extractCoverageObjectCall(callExpression) {
97
+ if (callExpression && (0, types_1.isIdentifier)(callExpression.callee)
98
+ && callExpression.callee.name.startsWith('cov_')) {
99
+ return callExpression;
100
+ }
101
+ return undefined;
46
102
  }
package/dist/src/main.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamscale/javascript-instrumenter",
3
- "version": "0.0.1-beta.24",
3
+ "version": "0.0.1-beta.29",
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",
package/CHANGELOG.md DELETED
@@ -1,13 +0,0 @@
1
- We use [Semantic Versioning](https://semver.org/).
2
-
3
- # New Release
4
-
5
- - [feature] JavaScript bundles can now be instrumented partially if a source map is present.
6
-
7
- # 0.0.1-beta.21
8
-
9
- - [fix] Include/exclude pattern and the paths to match were not normalized
10
-
11
- # 0.0.1-beta.20
12
-
13
- - [feature] Automatic release now for NPM packages and Docker images