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.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.spectator +2 -0
  4. data/.spectator-mspec +3 -0
  5. data/.travis.yml +8 -11
  6. data/CHANGELOG.md +33 -0
  7. data/CONTRIBUTING.md +8 -43
  8. data/Gemfile +15 -4
  9. data/Guardfile +77 -0
  10. data/README.md +15 -9
  11. data/Rakefile +36 -12
  12. data/benchmarks/operators.rb +11 -0
  13. data/bin/opal +10 -13
  14. data/bin/opal-build +4 -4
  15. data/bin/opal-mspec +10 -0
  16. data/bin/opal-repl +4 -3
  17. data/examples/sinatra/Gemfile +1 -1
  18. data/examples/sinatra/config.ru +3 -3
  19. data/lib/mspec/opal/main.rb.erb +2 -2
  20. data/lib/mspec/opal/rake_task.rb +31 -24
  21. data/lib/mspec/opal/runner.rb +18 -1
  22. data/lib/mspec/opal/sprockets.js +17 -0
  23. data/lib/opal.rb +1 -34
  24. data/lib/opal/builder.rb +92 -58
  25. data/lib/opal/builder_processors.rb +165 -0
  26. data/lib/opal/cli.rb +85 -144
  27. data/lib/opal/cli_options.rb +136 -90
  28. data/lib/opal/cli_runners.rb +10 -0
  29. data/lib/opal/cli_runners/nodejs.rb +56 -0
  30. data/lib/opal/cli_runners/phantom.js +35 -0
  31. data/lib/opal/cli_runners/phantomjs.rb +28 -0
  32. data/lib/opal/cli_runners/server.rb +54 -0
  33. data/lib/opal/compiler.rb +35 -16
  34. data/lib/opal/erb.rb +29 -15
  35. data/lib/opal/hike_path_finder.rb +18 -0
  36. data/lib/opal/nodes.rb +1 -0
  37. data/lib/opal/nodes/call.rb +107 -26
  38. data/lib/opal/nodes/call_special.rb +31 -6
  39. data/lib/opal/nodes/class.rb +2 -2
  40. data/lib/opal/nodes/constants.rb +5 -20
  41. data/lib/opal/nodes/def.rb +4 -4
  42. data/lib/opal/nodes/defined.rb +3 -3
  43. data/lib/opal/nodes/definitions.rb +1 -1
  44. data/lib/opal/nodes/for.rb +35 -0
  45. data/lib/opal/nodes/helpers.rb +2 -2
  46. data/lib/opal/nodes/iter.rb +3 -3
  47. data/lib/opal/nodes/literal.rb +10 -2
  48. data/lib/opal/nodes/masgn.rb +2 -2
  49. data/lib/opal/nodes/module.rb +2 -2
  50. data/lib/opal/nodes/scope.rb +1 -0
  51. data/lib/opal/nodes/singleton_class.rb +2 -2
  52. data/lib/opal/nodes/super.rb +2 -2
  53. data/lib/opal/nodes/top.rb +30 -3
  54. data/lib/opal/parser.rb +15 -1
  55. data/lib/opal/parser/grammar.rb +2571 -2452
  56. data/lib/opal/parser/grammar.y +37 -5
  57. data/lib/opal/parser/keywords.rb +2 -0
  58. data/lib/opal/parser/lexer.rb +21 -11
  59. data/lib/opal/path_reader.rb +28 -0
  60. data/lib/opal/paths.rb +38 -0
  61. data/lib/opal/source_map.rb +32 -15
  62. data/lib/opal/sprockets/environment.rb +9 -2
  63. data/lib/opal/sprockets/erb.rb +1 -2
  64. data/lib/opal/sprockets/path_reader.rb +34 -0
  65. data/lib/opal/sprockets/processor.rb +40 -39
  66. data/lib/opal/sprockets/server.rb +47 -33
  67. data/lib/opal/version.rb +1 -1
  68. data/opal.gemspec +10 -5
  69. data/opal/README.md +6 -0
  70. data/opal/corelib/array.rb +36 -4
  71. data/opal/corelib/array/inheritance.rb +6 -6
  72. data/opal/corelib/basic_object.rb +9 -9
  73. data/opal/corelib/boolean.rb +1 -1
  74. data/opal/corelib/class.rb +12 -12
  75. data/opal/corelib/dir.rb +20 -0
  76. data/opal/corelib/enumerable.rb +42 -42
  77. data/opal/corelib/enumerator.rb +1 -1
  78. data/opal/corelib/error.rb +2 -2
  79. data/opal/corelib/file.rb +56 -0
  80. data/opal/corelib/hash.rb +5 -5
  81. data/opal/corelib/helpers.rb +3 -3
  82. data/opal/corelib/io.rb +13 -10
  83. data/opal/corelib/kernel.rb +44 -68
  84. data/opal/corelib/method.rb +1 -1
  85. data/opal/corelib/module.rb +89 -114
  86. data/opal/corelib/nil_class.rb +1 -1
  87. data/opal/corelib/numeric.rb +27 -23
  88. data/opal/corelib/proc.rb +5 -5
  89. data/opal/corelib/range.rb +8 -4
  90. data/opal/corelib/regexp.rb +5 -5
  91. data/opal/corelib/runtime.js +589 -272
  92. data/opal/corelib/string.rb +52 -37
  93. data/opal/corelib/string/inheritance.rb +5 -5
  94. data/opal/corelib/time.rb +102 -52
  95. data/opal/corelib/variables.rb +3 -3
  96. data/opal/opal.rb +2 -0
  97. data/package.json +9 -0
  98. data/spec/filters/bugs/array.rb +0 -6
  99. data/spec/filters/bugs/language.rb +4 -0
  100. data/spec/filters/bugs/numeric.rb +7 -6
  101. data/spec/filters/bugs/opal.rb +2 -0
  102. data/spec/filters/bugs/regexp.rb +4 -0
  103. data/spec/filters/bugs/string.rb +0 -7
  104. data/spec/filters/bugs/stringscanner.rb +4 -1
  105. data/spec/filters/unsupported/private_methods.rb +2 -0
  106. data/spec/lib/builder_processors_spec.rb +27 -0
  107. data/spec/lib/builder_spec.rb +66 -0
  108. data/spec/{cli → lib}/cli_spec.rb +60 -5
  109. data/spec/{cli → lib}/compiler_spec.rb +66 -5
  110. data/spec/{cli → lib}/dependency_resolver_spec.rb +1 -1
  111. data/spec/lib/fixtures/no_requires.rb +1 -0
  112. data/spec/{cli → lib}/fixtures/opal_file.rb +0 -0
  113. data/spec/lib/fixtures/require_tree_test.rb +3 -0
  114. data/spec/lib/fixtures/required_tree_test/required_file1.rb +1 -0
  115. data/spec/lib/fixtures/required_tree_test/required_file2.rb +1 -0
  116. data/spec/lib/fixtures/requires.rb +7 -0
  117. data/spec/{cli → lib}/fixtures/sprockets_file.js.rb +0 -0
  118. data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
  119. data/spec/lib/hike_path_finder_spec.rb +23 -0
  120. data/spec/{cli → lib}/lexer_spec.rb +1 -1
  121. data/spec/{cli → lib}/parser/alias_spec.rb +1 -1
  122. data/spec/{cli → lib}/parser/and_spec.rb +1 -1
  123. data/spec/{cli → lib}/parser/attrasgn_spec.rb +1 -1
  124. data/spec/{cli → lib}/parser/begin_spec.rb +1 -1
  125. data/spec/{cli → lib}/parser/block_spec.rb +1 -1
  126. data/spec/{cli → lib}/parser/break_spec.rb +1 -1
  127. data/spec/{cli → lib}/parser/call_spec.rb +1 -1
  128. data/spec/{cli → lib}/parser/class_spec.rb +1 -1
  129. data/spec/{cli → lib}/parser/comments_spec.rb +1 -1
  130. data/spec/{cli → lib}/parser/def_spec.rb +1 -1
  131. data/spec/{cli → lib}/parser/if_spec.rb +1 -1
  132. data/spec/{cli → lib}/parser/iter_spec.rb +1 -1
  133. data/spec/{cli → lib}/parser/lambda_spec.rb +1 -1
  134. data/spec/{cli → lib}/parser/literal_spec.rb +1 -1
  135. data/spec/{cli → lib}/parser/masgn_spec.rb +1 -1
  136. data/spec/{cli → lib}/parser/module_spec.rb +1 -1
  137. data/spec/{cli → lib}/parser/not_spec.rb +1 -1
  138. data/spec/{cli → lib}/parser/op_asgn1_spec.rb +1 -1
  139. data/spec/{cli → lib}/parser/op_asgn2_spec.rb +1 -1
  140. data/spec/{cli → lib}/parser/or_spec.rb +1 -1
  141. data/spec/{cli → lib}/parser/return_spec.rb +1 -1
  142. data/spec/{cli → lib}/parser/sclass_spec.rb +1 -1
  143. data/spec/{cli → lib}/parser/string_spec.rb +8 -1
  144. data/spec/{cli → lib}/parser/super_spec.rb +1 -1
  145. data/spec/lib/parser/unary_spec.rb +48 -0
  146. data/spec/{cli → lib}/parser/undef_spec.rb +1 -1
  147. data/spec/{cli → lib}/parser/unless_spec.rb +1 -1
  148. data/spec/{cli → lib}/parser/variables_spec.rb +1 -1
  149. data/spec/{cli → lib}/parser/while_spec.rb +1 -1
  150. data/spec/{cli → lib}/parser/yield_spec.rb +1 -1
  151. data/spec/lib/path_reader_spec.rb +24 -0
  152. data/spec/lib/shared/path_finder_shared.rb +19 -0
  153. data/spec/lib/shared/path_reader_shared.rb +31 -0
  154. data/spec/lib/spec_helper.rb +9 -0
  155. data/spec/lib/sprockets/environment_spec.rb +30 -0
  156. data/spec/{cli → lib}/sprockets/erb_spec.rb +1 -1
  157. data/spec/lib/sprockets/path_reader_spec.rb +25 -0
  158. data/spec/{cli → lib}/sprockets/processor_spec.rb +9 -2
  159. data/spec/lib/sprockets/server_spec.rb +20 -0
  160. data/spec/opal/compiler/irb_spec.rb +11 -11
  161. data/spec/opal/core/fixtures/require_tree_files/file 1.rb +1 -0
  162. data/spec/opal/core/fixtures/require_tree_files/file 2.rb +1 -0
  163. data/spec/opal/core/fixtures/require_tree_files/file 3.rb +1 -0
  164. data/spec/opal/core/fixtures/require_tree_files/file 4.rb +1 -0
  165. data/spec/opal/core/fixtures/require_tree_files/file 5.rb +1 -0
  166. data/spec/opal/core/kernel/require_tree_spec.rb +7 -0
  167. data/spec/opal/core/kernel/respond_to_spec.rb +2 -2
  168. data/spec/opal/core/runtime/method_missing_spec.rb +19 -0
  169. data/spec/opal/core/source_map_spec.rb +2 -2
  170. data/spec/opal/core/string_spec.rb +11 -0
  171. data/spec/opal/stdlib/erb/erb_spec.rb +0 -1
  172. data/spec/opal/stdlib/thread/mutex_spec.rb +40 -0
  173. data/spec/opal/stdlib/thread/thread_queue_spec.rb +32 -0
  174. data/spec/opal/stdlib/thread/thread_spec.rb +60 -0
  175. data/spec/rubyspecs +54 -11
  176. data/spec/spec_helper.rb +18 -3
  177. data/spec/support/mspec_rspec_adapter.rb +33 -0
  178. data/spec/{cli/spec_helper.rb → support/parser_helpers.rb} +10 -10
  179. data/stdlib/README.md +3 -0
  180. data/stdlib/benchmark.rb +10 -0
  181. data/stdlib/date.rb +2 -2
  182. data/stdlib/dir.rb +1 -5
  183. data/stdlib/file.rb +1 -7
  184. data/stdlib/json.rb +10 -1
  185. data/stdlib/native.rb +5 -5
  186. data/stdlib/nodejs.rb +5 -0
  187. data/stdlib/nodejs/dir.rb +13 -0
  188. data/stdlib/nodejs/file.rb +98 -0
  189. data/stdlib/nodejs/fileutils.rb +26 -0
  190. data/stdlib/nodejs/io.rb +2 -0
  191. data/stdlib/nodejs/irb.rb +45 -0
  192. data/stdlib/nodejs/process.rb +16 -0
  193. data/stdlib/nodejs/require.rb +32 -0
  194. data/stdlib/nodejs/rubygems.rb +68 -0
  195. data/stdlib/nodejs/runtime.rb +25 -0
  196. data/stdlib/nodejs/yaml.rb +11 -0
  197. data/stdlib/opal-parser.rb +1 -2
  198. data/stdlib/opal-source-maps.rb +2 -0
  199. data/stdlib/phantomjs.rb +8 -0
  200. data/stdlib/process.rb +10 -0
  201. data/stdlib/promise.rb +12 -4
  202. data/stdlib/set.rb +27 -0
  203. data/stdlib/source_map.rb +5 -63
  204. data/stdlib/source_map/map.rb +220 -0
  205. data/stdlib/source_map/mapping.rb +26 -0
  206. data/stdlib/source_map/offset.rb +88 -0
  207. data/stdlib/source_map/version.rb +3 -0
  208. data/stdlib/source_map/vlq.rb +77 -101
  209. data/stdlib/sourcemap.rb +1 -0
  210. data/stdlib/strscan.rb +7 -1
  211. data/stdlib/template.rb +1 -1
  212. data/stdlib/thread.rb +147 -7
  213. metadata +238 -104
  214. data/lib/mspec/opal/mspec_fixes.rb +0 -87
  215. data/spec/cli/sprockets/environment_spec.rb +0 -14
  216. data/spec/filters/bugs/symbol.rb +0 -5
  217. data/spec/opal/core/kernel/warn_spec.rb +0 -83
  218. data/spec/opal/core/language/numbers_spec.rb +0 -60
  219. data/stdlib/opal-source-maps.js.erb +0 -2
  220. data/stdlib/source_map/generator.rb +0 -251
  221. data/stdlib/source_map/parser.rb +0 -102
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 218fab39fcc4bdbcd8df4f573c9409542f2e91df
4
- data.tar.gz: 2bacc0a96132c782d521cda64eb7cf74f3356874
3
+ metadata.gz: 3d851c3be15f64dbfc7a60b48889722334c757c0
4
+ data.tar.gz: e4e5a13810d7e30f2291aea3b5138e32e72ed15e
5
5
  SHA512:
