esprima 1.2.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/History.txt +8 -0
- data/esprima.gemspec +2 -2
- data/lib/esprima.rb +18 -8
- data/lib/esprima/parser.rb +9 -3
- data/lib/esprima/version.rb +1 -1
- data/spec/parser_spec.rb +26 -0
- metadata +101 -75
data/Gemfile
CHANGED
data/History.txt
CHANGED
data/esprima.gemspec
CHANGED
@@ -13,9 +13,9 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.platform = Gem::Platform::RUBY
|
14
14
|
s.has_rdoc = true
|
15
15
|
|
16
|
-
s.add_dependency '
|
16
|
+
s.add_dependency 'execjs', '~> 1.4.0'
|
17
17
|
s.add_dependency 'commonjs', '~> 0.2.6'
|
18
|
-
s.add_dependency 'escodegen', '~> 1.
|
18
|
+
s.add_dependency 'escodegen', '~> 1.2.0'
|
19
19
|
|
20
20
|
s.add_development_dependency 'rake'
|
21
21
|
s.add_development_dependency 'rspec', '~> 2.11.0'
|
data/lib/esprima.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'execjs'
|
4
4
|
require 'commonjs'
|
5
5
|
require 'escodegen'
|
6
6
|
|
@@ -11,13 +11,23 @@ require 'esprima/ast'
|
|
11
11
|
Enumerator = Enumerable::Enumerator unless defined?(Enumerator)
|
12
12
|
|
13
13
|
module Esprima
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
class << self
|
15
|
+
def load_path
|
16
|
+
@load_path ||= File.expand_path(File.join(File.dirname(__FILE__), "../vendor"))
|
17
|
+
end
|
18
|
+
|
19
|
+
def new_environment
|
20
|
+
context = new_context
|
21
|
+
env = CommonJS::Environment.new(context, :path => Esprima.load_path)
|
22
|
+
env.require("esprima")
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
17
26
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
27
|
+
def new_context
|
28
|
+
cxt_obj = ExecJS.runtime.class::Context.new(nil)
|
29
|
+
cxt_var = cxt_obj.instance_variables.select { |var_name| var_name.to_s.include?("context") }.first
|
30
|
+
cxt_obj.instance_variable_get(cxt_var)
|
31
|
+
end
|
22
32
|
end
|
23
33
|
end
|
data/lib/esprima/parser.rb
CHANGED
@@ -22,13 +22,19 @@ module Esprima
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def to_ruby_hash(obj)
|
25
|
-
if
|
25
|
+
if js_type_of?(obj, :array)
|
26
26
|
obj.map { |val| to_ruby_hash(val) }
|
27
|
-
elsif
|
27
|
+
elsif js_type_of?(obj, :object)
|
28
28
|
obj.inject({}) { |ret, (key, val)| ret[key.to_sym] = to_ruby_hash(val); ret }
|
29
29
|
else
|
30
30
|
obj
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def js_type_of?(obj, type_sym)
|
37
|
+
obj.class.to_s.split("::").last.downcase.include?(type_sym.to_s)
|
38
|
+
end
|
33
39
|
end
|
34
|
-
end
|
40
|
+
end
|
data/lib/esprima/version.rb
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -19,6 +19,18 @@ AST_RESULT = [{
|
|
19
19
|
}
|
20
20
|
}]
|
21
21
|
|
22
|
+
class MockV8
|
23
|
+
class Array
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class MockRhino
|
28
|
+
class JS
|
29
|
+
class NativeObject
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
22
34
|
describe Esprima::Parser do
|
23
35
|
describe "#parse" do
|
24
36
|
it "should parse a basic js expression" do
|
@@ -37,4 +49,18 @@ describe Esprima::Parser do
|
|
37
49
|
result[:body].should == AST_RESULT
|
38
50
|
end
|
39
51
|
end
|
52
|
+
|
53
|
+
describe "#js_type_of?" do
|
54
|
+
it "returns true if the object's class name includes the given text, false otherwise" do
|
55
|
+
parser = Esprima::Parser.new
|
56
|
+
|
57
|
+
mock_arr = MockV8::Array.new
|
58
|
+
parser.send(:js_type_of?, mock_arr, :array).should be_true
|
59
|
+
parser.send(:js_type_of?, mock_arr, :object).should be_false
|
60
|
+
|
61
|
+
mock_obj = MockRhino::JS::NativeObject.new
|
62
|
+
parser.send(:js_type_of?, mock_obj, :array).should be_false
|
63
|
+
parser.send(:js_type_of?, mock_obj, :object).should be_true
|
64
|
+
end
|
65
|
+
end
|
40
66
|
end
|
metadata
CHANGED
@@ -1,99 +1,127 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: esprima
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version: 1.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.4.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Cameron Dutro
|
9
9
|
- Ariya Hidayat
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
date: 2012-12-27 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: execjs
|
17
|
+
version_requirements: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.4.0
|
20
22
|
none: false
|
21
|
-
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
22
25
|
- - ~>
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version:
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 1.4.0
|
28
|
+
none: false
|
29
|
+
prerelease: false
|
25
30
|
type: :runtime
|
26
|
-
|
27
|
-
- !ruby/object:Gem::Dependency
|
31
|
+
- !ruby/object:Gem::Dependency
|
28
32
|
name: commonjs
|
29
|
-
|
30
|
-
|
33
|
+
version_requirements: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.2.6
|
31
38
|
none: false
|
32
|
-
|
39
|
+
requirement: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
33
41
|
- - ~>
|
34
|
-
- !ruby/object:Gem::Version
|
42
|
+
- !ruby/object:Gem::Version
|
35
43
|
version: 0.2.6
|
44
|
+
none: false
|
45
|
+
prerelease: false
|
36
46
|
type: :runtime
|
37
|
-
|
38
|
-
- !ruby/object:Gem::Dependency
|
47
|
+
- !ruby/object:Gem::Dependency
|
39
48
|
name: escodegen
|
40
|
-
|
41
|
-
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.2.0
|
42
54
|
none: false
|
43
|
-
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
44
57
|
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 1.
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.2.0
|
60
|
+
none: false
|
61
|
+
prerelease: false
|
47
62
|
type: :runtime
|
48
|
-
|
49
|
-
- !ruby/object:Gem::Dependency
|
63
|
+
- !ruby/object:Gem::Dependency
|
50
64
|
name: rake
|
51
|
-
|
52
|
-
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: !binary |-
|
70
|
+
MA==
|
53
71
|
none: false
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: !binary |-
|
77
|
+
MA==
|
78
|
+
none: false
|
79
|
+
prerelease: false
|
58
80
|
type: :development
|
59
|
-
|
60
|
-
- !ruby/object:Gem::Dependency
|
81
|
+
- !ruby/object:Gem::Dependency
|
61
82
|
name: rspec
|
62
|
-
|
63
|
-
|
83
|
+
version_requirements: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 2.11.0
|
64
88
|
none: false
|
65
|
-
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
66
91
|
- - ~>
|
67
|
-
- !ruby/object:Gem::Version
|
92
|
+
- !ruby/object:Gem::Version
|
68
93
|
version: 2.11.0
|
94
|
+
none: false
|
95
|
+
prerelease: false
|
69
96
|
type: :development
|
70
|
-
|
71
|
-
- !ruby/object:Gem::Dependency
|
97
|
+
- !ruby/object:Gem::Dependency
|
72
98
|
name: rr
|
73
|
-
|
74
|
-
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.0.4
|
75
104
|
none: false
|
76
|
-
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
77
107
|
- - ~>
|
78
|
-
- !ruby/object:Gem::Version
|
108
|
+
- !ruby/object:Gem::Version
|
79
109
|
version: 1.0.4
|
110
|
+
none: false
|
111
|
+
prerelease: false
|
80
112
|
type: :development
|
81
|
-
version_requirements: *id006
|
82
113
|
description: Ruby wrapper around the Esprima static code analyzer for JavaScript.
|
83
|
-
email:
|
114
|
+
email:
|
84
115
|
- cdutro@twitter.com
|
85
116
|
- ariya.hidayat@gmail.com
|
86
117
|
executables: []
|
87
|
-
|
88
118
|
extensions: []
|
89
|
-
|
90
119
|
extra_rdoc_files: []
|
91
|
-
|
92
|
-
|
120
|
+
files:
|
121
|
+
- lib/esprima.rb
|
93
122
|
- lib/esprima/ast.rb
|
94
123
|
- lib/esprima/parser.rb
|
95
124
|
- lib/esprima/version.rb
|
96
|
-
- lib/esprima.rb
|
97
125
|
- spec/ast_spec.rb
|
98
126
|
- spec/esprima_spec.rb
|
99
127
|
- spec/parser_spec.rb
|
@@ -108,30 +136,28 @@ files:
|
|
108
136
|
- esprima.gemspec
|
109
137
|
homepage: http://esprima.org
|
110
138
|
licenses: []
|
111
|
-
|
112
|
-
post_install_message:
|
139
|
+
post_install_message:
|
113
140
|
rdoc_options: []
|
114
|
-
|
115
|
-
require_paths:
|
141
|
+
require_paths:
|
116
142
|
- lib
|
117
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: !binary |-
|
148
|
+
MA==
|
118
149
|
none: false
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ! '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: !binary |-
|
155
|
+
MA==
|
124
156
|
none: false
|
125
|
-
requirements:
|
126
|
-
- - ">="
|
127
|
-
- !ruby/object:Gem::Version
|
128
|
-
version: "0"
|
129
157
|
requirements: []
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
signing_key:
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 1.8.24
|
160
|
+
signing_key:
|
134
161
|
specification_version: 3
|
135
162
|
summary: Ruby wrapper around the Esprima static code analyzer for JavaScript.
|
136
163
|
test_files: []
|
137
|
-
|