jcov 1.0.1 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,305 @@
1
+ // AST walker module for Mozilla Parser API compatible trees
2
+
3
+ (function(exports) {
4
+ "use strict";
5
+
6
+ // A simple walk is one where you simply specify callbacks to be
7
+ // called on specific nodes. The last two arguments are optional. A
8
+ // simple use would be
9
+ //
10
+ // walk.simple(myTree, {
11
+ // Expression: function(node) { ... }
12
+ // });
13
+ //
14
+ // to do something with all expressions. All Parser API node types
15
+ // can be used to identify node types, as well as Expression,
16
+ // Statement, and ScopeBody, which denote categories of nodes.
17
+ //
18
+ // The base argument can be used to pass a custom (recursive)
19
+ // walker, and state can be used to give this walked an initial
20
+ // state.
21
+ exports.simple = function(node, visitors, base, state) {
22
+ if (!base) base = exports.base;
23
+ function c(node, st, override) {
24
+ var type = override || node.type, found = visitors[type];
25
+ base[type](node, st, c);
26
+ if (found) found(node, st);
27
+ }
28
+ c(node, state);
29
+ };
30
+
31
+ // A recursive walk is one where your functions override the default
32
+ // walkers. They can modify and replace the state parameter that's
33
+ // threaded through the walk, and can opt how and whether to walk
34
+ // their child nodes (by calling their third argument on these
35
+ // nodes).
36
+ exports.recursive = function(node, state, funcs, base) {
37
+ var visitor = funcs ? exports.make(funcs, base) : base;
38
+ function c(node, st, override) {
39
+ visitor[override || node.type](node, st, c);
40
+ }
41
+ c(node, state);
42
+ };
43
+
44
+ function makeTest(test) {
45
+ if (typeof test == "string")
46
+ return function(type) { return type == test; };
47
+ else if (!test)
48
+ return function() { return true; };
49
+ else
50
+ return test;
51
+ }
52
+
53
+ function Found(node, state) { this.node = node; this.state = state; }
54
+
55
+ // Find a node with a given start, end, and type (all are optional,
56
+ // null can be used as wildcard). Returns a {node, state} object, or
57
+ // undefined when it doesn't find a matching node.
58
+ exports.findNodeAt = function(node, start, end, test, base, state) {
59
+ test = makeTest(test);
60
+ try {
61
+ if (!base) base = exports.base;
62
+ var c = function(node, st, override) {
63
+ var type = override || node.type;
64
+ if ((start == null || node.start <= start) &&
65
+ (end == null || node.end >= end))
66
+ base[type](node, st, c);
67
+ if (test(type, node) &&
68
+ (start == null || node.start == start) &&
69
+ (end == null || node.end == end))
70
+ throw new Found(node, st);
71
+ };
72
+ c(node, state);
73
+ } catch (e) {
74
+ if (e instanceof Found) return e;
75
+ throw e;
76
+ }
77
+ };
78
+
79
+ // Find the innermost node of a given type that contains the given
80
+ // position. Interface similar to findNodeAt.
81
+ exports.findNodeAround = function(node, pos, test, base, state) {
82
+ test = makeTest(test);
83
+ try {
84
+ if (!base) base = exports.base;
85
+ var c = function(node, st, override) {
86
+ var type = override || node.type;
87
+ if (node.start > pos || node.end < pos) return;
88
+ base[type](node, st, c);
89
+ if (test(type, node)) throw new Found(node, st);
90
+ };
91
+ c(node, state);
92
+ } catch (e) {
93
+ if (e instanceof Found) return e;
94
+ throw e;
95
+ }
96
+ };
97
+
98
+ // Find the outermost matching node after a given position.
99
+ exports.findNodeAfter = function(node, pos, test, base, state) {
100
+ test = makeTest(test);
101
+ try {
102
+ if (!base) base = exports.base;
103
+ var c = function(node, st, override) {
104
+ if (node.end < pos) return;
105
+ var type = override || node.type;
106
+ if (node.start >= pos && test(type, node)) throw new Found(node, st);
107
+ base[type](node, st, c);
108
+ };
109
+ c(node, state);
110
+ } catch (e) {
111
+ if (e instanceof Found) return e;
112
+ throw e;
113
+ }
114
+ };
115
+
116
+ // Find the outermost matching node before a given position.
117
+ exports.findNodeBefore = function(node, pos, test, base, state) {
118
+ test = makeTest(test);
119
+ if (!base) base = exports.base;
120
+ var max;
121
+ var c = function(node, st, override) {
122
+ if (node.start > pos) return;
123
+ var type = override || node.type;
124
+ if (node.end <= pos && (!max || max.node.end < node.end) && test(type, node))
125
+ max = new Found(node, st);
126
+ base[type](node, st, c);
127
+ };
128
+ c(node, state);
129
+ return max;
130
+ };
131
+
132
+ // Used to create a custom walker. Will fill in all missing node
133
+ // type properties with the defaults.
134
+ exports.make = function(funcs, base) {
135
+ if (!base) base = exports.base;
136
+ var visitor = {};
137
+ for (var type in base) visitor[type] = base[type];
138
+ for (var type in funcs) visitor[type] = funcs[type];
139
+ return visitor;
140
+ };
141
+
142
+ function skipThrough(node, st, c) { c(node, st); }
143
+ function ignore(node, st, c) {}
144
+
145
+ // Node walkers.
146
+
147
+ var base = exports.base = {};
148
+ base.Program = base.BlockStatement = function(node, st, c) {
149
+ for (var i = 0; i < node.body.length; ++i)
150
+ c(node.body[i], st, "Statement");
151
+ };
152
+ base.Statement = skipThrough;
153
+ base.EmptyStatement = ignore;
154
+ base.ExpressionStatement = function(node, st, c) {
155
+ c(node.expression, st, "Expression");
156
+ };
157
+ base.IfStatement = function(node, st, c) {
158
+ c(node.test, st, "Expression");
159
+ c(node.consequent, st, "Statement");
160
+ if (node.alternate) c(node.alternate, st, "Statement");
161
+ };
162
+ base.LabeledStatement = function(node, st, c) {
163
+ c(node.body, st, "Statement");
164
+ };
165
+ base.BreakStatement = base.ContinueStatement = ignore;
166
+ base.WithStatement = function(node, st, c) {
167
+ c(node.object, st, "Expression");
168
+ c(node.body, st, "Statement");
169
+ };
170
+ base.SwitchStatement = function(node, st, c) {
171
+ c(node.discriminant, st, "Expression");
172
+ for (var i = 0; i < node.cases.length; ++i) {
173
+ var cs = node.cases[i];
174
+ if (cs.test) c(cs.test, st, "Expression");
175
+ for (var j = 0; j < cs.consequent.length; ++j)
176
+ c(cs.consequent[j], st, "Statement");
177
+ }
178
+ };
179
+ base.ReturnStatement = function(node, st, c) {
180
+ if (node.argument) c(node.argument, st, "Expression");
181
+ };
182
+ base.ThrowStatement = function(node, st, c) {
183
+ c(node.argument, st, "Expression");
184
+ };
185
+ base.TryStatement = function(node, st, c) {
186
+ c(node.block, st, "Statement");
187
+ for (var i = 0; i < node.handlers.length; ++i)
188
+ c(node.handlers[i].body, st, "ScopeBody");
189
+ if (node.finalizer) c(node.finalizer, st, "Statement");
190
+ };
191
+ base.WhileStatement = function(node, st, c) {
192
+ c(node.test, st, "Expression");
193
+ c(node.body, st, "Statement");
194
+ };
195
+ base.DoWhileStatement = base.WhileStatement;
196
+ base.ForStatement = function(node, st, c) {
197
+ if (node.init) c(node.init, st, "ForInit");
198
+ if (node.test) c(node.test, st, "Expression");
199
+ if (node.update) c(node.update, st, "Expression");
200
+ c(node.body, st, "Statement");
201
+ };
202
+ base.ForInStatement = function(node, st, c) {
203
+ c(node.left, st, "ForInit");
204
+ c(node.right, st, "Expression");
205
+ c(node.body, st, "Statement");
206
+ };
207
+ base.ForInit = function(node, st, c) {
208
+ if (node.type == "VariableDeclaration") c(node, st);
209
+ else c(node, st, "Expression");
210
+ };
211
+ base.DebuggerStatement = ignore;
212
+
213
+ base.FunctionDeclaration = function(node, st, c) {
214
+ c(node, st, "Function");
215
+ };
216
+ base.VariableDeclaration = function(node, st, c) {
217
+ for (var i = 0; i < node.declarations.length; ++i) {
218
+ var decl = node.declarations[i];
219
+ if (decl.init) c(decl.init, st, "Expression");
220
+ }
221
+ };
222
+
223
+ base.Function = function(node, st, c) {
224
+ c(node.body, st, "ScopeBody");
225
+ };
226
+ base.ScopeBody = function(node, st, c) {
227
+ c(node, st, "Statement");
228
+ };
229
+
230
+ base.Expression = skipThrough;
231
+ base.ThisExpression = ignore;
232
+ base.ArrayExpression = function(node, st, c) {
233
+ for (var i = 0; i < node.elements.length; ++i) {
234
+ var elt = node.elements[i];
235
+ if (elt) c(elt, st, "Expression");
236
+ }
237
+ };
238
+ base.ObjectExpression = function(node, st, c) {
239
+ for (var i = 0; i < node.properties.length; ++i)
240
+ c(node.properties[i].value, st, "Expression");
241
+ };
242
+ base.FunctionExpression = base.FunctionDeclaration;
243
+ base.SequenceExpression = function(node, st, c) {
244
+ for (var i = 0; i < node.expressions.length; ++i)
245
+ c(node.expressions[i], st, "Expression");
246
+ };
247
+ base.UnaryExpression = base.UpdateExpression = function(node, st, c) {
248
+ c(node.argument, st, "Expression");
249
+ };
250
+ base.BinaryExpression = base.AssignmentExpression = base.LogicalExpression = function(node, st, c) {
251
+ c(node.left, st, "Expression");
252
+ c(node.right, st, "Expression");
253
+ };
254
+ base.ConditionalExpression = function(node, st, c) {
255
+ c(node.test, st, "Expression");
256
+ c(node.consequent, st, "Expression");
257
+ c(node.alternate, st, "Expression");
258
+ };
259
+ base.NewExpression = base.CallExpression = function(node, st, c) {
260
+ c(node.callee, st, "Expression");
261
+ if (node.arguments) for (var i = 0; i < node.arguments.length; ++i)
262
+ c(node.arguments[i], st, "Expression");
263
+ };
264
+ base.MemberExpression = function(node, st, c) {
265
+ c(node.object, st, "Expression");
266
+ if (node.computed) c(node.property, st, "Expression");
267
+ };
268
+ base.Identifier = base.Literal = ignore;
269
+
270
+ // A custom walker that keeps track of the scope chain and the
271
+ // variables defined in it.
272
+ function makeScope(prev) {
273
+ return {vars: Object.create(null), prev: prev};
274
+ }
275
+ exports.scopeVisitor = exports.make({
276
+ Function: function(node, scope, c) {
277
+ var inner = makeScope(scope);
278
+ for (var i = 0; i < node.params.length; ++i)
279
+ inner.vars[node.params[i].name] = {type: "argument", node: node.params[i]};
280
+ if (node.id) {
281
+ var decl = node.type == "FunctionDeclaration";
282
+ (decl ? scope : inner).vars[node.id.name] =
283
+ {type: decl ? "function" : "function name", node: node.id};
284
+ }
285
+ c(node.body, inner, "ScopeBody");
286
+ },
287
+ TryStatement: function(node, scope, c) {
288
+ c(node.block, scope, "Statement");
289
+ for (var i = 0; i < node.handlers.length; ++i) {
290
+ var handler = node.handlers[i], inner = makeScope(scope);
291
+ inner.vars[handler.param.name] = {type: "catch clause", node: handler.param};
292
+ c(handler.body, inner, "ScopeBody");
293
+ }
294
+ if (node.finalizer) c(node.finalizer, scope, "Statement");
295
+ },
296
+ VariableDeclaration: function(node, scope, c) {
297
+ for (var i = 0; i < node.declarations.length; ++i) {
298
+ var decl = node.declarations[i];
299
+ scope.vars[decl.id.name] = {type: "var", node: decl.id};
300
+ if (decl.init) c(decl.init, scope, "Expression");
301
+ }
302
+ }
303
+ });
304
+
305
+ })(typeof exports == "undefined" ? acorn.walk = {} : exports);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jcov
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: '1.1'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-10 00:00:00.000000000 Z
12
+ date: 2013-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: commander
@@ -43,22 +43,6 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: 0.11.1
46
- - !ruby/object:Gem::Dependency
47
- name: rkelly
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: 1.0.4
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 1.0.4
62
46
  - !ruby/object:Gem::Dependency
