opal 0.3.20 → 0.3.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. data/.gitignore +2 -7
  2. data/.rspec +2 -0
  3. data/.travis.yml +11 -0
  4. data/Gemfile +8 -2
  5. data/LICENSE +2 -3
  6. data/README.md +106 -239
  7. data/Rakefile +58 -16
  8. data/bin/opal +1 -0
  9. data/core/array.rb +180 -160
  10. data/core/basic_object.rb +8 -4
  11. data/core/boolean.rb +6 -6
  12. data/core/class.rb +9 -15
  13. data/core/dir.rb +89 -0
  14. data/core/enumerable.rb +83 -86
  15. data/core/error.rb +9 -4
  16. data/core/file.rb +85 -0
  17. data/core/hash.rb +67 -67
  18. data/core/kernel.rb +38 -42
  19. data/core/module.rb +57 -54
  20. data/core/numeric.rb +41 -41
  21. data/core/proc.rb +1 -5
  22. data/core/range.rb +11 -11
  23. data/core/regexp.rb +27 -22
  24. data/core/runtime.js +152 -221
  25. data/core/string.rb +86 -73
  26. data/core/time.rb +22 -18
  27. data/docs/post.html +9 -0
  28. data/docs/pre.html +32 -0
  29. data/lib/opal.rb +43 -3
  30. data/lib/opal/builder.rb +9 -26
  31. data/lib/opal/grammar.rb +1 -1
  32. data/lib/opal/grammar.y +1 -1
  33. data/lib/opal/lexer.rb +21 -15
  34. data/lib/opal/parser.rb +100 -111
  35. data/lib/opal/rake_task.rb +66 -0
  36. data/lib/opal/scope.rb +13 -5
  37. data/lib/opal/version.rb +1 -1
  38. data/opal.gemspec +2 -0
  39. data/spec/browser_spec.rb +28 -0
  40. data/spec/builder/lib_name_for_spec.rb +1 -6
  41. data/spec/grammar/alias_spec.rb +1 -1
  42. data/spec/grammar/and_spec.rb +1 -1
  43. data/spec/grammar/array_spec.rb +1 -1
  44. data/spec/grammar/attrasgn_spec.rb +1 -1
  45. data/spec/grammar/begin_spec.rb +1 -1
  46. data/spec/grammar/block_spec.rb +1 -1
  47. data/spec/grammar/break_spec.rb +1 -1
  48. data/spec/grammar/call_spec.rb +1 -1
  49. data/spec/grammar/class_spec.rb +1 -1
  50. data/spec/grammar/const_spec.rb +1 -1
  51. data/spec/grammar/cvar_spec.rb +1 -1
  52. data/spec/grammar/def_spec.rb +1 -1
  53. data/spec/grammar/false_spec.rb +1 -1
  54. data/spec/grammar/file_spec.rb +1 -1
  55. data/spec/grammar/gvar_spec.rb +1 -1
  56. data/spec/grammar/hash_spec.rb +1 -1
  57. data/spec/grammar/iasgn_spec.rb +1 -1
  58. data/spec/grammar/if_spec.rb +1 -1
  59. data/spec/grammar/iter_spec.rb +1 -1
  60. data/spec/grammar/ivar_spec.rb +1 -1
  61. data/spec/grammar/lambda_spec.rb +1 -1
  62. data/spec/grammar/lasgn_spec.rb +1 -1
  63. data/spec/grammar/line_spec.rb +1 -1
  64. data/spec/grammar/lvar_spec.rb +1 -1
  65. data/spec/grammar/masgn_spec.rb +1 -1
  66. data/spec/grammar/module_spec.rb +1 -1
  67. data/spec/grammar/nil_spec.rb +1 -1
  68. data/spec/grammar/not_spec.rb +1 -1
  69. data/spec/grammar/op_asgn1_spec.rb +1 -1
  70. data/spec/grammar/op_asgn2_spec.rb +1 -1
  71. data/spec/grammar/or_spec.rb +1 -1
  72. data/spec/grammar/return_spec.rb +1 -1
  73. data/spec/grammar/sclass_spec.rb +1 -1
  74. data/spec/grammar/self_spec.rb +1 -1
  75. data/spec/grammar/str_spec.rb +1 -1
  76. data/spec/grammar/super_spec.rb +1 -1
  77. data/spec/grammar/true_spec.rb +1 -1
  78. data/spec/grammar/undef_spec.rb +1 -1
  79. data/spec/grammar/unless_spec.rb +1 -1
  80. data/spec/grammar/while_spec.rb +1 -1
  81. data/spec/grammar/xstr_spec.rb +1 -1
  82. data/spec/grammar/yield_spec.rb +1 -1
  83. data/spec/spec_helper.rb +6 -1
  84. data/test/core/array/minus_spec.rb +13 -0
  85. data/test/core/enumerable/drop_while_spec.rb +0 -5
  86. data/test/core/range/case_compare_spec.rb +0 -1
  87. data/test/index.html +1 -1
  88. data/test/index.min.html +12 -0
  89. data/test/language/alias_spec.rb +0 -4
  90. data/test/language/fixtures/next.rb +62 -0
  91. data/test/language/metaclass_spec.rb +4 -4
  92. data/test/language/next_spec.rb +0 -63
  93. data/test/language/send_spec.rb +0 -5
  94. data/test/language/singleton_class_spec.rb +4 -0
  95. data/test/opal/array/subclassing_spec.rb +1 -1
  96. data/test/opal/class/bridge_class_spec.rb +2 -2
  97. data/test/opal/runtime/class_hierarchy_spec.rb +1 -2
  98. data/test/opal/runtime/method_missing_spec.rb +17 -0
  99. data/test/spec_helper.rb +4 -1
  100. metadata +32 -28
  101. data/docs/CNAME +0 -1
  102. data/docs/Rakefile +0 -55
  103. data/docs/css/styles.css +0 -50
  104. data/docs/css/syntax.css +0 -63
  105. data/docs/layout/post.html +0 -3
  106. data/docs/layout/pre.html +0 -11
  107. data/examples/dependencies/.gitignore +0 -1
  108. data/examples/dependencies/Gemfile +0 -6
  109. data/examples/dependencies/README.md +0 -41
  110. data/examples/dependencies/Rakefile +0 -10
  111. data/examples/dependencies/app.rb +0 -19
  112. data/examples/dependencies/build/.gitkeep +0 -0
  113. data/examples/dependencies/index.html +0 -13
  114. data/examples/hello_world/.gitignore +0 -1
  115. data/examples/hello_world/Gemfile +0 -3
  116. data/examples/hello_world/README.md +0 -27
  117. data/examples/hello_world/Rakefile +0 -23
  118. data/examples/hello_world/app.rb +0 -7
  119. data/examples/hello_world/index.html +0 -12
  120. data/lib/opal/builder_task.rb +0 -91
  121. data/spec/builder/build_order_spec.rb +0 -20
  122. data/test/opal/runtime/_methods_spec.rb +0 -48