6
- metadata.gz: 30228944916bea6c4e84cdc8ccac6e2b1f685b120800b8c9735daeee3bde90b208a97aed841972c42e86febe8ea8a8fc77588877ed16b1f1e3036474d399a03a
7
- data.tar.gz: d73f33c4916c14796cc9274854ff8bb0907144f8d7ec3fc2b10100307be415a94631962110fe5e5dcfe6bcb84c0674b9b12c3e8e2c26475034200e0f69a08368
6
+ metadata.gz: 6673321f15d3acdd817b9eeeefffc87a5cd2e9d9c0a8564ab272fb6096a295415a0243f8e079f10227d4c593ebd022b2b681c17abce715de50b19ebca5c77b08
7
+ data.tar.gz: 3ac4adb02d69f45cfa9396cab5814ae4b527dfbdb60b68d42a93c50dcb887d0b1d83c70d78800092e040eeb9f85235100db5b28a316bf1ba7f27c1e62c5631f9
data/.gitignore CHANGED
@@ -8,4 +8,3 @@ build/
8
8
  /cdn
9
9
  /node_modules
10
10
  /gh-pages
11
- /tmp
data/.spectator ADDED
@@ -0,0 +1,2 @@
1
+ BASE_DIR_REGEXP: 'lib/opal'
2
+ SPEC_DIR_REGEXP: 'spec/lib'
data/.spectator-mspec ADDED
@@ -0,0 +1,3 @@
1
+ BASE_DIR_REGEXP: '(?:opal/corelib|stdlib)'
2
+ SPEC_DIR_REGEXP: '(?:spec/corelib/(?:core|language)|spec/opal|spec/stdlib/.*?/spec\b)'
3
+ RSPEC_COMMAND: 'bundle exec ./bin/opal-mspec'
data/.travis.yml CHANGED
@@ -6,12 +6,9 @@ matrix:
6
6
  fast_finish: true
