opal 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +3 -0
- data/.travis.yml +0 -4
- data/README.md +6 -0
- data/Rakefile +30 -6
- data/bin/opal +6 -82
- data/corelib/{opal/array.rb → array.rb} +40 -56
- data/corelib/{opal/basic_object.rb → basic_object.rb} +2 -2
- data/corelib/{opal/boolean.rb → boolean.rb} +0 -8
- data/corelib/class.rb +47 -0
- data/corelib/{opal/comparable.rb → comparable.rb} +0 -0
- data/corelib/{opal/enumerable.rb → enumerable.rb} +208 -141
- data/corelib/{opal/enumerator.rb → enumerator.rb} +3 -3
- data/corelib/{opal/error.rb → error.rb} +1 -0
- data/corelib/{opal/hash.rb → hash.rb} +67 -56
- data/corelib/io.rb +39 -0
- data/corelib/{opal/kernel.rb → kernel.rb} +35 -31
- data/corelib/{opal/class.rb → module.rb} +29 -57
- data/corelib/native.rb +148 -0
- data/corelib/{opal/nil_class.rb → nil_class.rb} +2 -10
- data/corelib/{opal/numeric.rb → numeric.rb} +39 -14
- data/corelib/opal.rb +42 -25
- data/corelib/{opal/proc.rb → proc.rb} +3 -3
- data/corelib/{opal/range.rb → range.rb} +5 -1
- data/corelib/{opal/regexp.rb → regexp.rb} +0 -0
- data/corelib/{opal/runtime.js → runtime.js} +96 -188
- data/corelib/{opal/string.rb → string.rb} +20 -15
- data/corelib/struct.rb +139 -0
- data/corelib/{opal/time.rb → time.rb} +0 -0
- data/lib/opal.rb +4 -0
- data/lib/opal/cli.rb +79 -32
- data/lib/opal/cli_options.rb +91 -0
- data/lib/opal/erb.rb +41 -8
- data/lib/opal/grammar.rb +24 -10
- data/lib/opal/grammar.y +15 -4
- data/lib/opal/grammar_helpers.rb +4 -0
- data/lib/opal/lexer.rb +214 -143
- data/lib/opal/parser.rb +596 -562
- data/lib/opal/require_parser.rb +1 -1
- data/lib/opal/source_map.rb +15 -30
- data/lib/opal/target_scope.rb +24 -5
- data/lib/opal/version.rb +1 -1
- data/mri_spec/cli_spec.rb +18 -0
- data/mri_spec/fixtures/opal_file.rb +2 -0
- data/mri_spec/spec_helper.rb +17 -0
- data/opal.gemspec +5 -2
- data/spec/{rubyspec/filters → filters}/bugs/alias.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/ancestors.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array.rb +0 -0
- data/spec/filters/bugs/array/combination.rb +11 -0
- data/spec/filters/bugs/array/count.rb +3 -0
- data/spec/filters/bugs/array/delete_if.rb +3 -0
- data/spec/filters/bugs/array/drop.rb +3 -0
- data/spec/filters/bugs/array/drop_while.rb +5 -0
- data/spec/filters/bugs/array/eql.rb +3 -0
- data/spec/filters/bugs/array/flatten.rb +9 -0
- data/spec/filters/bugs/array/minus.rb +5 -0
- data/spec/filters/bugs/array/multipliy.rb +9 -0
- data/spec/filters/bugs/array/new.rb +3 -0
- data/spec/filters/bugs/array/pop.rb +6 -0
- data/spec/filters/bugs/array/rassoc.rb +4 -0
- data/spec/filters/bugs/array/rindex.rb +6 -0
- data/spec/filters/bugs/array/select.rb +3 -0
- data/spec/filters/bugs/array/shift.rb +7 -0
- data/spec/filters/bugs/array/shuffle.rb +11 -0
- data/spec/filters/bugs/array/slice.rb +7 -0
- data/spec/filters/bugs/array/take.rb +3 -0
- data/spec/filters/bugs/array/to_a.rb +3 -0
- data/spec/filters/bugs/array/try_convert.rb +7 -0
- data/spec/filters/bugs/array/uniq.rb +10 -0
- data/spec/filters/bugs/array/zip.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_delete.rb +1 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_fetch.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_first.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_flatten.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_intersection.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_join.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/break.rb +0 -0
- data/spec/filters/bugs/case.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/coerce_integer.rb +0 -0
- data/spec/filters/bugs/enumerable_sort_by.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/kernel/instance_variables.rb +0 -0
- data/spec/filters/bugs/kernel/rand.rb +4 -0
- data/spec/filters/bugs/language/array.rb +3 -0
- data/spec/filters/bugs/language/block.rb +6 -0
- data/spec/filters/bugs/language/break.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class_variables.rb +0 -0
- data/spec/filters/bugs/language/def.rb +27 -0
- data/spec/filters/bugs/language/defined.rb +3 -0
- data/spec/filters/bugs/language/ensure.rb +4 -0
- data/spec/filters/bugs/language/execution.rb +4 -0
- data/spec/filters/bugs/language/for.rb +18 -0
- data/spec/filters/bugs/language/if.rb +13 -0
- data/spec/filters/bugs/language/loop.rb +4 -0
- data/spec/filters/bugs/language/metaclass.rb +14 -0
- data/spec/filters/bugs/language/module.rb +6 -0
- data/spec/filters/bugs/language/next.rb +3 -0
- data/spec/filters/bugs/language/or.rb +3 -0
- data/spec/filters/bugs/language/order.rb +4 -0
- data/spec/filters/bugs/language/precedence.rb +10 -0
- data/spec/filters/bugs/language/proc.rb +24 -0
- data/spec/filters/bugs/language/redo.rb +5 -0
- data/spec/filters/bugs/language/rescue.rb +9 -0
- data/spec/filters/bugs/language/retry.rb +5 -0
- data/spec/filters/bugs/language/send.rb +10 -0
- data/spec/filters/bugs/language/super.rb +9 -0
- data/spec/filters/bugs/language/until.rb +8 -0
- data/spec/filters/bugs/language/variables.rb +37 -0
- data/spec/filters/bugs/language/while.rb +6 -0
- data/spec/filters/bugs/language/yield.rb +5 -0
- data/spec/{rubyspec/filters → filters}/bugs/module/class_variables.rb +0 -0
- data/spec/filters/bugs/module/method_defined.rb +6 -0
- data/spec/filters/bugs/parser.rb +10 -0
- data/spec/{rubyspec/filters → filters}/bugs/public_methods.rb +1 -0
- data/spec/filters/bugs/return.rb +7 -0
- data/spec/filters/bugs/singleton/instance.rb +4 -0
- data/spec/filters/bugs/source_map.rb +3 -0
- data/spec/filters/bugs/string/center.rb +4 -0
- data/spec/filters/bugs/string/lines.rb +3 -0
- data/spec/{rubyspec/filters → filters}/mspec/mocks.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/ruby_exe.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/should_receive.rb +0 -0
- data/spec/{rubyspec/filters → filters}/parser/block_args.rb +0 -0
- data/spec/{rubyspec/filters → filters}/unsupported/array_subclasses.rb +1 -0
- data/spec/filters/unsupported/frozen.rb +32 -0
- data/spec/filters/unsupported/immutable_strings.rb +3 -0
- data/spec/filters/unsupported/tainted.rb +17 -0
- data/spec/filters/unsupported/trusted.rb +15 -0
- data/spec/opal/class/constants_spec.rb +7 -0
- data/spec/opal/erb/erb_spec.rb +7 -1
- data/spec/opal/erb/inline_block.opalerb +3 -0
- data/spec/opal/hash/allocate_spec.rb +16 -0
- data/spec/opal/hash/new_spec.rb +10 -0
- data/spec/opal/hash/to_s_spec.rb +9 -0
- data/spec/opal/kernel/instance_variable_defined_spec.rb +15 -0
- data/spec/opal/kernel/rand_spec.rb +5 -5
- data/spec/opal/kernel/respond_to_spec.rb +14 -1
- data/spec/opal/language/block_spec.rb +13 -0
- data/spec/opal/language/rescue_spec.rb +27 -0
- data/spec/opal/language/return_spec.rb +38 -0
- data/spec/opal/language/singleton_class_spec.rb +13 -0
- data/spec/opal/language/super_spec.rb +99 -0
- data/spec/opal/language/variables_spec.rb +20 -0
- data/spec/opal/module/attr_accessor_spec.rb +8 -0
- data/spec/opal/module/constants_spec.rb +2 -2
- data/spec/opal/native/alias_native_spec.rb +18 -0
- data/spec/opal/native/each_spec.rb +14 -0
- data/spec/opal/native/element_reference_spec.rb +14 -0
- data/spec/opal/native/method_missing_spec.rb +39 -0
- data/spec/opal/native/new_spec.rb +19 -0
- data/spec/opal/native/nil_spec.rb +14 -0
- data/spec/opal/runtime2/class_hierarchy_spec.rb +2 -2
- data/spec/opal/source_map_spec.rb +3 -7
- data/spec/ospec/main.rb.erb +2 -5
- data/spec/parser/alias_spec.rb +4 -4
- data/spec/parser/and_spec.rb +2 -2
- data/spec/parser/array_spec.rb +6 -6
- data/spec/parser/attrasgn_spec.rb +8 -8
- data/spec/parser/begin_spec.rb +11 -11
- data/spec/parser/block_spec.rb +3 -3
- data/spec/parser/break_spec.rb +4 -4
- data/spec/parser/call_spec.rb +50 -48
- data/spec/parser/class_spec.rb +2 -2
- data/spec/parser/const_spec.rb +1 -1
- data/spec/parser/cvar_spec.rb +1 -1
- data/spec/parser/def_spec.rb +5 -5
- data/spec/parser/gvar_spec.rb +2 -2
- data/spec/parser/hash_spec.rb +4 -4
- data/spec/parser/iasgn_spec.rb +3 -3
- data/spec/parser/if_spec.rb +6 -6
- data/spec/parser/iter_spec.rb +6 -6
- data/spec/parser/lambda_spec.rb +5 -5
- data/spec/parser/lasgn_spec.rb +2 -2
- data/spec/parser/line_spec.rb +2 -2
- data/spec/parser/lvar_spec.rb +5 -5
- data/spec/parser/masgn_spec.rb +1 -1
- data/spec/parser/module_spec.rb +2 -2
- data/spec/parser/not_spec.rb +4 -4
- data/spec/parser/op_asgn1_spec.rb +2 -2
- data/spec/parser/op_asgn2_spec.rb +2 -2
- data/spec/parser/or_spec.rb +2 -2
- data/spec/parser/parse_spec.rb +66 -0
- data/spec/parser/parser_spec.rb +32 -38
- data/spec/parser/regexp_spec.rb +4 -4
- data/spec/parser/return_spec.rb +4 -4
- data/spec/parser/sclass_spec.rb +4 -4
- data/spec/parser/str_spec.rb +3 -3
- data/spec/parser/super_spec.rb +6 -6
- data/spec/parser/undef_spec.rb +3 -3
- data/spec/parser/unless_spec.rb +4 -4
- data/spec/parser/while_spec.rb +3 -3
- data/spec/parser/xstr_spec.rb +3 -3
- data/spec/parser/yield_spec.rb +6 -6
- data/spec/rubyspec/core/array/drop_spec.rb +1 -1
- data/spec/rubyspec/core/array/keep_if_spec.rb +1 -3
- data/spec/rubyspec/core/array/length_spec.rb +1 -3
- data/spec/rubyspec/core/array/map_spec.rb +2 -6
- data/spec/rubyspec/core/array/minus_spec.rb +3 -3
- data/spec/rubyspec/core/array/multiply_spec.rb +14 -16
- data/spec/rubyspec/core/array/new_spec.rb +3 -5
- data/spec/rubyspec/core/array/plus_spec.rb +2 -2
- data/spec/rubyspec/core/array/pop_spec.rb +4 -4
- data/spec/rubyspec/core/array/rassoc_spec.rb +2 -2
- data/spec/rubyspec/core/array/reject_spec.rb +2 -6
- data/spec/rubyspec/core/array/replace_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_each_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_spec.rb +4 -4
- data/spec/rubyspec/core/array/rindex_spec.rb +1 -1
- data/spec/rubyspec/core/array/select_spec.rb +3 -7
- data/spec/rubyspec/core/array/shared/collect.rb +7 -0
- data/spec/rubyspec/core/array/shared/index.rb +1 -1
- data/spec/rubyspec/core/array/shared/keep_if.rb +3 -0
- data/spec/rubyspec/core/array/shared/length.rb +3 -0
- data/spec/rubyspec/core/array/shared/replace.rb +3 -0
- data/spec/rubyspec/core/array/shared/slice.rb +3 -0
- data/spec/rubyspec/core/array/shuffle_spec.rb +1 -1
- data/spec/rubyspec/core/array/size_spec.rb +1 -3
- data/spec/rubyspec/core/array/slice_spec.rb +4 -6
- data/spec/rubyspec/core/array/sort_spec.rb +2 -2
- data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
- data/spec/rubyspec/core/array/try_convert_spec.rb +7 -7
- data/spec/rubyspec/core/array/uniq_spec.rb +7 -7
- data/spec/rubyspec/core/array/zip_spec.rb +1 -1
- data/spec/rubyspec/core/enumerable/collect_spec.rb +24 -0
- data/spec/rubyspec/core/enumerable/count_spec.rb +35 -19
- data/spec/rubyspec/core/enumerable/find_spec.rb +5 -0
- data/spec/rubyspec/core/hash/each_pair_spec.rb +7 -7
- data/spec/rubyspec/core/hash/each_spec.rb +13 -7
- data/spec/rubyspec/core/module/method_defined_spec.rb +4 -4
- data/spec/rubyspec/core/module/public_method_defined_spec.rb +19 -0
- data/spec/rubyspec/core/module/remove_const_spec.rb +23 -0
- data/spec/rubyspec/core/numeric/step_spec.rb +14 -0
- data/spec/rubyspec/core/string/center_spec.rb +43 -65
- data/spec/rubyspec/core/string/lines_spec.rb +1 -1
- data/spec/rubyspec/core/string/ljust_spec.rb +25 -9
- data/spec/rubyspec/core/string/rjust_spec.rb +26 -10
- data/spec/rubyspec/core/struct/fixtures/classes.rb +26 -0
- data/spec/rubyspec/core/struct/initialize_spec.rb +11 -0
- data/spec/rubyspec/core/struct/new_spec.rb +24 -0
- data/spec/rubyspec/fixtures/constants.rb +7 -0
- data/spec/rubyspec/language/break_spec.rb +1 -1
- data/spec/rubyspec/language/case_spec.rb +30 -30
- data/spec/rubyspec/language/def_spec.rb +34 -34
- data/spec/rubyspec/language/defined_spec.rb +2 -2
- data/spec/rubyspec/language/ensure_spec.rb +2 -2
- data/spec/rubyspec/language/execution_spec.rb +2 -2
- data/spec/rubyspec/language/for_spec.rb +17 -17
- data/spec/rubyspec/language/hash_spec.rb +3 -3
- data/spec/rubyspec/language/if_spec.rb +11 -11
- data/spec/rubyspec/language/loop_spec.rb +3 -3
- data/spec/rubyspec/language/metaclass_spec.rb +14 -14
- data/spec/rubyspec/language/module_spec.rb +6 -6
- data/spec/rubyspec/language/next_spec.rb +5 -5
- data/spec/rubyspec/language/not_spec.rb +1 -1
- data/spec/rubyspec/language/or_spec.rb +1 -1
- data/spec/rubyspec/language/order_spec.rb +3 -5
- data/spec/rubyspec/language/precedence_spec.rb +19 -19
- data/spec/rubyspec/language/proc_spec.rb +29 -29
- data/spec/rubyspec/language/redo_spec.rb +3 -5
- data/spec/rubyspec/language/rescue_spec.rb +7 -7
- data/spec/rubyspec/language/retry_spec.rb +2 -2
- data/spec/rubyspec/language/return_spec.rb +12 -12
- data/spec/rubyspec/language/send_spec.rb +9 -9
- data/spec/rubyspec/language/singleton_class_spec.rb +3 -4
- data/spec/rubyspec/language/super_spec.rb +7 -11
- data/spec/rubyspec/language/until_spec.rb +10 -10
- data/spec/rubyspec/language/variables_spec.rb +59 -67
- data/spec/rubyspec/language/versions/array_1.9.rb +1 -1
- data/spec/rubyspec/language/versions/block_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/break_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/literal_lambda_1.9.rb +12 -12
- data/spec/rubyspec/language/versions/send_1.9.rb +23 -23
- data/spec/rubyspec/language/versions/symbol_1.9.rb +2 -2
- data/spec/rubyspec/language/versions/variables_1.9.rb +1 -1
- data/spec/rubyspec/language/while_spec.rb +4 -4
- data/spec/rubyspec/language/yield_spec.rb +3 -3
- data/spec/rubyspec/library/erb/util/html_escape_spec.rb +10 -0
- data/spec/rubyspec/library/singleton/clone_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/dup_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/fixtures/classes.rb +18 -0
- data/spec/rubyspec/library/singleton/instance_spec.rb +30 -0
- data/spec/spec_helper.rb +214 -0
- data/stdlib/buffer.rb +40 -0
- data/stdlib/buffer/array.rb +66 -0
- data/stdlib/buffer/view.rb +70 -0
- data/stdlib/erb.rb +11 -20
- data/stdlib/forwardable.rb +71 -0
- data/stdlib/json.rb +78 -0
- data/stdlib/ostruct.rb +69 -0
- data/stdlib/rbconfig.rb +1 -0
- data/stdlib/singleton.rb +40 -0
- data/stdlib/stringio.rb +173 -0
- data/stdlib/template.rb +44 -0
- metadata +285 -79
- data/corelib/opal/native.rb +0 -31
- data/spec/opal/class/bridge_class_spec.rb +0 -39
- data/spec/opal/native_spec.rb +0 -209
- data/spec/ospec/runner.rb +0 -223
- data/spec/rubyspec/filters/bugs/block_args.rb +0 -3
- data/spec/rubyspec/filters/bugs/case.rb +0 -8
- data/spec/rubyspec/filters/bugs/language/module.rb +0 -3
- data/spec/rubyspec/filters/unsupported/frozen.rb +0 -4
- data/spec/rubyspec/filters/unsupported/tainted.rb +0 -7
data/.rspec
ADDED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -63,6 +63,12 @@ visit `http://localhost:9292/` in any web browser.
|
|
63
63
|
|
64
64
|
## Code Overview
|
65
65
|
|
66
|
+
What code is supposed to run where?
|
67
|
+
|
68
|
+
* `lib/` code runs inside your ruby env. It compiles ruby to javascript.
|
69
|
+
* `corelib/` is the runtime/corelib for our implementation (runs in browser)
|
70
|
+
* `stdlib/` is our implementation of ruby stdlib. It is optional (for browser).
|
71
|
+
|
66
72
|
### lib
|
67
73
|
|
68
74
|
The `lib` directory holds the opal parser/compiler used to compile ruby
|
data/Rakefile
CHANGED
@@ -6,6 +6,25 @@ require 'rack'
|
|
6
6
|
require 'webrick'
|
7
7
|
require 'opal-sprockets'
|
8
8
|
|
9
|
+
# mspec/rubyspec use a top level "language_version" to require relative specs.
|
10
|
+
# We can't do this at runtime, so we hijack the method (and make sure we only
|
11
|
+
# do this at the top level). We figure out which file we are including, and
|
12
|
+
# add it to our require list
|
13
|
+
class ::Opal::Parser
|
14
|
+
alias_method :mspec_process_call, :process_call
|
15
|
+
|
16
|
+
def process_call(sexp, level)
|
17
|
+
if sexp[1] == :language_version and @scope.top?
|
18
|
+
lang_type = sexp[2][2][1]
|
19
|
+
target = "rubyspec/language/versions/#{lang_type}_1.9"
|
20
|
+
@requires << target
|
21
|
+
return f("nil")
|
22
|
+
end
|
23
|
+
|
24
|
+
mspec_process_call sexp, level
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
9
28
|
class RunSpec
|
10
29
|
def initialize(file=nil)
|
11
30
|
Opal::Processor.arity_check_enabled = true
|
@@ -60,11 +79,19 @@ class RunSpec
|
|
60
79
|
end
|
61
80
|
end
|
62
81
|
|
82
|
+
require 'rspec/core/rake_task'
|
83
|
+
RSpec::Core::RakeTask.new(:mri_spec) do |t|
|
84
|
+
t.pattern = 'mri_spec/**/*_spec.rb'
|
85
|
+
end
|
86
|
+
|
63
87
|
desc "Run tests through mspec"
|
64
|
-
task :
|
88
|
+
task :mspec do
|
65
89
|
RunSpec.new
|
66
90
|
end
|
67
91
|
|
92
|
+
task :default => [:mri_spec, :mspec] do
|
93
|
+
end
|
94
|
+
|
68
95
|
desc "Build specs to build/specs.js and build/specs.min.js"
|
69
96
|
task :build_specs do
|
70
97
|
require 'uglifier'
|
@@ -120,8 +147,6 @@ end
|
|
120
147
|
desc "Build opal.js and opal-parser.js to build/"
|
121
148
|
task :dist do
|
122
149
|
Opal::Processor.arity_check_enabled = false
|
123
|
-
Opal::Processor.source_map_enabled = false
|
124
|
-
Opal::Processor.method_missing_enabled = false
|
125
150
|
|
126
151
|
env = Opal::Environment.new
|
127
152
|
|
@@ -131,9 +156,8 @@ task :dist do
|
|
131
156
|
puts "* building #{lib}..."
|
132
157
|
|
133
158
|
src = env[lib].to_s
|
134
|
-
|
135
|
-
|
136
|
-
min = gzp = nil
|
159
|
+
min = uglify src
|
160
|
+
gzp = gzip min
|
137
161
|
|
138
162
|
File.open("build/#{lib}.js", 'w+') { |f| f << src }
|
139
163
|
File.open("build/#{lib}.min.js", 'w+') { |f| f << min } if min
|
data/bin/opal
CHANGED
@@ -1,86 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
4
|
-
|
5
|
-
options
|
6
|
-
parser = OptionParser.new do |opts|
|
7
|
-
opts.banner = 'Usage: opal [options] -- [programfile]'
|
8
|
-
|
9
|
-
opts.on('-v', '--version', 'Display Opal Version') do |v|
|
10
|
-
require 'opal/version'
|
11
|
-
puts "Opal v#{Opal::VERSION}"
|
12
|
-
exit
|
13
|
-
end
|
14
|
-
|
15
|
-
opts.on("-h", "--help", "Show this message") do
|
16
|
-
puts opts
|
17
|
-
exit
|
18
|
-
end
|
19
|
-
|
20
|
-
opts.separator ''
|
21
|
-
opts.separator 'Basic Options:'
|
22
|
-
|
23
|
-
opts.on('-I', '--include DIR',
|
24
|
-
'Append a load path (may be used more than once)') do |i|
|
25
|
-
options[:load_paths] ||= []
|
26
|
-
options[:load_paths] << i
|
27
|
-
end
|
28
|
-
|
29
|
-
opts.on('-e', '--eval SOURCE', String,
|
30
|
-
'One line of script. Several -e\'s allowed. Omit [programfile]') do |source|
|
31
|
-
options[:evals] ||= []
|
32
|
-
options[:evals] << source
|
33
|
-
end
|
34
|
-
|
35
|
-
opts.on('-s', '--sexp', 'Show Sexps') do
|
36
|
-
options[:sexp] = true
|
37
|
-
end
|
38
|
-
|
39
|
-
opts.on('-c', '--compile', 'Compile to JavaScript') do
|
40
|
-
options[:compile] = true
|
41
|
-
end
|
42
|
-
|
43
|
-
opts.on('-s', '--server [PORT]', 'Start a server (default port: 3000)') do |port|
|
44
|
-
options[:server] = port.to_i
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
opts.separator ''
|
49
|
-
opts.separator 'Compilation Options:'
|
50
|
-
|
51
|
-
opts.on('-M', '--no-method-missing', 'Disable method missing') do |value|
|
52
|
-
options[:method_missing] = false
|
53
|
-
end
|
54
|
-
|
55
|
-
opts.on('-O', '--no-optimized-operators', 'Disable optimized operators') do |value|
|
56
|
-
options[:optimized_operators_enabled] = false
|
57
|
-
end
|
58
|
-
|
59
|
-
opts.on('-A', '--arity-check', 'Enable arity check') do |value|
|
60
|
-
options[:arity_check] = true
|
61
|
-
end
|
62
|
-
|
63
|
-
opts.on('-C', '--no-const-missing', 'Disable const missing') do |value|
|
64
|
-
options[:const_missing] = false
|
65
|
-
end
|
66
|
-
|
67
|
-
dynamic_require_levels = %w[error warning ignore]
|
68
|
-
opts.on('-D', '--dynamic-require LEVEL', dynamic_require_levels,
|
69
|
-
'Set levelDynamic require severity') do |level|
|
70
|
-
options[:dynamic_require_severity] = level
|
71
|
-
end
|
72
|
-
|
73
|
-
opts.on('-P', '--no-source-map', 'Disable source map') do |value|
|
74
|
-
options[:source_map_enabled] = false
|
75
|
-
end
|
76
|
-
|
77
|
-
opts.on("--irb", "IRB var mode") do |i|
|
78
|
-
options[:irb] = true
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
parser.parse!
|
3
|
+
require 'opal/cli_options'
|
4
|
+
options = Opal::CLIOptions.new
|
5
|
+
options.parse!
|
84
6
|
|
85
7
|
require 'opal/cli'
|
86
|
-
Opal::CLI.new ARGV.first, options
|
8
|
+
cli = Opal::CLI.new ARGV.first, options.options
|
9
|
+
cli.run
|
10
|
+
|
@@ -26,7 +26,7 @@ class Array
|
|
26
26
|
arr = [];
|
27
27
|
|
28
28
|
if (!obj) {
|
29
|
-
if (size
|
29
|
+
if (#{size.respond_to? :to_ary}) {
|
30
30
|
if (size['$is_a?'](Array))
|
31
31
|
return size;
|
32
32
|
return size['$to_ary']();
|
@@ -36,7 +36,7 @@ class Array
|
|
36
36
|
if (typeof(arguments[0]) == 'number')
|
37
37
|
size = arguments[0];
|
38
38
|
else {
|
39
|
-
if (arguments[0]
|
39
|
+
if (#{`arguments[0]`.respond_to? :to_int}) {
|
40
40
|
size = arguments[0]['$to_int']();
|
41
41
|
if (typeof(size) == 'number') {
|
42
42
|
if (size % 1 !== 0) {
|
@@ -66,8 +66,8 @@ class Array
|
|
66
66
|
else {
|
67
67
|
for (var i = 0, value; i < size; i++) {
|
68
68
|
value = block(i);
|
69
|
-
if (value ===
|
70
|
-
return
|
69
|
+
if (value === $breaker) {
|
70
|
+
return $breaker.$v;
|
71
71
|
}
|
72
72
|
arr[i] = block(i);
|
73
73
|
}
|
@@ -159,7 +159,7 @@ class Array
|
|
159
159
|
result = [];
|
160
160
|
|
161
161
|
if (typeof(b) == "object" && !(b._isArray)) {
|
162
|
-
if (
|
162
|
+
if (#{other.respond_to? :to_ary}) {
|
163
163
|
b = b['$to_ary']();
|
164
164
|
} else {
|
165
165
|
#{raise TypeError.new("can't convert to Array. Array#-") };
|
@@ -222,16 +222,11 @@ class Array
|
|
222
222
|
tmp1 = #{self}[i];
|
223
223
|
tmp2 = #{other}[i];
|
224
224
|
|
225
|
-
|
226
|
-
|
227
|
-
(typeof(tmp2.indexOf) == "function") && tmp2 &&
|
228
|
-
(tmp1.indexOf(tmp2) == tmp2.indexOf(tmp1))) {
|
229
|
-
if (tmp1.indexOf(tmp1) == tmp2.indexOf(tmp2)) {
|
230
|
-
continue;
|
231
|
-
}
|
225
|
+
if (tmp1._isArray && tmp2._isArray && (tmp1 === #{self})) {
|
226
|
+
continue;
|
232
227
|
}
|
233
228
|
|
234
|
-
if (
|
229
|
+
if (!(#{`tmp1` == `tmp2`})) {
|
235
230
|
return false;
|
236
231
|
}
|
237
232
|
|
@@ -343,8 +338,8 @@ class Array
|
|
343
338
|
|
344
339
|
|
345
340
|
for (var i = 0, length = #{self}.length, value; i < length; i++) {
|
346
|
-
if ((value = block(#{self}[i])) ===
|
347
|
-
return
|
341
|
+
if ((value = block(#{self}[i])) === $breaker) {
|
342
|
+
return $breaker.$v;
|
348
343
|
}
|
349
344
|
|
350
345
|
result.push(value);
|
@@ -357,8 +352,8 @@ class Array
|
|
357
352
|
def collect!(&block)
|
358
353
|
%x{
|
359
354
|
for (var i = 0, length = #{self}.length, val; i < length; i++) {
|
360
|
-
if ((val = block(#{self}[i])) ===
|
361
|
-
return
|
355
|
+
if ((val = block(#{self}[i])) === $breaker) {
|
356
|
+
return $breaker.$v;
|
362
357
|
}
|
363
358
|
|
364
359
|
#{self}[i] = val;
|
@@ -465,8 +460,8 @@ class Array
|
|
465
460
|
def delete_if(&block)
|
466
461
|
%x{
|
467
462
|
for (var i = 0, length = #{self}.length, value; i < length; i++) {
|
468
|
-
if ((value = block(#{self}[i])) ===
|
469
|
-
return
|
463
|
+
if ((value = block(#{self}[i])) === $breaker) {
|
464
|
+
return $breaker.$v;
|
470
465
|
}
|
471
466
|
|
472
467
|
if (value !== false && value !== nil) {
|
@@ -490,19 +485,20 @@ class Array
|
|
490
485
|
def each(&block)
|
491
486
|
return enum_for :each unless block_given?
|
492
487
|
|
493
|
-
|
494
|
-
|
495
|
-
for (var i = 0, length = #{self}.length; i < length; i++) {
|
496
|
-
|
488
|
+
%x{
|
489
|
+
if (block.length > 1) {
|
490
|
+
for (var i = 0, length = #{self}.length, el; i < length; i++) {
|
491
|
+
el = #{self}[i];
|
492
|
+
if (!el._isArray) el = [el];
|
493
|
+
|
494
|
+
if (block.apply(null, el) === $breaker) return $breaker.$v;
|
497
495
|
}
|
498
|
-
}
|
499
|
-
else
|
500
|
-
%x{
|
496
|
+
} else {
|
501
497
|
for (var i = 0, length = #{self}.length; i < length; i++) {
|
502
|
-
#{
|
498
|
+
if (block(#{self}[i]) === $breaker) return $breaker.$v;
|
503
499
|
}
|
504
500
|
}
|
505
|
-
|
501
|
+
}
|
506
502
|
|
507
503
|
self
|
508
504
|
end
|
@@ -633,8 +629,8 @@ class Array
|
|
633
629
|
}
|
634
630
|
else if (block !== nil) {
|
635
631
|
for (var i = 0, length = #{self}.length, value; i < length; i++) {
|
636
|
-
if ((value = block(#{self}[i])) ===
|
637
|
-
return
|
632
|
+
if ((value = block(#{self}[i])) === $breaker) {
|
633
|
+
return $breaker.$v;
|
638
634
|
}
|
639
635
|
|
640
636
|
if (value !== false && value !== nil) {
|
@@ -705,8 +701,8 @@ class Array
|
|
705
701
|
def keep_if(&block)
|
706
702
|
%x{
|
707
703
|
for (var i = 0, length = #{self}.length, value; i < length; i++) {
|
708
|
-
if ((value = block(#{self}[i])) ===
|
709
|
-
return
|
704
|
+
if ((value = block(#{self}[i])) === $breaker) {
|
705
|
+
return $breaker.$v;
|
710
706
|
}
|
711
707
|
|
712
708
|
if (value === false || value === nil) {
|
@@ -730,7 +726,7 @@ class Array
|
|
730
726
|
}
|
731
727
|
|
732
728
|
if (typeof(count) == 'object') {
|
733
|
-
if (
|
729
|
+
if (#{count.respond_to? :to_int}) {
|
734
730
|
count = count['$to_int']();
|
735
731
|
}
|
736
732
|
else {
|
@@ -808,8 +804,8 @@ class Array
|
|
808
804
|
var result = [];
|
809
805
|
|
810
806
|
for (var i = 0, length = #{self}.length, value; i < length; i++) {
|
811
|
-
if ((value = block(#{self}[i])) ===
|
812
|
-
return
|
807
|
+
if ((value = block(#{self}[i])) === $breaker) {
|
808
|
+
return $breaker.$v;
|
813
809
|
}
|
814
810
|
|
815
811
|
if (value === false || value === nil) {
|
@@ -854,8 +850,8 @@ class Array
|
|
854
850
|
%x{
|
855
851
|
if (block !== nil) {
|
856
852
|
for (var i = #{self}.length - 1, value; i >= 0; i--) {
|
857
|
-
if ((value = block(#{self}[i])) ===
|
858
|
-
return
|
853
|
+
if ((value = block(#{self}[i])) === $breaker) {
|
854
|
+
return $breaker.$v;
|
859
855
|
}
|
860
856
|
|
861
857
|
if (value !== false && value !== nil) {
|
@@ -882,8 +878,8 @@ class Array
|
|
882
878
|
for (var i = 0, length = #{self}.length, item, value; i < length; i++) {
|
883
879
|
item = #{self}[i];
|
884
880
|
|
885
|
-
if ((value = block(item)) ===
|
886
|
-
return
|
881
|
+
if ((value = block(item)) === $breaker) {
|
882
|
+
return $breaker.$v;
|
887
883
|
}
|
888
884
|
|
889
885
|
if (value !== false && value !== nil) {
|
@@ -957,13 +953,13 @@ class Array
|
|
957
953
|
if (block !== nil) {
|
958
954
|
var result = copy.sort(function(x, y) {
|
959
955
|
var result = block(x, y);
|
960
|
-
if (result ===
|
961
|
-
t_break.push(
|
956
|
+
if (result === $breaker) {
|
957
|
+
t_break.push($breaker.$v);
|
962
958
|
}
|
963
959
|
if (result === nil) {
|
964
960
|
t_arg_error = true;
|
965
961
|
}
|
966
|
-
if ((result != null) &&
|
962
|
+
if ((result != null) && #{ `result`.respond_to? :<=> }) {
|
967
963
|
result = result['$<=>'](0);
|
968
964
|
}
|
969
965
|
if (result !== -1 && result !== 0 && result !== 1) {
|
@@ -1034,8 +1030,8 @@ class Array
|
|
1034
1030
|
for (var i = 0, length = #{self}.length, item, value; i < length; i++) {
|
1035
1031
|
item = #{self}[i];
|
1036
1032
|
|
1037
|
-
if ((value = block(item)) ===
|
1038
|
-
return
|
1033
|
+
if ((value = block(item)) === $breaker) {
|
1034
|
+
return $breaker.$v;
|
1039
1035
|
}
|
1040
1036
|
|
1041
1037
|
if (value === false || value === nil) {
|
@@ -1055,18 +1051,6 @@ class Array
|
|
1055
1051
|
|
1056
1052
|
alias to_ary to_a
|
1057
1053
|
|
1058
|
-
def to_json
|
1059
|
-
%x{
|
1060
|
-
var result = [];
|
1061
|
-
|
1062
|
-
for (var i = 0, length = #{self}.length; i < length; i++) {
|
1063
|
-
result.push(#{ `#{self}[i]`.to_json });
|
1064
|
-
}
|
1065
|
-
|
1066
|
-
return '[' + result.join(', ') + ']';
|
1067
|
-
}
|
1068
|
-
end
|
1069
|
-
|
1070
1054
|
def to_n
|
1071
1055
|
%x{
|
1072
1056
|
var result = [], obj
|
@@ -26,7 +26,7 @@ class BasicObject
|
|
26
26
|
def instance_eval(&block)
|
27
27
|
%x{
|
28
28
|
if (block === nil) {
|
29
|
-
|
29
|
+
throw new Error("no block given");
|
30
30
|
}
|
31
31
|
|
32
32
|
var block_self = block._s, result;
|
@@ -42,7 +42,7 @@ class BasicObject
|
|
42
42
|
def instance_exec(*args, &block)
|
43
43
|
%x{
|
44
44
|
if (block === nil) {
|
45
|
-
|
45
|
+
throw new Error("no block given");
|
46
46
|
}
|
47
47
|
|
48
48
|
var block_self = block._s, result;
|
@@ -17,16 +17,8 @@ class Boolean
|
|
17
17
|
`(#{self} == true) === other.valueOf()`
|
18
18
|
end
|
19
19
|
|
20
|
-
def as_json
|
21
|
-
self
|
22
|
-
end
|
23
|
-
|
24
20
|
alias singleton_class class
|
25
21
|
|
26
|
-
def to_json
|
27
|
-
`(#{self} == true) ? 'true' : 'false'`
|
28
|
-
end
|
29
|
-
|
30
22
|
def to_s
|
31
23
|
`(#{self} == true) ? 'true' : 'false'`
|
32
24
|
end
|