opal 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (303) hide show
  1. data/.rspec +3 -0
  2. data/.travis.yml +0 -4
  3. data/README.md +6 -0
  4. data/Rakefile +30 -6
  5. data/bin/opal +6 -82
  6. data/corelib/{opal/array.rb → array.rb} +40 -56
  7. data/corelib/{opal/basic_object.rb → basic_object.rb} +2 -2
  8. data/corelib/{opal/boolean.rb → boolean.rb} +0 -8
  9. data/corelib/class.rb +47 -0
  10. data/corelib/{opal/comparable.rb → comparable.rb} +0 -0
  11. data/corelib/{opal/enumerable.rb → enumerable.rb} +208 -141
  12. data/corelib/{opal/enumerator.rb → enumerator.rb} +3 -3
  13. data/corelib/{opal/error.rb → error.rb} +1 -0
  14. data/corelib/{opal/hash.rb → hash.rb} +67 -56
  15. data/corelib/io.rb +39 -0
  16. data/corelib/{opal/kernel.rb → kernel.rb} +35 -31
  17. data/corelib/{opal/class.rb → module.rb} +29 -57
  18. data/corelib/native.rb +148 -0
  19. data/corelib/{opal/nil_class.rb → nil_class.rb} +2 -10
  20. data/corelib/{opal/numeric.rb → numeric.rb} +39 -14
  21. data/corelib/opal.rb +42 -25
  22. data/corelib/{opal/proc.rb → proc.rb} +3 -3
  23. data/corelib/{opal/range.rb → range.rb} +5 -1
  24. data/corelib/{opal/regexp.rb → regexp.rb} +0 -0
  25. data/corelib/{opal/runtime.js → runtime.js} +96 -188
  26. data/corelib/{opal/string.rb → string.rb} +20 -15
  27. data/corelib/struct.rb +139 -0
  28. data/corelib/{opal/time.rb → time.rb} +0 -0
  29. data/lib/opal.rb +4 -0
  30. data/lib/opal/cli.rb +79 -32
  31. data/lib/opal/cli_options.rb +91 -0
  32. data/lib/opal/erb.rb +41 -8
  33. data/lib/opal/grammar.rb +24 -10
  34. data/lib/opal/grammar.y +15 -4
  35. data/lib/opal/grammar_helpers.rb +4 -0
  36. data/lib/opal/lexer.rb +214 -143
  37. data/lib/opal/parser.rb +596 -562
  38. data/lib/opal/require_parser.rb +1 -1
  39. data/lib/opal/source_map.rb +15 -30
  40. data/lib/opal/target_scope.rb +24 -5
  41. data/lib/opal/version.rb +1 -1
  42. data/mri_spec/cli_spec.rb +18 -0
  43. data/mri_spec/fixtures/opal_file.rb +2 -0
  44. data/mri_spec/spec_helper.rb +17 -0
  45. data/opal.gemspec +5 -2
  46. data/spec/{rubyspec/filters → filters}/bugs/alias.rb +0 -0
  47. data/spec/{rubyspec/filters → filters}/bugs/ancestors.rb +0 -0
  48. data/spec/{rubyspec/filters → filters}/bugs/array.rb +0 -0
  49. data/spec/filters/bugs/array/combination.rb +11 -0
  50. data/spec/filters/bugs/array/count.rb +3 -0
  51. data/spec/filters/bugs/array/delete_if.rb +3 -0
  52. data/spec/filters/bugs/array/drop.rb +3 -0
  53. data/spec/filters/bugs/array/drop_while.rb +5 -0
  54. data/spec/filters/bugs/array/eql.rb +3 -0
  55. data/spec/filters/bugs/array/flatten.rb +9 -0
  56. data/spec/filters/bugs/array/minus.rb +5 -0
  57. data/spec/filters/bugs/array/multipliy.rb +9 -0
  58. data/spec/filters/bugs/array/new.rb +3 -0
  59. data/spec/filters/bugs/array/pop.rb +6 -0
  60. data/spec/filters/bugs/array/rassoc.rb +4 -0
  61. data/spec/filters/bugs/array/rindex.rb +6 -0
  62. data/spec/filters/bugs/array/select.rb +3 -0
  63. data/spec/filters/bugs/array/shift.rb +7 -0
  64. data/spec/filters/bugs/array/shuffle.rb +11 -0
  65. data/spec/filters/bugs/array/slice.rb +7 -0
  66. data/spec/filters/bugs/array/take.rb +3 -0
  67. data/spec/filters/bugs/array/to_a.rb +3 -0
  68. data/spec/filters/bugs/array/try_convert.rb +7 -0
  69. data/spec/filters/bugs/array/uniq.rb +10 -0
  70. data/spec/filters/bugs/array/zip.rb +4 -0
  71. data/spec/{rubyspec/filters → filters}/bugs/array_delete.rb +1 -0
  72. data/spec/{rubyspec/filters → filters}/bugs/array_fetch.rb +0 -0
  73. data/spec/{rubyspec/filters → filters}/bugs/array_first.rb +0 -0
  74. data/spec/{rubyspec/filters → filters}/bugs/array_flatten.rb +0 -0
  75. data/spec/{rubyspec/filters → filters}/bugs/array_intersection.rb +0 -0
  76. data/spec/{rubyspec/filters → filters}/bugs/array_join.rb +0 -0
  77. data/spec/{rubyspec/filters → filters}/bugs/break.rb +0 -0
  78. data/spec/filters/bugs/case.rb +4 -0
  79. data/spec/{rubyspec/filters → filters}/bugs/coerce_integer.rb +0 -0
  80. data/spec/filters/bugs/enumerable_sort_by.rb +3 -0
  81. data/spec/{rubyspec/filters → filters}/bugs/kernel/instance_variables.rb +0 -0
  82. data/spec/filters/bugs/kernel/rand.rb +4 -0
  83. data/spec/filters/bugs/language/array.rb +3 -0
  84. data/spec/filters/bugs/language/block.rb +6 -0
  85. data/spec/filters/bugs/language/break.rb +3 -0
  86. data/spec/{rubyspec/filters → filters}/bugs/language/class.rb +3 -0
  87. data/spec/{rubyspec/filters → filters}/bugs/language/class_variables.rb +0 -0
  88. data/spec/filters/bugs/language/def.rb +27 -0
  89. data/spec/filters/bugs/language/defined.rb +3 -0
  90. data/spec/filters/bugs/language/ensure.rb +4 -0
  91. data/spec/filters/bugs/language/execution.rb +4 -0
  92. data/spec/filters/bugs/language/for.rb +18 -0
  93. data/spec/filters/bugs/language/if.rb +13 -0
  94. data/spec/filters/bugs/language/loop.rb +4 -0
  95. data/spec/filters/bugs/language/metaclass.rb +14 -0
  96. data/spec/filters/bugs/language/module.rb +6 -0
  97. data/spec/filters/bugs/language/next.rb +3 -0
  98. data/spec/filters/bugs/language/or.rb +3 -0
  99. data/spec/filters/bugs/language/order.rb +4 -0
  100. data/spec/filters/bugs/language/precedence.rb +10 -0
  101. data/spec/filters/bugs/language/proc.rb +24 -0
  102. data/spec/filters/bugs/language/redo.rb +5 -0
  103. data/spec/filters/bugs/language/rescue.rb +9 -0
  104. data/spec/filters/bugs/language/retry.rb +5 -0
  105. data/spec/filters/bugs/language/send.rb +10 -0
  106. data/spec/filters/bugs/language/super.rb +9 -0
  107. data/spec/filters/bugs/language/until.rb +8 -0
  108. data/spec/filters/bugs/language/variables.rb +37 -0
  109. data/spec/filters/bugs/language/while.rb +6 -0
  110. data/spec/filters/bugs/language/yield.rb +5 -0
  111. data/spec/{rubyspec/filters → filters}/bugs/module/class_variables.rb +0 -0
  112. data/spec/filters/bugs/module/method_defined.rb +6 -0
  113. data/spec/filters/bugs/parser.rb +10 -0
  114. data/spec/{rubyspec/filters → filters}/bugs/public_methods.rb +1 -0
  115. data/spec/filters/bugs/return.rb +7 -0
  116. data/spec/filters/bugs/singleton/instance.rb +4 -0
  117. data/spec/filters/bugs/source_map.rb +3 -0
  118. data/spec/filters/bugs/string/center.rb +4 -0
  119. data/spec/filters/bugs/string/lines.rb +3 -0
  120. data/spec/{rubyspec/filters → filters}/mspec/mocks.rb +0 -0
  121. data/spec/{rubyspec/filters → filters}/mspec/ruby_exe.rb +0 -0
  122. data/spec/{rubyspec/filters → filters}/mspec/should_receive.rb +0 -0
  123. data/spec/{rubyspec/filters → filters}/parser/block_args.rb +0 -0
  124. data/spec/{rubyspec/filters → filters}/unsupported/array_subclasses.rb +1 -0
  125. data/spec/filters/unsupported/frozen.rb +32 -0
  126. data/spec/filters/unsupported/immutable_strings.rb +3 -0
  127. data/spec/filters/unsupported/tainted.rb +17 -0
  128. data/spec/filters/unsupported/trusted.rb +15 -0
  129. data/spec/opal/class/constants_spec.rb +7 -0
  130. data/spec/opal/erb/erb_spec.rb +7 -1
  131. data/spec/opal/erb/inline_block.opalerb +3 -0
  132. data/spec/opal/hash/allocate_spec.rb +16 -0
  133. data/spec/opal/hash/new_spec.rb +10 -0
  134. data/spec/opal/hash/to_s_spec.rb +9 -0
  135. data/spec/opal/kernel/instance_variable_defined_spec.rb +15 -0
  136. data/spec/opal/kernel/rand_spec.rb +5 -5
  137. data/spec/opal/kernel/respond_to_spec.rb +14 -1
  138. data/spec/opal/language/block_spec.rb +13 -0
  139. data/spec/opal/language/rescue_spec.rb +27 -0
  140. data/spec/opal/language/return_spec.rb +38 -0
  141. data/spec/opal/language/singleton_class_spec.rb +13 -0
  142. data/spec/opal/language/super_spec.rb +99 -0
  143. data/spec/opal/language/variables_spec.rb +20 -0
  144. data/spec/opal/module/attr_accessor_spec.rb +8 -0
  145. data/spec/opal/module/constants_spec.rb +2 -2
  146. data/spec/opal/native/alias_native_spec.rb +18 -0
  147. data/spec/opal/native/each_spec.rb +14 -0
  148. data/spec/opal/native/element_reference_spec.rb +14 -0
  149. data/spec/opal/native/method_missing_spec.rb +39 -0
  150. data/spec/opal/native/new_spec.rb +19 -0
  151. data/spec/opal/native/nil_spec.rb +14 -0
  152. data/spec/opal/runtime2/class_hierarchy_spec.rb +2 -2
  153. data/spec/opal/source_map_spec.rb +3 -7
  154. data/spec/ospec/main.rb.erb +2 -5
  155. data/spec/parser/alias_spec.rb +4 -4
  156. data/spec/parser/and_spec.rb +2 -2
  157. data/spec/parser/array_spec.rb +6 -6
  158. data/spec/parser/attrasgn_spec.rb +8 -8
  159. data/spec/parser/begin_spec.rb +11 -11
  160. data/spec/parser/block_spec.rb +3 -3
  161. data/spec/parser/break_spec.rb +4 -4
  162. data/spec/parser/call_spec.rb +50 -48
  163. data/spec/parser/class_spec.rb +2 -2
  164. data/spec/parser/const_spec.rb +1 -1
  165. data/spec/parser/cvar_spec.rb +1 -1
  166. data/spec/parser/def_spec.rb +5 -5
  167. data/spec/parser/gvar_spec.rb +2 -2
  168. data/spec/parser/hash_spec.rb +4 -4
  169. data/spec/parser/iasgn_spec.rb +3 -3
  170. data/spec/parser/if_spec.rb +6 -6
  171. data/spec/parser/iter_spec.rb +6 -6
  172. data/spec/parser/lambda_spec.rb +5 -5
  173. data/spec/parser/lasgn_spec.rb +2 -2
  174. data/spec/parser/line_spec.rb +2 -2
  175. data/spec/parser/lvar_spec.rb +5 -5
  176. data/spec/parser/masgn_spec.rb +1 -1
  177. data/spec/parser/module_spec.rb +2 -2
  178. data/spec/parser/not_spec.rb +4 -4
  179. data/spec/parser/op_asgn1_spec.rb +2 -2
  180. data/spec/parser/op_asgn2_spec.rb +2 -2
  181. data/spec/parser/or_spec.rb +2 -2
  182. data/spec/parser/parse_spec.rb +66 -0
  183. data/spec/parser/parser_spec.rb +32 -38
  184. data/spec/parser/regexp_spec.rb +4 -4
  185. data/spec/parser/return_spec.rb +4 -4
  186. data/spec/parser/sclass_spec.rb +4 -4
  187. data/spec/parser/str_spec.rb +3 -3
  188. data/spec/parser/super_spec.rb +6 -6
  189. data/spec/parser/undef_spec.rb +3 -3
  190. data/spec/parser/unless_spec.rb +4 -4
  191. data/spec/parser/while_spec.rb +3 -3
  192. data/spec/parser/xstr_spec.rb +3 -3
  193. data/spec/parser/yield_spec.rb +6 -6
  194. data/spec/rubyspec/core/array/drop_spec.rb +1 -1
  195. data/spec/rubyspec/core/array/keep_if_spec.rb +1 -3
  196. data/spec/rubyspec/core/array/length_spec.rb +1 -3
  197. data/spec/rubyspec/core/array/map_spec.rb +2 -6
  198. data/spec/rubyspec/core/array/minus_spec.rb +3 -3
  199. data/spec/rubyspec/core/array/multiply_spec.rb +14 -16
  200. data/spec/rubyspec/core/array/new_spec.rb +3 -5
  201. data/spec/rubyspec/core/array/plus_spec.rb +2 -2
  202. data/spec/rubyspec/core/array/pop_spec.rb +4 -4
  203. data/spec/rubyspec/core/array/rassoc_spec.rb +2 -2
  204. data/spec/rubyspec/core/array/reject_spec.rb +2 -6
  205. data/spec/rubyspec/core/array/replace_spec.rb +1 -3
  206. data/spec/rubyspec/core/array/reverse_each_spec.rb +1 -3
  207. data/spec/rubyspec/core/array/reverse_spec.rb +4 -4
  208. data/spec/rubyspec/core/array/rindex_spec.rb +1 -1
  209. data/spec/rubyspec/core/array/select_spec.rb +3 -7
  210. data/spec/rubyspec/core/array/shared/collect.rb +7 -0
  211. data/spec/rubyspec/core/array/shared/index.rb +1 -1
  212. data/spec/rubyspec/core/array/shared/keep_if.rb +3 -0
  213. data/spec/rubyspec/core/array/shared/length.rb +3 -0
  214. data/spec/rubyspec/core/array/shared/replace.rb +3 -0
  215. data/spec/rubyspec/core/array/shared/slice.rb +3 -0
  216. data/spec/rubyspec/core/array/shuffle_spec.rb +1 -1
  217. data/spec/rubyspec/core/array/size_spec.rb +1 -3
  218. data/spec/rubyspec/core/array/slice_spec.rb +4 -6
  219. data/spec/rubyspec/core/array/sort_spec.rb +2 -2
  220. data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
  221. data/spec/rubyspec/core/array/try_convert_spec.rb +7 -7
  222. data/spec/rubyspec/core/array/uniq_spec.rb +7 -7
  223. data/spec/rubyspec/core/array/zip_spec.rb +1 -1
  224. data/spec/rubyspec/core/enumerable/collect_spec.rb +24 -0
  225. data/spec/rubyspec/core/enumerable/count_spec.rb +35 -19
  226. data/spec/rubyspec/core/enumerable/find_spec.rb +5 -0
  227. data/spec/rubyspec/core/hash/each_pair_spec.rb +7 -7
  228. data/spec/rubyspec/core/hash/each_spec.rb +13 -7
  229. data/spec/rubyspec/core/module/method_defined_spec.rb +4 -4
  230. data/spec/rubyspec/core/module/public_method_defined_spec.rb +19 -0
  231. data/spec/rubyspec/core/module/remove_const_spec.rb +23 -0
  232. data/spec/rubyspec/core/numeric/step_spec.rb +14 -0
  233. data/spec/rubyspec/core/string/center_spec.rb +43 -65
  234. data/spec/rubyspec/core/string/lines_spec.rb +1 -1
  235. data/spec/rubyspec/core/string/ljust_spec.rb +25 -9
  236. data/spec/rubyspec/core/string/rjust_spec.rb +26 -10
  237. data/spec/rubyspec/core/struct/fixtures/classes.rb +26 -0
  238. data/spec/rubyspec/core/struct/initialize_spec.rb +11 -0
  239. data/spec/rubyspec/core/struct/new_spec.rb +24 -0
  240. data/spec/rubyspec/fixtures/constants.rb +7 -0
  241. data/spec/rubyspec/language/break_spec.rb +1 -1
  242. data/spec/rubyspec/language/case_spec.rb +30 -30
  243. data/spec/rubyspec/language/def_spec.rb +34 -34
  244. data/spec/rubyspec/language/defined_spec.rb +2 -2
  245. data/spec/rubyspec/language/ensure_spec.rb +2 -2
  246. data/spec/rubyspec/language/execution_spec.rb +2 -2
  247. data/spec/rubyspec/language/for_spec.rb +17 -17
  248. data/spec/rubyspec/language/hash_spec.rb +3 -3
  249. data/spec/rubyspec/language/if_spec.rb +11 -11
  250. data/spec/rubyspec/language/loop_spec.rb +3 -3
  251. data/spec/rubyspec/language/metaclass_spec.rb +14 -14
  252. data/spec/rubyspec/language/module_spec.rb +6 -6
  253. data/spec/rubyspec/language/next_spec.rb +5 -5
  254. data/spec/rubyspec/language/not_spec.rb +1 -1
  255. data/spec/rubyspec/language/or_spec.rb +1 -1
  256. data/spec/rubyspec/language/order_spec.rb +3 -5
  257. data/spec/rubyspec/language/precedence_spec.rb +19 -19
  258. data/spec/rubyspec/language/proc_spec.rb +29 -29
  259. data/spec/rubyspec/language/redo_spec.rb +3 -5
  260. data/spec/rubyspec/language/rescue_spec.rb +7 -7
  261. data/spec/rubyspec/language/retry_spec.rb +2 -2
  262. data/spec/rubyspec/language/return_spec.rb +12 -12
  263. data/spec/rubyspec/language/send_spec.rb +9 -9
  264. data/spec/rubyspec/language/singleton_class_spec.rb +3 -4
  265. data/spec/rubyspec/language/super_spec.rb +7 -11
  266. data/spec/rubyspec/language/until_spec.rb +10 -10
  267. data/spec/rubyspec/language/variables_spec.rb +59 -67
  268. data/spec/rubyspec/language/versions/array_1.9.rb +1 -1
  269. data/spec/rubyspec/language/versions/block_1.9.rb +0 -0
  270. data/spec/rubyspec/language/versions/break_1.9.rb +0 -0
  271. data/spec/rubyspec/language/versions/literal_lambda_1.9.rb +12 -12
  272. data/spec/rubyspec/language/versions/send_1.9.rb +23 -23
  273. data/spec/rubyspec/language/versions/symbol_1.9.rb +2 -2
  274. data/spec/rubyspec/language/versions/variables_1.9.rb +1 -1
  275. data/spec/rubyspec/language/while_spec.rb +4 -4
  276. data/spec/rubyspec/language/yield_spec.rb +3 -3
  277. data/spec/rubyspec/library/erb/util/html_escape_spec.rb +10 -0
  278. data/spec/rubyspec/library/singleton/clone_spec.rb +8 -0
  279. data/spec/rubyspec/library/singleton/dup_spec.rb +8 -0
  280. data/spec/rubyspec/library/singleton/fixtures/classes.rb +18 -0
  281. data/spec/rubyspec/library/singleton/instance_spec.rb +30 -0
  282. data/spec/spec_helper.rb +214 -0
  283. data/stdlib/buffer.rb +40 -0
  284. data/stdlib/buffer/array.rb +66 -0
  285. data/stdlib/buffer/view.rb +70 -0
  286. data/stdlib/erb.rb +11 -20
  287. data/stdlib/forwardable.rb +71 -0
  288. data/stdlib/json.rb +78 -0
  289. data/stdlib/ostruct.rb +69 -0
  290. data/stdlib/rbconfig.rb +1 -0
  291. data/stdlib/singleton.rb +40 -0
  292. data/stdlib/stringio.rb +173 -0
  293. data/stdlib/template.rb +44 -0
  294. metadata +285 -79
  295. data/corelib/opal/native.rb +0 -31
  296. data/spec/opal/class/bridge_class_spec.rb +0 -39
  297. data/spec/opal/native_spec.rb +0 -209
  298. data/spec/ospec/runner.rb +0 -223
  299. data/spec/rubyspec/filters/bugs/block_args.rb +0 -3
  300. data/spec/rubyspec/filters/bugs/case.rb +0 -8
  301. data/spec/rubyspec/filters/bugs/language/module.rb +0 -3
  302. data/spec/rubyspec/filters/unsupported/frozen.rb +0 -4
  303. data/spec/rubyspec/filters/unsupported/tainted.rb +0 -7
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format progress
3
+ --pattern mri_spec/**/*_spec.rb
data/.travis.yml CHANGED
@@ -7,7 +7,3 @@ rvm:
7
7
 
