opal 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitmodules +27 -3
- data/.rspec +1 -1
- data/CHANGELOG.md +29 -5
- data/README.md +30 -3
- data/Rakefile +18 -9
- data/bin/opal +1 -1
- data/bin/opal-build +70 -7
- data/lib/mspec/opal/rake_task.rb +6 -9
- data/lib/opal/cli.rb +2 -2
- data/lib/opal/nodes/call.rb +1 -1
- data/lib/opal/nodes/def.rb +1 -1
- data/lib/opal/nodes/rescue.rb +19 -18
- data/lib/opal/parser/grammar.rb +8 -3
- data/lib/opal/parser/grammar.y +4 -0
- data/lib/opal/parser/lexer.rb +10 -5
- data/lib/opal/sprockets/environment.rb +9 -0
- data/lib/opal/sprockets/erb.rb +9 -1
- data/lib/opal/sprockets/processor.rb +10 -14
- data/lib/opal/util.rb +50 -15
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +4 -4
- data/opal/corelib/enumerable.rb +1 -1
- data/opal/corelib/enumerator.rb +7 -3
- data/opal/corelib/hash.rb +38 -14
- data/opal/corelib/kernel.rb +6 -2
- data/opal/corelib/module.rb +15 -1
- data/opal/corelib/runtime.js +32 -2
- data/opal/corelib/string.rb +103 -53
- data/opal/corelib/variables.rb +3 -3
- data/spec/cli/fixtures/sprockets_file.js.rb +3 -0
- data/spec/cli/parser/literal_spec.rb +5 -0
- data/spec/cli/sprockets/environment_spec.rb +14 -0
- data/spec/cli/sprockets/erb_spec.rb +25 -0
- data/spec/cli/sprockets/processor_spec.rb +28 -0
- data/spec/{opal/filters → filters}/bugs/array.rb +29 -9
- data/spec/{opal/filters → filters}/bugs/basic_object.rb +2 -0
- data/spec/{opal/filters → filters}/bugs/class.rb +1 -0
- data/spec/{opal/filters → filters}/bugs/enumerable.rb +6 -2
- data/spec/filters/bugs/enumerator.rb +3 -0
- data/spec/{opal/filters → filters}/bugs/hash.rb +6 -24
- data/spec/{opal/filters → filters}/bugs/kernel.rb +0 -0
- data/spec/{opal/filters → filters}/bugs/language.rb +14 -3
- data/spec/{opal/filters → filters}/bugs/math.rb +3 -1
- data/spec/{opal/filters → filters}/bugs/module.rb +0 -0
- data/spec/{opal/filters → filters}/bugs/nil.rb +0 -0
- data/spec/{opal/filters → filters}/bugs/numeric.rb +1 -1
- data/spec/{opal/filters → filters}/bugs/opal.rb +0 -0
- data/spec/filters/bugs/regexp.rb +7 -0
- data/spec/{opal/filters → filters}/bugs/set.rb +0 -0
- data/spec/{opal/filters → filters}/bugs/singleton.rb +0 -0
- data/spec/{opal/filters → filters}/bugs/string.rb +40 -13
- data/spec/{opal/filters → filters}/bugs/stringscanner.rb +1 -0
- data/spec/{opal/filters → filters}/bugs/struct.rb +7 -2
- data/spec/{opal/filters → filters}/bugs/symbol.rb +0 -0
- data/spec/{opal/filters → filters}/bugs/time.rb +23 -0
- data/spec/{opal/filters → filters}/bugs/unknown.rb +0 -0
- data/spec/{opal/filters → filters}/unsupported/encoding.rb +34 -1
- data/spec/{opal/filters → filters}/unsupported/enumerator.rb +1 -0
- data/spec/{opal/filters → filters}/unsupported/float.rb +0 -0
- data/spec/{opal/filters → filters}/unsupported/frozen.rb +3 -2
- data/spec/{opal/filters → filters}/unsupported/hash_compare_by_identity.rb +0 -0
- data/spec/{opal/filters → filters}/unsupported/integer_size.rb +0 -0
- data/spec/{opal/filters → filters}/unsupported/method_added.rb +0 -0
- data/spec/{opal/filters → filters}/unsupported/mutable_strings.rb +14 -0
- data/spec/{opal/filters → filters}/unsupported/private_constants.rb +0 -0
- data/spec/{opal/filters → filters}/unsupported/private_methods.rb +0 -0
- data/spec/{opal/filters → filters}/unsupported/random.rb +0 -0
- data/spec/{opal/filters → filters}/unsupported/ruby_exe.rb +0 -0
- data/spec/{opal/filters → filters}/unsupported/tainted.rb +11 -0
- data/spec/{opal/filters → filters}/unsupported/time.rb +0 -0
- data/spec/{opal/filters → filters}/unsupported/trusted.rb +14 -0
- data/spec/opal/core/kernel/methods_spec.rb +16 -2
- data/spec/opal/core/language/string_spec.rb +29 -1
- data/spec/opal/core/module/remove_const_spec.rb +1 -1
- data/spec/opal/stdlib/erb/erb_spec.rb +3 -3
- data/spec/opal/stdlib/native/native_reader_spec.rb +22 -0
- data/spec/opal/stdlib/native/native_writer_spec.rb +30 -0
- data/spec/rubyspecs +285 -0
- data/spec/{opal/spec_helper.rb → spec_helper.rb} +0 -0
- data/stdlib/native.rb +21 -0
- data/stdlib/opal-parser.rb +14 -3
- data/stdlib/promise.rb +2 -2
- metadata +113 -97
- data/spec/opal/filters/bugs/regexp.rb +0 -5
- data/spec/opal/rubyspecs +0 -285
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c3f8f806c3ccc492181271b934421d199875687
|
4
|
+
data.tar.gz: 1793e3beab6345556bcb5d9255cbf0bbf6463f68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d3c05b2ef2434e3056b58981e4851964e207d92a5936914e1a54d73f04be7fe9651d43981dd5596c6b6244d3b652395af4cd99944c302d83b385cecfa6e2806
|
7
|
+
data.tar.gz: a2a98bee95fceb779251cd2cea489fac101aa936e32ff3bccb9395056c4e848c5b5c7907a6648970f0e4fc3658dd3853bf28bdf5ceb7692eda825247511f5182
|
data/.gitignore
CHANGED
data/.gitmodules
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
-
[submodule "spec/
|
2
|
-
path = spec/
|
3
|
-
url =
|
1
|
+
[submodule "spec/corelib"]
|
2
|
+
path = spec/corelib
|
3
|
+
url = https://github.com/rubyspec/rubyspec
|
4
|
+
[submodule "spec/stdlib/rubysl-singleton"]
|
5
|
+
path = spec/stdlib/rubysl-singleton
|
6
|
+
url = https://github.com/rubysl/rubysl-singleton
|
7
|
+
[submodule "spec/stdlib/rubysl-observer"]
|
8
|
+
path = spec/stdlib/rubysl-observer
|
9
|
+
url = https://github.com/rubysl/rubysl-observer
|
10
|
+
[submodule "spec/stdlib/rubysl-strscan"]
|
11
|
+
path = spec/stdlib/rubysl-strscan
|
12
|
+
url = https://github.com/rubysl/rubysl-strscan
|
13
|
+
[submodule "spec/stdlib/rubysl-delegate"]
|
14
|
+
path = spec/stdlib/rubysl-delegate
|
15
|
+
url = https://github.com/rubysl/rubysl-delegate
|
16
|
+
[submodule "spec/stdlib/rubysl-erb"]
|
17
|
+
path = spec/stdlib/rubysl-erb
|
18
|
+
url = https://github.com/rubysl/rubysl-erb
|
19
|
+
[submodule "spec/stdlib/rubysl-set"]
|
20
|
+
path = spec/stdlib/rubysl-set
|
21
|
+
url = https://github.com/rubysl/rubysl-set
|
22
|
+
[submodule "spec/stdlib/rubysl-pathname"]
|
23
|
+
path = spec/stdlib/rubysl-pathname
|
24
|
+
url = https://github.com/rubysl/rubysl-pathname
|
25
|
+
[submodule "spec/stdlib/rubysl-date"]
|
26
|
+
path = spec/stdlib/rubysl-date
|
27
|
+
url = https://github.com/rubysl/rubysl-date
|
data/.rspec
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,35 @@
|
|
1
|
-
##
|
1
|
+
## 0.6.1 2014-04-15
|
2
|
+
|
3
|
+
* Updated RubySpecs to master and added `rubysl-*` specs. Thanks to Mike Owens (@mieko)
|
4
|
+
|
5
|
+
* Added `Kernel#require_remote(url)` in `opal-parser` that requires files with basic synchronous ajax
|
6
|
+
GET requests. It is used to load `<scripts type="text/ruby" src="…url…">`.
|
7
|
+
|
8
|
+
* Various parsing fixes (Hash parsing, `def` returns method name, cleanup `core/util`, Enumerator fixes)
|
9
|
+
|
10
|
+
* Added `#native_reader`, `#native_writer` and `#native_accessor`as class methods
|
11
|
+
donated by `include Native`
|
12
|
+
|
13
|
+
* Added specs for Sprockets' processors (both .js.rb and .opalerb), backported from `opal-rails`
|
14
|
+
|
15
|
+
* Set 2.1.1 as RUBY_VERSION
|
16
|
+
|
17
|
+
* Add `opal-build` command utility to easily build libraries to js
|
18
|
+
|
19
|
+
* Add `opal-repl` to gemspec executables,
|
20
|
+
previously was only available by using Opal from source
|
21
|
+
|
22
|
+
* Fix parsing `=>` in hash literals where it would sometimes incorrectly
|
23
|
+
parse as a key name.
|
24
|
+
|
25
|
+
## 0.6.0 2014-03-05
|
2
26
|
|
3
27
|
* Fix parsing of escapes in single-strings ('foo\n'). Only ' and \
|
4
28
|
characters now get escaped in single quoted strings. Also, more escape
|
5
29
|
sequences in double-quoted strings are now supported: `\a`, `\v`, `\f`,
|
6
30
|
`\e`, `\s`, octal (`\314`), hex (`\xff`) and unicode (`\u1234`).
|
7
31
|
|
8
|
-
* Sourcemaps revamp. Lexer now tracks column and line info for
|
32
|
+
* Sourcemaps revamp. Lexer now tracks column and line info for every token to
|
9
33
|
produce much more accurate sourcemaps. All method calls are now located on
|
10
34
|
the correct source line, and multi-line xstrings are now split to generate
|
11
35
|
a map line-to-line for long inline javascript parts.
|
@@ -46,7 +70,7 @@
|
|
46
70
|
* Add `time.rb` to stdlib and moved `Time.parse()` and `Time.iso8601()`
|
47
71
|
methods there.
|
48
72
|
|
49
|
-
* `!` is now treated as
|
73
|
+
* `!` is now treated as an unary method call on the object. Opal now parsed
|
50
74
|
`!` as a def method name, and implements the method on `BasicObject`,
|
51
75
|
`NilClass` and `Boolean`.
|
52
76
|
|
@@ -67,7 +91,7 @@
|
|
67
91
|
`#to_f`, `#clone`, `#split`.
|
68
92
|
|
69
93
|
* Fix `Array` method compliance: `#first`, `#fetch`, `#insert`, `#delete_at`,
|
70
|
-
`#last
|
94
|
+
`#last`, `#splice`, `.try_convert`.
|
71
95
|
|
72
96
|
* Fix compliance of `Kernel#extend` and ensure it calls `#extended()` hook.
|
73
97
|
|
@@ -92,7 +116,7 @@
|
|
92
116
|
* Support any Tilt template for `index_path` in `Opal::Server`. All index
|
93
117
|
files are now run through `Tilt` (now supports haml etc).
|
94
118
|
|
95
|
-
* Fix code generation of `op_asgn_1` calls (foo[val] += 10).
|
119
|
+
* Fix code generation of `op_asgn_1` calls (`foo[val] += 10`).
|
96
120
|
|
97
121
|
* Add `base64` to stdlib.
|
98
122
|
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Opal is a ruby to javascript source-to-source compiler. It also has an
|
|
8
8
|
implementation of the ruby corelib.
|
9
9
|
|
10
10
|
Opal is [hosted on github](http://github.com/opal/opal), and there
|
11
|
-
is a Freenode IRC channel at [#opal](http://webchat.freenode.net/?channels=opal),
|
11
|
+
is a Freenode IRC channel at [#opal](http://webchat.freenode.net/?channels=opal),
|
12
12
|
ask questions on [stackoverflow#opalrb](http://stackoverflow.com/questions/ask?tags=opalrb).
|
13
13
|
|
14
14
|
|
@@ -58,17 +58,36 @@ First, install dependencies:
|
|
58
58
|
|
59
59
|
$ bundle install
|
60
60
|
|
61
|
-
|
61
|
+
RubySpec related repos must be cloned as a gitsubmodules:
|
62
62
|
|
63
63
|
$ git submodule update --init
|
64
64
|
|
65
|
-
|
65
|
+
The test suite can be run using (requires [phantomjs][]):
|
66
66
|
|
67
67
|
$ rake
|
68
68
|
|
69
|
+
This will command will run all RSpec and MSpec examples in sequence.
|
70
|
+
|
71
|
+
### MSpec
|
72
|
+
|
73
|
+
[MSpec][] tests can be run with:
|
74
|
+
|
75
|
+
$ rake mspec
|
76
|
+
|
69
77
|
Alternatively, you can just load up a rack instance using `rackup spec/config.ru`, and
|
70
78
|
visit `http://localhost:9292/` in any web browser.
|
71
79
|
|
80
|
+
### Rspec
|
81
|
+
|
82
|
+
[RSpec][] tests can be run with
|
83
|
+
|
84
|
+
$ rake rspec
|
85
|
+
|
86
|
+
Alternatively [spectator][] can be used in an autotest fashion with this command:
|
87
|
+
|
88
|
+
BASE_DIR_GLOB='lib/opal' SPEC_DIR_GLOB='spec/cli' spectator
|
89
|
+
|
90
|
+
|
72
91
|
## Code Overview
|
73
92
|
|
74
93
|
What code is supposed to run where?
|
@@ -95,6 +114,10 @@ StringScanner, Date, etc.
|
|
95
114
|
|
96
115
|
### spec
|
97
116
|
|
117
|
+
* **rubyspecs** (file) a whitelist of RubySpec files to be ran
|
118
|
+
* **corelib** RubySpec examples (submodule)
|
119
|
+
* **stdlib** `rubysl-*` examples (submodules)
|
120
|
+
* **filters** The list of MSpec/RubySpec examples that are either bugs or unsupported
|
98
121
|
* **opal** opal additions/special behaviour in the runtime/corelib
|
99
122
|
* **cli** specs for opal lib (parser, lexer, grammar, compiler etc)
|
100
123
|
|
@@ -145,3 +168,7 @@ THE SOFTWARE.
|
|
145
168
|
|
146
169
|
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/opal/opal/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
147
170
|
|
171
|
+
[phantomjs]: http://phantomjs.org
|
172
|
+
[spectator]: https://github.com/elia/spectator#readme
|
173
|
+
[MSpec]: https://github.com/rubyspec/mspec#readme
|
174
|
+
[RSpec]: https://github.com/rspec/rspec#readme
|
data/Rakefile
CHANGED
@@ -15,20 +15,29 @@ MSpec::Opal::RakeTask.new(:mspec)
|
|
15
15
|
task :default => [:rspec, :mspec]
|
16
16
|
|
17
17
|
|
18
|
-
desc
|
18
|
+
desc <<-DESC
|
19
|
+
Build *corelib* and *stdlib* to "build/"
|
20
|
+
|
21
|
+
You can restrict the file list with the FILES env var (comma separated)
|
22
|
+
and the destination dir with the DIR env var.
|
23
|
+
|
24
|
+
Example: rake dist DIR=/tmp/foo FILES='opal.rb,base64.rb'
|
25
|
+
DESC
|
19
26
|
task :dist do
|
20
27
|
require 'opal/util'
|
21
28
|
|
22
29
|
Opal::Processor.arity_check_enabled = false
|
23
30
|
Opal::Processor.const_missing_enabled = false
|
24
|
-
|
25
31
|
env = Opal::Environment.new
|
26
32
|
|
27
|
-
|
28
|
-
|
29
|
-
|
33
|
+
build_dir = ENV['DIR'] || 'build'
|
34
|
+
files = ENV['FILES'] ? ENV['FILES'].split(',') :
|
35
|
+
Dir['{opal,stdlib}/*.rb'].map { |lib| File.basename(lib, '.rb') }
|
36
|
+
|
37
|
+
Dir.mkdir build_dir unless File.directory? build_dir
|
38
|
+
width = files.map(&:size).max
|
30
39
|
|
31
|
-
|
40
|
+
files.each do |lib|
|
32
41
|
print "* building #{lib}...".ljust(width+'* building ... '.size)
|
33
42
|
$stdout.flush
|
34
43
|
|
@@ -36,9 +45,9 @@ task :dist do
|
|
36
45
|
min = Opal::Util.uglify src
|
37
46
|
gzp = Opal::Util.gzip min
|
38
47
|
|
39
|
-
File.open("
|
40
|
-
File.open("
|
41
|
-
File.open("
|
48
|
+
File.open("#{build_dir}/#{lib}.js", 'w+') { |f| f << src }
|
49
|
+
File.open("#{build_dir}/#{lib}.min.js", 'w+') { |f| f << min } if min
|
50
|
+
File.open("#{build_dir}/#{lib}.min.js.gz", 'w+') { |f| f << gzp } if gzp
|
42
51
|
|
43
52
|
print "done. ("
|
44
53
|
print "development: #{('%.2f' % (src.size/1000.0)).rjust(6)}KB"
|
data/bin/opal
CHANGED
data/bin/opal-build
CHANGED
@@ -1,14 +1,77 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'optparse'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
module Opal
|
6
|
+
class BuilderOptions < OptionParser
|
7
|
+
def initialize
|
8
|
+
@options = {}
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
super do |opts|
|
11
|
+
opts.banner = 'Usage: opal-build [options] -- [libname]'
|
12
|
+
|
13
|
+
opts.separator ''
|
14
|
+
opts.separator 'Options:'
|
15
|
+
|
16
|
+
opts.on("-h", "--help", "Show this message") do
|
17
|
+
puts opts
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on('-g', '--gem GEM_NAME', String,
|
22
|
+
'Adds the specified GEM_NAME to Opal\'s load path.',
|
23
|
+
'E.g.: opal-build --require opal-browser browser`',
|
24
|
+
'Will build browser.rb from the Opal gem opal-browser') do |g|
|
25
|
+
options[:gems] ||= []
|
26
|
+
options[:gems] << g
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on('-s', '--stub STUB', String) do |stub|
|
30
|
+
options[:stubs] ||= []
|
31
|
+
options[:stubs] << stub
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on('-r', '--require LIBRARY', String,
|
35
|
+
'Require the library before executing your script',
|
36
|
+
'E.g.: opal-build --require opal-browser browser`',
|
37
|
+
'Will build browser.rb from the Opal gem opal-browser') do |library|
|
38
|
+
options[:requires] ||= []
|
39
|
+
options[:requires] << library
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on('-o', '--output FILE', String,
|
43
|
+
'Write the built lib to a file (defaults to STDOUT)') do |file|
|
44
|
+
options[:output] = file
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
attr_reader :options
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
option_parser = Opal::BuilderOptions.new
|
54
|
+
option_parser.parse!
|
55
|
+
|
56
|
+
if ARGV.empty?
|
57
|
+
puts options
|
58
|
+
else
|
59
|
+
require 'opal'
|
60
|
+
options = option_parser.options
|
61
|
+
|
62
|
+
if options[:gems]
|
63
|
+
require 'rubygems'
|
64
|
+
options[:gems].each { |gem_name| Opal.use_gem gem_name }
|
65
|
+
end
|
66
|
+
|
67
|
+
if options[:requires]
|
68
|
+
options[:requires].each { |required_lib| require required_lib }
|
69
|
+
end
|
70
|
+
|
71
|
+
lib_name = ARGV.first
|
72
|
+
|
73
|
+
output = options[:output] ? File.open(options[:output], 'w') : $stdout
|
74
|
+
output.puts Opal::Builder.build(lib_name.dup.untaint)
|
10
75
|
end
|
11
76
|
|
12
|
-
require_file = ARGV[1..-1].last || gem_name.dup.untaint.gsub('-','/')
|
13
|
-
puts Opal::Builder.build require_file
|
14
77
|
|
data/lib/mspec/opal/rake_task.rb
CHANGED
@@ -5,7 +5,7 @@ class Opal::Nodes::CallNode
|
|
5
5
|
add_special :language_version do
|
6
6
|
if meth == :language_version and scope.top?
|
7
7
|
lang_type = arglist[2][1]
|
8
|
-
target = "
|
8
|
+
target = "corelib/language/versions/#{lang_type}_1.9"
|
9
9
|
|
10
10
|
if File.exist?(target)
|
11
11
|
compiler.requires << target
|
@@ -25,7 +25,7 @@ require 'webrick'
|
|
25
25
|
module MSpec
|
26
26
|
module Opal
|
27
27
|
DEFAULT_PATTERN = 'spec/opal/{parser,core,compiler,stdlib}/**/*_spec.rb'
|
28
|
-
DEFAULT_BASEDIR = 'spec
|
28
|
+
DEFAULT_BASEDIR = 'spec'
|
29
29
|
|
30
30
|
require 'rake'
|
31
31
|
require 'rake/tasklib'
|
@@ -111,7 +111,6 @@ module MSpec
|
|
111
111
|
@pattern = pattern || DEFAULT_PATTERN
|
112
112
|
@basedir = basedir = File.expand_path(basedir || DEFAULT_BASEDIR)
|
113
113
|
append_path basedir
|
114
|
-
append_path "#{basedir}/rubyspec"
|
115
114
|
use_gem 'mspec'
|
116
115
|
|
117
116
|
stubs.each do |asset|
|
@@ -158,9 +157,8 @@ module MSpec
|
|
158
157
|
end
|
159
158
|
|
160
159
|
def rubyspec_paths
|
161
|
-
rubyspec_dir = "#{basedir}/rubyspec"
|
162
160
|
rubyspec_white_list.map do |path|
|
163
|
-
dirname = File.join
|
161
|
+
dirname = File.join([basedir, path])
|
164
162
|
if File.directory? dirname
|
165
163
|
rubyspec_paths_in_dir(dirname, path)
|
166
164
|
else
|
@@ -178,9 +176,9 @@ module MSpec
|
|
178
176
|
end
|
179
177
|
|
180
178
|
def rubyspec_white_list
|
181
|
-
File.read("#{basedir}/rubyspecs").split("\n").
|
182
|
-
line.
|
183
|
-
end
|
179
|
+
File.read("#{basedir}/rubyspecs").split("\n").map do |line|
|
180
|
+
line.sub(/#.*/, '').strip
|
181
|
+
end.reject(&:empty?)
|
184
182
|
end
|
185
183
|
|
186
184
|
def files_to_run(pattern=nil)
|
@@ -251,4 +249,3 @@ module MSpec
|
|
251
249
|
|
252
250
|
end
|
253
251
|
end
|
254
|
-
|
data/lib/opal/cli.rb
CHANGED
@@ -76,7 +76,7 @@ module Opal
|
|
76
76
|
begin
|
77
77
|
stdin, stdout, stderr = Open3.popen3('node')
|
78
78
|
rescue Errno::ENOENT
|
79
|
-
raise
|
79
|
+
raise MissingNodeJS, 'Please install Node.js to be able to run Opal scripts.'
|
80
80
|
end
|
81
81
|
|
82
82
|
stdin.write code
|
@@ -88,7 +88,7 @@ module Opal
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
class
|
91
|
+
class MissingNodeJS < StandardError
|
92
92
|
end
|
93
93
|
|
94
94
|
def start_server
|
data/lib/opal/nodes/call.rb
CHANGED
@@ -98,7 +98,7 @@ module Opal
|
|
98
98
|
if SPECIALS.include? meth
|
99
99
|
if result = __send__("handle_#{meth}")
|
100
100
|
push result
|
101
|
-
|
101
|
+
return true
|
102
102
|
end
|
103
103
|
elsif RuntimeHelpers.compatible?(recvr, meth, arglist)
|
104
104
|
push(RuntimeHelpers.new(@sexp, @level, @compiler).compile)
|
data/lib/opal/nodes/def.rb
CHANGED
data/lib/opal/nodes/rescue.rb
CHANGED
@@ -91,16 +91,17 @@ module Opal
|
|
91
91
|
|
92
92
|
def compile
|
93
93
|
push "if ("
|
94
|
-
|
95
|
-
|
96
|
-
push
|
97
|
-
|
98
|
-
push
|
94
|
+
if rescue_exprs.empty?
|
95
|
+
# if no expressions are given, then catch all errors
|
96
|
+
push "true"
|
97
|
+
else
|
98
|
+
push "$opal.$rescue($err, ["
|
99
|
+
rescue_exprs.each_with_index do |rexpr, idx|
|
100
|
+
push ', ' unless idx == 0
|
101
|
+
push expr(rexpr)
|
102
|
+
end
|
103
|
+
push "])"
|
99
104
|
end
|
100
|
-
|
101
|
-
# if no classes are given, then catch all errors
|
102
|
-
push "true" if rescue_classes.empty?
|
103
|
-
|
104
105
|
push ") {"
|
105
106
|
|
106
107
|
if variable = rescue_variable
|
@@ -112,18 +113,18 @@ module Opal
|
|
112
113
|
line "}"
|
113
114
|
end
|
114
115
|
|
115
|
-
def rescue_variable
|
116
|
-
variable
|
116
|
+
def rescue_variable?(variable)
|
117
|
+
Sexp === variable and [:lasgn, :iasgn].include?(variable.type)
|
118
|
+
end
|
117
119
|
|
118
|
-
|
119
|
-
|
120
|
-
end
|
120
|
+
def rescue_variable
|
121
|
+
rescue_variable?(args.last) ? args.last.dup : nil
|
121
122
|
end
|
122
123
|
|
123
|
-
def
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
def rescue_exprs
|
125
|
+
exprs = args.dup
|
126
|
+
exprs.pop if rescue_variable?(exprs.last)
|
127
|
+
exprs.children
|
127
128
|
end
|
128
129
|
|
129
130
|
def rescue_body
|