opal 0.3.40 → 0.3.41

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +0 -2
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile +1 -1
  4. data/README.md +1 -1
  5. data/Rakefile +9 -11
  6. data/config.ru +5 -10
  7. data/lib/opal.rb +17 -2
  8. data/lib/opal/lexer.rb +6 -0
  9. data/lib/opal/parser.rb +2 -14
  10. data/lib/opal/server.rb +3 -1
  11. data/lib/opal/version.rb +1 -1
  12. data/opal.gemspec +0 -1
  13. data/opal/opal-parser.js.erb +7 -0
  14. data/{lib/assets/javascripts → opal}/opal.rb +0 -0
  15. data/{lib/assets/javascripts → opal}/opal/array.rb +0 -0
  16. data/{lib/assets/javascripts → opal}/opal/basic_object.rb +0 -0
  17. data/{lib/assets/javascripts → opal}/opal/boolean.rb +0 -0
  18. data/{lib/assets/javascripts → opal}/opal/class.rb +0 -0
  19. data/{lib/assets/javascripts → opal}/opal/comparable.rb +0 -0
  20. data/{lib/assets/javascripts → opal}/opal/date.rb +0 -0
  21. data/{lib/assets/javascripts → opal}/opal/enumerable.rb +0 -0
  22. data/{lib/assets/javascripts → opal}/opal/enumerator.rb +0 -0
  23. data/{lib/assets/javascripts → opal}/opal/error.rb +0 -0
  24. data/{lib/assets/javascripts → opal}/opal/hash.rb +0 -0
  25. data/{lib/assets/javascripts → opal}/opal/json.rb +0 -0
  26. data/{lib/assets/javascripts → opal}/opal/kernel.rb +0 -0
  27. data/{lib/assets/javascripts → opal}/opal/native.rb +0 -0
  28. data/{lib/assets/javascripts → opal}/opal/nil_class.rb +0 -0
  29. data/{lib/assets/javascripts → opal}/opal/numeric.rb +0 -0
  30. data/{lib/assets/javascripts → opal}/opal/proc.rb +0 -0
  31. data/{lib/assets/javascripts → opal}/opal/racc.rb +0 -0
  32. data/{lib/assets/javascripts → opal}/opal/range.rb +0 -0
  33. data/{lib/assets/javascripts → opal}/opal/regexp.rb +0 -0
  34. data/{lib/assets/javascripts → opal}/opal/runtime.js +3 -0
  35. data/{lib/assets/javascripts → opal}/opal/string.rb +0 -0
  36. data/{lib/assets/javascripts → opal}/opal/strscan.rb +0 -0
  37. data/{lib/assets/javascripts → opal}/opal/template.rb +0 -0
  38. data/{lib/assets/javascripts → opal}/opal/time.rb +0 -0
  39. data/spec/core/kernel/block_given.rb +1 -1
  40. data/spec/core_ext/class/proc_methods_spec.rb +23 -0
  41. metadata +31 -33
  42. data/bin/opal +0 -24
  43. data/lib/assets/javascripts/opal-parser.js.erb +0 -8
  44. data/lib/assets/javascripts/opal/parser.js +0 -57
  45. data/lib/opal/environment.rb +0 -12
data/.gitignore CHANGED
@@ -3,5 +3,3 @@
3
3
  .yardoc
4
4
  .bundle
5
5
  Gemfile.lock
6
- build
7
- gh-pages
@@ -1,3 +1,9 @@
1
+ ## Edge
2
+
3
+ * Depreceate Opal::Environment. The Opal::Server class provides a better
4
+ method of using the opal load paths. Opal.paths still stores a list of
5
+ load paths for generic sprockets based apps to use.
6
+
1
7
  ## 0.3.40 2013-02-23
2
8
 
3
9
  * Add Opal::Server as an easy to configure rack server for testing and
data/Gemfile CHANGED
@@ -3,4 +3,4 @@ gemspec
3
3
 
4
4
  gem 'rake'
5
5
  gem 'racc'
6
- gem 'opal-spec', '~> 0.2.12'
6
+ gem 'opal-spec', '~> 0.2.13'
data/README.md CHANGED
@@ -33,7 +33,7 @@ The `lib` directory holds the opal parser/compiler used to compile ruby
33
33
  into javascript. It is also built ready for the browser into `opal-parser.js`
34
34
  to allow compilation in any javascript environment.
35
35
 
36
- ### lib/assets/javascripts
36
+ ### opal
37
37
 
38
38
  This directory holds the opal runtime and corelib implemented in ruby and
39
39
  javascript. These are built using `rake`, as above.