@@ -0,0 +1,66 @@
1
+ require 'opal'
2
+ require 'opal/builder'
3
+ require 'fileutils'
4
+
5
+ module Opal
6
+ class RakeTask
7
+ include Rake::DSL if defined? Rake::DSL
8
+
9
+ attr_accessor :name, :build_dir, :specs_dir, :files, :dependencies
10
+
11
+ def initialize(namespace = nil)
12
+ @project_dir = Dir.getwd
13
+
14
+ @name = File.basename(@project_dir)
15
+ @build_dir = 'build'
16
+ @specs_dir = 'spec'
17
+ @files = Dir['lib/**/*.{rb,js}']
18
+ @dependencies = []
19
+
20
+ yield self if block_given?
21
+
22
+ define_tasks
23
+ end
24
+
25
+ def build_gem(name)
26
+ out = File.join @build_dir, "#{ name }.js"
27
+ puts " * #{out}"
28
+ write_code Opal.build_gem(name), out
29
+ rescue Gem::LoadError => e
30
+ puts " - Error: Could not find gem #{name}"
31
+ end
32
+
33
+ def write_code(code, out)
34
+ FileUtils.mkdir_p File.dirname(out)
35
+ File.open(out, 'w+') { |o| o.puts code }
36
+ end
37
+
38
+ def define_tasks
39
+ desc "Build opal project"
40
+ task 'opal:build' do
41
+ out = File.join @build_dir, "#{ @name }.js"
42
+ puts " * #{out}"
43
+ write_code Opal.build_files(@files), out
44
+ end
45
+
46
+ desc "Build specs"
47
+ task 'opal:spec' do
48
+ out = File.join @build_dir, 'specs.js'
49
+ puts " * #{out}"
50
+ write_code Opal.build_files(@specs_dir), out
51
+ end
52
+
53
+ desc "Build dependencies"
54
+ task 'opal:dependencies' do
55
+ out = File.join @build_dir, 'opal.js'
56
+ puts " * #{out}"
57
+ write_code Opal.runtime, File.join(@build_dir, 'opal.js')
58
+
59
+ @dependencies.each { |dep| build_gem dep }
60
+ end
61
+
62
+ desc "Build opal files, dependencies and specs"
63
+ task :opal => %w(opal:build opal:dependencies opal:spec)
64
+ end
65
+ end
66
+ end
@@ -30,6 +30,9 @@ module Opal
30
30
  # singleton methods defined on classes/modules
