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.
- data/.gitignore +2 -7
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +8 -2
- data/LICENSE +2 -3
- data/README.md +106 -239
- data/Rakefile +58 -16
- data/bin/opal +1 -0
- data/core/array.rb +180 -160
- data/core/basic_object.rb +8 -4
- data/core/boolean.rb +6 -6
- data/core/class.rb +9 -15
- data/core/dir.rb +89 -0
- data/core/enumerable.rb +83 -86
- data/core/error.rb +9 -4
- data/core/file.rb +85 -0
- data/core/hash.rb +67 -67
- data/core/kernel.rb +38 -42
- data/core/module.rb +57 -54
- data/core/numeric.rb +41 -41
- data/core/proc.rb +1 -5
- data/core/range.rb +11 -11
- data/core/regexp.rb +27 -22
- data/core/runtime.js +152 -221
- data/core/string.rb +86 -73
- data/core/time.rb +22 -18
- data/docs/post.html +9 -0
- data/docs/pre.html +32 -0
- data/lib/opal.rb +43 -3
- data/lib/opal/builder.rb +9 -26
- data/lib/opal/grammar.rb +1 -1
- data/lib/opal/grammar.y +1 -1
- data/lib/opal/lexer.rb +21 -15
- data/lib/opal/parser.rb +100 -111
- data/lib/opal/rake_task.rb +66 -0
- data/lib/opal/scope.rb +13 -5
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +2 -0
- data/spec/browser_spec.rb +28 -0
- data/spec/builder/lib_name_for_spec.rb +1 -6
- data/spec/grammar/alias_spec.rb +1 -1
- data/spec/grammar/and_spec.rb +1 -1
- data/spec/grammar/array_spec.rb +1 -1
- data/spec/grammar/attrasgn_spec.rb +1 -1
- data/spec/grammar/begin_spec.rb +1 -1
- data/spec/grammar/block_spec.rb +1 -1
- data/spec/grammar/break_spec.rb +1 -1
- data/spec/grammar/call_spec.rb +1 -1
- data/spec/grammar/class_spec.rb +1 -1
- data/spec/grammar/const_spec.rb +1 -1
- data/spec/grammar/cvar_spec.rb +1 -1
- data/spec/grammar/def_spec.rb +1 -1
- data/spec/grammar/false_spec.rb +1 -1
- data/spec/grammar/file_spec.rb +1 -1
- data/spec/grammar/gvar_spec.rb +1 -1
- data/spec/grammar/hash_spec.rb +1 -1
- data/spec/grammar/iasgn_spec.rb +1 -1
- data/spec/grammar/if_spec.rb +1 -1
- data/spec/grammar/iter_spec.rb +1 -1
- data/spec/grammar/ivar_spec.rb +1 -1
- data/spec/grammar/lambda_spec.rb +1 -1
- data/spec/grammar/lasgn_spec.rb +1 -1
- data/spec/grammar/line_spec.rb +1 -1
- data/spec/grammar/lvar_spec.rb +1 -1
- data/spec/grammar/masgn_spec.rb +1 -1
- data/spec/grammar/module_spec.rb +1 -1
- data/spec/grammar/nil_spec.rb +1 -1
- data/spec/grammar/not_spec.rb +1 -1
- data/spec/grammar/op_asgn1_spec.rb +1 -1
- data/spec/grammar/op_asgn2_spec.rb +1 -1
- data/spec/grammar/or_spec.rb +1 -1
- data/spec/grammar/return_spec.rb +1 -1
- data/spec/grammar/sclass_spec.rb +1 -1
- data/spec/grammar/self_spec.rb +1 -1
- data/spec/grammar/str_spec.rb +1 -1
- data/spec/grammar/super_spec.rb +1 -1
- data/spec/grammar/true_spec.rb +1 -1
- data/spec/grammar/undef_spec.rb +1 -1
- data/spec/grammar/unless_spec.rb +1 -1
- data/spec/grammar/while_spec.rb +1 -1
- data/spec/grammar/xstr_spec.rb +1 -1
- data/spec/grammar/yield_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -1
- data/test/core/array/minus_spec.rb +13 -0
- data/test/core/enumerable/drop_while_spec.rb +0 -5
- data/test/core/range/case_compare_spec.rb +0 -1
- data/test/index.html +1 -1
- data/test/index.min.html +12 -0
- data/test/language/alias_spec.rb +0 -4
- data/test/language/fixtures/next.rb +62 -0
- data/test/language/metaclass_spec.rb +4 -4
- data/test/language/next_spec.rb +0 -63
- data/test/language/send_spec.rb +0 -5
- data/test/language/singleton_class_spec.rb +4 -0
- data/test/opal/array/subclassing_spec.rb +1 -1
- data/test/opal/class/bridge_class_spec.rb +2 -2
- data/test/opal/runtime/class_hierarchy_spec.rb +1 -2
- data/test/opal/runtime/method_missing_spec.rb +17 -0
- data/test/spec_helper.rb +4 -1
- metadata +32 -28
- data/docs/CNAME +0 -1
- data/docs/Rakefile +0 -55
- data/docs/css/styles.css +0 -50
- data/docs/css/syntax.css +0 -63
- data/docs/layout/post.html +0 -3
- data/docs/layout/pre.html +0 -11
- data/examples/dependencies/.gitignore +0 -1
- data/examples/dependencies/Gemfile +0 -6
- data/examples/dependencies/README.md +0 -41
- data/examples/dependencies/Rakefile +0 -10
- data/examples/dependencies/app.rb +0 -19
- data/examples/dependencies/build/.gitkeep +0 -0
- data/examples/dependencies/index.html +0 -13
- data/examples/hello_world/.gitignore +0 -1
- data/examples/hello_world/Gemfile +0 -3
- data/examples/hello_world/README.md +0 -27
- data/examples/hello_world/Rakefile +0 -23
- data/examples/hello_world/app.rb +0 -7
- data/examples/hello_world/index.html +0 -12
- data/lib/opal/builder_task.rb +0 -91
- data/spec/builder/build_order_spec.rb +0 -20
- 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
|
data/lib/opal/scope.rb
CHANGED
|
@@ -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
|
data/lib/opal/version.rb
CHANGED
data/opal.gemspec
CHANGED
|
@@ -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
|
|
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
|
data/spec/grammar/alias_spec.rb
CHANGED
data/spec/grammar/and_spec.rb
CHANGED
data/spec/grammar/array_spec.rb
CHANGED
data/spec/grammar/begin_spec.rb
CHANGED
data/spec/grammar/block_spec.rb
CHANGED
data/spec/grammar/break_spec.rb
CHANGED
data/spec/grammar/call_spec.rb
CHANGED
data/spec/grammar/class_spec.rb
CHANGED
data/spec/grammar/const_spec.rb
CHANGED
data/spec/grammar/cvar_spec.rb
CHANGED
data/spec/grammar/def_spec.rb
CHANGED
data/spec/grammar/false_spec.rb
CHANGED
data/spec/grammar/file_spec.rb
CHANGED
data/spec/grammar/gvar_spec.rb
CHANGED
data/spec/grammar/hash_spec.rb
CHANGED
data/spec/grammar/iasgn_spec.rb
CHANGED
data/spec/grammar/if_spec.rb
CHANGED
data/spec/grammar/iter_spec.rb
CHANGED
data/spec/grammar/ivar_spec.rb
CHANGED
data/spec/grammar/lambda_spec.rb
CHANGED
data/spec/grammar/lasgn_spec.rb
CHANGED
data/spec/grammar/line_spec.rb
CHANGED
data/spec/grammar/lvar_spec.rb
CHANGED
data/spec/grammar/masgn_spec.rb
CHANGED
data/spec/grammar/module_spec.rb
CHANGED
data/spec/grammar/nil_spec.rb
CHANGED
data/spec/grammar/not_spec.rb
CHANGED
data/spec/grammar/or_spec.rb
CHANGED
data/spec/grammar/return_spec.rb
CHANGED
data/spec/grammar/sclass_spec.rb
CHANGED
data/spec/grammar/self_spec.rb
CHANGED
data/spec/grammar/str_spec.rb
CHANGED
data/spec/grammar/super_spec.rb
CHANGED
data/spec/grammar/true_spec.rb
CHANGED
data/spec/grammar/undef_spec.rb
CHANGED
data/spec/grammar/unless_spec.rb
CHANGED