8
8
  notifications:
9
9
  irc: "irc.freenode.org#opal"
10
-
11
- matrix:
12
- allow_failures:
13
- - rvm: 2.0.0
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 :default do
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
- #min = uglify src
135
- #gzp = gzip min
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 'optparse'
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['$to_ary'] && typeof(size['$to_ary']) == 'function'){
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]['$to_int'] && typeof(arguments[0]['$to_int']) == 'function' ) {
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 === __breaker) {
70
- return __breaker.$v;
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 (b['$to_ary'] && typeof(b['$to_ary']) == "function") {
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
- //recursive
226
- if (tmp1 && (typeof(tmp1.indexOf) == "function") &&
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 (!#{`#{self}[i]` == `other[i]`}) {
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])) === __breaker) {
347
- return __breaker.$v;
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])) === __breaker) {
361
- return __breaker.$v;
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])) === __breaker) {
469
- return __breaker.$v;
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
- if block.arity > 0
494
- %x{
495
- for (var i = 0, length = #{self}.length; i < length; i++) {
496
- if (block.apply(null, #{self}[i]._isArray ? #{self}[i] : [#{self}[i]]) === __breaker) return __breaker.$v;
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
- #{yield `#{self}[i]`};
498
+ if (block(#{self}[i]) === $breaker) return $breaker.$v;
503
499
  }
504
500
  }
505
- end
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])) === __breaker) {
637
- return __breaker.$v;
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])) === __breaker) {
709
- return __breaker.$v;
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 (typeof(count['$to_int']) == 'function') {
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])) === __breaker) {
812
- return __breaker.$v;
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])) === __breaker) {
858
- return __breaker.$v;
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)) === __breaker) {
886
- return __breaker.$v;
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 === __breaker) {
961
- t_break.push(__breaker.$v);
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) && result['$<=>'] && typeof(result['$<=>']) == "function") {
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)) === __breaker) {
1038
- return __breaker.$v;
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
- no_block_given();
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
- no_block_given();
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