esprima 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/lib/esprima/ast.rb +24 -0
- data/lib/esprima/version.rb +1 -1
- data/spec/ast_spec.rb +16 -0
- metadata +9 -3
data/History.txt
CHANGED
data/lib/esprima/ast.rb
CHANGED
@@ -37,8 +37,32 @@ module Esprima
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
def each_raw
|
41
|
+
if block_given?
|
42
|
+
each_raw_node(tree) { |node| yield node }
|
43
|
+
else
|
44
|
+
nodes = []
|
45
|
+
each_raw_node(tree) { |node| nodes << node }
|
46
|
+
nodes.to_enum
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
40
50
|
protected
|
41
51
|
|
52
|
+
def each_raw_node(subtree)
|
53
|
+
if subtree.is_a?(Array)
|
54
|
+
subtree.each do |t|
|
55
|
+
yield t if yieldable?(t)
|
56
|
+
each_raw_node(t) { |sub_t| yield sub_t if yieldable?(sub_t) }
|
57
|
+
end
|
58
|
+
elsif subtree.is_a?(Hash)
|
59
|
+
subtree.each_pair do |_, t|
|
60
|
+
yield t if yieldable?(t)
|
61
|
+
each_raw_node(t) { |sub_t| yield sub_t if yieldable?(sub_t) }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
42
66
|
def each_node
|
43
67
|
if tree.is_a?(Array)
|
44
68
|
tree.each do |t|
|
data/lib/esprima/version.rb
CHANGED
data/spec/ast_spec.rb
CHANGED
@@ -49,6 +49,22 @@ describe Esprima::AST do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
describe "#each_raw" do
|
53
|
+
it "yields arrays and hashes if a block is given" do
|
54
|
+
@ast.each_raw { |a| [Hash, Array].should include(a.class) }
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns an ast made up of arrays and hashes" do
|
58
|
+
result = @ast.each_raw.to_a
|
59
|
+
result.size.should == 5
|
60
|
+
result.should include(AST)
|
61
|
+
result.should include(AST.first)
|
62
|
+
result.should include(AST.first[:expression])
|
63
|
+
result.should include(AST.first[:expression][:left])
|
64
|
+
result.should include(AST.first[:expression][:right])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
52
68
|
describe "#[]" do
|
53
69
|
it "allows access to the internal tree with [] syntax" do
|
54
70
|
@ast[:body][0][:type].should == "ExpressionStatement"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esprima
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-04-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: execjs
|
@@ -144,15 +144,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
144
|
- - ! '>='
|
145
145
|
- !ruby/object:Gem::Version
|
146
146
|
version: '0'
|
147
|
+
segments:
|
148
|
+
- 0
|
149
|
+
hash: 926408375024729005
|
147
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
151
|
none: false
|
149
152
|
requirements:
|
150
153
|
- - ! '>='
|
151
154
|
- !ruby/object:Gem::Version
|
152
155
|
version: '0'
|
156
|
+
segments:
|
157
|
+
- 0
|
158
|
+
hash: 926408375024729005
|
153
159
|
requirements: []
|
154
160
|
rubyforge_project:
|
155
|
-
rubygems_version: 1.8.
|
161
|
+
rubygems_version: 1.8.25
|
156
162
|
signing_key:
|
157
163
|
specification_version: 3
|
158
164
|
summary: Ruby wrapper around the Esprima static code analyzer for JavaScript.
|