31
31
  attr_reader :smethods
32
32
 
33
+ # uses parents super method
34
+ attr_accessor :uses_super
35
+
33
36
  def initialize(type, parser)
34
37
  @parser = parser
35
38
  @type = type
@@ -79,13 +82,17 @@ module Opal
79
82
  # used for optimizing ivars as we can set them to nil in the
80
83
  # class body
81
84
  def def_in_class?
82
- @type == :def && @parent && @parent.class?
85
+ !@defs && @type == :def && @parent && @parent.class?
83
86
  end
84
87
 
85
88
  def proto
86
89
  "#{ @name }_prototype"
87
90
  end
88
91
 
92
+ def m_tbl
93
+ "#{ @name }_methods"
94
+ end
95
+
89
96
  ##
90
97
  # Vars to use inside each scope
91
98
  def to_vars
@@ -111,16 +118,17 @@ module Opal
111
118
  # Generates code for this module to donate methods
112
119
  def to_donate_methods
113
120
  out = ""
121
+ return out unless @type == :module
114
122
 
115
123
  unless @methods.empty?
116
124
  out += "%s;#{@name}._donate([%s]);" %
117
125
  [@parser.parser_indent, @methods.map(&:inspect).join(', ')]
118
126
  end
119
127
 
120
- unless @smethods.empty?
121
- out += "%s;#{@name}._sdonate([%s]);" %
122
- [@parser.parser_indent, @smethods.map(&:inspect).join(', ')]
123
- end
128
+ # unless @smethods.empty?
129
+ # out += "%s;#{@name}._sdonate([%s]);" %
130
+ # [@parser.parser_indent, @smethods.map(&:inspect).join(', ')]
131
+ # end
124
132
 
125
133
  out
126
134
  end
@@ -1,3 +1,3 @@
1
1
  module Opal
2
- VERSION = "0.3.20"
2
+ VERSION = "0.3.21"
3
3
  end
@@ -14,4 +14,6 @@ Gem::Specification.new do |s|
14
14
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
  s.require_paths = ['lib']