data/Rakefile CHANGED
@@ -1,23 +1,21 @@
1
1
  require 'bundler'
2
2
  Bundler.require
3
3
 
4
+ Opal::Processor.arity_check_enabled = true
5
+
4
6
  require 'opal/spec/rake_task'
5
7
  Opal::Spec::RakeTask.new(:default)
6
8
 
7
- desc "Run tests with method_missing turned off"
8
- task :test_no_method_missing do
9
- # some specs will fail (namely method_missing based specs)
10
- Opal::Processor.method_missing_enabled = false
11
- Rake::Task[:default].invoke
12
- end
13
-
14
9
  desc "Check file sizes for opal.js runtime"
15
10
  task :sizes do
16
- o = Opal::Environment.new['opal'].to_s
17
- m = uglify o
18
- g = gzip m
11
+ env = Sprockets::Environment.new
12
+ Opal.paths.each { |p| env.append_path p }
13
+
14
+ src = env['opal'].to_s
15
+ min = uglify src
16
+ gzp = gzip min
19
17
 
20
- puts "development: #{o.size}, minified: #{m.size}, gzipped: #{g.size}"
18
+ puts "development: #{src.size}, minified: #{min.size}, gzipped: #{gzp.size}"
21
19
  end
22
20
 
23
21
  desc "Rebuild grammar.rb for opal parser"
data/config.ru CHANGED
@@ -1,13 +1,8 @@
1
1
  require 'bundler'
2
2
  Bundler.require
3
3
 
4
- require 'opal/spec/server'
5
-
6
- # method_missing can be turned off if required (on by default)
7
- # Opal::Processor.method_missing_enabled = false
8
-
9
- # Run in non-debug mode (faster, all files concatenated into 1 file)
10
- run Opal::Spec::Server.new(false)
11
-
12
- # Run in debug mode - all files loaded seperately, but slower
13
- # run Opal::Spec::Server.new
4
+ run Opal::Server.new { |s|
5
+ s.main = 'opal/spec/sprockets_runner'
6
+ s.append_path 'spec'
7
+ s.debug = false
8
+ }
@@ -1,11 +1,16 @@
1
1
  require 'opal/parser'
2
2
  require 'opal/processor'
3
- require 'opal/environment'
4
3
  require 'opal/server'
5
4
  require 'opal/version'
6
5
 
7
6
  # Opal is a ruby to javascript compiler, with a runtime for running
8
7
  # in any javascript environment.
8
+ #
9
+ # Opal::Parser is the core class used for parsing ruby and generating
10
+ # javascript from its syntax tree. Opal::Processor is the main system used
11
+ # for compiling larger programs. Opal::Processor uses sprockets to maintain
12
+ # an environment of load paths, which can be used to require other ruby or
13
+ # javascript sources.
9
14
  module Opal
10
15
 
11
16
  # Parse given string of ruby into javascript
@@ -20,10 +25,20 @@ module Opal
20
25
  Parser.new.parse str, :file => file
21
26
  end
22
27
 
28
+ # Returns the path to the opal corelib. Used by Opal::Processor to load
29
+ # opal runtime and core lib.
30
+ #
31
+ # @return [String]
23
32
  def self.core_dir
24
- File.join File.dirname(__FILE__), 'assets', 'javascripts'
33
+ File.expand_path('../../opal', __FILE__)
25
34
  end
26
35
 
36
+ # Add a file path to opals load path. Any gem containing ruby code that Opal
37
+ # has access to should add a load path through this method. Load paths added
38
+ # here should only be paths which contain code targeted at being compiled by
39
+ # Opal.
40
+ #
41
+ # @param [String] path file path to add
27
42
  def self.append_path(path)
28
43
  paths << path
29
44
  end
@@ -42,6 +42,12 @@ module Opal
42
42
  raise "parse error on value #{val.inspect} :#{@file}:#{@line}"
43
43
  end
44
44
 
45
+ # LexerScope is used during lexing to keep track of local variables
46
+ # created inside a scope. A lexer scope can be asked if it has a local
47
+ # variable defined, and it can also check its parent scope if applicable.
48
+ #
49
+ # A LexerScope is created automatically as a new scope is entered during
50
+ # the lexing stage.
45
51
  class LexerScope
46
52
  attr_reader :locals
47
53
  attr_accessor :parent
@@ -585,7 +585,6 @@ module Opal
585
585
  str = sexp.shift
586
586
  if str == @file
587
587
  @uses_file = true
588
- # "'FILE'"
589
588
  @file.inspect
590
589
  else
591
590
  str.inspect
@@ -621,8 +620,6 @@ module Opal
621
620
  with_temp do |tmp|