7
7
 
8
8
  include:
9
- - rvm: 2.1.0
9
+ - rvm: 2.1.1
10
10
  env: RUN=default
11
11
 
12
- - rvm: 1.8.7
13
- env: RUN=rspec
14
-
15
12
  - rvm: 1.9.3
16
13
  env: RUN=rspec
17
14
 
@@ -31,18 +28,18 @@ matrix:
31
28
  - rvm: rbx
32
29
  - rvm: jruby
33
30
 
31
+ # Setting TimeZone. We'll need to do this in order to
32
+ # have the TZ related failures surface on Travis CI.
33
+ # http://stackoverflow.com/a/23374438/601782
34
34
  before_install:
35
35
  - git submodule update --init
36
36
 
37
- # Fix waiting for rubygems v2.2.1 to be released and active on travis
38
- # https://github.com/rubygems/rubygems/commit/f8e0f1d5f67cfc4e1966cc1e2db367aebf8a09e4
39
- - gem update bundler
40
- - bundle --version
41
- - gem update --system 2.1.11
42
- - gem --version
43
-
44
37
  script:
45
38
  - "bundle exec rake $RUN"
46
39
 
47
40
  notifications:
48
41
  irc: "irc.freenode.org#opal"
42
+ webhooks:
43
+ urls:
44
+ - https://webhooks.gitter.im/e/2ea12333adebda0c2289
45
+
data/CHANGELOG.md CHANGED
@@ -1,3 +1,36 @@
1
+ ## edge (upcoming 0.7)
2
+
3
+ * Fixed `-@` unary op. precedence with a numeric and followed by a method call (e.g. `-1.foo` was parsed as `-(1.foo)`)
4
+
5
+ * `require_relative` (with strings) is now preprocessed, expanded and added to `Compiler#requires`
6
+
7
+ * Rewritten the require system to respect requires position (previously all the requires were stacked up at the top of the file)
8
+
9
+ * Implement for-loop syntax
10
+
11
+ * Add Array#|
12
+
13
+ * Fix Range.new to raise `ArgumentError` on contructor values that cannot
14
+ be compared
15
+
16
+ * Fix compiler bug where Contiguous strings were not getting concatenated.
17
+
18
+ * Cleanup generated code for constant access. All constant lookups now go through `$scope.get('CONST_NAME')` to produce cleaner code and a unified place for const missing dispatch.
19
+
20
+ * Remove `const_missing` option from compiler. All constant lookups are now strict.
21
+
22
+ * Add initial support for Module#autoload.
23
+
24
+ ## 0.6.2 2014-04-25
25
+
26
+ * Added Range#size
27
+
28
+ * `opal` executable now reads STDIN when no file or `-e` are passed
29
+
30
+ * `opal` executable doesn't exit after showing version on `-v` if other options are passed
31
+
32
+ * (Internal) improved the mspec runner
33
+
1
34
  ## 0.6.1 2014-04-15