17
+
18
+ s.add_development_dependency 'rspec', '~> 2.10'
17
19
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'opal core features', :js, :type => :request do
4
+ before do
5
+ Capybara.app = lambda do |env|
6
+ path = env['PATH_INFO']
7
+ base_path = File.expand_path('../../test/index.html', __FILE__)
8
+
9
+ case path
10
+ when /\.js/
11
+ contents = File.read(File.join(File.dirname(base_path), '..', path))
12
+ [200, {'Content-Type' => 'application/x-javascript'}, [contents]]
13
+ else
14
+ contents = File.read(base_path)
15
+ [200, {'Content-Type' => 'text/html'}, [contents]]
16
+ end
17
+ end
18
+ end
19
+
20
+ it 'runs all specs in the browser' do
21
+ path = File.expand_path '../../test/index.html', __FILE__
22
+ p path
23
+ visit '/'
24
+ within '.summary' do
25
+ page.should have_content(' 0 failures ')
26
+ end
27
+ end
28
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Builder#lib_name_for" do
4
4
  before do
@@ -16,9 +16,4 @@ describe "Builder#lib_name_for" do
16
16
  @builder.lib_name_for('app/title.rb').should == 'app/title'
17
17
  @builder.lib_name_for('spec/spec_helper.rb').should == 'spec/spec_helper'
18
18
  end
19
-
20
- it "should remove the optional 'lib/opal/' prefix as well" do
21
- @builder.lib_name_for('lib/opal/json.rb').should == 'json'
22
- @builder.lib_name_for('lib/opal/json/parser.js').should == 'json/parser'
23
- end
24
19
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The alias keyword" do
4
4
  describe "with fitem" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The and statement" do
4
4
  it "should always return s(:and)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Arrays" do
4
4
  it "should parse empty arrays as s(:array)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Attribute assignments" do
4
4
  it "should return a s(:attrasgn) for simple assignments" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The begin keyword" do
4
4
  it "should be removed when used without a resuce or enusre body" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Block statements" do
4
4
  it "should return the direct expression if only one expresssion in block" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The break keyword" do
4
4
  it "should return s(:break) when given no args" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Method calls" do
4
4
  it "should use 'nil' for calls without a receiver" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The class keyword" do
4
4
  it "returns a plain s(:scope) when given an empty body" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Constants" do
4
4
  it "should always become a s(:const)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Class variables" do
4
4
  it "should always be returned as s(:cvar)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The def keyword" do
4
4
  describe "for normal definitions" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The false keyword" do
4
4
  it "should always return s(:false)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The __FILE__ keyword" do
4
4
  it "should always return a s(:str) with given parser filename" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Global variables" do
4
4
  it "should be returned as s(:gvar)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Hash literals" do
4
4
  it "without any assocs should return an empty hash sexp" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Instance variable assignment" do
4
4
  it "always returns an s(:iasgn)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The if keyword" do
4
4
  it "should return an s(:if) with given truthy and falsy bodies" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Iters" do
4
4
  describe "Iter on a command" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Instance variables" do
4
4
  it "always return an s(:ivar)" do
@@ -1,4 +1,4 @@
1
- File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Lambda literals" do
4
4
  it "should parse with either do/end construct or curly braces" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Local assignment" do
4
4
  it "returns an s(:lasgn)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The __LINE__ keyword" do
4
4
  it "should always return a literal number of the current line" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "An lvar" do
4
4
  describe "in any scope" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Masgn" do
4
4
  describe "with a single lhs splat" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The module keyword" do
4
4
  it "returns a plain s(:scope) when given an empty body" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The nil keyword" do
4
4
  it "always returns s(:nil)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The not keyword" do
4
4
  it "returns s(:not) with the single argument" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "op_asgn1" do
4
4
  it "returns s(:op_asgn1)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "op_asgn2" do
4
4
  it "returns s(:op_asgn2)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The or statement" do
4
4
  it "should always return s(:or)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The return keyword" do
4
4
  it "should return s(:return) when given no arguments" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Singleton classes" do
4
4
  it "returns an empty s(:scope) when given an empty body" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The self keyword" do
4
4
  it "always returns s(:self)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Strings" do
4
4
  it "parses empty strings" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The super keyword" do
4
4
  it "should return s(:zsuper) when no arguments or parans" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The true keyword" do
4
4
  it "always returns s(:true)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The undef keyword" do
4
4
  it "returns s(:undef) with the argument as an s(:lit)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "The unless keyword" do
4
4
  it "returns s(:if) with reversed true and false bodies" do