Skip to content

Commit cfec15c

Browse files
committed
Fix analysis of function expressions
1 parent 08ec447 commit cfec15c

4 files changed

Lines changed: 151 additions & 6 deletions

File tree

lib/node_modules/@stdlib/_tools/js/program-summary/lib/analyze.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ function analyze( results, ast, src, lines, scope, opts ) {
9090
results[ key ].data.push( res );
9191
continue;
9292
}
93+
// Wrap the function body in a parseable function wrapper (note: does not affect analysis as we isolate the function body below):
94+
str = 'function __anon__() {' + str + '}';
9395
} else {
9496
str = src.substring( node.start, node.end );
9597
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
f = function ( x, y ) {
2+
return x + y;
3+
};
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
{
2+
"length": 42,
3+
"lines": 4,
4+
"empty": 1,
5+
"sloc": 2,
6+
"lloc": 2,
7+
"scope": 0,
8+
"comments": {
9+
"count": 0,
10+
"length": 0,
11+
"lines": 0,
12+
"inline": 0,
13+
"block": {
14+
"count": 0,
15+
"length": 0,
16+
"lines": 0,
17+
"inline": 0,
18+
"jsdoc": {
19+
"count": 0,
20+
"length": 0,
21+
"lines": 0,
22+
"inline": 0
23+
}
24+
},
25+
"line": {
26+
"count": 0,
27+
"length": 0,
28+
"lines": 0,
29+
"inline": 0
30+
}
31+
},
32+
"statements": 2,
33+
"branches": 0,
34+
"if": {
35+
"count": 0,
36+
"data": []
37+
},
38+
"switch": {
39+
"count": 0,
40+
"data": []
41+
},
42+
"throw": 0,
43+
"try": {
44+
"count": 0,
45+
"data": []
46+
},
47+
"while": {
48+
"count": 0,
49+
"data": []
50+
},
51+
"dowhile": {
52+
"count": 0,
53+
"data": []
54+
},
55+
"for": {
56+
"count": 0,
57+
"data": []
58+
},
59+
"forin": {
60+
"count": 0,
61+
"data": []
62+
},
63+
"var": 0,
64+
"function": {
65+
"count": 1,
66+
"data": [
67+
{
68+
"length": 38,
69+
"lines": 3,
70+
"empty": 0,
71+
"sloc": 1,
72+
"lloc": 1,
73+
"scope": 0,
74+
"comments": {
75+
"count": 0,
76+
"length": 0,
77+
"lines": 0,
78+
"inline": 0,
79+
"block": {
80+
"count": 0,
81+
"length": 0,
82+
"lines": 0,
83+
"inline": 0,
84+
"jsdoc": {
85+
"count": 0,
86+
"length": 0,
87+
"lines": 0,
88+
"inline": 0
89+
}
90+
},
91+
"line": {
92+
"count": 0,
93+
"length": 0,
94+
"lines": 0,
95+
"inline": 0
96+
}
97+
},
98+
"statements": 1,
99+
"branches": 0,
100+
"if": {
101+
"count": 0,
102+
"data": []
103+
},
104+
"switch": {
105+
"count": 0,
106+
"data": []
107+
},
108+
"throw": 0,
109+
"try": {
110+
"count": 0,
111+
"data": []
112+
},
113+
"while": {
114+
"count": 0,
115+
"data": []
116+
},
117+
"dowhile": {
118+
"count": 0,
119+
"data": []
120+
},
121+
"for": {
122+
"count": 0,
123+
"data": []
124+
},
125+
"forin": {
126+
"count": 0,
127+
"data": []
128+
},
129+
"var": 0,
130+
"function": {
131+
"count": 0,
132+
"data": []
133+
},
134+
"type": "expression",
135+
"name": "(anonymous)",
136+
"params": 2
137+
}
138+
]
139+
}
140+
}

lib/node_modules/@stdlib/_tools/js/program-summary/test/fixtures/iife.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@
6565
"count": 1,
6666
"data": [
6767
{
68-
"length": 13,
69-
"lines": 1,
70-
"empty": 2,
71-
"sloc": 0,
72-
"lloc": 0,
68+
"length": 38,
69+
"lines": 3,
70+
"empty": 0,
71+
"sloc": 1,
72+
"lloc": 1,
7373
"scope": 0,
7474
"comments": {
7575
"count": 0,
@@ -95,7 +95,7 @@
9595
"inline": 0
9696
}
9797
},
98-
"statements": 0,
98+
"statements": 1,
9999
"branches": 0,
100100
"if": {
101101
"count": 0,

0 commit comments

Comments
 (0)