2
35
 
3
36
  * Updated RubySpecs to master and added `rubysl-*` specs. Thanks to Mike Owens (@mieko)
data/CONTRIBUTING.md CHANGED
@@ -8,12 +8,14 @@ FreeNode.
8
8
 
9
9
  ## Contributing
10
10
 
11
- * Before opening a new issue, search for previous discussions including closed
12
- ones. At comments there if a similar issue is found.
11
+ 1. Before opening a new issue, search for previous discussions including closed
12
+ ones. Add comments there if a similar issue is found.
13
13
 
14
- * Before sending pull requests make sure all tests run and pass (see below).
14
+ 2. Please report the version on which the issue is found.
15
15
 
16
- * Make sure to use a similar coding style to the rest of the code base. In ruby
16
+ 3. Before sending pull requests make sure all tests run and pass (see below).
17
+
18
+ 4. Make sure to use a similar coding style to the rest of the code base. In ruby
17
19
  and javascript code we use 2 spaces (no tabs).
18
20
 
19
21
  ## Quick Start
@@ -30,47 +32,10 @@ Get dependencies:
30
32
  $ bundle
31
33
  ```
32
34
 
33
- ## Running Tests
34
-
35
- ### Runtime
36
-
37
- Some opal specific tests are found inside `spec/`, but the majority of our
38
- runtime tests now come from rubyspec. Rubyspec is included as a git submodule.
39
- To get our latest referenced checkout, just run:
40
-
41
- ```
42
- $ git submodule update --init
43
- ```
44
-
45
- You need phantomjs installed to run tests. To build opal, its dependencies
46
- and all specs, run:
47
-
48
- ```
49
- $ bundle exec rake mspec
50
- ```
51
-
52
- You can alternatively run tests in a browser using:
53
-
54
- ```
55
- $ rackup
56
- ```
57
-
58
- And then opening `http://127.0.0.1:9292` in a web browser.
59
-
60
- ### Gem/lib tests
61
-
62
- We also include some tests for running under your standard ruby implementation
63
- which are in `mri_spec/`. To run tests tests using rake, use:
64
-
65
- ```
66
- $ bundle exec rake mri_spec
67
- ```
68
-
69
- ### All tests
70
-
71
- To run all the tests together (which you should do while contributing), run:
35
+ Run the test suite:
72
36
 