622
621
  "(#{tmp} = #{process(sexp.shift, :expr)}, (#{tmp} === nil || #{tmp} === false))"
623
622
  end
624
- # code = "!#{process sexp.shift, :expr}"
625
- # code
626
623
  end
627
624
 
628
625
  def process_block_pass(exp, level)
@@ -1133,7 +1130,6 @@ module Opal
1133
1130
  end
1134
1131
 
1135
1132
  code += stmt_code
1136
- # code += "\n#@indent" + process(stmts, :stmt)
1137
1133
 
1138
1134
  if @scope.uses_block? and !block_name
1139
1135
  params = params.empty? ? yielder : "#{params}, #{yielder}"
@@ -1662,12 +1658,8 @@ module Opal
1662
1658
  t = nil
1663
1659
 
1664
1660
  with_temp do |tmp|
1665
- # if t = js_truthy_optimize(lhs)
1666
- # "((%s = %s) ? %s : %s)" % [tmp, t, tmp, process(rhs, :expr)]
1667
- # else
1668
- "((%s = %s), %s !== false && %s !== nil ? %s : %s)" %
1669
- [tmp, process(lhs, :expr), tmp, tmp, tmp, process(rhs, :expr)]
1670
- # end
1661
+ "((%s = %s), %s !== false && %s !== nil ? %s : %s)" %
1662
+ [tmp, process(lhs, :expr), tmp, tmp, tmp, process(rhs, :expr)]
1671
1663
  end
1672
1664
  end
1673
1665
 
@@ -1874,9 +1866,7 @@ module Opal
1874
1866
  identity = @scope.identify!
1875
1867
  cls_name = @scope.parent.name
1876
1868
  jsid = mid_to_jsid @scope.mid.to_s
1877
- # base = @scope.defs ? '' : ".prototype"
1878
1869
 
1879
- # "%s._super%s%s.apply(this, %s)" % [cls_name, base, jsid, args]
1880
1870
  if @scope.defs
1881
1871
  "%s._super%s.apply(this, %s)" % [cls_name, jsid, args]
1882
1872
  else
@@ -1972,7 +1962,6 @@ module Opal
1972
1962
  err = types.map { |t|
1973
1963
  call = s(:call, t, :===, s(:arglist, s(:js_tmp, "$err")))
1974
1964
  a = process call, :expr
1975
- #puts a
1976
1965
  a
1977
1966
  }.join ', '
1978
1967
  err = "true" if err.empty?
@@ -1984,7 +1973,6 @@ module Opal
1984
1973
  end
1985
1974
 
1986
1975
  "if (#{err}) {#{@space}#{val}#{body}}"
1987
- # raise exp.inspect
1988
1976
  end
1989
1977
 
1990
1978
  # FIXME: Hack.. grammar should remove top level begin.
@@ -7,7 +7,9 @@ module Opal
7
7
  attr_accessor :debug, :index_path, :main, :public_dir, :sprockets
8
8
 
9
9
  def initialize(debug = true)
10
- @sprockets = Opal::Environment.new
10
+ @sprockets = Sprockets::Environment.new
11
+ Opal.paths.each { |p| @sprockets.append_path p }
12
+
11
13
  @public_dir = '.'
12
14
  @debug = debug
13
15
 
@@ -1,3 +1,3 @@
1
1
  module Opal
2
- VERSION = '0.3.40'
2
+ VERSION = '0.3.41'
3
3
  end
@@ -11,7 +11,6 @@ Gem::Specification.new do |s|
11
11
  s.description = 'Ruby runtime and core library for javascript.'
12
12
 
13
13
  s.files = `git ls-files`.split("\n")
14
- s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
15
14
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
15
  s.require_paths = ['lib']
17
16
 
@@ -0,0 +1,7 @@
1
+ <% require_asset 'opal/racc' %>
2
+ <% require_asset 'opal/strscan' %>
3
+
4
+ // We need (some) of the libs from our real ruby parser (not in sprockets load path)
5
+ <% %w(opal/grammar opal/lexer opal/parser opal/scope opal).each do |f| %>
6
+ <%= Opal.parse File.read(File.join Opal.core_dir, '..', 'lib', "#{f}.rb") %>
7
+ <% end %>
File without changes
@@ -177,6 +177,9 @@
177
177
  constructor.$to_s = module_to_s;
178
178
  constructor.toString = module_to_s;
179
179
 
180
+ constructor['$[]'] = undefined;
181
+ constructor['$call'] = undefined;
182
+
180
183
  var smethods;
181
184
 
182
185
  smethods = superklass._smethods.slice();
