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 CHANGED
@@ -2,6 +2,9 @@ source :rubygems
2
2
 
3
3
  gemspec
4
4
 
5
+ gem 'therubyrhino', :platform => :jruby
6
+ gem 'therubyracer', '~> 0.9.10', :platform => :mri
7
+
5
8
  group :test do
6
9
  gem 'rspec', '~> 2.11.0'
7
10
  gem 'rr', '~> 1.0.4'
@@ -1,3 +1,11 @@
1
+ === 1.4.0
2
+
3
+ * Supported different platforms with execjs, which should fix JRuby issues.
4
+
5
+ === 1.3.0
6
+
7
+ * Added JRuby compatibility.
8
+
1
9
  === 1.2.0
2
10
 
3
11
  * Added intermediate AST class that offers a few convenience methods like `each`.
@@ -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 'therubyracer', '~> 0.9.10'
16
+ s.add_dependency 'execjs', '~> 1.4.0'
17
17
  s.add_dependency 'commonjs', '~> 0.2.6'
18
- s.add_dependency 'escodegen', '~> 1.0.0'
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'
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'v8'
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
- def self.load_path
15
- @load_path ||= File.expand_path(File.join(File.dirname(__FILE__), "../vendor"))
16
- end
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
- def self.new_environment
19
- context = V8::Context.new
20
- env = CommonJS::Environment.new(context, :path => Esprima.load_path)
21
- env.require("esprima")
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
@@ -22,13 +22,19 @@ module Esprima
22
22
  end
23
23
 
24
24
  def to_ruby_hash(obj)
25
- if obj.is_a?(V8::Array)
25
+ if js_type_of?(obj, :array)
26
26
  obj.map { |val| to_ruby_hash(val) }
27
- elsif obj.is_a?(V8::Object)
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
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Esprima
4
- VERSION = "1.2.0"
4
+ VERSION = "1.4.0"
5
5
  end
@@ -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.2.0
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
- date: 2012-11-15 00:00:00 Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: therubyracer
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
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
- requirements:
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
22
25
  - - ~>
23
- - !ruby/object:Gem::Version
24
- version: 0.9.10
26
+ - !ruby/object:Gem::Version
27
+ version: 1.4.0
28
+ none: false
29
+ prerelease: false
25
30
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
31
+ - !ruby/object:Gem::Dependency
28
32
  name: commonjs
29
- prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
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
- requirements:
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
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
47
+ - !ruby/object:Gem::Dependency
39
48
  name: escodegen
40
- prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
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
- requirements:
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
44
57
  - - ~>
45
- - !ruby/object:Gem::Version
46
- version: 1.0.0
58
+ - !ruby/object:Gem::Version
59
+ version: 1.2.0
60
+ none: false
61
+ prerelease: false
47
62
  type: :runtime
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
63
+ - !ruby/object:Gem::Dependency
50
64
  name: rake
51
- prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
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
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: "0"
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
- version_requirements: *id004
60
- - !ruby/object:Gem::Dependency
81
+ - !ruby/object:Gem::Dependency
61
82
  name: rspec
62
- prerelease: false
63
- requirement: &id005 !ruby/object:Gem::Requirement
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
- requirements:
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
- version_requirements: *id005
71
- - !ruby/object:Gem::Dependency
97
+ - !ruby/object:Gem::Dependency
72
98
  name: rr
73
- prerelease: false
74
- requirement: &id006 !ruby/object:Gem::Requirement
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
- requirements:
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
- files:
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
- requirements:
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- version: "0"
123
- required_rubygems_version: !ruby/object:Gem::Requirement
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
- rubyforge_project:
132
- rubygems_version: 1.8.17
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
-