63
47
  name: cucumber
64
48
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +93,7 @@ dependencies:
109
93
  version: 1.1.1
110
94
  description: Javascript Coverage Tool
111
95
  email:
112
- - dmcinnes@yp.com
96
+ - doug@dougmcinnes.com
113
97
  executables:
114
98
  - jcov
115
99
  extensions: []
@@ -141,6 +125,7 @@ files:
141
125
  - features/configuration.feature
142
126
  - features/coverage.feature
143
127
  - features/html_report.feature
128
+ - features/instrumentation.feature
144
129
  - features/javascript_interface.feature
145
130
  - features/reporting.feature
146
131
  - features/run.feature
@@ -150,7 +135,13 @@ files:
150
135
  - lib/jcov.rb
151
136
  - lib/jcov/commands.rb
152
137
  - lib/jcov/configuration.rb
138
+ - lib/jcov/context.rb
139
+ - lib/jcov/context/instrumentation_context.rb
140
+ - lib/jcov/context/run_context.rb
153
141
  - lib/jcov/coverage.rb
142
+ - lib/jcov/errors.rb
143
+ - lib/jcov/js/parser.js
144
+ - lib/jcov/loader.rb
154
145
  - lib/jcov/reporter.rb
155
146
  - lib/jcov/reporter/console_reporter.rb
156
147
  - lib/jcov/reporter/file.html.erb
@@ -159,6 +150,8 @@ files:
159
150
  - lib/jcov/reporter/report.html.erb
160
151
  - lib/jcov/runner.rb
161
152
  - lib/jcov/version.rb
153
+ - vendor/acorn.js
154
+ - vendor/walk.js
162
155
  homepage: ''
163
156
  licenses: []
164
157
  post_install_message:
@@ -187,6 +180,7 @@ test_files:
187
180
  - features/configuration.feature
188
181
  - features/coverage.feature
189
182
  - features/html_report.feature
183
+ - features/instrumentation.feature
190
184
  - features/javascript_interface.feature
191
185
  - features/reporting.feature
192
186
  - features/run.feature