as-test 0.2.1 → 0.3.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.
Files changed (54) hide show
  1. package/.github/workflows/as-test.yml +3 -0
  2. package/CHANGELOG.md +1 -1
  3. package/README.md +73 -68
  4. package/as-test.config.json +7 -10
  5. package/assembly/__tests__/array.spec.ts +19 -0
  6. package/assembly/__tests__/math.spec.ts +16 -0
  7. package/assembly/__tests__/sleep.spec.ts +28 -0
  8. package/assembly/index.ts +181 -165
  9. package/assembly/src/expectation.ts +119 -112
  10. package/assembly/src/log.ts +19 -0
  11. package/assembly/src/suite.ts +99 -0
  12. package/assembly/src/tests.ts +10 -0
  13. package/assembly/tsconfig.json +1 -1
  14. package/assembly/util/helpers.ts +0 -33
  15. package/assembly/util/term.ts +55 -0
  16. package/assets/img/download.png +0 -0
  17. package/bin/about.js +135 -0
  18. package/bin/build.js +72 -131
  19. package/bin/index.js +70 -112
  20. package/bin/init.js +211 -39
  21. package/bin/reporter.js +1 -0
  22. package/bin/run.js +226 -68
  23. package/bin/types.js +25 -31
  24. package/bin/util.js +44 -20
  25. package/cli/build.ts +70 -109
  26. package/cli/index.ts +148 -159
  27. package/cli/init.ts +235 -34
  28. package/cli/reporter.ts +1 -0
  29. package/cli/run.ts +266 -57
  30. package/cli/types.ts +6 -11
  31. package/cli/util.ts +35 -0
  32. package/package.json +6 -2
  33. package/run/package.json +27 -0
  34. package/tests/array.run.js +7 -0
  35. package/tests/math.run.js +7 -0
  36. package/tests/sleep.run.js +7 -0
  37. package/transform/lib/coverage.js +325 -319
  38. package/transform/lib/index.js +51 -31
  39. package/transform/lib/index.js.map +1 -1
  40. package/transform/lib/mock.js +60 -52
  41. package/transform/lib/mock.js.map +1 -1
  42. package/transform/package.json +1 -1
  43. package/transform/src/index.ts +22 -3
  44. package/transform/src/mock.ts +1 -1
  45. package/asconfig.json +0 -31
  46. package/assembly/__tests__/example.spec.ts +0 -79
  47. package/assembly/reporters/tap.ts +0 -30
  48. package/assembly/src/group.ts +0 -44
  49. package/assembly/src/node.ts +0 -13
  50. package/test.config.json +0 -0
  51. package/tests/test.tap +0 -14
  52. package/unision +0 -38
  53. package/unision.pub +0 -1
  54. package/utils.ts +0 -1
@@ -1,44 +1,47 @@
1
- import { BlockStatement, ExpressionStatement, Node, } from "assemblyscript/dist/assemblyscript.js";
1
+ import {
2
+ BlockStatement,
3
+ ExpressionStatement,
4
+ Node,
5
+ } from "assemblyscript/dist/assemblyscript.js";
2
6
  import { BaseVisitor, SimpleParser } from "visitor-as/dist/index.js";
3
7
  import { RangeTransform } from "visitor-as/dist/transformRange.js";
4
8
  import { isStdlib } from "visitor-as/dist/utils.js";
5
9
  var CoverType;
6
10
  (function (CoverType) {
7
- CoverType[CoverType["Function"] = 0] = "Function";
8
- CoverType[CoverType["Expression"] = 1] = "Expression";
9
- CoverType[CoverType["Block"] = 2] = "Block";
11
+ CoverType[(CoverType["Function"] = 0)] = "Function";
12
+ CoverType[(CoverType["Expression"] = 1)] = "Expression";
13
+ CoverType[(CoverType["Block"] = 2)] = "Block";
10
14
  })(CoverType || (CoverType = {}));