73
37
  ```
74
38
  $ bundle exec rake
75
39
  ```
76
40
 
41
+ See the [README](https://github.com/opal/opal/blob/master/README.md#running-tests) for further details.
data/Gemfile CHANGED
@@ -2,15 +2,26 @@ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  # Stick with older racc until
5
- # https://github.com/tenderlove/racc/issues/32
6
- # and
7
5
  # https://github.com/tenderlove/racc/issues/22
8
- # are solved.
9
- gem 'racc', '< 1.4.10' if RUBY_VERSION.to_f < 1.9 or RUBY_ENGINE == 'jruby'
6
+ # is solved.
7
+ gem 'racc', '< 1.4.10' if RUBY_ENGINE == 'jruby'
10
8
  gem 'json', '< 1.8.1' if RUBY_VERSION.to_f == 2.1 and RUBY_ENGINE == 'ruby'
11
9
  gem 'rubysl', :platform => :rbx
10
+ gem 'thin', platform: :mri
11
+
12
+ # Uncomment to try with sprockets 3.0:
13
+ #
14
+ # gem 'sprockets', '~> 3.0.0.beta'
12
15
 
13
16
  group :repl do
14
17
  gem 'therubyracer', :platform => :mri, :require => 'v8'
15
18
  gem 'therubyrhino', :platform => :jruby
16
19
  end
20
+
21
+ unless ENV['CI']
22
+ gem 'rb-fsevent'
23
+ gem 'guard', require: false
24
+ gem 'terminal-notifier-guard'
25
+ end
26
+
27
+ gem 'mspec', github: 'opal/mspec'
data/Guardfile ADDED
@@ -0,0 +1,77 @@
1
+ require 'guard/plugin'
2
+
3
+ class ::Guard::Opal < Plugin
4
+ def mspec *paths
5
+ command = ['bundle', 'exec', './bin/opal-mspec', *paths.flatten]
6
+ result = time(:mspec, *paths) { system *command }
7
+ notify 'MSpec', result
8
+ end
9
+
10
+ def rspec *paths
11
+ command = ['bundle', 'exec', 'rspec', *paths.flatten]
12
+ result = time(:rspec, *paths) { system *command }
13
+ notify 'RSpec', result
14
+ end
15
+
16
+ def notify lib, result
17
+ if result
18
+ ::Guard::Notifier.notify(
19
+ 'Success ♥︎', title: "#{lib} results", image: :success, priority: 1
20
+ )
21
+ else
22
+ ::Guard::Notifier.notify(
23
+ 'Failed ♠︎', title: "#{lib} results", image: :failed, priority: 1
24
+ )
25
+ end
26
+ end
27
+
28
+ def color *args
29
+ Guard::UI.send :color, *args
30
+ end
31
+
32
+ def terminal_columns
33
+ cols = `tput cols 2> /dev/tty`.strip.to_i
34
+ ($?.success? && cols.nonzero?) ? cols : 80
35
+ end
36
+
37
+ def time *titles
38
+ columns = terminal_columns
39
+ puts color("=== running: #{titles.join(' ')} ".ljust(columns,'='), :cyan)
40
+ s = Time.now
41
+ result = yield
42
+ t = (Time.now - s).to_f
43
+ puts color("=== time: #{t} seconds ".ljust(columns, '='), :cyan)
44
+ result
45
+ end
46
+
47
+ def run_on_changes(changes)
48
+ m = changes
49
+ path = m[0]
50
+ puts color("Searching specs for #{m[0]}...", :yellow)
51
+ case path
52
+ when %r{grammar\.y$} then system 'rake racc'
53
+ when %r{^spec/lib} then rspec path
54
+ when %r{^spec/corelib} then mspec path
55
+ when %r{^opal/corelib}
56
+ name = File.basename(path, '.rb')
57
+ mspec "spec/corelib/core/#{name}/**/*_spec.rb"
58
+ when %r{^lib/opal/(.*)\.rb$}
59
+ name = $1
60
+ specs = Dir["spec/lib/#{name}_spec.rb"]
61
+ rspec *specs
62
+ end
63
+ end
64
+
65
+ def run_all
66
+ time(:all) { system 'bundle', 'exec', 'rake' }
67
+ end
68
+ end
69
+
70
+ guard :opal do
71
+ ignore %r{^(tmp|tasks|pkg|cdn|build|node_modules|grammar.rb)}
72
+ watch %r{^spec/.*}
73
+ watch %r{^lib/.*}
74
+ watch %r{^bin/.*}
75
+ watch %r{^opal/.*}
76
+ watch %r{^stdlib/.*}
77
+ end
data/README.md CHANGED
@@ -1,15 +1,19 @@
1
1
  # Opal
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/opal/opal.svg?branch=master)](http://travis-ci.org/opal/opal)
4
- [![Gem Version](https://badge.fury.io/rb/opal.svg)](http://badge.fury.io/rb/opal)
5
- [![Code Climate](http://img.shields.io/codeclimate/github/opal/opal.svg)](https://codeclimate.com/github/opal/opal)
3
+ [![Build Status](http://img.shields.io/travis/opal/opal/master.svg?style=flat)](http://travis-ci.org/opal/opal)
4
+ [![Gem Version](http://img.shields.io/gem/v/opal.svg?style=flat)](http://badge.fury.io/rb/opal)
5
+ [![Code Climate](http://img.shields.io/codeclimate/github/opal/opal.svg?style=flat)](https://codeclimate.com/github/opal/opal)
6
6
 
7
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
11
  is a Freenode IRC channel at [#opal](http://webchat.freenode.net/?channels=opal),
12
- ask questions on [stackoverflow#opalrb](http://stackoverflow.com/questions/ask?tags=opalrb).
12
+ ask questions on [stackoverflow (tag #opalrb)](http://stackoverflow.com/questions/ask?tags=opalrb).
13
+
14
+ [![Stack Overflow](http://img.shields.io/badge/stackoverflow-%23opalrb-orange.svg?style=flat)](http://stackoverflow.com/questions/ask?tags=opalrb)
15
+ [![API doc](http://img.shields.io/badge/doc-api-blue.svg?style=flat)](http://opalrb.org/docs/api)
16
+ [![Gitter chat](http://img.shields.io/badge/gitter-opal%2Fopal-009966.svg?style=flat)](https://gitter.im/opal/opal)
13
17
 
14
18
 
15
19
 
@@ -68,6 +72,12 @@ The test suite can be run using (requires [phantomjs][]):
68
72
 
69
73
  This will command will run all RSpec and MSpec examples in sequence.
70
74
 
75
+ #### Automated runs
76
+
77
+ A `Guardfile` with decent mappings between specs and lib/corelib/stdlib files is in place.
78
+ Run `bundle exec guard -i` to have it started.
79
+
80
+
71
81
  ### MSpec
72
82
 
73
83
  [MSpec][] tests can be run with:
@@ -77,16 +87,13 @@ This will command will run all RSpec and MSpec examples in sequence.
77
87
  Alternatively, you can just load up a rack instance using `rackup spec/config.ru`, and
78
88
  visit `http://localhost:9292/` in any web browser.
79
89
 
90
+
80
91
  ### Rspec
81
92
 
82
93
  [RSpec][] tests can be run with
83
94
 
84
95
  $ rake rspec
85
96
 
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
97
 
91
98
  ## Code Overview
92
99
 
@@ -167,6 +174,5 @@ THE SOFTWARE.
167
174
 
168
175
 
169
176
  [phantomjs]: http://phantomjs.org
170
- [spectator]: https://github.com/elia/spectator#readme
171
177
  [MSpec]: https://github.com/rubyspec/mspec#readme
172
178
  [RSpec]: https://github.com/rspec/rspec#readme
data/Rakefile CHANGED
@@ -1,3 +1,6 @@
1
+ # FIXME: there must be a better way
2
+ Encoding.default_external = 'utf-8'
3
+
1
4
  require 'bundler'
2
5
  Bundler.require
3
6
  Bundler::GemHelper.install_tasks
@@ -6,7 +9,7 @@ import 'tasks/github.rake'
6
9
 
7
10
  require 'rspec/core/rake_task'
8
11
  RSpec::Core::RakeTask.new(:rspec) do |t|
9
- t.pattern = 'spec/cli/**/*_spec.rb'
12
+ t.pattern = 'spec/lib/**/*_spec.rb'
10
13
  end
11
14
 
12
15
  require 'mspec/opal/rake_task'
@@ -27,12 +30,14 @@ and the destination dir with the DIR env var.
27
30
 
28
31
  Example: rake dist DIR=/tmp/foo FILES='opal.rb,base64.rb'
29
32
  Example: rake dist DIR=cdn/opal/#{Opal::VERSION}
33
+ Example: rake dist DIR=cdn/opal/master
30
34
  DESC
31
35
  task :dist do
32
36
  require 'opal/util'
33
37
 
34
38
  Opal::Processor.arity_check_enabled = false
35
39
  Opal::Processor.const_missing_enabled = false
40
+ Opal::Processor.dynamic_require_severity = :warning
36
41
  env = Opal::Environment.new
37
42
 
38
43
  build_dir = ENV['DIR'] || 'build'
@@ -73,19 +78,38 @@ task :clobber do
73
78
  end
74
79
 
75
80
  namespace :doc do
76
- generate_docs_for = ->(glob, name){
77
- release_name = `git rev-parse --abbrev-ref HEAD`.chomp
78
- command = "yard doc #{glob} -o gh-pages/doc/#{release_name}/#{name}"
79
- puts command
80
- system command
81
- }
82
-
83
- task :corelib do
84
- generate_docs_for['opal/**/*.rb', 'corelib']
81
+ doc_repo = Pathname(ENV['DOC_REPO'] || 'gh-pages')
82
+ doc_base = doc_repo.join('doc')
83
+ current_git_release = -> { `git rev-parse --abbrev-ref HEAD`.chomp }
84
+ template_option = "--template opal --template-path #{doc_repo.join('yard-templates')}"
85
+
86
+ directory doc_repo.to_s do
87
+ remote = ENV['DOC_REPO_REMOTE'] || '.'
88
+ sh 'git', 'clone', '-b', 'gh-pages', '--', remote, doc_repo.to_s
89
+ end
90
+
91
+ task :corelib => doc_repo.to_s do
92
+ git = current_git_release.call
93
+ name = 'corelib'
94
+ glob = 'opal/**/*.rb'
95
+
96
+ command = "doxx --template #{doc_repo.join('doxx-templates/opal.jade')} "\
97
+ "--source opal/corelib --target #{doc_base}/#{git}/#{name} "\
98
+ "--title \"Opal runtime.js Documentation\" --readme opal/README.md"
99
+ puts command; system command or $stderr.puts "Please install doxx with: npm install"
100
+
101
+ command = "yard doc #{glob} #{template_option} "\
102
+ "--readme opal/README.md -o #{doc_base}/#{git}/#{name}"
103
+ puts command; system command
85
104
  end
86
105
 
87
- task :stdlib do
88
- generate_docs_for['stdlib/**/*.rb', 'stdlib']
106
+ task :stdlib => doc_repo do
107
+ git = current_git_release.call
108
+ name = 'stdlib'
109
+ glob = '{stdlib/**/*,opal/compiler,opal/erb,opal/version}.rb'
110
+ command = "yard doc #{glob} #{template_option} "\
111
+ "--readme stdlib/README.md -o gh-pages/doc/#{git}/#{name}"
112
+ puts command; system command
89
113
  end
90
114
  end
91
115
 
@@ -0,0 +1,11 @@
1
+ require "benchmark"
2
+
3
+ time = Benchmark.measure do
4
+ a = 0
5
+ 100000.times do
6
+ a = a + 1
7
+ end
8
+ puts a
9
+ end
10
+
11
+ puts time
data/bin/opal CHANGED
@@ -1,25 +1,22 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # Error codes are taken from /usr/include/sysexits.h
4
+
3
5
  require 'opal/cli_options'
4
6
  options = Opal::CLIOptions.new
5
- options.parse!
6
-
7
-
8
- if ARGV.empty? and !options.options[:evals]
9
- if options.options[:verbose]
10
- exit
11
- else
12
- options.options[:evals] ||= []
13
- options.options[:evals] << gets(nil)
14
- end
7
+ begin
8
+ options.parse!
9
+ rescue OptionParser::InvalidOption => e
10
+ $stderr.puts "#{$0}: #{e.message} (-h will show valid options)"
11
+ exit 64
15
12
  end
16
13
 
17
14
  require 'opal/cli'
18
- cli = Opal::CLI.new options.options.merge(:filename => ARGV.first)
15
+ cli = Opal::CLI.new options.options.merge(:file => ARGF.file, :argv => ARGV.dup)
19
16
 
20
17
  begin
21
18
  cli.run
22
- rescue Opal::CLI::MissingNodeJS => e
19
+ rescue Opal::CliRunners::RunnerError => e
23
20
  $stderr.puts e.message
24
- exit 127
21
+ exit 72
25
22
  end