opal 0.6.3 → 0.7.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.spectator +2 -0
- data/.spectator-mspec +3 -0
- data/.travis.yml +8 -11
- data/CHANGELOG.md +33 -0
- data/CONTRIBUTING.md +8 -43
- data/Gemfile +15 -4
- data/Guardfile +77 -0
- data/README.md +15 -9
- data/Rakefile +36 -12
- data/benchmarks/operators.rb +11 -0
- data/bin/opal +10 -13
- data/bin/opal-build +4 -4
- data/bin/opal-mspec +10 -0
- data/bin/opal-repl +4 -3
- data/examples/sinatra/Gemfile +1 -1
- data/examples/sinatra/config.ru +3 -3
- data/lib/mspec/opal/main.rb.erb +2 -2
- data/lib/mspec/opal/rake_task.rb +31 -24
- data/lib/mspec/opal/runner.rb +18 -1
- data/lib/mspec/opal/sprockets.js +17 -0
- data/lib/opal.rb +1 -34
- data/lib/opal/builder.rb +92 -58
- data/lib/opal/builder_processors.rb +165 -0
- data/lib/opal/cli.rb +85 -144
- data/lib/opal/cli_options.rb +136 -90
- data/lib/opal/cli_runners.rb +10 -0
- data/lib/opal/cli_runners/nodejs.rb +56 -0
- data/lib/opal/cli_runners/phantom.js +35 -0
- data/lib/opal/cli_runners/phantomjs.rb +28 -0
- data/lib/opal/cli_runners/server.rb +54 -0
- data/lib/opal/compiler.rb +35 -16
- data/lib/opal/erb.rb +29 -15
- data/lib/opal/hike_path_finder.rb +18 -0
- data/lib/opal/nodes.rb +1 -0
- data/lib/opal/nodes/call.rb +107 -26
- data/lib/opal/nodes/call_special.rb +31 -6
- data/lib/opal/nodes/class.rb +2 -2
- data/lib/opal/nodes/constants.rb +5 -20
- data/lib/opal/nodes/def.rb +4 -4
- data/lib/opal/nodes/defined.rb +3 -3
- data/lib/opal/nodes/definitions.rb +1 -1
- data/lib/opal/nodes/for.rb +35 -0
- data/lib/opal/nodes/helpers.rb +2 -2
- data/lib/opal/nodes/iter.rb +3 -3
- data/lib/opal/nodes/literal.rb +10 -2
- data/lib/opal/nodes/masgn.rb +2 -2
- data/lib/opal/nodes/module.rb +2 -2
- data/lib/opal/nodes/scope.rb +1 -0
- data/lib/opal/nodes/singleton_class.rb +2 -2
- data/lib/opal/nodes/super.rb +2 -2
- data/lib/opal/nodes/top.rb +30 -3
- data/lib/opal/parser.rb +15 -1
- data/lib/opal/parser/grammar.rb +2571 -2452
- data/lib/opal/parser/grammar.y +37 -5
- data/lib/opal/parser/keywords.rb +2 -0
- data/lib/opal/parser/lexer.rb +21 -11
- data/lib/opal/path_reader.rb +28 -0
- data/lib/opal/paths.rb +38 -0
- data/lib/opal/source_map.rb +32 -15
- data/lib/opal/sprockets/environment.rb +9 -2
- data/lib/opal/sprockets/erb.rb +1 -2
- data/lib/opal/sprockets/path_reader.rb +34 -0
- data/lib/opal/sprockets/processor.rb +40 -39
- data/lib/opal/sprockets/server.rb +47 -33
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +10 -5
- data/opal/README.md +6 -0
- data/opal/corelib/array.rb +36 -4
- data/opal/corelib/array/inheritance.rb +6 -6
- data/opal/corelib/basic_object.rb +9 -9
- data/opal/corelib/boolean.rb +1 -1
- data/opal/corelib/class.rb +12 -12
- data/opal/corelib/dir.rb +20 -0
- data/opal/corelib/enumerable.rb +42 -42
- data/opal/corelib/enumerator.rb +1 -1
- data/opal/corelib/error.rb +2 -2
- data/opal/corelib/file.rb +56 -0
- data/opal/corelib/hash.rb +5 -5
- data/opal/corelib/helpers.rb +3 -3
- data/opal/corelib/io.rb +13 -10
- data/opal/corelib/kernel.rb +44 -68
- data/opal/corelib/method.rb +1 -1
- data/opal/corelib/module.rb +89 -114
- data/opal/corelib/nil_class.rb +1 -1
- data/opal/corelib/numeric.rb +27 -23
- data/opal/corelib/proc.rb +5 -5
- data/opal/corelib/range.rb +8 -4
- data/opal/corelib/regexp.rb +5 -5
- data/opal/corelib/runtime.js +589 -272
- data/opal/corelib/string.rb +52 -37
- data/opal/corelib/string/inheritance.rb +5 -5
- data/opal/corelib/time.rb +102 -52
- data/opal/corelib/variables.rb +3 -3
- data/opal/opal.rb +2 -0
- data/package.json +9 -0
- data/spec/filters/bugs/array.rb +0 -6
- data/spec/filters/bugs/language.rb +4 -0
- data/spec/filters/bugs/numeric.rb +7 -6
- data/spec/filters/bugs/opal.rb +2 -0
- data/spec/filters/bugs/regexp.rb +4 -0
- data/spec/filters/bugs/string.rb +0 -7
- data/spec/filters/bugs/stringscanner.rb +4 -1
- data/spec/filters/unsupported/private_methods.rb +2 -0
- data/spec/lib/builder_processors_spec.rb +27 -0
- data/spec/lib/builder_spec.rb +66 -0
- data/spec/{cli → lib}/cli_spec.rb +60 -5
- data/spec/{cli → lib}/compiler_spec.rb +66 -5
- data/spec/{cli → lib}/dependency_resolver_spec.rb +1 -1
- data/spec/lib/fixtures/no_requires.rb +1 -0
- data/spec/{cli → lib}/fixtures/opal_file.rb +0 -0
- data/spec/lib/fixtures/require_tree_test.rb +3 -0
- data/spec/lib/fixtures/required_tree_test/required_file1.rb +1 -0
- data/spec/lib/fixtures/required_tree_test/required_file2.rb +1 -0
- data/spec/lib/fixtures/requires.rb +7 -0
- data/spec/{cli → lib}/fixtures/sprockets_file.js.rb +0 -0
- data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
- data/spec/lib/hike_path_finder_spec.rb +23 -0
- data/spec/{cli → lib}/lexer_spec.rb +1 -1
- data/spec/{cli → lib}/parser/alias_spec.rb +1 -1
- data/spec/{cli → lib}/parser/and_spec.rb +1 -1
- data/spec/{cli → lib}/parser/attrasgn_spec.rb +1 -1
- data/spec/{cli → lib}/parser/begin_spec.rb +1 -1
- data/spec/{cli → lib}/parser/block_spec.rb +1 -1
- data/spec/{cli → lib}/parser/break_spec.rb +1 -1
- data/spec/{cli → lib}/parser/call_spec.rb +1 -1
- data/spec/{cli → lib}/parser/class_spec.rb +1 -1
- data/spec/{cli → lib}/parser/comments_spec.rb +1 -1
- data/spec/{cli → lib}/parser/def_spec.rb +1 -1
- data/spec/{cli → lib}/parser/if_spec.rb +1 -1
- data/spec/{cli → lib}/parser/iter_spec.rb +1 -1
- data/spec/{cli → lib}/parser/lambda_spec.rb +1 -1
- data/spec/{cli → lib}/parser/literal_spec.rb +1 -1
- data/spec/{cli → lib}/parser/masgn_spec.rb +1 -1
- data/spec/{cli → lib}/parser/module_spec.rb +1 -1
- data/spec/{cli → lib}/parser/not_spec.rb +1 -1
- data/spec/{cli → lib}/parser/op_asgn1_spec.rb +1 -1
- data/spec/{cli → lib}/parser/op_asgn2_spec.rb +1 -1
- data/spec/{cli → lib}/parser/or_spec.rb +1 -1
- data/spec/{cli → lib}/parser/return_spec.rb +1 -1
- data/spec/{cli → lib}/parser/sclass_spec.rb +1 -1
- data/spec/{cli → lib}/parser/string_spec.rb +8 -1
- data/spec/{cli → lib}/parser/super_spec.rb +1 -1
- data/spec/lib/parser/unary_spec.rb +48 -0
- data/spec/{cli → lib}/parser/undef_spec.rb +1 -1
- data/spec/{cli → lib}/parser/unless_spec.rb +1 -1
- data/spec/{cli → lib}/parser/variables_spec.rb +1 -1
- data/spec/{cli → lib}/parser/while_spec.rb +1 -1
- data/spec/{cli → lib}/parser/yield_spec.rb +1 -1
- data/spec/lib/path_reader_spec.rb +24 -0
- data/spec/lib/shared/path_finder_shared.rb +19 -0
- data/spec/lib/shared/path_reader_shared.rb +31 -0
- data/spec/lib/spec_helper.rb +9 -0
- data/spec/lib/sprockets/environment_spec.rb +30 -0
- data/spec/{cli → lib}/sprockets/erb_spec.rb +1 -1
- data/spec/lib/sprockets/path_reader_spec.rb +25 -0
- data/spec/{cli → lib}/sprockets/processor_spec.rb +9 -2
- data/spec/lib/sprockets/server_spec.rb +20 -0
- data/spec/opal/compiler/irb_spec.rb +11 -11
- data/spec/opal/core/fixtures/require_tree_files/file 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 3.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 4.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 5.rb +1 -0
- data/spec/opal/core/kernel/require_tree_spec.rb +7 -0
- data/spec/opal/core/kernel/respond_to_spec.rb +2 -2
- data/spec/opal/core/runtime/method_missing_spec.rb +19 -0
- data/spec/opal/core/source_map_spec.rb +2 -2
- data/spec/opal/core/string_spec.rb +11 -0
- data/spec/opal/stdlib/erb/erb_spec.rb +0 -1
- data/spec/opal/stdlib/thread/mutex_spec.rb +40 -0
- data/spec/opal/stdlib/thread/thread_queue_spec.rb +32 -0
- data/spec/opal/stdlib/thread/thread_spec.rb +60 -0
- data/spec/rubyspecs +54 -11
- data/spec/spec_helper.rb +18 -3
- data/spec/support/mspec_rspec_adapter.rb +33 -0
- data/spec/{cli/spec_helper.rb → support/parser_helpers.rb} +10 -10
- data/stdlib/README.md +3 -0
- data/stdlib/benchmark.rb +10 -0
- data/stdlib/date.rb +2 -2
- data/stdlib/dir.rb +1 -5
- data/stdlib/file.rb +1 -7
- data/stdlib/json.rb +10 -1
- data/stdlib/native.rb +5 -5
- data/stdlib/nodejs.rb +5 -0
- data/stdlib/nodejs/dir.rb +13 -0
- data/stdlib/nodejs/file.rb +98 -0
- data/stdlib/nodejs/fileutils.rb +26 -0
- data/stdlib/nodejs/io.rb +2 -0
- data/stdlib/nodejs/irb.rb +45 -0
- data/stdlib/nodejs/process.rb +16 -0
- data/stdlib/nodejs/require.rb +32 -0
- data/stdlib/nodejs/rubygems.rb +68 -0
- data/stdlib/nodejs/runtime.rb +25 -0
- data/stdlib/nodejs/yaml.rb +11 -0
- data/stdlib/opal-parser.rb +1 -2
- data/stdlib/opal-source-maps.rb +2 -0
- data/stdlib/phantomjs.rb +8 -0
- data/stdlib/process.rb +10 -0
- data/stdlib/promise.rb +12 -4
- data/stdlib/set.rb +27 -0
- data/stdlib/source_map.rb +5 -63
- data/stdlib/source_map/map.rb +220 -0
- data/stdlib/source_map/mapping.rb +26 -0
- data/stdlib/source_map/offset.rb +88 -0
- data/stdlib/source_map/version.rb +3 -0
- data/stdlib/source_map/vlq.rb +77 -101
- data/stdlib/sourcemap.rb +1 -0
- data/stdlib/strscan.rb +7 -1
- data/stdlib/template.rb +1 -1
- data/stdlib/thread.rb +147 -7
- metadata +238 -104
- data/lib/mspec/opal/mspec_fixes.rb +0 -87
- data/spec/cli/sprockets/environment_spec.rb +0 -14
- data/spec/filters/bugs/symbol.rb +0 -5
- data/spec/opal/core/kernel/warn_spec.rb +0 -83
- data/spec/opal/core/language/numbers_spec.rb +0 -60
- data/stdlib/opal-source-maps.js.erb +0 -2
- data/stdlib/source_map/generator.rb +0 -251
- data/stdlib/source_map/parser.rb +0 -102
@@ -0,0 +1 @@
|
|
1
|
+
p 2
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'lib/spec_helper'
|
2
|
+
require 'lib/shared/path_finder_shared'
|
3
|
+
require 'opal/hike_path_finder'
|
4
|
+
|
5
|
+
describe Opal::HikePathFinder do
|
6
|
+
subject(:path_finder) { described_class.new(root) }
|
7
|
+
let(:root) { File.expand_path('..', __FILE__) }
|
8
|
+
let(:path) { 'fixtures/opal_file' }
|
9
|
+
let(:full_path) { File.join(root, path + ext) }
|
10
|
+
let(:ext) { '.rb' }
|
11
|
+
|
12
|
+
include_examples :path_finder
|
13
|
+
|
14
|
+
context 'with absolute paths' do
|
15
|
+
it 'returns the path if exists' do
|
16
|
+
expect(path_finder.find(full_path)).to eq(full_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'gives nil if it is missing' do
|
20
|
+
expect(path_finder.find(full_path+'/not-real')).to eq(nil)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'support/parser_helpers'
|
2
2
|
|
3
3
|
describe "Strings" do
|
4
4
|
it "parses empty strings" do
|
@@ -237,6 +237,13 @@ describe "x-strings" do
|
|
237
237
|
}.should raise_error(Exception)
|
238
238
|
end
|
239
239
|
end
|
240
|
+
|
241
|
+
describe "contiguous strings" do
|
242
|
+
it "concatenates parts" do
|
243
|
+
parsed('"a" "b"').should == [:dstr, "a", [:str, "b"]]
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
240
247
|
end
|
241
248
|
|
242
249
|
describe "Heredocs" do
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'support/parser_helpers'
|
2
|
+
|
3
|
+
describe Opal::Parser do
|
4
|
+
describe '-@' do
|
5
|
+
context 'with an integer' do
|
6
|
+
it "parses unary op. with the right precedence" do
|
7
|
+
parsed("-1.hello").should == [:call, [:int, -1], :hello, [:arglist]]
|
8
|
+
end
|
9
|
+
|
10
|
+
it "parses unary op. as a method call" do
|
11
|
+
parsed("-1").should == [:int, -1]
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with a float' do
|
17
|
+
it "parses unary op. with the right precedence" do
|
18
|
+
parsed("-1.23.hello").should == [:call, [:float, -1.23], :hello, [:arglist]]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "parses unary op. as a method call" do
|
22
|
+
parsed("-1.23").should == [:float, -1.23]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '+@' do
|
28
|
+
context 'with an integer' do
|
29
|
+
it "parses unary op. with the right precedence" do
|
30
|
+
parsed("+1.hello").should == [:call, [:int, 1], :hello, [:arglist]]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "parses unary op. as a method call" do
|
34
|
+
parsed("-1").should == [:int, -1]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with a float' do
|
39
|
+
it "parses unary op. with the right precedence" do
|
40
|
+
parsed("+1.23.hello").should == [:call, [:float, 1.23], :hello, [:arglist]]
|
41
|
+
end
|
42
|
+
|
43
|
+
it "parses unary op. as a method call" do
|
44
|
+
parsed("-1.23").should == [:float, -1.23]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'lib/spec_helper'
|
2
|
+
require 'lib/shared/path_reader_shared'
|
3
|
+
require 'lib/shared/path_finder_shared'
|
4
|
+
require 'opal/path_reader'
|
5
|
+
|
6
|
+
|
7
|
+
describe Opal::PathReader do
|
8
|
+
subject(:file_reader) { described_class.new(path_finder) }
|
9
|
+
let(:path_finder) { double('path_finder') }
|
10
|
+
let(:path) { 'opal_file' }
|
11
|
+
let(:full_path) { File.expand_path('../fixtures/opal_file.rb', __FILE__) }
|
12
|
+
let(:contents) { File.read(full_path) }
|
13
|
+
|
14
|
+
before do
|
15
|
+
path_finder.stub(:find) {|path| nil}
|
16
|
+
path_finder.stub(:find).with(path).and_return(full_path)
|
17
|
+
path_finder.stub(:paths).and_return(Opal.paths)
|
18
|
+
end
|
19
|
+
|
20
|
+
include_examples :path_finder
|
21
|
+
include_examples :path_reader do
|
22
|
+
let(:path_reader) { file_reader }
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'lib/spec_helper'
|
2
|
+
|
3
|
+
shared_examples :path_finder do
|
4
|
+
# @param path
|
5
|
+
# the path we want to read
|
6
|
+
#
|
7
|
+
# @param full_path
|
8
|
+
# the expanded path that should be found
|
9
|
+
#
|
10
|
+
it 'returns the full path if the path exists' do
|
11
|
+
expect(path_finder.find(path)).to eq(full_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns nil if the path is missing' do
|
15
|
+
expect(path_finder.find('unexpected-path')).to eq(nil)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'lib/spec_helper'
|
2
|
+
|
3
|
+
# Below the helpers expected from a spec that
|
4
|
+
# includes these shared examples:
|
5
|
+
#
|
6
|
+
# @object [PathReader] path_reader the object under test
|
7
|
+
# @method [String] path the path we want to read
|
8
|
+
# @method [String] contents the contents we expect to be read
|
9
|
+
#
|
10
|
+
shared_examples :path_reader do
|
11
|
+
describe '#paths' do
|
12
|
+
it 'is an Enumberable' do
|
13
|
+
expect(path_reader.paths).to be_an(Enumerable)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'includes Opal.paths' do
|
17
|
+
paths = path_reader.paths.to_a
|
18
|
+
Opal.paths.each { |path| expect(paths).to include(path) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#read' do
|
23
|
+
it 'responds to #path' do
|
24
|
+
expect(path_reader.read(path)).to eq(contents)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns nil if the file is missing' do
|
28
|
+
expect(path_reader.read('unexpected-path!')).to be_nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'opal'
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
5
|
+
config.run_all_when_everything_filtered = true
|
6
|
+
config.filter_run :focus
|
7
|
+
config.order = 'random'
|
8
|
+
config.before { Opal.instance_variable_set('@paths', nil) }
|
9
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'lib/spec_helper'
|
2
|
+
require 'opal/sprockets/environment'
|
3
|
+
|
4
|
+
describe Opal::Environment do
|
5
|
+
let(:env) { described_class.new }
|
6
|
+
let(:logical_path) { 'sprockets_file' }
|
7
|
+
|
8
|
+
before { env.append_path File.expand_path('../../fixtures/', __FILE__) }
|
9
|
+
|
10
|
+
it 'compiles Ruby to JS' do
|
11
|
+
expect(env[logical_path].source).to include('$puts(')
|
12
|
+
expect(env[logical_path+'.js'].source).to include('$puts(')
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'require_tree sprockets directive' do
|
16
|
+
it 'is still supported' do
|
17
|
+
source = env['sprockets_require_tree_test'].source
|
18
|
+
expect(source).to include('required_file1')
|
19
|
+
expect(source).to include('required_file2')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'require_tree helper' do
|
24
|
+
it 'is handled by the processor' do
|
25
|
+
source = env['require_tree_test'].source
|
26
|
+
expect(source).to include('required_file1')
|
27
|
+
expect(source).to include('required_file2')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|