11
15
  class CoverPoint {
12
- file = "";
13
- hash = "";
14
- line = 0;
15
- column = 0;
16
- type;
17
- executed = false;
16
+ file = "";
17
+ hash = "";
18
+ line = 0;
19
+ column = 0;
20
+ type;
21
+ executed = false;
18
22
  }
19
23
  export class CoverageTransform extends BaseVisitor {
20
- mustImport = false;
21
- points = new Map();
22
- globalStatements = [];
23
- visitBinaryExpression(node) {
24
- super.visitBinaryExpression(node);
25
- if (node.visited)
26
- return;
27
- node.visited = true;
28
- const path = node.range.source.normalizedPath;
29
- switch (node.operator) {
30
- case 98:
31
- case 97: {
32
- const right = node.right;
33
- const rightLc = getLineCol(node);
34
- const point = new CoverPoint();
35
- point.line = rightLc?.line;
36
- point.column = rightLc?.column;
37
- point.file = path;
38
- point.type = CoverType.Expression;
39
- point.hash = hash(point);
40
- const replacer = new RangeTransform(node);
41
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
24
+ mustImport = false;
25
+ points = new Map();
26
+ globalStatements = [];
27
+ visitBinaryExpression(node) {
28
+ super.visitBinaryExpression(node);
29
+ if (node.visited) return;
30
+ node.visited = true;
31
+ const path = node.range.source.normalizedPath;
32
+ switch (node.operator) {
33
+ case 98:
34
+ case 97: {
35
+ const right = node.right;
36
+ const rightLc = getLineCol(node);
37
+ const point = new CoverPoint();
38
+ point.line = rightLc?.line;
39
+ point.column = rightLc?.column;
40
+ point.file = path;
41
+ point.type = CoverType.Expression;
42
+ point.hash = hash(point);
43
+ const replacer = new RangeTransform(node);
44
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
42
45
  file: "${point.file}",
43
46
  hash: "${point.hash}",
44
47
  line: ${point.line},
@@ -46,35 +49,35 @@ export class CoverageTransform extends BaseVisitor {
46
49
  type: "Expression",
47
50
  executed: false
48
51
  });`);
49
- replacer.visit(registerStmt);
50
- let coverExpression = SimpleParser.parseExpression(`(__COVER("${point.hash}"), $$REPLACE_ME)`);
51
- replacer.visit(coverExpression);
52
- coverExpression.expression.expressions[1] = right;
53
- node.right = coverExpression;
54
- this.globalStatements.push(registerStmt);
55
- break;
56
- }
57
- }
52
+ replacer.visit(registerStmt);
53
+ let coverExpression = SimpleParser.parseExpression(
54
+ `(__COVER("${point.hash}"), $$REPLACE_ME)`,
55
+ );
56
+ replacer.visit(coverExpression);
57
+ coverExpression.expression.expressions[1] = right;
58
+ node.right = coverExpression;
59
+ this.globalStatements.push(registerStmt);
60
+ break;
61
+ }
58
62
  }
59
- visitMethodDeclaration(node) {
60
- super.visitMethodDeclaration(node);
61
- if (node.visited)
62
- return;
63
- node.visited = true;
64
- if (node.body) {
65
- if (node.body.visited)
66
- return;
67
- node.body.visited = true;
68
- const path = node.range.source.normalizedPath;
69
- const funcLc = getLineCol(node);
70
- const point = new CoverPoint();
71
- point.line = funcLc?.line;
72
- point.column = funcLc?.column;
73
- point.file = path;
74
- point.type = CoverType.Function;
75
- point.hash = hash(point);
76
- const replacer = new RangeTransform(node);
77
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
63
+ }
64
+ visitMethodDeclaration(node) {
65
+ super.visitMethodDeclaration(node);
66
+ if (node.visited) return;
67
+ node.visited = true;
68
+ if (node.body) {
69
+ if (node.body.visited) return;
70
+ node.body.visited = true;
71
+ const path = node.range.source.normalizedPath;
72
+ const funcLc = getLineCol(node);
73
+ const point = new CoverPoint();
74
+ point.line = funcLc?.line;
75
+ point.column = funcLc?.column;
76
+ point.file = path;
77
+ point.type = CoverType.Function;
78
+ point.hash = hash(point);
79
+ const replacer = new RangeTransform(node);
80
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
78
81
  file: "${point.file}",
79
82
  hash: "${point.hash}",
80
83
  line: ${point.line},
@@ -82,33 +85,34 @@ export class CoverageTransform extends BaseVisitor {
82
85
  type: "Function",
83
86
  executed: false
84
87
  })`);
85
- replacer.visit(registerStmt);
86
- const coverStmt = SimpleParser.parseStatement(`__COVER("${point.hash}")`, true);
87
- replacer.visit(coverStmt);
88
- const bodyBlock = node.body;
89
- bodyBlock.statements.unshift(coverStmt);
90
- this.globalStatements.push(registerStmt);
91
- }
88
+ replacer.visit(registerStmt);
89
+ const coverStmt = SimpleParser.parseStatement(
90
+ `__COVER("${point.hash}")`,
91
+ true,
92
+ );
93
+ replacer.visit(coverStmt);
94
+ const bodyBlock = node.body;
95
+ bodyBlock.statements.unshift(coverStmt);
96
+ this.globalStatements.push(registerStmt);
92
97
  }
93
- visitParameter(node) {
94
- if (node.visited)
95
- return;
96
- node.visited = true;
97
- const path = node.range.source.normalizedPath;
98
- if (node.initializer) {
99
- if (node.initializer.visited)
100
- return;
101
- node.initializer.visited = true;
102
- super.visitParameter(node);
103
- const paramLc = getLineCol(node.initializer);
104
- const point = new CoverPoint();
105
- point.line = paramLc?.line;
106
- point.column = paramLc?.column;
107
- point.file = path;
108
- point.type = CoverType.Expression;
109
- point.hash = hash(point);
110
- const replacer = new RangeTransform(node);
111
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
98
+ }
99
+ visitParameter(node) {
100
+ if (node.visited) return;
101
+ node.visited = true;
102
+ const path = node.range.source.normalizedPath;
103
+ if (node.initializer) {
104
+ if (node.initializer.visited) return;
105
+ node.initializer.visited = true;
106
+ super.visitParameter(node);
107
+ const paramLc = getLineCol(node.initializer);
108
+ const point = new CoverPoint();
109
+ point.line = paramLc?.line;
110
+ point.column = paramLc?.column;
111
+ point.file = path;
112
+ point.type = CoverType.Expression;
113
+ point.hash = hash(point);
114
+ const replacer = new RangeTransform(node);
115
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
112
116
  file: "${point.file}",
113
117
  hash: "${point.hash}",
114
118
  line: ${point.line},
@@ -116,34 +120,33 @@ export class CoverageTransform extends BaseVisitor {
116
120
  type: "Expression",
117
121
  executed: false
118
122
  })`);
119
- replacer.visit(registerStmt);
120
- const coverExpression = SimpleParser.parseExpression(`(__COVER("${point.hash}"), $$REPLACE_ME)`);
121
- replacer.visit(coverExpression);
122
- coverExpression.expression.expressions[1] =
123
- node.initializer;
124
- node.initializer = coverExpression;
125
- this.globalStatements.push(registerStmt);
126
- }
123
+ replacer.visit(registerStmt);
124
+ const coverExpression = SimpleParser.parseExpression(
125
+ `(__COVER("${point.hash}"), $$REPLACE_ME)`,
126
+ );
127
+ replacer.visit(coverExpression);
128
+ coverExpression.expression.expressions[1] = node.initializer;
129
+ node.initializer = coverExpression;
130
+ this.globalStatements.push(registerStmt);
127
131
  }
128
- visitFunctionDeclaration(node, isDefault) {
129
- super.visitFunctionDeclaration(node, isDefault);
130
- if (node.visited)
131
- return;
132
- node.visited = true;
133
- if (node.body) {
134
- if (node.body.visited)
135
- return;
136
- node.body.visited = true;
137
- const path = node.range.source.normalizedPath;
138
- const funcLc = getLineCol(node);
139
- const point = new CoverPoint();
140
- point.line = funcLc?.line;
141
- point.column = funcLc?.column;
142
- point.file = path;
143
- point.type = CoverType.Function;
144
- point.hash = hash(point);
145
- const replacer = new RangeTransform(node);
146
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
132
+ }
133
+ visitFunctionDeclaration(node, isDefault) {
134
+ super.visitFunctionDeclaration(node, isDefault);
135
+ if (node.visited) return;
136
+ node.visited = true;
137
+ if (node.body) {
138
+ if (node.body.visited) return;
139
+ node.body.visited = true;
140
+ const path = node.range.source.normalizedPath;
141
+ const funcLc = getLineCol(node);
142
+ const point = new CoverPoint();
143
+ point.line = funcLc?.line;
144
+ point.column = funcLc?.column;
145
+ point.file = path;
146
+ point.type = CoverType.Function;
147
+ point.hash = hash(point);
148
+ const replacer = new RangeTransform(node);
149
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
147
150
  file: "${point.file}",
148
151
  hash: "${point.hash}",
149
152
  line: ${point.line},
@@ -151,54 +154,57 @@ export class CoverageTransform extends BaseVisitor {
151
154
  type: "Function",
152
155
  executed: false
153
156
  })`);
154
- replacer.visit(registerStmt);
155
- this.globalStatements.push(registerStmt);
156
- if (node.body.kind === 35) {
157
- const coverStmt = SimpleParser.parseStatement(`{
157
+ replacer.visit(registerStmt);
158
+ this.globalStatements.push(registerStmt);
159
+ if (node.body.kind === 35) {
160
+ const coverStmt = SimpleParser.parseStatement(`{
158
161
  __COVER("${point.hash}")
159
162
  return $$REPLACE_ME
160
163
  }`);
161
- replacer.visit(coverStmt);
162
- const bodyReturn = coverStmt.statements[1];
163
- const body = node.body;
164
- node.arrowKind = 2;
165
- bodyReturn.value = body.expression;
166
- node.body = body;
167
- }
168
- else {
169
- const coverStmt = SimpleParser.parseStatement(`__COVER("${point.hash}")`, true);
170
- replacer.visit(coverStmt);
171
- if (node.body instanceof BlockStatement) {
172
- node.body.statements.unshift(coverStmt);
173
- }
174
- else if (node.body instanceof ExpressionStatement) {
175
- const expression = node.body.expression;
176
- node.body = Node.createBlockStatement([Node.createReturnStatement(expression, expression.range)], expression.range);
177
- const bodyBlock = node.body;
178
- bodyBlock.statements.unshift(coverStmt);
179
- }
180
- }
164
+ replacer.visit(coverStmt);
165
+ const bodyReturn = coverStmt.statements[1];
166
+ const body = node.body;
167
+ node.arrowKind = 2;
168
+ bodyReturn.value = body.expression;
169
+ node.body = body;
170
+ } else {
171
+ const coverStmt = SimpleParser.parseStatement(
172
+ `__COVER("${point.hash}")`,
173
+ true,
174
+ );
175
+ replacer.visit(coverStmt);
176
+ if (node.body instanceof BlockStatement) {
177
+ node.body.statements.unshift(coverStmt);
178
+ } else if (node.body instanceof ExpressionStatement) {
179
+ const expression = node.body.expression;
180
+ node.body = Node.createBlockStatement(
181
+ [Node.createReturnStatement(expression, expression.range)],
182
+ expression.range,
183
+ );
184
+ const bodyBlock = node.body;
185
+ bodyBlock.statements.unshift(coverStmt);
181
186
  }
187
+ }
182
188
  }
183
- visitIfStatement(node) {
184
- if (node.visited)
185
- return;
186
- node.visited = true;
187
- let visitIfTrue = false;
188
- let visitIfFalse = false;
189
- const ifTrue = node.ifTrue;
190
- const ifFalse = node.ifFalse;
191
- const path = node.range.source.normalizedPath;
192
- if (ifTrue.kind !== 30) {
193
- const trueLc = getLineCol(ifTrue);
194
- const point = new CoverPoint();
195
- point.line = trueLc?.line;
196
- point.column = trueLc?.column;
197
- point.file = path;
198
- point.type = CoverType.Expression;
199
- point.hash = hash(point);
200
- const replacer = new RangeTransform(ifTrue);
201
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
189
+ }
190
+ visitIfStatement(node) {
191
+ if (node.visited) return;
192
+ node.visited = true;
193
+ let visitIfTrue = false;
194
+ let visitIfFalse = false;
195
+ const ifTrue = node.ifTrue;
196
+ const ifFalse = node.ifFalse;
197
+ const path = node.range.source.normalizedPath;
198
+ if (ifTrue.kind !== 30) {
199
+ const trueLc = getLineCol(ifTrue);
200
+ const point = new CoverPoint();
201
+ point.line = trueLc?.line;
202
+ point.column = trueLc?.column;
203
+ point.file = path;
204
+ point.type = CoverType.Expression;
205
+ point.hash = hash(point);
206
+ const replacer = new RangeTransform(ifTrue);
207
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
202
208
  file: "${point.file}",
203
209
  hash: "${point.hash}",
204
210
  line: ${point.line},
@@ -206,25 +212,28 @@ export class CoverageTransform extends BaseVisitor {
206
212
  type: "Expression",
207
213
  executed: false
208
214
  })`);
209
- replacer.visit(registerStmt);
210
- const coverStmt = SimpleParser.parseStatement(`{__COVER("${point.hash}")};`, true);
211
- replacer.visit(coverStmt);
212
- coverStmt.statements.push(ifTrue);
213
- node.ifTrue = coverStmt;
214
- this.globalStatements.push(registerStmt);
215
- visitIfTrue = true;
216
- visitIfFalse = !!ifFalse;
217
- }
218
- if (ifFalse && ifFalse.kind !== 30) {
219
- const falseLc = getLineCol(ifFalse);
220
- const point = new CoverPoint();
221
- point.line = falseLc?.line;
222
- point.column = falseLc?.column;
223
- point.file = path;
224
- point.type = CoverType.Expression;
225
- point.hash = hash(point);
226
- const replacer = new RangeTransform(ifTrue);
227
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
215
+ replacer.visit(registerStmt);
216
+ const coverStmt = SimpleParser.parseStatement(
217
+ `{__COVER("${point.hash}")};`,
218
+ true,
219
+ );
220
+ replacer.visit(coverStmt);
221
+ coverStmt.statements.push(ifTrue);
222
+ node.ifTrue = coverStmt;
223
+ this.globalStatements.push(registerStmt);
224
+ visitIfTrue = true;
225
+ visitIfFalse = !!ifFalse;
226
+ }
227
+ if (ifFalse && ifFalse.kind !== 30) {
228
+ const falseLc = getLineCol(ifFalse);
229
+ const point = new CoverPoint();
230
+ point.line = falseLc?.line;
231
+ point.column = falseLc?.column;
232
+ point.file = path;
233
+ point.type = CoverType.Expression;
234
+ point.hash = hash(point);
235
+ const replacer = new RangeTransform(ifTrue);
236
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
228
237
  file: "${point.file}",
229
238
  hash: "${point.hash}",
230
239
  line: ${point.line},
@@ -232,51 +241,50 @@ export class CoverageTransform extends BaseVisitor {
232
241
  type: "Expression",
233
242
  executed: false
234
243
  })`);
235
- replacer.visit(registerStmt);
236
- const coverStmt = SimpleParser.parseStatement(`{__COVER("${point.hash}")};`, true);
237
- replacer.visit(coverStmt);
238
- coverStmt.statements.push(ifFalse);
239
- node.ifFalse = coverStmt;
240
- this.globalStatements.push(registerStmt);
241
- visitIfTrue = true;
242
- visitIfFalse = true;
243
- }
244
- if (visitIfTrue || visitIfFalse) {
245
- if (visitIfTrue) {
246
- if (ifTrue.visited)
247
- return;
248
- ifTrue.visited = true;
249
- this._visit(ifTrue);
250
- }
251
- if (visitIfFalse) {
252
- if (ifFalse.visited)
253
- return;
254
- ifFalse.visited = true;
255
- this._visit(ifFalse);
256
- }
257
- }
258
- else {
259
- super.visitIfStatement(node);
260
- }
244
+ replacer.visit(registerStmt);
245
+ const coverStmt = SimpleParser.parseStatement(
246
+ `{__COVER("${point.hash}")};`,
247
+ true,
248
+ );
249
+ replacer.visit(coverStmt);
250
+ coverStmt.statements.push(ifFalse);
251
+ node.ifFalse = coverStmt;
252
+ this.globalStatements.push(registerStmt);
253
+ visitIfTrue = true;
254
+ visitIfFalse = true;
255
+ }
256
+ if (visitIfTrue || visitIfFalse) {
257
+ if (visitIfTrue) {
258
+ if (ifTrue.visited) return;
259
+ ifTrue.visited = true;
260
+ this._visit(ifTrue);
261
+ }
262
+ if (visitIfFalse) {
263
+ if (ifFalse.visited) return;
264
+ ifFalse.visited = true;
265
+ this._visit(ifFalse);
266
+ }
267
+ } else {
268
+ super.visitIfStatement(node);
261
269
  }
262
- visitTernaryExpression(node) {
263
- if (node.visited)
264
- return;
265
- node.visited = true;
266
- super.visitTernaryExpression(node);
267
- const trueExpression = node.ifThen;
268
- const falseExpression = node.ifElse;
269
- const path = node.range.source.normalizedPath;
270
- {
271
- const trueLc = getLineCol(trueExpression);
272
- const point = new CoverPoint();
273
- point.line = trueLc?.line;
274
- point.column = trueLc?.column;
275
- point.file = path;
276
- point.type = CoverType.Expression;
277
- point.hash = hash(point);
278
- const replacer = new RangeTransform(trueExpression);
279
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
270
+ }
271
+ visitTernaryExpression(node) {
272
+ if (node.visited) return;
273
+ node.visited = true;
274
+ super.visitTernaryExpression(node);
275
+ const trueExpression = node.ifThen;
276
+ const falseExpression = node.ifElse;
277
+ const path = node.range.source.normalizedPath;
278
+ {
279
+ const trueLc = getLineCol(trueExpression);
280
+ const point = new CoverPoint();
281
+ point.line = trueLc?.line;
282
+ point.column = trueLc?.column;
283
+ point.file = path;
284
+ point.type = CoverType.Expression;
285
+ point.hash = hash(point);
286
+ const replacer = new RangeTransform(trueExpression);
287
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
280
288
  file: "${point.file}",
281
289
  hash: "${point.hash}",
282
290
  line: ${point.line},
@@ -284,24 +292,25 @@ export class CoverageTransform extends BaseVisitor {
284
292
  type: "Expression",
285
293
  executed: false
286
294
  })`);
287
- replacer.visit(registerStmt);
288
- const coverExpression = SimpleParser.parseExpression(`(__COVER("${point.hash}"), $$REPLACE_ME)`);
289
- replacer.visit(coverExpression);
290
- coverExpression.expression.expressions[1] =
291
- trueExpression;
292
- node.ifThen = coverExpression;
293
- this.globalStatements.push(registerStmt);
294
- }
295
- {
296
- const falseLc = getLineCol(falseExpression);
297
- const point = new CoverPoint();
298
- point.line = falseLc?.line;
299
- point.column = falseLc?.column;
300
- point.file = path;
301
- point.type = CoverType.Expression;
302
- point.hash = hash(point);
303
- const replacer = new RangeTransform(falseExpression);
304
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
295
+ replacer.visit(registerStmt);
296
+ const coverExpression = SimpleParser.parseExpression(
297
+ `(__COVER("${point.hash}"), $$REPLACE_ME)`,
298
+ );
299
+ replacer.visit(coverExpression);
300
+ coverExpression.expression.expressions[1] = trueExpression;
301
+ node.ifThen = coverExpression;
302
+ this.globalStatements.push(registerStmt);
303
+ }
304
+ {
305
+ const falseLc = getLineCol(falseExpression);
306
+ const point = new CoverPoint();
307
+ point.line = falseLc?.line;
308
+ point.column = falseLc?.column;
309
+ point.file = path;
310
+ point.type = CoverType.Expression;
311
+ point.hash = hash(point);
312
+ const replacer = new RangeTransform(falseExpression);
313
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
305
314
  file: "${point.file}",
306
315
  hash: "${point.hash}",
307
316
  line: ${point.line},
@@ -309,29 +318,29 @@ export class CoverageTransform extends BaseVisitor {
309
318
  type: "Expression",
310
319
  executed: false
311
320
  })`);
312
- replacer.visit(registerStmt);
313
- const coverExpression = SimpleParser.parseExpression(`(__COVER("${point.hash}"), $$REPLACE_ME)`);
314
- replacer.visit(coverExpression);
315
- coverExpression.expression.expressions[1] =
316
- falseExpression;
317
- node.ifElse = coverExpression;
318
- this.globalStatements.push(registerStmt);
319
- }
321
+ replacer.visit(registerStmt);
322
+ const coverExpression = SimpleParser.parseExpression(
323
+ `(__COVER("${point.hash}"), $$REPLACE_ME)`,
324
+ );
325
+ replacer.visit(coverExpression);
326
+ coverExpression.expression.expressions[1] = falseExpression;
327
+ node.ifElse = coverExpression;
328
+ this.globalStatements.push(registerStmt);
320
329
  }
321
- visitSwitchCase(node) {
322
- if (node.visited)
323
- return;
324
- node.visited = true;
325
- const path = node.range.source.normalizedPath;
326
- const caseLc = getLineCol(node);
327
- const point = new CoverPoint();
328
- point.line = caseLc?.line;
329
- point.column = caseLc?.column;
330
- point.file = path;
331
- point.type = CoverType.Block;
332
- point.hash = hash(point);
333
- const replacer = new RangeTransform(node);
334
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
330
+ }
331
+ visitSwitchCase(node) {
332
+ if (node.visited) return;
333
+ node.visited = true;
334
+ const path = node.range.source.normalizedPath;
335
+ const caseLc = getLineCol(node);
336
+ const point = new CoverPoint();
337
+ point.line = caseLc?.line;
338
+ point.column = caseLc?.column;
339
+ point.file = path;
340
+ point.type = CoverType.Block;
341
+ point.hash = hash(point);
342
+ const replacer = new RangeTransform(node);
343
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
335
344
  file: "${point.file}",
336
345
  hash: "${point.hash}",
337
346
  line: ${point.line},
@@ -339,27 +348,26 @@ export class CoverageTransform extends BaseVisitor {
339
348
  type: "Block",
340
349
  executed: false
341
350
  })`);
342
- replacer.visit(registerStmt);
343
- const coverStmt = SimpleParser.parseStatement(`__COVER("${point.hash}")`);
344
- replacer.visit(coverStmt);
345
- this.globalStatements.push(registerStmt);
346
- super.visitSwitchCase(node);
347
- node.statements.unshift(coverStmt);
348
- }
349
- visitBlockStatement(node) {
350
- if (node.visited)
351
- return;
352
- node.visited = true;
353
- const path = node.range.source.normalizedPath;
354
- const blockLc = getLineCol(node);
355
- const point = new CoverPoint();
356
- point.line = blockLc?.line;
357
- point.column = blockLc?.column;
358
- point.file = path;
359
- point.type = CoverType.Block;
360
- point.hash = hash(point);
361
- const replacer = new RangeTransform(node);
362
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
351
+ replacer.visit(registerStmt);
352
+ const coverStmt = SimpleParser.parseStatement(`__COVER("${point.hash}")`);
353
+ replacer.visit(coverStmt);
354
+ this.globalStatements.push(registerStmt);
355
+ super.visitSwitchCase(node);
356
+ node.statements.unshift(coverStmt);
357
+ }
358
+ visitBlockStatement(node) {
359
+ if (node.visited) return;
360
+ node.visited = true;
361
+ const path = node.range.source.normalizedPath;
362
+ const blockLc = getLineCol(node);
363
+ const point = new CoverPoint();
364
+ point.line = blockLc?.line;
365
+ point.column = blockLc?.column;
366
+ point.file = path;
367
+ point.type = CoverType.Block;
368
+ point.hash = hash(point);
369
+ const replacer = new RangeTransform(node);
370
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
363
371
  file: "${point.file}",
364
372
  hash: "${point.hash}",
365
373
  line: ${point.line},
@@ -367,51 +375,49 @@ export class CoverageTransform extends BaseVisitor {
367
375
  type: "Block",
368
376
  executed: false
369
377
  })`);
370
- replacer.visit(registerStmt);
371
- const coverStmt = SimpleParser.parseStatement(`__COVER("${point.hash}")`);
372
- replacer.visit(coverStmt);
373
- this.globalStatements.push(registerStmt);
374
- super.visitBlockStatement(node);
375
- node.statements.unshift(coverStmt);
376
- }
377
- visitSource(node) {
378
- if (node.isLibrary)
379
- return;
380
- if (node.simplePath === "coverage")
381
- return;
382
- if (isStdlib(node))
383
- return;
384
- super.visitSource(node);
385
- }
378
+ replacer.visit(registerStmt);
379
+ const coverStmt = SimpleParser.parseStatement(`__COVER("${point.hash}")`);
380
+ replacer.visit(coverStmt);
381
+ this.globalStatements.push(registerStmt);
382
+ super.visitBlockStatement(node);
383
+ node.statements.unshift(coverStmt);
384
+ }
385
+ visitSource(node) {
386
+ if (node.isLibrary) return;
387
+ if (node.simplePath === "coverage") return;
388
+ if (isStdlib(node)) return;
389
+ super.visitSource(node);
390
+ }
386
391
  }
387
392
  function djb2Hash(str) {
388
- const points = Array.from(str);
389
- let h = 5381;
390
- for (let p = 0; p < points.length; p++)
391
- h = ((h << 5) - h + points[p].codePointAt(0)) | 0;
392
- return h;
393
+ const points = Array.from(str);
394
+ let h = 5381;
395
+ for (let p = 0; p < points.length; p++)
396
+ h = ((h << 5) - h + points[p].codePointAt(0)) | 0;
397
+ return h;
393
398
  }
394
399
  function hash(point) {
395
- const hsh = djb2Hash(point.file +
396
- point.line.toString() +
397
- point.column.toString() +
398
- point.type.toString());
399
- if (hsh < 0) {
400
- const out = hsh.toString(16);
401
- return "3" + out.slice(1);
402
- }
403
- else {
404
- return hsh.toString(16);
405
- }
400
+ const hsh = djb2Hash(
401
+ point.file +
402
+ point.line.toString() +
403
+ point.column.toString() +
404
+ point.type.toString(),
405
+ );
406
+ if (hsh < 0) {
407
+ const out = hsh.toString(16);
408
+ return "3" + out.slice(1);
409
+ } else {
410
+ return hsh.toString(16);
411
+ }
406
412
  }
407
413
  class LineColumn {
408
- line;
409
- column;
414
+ line;
415
+ column;
410
416
  }
411
417
  function getLineCol(node) {
412
- return {
413
- line: node.range.source.lineAt(node.range.start),
414
- column: node.range.source.columnAt(),
415
- };
418
+ return {
419
+ line: node.range.source.lineAt(node.range.start),
420
+ column: node.range.source.columnAt(),
421
+ };
416
422
  }
417
- //# sourceMappingURL=coverage.js.map
423
+ //# sourceMappingURL=coverage.js.map