[gjs/wip/ptomato/develop] coverage: Walk AST in more cases
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/develop] coverage: Walk AST in more cases
- Date: Sat, 23 Sep 2017 07:05:32 +0000 (UTC)
commit 80613a5dd62618376fb13ca1a7ba2a364bc22e45
Author: Philip Chimento <philip chimento gmail com>
Date: Fri Sep 22 23:08:01 2017 -0700
coverage: Walk AST in more cases
- Labeled statements (the string constant was misspelled)
- The switch expression of a switch-case statement
- Default parameters to a function
installed-tests/js/testCoverage.js | 31 +++++++++++++++++++++++++++++++
modules/_bootstrap/coverage.js | 9 +++++----
2 files changed, 36 insertions(+), 4 deletions(-)
---
diff --git a/installed-tests/js/testCoverage.js b/installed-tests/js/testCoverage.js
index a5fb2bf..f2b723c 100644
--- a/installed-tests/js/testCoverage.js
+++ b/installed-tests/js/testCoverage.js
@@ -527,6 +527,37 @@ describe('Coverage.functionsForAST', function () {
{ key: '(anonymous):2:1', line: 2, n_params: 1 },
],
],
+
+ 'finds functions inside labeled statement': [
+ `loop:
+ for (function () {}; ; ) {}`,
+ [
+ { key: '(anonymous):2:0', line: 2, n_params: 0 },
+ ],
+ ],
+
+ 'finds functions inside switch expression': [
+ 'switch (function () {}) {}',
+ [
+ { key: '(anonymous):1:0', line: 1, n_params: 0 },
+ ],
+ ],
+
+ 'finds functions inside function default arguments': [
+ 'function foo(bar=function () {}) {}',
+ [
+ { key: 'foo:1:1', line: 1, n_params: 1 },
+ { key: '(anonymous):1:0', line: 1, n_params: 0 },
+ ],
+ ],
+
+ 'finds functions inside function expression default arguments': [
+ 'void function foo(bar=function () {}) {}',
+ [
+ { key: 'foo:1:1', line: 1, n_params: 1 },
+ { key: '(anonymous):1:0', line: 1, n_params: 0 },
+ ],
+ ],
};
Object.keys(testTable).forEach(testcase => {
diff --git a/modules/_bootstrap/coverage.js b/modules/_bootstrap/coverage.js
index ec3a4b4..bfe12ef 100644
--- a/modules/_bootstrap/coverage.js
+++ b/modules/_bootstrap/coverage.js
@@ -26,10 +26,8 @@ function getSubNodesForNode(node) {
let subNodes = [];
switch (node.type) {
/* These statements have a single body */
- case 'LabelledStatement':
+ case 'LabeledStatement':
case 'WithStatement':
- case 'FunctionDeclaration':
- case 'FunctionExpression':
case 'CatchClause':
case 'ClassMethod':
subNodes.push(node.body);
@@ -95,8 +93,10 @@ function getSubNodesForNode(node) {
subNodes.push(elem);
});
break;
+ case 'FunctionDeclaration':
+ case 'FunctionExpression':
case 'ArrowFunctionExpression':
- Array.prototype.push.apply(subNodes, node.defaults);
+ subNodes.push(...node.defaults);
subNodes.push(node.body);
break;
case 'SequenceExpression':
@@ -142,6 +142,7 @@ function getSubNodesForNode(node) {
subNodes.push(node.finalizer);
break;
case 'SwitchStatement':
+ subNodes.push(node.discriminant);
for (let caseClause of node.cases) {
caseClause.consequent.forEach(function(expression) {
subNodes.push(expression);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]