@@ -27,4 +27,4 @@ describe "Kernel#block_given?" do
27
27
  BlockGivenSpecs.is_block_given(&nil).should == false
28
28
  BlockGivenSpecs.is_block_given(&:x).should == true
29
29
  end
30
- end
30
+ end if false
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ module ClassProcMethodsSpec
4
+ class A; end
5
+
6
+ class B
7
+ def self.[](a); :foo; end
8
+ end
9
+
10
+ class C < B; end
11
+ end
12
+
13
+ describe "Class: proc methods" do
14
+ it "classes should not inherit proc methods" do
15
+ ClassProcMethodsSpec::A.respond_to?(:[]).should be_false
16
+ ClassProcMethodsSpec::A.respond_to?(:call).should be_false
17
+ end
18
+
19
+ it "subclasses inherit proc methods if defined on suprt class" do
20
+ ClassProcMethodsSpec::B[nil].should eq(:foo)
21
+ ClassProcMethodsSpec::C[nil].should eq(:foo)
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.40
4
+ version: 0.3.41
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-02-23 00:00:00.000000000 Z
12
+ date: 2013-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets
@@ -29,8 +29,7 @@ dependencies:
29
29
  version: '0'
30
30
  description: Ruby runtime and core library for javascript.
31
31
  email: adam.beynon@gmail.com
32
- executables:
33
- - opal
32
+ executables: []
34
33
  extensions: []
35
34
  extra_rdoc_files: []
36
35
  files:
@@ -42,37 +41,8 @@ files:
42
41
  - LICENSE
43
42
  - README.md
44
43
  - Rakefile
45
- - bin/opal
46
44
  - config.ru
47
- - lib/assets/javascripts/opal-parser.js.erb
48
- - lib/assets/javascripts/opal.rb
49
- - lib/assets/javascripts/opal/array.rb
50
- - lib/assets/javascripts/opal/basic_object.rb
51
- - lib/assets/javascripts/opal/boolean.rb
52
- - lib/assets/javascripts/opal/class.rb
53
- - lib/assets/javascripts/opal/comparable.rb
54
- - lib/assets/javascripts/opal/date.rb
55
- - lib/assets/javascripts/opal/enumerable.rb
56
- - lib/assets/javascripts/opal/enumerator.rb
57
- - lib/assets/javascripts/opal/error.rb
58
- - lib/assets/javascripts/opal/hash.rb
59
- - lib/assets/javascripts/opal/json.rb
60
- - lib/assets/javascripts/opal/kernel.rb
61
- - lib/assets/javascripts/opal/native.rb
62
- - lib/assets/javascripts/opal/nil_class.rb
63
- - lib/assets/javascripts/opal/numeric.rb
64
- - lib/assets/javascripts/opal/parser.js
65
- - lib/assets/javascripts/opal/proc.rb
66
- - lib/assets/javascripts/opal/racc.rb
67
- - lib/assets/javascripts/opal/range.rb
68
- - lib/assets/javascripts/opal/regexp.rb
69
- - lib/assets/javascripts/opal/runtime.js
70
- - lib/assets/javascripts/opal/string.rb
71
- - lib/assets/javascripts/opal/strscan.rb
72
- - lib/assets/javascripts/opal/template.rb
73
- - lib/assets/javascripts/opal/time.rb
74
45
  - lib/opal.rb
75
- - lib/opal/environment.rb
76
46
  - lib/opal/grammar.rb
77
47
  - lib/opal/grammar.y
78
48
  - lib/opal/lexer.rb
@@ -82,6 +52,32 @@ files:
82
52
  - lib/opal/server.rb
83
53
  - lib/opal/version.rb
84
54
  - opal.gemspec
55
+ - opal/opal-parser.js.erb
56
+ - opal/opal.rb
57
+ - opal/opal/array.rb
58
+ - opal/opal/basic_object.rb
59
+ - opal/opal/boolean.rb
60
+ - opal/opal/class.rb
61
+ - opal/opal/comparable.rb
62
+ - opal/opal/date.rb
63
+ - opal/opal/enumerable.rb
64
+ - opal/opal/enumerator.rb
65
+ - opal/opal/error.rb
66
+ - opal/opal/hash.rb
67
+ - opal/opal/json.rb
68
+ - opal/opal/kernel.rb
69
+ - opal/opal/native.rb
70
+ - opal/opal/nil_class.rb
71
+ - opal/opal/numeric.rb
72
+ - opal/opal/proc.rb
73
+ - opal/opal/racc.rb
74
+ - opal/opal/range.rb
75
+ - opal/opal/regexp.rb
76
+ - opal/opal/runtime.js
77
+ - opal/opal/string.rb
78
+ - opal/opal/strscan.rb
79
+ - opal/opal/template.rb
80
+ - opal/opal/time.rb
85
81
  - spec/core/array/allocate_spec.rb
