jsinstrument 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  /* automatically generated by JSInstrument */
2
2
  /*
3
- * create __coverage__ object as a global variable
3
+ * create %{js_object_name} object as a global variable
4
4
  */
5
5
  !function(root){
6
6
  if (root && (typeof root.%{js_object_name} === 'undefined')) {
@@ -49,16 +49,15 @@ module JSInstrument
49
49
  ast.each do |node|
50
50
  parent = node.parent
51
51
  line = node.line
52
+ node_classname = node.class.name.split(/::/)[-1].sub('Node', '')
53
+ parent_classname = parent.class.name.split(/::/)[-1].sub('Node', '')
52
54
  # instrument only if we can get the line no. and we haven't instrumented it
53
55
  #
54
56
  if line and not instrumented_lines.member? line
55
- if ExpressionStatementNode === node or EmptyStatementNode === node or
56
- DoWhileNode === node or WhileNode === node or ForNode === node or
57
- ForInNode === node or ContinueNode === node or VarDeclNode === node or
58
- SwitchNode === node or BreakNode === node or ThrowNode === node or
59
- ReturnNode === node or IfNode === node or VarStatementNode === node
57
+ if node_classname in ['ExpressionStatement', 'EmptyStatement', 'DoWhile', 'While', 'For',
58
+ 'ForIn', 'Continue', 'VarDecl', 'Switch', 'Break', 'Throw', 'Return', 'If', 'VarStatement']
60
59
 
61
- if DoWhileNode === parent
60
+ if parent_classname == 'DoWhile'
62
61
  if parent.left.eql? node
63
62
  instrumented_lines.add line
64
63
  parent.left = get_inserted_block node
@@ -66,8 +65,7 @@ module JSInstrument
66
65
  # in RKelly, ConditionalNode extends IfNode
67
66
  # which is so annoying
68
67
  # I mean why they mix a expression and a statement?
69
- elsif (IfNode === parent and not ConditionalNode === parent) or
70
- WhileNode === parent or ForNode === parent or ForInNode === parent or WithNode === parent
68
+ elsif parent_classname in ['If', 'While', 'For', 'ForIn', 'With']
71
69
  if parent.value.eql? node
72
70
  instrumented_lines.add line
73
71
  parent.value = get_inserted_block node
@@ -75,20 +73,20 @@ module JSInstrument
75
73
  instrumented_lines.add line
76
74
  parent.else = get_inserted_block node
77
75
  end
78
- elsif CaseBlockNode === parent or LabelNode === parent
76
+ elsif parent_classname in ['CaseBlock', 'Label']
79
77
  # do nothing here
80
- elsif SourceElementsNode === parent
78
+ elsif parent_classname == 'SourceElements'
81
79
  if insert_func_before node
82
80
  instrumented_lines.add line
83
81
  end
84
82
  end
85
- elsif WithNode === node or TryNode === node
86
- if SourceElementsNode === parent
83
+ elsif node_classname in ['With', 'Try']
84
+ if parent_classname == 'SourceElements'
87
85
  if insert_func_before node
88
86
  instrumented_lines.add line
89
87
  end
90
88
  end
91
- elsif FunctionDeclNode === node or FunctionExprNode === node
89
+ elsif node_classname in ['FunctionDecl', 'FunctionExpr']
92
90
  if insert_func_before node
93
91
  instrumented_lines.add line
94
92
  end
@@ -1,3 +1,3 @@
1
1
  module JSInstrument
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -10,6 +10,7 @@ module RKelly
10
10
  ## define methods for traverse different kinds of nodes
11
11
  ## consts are from RKelly::Visitors::Visitor
12
12
 
13
+ # dont need to link the value for termianl nodes
13
14
  TERMINAL_NODES.each do |type|
14
15
  define_method(:"visit_#{type}Node") { |o| o.value }
15
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsinstrument
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
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-10-10 00:00:00.000000000 Z
12
+ date: 2013-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rkelly
@@ -68,7 +68,6 @@ extra_rdoc_files: []
68
68
  files:
69
69
  - .gitignore
70
70
  - Gemfile
71
- - LICENSE.txt
72
71
  - README.md
73
72
  - Rakefile
74
73
  - jsinstrument.gemspec
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2013 Mushan Yang
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.