86
82
  - spec/core/array/append_spec.rb
87
83
  - spec/core/array/assoc_spec.rb
@@ -381,6 +377,7 @@ files:
381
377
  - spec/core_ext/array/to_json_spec.rb
382
378
  - spec/core_ext/basic_object/send_spec.rb
383
379
  - spec/core_ext/class/_inherited_spec.rb
380
+ - spec/core_ext/class/proc_methods_spec.rb
384
381
  - spec/core_ext/class/singleton_methods_spec.rb
385
382
  - spec/core_ext/constants_spec.rb
386
383
  - spec/core_ext/method_missing_spec.rb
@@ -793,6 +790,7 @@ test_files:
793
790
  - spec/core_ext/array/to_json_spec.rb
794
791
  - spec/core_ext/basic_object/send_spec.rb
795
792
  - spec/core_ext/class/_inherited_spec.rb
793
+ - spec/core_ext/class/proc_methods_spec.rb
796
794
  - spec/core_ext/class/singleton_methods_spec.rb
797
795
  - spec/core_ext/constants_spec.rb
798
796
  - spec/core_ext/method_missing_spec.rb
data/bin/opal DELETED
@@ -1,24 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'optparse'
4
- require 'opal'
5
-
6
- options = {}
7
- parser = OptionParser.new do |opts|
8
- opts.banner = "Usage: opal [options] file.rb"
9
-
10
- opts.on("-v", "--version", "Opal Version") do |v|
11
- puts Opal::VERSION
12
- exit
13
- end
14
- end
15
-
16
- parser.parse!
17
-
18
- if ARGV.empty?
19
- puts parser.banner
20
- else
21
- src = ARGV.first
22
- src = File.read src if File.exist? src
23
- puts Opal.parse(src)
24
- end
@@ -1,8 +0,0 @@
1
- <% require_asset 'opal/racc' %>
2
- <% require_asset 'opal/strscan' %>
3
- <% require_asset 'opal/parser' %>
4
-
5
- // We need (some) of the libs from our real ruby parser (not in sprockets load path)
6
- <% ['/grammar', '/lexer', '/parser', '/scope', ''].each do |f| %>
7
- <%= Opal.parse File.read(File.join Opal.core_dir, '..', '..', "opal#{f}.rb") %>
8
- <% end %>
@@ -1,57 +0,0 @@
1
- (function() {
2
- // quick exit if not insde browser
3
- if (typeof(window) === 'undefined' || typeof(document) === 'undefined') {
4
- return;
5
- }
6
-
7
- function findRubyScripts() {
8
- var all = document.getElementsByTagName('script');
9
- for (var i = 0, script; i < all.length; i++) {
10
- script = all[i];
11
- if (script.type === 'text/ruby') {
12
- if (script.src) {
13
- request(script.src, function(result) {
14
- runRuby(result);
15
- });
16
- }
17
- else {
18
- runRuby(script.innerHTML);
19
- }
20
- }
21
- else if (script.type === 'text/erb') {
22
- runERB(script.innerHTML);
23
- }
24
- }
25
- }
26
-
27
- function runRuby(source) {
28
- var js = Opal.Opal.Parser.$new().$parse(source);
29
- eval('(' + js + ')()');
30
- }
31
-
32
- function request(url, callback) {
33
- var xhr = new (window.ActiveXObject || XMLHttpRequest)('Microsoft.XMLHTTP');
34
- xhr.open('GET', url, true);
35
- if ('overrideMimeType' in xhr) {
36
- xhr.overrideMimeType('text/plain');
37
- }
38
- xhr.onreadystatechange = function() {
39
- if (xhr.readyState === 4) {
40
- if (xhr.status === 0 || xhr.status === 200) {
41
- callback(xhr.responseText);
42
- }
43
- else {
44
- throw new Error('Could not load ruby at: ' + url);
45
- }
46
- }
47
- };
48
- xhr.send(null);
49
- }
50
-
51
- if (window.addEventListener) {
52
- window.addEventListener('DOMContentLoaded', findRubyScripts, false);
53
- }
54
- else {
55
- window.attachEvent('onload', findRubyScripts);
56
- }
57
- })();
@@ -1,12 +0,0 @@
1
- require 'opal'
2
- require 'sprockets'
3
-
4
- module Opal
5
- class Environment < Sprockets::Environment
6
- def initialize(*)
7
- super
8
-
9
- Opal.paths.each { |path| append_path path }
10
- end
11
- end
12
- end